Public Member Functions | Public Attributes | Friends

MNFace Class Reference

This reference page is linked to from the following overview topics: MNMesh Edges, MNMesh Note on Debugging.


Search for all occurrences

Detailed Description

The face structure used with the MNMesh mesh.

MNFace are not necessarily triangles. They also may contain hidden vertices which are used in converting the face back to triangles. This triangulation is always maintained in the face.

See also:
FlagUser, MNFace, BitArray.

#include <mnmesh.h>

Inheritance diagram for MNFace:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  MNFace ()
  Constructor.
  MNFace (int d)
  Constructor.
DllExport  MNFace (const MNFace *from)
  Constructor.
  ~MNFace ()
  Frees all arrays.
DllExport void  Init ()
  Initialize the face.
DllExport void  SetDeg (int d)
  Set the number of edges and vertices this face has.
DllExport void  Clear ()
  Frees all arrays, setting them to NULL, and resets degree.
int  TriNum ()
  Returns the number of triangles in this face.
DllExport int  FindTriPoint (int edge)
  Given the index of a particular edge, this routine returns the point (distinct from edge and (edge+1)deg) that forms a triangle with the edge, given the current scheme of diagonals.
DllExport int  FindTriPoint (int a, int b)
  Given two verts that form a diagonal in the polygon, this method finds the vertex between them that connects by a diagonal or an outer edge to both of them.
DllExport void  GetTriangles (Tab< int > &tri)
  This method fills in the table with the full triangulation for the face, based on the internal diagonal list.
DllExport void  SetAlloc (int d)
  Allocates enough memory in the arrays for the face to have degree d, but does not actually set the degree.
DllExport void  MakePoly (int fdeg, int *vv, bool *vis=NULL, bool *sel=NULL)
  Makes this face into a polygon with the specified vertices and other information.
DllExport void  Insert (int pos, int num=1)
  Inserts space for more vertices and edges on this face.
DllExport bool  Delete (int pos, int num=1, int edir=1, bool fixtri=TRUE)
  Deletes vertices & edges from this face.
DllExport void  RotateStart (int newstart)
  Re-indexes the vertices and edges so that the vertex in position newstart becomes the new first vertex.
DllExport void  Flip ()
  Reverses order of verts, effectively inverting the face.
DllExport int  VertIndex (int vv, int ee=-1)
  Returns the position of vertex vv in this face's list of vertices.
DllExport int  EdgeIndex (int ee, int vv=-1)
  Returns the position of edge ee in this face's list of edges.
DllExport void  ReplaceVert (int ov, int nv, int ee=-1)
  Replaces vertex ov with vertex nv in the list of vertices.
DllExport void  ReplaceEdge (int oe, int ne, int vv=-1)
  Replaces edge oe with edge ne in the list of edges.
DllExport MNFace operator= (const MNFace &from)
  Assignment operator.
DllExport bool  operator== (const MNFace &from)
  Comparison operator.
int &  operator[] (int i)
  Access operator.
const int &  operator[] (int i) const
  Access operator.
DllExport void  MNDebugPrint (bool triprint=FALSE)
  Uses DebugPrint to print out face information to the Debug Results window in DevStudio.
DllExport IOResult  Save (ISave *isave)
DllExport IOResult  Load (ILoad *iload)

Public Attributes

int  deg
  This is the degree: the number of vertices and edges that this face has.
int *  vtx
  This is the list of vertices that make up the corners of this face.
int *  edg
  This is the list of edges that border this face, in order.
int *  diag
  This is where the triangulation is stored.
DWORD  smGroup
  This contains the smoothing groups assigned to this face.
MtlID  material
  This is the material ID assigned to this face.
int  track
BitArray  visedg
  Contains a visibility bit for each edge on this face.
BitArray  edgsel
  Contains a selection bit for each edge on this face.
BitArray  bndedg
  Boundary Edges.

Friends

class  MNMesh

Constructor & Destructor Documentation

