Database Preprocessing for Urban IRT (CNP scenario)

Detailed Description

This is an example of how to use the WinProp API to preprocess a mixed urban-indoor database (CNP scenario) for IRT. The full example is distributed with the installation.
#include <stdio.h>
#include <string>
#include <iostream>

#include "IRT_preprocess_urban_CNP.h"

#ifndef API_DATA_FOLDER
#define API_DATA_FOLDER "../../api/winprop/data/"
#endif // !API_DATA_FOLDER

int main(int argc, char** argv)
{
	int Error = 0;
	WinProp_PreProUrban	PreproPara;
	WinProp_Callback    Callback;

    // Initializations
    WinProp_Structure_Init_Callback(&Callback);
	WinProp_Structure_Init_PreProUrban(&PreproPara);
	Callback.Percentage = CallbackProgress;
	Callback.Message = CallbackMessage;
	Callback.Error = CallbackError;

	// Definition of parameters for preprocessing
	sprintf(PreproPara.FilenameBuildings, "%s", API_DATA_FOLDER  "/outdoor/OfficeParkCNP");

	PreproPara.Model = PREDMODEL_IRT;
	PreproPara.Mode = PP_MODE_IRT_3D;
	PreproPara.NrHeights = 1;
	PreproPara.Heights = (double*)malloc(sizeof(double) * (PreproPara.NrHeights));
	PreproPara.Heights[0] = 1.5;
	PreproPara.HeightAbsolute = 0;
	PreproPara.ConsiderIndoorPixels = 1;
	PreproPara.AdaptiveResolution = 0;
	PreproPara.Resolution = (double)10.;
	PreproPara.SegmentHorizontal = (double)100.;
	PreproPara.SegmentVertical = (double)100.;
	PreproPara.TileHorizontal = (double)100.;
	PreproPara.TileVertical = (double)100.;
	PreproPara.ConsiderTopography = 0;
	PreproPara.AbsoluteBuildingHeights = 0;
	PreproPara.MultipleInteractions = 1;

	PreproPara.SphericMode = PP_MODE_IRT_ZONE_OFF;

	// Enable multi threading
	PreproPara.MultiThreading = 2;

	// Set IRT preprocessing area
	PreproPara.lowerLeft = { 74.437, 32.228, PreproPara.Heights[0] };
	PreproPara.upperRight = { 184.812, 159.853, PreproPara.Heights[0] };

	// Set IRT CNP parameters
	PreproPara.CNPIndoorMode = 2;
	PreproPara.CNPIndoorTile = 5.0;
	PreproPara.CNPIndoorSegment = 5.0;
	PreproPara.CNPResolution = 2.0;
	PreproPara.CNPNrHeights = 1;
	PreproPara.CNPHeights = (double*)malloc(sizeof(double) * (PreproPara.CNPNrHeights));
	PreproPara.CNPHeights[0] = 1.5;
	PreproPara.CNPUrbanTile = 5.0f;
	PreproPara.CNPRedRes = 1;
	PreproPara.CNPRedResFactor = 2;
	PreproPara.CNPSphericZone = 0;
	PreproPara.CNPSphericRadius = 100.0;

	// Compute the preprocessing
	Error = OutdoorPlugIn_ComputePrePro(
		&PreproPara,
		API_DATA_FOLDER "/outdoor/OfficeParkCNP_IRT_API", // no extension here
		nullptr,
		nullptr,
		&Callback,
		nullptr
	);

	if (PreproPara.CornersPolygon != nullptr)
		free(PreproPara.CornersPolygon);
	if (PreproPara.Heights != NULL)
		free(PreproPara.Heights);
	if (PreproPara.CNPHeights != NULL)
		free(PreproPara.CNPHeights);
	PreproPara.Heights = nullptr;
	PreproPara.NrHeights = 0;
	PreproPara.CNPHeights = nullptr;
	PreproPara.CNPNrHeights = 0;

	return 0;
}

int _STD_CALL CallbackMessage(const char * Text)
{
	if (Text == nullptr)
		return 0;

	std::cout << "\n" << Text;

	return(0);
}

int _STD_CALL CallbackError(const char * Text, int Error)
{
	if (Text == nullptr)
		return 0;

	std::cout << "\n";

#ifdef __LINUX
	std::cout << "\033[31m" << "Error (" << Error << "): "; // highlight error in red color
#else
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED);
	std::cout << "Error (" << Error << "): ";
#endif // __LINUX
	std::cout << Text;

#ifdef __LINUX
	std::cout << "\033[0m"; // highlight error in red color
#else
	SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
#endif // __LINUX

	return 0;
}

int _STD_CALL CallbackProgress(int value, const char* text)
{
	char Line[200];

	sprintf(Line, "\n%d%% %s", value, text);
	std::cout << Line;

	return(0);
}