Skip to content

Commit 2a5b924

Browse files
committed
fix triangle winding order in example CreateWallAndWriteFile
1 parent 2f8cd54 commit 2a5b924

File tree

13 files changed

+214
-95
lines changed

13 files changed

+214
-95
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*.pdb
2121
*.tlog
2222
*.log
23+
*.bin
2324
bin
2425
bin32
2526
/build/

IfcPlusPlus/IfcPlusPlus.vcxproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
5050
<ConfigurationType>DynamicLibrary</ConfigurationType>
5151
<UseDebugLibraries>true</UseDebugLibraries>
52-
<PlatformToolset>v142</PlatformToolset>
52+
<PlatformToolset>v143</PlatformToolset>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>
5555
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@@ -76,7 +76,7 @@
7676
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
7777
<ConfigurationType>DynamicLibrary</ConfigurationType>
7878
<UseDebugLibraries>false</UseDebugLibraries>
79-
<PlatformToolset>v142</PlatformToolset>
79+
<PlatformToolset>v143</PlatformToolset>
8080
<WholeProgramOptimization>true</WholeProgramOptimization>
8181
<CharacterSet>Unicode</CharacterSet>
8282
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
@@ -184,6 +184,7 @@
184184
</DisableSpecificWarnings>
185185
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
186186
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
187+
<LanguageStandard>stdcpp20</LanguageStandard>
187188
</ClCompile>
188189
<Link>
189190
<GenerateDebugInformation>true</GenerateDebugInformation>

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

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU
5959
#include <ifcpp/IFC4/include/IfcUnitAssignment.h>
6060
#include <ifcpp/IFC4/include/IfcUnitEnum.h>
6161
#include <ifcpp/IFC4/include/IfcWall.h>
62+
#include <ifcpp/geometry/Carve/GeometryInputData.h>
6263
#include "IncludeCarveHeaders.h"
6364

6465
inline void convertPlacement(double local_x[3], double local_z[3], double location[3], shared_ptr<IfcAxis2Placement3D>& axis2placement3d, std::vector<shared_ptr<BuildingEntity> >& vec_new_entities)
@@ -203,7 +204,7 @@ namespace GeomDebugDump
203204
return -1;
204205
}
205206

