Skip to content

Commit a70e5d1

Browse files
committed
add support for colors, that are defined on the IfcElement level, instead of item level
1 parent fc44916 commit a70e5d1

File tree

9 files changed

+496
-146
lines changed

9 files changed

+496
-146
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ examples/SimpleViewerExampleMFC/.vs/IfcQueryViewer/v15/.suo
3535
examples/SimpleViewerExampleMFC/.vs/SimpleViewerExampleMFC/v15/.suo
3636
examples/CreateWallAndWriteFile/CreateWallAndWriteFile/x64/
3737
examples/CreateWallAndWriteFile/CreateWallAndWriteFile/SimpleWall.ifc
38-
examples/LoadFileExampleNoGUI/LoadFileExampleNoGUI/x64/
39-
40-
*.db-wal
41-
*.db-shm
4238
examples/CreateWallAndWriteFile/SimpleWall.ifc
39+
examples/LoadFileExampleNoGUI/LoadFileExampleNoGUI/x64/
40+
external/Carve/build/

IfcPlusPlus/src/ifcpp/geometry/Carve/ConverterOSG.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ class ConverterOSG : public StatusCallback
722722
bool draw_bounding_box = false;
723723
double crease_angle = m_geom_settings->getCoplanarFacesMaxDeltaAngle();
724724
double min_triangle_area = m_geom_settings->getMinTriangleArea();
725+
std::vector<osg::ref_ptr<osg::Switch> > vec_current_switches;
725726

726727
// create OSG objects
727728
std::vector<shared_ptr<RepresentationData> >& vec_product_representations = product_shape->m_vec_representations;
@@ -976,10 +977,18 @@ class ConverterOSG : public StatusCallback
976977
}
977978

978979
map_representation_switches.insert( std::make_pair( representation_id, representation_switch ) );
980+
vec_current_switches.push_back(representation_switch);
979981
}
980982
}
981983

982984
// TODO: if no color or material is given, set color 231/219/169 for walls, 140/140/140 for slabs
985+
if (product_shape->m_vec_product_appearances.size() > 0)
986+
{
987+
for (auto representation_switch : vec_current_switches)
988+
{
989+
applyAppearancesToGroup(product_shape->m_vec_product_appearances, representation_switch);
990+
}
991+
}
983992
}
984993

985994
/*\brief method convertToOSG: Creates geometry for OpenSceneGraph from given ProductShapeData.
@@ -1058,7 +1067,7 @@ class ConverterOSG : public StatusCallback
10581067
{
10591068
continue;
10601069
}
1061-
1070+
10621071
const int product_id = ifc_product->m_entity_id;
10631072
std::string product_guid;
10641073
std::map<int, osg::ref_ptr<osg::Switch> > map_representation_switches;

IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryConverter.h

Lines changed: 145 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU
2828
#include <ifcpp/IFC4/include/IfcRelAggregates.h>
2929
#include <ifcpp/IFC4/include/IfcRelContainedInSpatialStructure.h>
3030
#include <ifcpp/IFC4/include/IfcRelDefinesByProperties.h>
31+
#include <ifcpp/IFC4/include/IfcSite.h>
3132
#include <ifcpp/IFC4/include/IfcSpace.h>
3233
#include <ifcpp/IFC4/include/IfcWindow.h>
3334

@@ -94,7 +95,7 @@ class GeometryConverter : public StatusCallback
9495
{
9596
m_product_shape_data.clear();
9697
m_map_outside_spatial_structure.clear();
97-
m_representation_converter->clearCache(false);
98+
m_representation_converter->clearCache();
9899
m_messages.clear();
99100
}
100101

@@ -116,7 +117,7 @@ class GeometryConverter : public StatusCallback
116117
}
117118
clearInputCache();
118119
m_ifc_model = model;
119-
m_representation_converter->clearCache(false);
120+
m_representation_converter->clearCache();
120121
m_representation_converter->setUnitConverter( m_ifc_model->getUnitConverter() );
121122
m_ifc_model->setMessageTarget( this );
122123
}
@@ -289,6 +290,66 @@ class GeometryConverter : public StatusCallback
289290
}
290291
}
291292

293+
void resetIfcSiteLargeCoords(shared_ptr<IfcSite>& ifc_site)
294+
{
295+
if (!ifc_site)
296+
{
297+
return;
298+
}
299+
300+
if (!ifc_site->m_ObjectPlacement)
301+
{
302+
return;
303+
}
304+
305+
shared_ptr<IfcLocalPlacement> local_placement = dynamic_pointer_cast<IfcLocalPlacement>(ifc_site->m_ObjectPlacement);
306+
if (!local_placement)
307+
{
308+
return;
309+
}
310+
311+
if (local_placement->m_RelativePlacement)
312+
{
313+
shared_ptr<IfcAxis2Placement3D> axis_placement = dynamic_pointer_cast<IfcAxis2Placement3D>(local_placement->m_RelativePlacement);
314+
if (axis_placement)
315+
{
316+
if (axis_placement->m_Location)
317+
{
318+
shared_ptr<IfcCartesianPoint> placement_location = dynamic_pointer_cast<IfcCartesianPoint>(axis_placement->m_Location);
319+
if (placement_location)
320+
{
321+
if (placement_location->m_Coordinates.size() > 2)
322+
{
323+
if (placement_location->m_Coordinates[0])
324+
{
325+
if (placement_location->m_Coordinates[0]->m_value > 1000)
326+
{
327+
placement_location->m_Coordinates[0]->m_value = 0;
328+
}
329+
}
330+
331+
if (placement_location->m_Coordinates[1])
332+
{
333+
if (placement_location->m_Coordinates[1]->m_value > 1000)
334+
{
335+
placement_location->m_Coordinates[1]->m_value = 0;
336+
}
337+
}
338+
339+
if (placement_location->m_Coordinates[2])
340+
{
341+
if (placement_location->m_Coordinates[2]->m_value > 1000)
342+
{
343+
placement_location->m_Coordinates[2]->m_value = 0;
344+
}
345+
}
346+
}
347+
}
348+
}
349+
}
350+
}
351+
}
352+
292353
/*\brief method convertGeometry: Creates geometry for Carve from previously loaded BuildingModel model.
293354
**/
294355
void convertGeometry()
@@ -297,7 +358,7 @@ class GeometryConverter : public StatusCallback
297358
progressValueCallback( 0, "geometry" );
298359
m_product_shape_data.clear();
299360
m_map_outside_spatial_structure.clear();
300-
m_representation_converter->clearCache(false);
361+
m_representation_converter->clearCache();
301362

