Adding axis aligned bounding box and bounding sphere support for halfedge mesh model

parent 8de2fa5f
......@@ -108,6 +108,18 @@ namespace ITAGeo
std::complex< double > cdTransmissionFactor; //! Complex-valued transmission factor [0..1]
std::complex< double > cdScatteringCoefficient; //! Complex-valued scattering coefficient [0..1]
inline CScalarMaterial()
{
SetDefaults();
};
inline CScalarMaterial( const std::complex< double >& cdR, const std::complex< double >& cdT, const std::complex< double >& cdS )
: cdReflectionFactor( cdR )
, cdTransmissionFactor( cdT )
, cdScatteringCoefficient( cdS )
{
};
inline ~CScalarMaterial() {};
inline std::string GetIdentifier() const
......
......@@ -152,6 +152,27 @@ namespace ITAGeo
//! Returns bounding box min and max point
void GetBoundingBoxAxesAligned( VistaVector3D& v3Min, VistaVector3D& v3Max ) const;
//! Returns bounding sphere centroid and radius
/**
* @param[out] v3Centroid Sphere center
* @param[out] fRadius Sphere radius in meter
*/
void GetBoundingSphere( VistaVector3D& v3Centroid, float& fRadius ) const;
VistaVector3D GetBarycenter() const;
//! Returns true, if position is within axis-aligned bounding box
bool GetInsideBoundingBoxAxesAligned( const VistaVector3D& v3Pos ) const;
//! Returns true, if position is within axis-aligned bounding box
/**
* @param[in] v3Pos Position to be tested
* @note This function is slow because it has to create the bounding sphere. Consider own implementation
*
*/
bool GetInsideBoundingSphere( const VistaVector3D& v3Pos ) const;
protected:
CITAMeshPtr* m_prModelMeshData; // CITAMesh pointer
......
......@@ -246,6 +246,67 @@ void ITAGeo::CHalfedgeMeshModel::GetBoundingBoxAxesAligned( VistaVector3D& v3Min
}
}
void ITAGeo::CHalfedgeMeshModel::GetBoundingSphere( VistaVector3D& v3Centroid, float& fRadius ) const
{
CITAMesh* pMesh = static_cast< CITAMesh* >( m_prModelMeshData->pTopLevelMesh );
v3Centroid = GetBarycenter();
fRadius = 0.0f;
CITAMesh::VertexIter v_it = pMesh->vertices_begin();
while( v_it != pMesh->vertices_end() )
{
CITAMesh::VertexHandle hVertex( *v_it++ );
VistaVector3D v3VertexPointOuter( pMesh->point( hVertex ).data() );
const float fDistance = ( v3VertexPointOuter - v3Centroid ).GetLength();
if( fDistance > fRadius )
fRadius = fDistance;
}
}
VistaVector3D ITAGeo::CHalfedgeMeshModel::GetBarycenter() const
{
VistaVector3D v3Barycenter( 0.0f, 0.0f, 0.0f );
CITAMesh* pMesh = static_cast< CITAMesh* >( m_prModelMeshData->pTopLevelMesh );
if( pMesh->n_vertices() == 0 )
return v3Barycenter;
CITAMesh::VertexIter v_it = pMesh->vertices_begin();
while( v_it != pMesh->vertices_end() )
{
CITAMesh::VertexHandle hVertex( *v_it++ );
VistaVector3D v3VertexPoint( pMesh->point( hVertex ).data() );
v3Barycenter += v3VertexPoint;
}
return v3Barycenter / float( pMesh->n_vertices() );
}
bool ITAGeo::CHalfedgeMeshModel::GetInsideBoundingBoxAxesAligned( const VistaVector3D& v3Pos ) const
{
VistaVector3D v3Min, v3Max;
GetBoundingBoxAxesAligned( v3Min, v3Max );
if( ( v3Pos[ Vista::X ] < v3Min[ Vista::X ] ) || ( v3Pos[ Vista::X ] > v3Max[ Vista::X ] ) )
return false;
if( ( v3Pos[ Vista::Y ] < v3Min[ Vista::Y ] ) || ( v3Pos[ Vista::Y ] > v3Max[ Vista::Y ] ) )
return false;
if( ( v3Pos[ Vista::Z ] < v3Min[ Vista::Z ] ) || ( v3Pos[ Vista::Z ] > v3Max[ Vista::Z ] ) )
return false;
return true;
}
bool ITAGeo::CHalfedgeMeshModel::GetInsideBoundingSphere( const VistaVector3D& v3Pos ) const
{
VistaVector3D v3Centroid;
float fRadius = 0.0f;
GetBoundingSphere( v3Centroid, fRadius );
return bool( ( v3Centroid - v3Pos ).GetLength() < fRadius );
}
CITAMeshPtr* ITAGeo::CHalfedgeMeshModel::GetMesh()
{
return m_prModelMeshData;
......
......@@ -22,12 +22,12 @@ ITAGeo::CMaterialManager::~CMaterialManager()
}
bool ITAGeo::CMaterialManager::HasMaterial( const std::string& sMaterialIdentifier ) const
{
return ( GetMaterial( sMaterialIdentifier ) != nullptr );
}
// Material directory
struct CMATFileMaterial
......@@ -50,7 +50,6 @@ ITAGeo::CMaterialDirectory::CMaterialDirectory( const std::string& sFolderPath,
VistaFileSystemDirectory d( sFolderPath );
if( d.Exists() && d.IsDirectory() )
AddMaterialsFromFolder( sFolderPath, bRecursive );
}
ITAGeo::CMaterialDirectory::~CMaterialDirectory()
......
......@@ -428,6 +428,12 @@ bool ITAGeo::CSketchUpModel::Store( const std::string& sSKPFilePath, bool bOverw
{
const CPropagationAnchor* pSourceAnchor( oPath[ m ] );
const CPropagationAnchor* pTargetAnchor( oPath[ m + 1 ] );
if( pSourceAnchor == pTargetAnchor )
ITA_EXCEPT_INVALID_PARAMETER( "A propagation path can not have the same anchors in a row." );
if( pSourceAnchor->v3InteractionPoint == pTargetAnchor->v3InteractionPoint )
ITA_EXCEPT_INVALID_PARAMETER( "Source and target anchor of propagation path have same interaction point." );
SUPoint3D v3SUStart = VistaVectorToSUPoint( pSourceAnchor->v3InteractionPoint );
SUPoint3D v3SUEnd = VistaVectorToSUPoint( pTargetAnchor->v3InteractionPoint );
......
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