23#ifndef VCL_SPACE_COMPLEX_MESH_POS_H
24#define VCL_SPACE_COMPLEX_MESH_POS_H
26#include <vclib/mesh.h>
46template<face::HasAdjacentFaces FaceType>
49 const FaceType* mFace =
nullptr;
51 const typename FaceType::VertexType* mVertex =
nullptr;
56 using VertexType = FaceType::VertexType;
63 MeshPos(
const FaceType* f,
short e) : mFace(f), mEdge(e)
66 mVertex = f->vertex(e);
70 MeshPos(
const FaceType* f,
const VertexType* v) : mFace(f), mVertex(v)
72 for (uint
i = 0;
i < f->vertexNumber();
i++)
73 if (f->vertex(
i) == v)
88 MeshPos(
const FaceType* f,
const VertexType* v,
short e) :
89 mFace(f), mVertex(v), mEdge(e)
107 static bool isValid(
const FaceType* f,
const VertexType* v,
short e)
109 if (f ==
nullptr || v ==
nullptr || e < 0)
111 if (!comp::isAdjacentFacesAvailableOn(*f))
113 return (
ushort) e < f->vertexNumber() &&
114 (v == f->vertex(e) || v == f->vertexMod(e + 1));
117 const FaceType* face()
const {
return mFace; }
119 const VertexType* vertex()
const {
return mVertex; }
121 short edge()
const {
return mEdge; }
123 const FaceType* adjFace()
const {
return mFace->adjFace(mEdge); }
125 const VertexType* adjVertex()
const
127 MeshPos<FaceType> tmpPos = *
this;
129 return tmpPos.vertex();
132 short adjEdge()
const
134 MeshPos<FaceType> tmpPos = *
this;
136 return tmpPos.edge();
152 return mFace ==
nullptr || mVertex ==
nullptr || mEdge < 0;
187 const FaceType*
nf = mFace->adjFace(mEdge);
190 mEdge =
nf->indexOfAdjFace(mFace);
195 const auto* v1 = mFace->vertexMod(
oldEdge + 1);
196 mEdge =
nf->indexOfEdge(
v0, v1);
219 if (mFace->vertexMod(mEdge) == mVertex) {
220 mVertex = mFace->vertexMod(mEdge + 1);
223 mVertex = mFace->vertexMod(mEdge);
233 if (mFace->vertexMod(mEdge + 1) == mVertex) {
234 mEdge = (mEdge + 1) % (
short) mFace->vertexNumber();
237 short n = mFace->vertexNumber();
238 mEdge = ((mEdge - 1) %
n +
n) %
287 bool onBorder =
false;
288 uint count = countAdjacentFacesToV(onBorder);
298 return mFace ==
op.mFace && mVertex ==
op.mVertex && mEdge ==
op.mEdge;
301 bool operator!=(
const MeshPos& op)
const {
return !(*
this == op); }
303 bool operator<(
const MeshPos& op)
const
305 if (mFace == op.mFace) {
306 if (mEdge == op.mEdge)
307 return mVertex < op.mVertex;
309 return mEdge < op.mEdge;
312 return mFace < op.mFace;
317 uint countAdjacentFacesToV(
bool& onBorder)
const
322 MeshPos<FaceType> mp = *
this;
326 mp.nextEdgeAdjacentToV();
330 if (mp.isEdgeOnBorder())
A class representing a box in N-dimensional space.
Definition box.h:46
The MeshPos class describes a "Position in a Mesh" that can be identified with a triplet of Face-Vert...
Definition mesh_pos.h:48
uint numberOfAdjacentFacesToV() const
Returns the number of adjacent faces to the current vertex of this MeshPos. This works also for verti...
Definition mesh_pos.h:285
MeshPos()=default
Empty constructor that creates a null (invalid) MeshPos.
bool isEdgeOnBorder() const
Returns true if the current edge of this MeshPos is on a border. To check if is on border,...
Definition mesh_pos.h:162
void flipVertex()
Moves this MeshPos to the vertex adjacent to the current vertex that shares the same face and the sam...
Definition mesh_pos.h:217
bool isCCWOriented() const
Returns true if the current vertex of the MeshPos corresponts to the first vertex of the current edge...
Definition mesh_pos.h:172
MeshPos(const FaceType *f, const VertexType *v, short e)
Constructor that creates a MeshPos with the given facem vertex and edge. The given triplet must descr...
Definition mesh_pos.h:88
static bool isValid(const FaceType *f, const VertexType *v, short e)
Helper function to check if a MeshPos is valid, that is if:
Definition mesh_pos.h:107
bool nextEdgeOnBorderAdjacentToV()
Moves the MeshPos to the next edge on border that is adjacent to the current vertex of the MeshPos....
Definition mesh_pos.h:268
bool flipFace()
Moves this MeshPos to the face adjacent to the current face that shares the same vertex and the same ...
Definition mesh_pos.h:185
bool isNull() const
Returns true if this is null, non initialized, MeshPos. The result of this function is different from...
Definition mesh_pos.h:150
void nextEdgeAdjacentToV()
Moves this MeshPos to the next edge that is adjacent to the current vertex of the MeshPos....
Definition mesh_pos.h:254
void flipEdge()
Moves this MeshPos to the edge adjacent to the current edge that shares the same face and the same ve...
Definition mesh_pos.h:231
bool isValid() const
Returns true if this MeshPos is valid.
Definition mesh_pos.h:143