35
35
36
36
#include < iostream>
37
37
38
+ #if defined _DEBUG || defined _DEBUG_RELEASE
39
+ static long globalNumMeshSets = 0 ;
40
+ #endif
41
+
38
42
namespace carve {
39
43
namespace poly {
40
44
class Polyhedron ;
@@ -339,7 +343,7 @@ namespace carve {
339
343
aabb_t getAABB () const ;
340
344
341
345
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 );
343
347
344
348
void clearEdges ();
345
349
@@ -630,6 +634,8 @@ namespace carve {
630
634
bool is_inner_mesh = false ; // completely inside other mesh
631
635
632
636
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 (); }
633
639
634
640
protected:
635
641
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 {
648
654
649
655
bool isNegative () const { return is_negative; }
650
656
651
- double volume () const
657
+ double volume ()
652
658
{
653
- if ( is_negative || !faces.size () ) {
659
+ if ( is_negative || !faces.size ()) {
654
660
return 0.0 ;
655
661
}
656
662
663
+ if (!std::isnan (m_volume))
664
+ {
665
+ return m_volume;
666
+ }
667
+
657
668
double vol = 0.0 ;
658
669
typename vertex_t ::vector_t origin = faces[0 ]->edge ->vert ->v ;
659
670
660
- for ( size_t f = 0 ; f < faces.size (); ++f )
671
+ for ( size_t f = 0 ; f < faces.size (); ++f)
661
672
{
662
673
face_t * face = faces[f];
663
674
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 )
665
676
{
666
677
vol += carve::geom3d::tetrahedronVolume (e1 ->vert ->v , e2 ->vert ->v , e2 ->next ->vert ->v , origin);
667
678
}
668
679
}
680
+ m_volume = vol;
669
681
return vol;
670
682
}
671
683
@@ -728,6 +740,7 @@ namespace carve {
728
740
729
741
std::vector<vertex_t > vertex_storage;
730
742
std::vector<mesh_t *> meshes;
743
+ // bool m_inner_outer_meshes_classified = false;
731
744
732
745
public:
733
746
template <typename face_type>
@@ -827,17 +840,14 @@ namespace carve {
827
840
828
841
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());
829
842
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.
832
844
MeshSet (std::vector<face_t *>& faces, const MeshOptions& opts = MeshOptions());
833
845
834
846
MeshSet (std::list<face_t *>& faces, const MeshOptions& opts = MeshOptions());
835
847
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);
838
849
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.
841
851
MeshSet (std::vector<mesh_t *>& _meshes);
842
852
843
853
MeshSet* clone () const ;
@@ -864,6 +874,38 @@ namespace carve {
864
874
void canonicalize ();
865
875
866
876
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
+ // }
867
909
};
868
910
869
911
carve::PointClass classifyPoint ( const carve::mesh::MeshSet<3 >* meshset, const carve::geom::RTreeNode<3 , carve::mesh::Face<3 >*>* face_rtree,
0 commit comments