Skip to content

Commit edca2c9

Browse files
committed
improve geometry processing
1 parent 118636e commit edca2c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+17116
-9807
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ examples/LoadFileExample/dump_mesh_debug.txt
5353
examples/CreateIfcWallAndWriteFile/example.ifc
5454
examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj.user
5555
examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj.user
56+
.vs/IfcPlusPlus/v17/DocumentLayout.json
57+
examples/SimpleViewerExampleQt/.vs/SimpleViewerExampleQt/v17/DocumentLayout.json

IfcPlusPlus/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(IFCPP_SOURCE_FILES
3737
src/ifcpp/writer/WriterUtil.cpp
3838
src/ifcpp/geometry/MeshOps.cpp
3939
src/ifcpp/geometry/GeometryInputData.cpp
40+
src/ifcpp/geometry/MeshSimplifier.cpp
4041
src/external/Carve/src/lib/aabb.cpp
4142
src/external/Carve/src/lib/carve.cpp
4243
src/external/Carve/src/lib/convex_hull.cpp

IfcPlusPlus/IfcPlusPlus.vcxproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
</DisableSpecificWarnings>
185185
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
186186
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
187-
<LanguageStandard>stdcpp17</LanguageStandard>
187+
<LanguageStandard>stdcpp20</LanguageStandard>
188188
</ClCompile>
189189
<Link>
190190
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -265,7 +265,7 @@
265265
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
266266
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
267267
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
268-
<LanguageStandard>stdcpp17</LanguageStandard>
268+
<LanguageStandard>stdcpp20</LanguageStandard>
269269
<DisableSpecificWarnings>4267;4244</DisableSpecificWarnings>
270270
</ClCompile>
271271
<Link>
@@ -338,8 +338,10 @@
338338
</Lib>
339339
</ItemDefinitionGroup>
340340
<ItemGroup>
341+
<ClCompile Include="src\ifcpp\geometry\CSG_Adapter.cpp" />
341342
<ClCompile Include="src\ifcpp\geometry\GeometryInputData.cpp" />
342343
<ClCompile Include="src\ifcpp\geometry\MeshOps.cpp" />
344+
<ClCompile Include="src\ifcpp\geometry\MeshSimplifier.cpp" />
343345
<ClCompile Include="src\ifcpp\IFC4X3\EntityFactory.cpp">
344346
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/bigobj %(AdditionalOptions)</AdditionalOptions>
345347
</ClCompile>

IfcPlusPlus/IfcPlusPlus.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,11 @@
290290
<ClCompile Include="src\ifcpp\geometry\GeometryInputData.cpp">
291291
<Filter>Quelldateien</Filter>
292292
</ClCompile>
293+
<ClCompile Include="src\ifcpp\geometry\CSG_Adapter.cpp">
294+
<Filter>Quelldateien</Filter>
295+
</ClCompile>
296+
<ClCompile Include="src\ifcpp\geometry\MeshSimplifier.cpp">
297+
<Filter>Quelldateien</Filter>
298+
</ClCompile>
293299
</ItemGroup>
294300
</Project>

IfcPlusPlus/src/external/Carve/src/include/carve/aabb.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct aabb {
7171
void expand(double pad);
7272

7373
bool completelyContains(const aabb<ndim>& other) const;
74+
bool completelyContains(const aabb<ndim>& other, double eps) const;
7475

7576
bool containsPoint(const vector_t& v) const;
7677

IfcPlusPlus/src/external/Carve/src/include/carve/aabb_impl.hpp

+36
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,42 @@ namespace carve {
181181
return true;
182182
}
183183

184+
/*
185+
* This function checks if the other aabb is completely contained in this aabb
186+
* @param other the other aabb
187+
* @param eps the epsilon value. If positive, it allows the other aabb to be slightly bigger than this aabb
188+
* If negative, the other aabb must be strictly smaller than this aabb
189+
*/
190+
template <unsigned ndim>
191+
bool aabb<ndim>::completelyContains(const aabb<ndim>& other, double eps) const
192+
{
193+
// pos ext eps
194+
// ----------|------------|---|
195+
//
196+
// ----------|-----------------| other is bigger than this+eps -> false
197+
198+
// ----------|--------------| other is smaller in all dimensions -> true
199+
200+
for (unsigned i = 0; i < ndim; ++i)
201+
{
202+
// if max point of other is greater than max point of this, return false
203+
double max = pos.v[i] + extent[i];
204+
double maxOther = other.pos.v[i] + other.extent[i];
205+
if (maxOther > max + eps)
206+
{
207+
return false;
208+
}
209+
210+
double min = pos.v[i] - extent[i];
211+
double minOther = other.pos.v[i] - other.extent[i];
212+
if (minOther < min - eps)
213+
{
214+
return false;
215+
}
216+
}
217+
return true;
218+
}
219+
184220
template <unsigned ndim>
185221
bool aabb<ndim>::containsPoint(const vector_t& v) const {
186222
for( unsigned i = 0; i < ndim; ++i ) {

IfcPlusPlus/src/external/Carve/src/include/carve/carve.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,8 @@ namespace carve {
264264
MACRO_BEGIN throw carve::exception() << __FILE__ << ":" << __LINE__ << " " \
265265
<< #x; \
266266
MACRO_END
267+
268+
void printToDebugLogOn(bool on);
269+
bool IsPrintToDebugLogOn();
270+
void printToDebugLog(const char* funcName, std::string details);
271+
void clearDebugLogLinux();

IfcPlusPlus/src/external/Carve/src/include/carve/geom3d.hpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <carve/carve.hpp>
2828
#include <carve/geom.hpp>
29-
29+
#include <iostream>
3030
#include <math.h>
3131
#include <carve/math_constants.hpp>
3232

@@ -299,6 +299,13 @@ namespace carve {
299299
double d3 = carve::geom::dotcross(direction, b, base);
300300
#endif
301301

302+
if (isnan(d1) || isnan(d2) || isnan(d3))
303+
{
304+
printToDebugLog( __FUNCTION__, " d1=" +std::to_string( d1) + ", d2=" + std::to_string(d2) +
305+
", d3=" + std::to_string(d3 ) );
306+
}
307+
308+
302309
// CASE: a and b are coplanar wrt. direction.
303310
if( d1 == 0.0 ) {
304311
// a and b point in the same direction.
@@ -325,7 +332,7 @@ namespace carve {
325332
return -1;
326333
}
327334
if( d2 > 0.0 && d3 < 0.0 ) {
328-
return +1;
335+
return 1;
329336
}
330337

331338
// both a and b are to one side of plane(direction, base) -
@@ -342,7 +349,7 @@ namespace carve {
342349
return dot(a, base) > 0.0 ? +1 : -1;
343350
}
344351
else {
345-
return dot(a, base) > 0.0 ? -1 : +1;
352+
return dot(a, base) > 0.0 ? -1 : 1;
346353
}
347354
}
348355

IfcPlusPlus/src/external/Carve/src/include/carve/geom_impl.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace carve {
4444
#if defined(CARVE_DEBUG)
4545
CARVE_ASSERT(length() > 0.0);
4646
#endif
47-
if( length2() == 0.0 )
47+
if( length2() < 1e-16 )
4848
{
4949
return *this;
5050
}

IfcPlusPlus/src/external/Carve/src/include/carve/mesh.hpp

+53-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535

3636
#include <iostream>
3737

38+
#if defined _DEBUG || defined _DEBUG_RELEASE
39+
static long globalNumMeshSets = 0;
40+
#endif
41+
3842
namespace carve {
3943
namespace poly {
4044
class Polyhedron;
@@ -339,7 +343,7 @@ namespace carve {
339343
aabb_t getAABB() const;
340344

341345
bool recalc(double CARVE_EPSILON);
342-
carve::geom::vector<ndim> computeNormal(double CARVE_EPSILON);
346+
carve::geom::vector<ndim> computeNormal(double CARVE_EPSILON, bool calledRecursive = false);
343347

344348
void clearEdges();
345349

@@ -630,6 +634,8 @@ namespace carve {
630634
bool is_inner_mesh = false; // completely inside other mesh
631635

632636
meshset_t* meshset = nullptr;
637+
double m_volume = std::numeric_limits<double>::quiet_NaN();
638+
void resetVolume() { m_volume = std::numeric_limits<double>::quiet_NaN(); }
633639

634640
protected:
635641
Mesh(std::vector<face_t*>& _faces, std::vector<edge_t*>& _open_edges, std::vector<edge_t*>& _closed_edges, bool _is_negative, bool _is_inner_mesh);
@@ -648,24 +654,30 @@ namespace carve {
648654

649655
bool isNegative() const { return is_negative; }
650656

651-
double volume() const
657+
double volume()
652658
{
653-
if( is_negative || !faces.size() ) {
659+
if (is_negative || !faces.size()) {
654660
return 0.0;
655661
}
656662

663+
if (!std::isnan(m_volume))
664+
{
665+
return m_volume;
666+
}
667+
657668
double vol = 0.0;
658669
typename vertex_t::vector_t origin = faces[0]->edge->vert->v;
659670

660-
for( size_t f = 0; f < faces.size(); ++f )
671+
for (size_t f = 0; f < faces.size(); ++f)
661672
{
662673
face_t* face = faces[f];
663674
edge_t* e1 = face->edge;
664-
for( edge_t* e2 = e1->next; e2->next != e1; e2 = e2->next )
675+
for (edge_t* e2 = e1->next; e2->next != e1; e2 = e2->next)
665676
{
666677
vol += carve::geom3d::tetrahedronVolume(e1->vert->v, e2->vert->v, e2->next->vert->v, origin);
667678
}
668679
}
680+
m_volume = vol;
669681
return vol;
670682
}
671683

@@ -728,6 +740,7 @@ namespace carve {
728740

729741
std::vector<vertex_t> vertex_storage;
730742
std::vector<mesh_t*> meshes;
743+
//bool m_inner_outer_meshes_classified = false;
731744

732745
public:
733746
template <typename face_type>
@@ -827,17 +840,14 @@ namespace carve {
827840

828841
MeshSet(const std::vector<typename vertex_t::vector_t>& points, size_t n_faces, const std::vector<int>& face_indices, double CARVE_EPSILON, const MeshOptions& opts = MeshOptions());
829842

830-
// Construct a mesh set from a set of disconnected faces. Takes
831-
// possession of the face pointers.
843+
// Construct a mesh set from a set of disconnected faces. Takes possession of the face pointers.
832844
MeshSet(std::vector<face_t*>& faces, const MeshOptions& opts = MeshOptions());
833845

834846
MeshSet(std::list<face_t*>& faces, const MeshOptions& opts = MeshOptions());
835847

836-
MeshSet(std::vector<vertex_t>& _vertex_storage,
837-
std::vector<mesh_t*>& _meshes);
848+
MeshSet(std::vector<vertex_t>& _vertex_storage, std::vector<mesh_t*>& _meshes);
838849

839-
// This constructor consolidates and rewrites vertex pointers in
840-
// each mesh, repointing them to local storage.
850+
// This constructor consolidates and rewrites vertex pointers in each mesh, repointing them to local storage.
841851
MeshSet(std::vector<mesh_t*>& _meshes);
842852

843853
MeshSet* clone() const;
@@ -864,6 +874,38 @@ namespace carve {
864874
void canonicalize();
865875

866876
void separateMeshes();
877+
878+
//void classifyInnerOuterMeshes(double eps);
879+
880+
//double volume(double eps)
881+
//{
882+
// if (!m_inner_outer_meshes_classified)
883+
// {
884+
// classifyInnerOuterMeshes(eps);
885+
// }
886+
887+
// double vol = 0;
888+
// for (size_t ii = 0; ii < meshes.size(); ++ii)
889+
// {
890+
// carve::mesh::Mesh<ndim>* mesh = meshes[ii];
891+
// double meshVolume = mesh->volume();
892+
// if (meshVolume < 0.0)
893+
// {
894+
// mesh->invert();
895+
// meshVolume = -meshVolume;
896+
// }
897+
898+
// if (mesh->is_inner_mesh)
899+
// {
900+
// vol -= meshVolume;
901+
// }
902+
// else
903+
// {
904+
// vol += meshVolume;
905+
// }
906+
// }
907+
// return vol;
908+
//}
867909
};
868910

869911
carve::PointClass classifyPoint( const carve::mesh::MeshSet<3>* meshset, const carve::geom::RTreeNode<3, carve::mesh::Face<3>*>* face_rtree,

0 commit comments

Comments
 (0)