VCG Library
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
vcg::tri::CoM< MeshType > Class Template Reference

Classes

struct  LaplacianFunctor
 LaplacianFunctor basic Laplacian smoothing functor. More...
 
class  Param
 Parameter class controlling the behavior of CoM algorithms. More...
 
struct  QualityDistanceFieldFunctor
 QualityDistanceFieldFunctor quality field based smoothing functor. More...
 

Public Types

enum  ControlPoints { AllVertices , EndsAndNodes , Selected }
 Which polyline vertices SetControlPoints() makes control points. More...
 
typedef MeshType::ScalarType ScalarType
 
typedef MeshType::CoordType CoordType
 
typedef MeshType::VertexType VertexType
 
typedef MeshType::VertexPointer VertexPointer
 
typedef MeshType::VertexIterator VertexIterator
 
typedef MeshType::EdgeIterator EdgeIterator
 
typedef MeshType::EdgeType EdgeType
 
typedef MeshType::FaceType FaceType
 
typedef MeshType::FacePointer FacePointer
 
typedef MeshType::FaceIterator FaceIterator
 
typedef Segment3< ScalarType > Segment3Type
 
typedef vcg::GridStaticPtr< FaceType, ScalarType > MeshGrid
 
typedef std::vector< std::pair< FaceType *, CoordType > > Location
 

Public Member Functions

 CoM (MeshType &_m)
 
FaceType * GetClosestFace (const CoordType &p)
 Get the closest face to a query point.
 
FaceType * GetClosestFaceIP (const CoordType &p, CoordType &ip)
 Get the closest face and its barycentric coordinates.
 
FaceType * GetClosestFaceIP (const CoordType &p, CoordType &ip, CoordType &in)
 Get the closest face, barycentric coordinates, and normal.
 
FaceType * GetClosestFacePoint (const CoordType &p, CoordType &closestP)
 Get the closest face and the closest point on it.
 
bool IsSnappedEdge (CoordType &ip, int &ei)
 Check if a barycentric coordinate is snapped to an edge.
 
bool IsSnappedVertex (CoordType &ip, int &vi)
 Check if a barycentric coordinate is snapped to a vertex.
 
VertexPointer FindVertexSnap (FacePointer fp, CoordType &ip)
 Find the vertex pointer for a vertex-snapped barycentric coordinate.
 
bool SnapPolyline (MeshType &poly)
 SnapPolyline snaps the vertexes of a polyline onto the base mesh.
 
void SetControlPoints (MeshType &poly, ControlPoints mode=EndsAndNodes)
 Choose the control points of a polyline (stored as its vertex selection).
 
int ConnectCrossings (MeshType &poly)
 Make the points where strands meet into junctions (opt-in).
 
void SelectUniformlyDistributed (MeshType &poly, int k)
 
void DecomposeNonManifoldPolyline (MeshType &poly, bool singSplitFlag=true)
 
void Init ()
 Initialize the CoM data structures for processing.
 
void SimplifyNullEdges (MeshType &poly)
 Remove duplicate/zero-length edges from a polyline.
 
int CollapseNullEdges (MeshType &poly)
 Merge the two ends of every zero-length polyline edge.
 
void Simplify (MeshType &poly)
 
void EvaluateHausdorffDistance (MeshType &poly, Distribution< ScalarType > &dist)
 
bool BarycentricSnap (CoordType &ip, const FaceType &f)
 Snap the barycentric coordinates of a point of face f onto a vertex or an edge.
 
ScalarType MaxSegDist (VertexType *v0, VertexType *v1, CoordType &farthestPointOnSurf, CoordType &farthestN, Distribution< ScalarType > *distanceDistribution=0)
 
void RefineCurveByDistance (MeshType &poly)
 RefineCurve.
 
void RefineCurveByBaseMesh (MeshType &poly)
 Make every polyline segment lie inside one face or along one edge of the base mesh, by inserting the exact points where it crosses the mesh edges.
 
bool RoundingSnap (CoordType &ip, const FaceType &f) const
 
Location Locate (const CoordType &p)
 
Location LocationFrom (FaceType *f, const CoordType &ip) const
 
bool OnCutSeam (const Location &loc) const
 
void TraceSegment (const CoordType &p, const CoordType &q, std::vector< CoordType > &crossings)
 
