Skip to content

Commit

Permalink
improve geometry processing
Browse files Browse the repository at this point in the history
  • Loading branch information
ifcquery committed Mar 20, 2024
1 parent 118636e commit edca2c9
Show file tree
Hide file tree
Showing 66 changed files with 17,116 additions and 9,807 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ examples/LoadFileExample/dump_mesh_debug.txt
examples/CreateIfcWallAndWriteFile/example.ifc
examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj.user
examples/SimpleViewerExampleQt/SimpleViewerExampleQt.vcxproj.user
.vs/IfcPlusPlus/v17/DocumentLayout.json
examples/SimpleViewerExampleQt/.vs/SimpleViewerExampleQt/v17/DocumentLayout.json
1 change: 1 addition & 0 deletions IfcPlusPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(IFCPP_SOURCE_FILES
src/ifcpp/writer/WriterUtil.cpp
src/ifcpp/geometry/MeshOps.cpp
src/ifcpp/geometry/GeometryInputData.cpp
src/ifcpp/geometry/MeshSimplifier.cpp
src/external/Carve/src/lib/aabb.cpp
src/external/Carve/src/lib/carve.cpp
src/external/Carve/src/lib/convex_hull.cpp
Expand Down
6 changes: 4 additions & 2 deletions IfcPlusPlus/IfcPlusPlus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down Expand Up @@ -265,7 +265,7 @@
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<DisableSpecificWarnings>4267;4244</DisableSpecificWarnings>
</ClCompile>
<Link>
Expand Down Expand Up @@ -338,8 +338,10 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\ifcpp\geometry\CSG_Adapter.cpp" />
<ClCompile Include="src\ifcpp\geometry\GeometryInputData.cpp" />
<ClCompile Include="src\ifcpp\geometry\MeshOps.cpp" />
<ClCompile Include="src\ifcpp\geometry\MeshSimplifier.cpp" />
<ClCompile Include="src\ifcpp\IFC4X3\EntityFactory.cpp">
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/bigobj %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand Down
6 changes: 6 additions & 0 deletions IfcPlusPlus/IfcPlusPlus.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,11 @@
<ClCompile Include="src\ifcpp\geometry\GeometryInputData.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\ifcpp\geometry\CSG_Adapter.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\ifcpp\geometry\MeshSimplifier.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions IfcPlusPlus/src/external/Carve/src/include/carve/aabb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct aabb {
void expand(double pad);

bool completelyContains(const aabb<ndim>& other) const;
bool completelyContains(const aabb<ndim>& other, double eps) const;

bool containsPoint(const vector_t& v) const;

Expand Down
36 changes: 36 additions & 0 deletions IfcPlusPlus/src/external/Carve/src/include/carve/aabb_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ namespace carve {
return true;
}

/*
* This function checks if the other aabb is completely contained in this aabb
* @param other the other aabb
* @param eps the epsilon value. If positive, it allows the other aabb to be slightly bigger than this aabb
* If negative, the other aabb must be strictly smaller than this aabb
*/
template <unsigned ndim>
bool aabb<ndim>::completelyContains(const aabb<ndim>& other, double eps) const
{
// pos ext eps
// ----------|------------|---|
//
// ----------|-----------------| other is bigger than this+eps -> false

// ----------|--------------| other is smaller in all dimensions -> true

for (unsigned i = 0; i < ndim; ++i)
{
// if max point of other is greater than max point of this, return false
double max = pos.v[i] + extent[i];
double maxOther = other.pos.v[i] + other.extent[i];
if (maxOther > max + eps)
{
return false;
}

double min = pos.v[i] - extent[i];
double minOther = other.pos.v[i] - other.extent[i];
if (minOther < min - eps)
{
return false;
}
}
return true;
}

template <unsigned ndim>
bool aabb<ndim>::containsPoint(const vector_t& v) const {
for( unsigned i = 0; i < ndim; ++i ) {
Expand Down
5 changes: 5 additions & 0 deletions IfcPlusPlus/src/external/Carve/src/include/carve/carve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,8 @@ namespace carve {
MACRO_BEGIN throw carve::exception() << __FILE__ << ":" << __LINE__ << " " \
<< #x; \
MACRO_END

void printToDebugLogOn(bool on);
bool IsPrintToDebugLogOn();
void printToDebugLog(const char* funcName, std::string details);
void clearDebugLogLinux();
13 changes: 10 additions & 3 deletions IfcPlusPlus/src/external/Carve/src/include/carve/geom3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <carve/carve.hpp>
#include <carve/geom.hpp>

#include <iostream>
#include <math.h>
#include <carve/math_constants.hpp>

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

if (isnan(d1) || isnan(d2) || isnan(d3))
{
printToDebugLog( __FUNCTION__, " d1=" +std::to_string( d1) + ", d2=" + std::to_string(d2) +
", d3=" + std::to_string(d3 ) );
}


// CASE: a and b are coplanar wrt. direction.
if( d1 == 0.0 ) {
// a and b point in the same direction.
Expand All @@ -325,7 +332,7 @@ namespace carve {
return -1;
}
if( d2 > 0.0 && d3 < 0.0 ) {
return +1;
return 1;
}

// both a and b are to one side of plane(direction, base) -
Expand All @@ -342,7 +349,7 @@ namespace carve {
return dot(a, base) > 0.0 ? +1 : -1;
}
else {
return dot(a, base) > 0.0 ? -1 : +1;
return dot(a, base) > 0.0 ? -1 : 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace carve {
#if defined(CARVE_DEBUG)
CARVE_ASSERT(length() > 0.0);
#endif
if( length2() == 0.0 )
if( length2() < 1e-16 )
{
return *this;
}
Expand Down
64 changes: 53 additions & 11 deletions IfcPlusPlus/src/external/Carve/src/include/carve/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

#include <iostream>

#if defined _DEBUG || defined _DEBUG_RELEASE
static long globalNumMeshSets = 0;
#endif

namespace carve {
namespace poly {
class Polyhedron;
Expand Down Expand Up @@ -339,7 +343,7 @@ namespace carve {
aabb_t getAABB() const;

bool recalc(double CARVE_EPSILON);
carve::geom::vector<ndim> computeNormal(double CARVE_EPSILON);
carve::geom::vector<ndim> computeNormal(double CARVE_EPSILON, bool calledRecursive = false);

void clearEdges();

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

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

protected:
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);
Expand All @@ -648,24 +654,30 @@ namespace carve {

bool isNegative() const { return is_negative; }

double volume() const
double volume()
{
if( is_negative || !faces.size() ) {
if (is_negative || !faces.size()) {
return 0.0;
}

if (!std::isnan(m_volume))
{
return m_volume;
}

double vol = 0.0;
typename vertex_t::vector_t origin = faces[0]->edge->vert->v;

for( size_t f = 0; f < faces.size(); ++f )
for (size_t f = 0; f < faces.size(); ++f)
{
face_t* face = faces[f];
edge_t* e1 = face->edge;
for( edge_t* e2 = e1->next; e2->next != e1; e2 = e2->next )
for (edge_t* e2 = e1->next; e2->next != e1; e2 = e2->next)
{
vol += carve::geom3d::tetrahedronVolume(e1->vert->v, e2->vert->v, e2->next->vert->v, origin);
}
}
m_volume = vol;
return vol;
}

Expand Down Expand Up @@ -728,6 +740,7 @@ namespace carve {

std::vector<vertex_t> vertex_storage;
std::vector<mesh_t*> meshes;
//bool m_inner_outer_meshes_classified = false;

public:
template <typename face_type>
Expand Down Expand Up @@ -827,17 +840,14 @@ namespace carve {

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());

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

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

MeshSet(std::vector<vertex_t>& _vertex_storage,
std::vector<mesh_t*>& _meshes);
MeshSet(std::vector<vertex_t>& _vertex_storage, std::vector<mesh_t*>& _meshes);

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

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

void separateMeshes();

//void classifyInnerOuterMeshes(double eps);

//double volume(double eps)
//{
// if (!m_inner_outer_meshes_classified)
// {
// classifyInnerOuterMeshes(eps);
// }

// double vol = 0;
// for (size_t ii = 0; ii < meshes.size(); ++ii)
// {
// carve::mesh::Mesh<ndim>* mesh = meshes[ii];
// double meshVolume = mesh->volume();
// if (meshVolume < 0.0)
// {
// mesh->invert();
// meshVolume = -meshVolume;
// }

// if (mesh->is_inner_mesh)
// {
// vol -= meshVolume;
// }
// else
// {
// vol += meshVolume;
// }
// }
// return vol;
//}
};

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

0 comments on commit edca2c9

Please sign in to comment.