Adding feature that puts visualization content into specified SketchUp layers

parent 9dc463df
......@@ -25,6 +25,7 @@
#include <ITAGeoHalfedgeMeshModel.h>
// STL includes
#include <map>
#include <string>
#include <vector>
......@@ -93,12 +94,15 @@ namespace ITAGeo
//! Add propagation path visualization (that will be drawn if model is stored)
/**
* @note Uses pointers to propagation anchors.
* @param[in] oPath Propagation anchor list
* @param[in] sLayerName SketchUp layer name (new or existing)
*
* @todo Add visualization as layers
*/
void AddPropagationPathVisualization( const ITAGeo::CPropagationPath& oPath, std::string sName );
void AddPropagationPathVisualization( const ITAGeo::CPropagationPath& oPath, const std::string& sLayerName = "Layer0" );
//! Add a visualization mesh
void AddVisualizationMesh( const ITAGeo::CHalfedgeMeshModel* pVisMesh );
void AddVisualizationMesh( const ITAGeo::CHalfedgeMeshModel* pVisMesh, const std::string& sLayerName = "Layer0" );
//! Triangulate all meshes in model
bool TriangulateMeshes();
......@@ -128,8 +132,8 @@ namespace ITAGeo
std::vector< CHalfedgeMeshModelComponentDefinition > m_voMeshComponentDefinitions; //!< Halfedge mesh models from top-level component definitions (exploded)
std::vector< CHalfedgeMeshModelComponentInstance > m_voMeshComponentInstances; //!< Halfedge mesh models from top-level component instances (pointer and transform matrix)
std::vector< ITAGeo::CPropagationPath > m_voGeoPropPathsVisualization; //!< Propagation paths for visualization of acoustic effects (never populated in Load() method)
std::vector< const ITAGeo::CHalfedgeMeshModel* > m_vpAcousticVisualizationMeshes; //!< Mesh list with extra visualization data
std::map< std::string, std::vector< ITAGeo::CPropagationPath > > m_mGeoPropPathsVisualization; //!< Propagation paths for visualization of acoustic effects (never populated in Load() method)
std::map< std::string, std::vector< const ITAGeo::CHalfedgeMeshModel* > > m_mAcousticVisualizationMeshes; //!< Mesh list with extra visualization data
std::vector< std::string > m_vsLayers; //!< Layer names (also unused layers)
......
......@@ -91,7 +91,7 @@ bool ITAGeo::CSketchUpModel::Load( const std::string& sSKPFilePath )
int iSUVersionMajor, iSUVersionMinor, iBuild;
SU_EXC( SUModelGetVersion( rModel, &iSUVersionMajor, &iSUVersionMinor, &iBuild ) );
SUStringRef rModelName = SU_INVALID;
SU_EXC( SUStringCreate( &rModelName ) );
SU_EXC( SUModelGetName( rModel, &rModelName ) );
......@@ -379,77 +379,82 @@ bool ITAGeo::CSketchUpModel::Store( const std::string& sSKPFilePath, bool bOverw
// Add visualization meshes (with individual layers)
for( size_t n = 0; n < m_vpAcousticVisualizationMeshes.size(); n++ )
for( auto key : m_mAcousticVisualizationMeshes )
{
const CHalfedgeMeshModel* pHMM( m_vpAcousticVisualizationMeshes[ n ] );
std::string sVisMeshLayerSuffix = "default";
if( pHMM->GetName().empty() == false )
sVisMeshLayerSuffix = pHMM->GetName();
const std::string& sVisLayerName( key.first );
std::vector< const CHalfedgeMeshModel* > vpHMM( key.second );
SULayerRef rVisLayer = SU_INVALID;
std::string sVisLayerName = "ITA_Vis_" + sVisMeshLayerSuffix;
SU_EXC( SULayerCreate( &rVisLayer ) );
SU_EXC( SULayerSetName( rVisLayer, sVisLayerName.c_str() ) );
SU_EXC( SUModelAddLayers( rModel, 1, &rVisLayer ) );
for( size_t n = 0; n < vpHMM.size(); n++ )
{
const CHalfedgeMeshModel* pHMM( vpHMM[ n ] );
SULayerRef rVisLayer = SU_INVALID;
SU_EXC( SULayerCreate( &rVisLayer ) );
SU_EXC( SULayerSetName( rVisLayer, sVisLayerName.c_str() ) );
SU_EXC( SUModelAddLayers( rModel, 1, &rVisLayer ) );
CITAMesh* pVisMesh = pHMM->GetMesh()->pTopLevelMesh;
SU_EXC( ITAMeshToSUEntities( pVisMesh, &rEntities, &rVisLayer ) );
CITAMesh* pVisMesh = pHMM->GetMesh()->pTopLevelMesh;
SU_EXC( ITAMeshToSUEntities( pVisMesh, &rEntities, &rVisLayer ) );
}
}
// Propagation path visualization
SULayerRef rPropLayer = SU_INVALID;
std::string sPropLayerName = "ITA_Acoustics_PropagationPaths";
SU_EXC( SULayerCreate( &rPropLayer ) );
SU_EXC( SULayerSetName( rPropLayer, sPropLayerName.c_str() ) );
SU_EXC( SUModelAddLayers( rModel, 1, &rPropLayer ) );
SUMaterialRef rMaterial = SU_INVALID;
SU_EXC( SUMaterialCreate( &rMaterial ) );
SUColor oSUColor;
oSUColor.red = SUByte( 255.0f );
oSUColor.green = SUByte( 0.0f );
oSUColor.blue = SUByte( 0.0f );
SU_EXC( SUMaterialSetColor( rMaterial, &oSUColor ) );
SUMaterialSetName( rMaterial, "ITA_Acoustics_DefaultPropagationPath" );
SUModelAddMaterials( rModel, 1, &rMaterial );
std::vector< SUCurveRef > vrCurves( m_voGeoPropPathsVisualization.size() );
for( size_t n = 0; n < m_voGeoPropPathsVisualization.size(); n++ )
for( auto key : m_mGeoPropPathsVisualization )
{
const CPropagationPath& oPath( m_voGeoPropPathsVisualization[ n ] );
std::vector< ITAGeo::CPropagationPath > voGeoPropPathsVisualization( key.second );
// Propagation path visualization
SULayerRef rPropLayer = SU_INVALID;
const std::string& sPropLayerName( key.first );
SU_EXC( SULayerCreate( &rPropLayer ) );
SU_EXC( SULayerSetName( rPropLayer, sPropLayerName.c_str() ) );
SU_EXC( SUModelAddLayers( rModel, 1, &rPropLayer ) );
SUMaterialRef rMaterial = SU_INVALID;
SU_EXC( SUMaterialCreate( &rMaterial ) );
SUColor oSUColor;
oSUColor.red = SUByte( 255.0f );
oSUColor.green = SUByte( 0.0f );
oSUColor.blue = SUByte( 0.0f );
SU_EXC( SUMaterialSetColor( rMaterial, &oSUColor ) );
SUMaterialSetName( rMaterial, "ITA_Acoustics_DefaultPropagationPath" );
SUModelAddMaterials( rModel, 1, &rMaterial );
std::vector< SUCurveRef > vrCurves( voGeoPropPathsVisualization.size() );
for( size_t n = 0; n < voGeoPropPathsVisualization.size(); n++ )
{
const CPropagationPath& oPath( voGeoPropPathsVisualization[ n ] );
if( oPath.size() <= 1 )
continue;
if( oPath.size() <= 1 )
continue;
std::vector< SUEdgeRef > vrEdges( oPath.size() - 1 );
for( size_t m = 0; m < vrEdges.size(); m++ )
{
auto pSourceAnchor( oPath[ m ] );
auto 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." );
std::vector< SUEdgeRef > vrEdges( oPath.size() - 1 );
for( size_t m = 0; m < vrEdges.size(); m++ )
{
auto pSourceAnchor( oPath[ m ] );
auto pTargetAnchor( oPath[ m + 1 ] );
SUPoint3D v3SUStart = VistaVectorToSUPoint( pSourceAnchor->v3InteractionPoint );
SUPoint3D v3SUEnd = VistaVectorToSUPoint( pTargetAnchor->v3InteractionPoint );
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." );
SU_EXC( SUEdgeCreate( &vrEdges[ m ], &v3SUStart, &v3SUEnd ) );
SUPoint3D v3SUStart = VistaVectorToSUPoint( pSourceAnchor->v3InteractionPoint );
SUPoint3D v3SUEnd = VistaVectorToSUPoint( pTargetAnchor->v3InteractionPoint );
SUDrawingElementRef rDrawingElement = SUEdgeToDrawingElement( vrEdges[ m ] );
SU_EXC( SUDrawingElementSetMaterial( rDrawingElement, rMaterial ) );
SU_EXC( SUDrawingElementSetLayer( rDrawingElement, rPropLayer ) );
}
SU_EXC( SUCurveCreateWithEdges( &vrCurves[ n ], &vrEdges[ 0 ], vrEdges.size() ) );
SU_EXC( SUEdgeCreate( &vrEdges[ m ], &v3SUStart, &v3SUEnd ) );
}
SUDrawingElementRef rDrawingElement = SUEdgeToDrawingElement( vrEdges[ m ] );
SU_EXC( SUDrawingElementSetMaterial( rDrawingElement, rMaterial ) );
SU_EXC( SUDrawingElementSetLayer( rDrawingElement, rPropLayer ) );
}
SU_EXC( SUCurveCreateWithEdges( &vrCurves[ n ], &vrEdges[ 0 ], vrEdges.size() ) );
if( vrCurves.size() > 0 )
SU_EXC( SUEntitiesAddCurves( rEntities, vrCurves.size(), &vrCurves[ 0 ] ) );
}
if( vrCurves.size() > 0 )
SU_EXC( SUEntitiesAddCurves( rEntities, vrCurves.size(), &vrCurves[ 0 ] ) );
}
// Store to file
......@@ -542,14 +547,17 @@ bool ITAGeo::CSketchUpModel::AddLayer( std::string& sLayerName )
return true;
}
void ITAGeo::CSketchUpModel::AddPropagationPathVisualization( const CPropagationPath& oPath, std::string sName )
void ITAGeo::CSketchUpModel::AddPropagationPathVisualization( const CPropagationPath& oPath, const std::string& sLayerName /* = "Layer0" */ )
{
m_voGeoPropPathsVisualization.push_back( oPath );
if( sLayerName.empty() )
ITA_EXCEPT_INVALID_PARAMETER( "Layer name can't be empty" );
m_mGeoPropPathsVisualization[ sLayerName ].push_back( oPath );
}
void ITAGeo::CSketchUpModel::AddVisualizationMesh( const CHalfedgeMeshModel* pVisMesh )
void ITAGeo::CSketchUpModel::AddVisualizationMesh( const CHalfedgeMeshModel* pVisMesh, const std::string& sLayerName /* = "Layer0" */ )
{
m_vpAcousticVisualizationMeshes.push_back( pVisMesh );
m_mAcousticVisualizationMeshes[ sLayerName ].push_back( pVisMesh );
}
bool ITAGeo::CSketchUpModel::TriangulateMeshes()
......
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