42 #define POLYLINEPLUGIN_CC 44 #include "PolyLinePlugin.hh" 50 template<
class MeshT >
51 bool cutted(MeshT& _mesh,
typename MeshT::HalfedgeHandle _he,
const ACG::Vec3d _planeNormal,
const ACG::Vec3d _planePoint,
ACG::Vec3d* _point = 0) {
54 typename MeshT::Point p0 = _mesh.point( _mesh.from_vertex_handle(_he) );
55 typename MeshT::Point p1 = _mesh.point( _mesh.to_vertex_handle(_he) );
57 typename MeshT::Point u = p1 - p0;
58 typename MeshT::Point w = p0 - _planePoint;
60 double D = (_planeNormal | u);
61 double N = - (_planeNormal | w);
67 *_point = p0 + sI * u;
69 return (sI >= 0.0 && sI <= 1.0 );
83 template<
class MeshT >
84 std::vector< ACG::Vec3d > getIntersectionLoop( MeshT* _mesh,
91 _mesh->get_property_handle(cut,
"Plane Cut Property" );
93 typename MeshT::FaceHandle fh ( _fh );
95 typename MeshT::FaceHandle current_face =
typename MeshT::FaceHandle(_fh);
98 bool nothingFound =
true;
99 int expansionLevel = 0;
100 bool flip_dir =
false;
103 std::vector< ACG::Vec3d > linePoints;
105 std::vector< typename MeshT::FaceHandle > startCandidates;
106 std::vector< typename MeshT::FaceHandle > expandable;
107 expandable.push_back( fh );
113 for (
typename MeshT::FaceHalfedgeIter fhe_it( *_mesh, current_face ); fhe_it.is_valid(); ++fhe_it){
114 if ( _mesh->property(cut,*fhe_it) )
117 typename MeshT::Point p0 = _mesh->point( _mesh->from_vertex_handle(*fhe_it) );
118 typename MeshT::Point p1 = _mesh->point( _mesh->to_vertex_handle(*fhe_it) );
120 typename MeshT::Point u = p1 - p0;
121 typename MeshT::Point w = p0 - _planePoint;
123 double D = (_planeNormal | u);
124 double N = - (_planeNormal | w);
128 if (sI < 0.0 || sI > 1.0 )
131 nothingFound =
false;
134 _mesh->property(cut,*fhe_it) =
true;
135 _mesh->property(cut,_mesh->opposite_halfedge_handle(*fhe_it)) =
true;
136 current_face = _mesh->face_handle(_mesh->opposite_halfedge_handle(*fhe_it));
138 if (!current_face.is_valid())
141 typename MeshT::Point cutPoint = p0 + sI * u;
145 linePoints.push_back(cutPoint);
147 linePoints.insert( linePoints.begin() , cutPoint );
156 if ( startCandidates.empty() ){
158 if (expansionLevel > 3 )
159 std::cerr <<
"Expanded" << expansionLevel <<
"rings but still nothing found!" << std::endl;
163 for (uint i=0; i < expandable.size(); i++)
164 for(
typename MeshT::FaceFaceIter ff_it(*_mesh, expandable[i]); ff_it.is_valid(); ++ff_it )
165 startCandidates.push_back( *ff_it );
172 if ( !startCandidates.empty() ){
173 fh = startCandidates.back();
174 expandable.push_back( fh );
175 startCandidates.pop_back();
179 }
else if (! flip_dir ){
203 template<
class MeshT >
210 _mesh->add_property(cut,
"Plane Cut Property" );
212 typename MeshT::HalfedgeIter e_it, e_end = _mesh->halfedges_end();
213 for( e_it = _mesh->halfedges_begin(); e_it != e_end; ++e_it )
214 _mesh->property( cut, *e_it ) =
false;
216 std::vector< ACG::Vec3d > linePoints = getIntersectionLoop(_mesh,_fh,_planeNormal,_planePoint,_closed);
218 _mesh->remove_property( cut );
232 template<
class MeshT >
233 typename MeshT::EdgeHandle
236 typename MeshT::EdgeIter e_it;
237 typename MeshT::EdgeIter e_end = _mesh.edges_end();
239 typename MeshT::Scalar minDistance = FLT_MAX;
240 typename MeshT::EdgeHandle minEdge(-1);
242 for (e_it = _mesh.edges_begin(); e_it != e_end; ++e_it){
244 typename MeshT::HalfedgeHandle hh = _mesh.halfedge_handle(*e_it, 0);
247 typename MeshT::Point p0 = _mesh.point( _mesh.from_vertex_handle(hh) );
248 typename MeshT::Point p1 = _mesh.point( _mesh.to_vertex_handle(hh) );
250 typename MeshT::Point u = p1 - p0;
251 typename MeshT::Point w = p0 - _planePoint;
253 double D = (_planeNormal | u);
254 double N = - (_planeNormal | w);
259 if (sI >= 0.0 && sI <= 1.0 ){
261 typename MeshT::Point cutPoint = p0 + sI * u;
263 typename MeshT::Scalar dist = (cutPoint - _planePoint).sqrnorm();
265 if ( dist < minDistance ){
286 template<
class MeshT >
291 std::vector< std::vector<ACG::Vec3d> > lines;
294 _mesh->add_property(cut,
"Plane Cut Property" );
296 std::queue< typename MeshT::EdgeHandle > queue;
299 for(
typename MeshT::EdgeIter e_it = _mesh->edges_begin(); e_it != _mesh->edges_end(); ++e_it ) {
302 if ( cutted(*_mesh, _mesh->halfedge_handle(*e_it, 0),_planeNormal, _planePoint, 0) ) {
307 _mesh->property( cut, _mesh->halfedge_handle(*e_it, 0) ) =
false;
308 _mesh->property( cut, _mesh->halfedge_handle(*e_it, 1) ) =
false;
314 while( !queue.empty() ) {
317 typename MeshT::HalfedgeHandle hh = _mesh->halfedge_handle( queue.front() , 0);
321 if ( _mesh->property(cut,hh) )
325 typename MeshT::FaceHandle fh = _mesh->face_handle(hh);
328 if ( !fh.is_valid() ) {
329 fh = _mesh->face_handle(_mesh->opposite_halfedge_handle(hh));
333 if ( !fh.is_valid() )
340 lines.push_back(getIntersectionLoop(_mesh,fh.idx(),_planeNormal,_planePoint,closed) );
345 _mesh->remove_property( cut );
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< std::vector< ACG::Vec3d > > getMultipleIntersectionPoints(MeshT *_mesh, ACG::Vec3d _planeNormal, ACG::Vec3d _planePoint)
get all points from the intersection between mesh and plane
std::vector< ACG::Vec3d > getIntersectionPoints(MeshT *_mesh, uint _fh, ACG::Vec3d _planeNormal, ACG::Vec3d _planePoint, bool &_closed)
get the points from the closest connected intersection between mesh and plane