MNFace ( ) [inline]

Constructor.

Initializes the face's arrays to NULL.

{ Init(); }
MNFace ( int  d ) [inline]

Constructor.

Initializes the face's degree to d and allocates space for all the arrays.

{ Init(); SetDeg (d); }
DllExport MNFace ( const MNFace from )

Constructor.

Copies flags, smoothing groups, and material from "from", but initializes the face's arrays to NULL and degree to 0.

~MNFace ( ) [inline]

Frees all arrays.

{ Clear(); }

Member Function Documentation

DllExport void Init ( )

Initialize the face.

DllExport void SetDeg ( int  d )

Set the number of edges and vertices this face has.

Parameters:
int d

Number of vertices and edges.
DllExport void Clear ( )

Frees all arrays, setting them to NULL, and resets degree.

int TriNum ( ) [inline]

Returns the number of triangles in this face.

{ return deg-2; }
DllExport int FindTriPoint ( int  edge )

Given the index of a particular edge, this routine returns the point (distinct from edge and (edge+1)deg) that forms a triangle with the edge, given the current scheme of diagonals.

Parameters:
int edge

An index into the vertex array (in the range 0 to deg-1) that indicates the starting vertex of the edge. (In other words, the edge falls between vertex vtx[edge] and vtx[(edge+1)deg].)
Returns:
The index of the desired vertex, again in the (0,deg-1) range, or edge if there's an error.
DllExport int FindTriPoint ( int  a,
int  b 
)

Given two verts that form a diagonal in the polygon, this method finds the vertex between them that connects by a diagonal or an outer edge to both of them.

(Here, "between them" means after a and before b in sequence around the outside of the polygon. If we have an octagon where a=6 and b=2, the result would be 7, 0, or 1. To get the other result, in the 3,4,5 range, call the method with a=2 and b=6.)

Parameters:
int a, b

Two vertices, "internally indexed" in the 0 to deg-1 range. This method is only guaranteed to work if the vertices share a diagonal. (Otherwise, there may be no solution.)
Returns:
The index of the desired vertex, again in the (0,deg-1) range, or a if there's an error.
DllExport void GetTriangles ( Tab< int > &  tri )

This method fills in the table with the full triangulation for the face, based on the internal diagonal list.

The table is set to size (deg-2)*3.

Parameters:
Tab<int> &tri

The table of triangles.
DllExport void SetAlloc ( int  d )

Allocates enough memory in the arrays for the face to have degree d, but does not actually set the degree.

If the arrays are already large enough (or larger), it does not reallocate them. You generally don't need to use this method separately; MakePoly, Insert, and other methods which may require additional memory will call this if needed.

DllExport void MakePoly ( int  fdeg,
int *  vv,
bool *  vis = NULL,
bool *  sel = NULL 
)

Makes this face into a polygon with the specified vertices and other information.

This routine also supplies a default triangulation for the face; however, since this MNFace-level routine cannot access the vertex positions contained in the parent MNMesh, this triangulation may not work for non-convex faces. If the face may not be convex, a call to MNMesh::RetriangulateFace for this face will correct the triangulation.

Parameters:
int fdeg

The degree to set this face to.

int *vv

The list of vertices for this face. There must be at least fdeg of these. These values should be indices into the parent MNMesh's array of MNVerts.

bool *vis=NULL

The edge visibility flags for the edges of this face. If this is NULL, it is ignored; otherwise, there must be at least fdeg of these. vis[i] represents the visibility of the edge going from vv[i] to vv[(i+1)fdeg]. See the MNMesh note on edge selection & visibility for more information.

bool *sel=NULL

The edge selection flags for the edges of this face. If this is NULL, it is ignored; otherwise, there must be at least fdeg of these. sel[i] represents the selection bit of the edge going from vv[i] to vv[(i+1)fdeg]. See the MNMesh note on edge selection & visibility for more information.
DllExport void Insert ( int  pos,
int  num = 1 
)

Inserts space for more vertices and edges on this face.