template<typename PositionFunctor >
void MoveAndProject (MeshType &poly, int iterNum, ScalarType moveWeight, ScalarType projectWeight, PositionFunctor &desiredPos)
 MoveAndProject.
 
void SmoothProject (MeshType &poly, int iterNum, ScalarType smoothWeight, ScalarType projectWeight)
 

Static Public Member Functions

static bool BarycentricSnap (CoordType &ip, const FaceType &f, ScalarType barThr, ScalarType distThr)
 BarycentricSnap() with explicit thresholds, e.g. rounding-level ones.
 
static void ThrowCutSeam (const CoordType &p)
 

Public Attributes

MeshType & base
 Reference to the base triangulated surface mesh.
 
MeshGrid uniformGrid
 Spatial acceleration structure for closest point queries.
 
Param par
 Parameters controlling algorithm behavior.
 

Friends

template<class >
class CoMEmbed
 

Member Typedef Documentation

◆ Location

template<class MeshType >
typedef std::vector<std::pair<FaceType *, CoordType> > vcg::tri::CoM< MeshType >::Location

Where a point is on the mesh: every face it belongs to, with its barycentric coordinates there. One face for a point inside a face, the two faces of an edge, or the faces around a vertex.

Member Enumeration Documentation

◆ ControlPoints

template<class MeshType >
enum vcg::tri::CoM::ControlPoints

Which polyline vertices SetControlPoints() makes control points.

Enumerator
AllVertices 

every vertex: the polyline is taken as it is, only projected and refined

EndsAndNodes 

the ends (degree 1) and the junctions (degree > 2): each strand is free

Selected 

the vertices already selected, left as they are

Constructor & Destructor Documentation

◆ CoM()

template<class MeshType >
vcg::tri::CoM< MeshType >::CoM ( MeshType &  _m)
inline

Constructor: initializes the CoM with a base mesh. It updates the bounding box of the base mesh first, because every default in Param is a fraction of its diagonal: a stale box would silently give tolerances of the wrong scale.

Member Function Documentation

◆ BarycentricSnap()

template<class MeshType >
bool vcg::tri::CoM< MeshType >::BarycentricSnap ( CoordType &  ip,
const FaceType &  f 
)
inline

Snap the barycentric coordinates of a point of face f onto a vertex or an edge.

Parameters
ipInput/Output: barycentric coordinates in f (summing to 1)
fThe face they refer to
Returns
true if the point is now on a vertex or an edge (at least one coordinate is 0)

A coordinate is set to 0 only if it is within Param::barycentricSnapThr of 0 and the snap moves the point by at most Param::maxSnapThr. The barycentric bound alone is only meaningful on well-shaped, uniformly sized triangles: on a large or skinny one it can move a point far, which the distance bound prevents; on tiny triangles the barycentric bound keeps a point from being snapped across them. Two coordinates at 0 put the point on a vertex. The remaining coordinates are renormalized so they sum to exactly 1. Setting either threshold to 0 disables snapping.

See also
IsSnappedVertex, IsSnappedEdge

◆ CollapseNullEdges()

template<class MeshType >
int vcg::tri::CoM< MeshType >::CollapseNullEdges ( MeshType &  poly)
inline

Merge the two ends of every zero-length polyline edge.

Returns
the number of edges collapsed

Vertices are merged only along the polyline, never because they happen to coincide: two strands passing through the same point stay two strands, and are not joined into a junction that smoothing would then treat as one. (Clean::RemoveDuplicateVertex, used here before, merged them.) Compacts poly and updates its VE adjacency.

◆ ConnectCrossings()

template<class MeshType >
int vcg::tri::CoM< MeshType >::ConnectCrossings ( MeshType &  poly)
inline

Make the points where strands meet into junctions (opt-in).

Returns
the number of junctions made

After CoMEmbed::SplitMeshWithPolyline() two strands that cross or touch each have a vertex at the same position. By default they stay separate strands; this merges every set of coinciding vertices into one and merges the edges two strands share, so the meeting points become part of the curve's topology; where the merged curve branches the vertex is a junction, and a control point.

◆ FindVertexSnap()

template<class MeshType >
VertexPointer vcg::tri::CoM< MeshType >::FindVertexSnap ( FacePointer  fp,
CoordType &  ip 
)
inline

