NL3D::CMRMSewingMesh Class Reference

#include <mrm_internal.h>


Detailed Description

An internal polygon with LOD information for Interface system

Definition at line 327 of file mrm_internal.h.

Public Member Functions

void build (const CMesh::CInterface &meshInt, uint nWantedLods, uint divisor)
sint getNumCollapseEdge (uint lod) const
 get the number of edge to collapse for a lod

sint mustCollapseEdge (uint lod, const CMRMEdge &edge, uint &vertToCollapse) const

Private Attributes

std::vector< CLod_Lods


Member Function Documentation

void NL3D::CMRMSewingMesh::build const CMesh::CInterface meshInt,
uint  nWantedLods,
uint  divisor
 

Build a MRM sewing mesh from a CMeshBuild interface.

Definition at line 67 of file mrm_internal.cpp.

References NLMISC::CVector::norm(), NLMISC::CVector::normalize(), sint, uint, and NL3D::CMesh::CInterface::Vertices.

00068 {
00069         /* The polygon is MRM-egde-like reduced (pop an edge when needed)
00070                 At each lod we store what edge is collapsed.
00071         */
00072         _Lods.clear();
00073         _Lods.resize(nWantedLods);
00074 
00075         // build edge list
00076         std::vector<CMRMEdge>   edgeList;
00077         uint    nMaxEdges= meshInt.Vertices.size();
00078         edgeList.resize(nMaxEdges);
00079         for(uint i=0;i<nMaxEdges;i++)
00080         {
00081                 edgeList[i].v0= i;
00082                 edgeList[i].v1= (i+1)%nMaxEdges;
00083         }
00084 
00085         // build how many edges the coarsest lod will have. At least 3 edge for a correct cross section
00086         sint    nBaseEdges= nMaxEdges/divisor;
00087         nBaseEdges=max(nBaseEdges,3);
00088 
00089         // must fill all LODs, from end to start. do not proces last lod since it will be the coarsest mesh (no collapse)
00090         for(uint lod=nWantedLods-1;lod>0;lod--)
00091         {
00092                 // Linear.
00093                 sint    nCurEdges= (sint)floor( 0.5f + nBaseEdges + (nMaxEdges-nBaseEdges) * (float)(lod-1)/(nWantedLods-1) );
00094                 nCurEdges=max(nCurEdges,3);
00095 
00096                 // the current edge list is reduced until same size as wanted
00097                 while(nCurEdges<(sint)edgeList.size())
00098                 {
00099                         // search the smallest edge
00100                         float   bestDist= FLT_MAX;
00101                         uint    bestEdgeId= 0;
00102                         for(uint j=0;j<edgeList.size();j++)
00103                         {
00104                                 uint    precEdgeId= (j + edgeList.size() -1) % edgeList.size();
00105                                 CVector edgeDelta= (meshInt.Vertices[edgeList[j].v1].Pos - meshInt.Vertices[edgeList[j].v0].Pos);
00106 
00107                                 // compute dist between 2 verts
00108                                 float   dist= edgeDelta.norm();
00109 
00110                                 // compute dir of prec and cur edges
00111                                 CVector curEdgeDir= edgeDelta;
00112                                 CVector precEdgeDir= (meshInt.Vertices[edgeList[precEdgeId].v1].Pos - meshInt.Vertices[edgeList[precEdgeId].v0].Pos);
00113                                 curEdgeDir.normalize();
00114                                 precEdgeDir.normalize();
00115 
00116                                 // compute how linear they are from -1 to 1.
00117                                 float   angularPart= curEdgeDir * precEdgeDir;
00118 
00119                                 /* The more the edge is linear to the previous edge, the more we can collapse it.
00120                                         If totaly linear (curEdgeDir*precEdgeDir==1), it should be a good idea to collapse it now.
00121                                         But the fact is that this is an interface and we don't know what kind of mesh share those edges
00122                                         (I mean it is possible that neighbors faces are absolutely not coplanar).
00123                                         So don't add to much importance on Angular Part
00124                                 */
00125                                 const float     angularBias= 1; // if 0, 2 linear edges will collapse asap.
00126                                 dist*= angularBias + 1-angularPart;
00127 
00128                                 // take min dist
00129                                 if(dist<bestDist)
00130                                 {
00131                                         bestDist= dist;
00132                                         bestEdgeId= j;
00133                                 }
00134                         }
00135 
00136                         // mark as remove it
00137                         _Lods[lod].EdgeToCollapse.push_back(edgeList[bestEdgeId]);
00138                         // changes vert ids of the prec edge. eg: edge(12) is deleted=> 01 12 23... becomes 02 23 (NB: 1 is collapsed to 2)
00139                         uint    precEdgeId= (bestEdgeId+edgeList.size()-1)%edgeList.size();
00140                         edgeList[precEdgeId].v1= edgeList[bestEdgeId].v1;
00141                         // and erase the edge from the current list
00142                         edgeList.erase( edgeList.begin()+bestEdgeId );
00143                 }
00144         }
00145 
00146 }

sint NL3D::CMRMSewingMesh::getNumCollapseEdge uint  lod  )  const
 

get the number of edge to collapse for a lod

Definition at line 59 of file mrm_internal.cpp.

References nlassert, sint, and uint.

Referenced by NL3D::CMRMBuilder::computeEdgeCost().

00060 {
00061         nlassert(lod<_Lods.size());
00062         return _Lods[lod].EdgeToCollapse.size();
00063 }

sint NL3D::CMRMSewingMesh::mustCollapseEdge uint  lod,
const CMRMEdge edge,
uint vertToCollapse
const
 

>=0 if the lod has this edge to collapse. -1 else. NB: order of collapse is returned.

Parameters:
vertToCollapse is the vertex id which must be collapsed to the other (ie the one which moves/dissapear)

Definition at line 41 of file mrm_internal.cpp.

References nlassert, sint, and uint.

Referenced by NL3D::CMRMBuilder::collapseEdge(), and NL3D::CMRMBuilder::computeEdgeCost().

00042 {
00043         nlassert(lod<_Lods.size());
00044         for(uint i=0;i<_Lods[lod].EdgeToCollapse.size();i++)
00045         {
00046                 if(edge==_Lods[lod].EdgeToCollapse[i])
00047                 {
00048                         // the vertex which must be collapsed is v0.
00049                         vertToCollapse= _Lods[lod].EdgeToCollapse[i].v0;
00050                         return i;
00051                 }
00052         }
00053         // not found
00054         return -1;
00055 }


Field Documentation

std::vector<CLod> NL3D::CMRMSewingMesh::_Lods [private]
 

Definition at line 336 of file mrm_internal.h.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:57:06 2004 for NeL by doxygen 1.3.6