Commit fb8e1e96 authored by Armin Erraji's avatar Armin Erraji

Added RTree implementation (not working yet)

parent 2b2589e8
......@@ -26,7 +26,7 @@ namespace ITAPropagationPathSim
ITA_PROPAGATION_PATH_SIM_API bool ConstructImageEdges(shared_ptr<const ITAGeo::CEmitter> pEmitter, vector<CPropagationShapeShared>& vpPropagationTree);
ITA_PROPAGATION_PATH_SIM_API bool ConstructImageEdges(vector<CPropagationShapeShared>& vpPropagationTree);
}
}
}
......
......@@ -3,6 +3,8 @@
#include<ITAPropagationPathSim/CombinedModel/PropagationShapes.h>
#include <ITAPropagationPathSim/CombinedModel/RTree.h>
// ITA includes
#include <ITAGeo/Base.h>
#include <ITAGeo/Halfedge/MeshModel.h>
......@@ -36,8 +38,11 @@ namespace ITAPropagationPathSim
void ApplyEmitter(shared_ptr<CEmitter> pEmitter);
//Just for testing, the ApplyEmitter is divided into two parts
void ApplyEmitterForTestingOnlyTreeAndImageEdges(shared_ptr<CEmitter> pEmitter);
void ApplyEmitterForTestingOnlyImageSources();
void ApplySensor(shared_ptr<CSensor> pSensor);
void ConstructPropagationPathsWithStopWatch(CPropagationPathList& oPaths);
void ConstructPropagationPaths(CPropagationPathList& oPaths);
......@@ -47,6 +52,8 @@ namespace ITAPropagationPathSim
private:
vector<CPropagationShapeShared> m_vpPropagationShapes; //!< Vector of all propagation shapes
CShapesTree m_ShapesTree;
shared_ptr<const ITAGeo::Halfedge::CMeshModelList> m_pMeshModelList; //!< Copy of propagation model list
CShapesMap m_mvpShapeVisibilityMap; //!< Map of which shape can illuminate which ones
vector<CPropagationShapeShared> m_vpPropagationTree; //!< Vector of all propagation shapes (as well as its children) visible to the emitter
......
......@@ -39,9 +39,13 @@ namespace ITAPropagationPathSim
void Create(const vector<CPropagationShapeShared>& vpShapesIn);
//TODO
bool IsLineSegmentIntersected(const VistaVector3D& oLineStart, const VistaVector3D& oLineEnd) const;
bool CanLineSegmentIntersect(const VistaVector3D& oLineStart, const VistaVector3D& oLineEnd, const CPropagationShapeShared & oShape) const;
bool CanLineSegmentIntersect(const VistaVector3D& oLineStart, const VistaVector3D& oLineEnd) const;
bool RecursiveIntersectionTest(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd, const CShapesTree & oTree, const CPropagationShapeShared & oShape) const;
bool RecursiveIntersectionTest(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd, const CShapesTree & oTree) const;
bool ContainsShape(const CPropagationShapeShared & oShape) const;
//TODO
//void GetNonIntersectedFaces(vector<CPropagationShapeShared>& vpFacesOut, const VistaVector3D& oLineStart, const VistaVector3D& oLineStart);
......
......@@ -279,7 +279,7 @@ namespace ITAPropagationPathSim
return true;
}
bool ConstructImageEdges(shared_ptr<const ITAGeo::CEmitter> pEmitter, vector<CPropagationShapeShared>& vpPropagationTree)
bool ConstructImageEdges(vector<CPropagationShapeShared>& vpPropagationTree)
{
//First element of tree has never an image edge, so only construct them for its children
for (auto& pShape : vpPropagationTree)
......
......@@ -7,6 +7,7 @@
#include <ITAStopWatch.h> //TODO:Delete, just for testing
#include <ITAStringUtils.h>
//Typedefs
typedef OpenMesh::PolyMesh_ArrayKernelT<> CITAMesh;
struct CITAMeshPtr
......@@ -86,6 +87,8 @@ void ITAPropagationPathSim::CombinedModel::CPathEngine::InitializePathEnvironmen
//Get all propagation shapes of the mesh model list
ConstructPropagationShapes();
m_ShapesTree.Create(m_vpPropagationShapes);
//Create a visibility map
CreateVisibilityMap();
}
......@@ -102,16 +105,34 @@ void ITAPropagationPathSim::CombinedModel::CPathEngine::ApplyEmitter(shared_ptr<
ImageConstruction::ConstructImageSources(m_pEmitter, m_vpPropagationTree);
//Construct image edges
ImageConstruction::ConstructImageEdges(m_pEmitter, m_vpPropagationTree);
ImageConstruction::ConstructImageEdges(m_vpPropagationTree);
//Following not working accurately
//Calculate accumulated angle and angle culling for tree
//Calculate accumulated angle and angle culling for tree (without knowing the exactly position)
//if (*m_pAccumulatedAngleThreshold > 0)
//{
// Diffraction::AccumulatedAngleCulling(*m_pAccumulatedAngleThreshold, m_pEmitter,m_vpPropagationTree, m_vpPropagationTree);
//}
}
void ITAPropagationPathSim::CombinedModel::CPathEngine::ApplyEmitterForTestingOnlyTreeAndImageEdges(shared_ptr<ITAGeo::CEmitter> pEmitter)
{
//Set emitter
m_pEmitter = pEmitter;
//Create propagation tree
CreatePropagationTree();
//Construct image edges
ImageConstruction::ConstructImageEdges(m_vpPropagationTree);
}
void ITAPropagationPathSim::CombinedModel::CPathEngine::ApplyEmitterForTestingOnlyImageSources()
{
//Construct image sources
ImageConstruction::ConstructImageSources(m_pEmitter, m_vpPropagationTree);
}
size_t ITAPropagationPathSim::CombinedModel::CPathEngine::GetNumberPropagationPathCandidates()
{
if(m_vpPropagationCandidates.size() > 0)
......@@ -1028,6 +1049,10 @@ bool ITAPropagationPathSim::CombinedModel::CPathEngine::CanPointIlluminateEdge(c
bool ITAPropagationPathSim::CombinedModel::CPathEngine::IsPathVisible(const VistaVector3D& v3StartPoint, const VistaVector3D& v3EndPoint)
{
//Search of intersections on bounding boxes
if (!m_ShapesTree.CanLineSegmentIntersect(v3StartPoint, v3EndPoint)) return true;
//Search for intersections between two neighbored anchors and repeat it for all neighbored anchors of the path
//Iterate intersection search over all mesh models
......
......@@ -41,9 +41,9 @@ void CShapesTree::CreateBranches()
vvpBranchShapes.resize(8);
//Points, where branches are sub-divided into. Mid points between max and min.
float fSubDivideX = m_v3TreeMin[Vista::X] + m_v3TreeMax[Vista::X] / 2.0f;
float fSubDivideY = m_v3TreeMin[Vista::Y] + m_v3TreeMax[Vista::Y] / 2.0f;
float fSubDivideZ = m_v3TreeMin[Vista::Z] + m_v3TreeMax[Vista::Z] / 2.0f;
float fSubDivideX = (m_v3TreeMin[0] + m_v3TreeMax[0]) / 2.0f;
float fSubDivideY = (m_v3TreeMin[1] + m_v3TreeMax[1]) / 2.0f;
float fSubDivideZ = (m_v3TreeMin[2] + m_v3TreeMax[2]) / 2.0f;
//Add building to branchbuildings vector according to its location
for (auto &pShape : m_vpShapes)
......@@ -103,17 +103,18 @@ void CShapesTree::CreateBranches()
}
}
//For each subdivided building vector, create a branch
//For each subdivided building vector, create a branch. Create no further branch, if only one vvpBranchShapes vector exists
if(vvpBranchShapes.size() > 1)
for (auto &vpShapesCurrentBranch : vvpBranchShapes)
{
if (vpShapesCurrentBranch.size() > 0)
{
auto pBranch = make_shared< CShapesTree>();
pBranch->Create(vpShapesCurrentBranch);
m_vpBranches.push_back(pBranch);
if (vpShapesCurrentBranch.size() > 0)
{
auto pBranch = make_shared< CShapesTree>();
pBranch->Create(vpShapesCurrentBranch);
m_vpBranches.push_back(pBranch);
}
}
}
}
void CShapesTree::SetVertices()
......@@ -140,23 +141,137 @@ void CShapesTree::SetVertices()
// ---Test function----------------------------------------------------------------------------------------------
bool CShapesTree::IsLineSegmentIntersected(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd) const
bool CShapesTree::CanLineSegmentIntersect(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd, const CPropagationShapeShared & pShape) const
{
//Compute intersection test with bounding box. if if intersectes, further test lower branches for intersections
return RecursiveIntersectionTest(oLineStart, oLineEnd, *this, pShape);
}
bool CShapesTree::CanLineSegmentIntersect(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd) const
{
//Compute intersection test with bounding box. if if intersectes, further test lower branches for intersections
return RecursiveIntersectionTest(oLineStart, oLineEnd, *this);
}
//if (oLineStart.x < m_v3TreeMin.x && oLineEnd.x < m_v3TreeMin.x) return false;
//if (oLineStart.x > m_v3TreeMax.x && oLineEnd.x > m_v3TreeMax.x) return false;
//if (oLineStart.y < m_v3TreeMin.y && m_v3TreeMin.y < B1.y) return false;
//if (oLineStart.y > m_v3TreeMax.y && oLineEnd.y > m_v3TreeMax.y) return false;
//if (oLineStart.z < m_v3TreeMin.z && oLineEnd.z < m_v3TreeMin.z) return false;
//if (oLineStart.z > m_v3TreeMax.z && oLineEnd.z > m_v3TreeMax.z) return false;
bool CShapesTree::RecursiveIntersectionTest(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd, const CShapesTree& oTree, const CPropagationShapeShared & pShape) const
{
if (!oTree.ContainsShape(pShape))
return false;
VistaVector3D v3Origin = oLineStart;
VistaVector3D v3Dir = (oLineEnd - oLineStart).GetNormalized();
//Iersection test with the bounding box. Only if line intersects the box, test its branch
//https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection
float tmin = (oTree.m_v3TreeMin[0] - v3Origin[0]) / v3Dir[0];
float tmax = (oTree.m_v3TreeMax[0] - v3Origin[0]) / v3Dir[0];
if (tmin > tmax) swap(tmin, tmax);
float tymin = (oTree.m_v3TreeMin[1] - v3Origin[1]) / v3Dir[1];
float tymax = (oTree.m_v3TreeMax[1] - v3Origin[1]) / v3Dir[1];
if (tymin > tymax) swap(tymin, tymax);
if ((tmin > tymax) || (tymin > tmax))
return false;
if (tymin > tmin)
tmin = tymin;
if (tymax < tmax)
tmax = tymax;
float tzmin = (oTree.m_v3TreeMin[2] - v3Origin[2]) / v3Dir[2];
float tzmax = (oTree.m_v3TreeMax[2] - v3Origin[2]) / v3Dir[2];
if (tzmin > tzmax) swap(tzmin, tzmax);
if ((tmin > tzmax) || (tzmin > tmax))
return false;
if (tzmin > tmin)
tmin = tzmin;
if (tzmax < tmax)
tmax = tzmax;
//Intersection test with children
bool bIntersectsChild = false;
for (auto& pChild : oTree.m_vpBranches)
{
bIntersectsChild |= RecursiveIntersectionTest(oLineStart, oLineEnd, *pChild,pShape);
}
return bIntersectsChild;
}
bool CShapesTree::RecursiveIntersectionTest(const VistaVector3D & oLineStart, const VistaVector3D & oLineEnd, const CShapesTree& oTree) const
{
VistaVector3D v3Origin = oLineStart;
VistaVector3D v3Dir = (oLineEnd - oLineStart).GetNormalized();
//Iersection test with the bounding box. Only if line intersects the box, test its branch
//https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection
float tmin = (oTree.m_v3TreeMin[0] - v3Origin[0]) / v3Dir[0];
float tmax = (oTree.m_v3TreeMax[0] - v3Origin[0]) / v3Dir[0];
if (tmin > tmax) swap(tmin, tmax);
float tymin = (oTree.m_v3TreeMin[1] - v3Origin[1]) / v3Dir[1];
float tymax = (oTree.m_v3TreeMax[1] - v3Origin[1]) / v3Dir[1];
if (tymin > tymax) swap(tymin, tymax);
if ((tmin > tymax) || (tymin > tmax))
return false;
if (tymin > tmin)
tmin = tymin;
if (tymax < tmax)
tmax = tymax;
float tzmin = (oTree.m_v3TreeMin[2] - v3Origin[2]) / v3Dir[2];
float tzmax = (oTree.m_v3TreeMax[2] - v3Origin[2]) / v3Dir[2];
if (tzmin > tzmax) swap(tzmin, tzmax);
if ((tmin > tzmax) || (tzmin > tmax))
return false;
if (tzmin > tmin)
tmin = tzmin;
if (tzmax < tmax)
tmax = tzmax;
//Intersection test with children
bool bIntersectsChild = false;
for (auto& pChild : oTree.m_vpBranches)
{
bIntersectsChild |= RecursiveIntersectionTest(oLineStart, oLineEnd, *pChild);
}
return bIntersectsChild;
return false;
}
bool ITAPropagationPathSim::CombinedModel::CShapesTree::ContainsShape(const CPropagationShapeShared& pShapeIn) const
{
for (auto& pTreeShape : m_vpShapes)
{
if (pTreeShape->GetIdentifier() == pShapeIn->GetIdentifier())
return true;
}
return false;
}
This diff is collapsed.
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