CombinedModelTest.cpp 4.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * ----------------------------------------------------------------
 *
 *		ITA geometrical acoustics
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2018
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 * Tests the image (source) model algorithm.
 *
 */

#include <ITAStopWatch.h>
#include <ITAStringUtils.h>

24
#include <ITAPropagationPathSim/CombinedModel/PropagationEngine.h>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <ITAGeo/Base.h>
#include <ITAGeo/Utils.h>
#include <ITAGeo/SketchUp/Model.h>
#include <ITAGeo/Material/Material.h>
#include <ITAGeo/Material/Manager.h>

#include <cassert>

using namespace std;
using namespace ITAGeo;
using namespace ITAPropagationPathSim;

int main( int iNumInArgs, char* pcInArgs[] )
{
	string sSubFolder = "SketchUpFiles/";

41
	string sInFile = "ThreeBuildings.skp";
42 43 44 45
	if( iNumInArgs > 1 )
		sInFile = string( pcInArgs[ 1 ] );


46 47

	//Load geo model(for later saving of the propagation paths)
48
	SketchUp::CModel oGeoModel;
49

50 51
	if( oGeoModel.Load(sSubFolder + sInFile ) )
	{
52
		cout << "Successfully loaded '" << sInFile << "'" << endl;
53 54 55 56 57 58 59
	}
	else
	{
		cerr << "Could not load " << sInFile << endl;
		return 255;
	}

60 61
	//Load mesh model list
	auto pMeshModelList = make_shared< ITAGeo::Halfedge::CMeshModelList>();
62

63
	if (pMeshModelList->Load(sSubFolder + sInFile))
64
	{
65
		cout << "Successfully loaded '" << sInFile << "'" << endl;
66 67 68
	}
	else
	{
69 70
		cerr << "Could not load " << sInFile << endl;
		return 255;
71 72
	}

73 74 75 76 77 78
	//auto pSensor = make_shared< CSensor >( VistaVector3D( 3.0f, 3.3f, 1.3f ) );
	//auto pEmitter = make_shared< CEmitter  >( VistaVector3D( 2.1f, 2.2f, 1.7f ) );

	auto pSensor = make_shared< CSensor >(VistaVector3D(3.0f, 0, 1.4f));
	auto pEmitter = make_shared< CEmitter  >(VistaVector3D(-3.0f, 0, 1.4f));

79

80 81
	cout << "Emitter: " << pEmitter->vPos << endl;
	cout << "Sensor: " << pSensor->vPos << endl;
82

83 84 85 86 87 88 89 90 91 92
	//Configuration of the engine 
	const bool bOnlyNeighbouredEdgeDiffraction = false;
	const bool bDiffractionOnlyIntoShadowRegion = true;
	const bool bFilterNotVisiblePathsBetweenEdges = false; //Intersection test between edges(expensive)
	const bool bFilterNotVisiblePointToEdge = true; //Intersection test between emitter/sensor and edges
	const bool bFilterNotVisiblePaths = true; //Intersection test of calculated sub paths

	const int iMaxDiffractionOrder = 3;
	const int iMaxReflectionOrder = 2;
	const int iMaxCombinedOrder = 5;
93 94 95

	ITAStopWatch sw; sw.start();

96
	auto pPathEngine = make_shared<CombinedModel::CPathEngine>();
97
	cout << "Calculation time initialization path engine: " << timeToString(sw.stop()) << endl;
98

99
	sw.start();
100

101 102 103 104 105 106 107 108 109 110 111
	pPathEngine->ConfigureFilter(bOnlyNeighbouredEdgeDiffraction, bDiffractionOnlyIntoShadowRegion, bFilterNotVisiblePathsBetweenEdges, bFilterNotVisiblePointToEdge, bFilterNotVisiblePointToEdge);
	cout << "Calculation time configuring filter: " << timeToString(sw.stop()) << endl;

	sw.start();

	pPathEngine->InitializePathEnvironment(pMeshModelList);
	cout << "Calculation time initialization path environment: " << timeToString(sw.stop()) << endl;

	sw.start();

	pPathEngine->ApplyEmitter(pEmitter, iMaxDiffractionOrder, iMaxReflectionOrder, iMaxCombinedOrder);
112
	cout << "Calculation time applying emitter: " << timeToString(sw.stop()) << endl;
113

114
	sw.start();
115

116 117 118
	pPathEngine->ApplySensor(pSensor);
	cout << "Calculation time applying sensor: " << timeToString(sw.stop()) << endl;

119
	CPropagationPathList oPathListAll, oPathListVisible;
120

121 122 123 124
	sw.start();

	pPathEngine->ConstructPropagationPaths(oPathListAll);
	cout << "Calculation time propagation path creation: " << timeToString(sw.stop()) << endl;
125

126 127
	sw.start();

128
	pMeshModelList->FilterVisiblePaths(oPathListAll, oPathListVisible);
129
	cout << "Calculation time filtering visible paths: " << timeToString(sw.stop()) << endl;
130

131 132 133 134
	cout << "All paths: " << to_string(oPathListAll.size()) << endl;
	cout << "Visible paths: " << to_string(oPathListVisible.size()) << endl;


135 136 137
	//Add emitter and sensor to visualization
	oGeoModel.AddEmitterVisualization(*pEmitter, "Emitter A");
	oGeoModel.AddSensorVisualization(*pSensor, "Sensor A");
138

139
	
140

141
	for (auto& oPath : oPathListVisible)
142
	{
143 144
		long iNumReflections = (long) oPath.GetNumReflections(); 
		long iNumDiffractions = (long) oPath.GetNumDiffractions();
145

146
		
147
		string sPathName = "Paths_Refl_Order_" + to_string(iNumReflections) + "_Diffr_Order_" + to_string(iNumDiffractions);
148
		oGeoModel.AddPropagationPathVisualization(oPath, sPathName);
149
	}
150

151
	oPathListVisible.Store("CombinedModelTest_" + sInFile + ".json");
152

153
	oGeoModel.Store(sSubFolder +"CombinedModelTest_"+ sInFile);
154 155 156

	return 0;
}