Commit 34789664 authored by Armin Erraji's avatar Armin Erraji

Implement Base Image Source model class

parent 9627dbc3
......@@ -42,11 +42,11 @@ namespace ITAPropagationPathSim
* Creates a copy if the model and pre-allocates all image sources.
* @note Not efficient for complex geometries! Use an engine that employs image pools and pre-filtering of possible images
*
* @param[in] oBuildings Mesh model (will be copied)
* @param[in] iEmitterImageOrder Defaults to 2 (first order images of sending entity / source)
* @param[in] vpMeshModelList Mesh model (will be copied)
* @param[in] iSourceImageOrder Defaults to 2 (first order images of sending entity / source)
*
*/
CSource(const ITAGeo::Urban::CModel& oUrbanModel, const int iEmitterImageOrder = ITAGeo::ORDER_2);
CSource(const ITAGeo::Halfedge::CMeshModelList& vpMeshModelList,int iSourceImageOrder = ITAGeo::ORDER_2);
//! Destructor
virtual ~CSource();
......@@ -105,8 +105,8 @@ namespace ITAPropagationPathSim
//---Member variables-------------------------------------------------------------------------------------------------
//Vector of building meshes
map< string, ITAGeo::Halfedge::CMeshModel* > m_mpBuildings;
//Vector of mesh models
ITAGeo::Halfedge::CMeshModelList m_vpMeshModelList;
//! Root of image sources as image source of order 0 (commonly the emitter)
CImageNode* m_pImagesRoot;
......@@ -116,17 +116,14 @@ namespace ITAPropagationPathSim
//! Max order of image sources
int m_iMaxOrder;
//! Vector of building names
vector<string> m_vsBuildingNames;
};
//! Simple image node for urban models
class CSource::CImageNode // @todo: evtl. vererben von ITAPropagationPathSim::MirrorImage::CEngine::CImageNode
class CSource::CImageNode
{
public:
//---Constructor------------------------------------------------------------------------------------------------------
CImageNode(const int iOrder, const int iMaxOrder, const ITAGeo::Urban::CModel& oUrbanModel, CImageNode* pParent_ = nullptr, const int iBuildingIndex = -1);
CImageNode(const int iOrder, const int iMaxOrder, const ITAGeo::Halfedge::CMeshModelList& vpMeshModelList, CImageNode* pParent_ = nullptr, const int iBuildingIndex = -1);
//---Member functions-------------------------------------------------------------------------------------------------
......@@ -134,7 +131,7 @@ namespace ITAPropagationPathSim
//---Member variables-------------------------------------------------------------------------------------------------
string m_sBuildingName = "";
string m_sMeshModelName = "";
CImageNode* pParent; //!< Pointer to parent node or nullptr
map <string, vector< CImageNode* >> mpImageChildren; //!< List of siblings, mapped by its parent building and its own building
......
......@@ -15,34 +15,25 @@ struct CITAMeshPtr
//---Constructor----------------------------------------------------------------------------------------------------------------------------
CSource::CSource(const ITAGeo::Urban::CModel& oUrbanModel, const int iEmitterImageOrder)
CSource::CSource(const ITAGeo::Halfedge::CMeshModelList& vpMeshModelList, const int iSourceImageOrder)
{
//Copy to buildings vector
for(int i = 0; i< oUrbanModel.GetNumBuildings(); i++)
{
auto oCurrentBuilding = oUrbanModel.GetBuildings()[i];
string sBuildingName = oUrbanModel.GetBuildingNames()[i];
ITAGeo::Halfedge::CMeshModel* pCurrentBuildingCopy = new ITAGeo::Halfedge::CMeshModel();
pCurrentBuildingCopy->CopyFrom(*oCurrentBuilding);
m_vpMeshModelList.CopyFrom(vpMeshModelList);
// Calculate mesh face normals
CITAMesh* pMesh = pCurrentBuildingCopy->GetMesh()->pMesh;
//Copy to mesh model vector
for(int i = 0; i< vpMeshModelList.GetNumMeshes(); i++)
{
// Calculate mesh face normals
CITAMesh* pMesh = m_vpMeshModelList[i]->GetMesh()->pMesh;
pMesh->request_face_normals();
pMesh->update_face_normals();
//Add current building to member variable
m_mpBuildings[sBuildingName] = pCurrentBuildingCopy;
}
//Initialize image root
m_pImagesRoot = new CImageNode(ITAGeo::ORDER_0, iEmitterImageOrder, oUrbanModel);
m_pImagesRoot = new CImageNode(ITAGeo::ORDER_0, iSourceImageOrder, vpMeshModelList);
//Set max order member variable
m_iMaxOrder = iEmitterImageOrder;
//Get building name vector
m_vsBuildingNames = oUrbanModel.GetBuildingNames();
m_iMaxOrder = iSourceImageOrder;
}
//---Destructor-----------------------------------------------------------------------------------------------------------------------------
......@@ -50,11 +41,6 @@ CSource::CSource(const ITAGeo::Urban::CModel& oUrbanModel, const int iEmitterIma
CSource::~CSource()
{
delete m_pImagesRoot;
for each (string buildingName in m_vsBuildingNames)
{
delete m_mpBuildings[buildingName];
}
}
//---Construct functions--------------------------------------------------------------------------------------------------------------------
......@@ -78,34 +64,30 @@ void CSource::ConstructImagesRecursive(CImageNode* pParent, const int iMaxOrder,
if (iCurrentOrder > iMaxOrder)
return;
//Iterate over all buildings
for each (string sBuildingName in m_vsBuildingNames)
//Iterate over all mesh models
for(auto& pMeshModel : m_vpMeshModelList)
{
CITAMesh* pCurrentMesh = m_mpBuildings[sBuildingName]->GetMesh()->pMesh;
CITAMesh* pCurrentMesh = pMeshModel->GetMesh()->pMesh;
//Iterate over all faces of current building mesh
//Iterate over all faces of current mesh
size_t n_face = 0;
CITAMesh::ConstFaceIter cf_it = pCurrentMesh->faces_begin();
while (cf_it != pCurrentMesh->faces_end())
{
CITAMesh::FaceHandle hFace(*cf_it++);
if (pParent->pParent == nullptr || (hFace.idx() != pParent->pImage->iPolygonIndex) || (sBuildingName != pParent->m_sBuildingName))
if (pParent->pParent == nullptr || (hFace.idx() != pParent->pImage->iPolygonIndex) || (pMeshModel->GetName() != pParent->m_sMeshModelName))
{
CImageNode* pSibling = pParent->mpImageChildren[sBuildingName][n_face++];
CImageNode* pSibling = pParent->mpImageChildren[pMeshModel->GetName()][n_face++];
// Calculates next-order images from parent image based on mirror approach
CalculateImage(pCurrentMesh, pParent->pImage, pSibling->pImage, hFace);
// Recursive construction until max order is reached
ConstructImagesRecursive(pSibling, iMaxOrder, iCurrentOrder + 1);
}
}
}
}
void CSource::ConstructReflectionPaths(std::shared_ptr< ITAGeo::CPropagationAnchor > pDestinationAnchor, ITAGeo::CPropagationPathList& oPathList, const ITAGeo::ECulling eCulling /* = NONE*/, const int iMaxOrder /* = -1 */)
......@@ -154,9 +136,9 @@ void CSource::ConstructReflectionPathList(CImageNode * pRoot, std::shared_ptr<IT
auto iCurrentOrder = pRoot->pImage->iOrder;
if ((iOrder != iCurrentOrder) && (iCurrentOrder < iMaxOrder))
{
for each (string sBuildingName in m_vsBuildingNames)
for each (auto& pMeshModel in m_vpMeshModelList)
{
for each (auto pChild in pRoot->mpImageChildren[sBuildingName])
for each (auto pChild in pRoot->mpImageChildren[pMeshModel->GetName()])
{
ConstructReflectionPathList(pChild, pDestination, oPathList, iMaxOrder, eCulling, iOrder);
}
......@@ -174,7 +156,7 @@ void CSource::ConstructReflectionsPath(CImageNode* pNode, std::shared_ptr< const
return;
//Get current mesh and the corresponding face handle
auto pCurrentMesh = m_mpBuildings[pNode->m_sBuildingName]->GetMesh()->pMesh;
auto pCurrentMesh = m_vpMeshModelList.GetMeshModel(pNode->m_sMeshModelName)->GetMesh()->pMesh;
auto hFace = pCurrentMesh->face_handle(iFaceIndex);
VistaVector3D v3CurrentOrigin = pStartAnchor->v3InteractionPoint;
......@@ -195,7 +177,7 @@ void CSource::ConstructReflectionsPath(CImageNode* pNode, std::shared_ptr< const
oPath[pNode->pImage->iOrder] = pReflectionAnchor;
//Add further propagation anchors to path until root of image sources is reached (no further buildings)
if (pNode->m_sBuildingName != "")
if (pNode->m_sMeshModelName != "")
{
ConstructReflectionsPath(pNode->pParent, pReflectionAnchor, oPath, eCulling);
}
......@@ -226,7 +208,7 @@ int CSource::GetImageOrder() const
//===CImageNode====================================================================================================================================================
CSource::CImageNode::CImageNode(const int iOrder, const int iMaxOrder, const ITAGeo::Urban::CModel& oUrbanModel, CImageNode* pParent_ /* = nullptr */, const int iBuildingIndex /* = -1 */ )
CSource::CImageNode::CImageNode(const int iOrder, const int iMaxOrder, const ITAGeo::Halfedge::CMeshModelList& vpMeshModelList, CImageNode* pParent_ /* = nullptr */, const int iMeshIndex /* = -1 */ )
//CSourceEngine::CImageNode::CImageNode(const int iOrder, const int iBuildingIndex, CImageNode* pParent_ /* = nullptr */)
:pParent(pParent_)
{
......@@ -234,36 +216,36 @@ CSource::CImageNode::CImageNode(const int iOrder, const int iMaxOrder, const ITA
pImage->iOrder = iOrder;
//Set building name
if (iBuildingIndex >= 0)
m_sBuildingName = oUrbanModel.GetBuildingNames().at(iBuildingIndex);
if (iMeshIndex >= 0)
m_sMeshModelName = vpMeshModelList[iMeshIndex]->GetName();
else
m_sBuildingName = ""; //the root of the image sources is linked to no building
m_sMeshModelName = ""; //the root of the image sources is linked to no building
////Construct node tree
size_t numBuildings = oUrbanModel.GetNumBuildings();
size_t numMeshes = vpMeshModelList.size();
for (int it_building = 0; it_building < numBuildings; it_building++)
for (int it_mesh = 0; it_mesh < numMeshes; it_mesh++)
{
//Current building name
string sCurrentBuildingName = oUrbanModel.GetBuildingNames().at(it_building);
string sCurrentMeshModelName = vpMeshModelList[it_mesh]->GetName();
//Get number of faces of current building mesh
size_t iNumFaces = oUrbanModel.GetBuildings().at(it_building)->GetMesh()->pMesh->n_faces(); //@todo: Reason for long intialization. Change call of number of faces
size_t iNumFaces = vpMeshModelList[it_mesh]->GetMesh()->pMesh->n_faces(); //@todo: Reason for long intialization. Change call of number of faces
if (iOrder < iMaxOrder)
{
if (iOrder == ITAGeo::ORDER_0 || it_building != iBuildingIndex )
if (iOrder == ITAGeo::ORDER_0 || it_mesh != iMeshIndex )
{
for (int i = 0; i < iNumFaces; i++)
mpImageChildren[sCurrentBuildingName].push_back(new CImageNode(iOrder + 1, iMaxOrder, oUrbanModel, this, it_building));
mpImageChildren[sCurrentMeshModelName].push_back(new CImageNode(iOrder + 1, iMaxOrder, vpMeshModelList, this, it_mesh));
}
else
{
// After first order we only create one image less because there is no image from the same face as parent
for (int i = 0; i < iNumFaces - 1; i++)
mpImageChildren[sCurrentBuildingName].push_back(new CImageNode(iOrder + 1, iMaxOrder, oUrbanModel, this, it_building));
mpImageChildren[sCurrentMeshModelName].push_back(new CImageNode(iOrder + 1, iMaxOrder, vpMeshModelList, this, it_mesh));
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment