algorithms::TriangleSurface Class Reference

Class representing a triangulated surface. More...

#include <algorithms/triangle_growth.h>

List of all members.

Classes

struct  Cell
 Type of a cell, i.e. More...
struct  Position
 Structure describing the position of a point on a triangulated surface, relatively to this surface. More...
struct  Vertex
 Type of a vertex, i.e. More...

Public Types

typedef
vvcomplex::VVComplexGraph
< Cell, Vertex
CellComplex
 Type of the complex graph holding the triangle structure.

Public Member Functions

Point3d center3d (int face) const
 Returns the coordinates of the center of the face.
Position centerPosition (int face) const
 Returns the position of the center of the face.
void clear ()
 Reset the structure .
std::vector< Positioncontour () const
 Return a description of the contour of the surface independent of the time.
 EXPORT_COMPLEX_VERTICES (CellComplex)
Point3d normal (const Position &pos) const
 Get the normal to the surface at position pos.
Point3d point3d (const Position &pos) const
 Get the 3d position from the position relative to the triangular surface.
Position position (const Position &start, const Point3d &pos) const
 Same as position(const Point3d&), but specifies a starting point.
Position position (const Point3d &pos) const
 Give the position, relatively to the surface, of the point closest to pos.
Point3d smoothNormal (const Position &pos) const
 Get the "smoothed" normal.
Position vector (const Position &ref, const Point3d &pos) const
 Creates a vector attached to the surface.
Position vector (const Point3d &ref, const Point3d &pos) const
 Creates a vector attached to the surface.
Point3d vector3d (const Position &pos) const
 Return the vector represented by pos.

Public Attributes

std::vector< cell > faces
 List of faces.
Point3d pmax
Point3d pmin
 Bounding box of the surface.
CellComplex S
 Complex graph holding the triangle structure.
double time
 Time of this triangle surface.
int time_index
std::vector< junction > vertices
 List of vertices.

Protected Types

typedef std::unordered_set< cell > cell_set_t

Protected Member Functions

Position find_position (const cell &c, const Point3d &pos, cell_set_t &visited) const
std::vector< PositionnextContourVertex (const junction &first, const cell &c, const junction &j, std::vector< Position > acc) const
Position vertexPosition (const junction &j) const

Detailed Description

Class representing a triangulated surface.

Definition at line 31 of file triangle_growth.h.


Member Typedef Documentation

Type of the complex graph holding the triangle structure.

Definition at line 59 of file triangle_growth.h.


Member Function Documentation

Point3d algorithms::TriangleSurface::center3d ( int  face  )  const

Returns the coordinates of the center of the face.

Effectively, this will be the points of barycentric coordinates (1,1,1)/3 on the face.

Definition at line 99 of file triangle_growth.cpp.

References graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::anyIn(), faces, graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::nextTo(), graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::reference(), and S.

00100   {
00101     const cell& f = S.reference(faces[face]);
00102     const junction& j1 = S.anyIn(f);
00103     const junction& j2 = S.nextTo(f, j1);
00104     const junction& j3 = S.nextTo(f, j2);
00105     return (j1->pos + j2->pos + j3->pos)/3;
00106   }

TriangleSurface::Position algorithms::TriangleSurface::centerPosition ( int  face  )  const

Returns the position of the center of the face.

Effectively, this will be the points of barycentric coordinates (1,1,1)/3 on the face.

Definition at line 90 of file triangle_growth.cpp.

References graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::anyIn(), faces, graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::nextTo(), graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::reference(), and S.

00091   {
00092     const cell& f = S.reference(faces[face]);
00093     const junction& j1 = S.anyIn(f);
00094     const junction& j2 = S.nextTo(f, j1);
00095     const junction& j3 = S.nextTo(f, j2);
00096     return Position(Point3d(1,1,1)/3, j1->id, j2->id, j3->id, face);
00097   }

void algorithms::TriangleSurface::clear (  ) 

Reset the structure .

..

Definition at line 126 of file triangle_growth.cpp.

References graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::clear(), faces, S, time, and vertices.

00127   {
00128     S.clear();
00129     vertices.clear();
00130     faces.clear();
00131     time = -HUGE_VAL;
00132     time_index = -1;
00133   }

std::vector< TriangleSurface::Position > algorithms::TriangleSurface::contour (  )  const

Return a description of the contour of the surface independent of the time.

Definition at line 917 of file triangle_growth.cpp.

References faces, and forall.

Referenced by algorithms::TriangleGrowth::contour().