This is used, for example, when two faces are joined, to add room for the vertices & edges of one face to the other. This routine also renumbers the existing vertices and corrects the existing face triangulation, although it cannot provide the triangulation for the new vertices. It reserves space for the new triangles at the end of the triangle array. If you do not want to compute the triangulation for the new vertices yourself, you may use the MNMesh RetriangulateFace method after filling in the new vertices.

Parameters:
int pos

The location within the face where the new vertices and edges should be added.

int num

The number of new vertices and edges.
DllExport bool Delete ( int  pos,
int  num = 1,
int  edir = 1,
bool  fixtri = TRUE 
)

Deletes vertices & edges from this face.

This routine also corrects the face triangulation, removing those triangles that include the deleted edges and re-indexing the rest. However, delete may cause the triangulation to become invalid, by causing one or more of the corrected triangles to have a flipped normal.

Parameters:
int pos

The position of the first vertex to be deleted.

int num=1

The number of vertices & edges to delete.

int edir=1

There are two choices for the edges to be deleted: we can delete the edges going from pos to pos+1, pos+1 to pos+2, ... pos+num-1 to pos+num, or we can delete pos-1 to pos, pos to pos+1, ... pos+num-2 to pos+num-1. (pos+num-1 is the last vertex deleted.) That is to say, we can delete the edges "before" the vertices we're deleting, or we can delete the edges "after" them. If edir is positive, we delete the edges after the vertices. If it's negative, we delete the edges before. Keep in mind that this also affects edge visibility and selection information on this face.

bool fixtri=TRUE

This argument indicates how far Delete should go in fixing the triangulation. Delete will always correct the values of the tri array to correspond to the reduced-degree face. If fixtri is true, it will also delete those triangles that have collapsed because they had two vertices in the deleted region. If not, it will leave these triangles with overlapping vertices, as in (0,0,2).

Returns:
Delete returns TRUE if fixtri is FALSE. If fixtri is TRUE, Delete will return TRUE if it successfully corrected the triangulation, or FALSE if there was a problem. If FALSE is returned, the triangulation will need to be revised with a call to RetriangulateFace.
DllExport void RotateStart ( int  newstart )

Re-indexes the vertices and edges so that the vertex in position newstart becomes the new first vertex.

Triangulation is also corrected. Mapping coordinates and vertex colors are corrected automatically.

DllExport void Flip ( )

Reverses order of verts, effectively inverting the face.

vtx[0] remains unchanged, but vertex deg-1 becomes vertex 1, etc. Note that this operation wreaks havoc on nearby edges and should be used with caution.

DllExport int VertIndex ( int  vv,
int  ee = -1 
)

Returns the position of vertex vv in this face's list of vertices.

For a given face fc, if fc.vtx[i] = vv, fc.VertIndex (vv) = i. Sometimes a single vertex from the MNMesh's MNVert list can be referenced more than once by a single face. The picture below illustrates this problem. The small triangle is actually outside of the face, and the vertex at the top of it is referenced twice by the face. Thus an additional edge parameter can be accepted. If ee is -1, it is ignored, and the first instance of vv is used. If ee>-1, this method looks for the instance of vv that starts out edge ee. Thus if fc.vtx[i] = vv and fc.vtx[j] = vv, but fc.edg[i] != ee and fc.edg[j] = ee, j is returned. IMPORTANT: If no vertex is found matching the given parameters, this method generates an assertion failure. Please be sure that vertex vv is actually on the face (and that edge ee follows it if ee is not -1) before using this method.

DllExport int EdgeIndex ( int  ee,
int  vv = -1 
)

Returns the position of edge ee in this face's list of edges.

