42 #define PLANEPLUGIN_CC 44 #include "PlanePlugin.hh" 49 #include <ACG/Scenegraph/LineNode.hh> 51 #include <ACG/Geometry/Algorithms.hh> 52 #include <ACG/Scenegraph/DrawModes.hh> 66 template<
class MeshT >
74 _mesh->add_property(cut,
"Plane Cut Property" );
76 typename MeshT::FaceHandle fh ( _fh );
78 typename MeshT::FaceHandle current_face =
typename MeshT::FaceHandle(_fh);
80 typename MeshT::HalfedgeIter e_it, e_end = _mesh->halfedges_end();
81 for( e_it = _mesh->halfedges_begin(); e_it != e_end; ++e_it )
82 _mesh->property( cut, *e_it ) =
false;
86 bool nothingFound =
true;
87 int expansionLevel = 0;
88 bool flip_dir =
false;
91 std::vector< ACG::Vec3d > linePoints;
93 std::vector< typename MeshT::FaceHandle > startCandidates;
94 std::vector< typename MeshT::FaceHandle > expandable;
95 expandable.push_back( fh );
101 for (
typename MeshT::FaceHalfedgeIter fhe_it( *_mesh, current_face ); fhe_it.is_valid(); ++fhe_it){
102 if ( _mesh->property(cut,*fhe_it) )
105 typename MeshT::Point p0 = _mesh->point( _mesh->from_vertex_handle(*fhe_it) );
106 typename MeshT::Point p1 = _mesh->point( _mesh->to_vertex_handle(*fhe_it) );
108 typename MeshT::Point u = p1 - p0;
109 typename MeshT::Point w = p0 - _planePoint;
111 double D = (_planeNormal | u);
112 double N = - (_planeNormal | w);
116 if (sI < 0.0 || sI > 1.0 )
119 nothingFound =
false;
122 _mesh->property(cut,*fhe_it) =
true;
123 _mesh->property(cut,_mesh->opposite_halfedge_handle(*fhe_it)) =
true;
124 current_face = _mesh->face_handle(_mesh->opposite_halfedge_handle(*fhe_it));
126 if (!current_face.is_valid())
129 typename MeshT::Point cutPoint = p0 + sI * u;
133 linePoints.push_back(cutPoint);
135 linePoints.insert( linePoints.begin() , cutPoint );
144 if ( startCandidates.empty() ){
146 if (expansionLevel > 3 )
147 std::cerr <<
"Expanded" << expansionLevel <<
"rings but still nothing found!" << std::endl;
151 for (uint i=0; i < expandable.size(); i++)
152 for(
typename MeshT::FaceFaceIter ff_it(*_mesh, expandable[i]); ff_it.is_valid(); ++ff_it )
153 startCandidates.push_back( *ff_it );
160 if ( !startCandidates.empty() ){
161 fh = startCandidates.back();
162 expandable.push_back( fh );
163 startCandidates.pop_back();
167 }
else if (! flip_dir ){
176 _mesh->remove_property( cut );
190 template<
class MeshT >
191 typename MeshT::EdgeHandle
194 typename MeshT::EdgeIter e_it;
195 typename MeshT::EdgeIter e_end = _mesh.edges_end();
197 typename MeshT::Scalar minDistance = FLT_MAX;
198 typename MeshT::EdgeHandle minEdge(-1);
200 for (e_it = _mesh.edges_begin(); e_it != e_end; ++e_it){
202 typename MeshT::HalfedgeHandle hh = _mesh.halfedge_handle(*e_it, 0);
205 typename MeshT::Point p0 = _mesh.point( _mesh.from_vertex_handle(hh) );
206 typename MeshT::Point p1 = _mesh.point( _mesh.to_vertex_handle(hh) );
208 typename MeshT::Point u = p1 - p0;
209 typename MeshT::Point w = p0 - _planePoint;
211 double D = (_planeNormal | u);
212 double N = - (_planeNormal | w);
217 if (sI >= 0.0 && sI <= 1.0 ){
219 typename MeshT::Point cutPoint = p0 + sI * u;
221 typename MeshT::Scalar dist = (cutPoint - _planePoint).sqrnorm();
223 if ( dist < minDistance ){
MeshT::EdgeHandle getCuttedEdge(MeshT &_mesh, ACG::Vec3d &_planeNormal, ACG::Vec3d &_planePoint)
get an edge of the mesh that is cut by the plane
std::vector< ACG::Vec3d > getIntersectionPoints(MeshT *_mesh, uint _fh, ACG::Vec3d _planeNormal, ACG::Vec3d _planePoint, bool &_closed)
get the points from the intersection between mesh and plane