Find the vertex pointer for a vertex-snapped barycentric coordinate.

Parameters
fpThe face containing the point
ipThe barycentric coordinate (should be snapped to a vertex)
Returns
Pointer to the snapped vertex, or nullptr if not vertex-snapped

◆ GetClosestFace()

template<class MeshType >
FaceType * vcg::tri::CoM< MeshType >::GetClosestFace ( const CoordType &  p)
inline

Get the closest face to a query point.

Parameters
pThe query point
Returns
Pointer to the closest face
Exceptions
vcg::MissingPreconditionExceptionif no face is within Param::gridBailout, as all the closest-face queries below

◆ GetClosestFaceIP() [1/2]

template<class MeshType >
FaceType * vcg::tri::CoM< MeshType >::GetClosestFaceIP ( const CoordType &  p,
CoordType &  ip 
)
inline

Get the closest face and its barycentric coordinates.

Parameters
pThe query point
ipOutput: barycentric coordinates of the closest point on the returned face
Returns
Pointer to the closest face

◆ GetClosestFaceIP() [2/2]

template<class MeshType >
FaceType * vcg::tri::CoM< MeshType >::GetClosestFaceIP ( const CoordType &  p,
CoordType &  ip,
CoordType &  in 
)
inline

Get the closest face, barycentric coordinates, and normal.

Parameters
pThe query point
ipOutput: barycentric coordinates of the closest point on the returned face
inOutput: normal at the closest point
Returns
Pointer to the closest face

◆ GetClosestFacePoint()

template<class MeshType >
FaceType * vcg::tri::CoM< MeshType >::GetClosestFacePoint ( const CoordType &  p,
CoordType &  closestP 
)
inline

Get the closest face and the closest point on it.

Parameters
pThe query point
closestPOutput: the 3D coordinates of the closest point on the surface
Returns
Pointer to the closest face

◆ Init()

template<class MeshType >
void vcg::tri::CoM< MeshType >::Init ( )
inline

Initialize the CoM data structures for processing.

This must be called after construction and whenever the base mesh is modified. It performs:

  • Face normal computation
  • Face-Face topology update
  • Spatial acceleration structure (uniform grid) construction
Note
Call this before using any polyline processing methods.
Warning
If the base mesh topology changes, call Init() again.

◆ IsSnappedEdge()

template<class MeshType >
bool vcg::tri::CoM< MeshType >::IsSnappedEdge ( CoordType &  ip,
int &  ei 
)
inline

Check if a barycentric coordinate is snapped to an edge.

Parameters
ipThe barycentric coordinate (must be snapped)
eiOutput: index (0,1,2) of the edge opposite to the zero coordinate
Returns
true if snapped to an edge (exactly one coordinate is 0, other two are positive)

Edge snapping means the point lies on one of the three edges of the triangle. Edge i is the edge from vertex i to vertex (i+1)%3, opposite to vertex (i+2)%3.

◆ IsSnappedVertex()

template<class MeshType >
bool vcg::tri::CoM< MeshType >::IsSnappedVertex ( CoordType &  ip,
int &  vi 
)
inline

Check if a barycentric coordinate is snapped to a vertex.

Parameters
ipThe barycentric coordinate (must be snapped)
viOutput: index (0,1,2) of the vertex with coordinate == 1.0
Returns
true if snapped to a vertex (one coordinate is 1.0, others are 0.0)

◆ MoveAndProject()

template<class MeshType >
template<typename PositionFunctor >
void vcg::tri::CoM< MeshType >::MoveAndProject ( MeshType &  poly,
int  iterNum,
ScalarType  moveWeight,
ScalarType  projectWeight,
PositionFunctor &  desiredPos 
)
inline

MoveAndProject.

Parameters
poly
iterNum
moveWeight[0..1] blend toward the desired position returned by the functor
projectWeight[0..1] blend toward the closest point on the surface
desiredPosfunctor: std::vector<CoordType>(const MeshType&)

Generic version of SmoothProject: the per-vertex desired position is supplied by a functor instead of being hard-coded as a Laplacian average.

◆ OnCutSeam()

template<class MeshType >
bool vcg::tri::CoM< MeshType >::OnCutSeam ( const Location &  loc) const
inline