302363
if( !m_ifc_model )
303364
{
@@ -325,6 +386,12 @@ class GeometryConverter : public StatusCallback
325386
if (object_def)
326387
{
327388
vec_object_definitions.push_back(object_def);
389+
390+
shared_ptr<IfcSite> ifc_site = dynamic_pointer_cast<IfcSite>(object_def);
391+
if (ifc_site)
392+
{
393+
resetIfcSiteLargeCoords(ifc_site);
394+
}
328395
}
329396
}
330397
}
@@ -520,6 +587,23 @@ class GeometryConverter : public StatusCallback
520587
progressValueCallback( 1.0, "geometry" );
521588
}
522589

590+
void addVector3D(const vec3& point, std::vector<float>& target_array)
591+
{
592+
bool m_roundCoords = false;
593+
if (m_roundCoords)
594+
{
595+
target_array.push_back(round(point.x*10000)*0.0001);
596+
target_array.push_back(round(point.y*10000)*0.0001);
597+
target_array.push_back(round(point.z*10000)*0.0001);
598+
}
599+
else
600+
{
601+
target_array.push_back(point.x);
602+
target_array.push_back(point.y);
603+
target_array.push_back(point.z);
604+
}
605+
}
606+
523607
//\brief method convertIfcProduct: Creates geometry objects (meshset with connected vertex-edge-face graph) from an IfcProduct object
524608
// caution: when using OpenMP, this method runs in parallel threads, so every write access to member variables needs a write lock
525609
void convertIfcProductShape( shared_ptr<ProductShapeData>& product_shape )
@@ -535,21 +619,21 @@ class GeometryConverter : public StatusCallback
535619
{
536620
return;
537621
}
538-
539-
if( !ifc_product->m_Representation )
540-
{
541-
return;
542-
}
543-
622+
544623
double length_factor = 1.0;
545-
if( m_ifc_model )
624+
if (m_ifc_model)
546625
{
547-
if( m_ifc_model->getUnitConverter() )
626+
if (m_ifc_model->getUnitConverter())
548627
{
549628
length_factor = m_ifc_model->getUnitConverter()->getLengthInMeterFactor();
550629
}
551630
}
552631