00918   {
00919     std::vector<Position> result;
00920     switch(faces.size())
00921     {
00922       case 0:
00923         return result; // No contour !
00924       case 1:
00925         {
00926           const cell& c = S.any_cell();
00927           const junction& j1 = S.anyIn(c);
00928           const junction& j2 = S.nextTo(c, j1);
00929           const junction& j3 = S.nextTo(c, j2);
00930           result.push_back(vertexPosition(j1));
00931           result.push_back(vertexPosition(j2));
00932           result.push_back(vertexPosition(j3));
00933         }
00934         break;
00935       case 2:
00936         {
00937           const cell& c1 = S.reference(faces[0]);
00938           const cell& c2 = S.reference(faces[1]);
00939           forall(const junction& j, S.neighbors(c1))
00940           {
00941             if(S.valence(j) == 1)
00942             {
00943               result.push_back(vertexPosition(S.prevTo(c1, j)));
00944               result.push_back(vertexPosition(j));
00945               result.push_back(vertexPosition(S.nextTo(c1, j)));
00946               break;
00947             }
00948           }
00949           forall(const junction& j, S.neighbors(c2))
00950           {
00951             if(S.valence(j) == 1)
00952             {
00953               result.push_back(vertexPosition(j));
00954               break;
00955             }
00956           }
00957         }
00958         break;
00959       default:
00960         // First, find one point of the contour
00961         forall(const junction& j, S.junctions())
00962         {
00963           if(S.border(j))
00964           {
00965             result.push_back(vertexPosition(j));
00966             forall(const cell& c, S.neighbors(j))
00967             {
00968               const junction& jn = S.nextTo(c, j);
00969               int nb_common_cells = 0;
00970               forall(const cell& cn, S.neighbors(jn))
00971               {
00972                 if(S.edge(j, cn))
00973                   nb_common_cells++;
00974               }
00975               if(nb_common_cells == 1)
00976               {
00977                 result.push_back(vertexPosition(jn));
00978                 return nextContourVertex(j, c, jn, result);
00979               }
00980             }
00981             return result;
00982           }
00983         }
00984     }
00985     return result; // Should not be reached!
00986   }

Point3d algorithms::TriangleSurface::normal ( const Position pos  )  const

Get the normal to the surface at position pos.

Definition at line 70 of file triangle_growth.cpp.

References faces.

00071   {
00072     return faces[pos.face]->normal;
00073   }

Point3d algorithms::TriangleSurface::point3d ( const Position pos  )  const

Get the 3d position from the position relative to the triangular surface.

Definition at line 62 of file triangle_growth.cpp.

References geometry::barycentricToCartesian(), and vertices.

Referenced by vector3d().

00063   {
00064     const Point3d& p1 = vertices[pos.v1]->pos;
00065     const Point3d& p2 = vertices[pos.v2]->pos;
00066     const Point3d& p3 = vertices[pos.v3]->pos;
00067     return geometry::barycentricToCartesian(pos.barycentric, p1, p2, p3);
00068   }

TriangleSurface::Position algorithms::TriangleSurface::position ( const Position start,
const Point3d &  pos 
) const

Same as position(const Point3d&), but specifies a starting point.

The position will be searched, starting from the start position and going from triangle to triangle. The first traversed triangle in which pos can be projected will be used as reference.

Note:
This method works only for surfaces regular enough, at least from start to pos.

Definition at line 292 of file triangle_growth.cpp.

References faces, and position().

00293   {
00294     if(start)
00295     {
00296       cell_set_t visited;
00297       const cell& c = faces[start.face];
00298       visited.insert(c);
00299       return find_position(c, pos, visited);
00300     }
00301     else
00302       return position(pos);
00303   }

TriangleSurface::Position algorithms::TriangleSurface::position ( const Point3d &  pos  )  const

Give the position, relatively to the surface, of the point closest to pos.

Definition at line 135 of file triangle_growth.cpp.

References graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::anyIn(), geometry::cartesianToBarycentric(), forall, graph::VVBiGraph< Vertex1Content, Vertex2Content, Edge1Content, Edge2Content_, compact >::nextTo(), geometry::projectPointOnTriangle(), S, and vvassert.

Referenced by position(), and vector().