For a given face fc, if fc.edg[i] = ee, fc.EdgeIndex (ee) = i. Sometimes a single edge from the MNMesh's MNEdge list can be referenced more than once by a single face. The small rectangle is actually outside of the face, and the edge above it is referenced twice by the face, once in each direction. Thus an additional vertex parameter can be accepted. If vv is -1, it is ignored, and the first instance of ee is used. If vv>-1, this method looks for the instance of ee that starts out with vertex vv. Thus if fc.edg[i] = ee and fc.edg[j] = ee, but fc.vtx[i] != vv and fc.vtx[j] = vv, j is returned. IMPORTANT: If no edge is found matching the given parameters, this method generates an assertion failure. Please be sure that edge ee is actually on the face (and that vertex vv follows it if vv is not -1) before using this method.

DllExport void ReplaceVert ( int  ov,
int  nv,
int  ee = -1 
)

Replaces vertex ov with vertex nv in the list of vertices.

It is possible for a face to reference the same vertex more than once, however the combination of a vertex followed by a specified edge is unique. Therefore if ee<0, all instances of ov are replaced by nv, but if not, only the instance of ov followed by ee is replaced.

DllExport void ReplaceEdge ( int  oe,
int  ne,
int  vv = -1 
)

Replaces edge oe with edge ne in the list of edges.

It is possible for a face to reference the same edge twice, however the combination of an edge preceded by a specified vertex is unique. Therefore if vv<0, all instances of oe are replaced by ne, but if not, only the instance of oe preceded by vv is replaced.

DllExport MNFace& operator= ( const MNFace from )

Assignment operator.

Copies all information from "from", including triangulation, hidden vertices, flags, smoothing & material info, and "track".

DllExport bool operator== ( const MNFace from )

Comparison operator.

int& operator[] ( int  i ) [inline]

Access operator.

{ return vtx[i]; }
const int& operator[] ( int  i ) const [inline]

Access operator.

{ return vtx[i]; }  
DllExport void MNDebugPrint ( bool  triprint = FALSE )

Uses DebugPrint to print out face information to the Debug Results window in DevStudio.

The information consists of the vertices and edges used by this face. It is generally a good idea to put in a DebugPrint immediately before this with the index of the edge, so you know which one is being printed out:

    DebugPrint(_M("Face %d: "), fid);
    F(fid)->MNDebugPrint();
Parameters:
bool triprint=FALSE

Print out triangulation information.

bool hinfo=TRUE

Print out hidden vertex information.
DllExport IOResult Save ( ISave isave )
DllExport IOResult Load ( ILoad iload )

Friends And Related Function Documentation

friend class MNMesh [friend]

Member Data Documentation

int deg

This is the degree: the number of vertices and edges that this face has.

int* vtx

This is the list of vertices that make up the corners of this face.

Each value is an index into the parent MNMesh's list of MNVerts.

int* edg

This is the list of edges that border this face, in order.

Each edg[i] goes between vtx[i] and vtx[(i+1)deg]. Each value is an index into the parent MNMesh's list of MNEdges. These values may not be valid if the MNMesh's MN_MESH_FILLED_IN flag is not set.

int* diag

This is where the triangulation is stored.

The number of triangles in a face is given by deg - 2 + hdeg*2. This array contains three times this number, for all the corners of all the sub-triangles. The triangle values are indices into the vtx and hvtx arrays of this face. Hidden vertices are indicated by values less than zero: hvtx[i] is represented by -1-i. Thus a triangle (1, 2, -2) would represent a triangle using vtx[1], vtx[2], and hvtx[-1]. The diag array's allocated size is always (dalloc-3)*2. If dalloc==3 (triangle), this pointer is NULL.

DWORD smGroup

This contains the smoothing groups assigned to this face.

MtlID material

This is the material ID assigned to this face.

int track

Contains a visibility bit for each edge on this face.

See the MNMesh note on edge selection & visibility for more information.

Contains a selection bit for each edge on this face.

See the MNMesh note on edge selection & visibility for more information.

Boundary Edges.


MNFace MNFace MNFace MNFace MNFace MNFace MNFace MNFace MNFace MNFace
MNFace MNFace MNFace MNFace MNFace MNFace MNFace MNFace MNFace MNFace