632+
if( !ifc_product->m_Representation )
633+
{
634+
return;
635+
}
636+
553637
// evaluate IFC geometry
554638
shared_ptr<IfcProductRepresentation>& product_representation = ifc_product->m_Representation;
555639
std::vector<shared_ptr<IfcRepresentation> >& vec_representations = product_representation->m_Representations;
@@ -591,12 +675,21 @@ class GeometryConverter : public StatusCallback
591675
m_representation_converter->getPlacementConverter()->convertIfcObjectPlacement( ifc_product->m_ObjectPlacement, product_shape, placement_already_applied, false );
592676
}
593677

594-
// handle openings
678+
595679
std::vector<shared_ptr<ProductShapeData> > vec_opening_data;
596680
const shared_ptr<IfcElement> ifc_element = dynamic_pointer_cast<IfcElement>(ifc_product);
597681
if( ifc_element )
598682
{
683+
// handle openings
599684
m_representation_converter->subtractOpenings(ifc_element, product_shape);
685+
686+
// handle styles on IfcElement level
687+
std::vector<shared_ptr<AppearanceData> > vec_apperances;
688+
StylesConverter::convertElementStyle(ifc_element, vec_apperances);
689+
for (auto appearance_data : vec_apperances)
690+
{
691+
product_shape->addAppearance(appearance_data);
692+
}
600693
}
601694

602695
// Fetch the IFCProduct relationships
@@ -645,6 +738,46 @@ class GeometryConverter : public StatusCallback
645738
}
646739
}
647740

741+
bool hasRelatedOpenings(shared_ptr<ProductShapeData>& product_shape)
742+
{
743+
if (product_shape->m_ifc_object_definition.expired())
744+
{
745+
return false;
746+
}
747+
748+
shared_ptr<IfcObjectDefinition> ifc_object_def(product_shape->m_ifc_object_definition);
749+
shared_ptr<IfcProduct> ifc_product = dynamic_pointer_cast<IfcProduct>(ifc_object_def);
750+
if (!ifc_product)
751+
{
752+
return false;
753+
}
754+
755+
shared_ptr<IfcElement> ifc_element = dynamic_pointer_cast<IfcElement>(ifc_product);
756+
if (!ifc_element)
757+
{
758+
return false;
759+
}
760+
761+
if (ifc_element->m_HasOpenings_inverse.size() == 0)
762+
{
763+
return false;
764+
}
765+
766+
// collect aggregated objects
767+
const std::vector<weak_ptr<IfcRelAggregates> >& vec_decomposed_by = ifc_object_def->m_IsDecomposedBy_inverse;
768+
if (vec_decomposed_by.size() > 0)
769+
{
770+
return true;
771+
}
772+
773+
const std::vector<weak_ptr<IfcRelAggregates> >& vec_decomposes = ifc_object_def->m_Decomposes_inverse;
774+
if (vec_decomposes.size() > 0)
775+
{
776+
return true;
777+
}
778+
return false;
779+
}
780+
648781
void subtractOpeningsInRelatedObjects(shared_ptr<ProductShapeData>& product_shape)
649782
{
650783
if( product_shape->m_ifc_object_definition.expired() )

IfcPlusPlus/src/ifcpp/geometry/Carve/GeometryInputData.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,9 @@ class ProductShapeData
562562
bool m_added_to_spatial_structure = false;
563563
weak_ptr<ProductShapeData> m_parent;
564564
std::vector<shared_ptr<TransformData> > m_vec_transforms;
565-
566-
protected:
567565
std::vector<shared_ptr<ProductShapeData> > m_vec_children;
568566
std::vector<shared_ptr<AppearanceData> > m_vec_product_appearances;
569567

570-
public:
571568
ProductShapeData() {}
572569
ProductShapeData( std::wstring entity_guid ) : m_entity_guid(entity_guid) { }
573570

IfcPlusPlus/src/ifcpp/geometry/Carve/RepresentationConverter.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,13 @@ class RepresentationConverter : public StatusCallback
113113

114114
virtual ~RepresentationConverter()
115115
{
116-
clearCache(false);
116+
clearCache();
117117
}
118118

119-
void clearCache( bool resetUnitFactor )
119+
void clearCache()
120120
{
121121
m_profile_cache->clearProfileCache();
122122
m_styles_converter->clearStylesCache();
123-
if (resetUnitFactor)
124-
{
125-
m_unit_converter->resetUnitFactors();
126-
}
127123
}
128124
shared_ptr<GeometrySettings>& getGeomSettings() { return m_geom_settings; }
129125
shared_ptr<UnitConverter>& getUnitConverter() { return m_unit_converter; }

0 commit comments

Comments
 (0)