206-
inline void MeshSet2Stream(const carve::mesh::MeshSet<3>* meshset, const vec3& offset, const carve::geom::vector<4>& color, std::stringstream& strs_out)
207+
inline void MeshSet2Stream(const carve::mesh::MeshSet<3>* meshset, const carve::math::Matrix& transform, const vec3& offset, const carve::geom::vector<4>& color, std::stringstream& strs_out)
207208
{
208209
strs_out << "Polyhedron{" << std::endl;
209210
strs_out << "color{" << color.x << ", " << color.y << ", " << color.z << ", " << color.w << "}" << std::endl;
@@ -225,9 +226,10 @@ namespace GeomDebugDump
225226
{
226227
strs_vertices << ", ";
227228
}
228-
double x = (vertex.v.x + offset.x)*scale_length_factor;
229-
double y = (vertex.v.y + offset.y)*scale_length_factor;
230-
double z = (vertex.v.z + offset.z)*scale_length_factor;
229+
vec3 vertex_transformed = transform * vertex.v;
230+
double x = (vertex_transformed.x + offset.x)*scale_length_factor;
231+
double y = (vertex_transformed.y + offset.y)*scale_length_factor;
232+
double z = (vertex_transformed.z + offset.z)*scale_length_factor;
231233

232234
strs_vertices << "{" << x << "," << y << "," << z << "}" << std::endl;
233235
++vertex_count;
@@ -350,6 +352,7 @@ namespace GeomDebugDump
350352
inline void dumpMeshsets( const std::vector<carve::mesh::MeshSet<3>* >& vec_meshsets, const vec3& offset, const std::vector<carve::geom::vector<4> >& vec_colors, bool append )
351353
{
352354
std::stringstream strs_out;
355+
carve::math::Matrix ident = carve::math::Matrix::IDENT();
353356
for( size_t i = 0; i < vec_meshsets.size(); ++i )
354357
{
355358
carve::mesh::MeshSet<3>* meshset = vec_meshsets[i];
@@ -358,7 +361,7 @@ namespace GeomDebugDump
358361
{
359362
color = vec_colors[i];
360363
}
361-
MeshSet2Stream(meshset, offset, color, strs_out);
364+
MeshSet2Stream(meshset, ident, offset, color, strs_out);
362365
}
363366

364367
if( !append )
@@ -370,7 +373,7 @@ namespace GeomDebugDump
370373
dump_ofstream.close();
371374
}
372375

373-
inline void dumpPolyhedron( const carve::poly::Polyhedron* poly, const vec3& offset, const carve::geom::vector<4>& color, bool append )
376+
inline void dumpPolyhedron( const carve::poly::Polyhedron* poly, const vec3& offset, const carve::geom::vector<4>& color, bool append)
374377
{
375378
std::stringstream strs_out;
376379
Polyhedron2Stream( poly, offset, color, strs_out );
@@ -384,10 +387,10 @@ namespace GeomDebugDump
384387
dump_ofstream << strs_out.str().c_str();
385388
dump_ofstream.close();
386389
}
387-
inline void dumpMeshSet(const carve::mesh::MeshSet<3>* poly, const vec3& offset, const carve::geom::vector<4>& color, bool append)
390+
inline void dumpMeshSetWithTransform(const carve::mesh::MeshSet<3>* meshset, const carve::math::Matrix& transform, const vec3& offset, const carve::geom::vector<4>& color, bool append, bool move_offset = true)
388391
{
389392
std::stringstream strs_out;
390-
MeshSet2Stream(poly, offset, color, strs_out);
393+
MeshSet2Stream(meshset, transform, offset, color, strs_out);
391394

392395
if( !append )
393396
{
@@ -397,25 +400,66 @@ namespace GeomDebugDump
397400
std::ofstream dump_ofstream("dump_mesh_debug.txt", std::ofstream::app);
398401
dump_ofstream << strs_out.str().c_str();
399402
dump_ofstream.close();
403+
404+
if( move_offset )
405+
{
406+
dump_y_pos_geom += meshset->getAABB().extent.y * 2.2;
407+
}
400408
}
401409

402-
inline void dumpPolyhedronInput( const carve::input::PolyhedronData& poly_input, const vec3& offset, const carve::geom::vector<4>& color, bool append )
410+
inline void dumpPolyhedronInput( const carve::input::PolyhedronData& poly_input, const vec3& offset, const carve::geom::vector<4>& color, bool append)
403411
{
404412
dumpPolyhedron( poly_input.create( carve::input::opts() ), offset, color, append );
405413
}
406414

407-
inline void dumpMeshset( const shared_ptr<carve::mesh::MeshSet<3> >& meshset, const carve::geom::vector<4>& color, bool append, bool move_offset = true )
415+
//inline void dumpMeshset( const shared_ptr<carve::mesh::MeshSet<3> >& meshset, const carve::math::Matrix& transform, const carve::geom::vector<4>& color, bool append, bool move_offset = true )
416+
//{
417+
// if( meshset->meshes.size() == 0 )
418+
// {
419+
// return;
420+
// }
421+
// vec3 offset = carve::geom::VECTOR( 0, dump_y_pos_geom, 0 );
422+
// dumpMeshSet( meshset.get(), transform, offset, color, append );
423+
424+
// if( move_offset )
425+
// {
426+
// dump_y_pos_geom += meshset->getAABB().extent.y*2.2;
427+
// }
428+
//}
429+
430+
inline void dumpMeshset(const shared_ptr<carve::mesh::MeshSet<3> >& meshset, const carve::geom::vector<4>& color, bool append, bool move_offset = true)
408431
{
409-
if( meshset->meshes.size() == 0 )
410-
{
411-
return;
432+
carve::math::Matrix ident = carve::math::Matrix::IDENT();
433+
vec3 offset = carve::geom::VECTOR(0, dump_y_pos_geom, 0);
434+
dumpMeshSetWithTransform(meshset.get(), ident, offset, color, append, move_offset);
435+
}
436+
437+
inline void dumpItemData(const shared_ptr<ItemShapeData >& itemData, const carve::math::Matrix& transform, const carve::geom::vector<4>& color, bool append, bool move_offset = true)
438+
{
439+
vec3 offset = carve::geom::VECTOR(0, dump_y_pos_geom, 0);
440+
for( const shared_ptr<carve::mesh::MeshSet<3> >& meshset : itemData->m_meshsets ) {
441+
dumpMeshSetWithTransform(meshset.get(), transform, offset, color, append, move_offset);
412442
}
413-
vec3 offset = carve::geom::VECTOR( 0, dump_y_pos_geom, 0 );
414-
dumpMeshSet( meshset.get(), offset, color, append );
415443

416-
if( move_offset )
417-
{
418-
dump_y_pos_geom += meshset->getAABB().extent.y*2.2;
444+
for( auto meshset : itemData->m_meshsets_open ) {
445+
dumpMeshSetWithTransform(meshset.get(), transform, offset, color, append, move_offset);
446+
}
447+
}
448+
449+
inline void dumpProductData(const shared_ptr<ProductShapeData >& productData, const carve::geom::vector<4>& color, bool append, bool move_offset = true, bool includeChildren = false)
450+
{
451+
carve::math::Matrix transform = productData->getTransform();
452+
for( const shared_ptr<RepresentationData >& rep : productData->m_vec_representations ) {
453+
454+
for( const shared_ptr<ItemShapeData >& itemData : rep->m_vec_item_data ) {
455+
dumpItemData(itemData, transform, color, append, move_offset);
456+
}
457+
}
458+
459+
if( includeChildren ) {
460+
for( const shared_ptr<ProductShapeData >& child : productData->m_vec_children ) {
461+
dumpProductData(child, color, append, move_offset, includeChildren);
462+
}
419463
}
420464
}
421465

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,17 +782,66 @@ class ProductShapeData
782782
}
783783
};
784784

785+
786+
#define ROUND_POLY_COORDINATES_UP 1000000.0
787+
#define ROUND_POLY_COORDINATES_DOWN 0.000001
788+
785789
class PolyInputCache3D
786790
{
787791
public:
788792
PolyInputCache3D()
789793
{
790794
m_poly_data = shared_ptr<carve::input::PolyhedronData>(new carve::input::PolyhedronData());
791795
}
792-
793-
size_t addPoint( const vec3& v )
796+
797+
size_t addPointPrecise(const vec3& v)
798+
{
799+
const double vertex_x = v.x;
800+
const double vertex_y = v.y;
801+
const double vertex_z = v.z;
802+
803+
// insert: returns a pair, with its member pair::first set to an iterator pointing to either the newly inserted element or to the element with an equivalent key in the map
804+
std::map<double, std::map<double, size_t> >& map_y_index = m_existing_vertices_coords.insert(std::make_pair(vertex_x, std::map<double, std::map<double, size_t> >())).first->second;
805+
std::map<double, size_t>& map_z_index = map_y_index.insert(std::make_pair(vertex_y, std::map<double, size_t>())).first->second;
806+
auto it_find_z = map_z_index.find(vertex_z);
807+
if( it_find_z != map_z_index.end() )
808+
{
809+
// vertex already exists in polyhedron. return its index
810+
size_t vertex_index = it_find_z->second;
811+
return vertex_index;
812+
}
813+
else
814+
{
815+
// add point to polyhedron
816+
size_t vertex_index = m_poly_data->addVertex(v);
817+
map_z_index[vertex_z] = vertex_index;
818+
return vertex_index;
819+
}
820+
}
821+
822+
size_t addPoint(const vec3& v)
794823
{
795-
return m_poly_data->addVertex(v);
824+
const double vertex_x = round(v.x * ROUND_POLY_COORDINATES_UP) * ROUND_POLY_COORDINATES_DOWN;
825+
const double vertex_y = round(v.y * ROUND_POLY_COORDINATES_UP) * ROUND_POLY_COORDINATES_DOWN;
826+
const double vertex_z = round(v.z * ROUND_POLY_COORDINATES_UP) * ROUND_POLY_COORDINATES_DOWN;
827+
828+
// insert: returns a pair, with its member pair::first set to an iterator pointing to either the newly inserted element or to the element with an equivalent key in the map
829+
std::map<double, std::map<double, size_t> >& map_y_index = m_existing_vertices_coords.insert(std::make_pair(vertex_x, std::map<double, std::map<double, size_t> >())).first->second;
830+
std::map<double, size_t>& map_z_index = map_y_index.insert(std::make_pair(vertex_y, std::map<double, size_t>())).first->second;
831+
auto it_find_z = map_z_index.find(vertex_z);
832+
if( it_find_z != map_z_index.end() )
833+
{
834+
// vertex already exists in polyhedron. return its index
835+
size_t vertex_index = it_find_z->second;
836+
return vertex_index;
837+
}
838+
else
839+
{
840+
// add point to polyhedron
841+
size_t vertex_index = m_poly_data->addVertex(v);
842+
map_z_index[vertex_z] = vertex_index;
843+
return vertex_index;
844+
}
796845
}
797846

798847
bool checkFaceIndices()
@@ -816,7 +865,7 @@ class PolyInputCache3D
816865
return false;
817866
}
818867
}
819-
868+
820869
++face_count;
821870
}
822871