00136   {
00137     Position result;
00138     double best_dist = HUGE_VAL;
00139     cell best_cell(0);
00140     Point3d best_pos;
00141     OUT("New matching for point " << pos);
00142     forall(const cell& c, S.cells())
00143     {
00144       const junction& v1 = S.anyIn(c);
00145       const junction& v2 = S.nextTo(c, v1);
00146       const junction& v3 = S.nextTo(c, v2);
00147       const Point3d& p1 = v1->pos;
00148       const Point3d& p2 = v2->pos;
00149       const Point3d& p3 = v3->pos;
00150 //      if(util::normsq(pos-p1) > max_sq_dist and
00151 //         util::normsq(pos-p2) > max_sq_dist and
00152 //         util::normsq(pos-p3) > max_sq_dist)
00153 //        continue;
00154       double s;
00155       Point3d u = geometry::projectPointOnTriangle(pos, p1, p2, p3, s);
00156       if(best_dist > s)
00157       {
00158         OUT("Improved distance to: " << s << " for cell " << c.id());
00159         best_dist = s;
00160         best_cell = c;
00161         best_pos = u;
00162       }
00163     }
00164     OUT("Best distance = " << best_dist);
00165     // Now, find the barycentric coordinates
00166     vvassert(best_cell);
00167     if(best_cell)
00168     {
00169       const junction& v1 = S.anyIn(best_cell);
00170       const junction& v2 = S.nextTo(best_cell, v1);
00171       const junction& v3 = S.nextTo(best_cell, v2);
00172       const Point3d& p1 = v1->pos;
00173       const Point3d& p2 = v2->pos;
00174       const Point3d& p3 = v3->pos;
00175       result.barycentric = geometry::cartesianToBarycentric(best_pos, p1, p2, p3);
00176       result.v1 = v1->id;
00177       result.v2 = v2->id;
00178       result.v3 = v3->id;
00179       result.face = best_cell->id;
00180     }
00181     return result;
00182   }

Point3d algorithms::TriangleSurface::smoothNormal ( const Position pos  )  const

Get the "smoothed" normal.

To each vertex is associated a normal, mostly used for visualization. This function will interpolate between these specified normals rather that using the actual normal of the triangle.

Definition at line 75 of file triangle_growth.cpp.

References geometry::barycentricToCartesian(), and vertices.

00076   {
00077     const Point3d& p1 = vertices[pos.v1]->normal;
00078     const Point3d& p2 = vertices[pos.v2]->normal;
00079     const Point3d& p3 = vertices[pos.v3]->normal;
00080     return geometry::barycentricToCartesian(pos.barycentric, p1, p2, p3);
00081   }

TriangleSurface::Position algorithms::TriangleSurface::vector ( const Position ref,
const Point3d &  pos 
) const

Creates a vector attached to the surface.

Definition at line 108 of file triangle_growth.cpp.

References geometry::cartesianToBarycentric(), and vertices.

00109   {
00110     const Point3d& p1 = vertices[ref.v1]->pos;
00111     const Point3d& p2 = vertices[ref.v2]->pos;
00112     const Point3d& p3 = vertices[ref.v3]->pos;
00113     const Point3d& pt = p1 + pos;
00114     const Point3d& vec = geometry::cartesianToBarycentric(pt, p1, p2, p3);
00115     Position result = ref;
00116     result.barycentric = vec;
00117     return result;
00118   }

TriangleSurface::Position algorithms::TriangleSurface::vector ( const Point3d &  ref,
const Point3d &  pos 
) const

Creates a vector attached to the surface.

Definition at line 120 of file triangle_growth.cpp.

References position().

00121   {
00122     const Position& ref_p = position(ref);
00123     return vector(ref_p, pos);
00124   }

Point3d algorithms::TriangleSurface::vector3d ( const Position pos  )  const

Return the vector represented by pos.

The vector is such that its orientation and size are deformed with the surface. Also, the vector will always be in the plane of the triangle it is defined on.

Definition at line 83 of file triangle_growth.cpp.

References point3d(), and vertices.

00084   {
00085     const Point3d& p = point3d(pos);
00086     const Point3d& ref = vertices[pos.v1]->pos;
00087     return p-ref;
00088   }


Member Data Documentation

List of faces.

Definition at line 186 of file triangle_growth.h.

Referenced by center3d(), centerPosition(), clear(), contour(), normal(), and position().

Bounding box of the surface.

Definition at line 189 of file triangle_growth.h.

Complex graph holding the triangle structure.

Definition at line 63 of file triangle_growth.h.

Referenced by center3d(), centerPosition(), clear(), and position().

Time of this triangle surface.

Definition at line 180 of file triangle_growth.h.

Referenced by clear(), and algorithms::TriangleGrowth::surface().

List of vertices.

Definition at line 184 of file triangle_growth.h.

Referenced by clear(), point3d(), smoothNormal(), vector(), and vector3d().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:04 2013 for VVE by  doxygen 1.6.3