42#define POLYLINEPLUGIN_CC
44#include "PolyLinePlugin.hh"
50template<
class MeshT >
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 );
83template<
class MeshT >
84std::vector< ACG::Vec3d > getIntersectionLoop(
MeshT* _mesh,
91 _mesh->get_property_handle(cut,
"Plane Cut Property" );
93 typename MeshT::FaceHandle fh ( _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 (
auto fhe_it : current_face.
halfedges()){
114 if ( _mesh->property(cut,fhe_it) )
117 typename MeshT::Point p0 = _mesh->point( fhe_it.from() );
118 typename MeshT::Point p1 = _mesh->point( fhe_it.to() );
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,fhe_it.opp()) =
true;
136 current_face = fhe_it.opp().face();
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 ){
203template<
class MeshT >
210 _mesh->add_property(cut,
"Plane Cut Property" );
212 for (
auto he_it : _mesh->halfedges())
213 _mesh->property( cut, he_it ) =
false;
215 std::vector< ACG::Vec3d > linePoints = getIntersectionLoop(_mesh,_fh,_planeNormal,_planePoint,_closed);
217 _mesh->remove_property( cut );
231template<
class MeshT >
232typename MeshT::EdgeHandle
235 typename MeshT::Scalar minDistance = FLT_MAX;
236 typename MeshT::EdgeHandle minEdge(-1);
238 for (
auto e_it : _mesh.edges()){
243 typename MeshT::Point p0 = _mesh.point( hh.
from() );
244 typename MeshT::Point p1 = _mesh.point( hh.
to() );
246 typename MeshT::Point u = p1 - p0;
247 typename MeshT::Point w = p0 - _planePoint;
249 double D = (_planeNormal | u);
250 double N = - (_planeNormal | w);
255 if (sI >= 0.0 && sI <= 1.0 ){
257 typename MeshT::Point cutPoint = p0 + sI * u;
259 typename MeshT::Scalar dist = (cutPoint - _planePoint).sqrnorm();
261 if ( dist < minDistance ){
282template<
class MeshT >
287 std::vector< std::vector<ACG::Vec3d> > lines;
290 _mesh->add_property(cut,
"Plane Cut Property" );
292 std::queue< typename OpenMesh::SmartEdgeHandle > queue;
295 for(
auto e_it : _mesh->edges()) {
298 if ( cutted(*_mesh, e_it.h0(),_planeNormal, _planePoint, 0) ) {
303 _mesh->property( cut, e_it.h0() ) =
false;
304 _mesh->property( cut, e_it.h1() ) =
false;
310 while( !queue.empty() ) {
317 if ( _mesh->property(cut,hh) )
321 typename MeshT::FaceHandle fh = hh.
face();
324 if ( !fh.is_valid() ) {
329 if ( !fh.is_valid() )
336 lines.push_back(getIntersectionLoop(_mesh,fh.idx(),_planeNormal,_planePoint,closed) );
341 _mesh->remove_property( cut );
bool is_valid() const
The handle is valid iff the index is not negative.
VertexHandle from_vertex_handle(HalfEdgeHandle _h) const
Get the vertex the halfedge starts from.
VertexHandle to_vertex_handle(HalfEdgeHandle _h) const
Get the vertex the halfedge points to.
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 closest connected intersection between mesh and 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
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
PolyConnectivity::ConstFaceHalfedgeRange halfedges() const
Returns a range of halfedges of the face (PolyConnectivity::fh_range())
SmartFaceHandle face() const
Returns incident face of halfedge.
SmartVertexHandle from() const
Returns vertex at start of halfedge.
SmartHalfedgeHandle opp() const
Returns opposite halfedge handle.
SmartVertexHandle to() const
Returns vertex pointed to by halfedge.