@@ -828,4 +877,5 @@ class PolyInputCache3D
828877
}
829878

830879
shared_ptr<carve::input::PolyhedronData> m_poly_data;
880+
std::map<double, std::map<double, std::map<double, size_t> > > m_existing_vertices_coords;
831881
};

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ class PlacementConverter : public StatusCallback
305305

306306
inline void convertIfcPlacement( const shared_ptr<IfcPlacement>& placement, shared_ptr<TransformData>& resulting_matrix, bool only_rotation = false )
307307
{
308-
const double length_factor = m_unit_converter->getLengthInMeterFactor();
309308
if( dynamic_pointer_cast<IfcAxis1Placement>( placement ) )
310309
{
311310
messageCallback( "IfcAxis1Placement not implemented", StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__, placement.get() );

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class RepresentationConverter : public StatusCallback
202202
representation_data->m_ifc_representation = ifc_representation;
203203
representation_data->m_ifc_representation_context = ifc_representation->m_ContextOfItems;
204204

205-
const double length_factor = m_unit_converter->getLengthInMeterFactor();
206205
for( size_t i_representation_items = 0; i_representation_items < ifc_representation->m_Items.size(); ++i_representation_items )
207206
{
208207
shared_ptr<IfcRepresentationItem> representation_item = ifc_representation->m_Items[i_representation_items];

IfcPlusPlus/src/ifcpp/model/BuildingModel.cpp

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,46 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU
1919
#include <iostream>
2020
#include <ctime>
2121
#include <memory>
22-
#include "ifcpp/IFC4/include/IfcLabel.h"
23-
#include "ifcpp/IFC4/include/IfcIdentifier.h"
24-
#include "ifcpp/IFC4/include/IfcUnitEnum.h"
25-
#include "ifcpp/IFC4/include/IfcSIUnitName.h"
26-
#include "ifcpp/IFC4/include/IfcLengthMeasure.h"
27-
#include "ifcpp/IFC4/include/IfcChangeActionEnum.h"
28-
#include "ifcpp/IFC4/include/IfcValue.h"
29-
#include "ifcpp/IFC4/include/IfcPlaneAngleMeasure.h"
30-
#include "ifcpp/IFC4/include/IfcGloballyUniqueId.h"
31-
#include "ifcpp/IFC4/include/IfcDimensionCount.h"
32-
#include "ifcpp/IFC4/include/IfcPerson.h"
33-
#include "ifcpp/IFC4/include/IfcOrganization.h"
34-
#include "ifcpp/IFC4/include/IfcPersonAndOrganization.h"
35-
#include "ifcpp/IFC4/include/IfcApplication.h"
36-
#include "ifcpp/IFC4/include/IfcSIUnit.h"
37-
#include "ifcpp/IFC4/include/IfcCartesianPoint.h"
38-
#include "ifcpp/IFC4/include/IfcAxis2Placement.h"
39-
#include "ifcpp/IFC4/include/IfcAxis2Placement3D.h"
40-
#include "ifcpp/IFC4/include/IfcOwnerHistory.h"
41-
#include "ifcpp/IFC4/include/IfcDimensionalExponents.h"
42-
#include "ifcpp/IFC4/include/IfcMeasureWithUnit.h"
43-
#include "ifcpp/IFC4/include/IfcConversionBasedUnit.h"
44-
#include "ifcpp/IFC4/include/IfcUnitAssignment.h"
45-
#include "ifcpp/IFC4/include/IfcProject.h"
46-
#include "ifcpp/IFC4/include/IfcGeometricRepresentationContext.h"
47-
#include "ifcpp/IFC4/include/IfcProduct.h"
48-
#include "ifcpp/IFC4/include/IfcDirection.h"
49-
#include "ifcpp/IFC4/include/IfcReal.h"
50-
#include "ifcpp/IFC4/include/IfcRelationship.h"
51-
#include "ifcpp/IFC4/include/IfcRelAggregates.h"
52-
#include "ifcpp/IFC4/include/IfcSite.h"
53-
#include "ifcpp/IFC4/include/IfcBuilding.h"
54-
#include "ifcpp/IFC4/include/IfcElementAssembly.h"
55-
#include "ifcpp/IFC4/include/IfcStyledItem.h"
56-
#include "ifcpp/IFC4/include/IfcUnit.h"
57-
#include "ifcpp/reader/ReaderUtil.h"
58-
#include "ifcpp/writer/WriterUtil.h"
22+
23+
#include <ifcpp/IFC4/include/IfcApplication.h>
24+
#include <ifcpp/IFC4/include/IfcAxis2Placement.h>
25+
#include <ifcpp/IFC4/include/IfcAxis2Placement3D.h>
26+
#include <ifcpp/IFC4/include/IfcBuilding.h>
27+
#include <ifcpp/IFC4/include/IfcCartesianPoint.h>
28+
#include <ifcpp/IFC4/include/IfcConversionBasedUnit.h>
29+
#include <ifcpp/IFC4/include/IfcChangeActionEnum.h>
30+
#include <ifcpp/IFC4/include/IfcDimensionalExponents.h>
31+
#include <ifcpp/IFC4/include/IfcDimensionCount.h>
32+
#include <ifcpp/IFC4/include/IfcDirection.h>
33+
#include <ifcpp/IFC4/include/IfcElementAssembly.h>
34+
#include <ifcpp/IFC4/include/IfcGeometricRepresentationContext.h>
35+
#include <ifcpp/IFC4/include/IfcGloballyUniqueId.h>
36+
#include <ifcpp/IFC4/include/IfcIdentifier.h>
37+
#include <ifcpp/IFC4/include/IfcLabel.h>
38+
#include <ifcpp/IFC4/include/IfcLengthMeasure.h>
39+
#include <ifcpp/IFC4/include/IfcMeasureWithUnit.h>
40+
#include <ifcpp/IFC4/include/IfcOrganization.h>
41+
#include <ifcpp/IFC4/include/IfcOwnerHistory.h>
42+
#include <ifcpp/IFC4/include/IfcPersonAndOrganization.h>
43+
#include <ifcpp/IFC4/include/IfcPerson.h>
44+
#include <ifcpp/IFC4/include/IfcPlaneAngleMeasure.h>
45+
#include <ifcpp/IFC4/include/IfcProject.h>
46+
#include <ifcpp/IFC4/include/IfcProduct.h>
47+
#include <ifcpp/IFC4/include/IfcReal.h>
48+
#include <ifcpp/IFC4/include/IfcRelationship.h>
49+
#include <ifcpp/IFC4/include/IfcRelAggregates.h>
50+
#include <ifcpp/IFC4/include/IfcRelContainedInSpatialStructure.h>
51+
#include <ifcpp/IFC4/include/IfcSite.h>
52+
#include <ifcpp/IFC4/include/IfcSIUnit.h>
53+
#include <ifcpp/IFC4/include/IfcSIUnitName.h>
54+
#include <ifcpp/IFC4/include/IfcSpatialStructureElement.h>
55+
#include <ifcpp/IFC4/include/IfcStyledItem.h>
56+
#include <ifcpp/IFC4/include/IfcUnit.h>
57+
#include <ifcpp/IFC4/include/IfcUnitEnum.h>
58+
#include <ifcpp/IFC4/include/IfcUnitAssignment.h>
59+
#include <ifcpp/IFC4/include/IfcValue.h>
60+
#include <ifcpp/reader/ReaderUtil.h>
61+
#include <ifcpp/writer/WriterUtil.h>
5962

6063
#include "AttributeObject.h"
6164
#include "BuildingGuid.h"
@@ -667,6 +670,27 @@ void BuildingModel::collectDependentEntities( shared_ptr<BuildingEntity> entity,
667670
}
668671
}
669672

673+
shared_ptr<IfcSpatialElement> spatial_element = dynamic_pointer_cast<IfcSpatialElement>(entity);
674+
if( spatial_element && false )
675+
{
676+
for( const auto& contains_weak_ptr : spatial_element->m_ContainsElements_inverse )
677+
{
678+
if( contains_weak_ptr.expired() )
679+
{
680+
continue;
681+
}
682+
683+
shared_ptr<IfcRelContainedInSpatialStructure> rel_contained(contains_weak_ptr);
684+
if( rel_contained )
685+
{
686+
for( auto relatedProduct : rel_contained->m_RelatedElements )
687+
{
688+
collectDependentEntities(relatedProduct, target_map, resolveInverseAttributes);
689+
}
690+
}
691+
}
692+
}
693+
670694
std::vector<std::pair<std::string, shared_ptr<BuildingObject> > > vec_attributes;
671695
entity->getAttributes( vec_attributes );
672696

0 commit comments

Comments
 (0)