Whether a border the point at loc lies on has a coincident twin border edge: the two sides of a cut, or of a seam where a file split its vertices. The surface is disconnected there but has no gap, and since CoM locates curve points by position it cannot tell the two sides apart; the trace stops as at a real border, and this only lets the error say which of the two it met (ThrowCutSeam). A linear scan: it runs once, on failure.

◆ RefineCurveByBaseMesh()

template<class MeshType >
void vcg::tri::CoM< MeshType >::RefineCurveByBaseMesh ( MeshType &  poly)
inline

Make every polyline segment lie inside one face or along one edge of the base mesh, by inserting the exact points where it crosses the mesh edges.

Parameters
polyThe polyline; its own vertices are snapped first (SnapPolyline), then kept

Each segment is traced across the mesh along its section by one plane (TraceSegment): in the current face the edge where it leaves is the first barycentric coordinate to reach zero, and the crossing point is made with that coordinate exactly zero, so it lies exactly on the edge. The trace then continues in the faces on the other side, through a vertex if it leaves through one, until it reaches a face that also holds the far end. Two strands traced through the same faces therefore keep their order along every edge they cross: close parallel curves stay parallel, which approximate crossing points (the bisection used here before) did not guarantee.

Exceptions
vcg::MissingPreconditionExceptionif a segment cannot be traced, e.g. one that leaves the surface across a border

◆ RefineCurveByDistance()

template<class MeshType >
void vcg::tri::CoM< MeshType >::RefineCurveByDistance ( MeshType &  poly)
inline

RefineCurve.

Parameters
polythe curve to be refined
uniformFlag

Make one pass of refinement for all the edges of the curve that are distant from the basemesh uses two parameters:

  • par.minRefEdgeLen
  • par.surfDistThr

◆ RoundingSnap()

template<class MeshType >
bool vcg::tri::CoM< MeshType >::RoundingSnap ( CoordType &  ip,
const FaceType &  f 
) const
inline

Snap at rounding level only: a point this close to a vertex or an edge is on it. Shared by the trace and by CoMEmbed, so both agree on where a curve point is.

By distance alone, with no barycentric bound: at rounding level a point within the distance of an edge is on it however small the triangle, and that distance is the same seen from either face of the edge, so a point found on an edge in one face is found on it again in the other. A barycentric bound depends on the face's shape: on a tiny triangle next to a vertex, one face put a point on an edge where its neighbour put it on another, and the curve embedding then found a segment in no face.

◆ SetControlPoints()

template<class MeshType >
void vcg::tri::CoM< MeshType >::SetControlPoints ( MeshType &  poly,
ControlPoints  mode = EndsAndNodes 
)
inline

Choose the control points of a polyline (stored as its vertex selection).

Call it once on the input curve, before smoothing or refining it. With EndsAndNodes the curve keeps its topology and its ends, and every strand between them is free to become a geodesic; a helix on a cylinder with fixed ends stays a helix, since the strand cannot unwind around the cylinder.

◆ SimplifyNullEdges()

template<class MeshType >
void vcg::tri::CoM< MeshType >::SimplifyNullEdges ( MeshType &  poly)
inline

Remove duplicate/zero-length edges from a polyline.

Parameters
polyThe polyline to simplify

Removes vertices that have collapsed to the same position.

◆ SnapPolyline()

template<class MeshType >
bool vcg::tri::CoM< MeshType >::SnapPolyline ( MeshType &  poly)
inline

SnapPolyline snaps the vertexes of a polyline onto the base mesh.

Parameters
poly
newVertVecthe vector of the indexes of the snapped vertices
Returns
true if it has modified the polyline

Polyline vertices can be snapped either on vertexes or on edges. Usually the only points that we should allow to not be snapped are the endpoints and non manifold points. Vertexes are colored according to their snapping state

◆ TraceSegment()

template<class MeshType >
void vcg::tri::CoM< MeshType >::TraceSegment ( const CoordType &  p,
const CoordType &  q,
std::vector< CoordType > &  crossings 
)
inline

The points where the segment from p to q crosses mesh edges, in order.

The segment is traced as the section of the surface by one plane: through p and q, containing the mean surface normal at the two ends. Every face then agrees on where the trace goes, since the plane is the same for all of them. (Projecting q onto each face plane in turn does not: on a curved surface two neighbouring faces can each say q lies across the other, and the trace bounces between them.)


The documentation for this class was generated from the following file: