NL3D::CZoneCornerSmoother Class Reference

#include <zone_corner_smoother.h>


Detailed Description

A class used to setup CornerSmoothFlag in CPatch. NB: it works with a compiled CZone (ie added in a landscape, and got with landscape->getZone()). NB: it changes values directly in CPatch (which it should not be permitted...), but don't except see the changes in realtime.
Author:
Lionel Berenguier

Nevrax France

Date:
2001

Definition at line 51 of file zone_corner_smoother.h.

Public Member Functions

void computeAllCornerSmoothFlags (CZone *zone, std::vector< CZone * > neighborZones)
 CZoneCornerSmoother ()
 Constructor.


Private Types

typedef TIdVertexMap::iterator ItIdVertexMap
typedef TVertexMap::iterator ItVertexMap
typedef std::map< const CTessVertex *,
sint
TIdVertexMap
typedef std::map< sint, CVertexSmoothInfoTVertexMap

Private Member Functions

void buildPatchBindInfo (CPatch &pa, const CZone::CPatchConnect &pc, bool smoothEdge[4], bool cornerOnBind[4])
void updateVertex (uint idVert, uint corner, bool smoothEdge[4], bool cornerOnBind[4])

Private Attributes

TIdVertexMap IdVertexMap
TVertexMap VertexMap


Member Typedef Documentation

typedef TIdVertexMap::iterator NL3D::CZoneCornerSmoother::ItIdVertexMap [private]
 

Definition at line 95 of file zone_corner_smoother.h.

Referenced by computeAllCornerSmoothFlags().

typedef TVertexMap::iterator NL3D::CZoneCornerSmoother::ItVertexMap [private]
 

Definition at line 92 of file zone_corner_smoother.h.

typedef std::map<const CTessVertex *, sint> NL3D::CZoneCornerSmoother::TIdVertexMap [private]
 

Definition at line 94 of file zone_corner_smoother.h.

typedef std::map<sint, CVertexSmoothInfo> NL3D::CZoneCornerSmoother::TVertexMap [private]
 

Definition at line 91 of file zone_corner_smoother.h.


Constructor & Destructor Documentation

NL3D::CZoneCornerSmoother::CZoneCornerSmoother  ) 
 

Constructor.

Definition at line 36 of file zone_corner_smoother.cpp.

00037 {
00038 }


Member Function Documentation

void NL3D::CZoneCornerSmoother::buildPatchBindInfo CPatch pa,
const CZone::CPatchConnect pc,
bool  smoothEdge[4],
bool  cornerOnBind[4]
[private]
 

Definition at line 42 of file zone_corner_smoother.cpp.

References NL3D::CPatchUVLocator::build(), NL3D::CPatch::getBindNeighbor(), NL3D::CPatch::getSmoothFlag(), NL3D::CPatch::CBindInfo::MultipleBindId, NL3D::CPatch::CBindInfo::MultipleBindNum, NL3D::CPatchUVLocator::sameEdgeOrder(), uint, and NL3D::CPatch::CBindInfo::Zone.

Referenced by computeAllCornerSmoothFlags().

00043 {
00044         uint    edge, corner;
00045 
00046         /*
00047                 Some terminology here: an edge is supposed going from Corner=edge, to corner=(edge+1)&3.
00048                 eg: edge 0 goes from corner0 to corner1.
00049         */
00050 
00051         for(corner=0; corner<4; corner++)
00052                 cornerOnBind[corner]= false;
00053 
00054         // for 4 edges.
00055         for(edge=0; edge<4; edge++)
00056         {
00057                 // Is this edge smoothed??
00058                 smoothEdge[edge]= pa.getSmoothFlag(edge);
00059 
00060                 // build bindInfo.
00061                 CPatch::CBindInfo       bindInfo;
00062                 CPatchUVLocator         patchUvLocator;
00063                 pa.getBindNeighbor(edge, bindInfo);
00064                 // if neighbor(s) is present.
00065                 if(bindInfo.Zone)
00066                 {
00067                         patchUvLocator.build(&pa, edge, bindInfo);
00068                         // if not sameEdgeOnOrder (NB: all special cases of bind 1/X X/1 managed :) ), not smoothed!
00069                         if( !patchUvLocator.sameEdgeOrder() )
00070                                 smoothEdge[edge]= false;
00071 
00072                         // Manage bind 1/4 for the 2 patchs on the center of the bind.
00073                         if(bindInfo.MultipleBindNum==4 && (bindInfo.MultipleBindId==1 || bindInfo.MultipleBindId==2) )
00074                         {
00075                                 // easy, this edge starts and ends on a bind...
00076                                 cornerOnBind[edge]= true;
00077                                 cornerOnBind[(edge+1)&3]= true;
00078                         }
00079                         // else for case bind 1/2, and for case of patch 0 and patch 3 of the bind 1/4.
00080                         else if(bindInfo.MultipleBindNum>=2)
00081                         {
00082                                 // Beware of the mirroring!! (make a draw...)
00083                                 /*
00084                                         ----------|-----------
00085                                                       |           
00086                                                       | |         
00087                                                     1 | |         
00088                                                   ^   | v         
00089                                                   |   |           
00090                                                   |   *-----------
00091                                                   |   |           
00092                                                   |   | |         
00093                                                     0 | |         
00094                                                       | v         
00095                                                       |           
00096                                         ----------|-----------
00097                                 */
00098                                 // If we are the patch0 on the neighbor, then we start on a bind, else we ends.
00099                                 if(bindInfo.MultipleBindId==0)
00100                                         cornerOnBind[edge]= true;
00101                                 else
00102                                         cornerOnBind[(edge+1)&3]= true;
00103                         }
00104 
00105                 }
00106         }
00107 }

void NL3D::CZoneCornerSmoother::computeAllCornerSmoothFlags CZone zone,
std::vector< CZone * >  neighborZones
 

the doit method. this Zone and his 8 neighbors should be added into a landscape. this method call setCornerSmoothFlag() on all CPatch of the zone. All corner smooth are set to false but if:

  • the corner is a vertex on a bind 1/X OR the vertex has exaclty 4 patch around him. AND
  • All edges sharing this corner must be smoothed getSmoothFlag()==true. AND
  • All edges sharing this corner must be "SameEdgeOrder", ie the patchs sharing this edge must have same number of tiles along this edge.

This is important for noise computing, and lighting.

Definition at line 134 of file zone_corner_smoother.cpp.

References NL3D::CZone::CPatchConnect::BaseVertices, buildPatchBindInfo(), NL3D::CPatch::getCornerVertex(), NL3D::CZone::getNumPatchs(), NL3D::CZone::getPatchConnect(), IdVertexMap, ItIdVertexMap, nlassert, NL3D::CZoneCornerSmoother::CVertexSmoothInfo::NPatchShared, NL3D::CPatch::setCornerSmoothFlag(), sint, NL3D::CZoneCornerSmoother::CVertexSmoothInfo::Smoothed, uint, updateVertex(), VertexMap, and NL3D::CZoneCornerSmoother::CVertexSmoothInfo::VertexOnBind.

00135 {
00136         nlassert(zone);
00137         sint    npatchs= zone->getNumPatchs();
00138         sint    i;
00139 
00140         VertexMap.clear();
00141         IdVertexMap.clear();
00142 
00143         // for all patchs of the center zone, build the vertexMap.
00144         //==================
00145         for(i=0; i<npatchs; i++)
00146         {
00147                 CPatch                                          &pa= (CPatch&)*(((const CZone*)zone)->getPatch(i));
00148                 const CZone::CPatchConnect      &pc= *(zone->getPatchConnect(i));
00149                 uint    corner;
00150 
00151                 // build bind info for 4 edges and 4 vertices.
00152                 bool    smoothEdge[4];
00153                 bool    cornerOnBind[4];
00154                 buildPatchBindInfo(pa, pc, smoothEdge, cornerOnBind);
00155 
00156                 // for 4 corners.
00157                 for(corner=0; corner<4; corner++)
00158                 {
00159                         // get the vertex id for this patch.
00160                         uint    idVert= pc.BaseVertices[corner];
00161 
00162                         // update this vertex smooth info.
00163                         updateVertex(idVert, corner, smoothEdge, cornerOnBind);
00164 
00165                         // for Bind with neighbor zones, must insert it in the map CTessVertex* -> VertexId.
00166                         IdVertexMap[pa.getCornerVertex(corner)]= idVert;
00167                 }
00168         }
00169 
00170 
00171         // for all patchs of all neigbhors zone, update for vertices that are connected to the centerZone.
00172         //==================
00173         for(uint nbZone=0; nbZone<neighborZones.size(); nbZone++)
00174         {
00175                 CZone   *neighborZone= neighborZones[nbZone];
00176                 nlassert(neighborZone);
00177                 for(i=0; i<neighborZone->getNumPatchs(); i++)
00178                 {
00179                         CPatch                                          &pa= (CPatch&)*(((const CZone*)neighborZone)->getPatch(i));
00180                         const CZone::CPatchConnect      &pc= *(neighborZone->getPatchConnect(i));
00181                         uint    corner;
00182 
00183                         // build bind info for 4 edges and 4 vertices.
00184                         bool    smoothEdge[4];
00185                         bool    cornerOnBind[4];
00186                         buildPatchBindInfo(pa, pc, smoothEdge, cornerOnBind);
00187 
00188                         // for 4 corners.
00189                         for(corner=0; corner<4; corner++)
00190                         {
00191                                 // try to find the vertex of the centerZone binded to this corner.
00192                                 ItIdVertexMap   it= IdVertexMap.find(pa.getCornerVertex(corner));
00193 
00194                                 // If this patch is binded on a vertex of the centerZone, must update this vertex.
00195                                 if(it != IdVertexMap.end())
00196                                 {
00197                                         // get the vertex id for this patch.
00198                                         uint    idVert= it->second;
00199 
00200                                         // update this vertex smooth info.
00201                                         updateVertex(idVert, corner, smoothEdge, cornerOnBind);
00202                                 }
00203 
00204                         }
00205                 }
00206         }
00207 
00208 
00209         // for all patchs of the center zone, build the finalSmooth.
00210         //==================
00211         for(i=0; i<npatchs; i++)
00212         {
00213                 CPatch                                          &pa= (CPatch&)*(((const CZone*)zone)->getPatch(i));
00214                 const CZone::CPatchConnect      &pc= *(zone->getPatchConnect(i));
00215                 uint    corner;
00216 
00217                 // for 4 corners.
00218                 for(corner=0; corner<4; corner++)
00219                 {
00220                         uint    idVert= pc.BaseVertices[corner];
00221                         // get from map.
00222                         CVertexSmoothInfo       &vert= VertexMap[idVert];
00223 
00224                         // the vertex is smoothed if all edges around him are smoothed, AND
00225                         // if it has 4 patchs around him or if it is a bind.
00226                         bool    finalSmooth;
00227                         finalSmooth= vert.Smoothed && (vert.VertexOnBind || vert.NPatchShared==4);
00228 
00229                         // update the patch.
00230                         pa.setCornerSmoothFlag(corner, finalSmooth);
00231                 }
00232 
00233         }
00234 
00235 
00236 }

void NL3D::CZoneCornerSmoother::updateVertex uint  idVert,
uint  corner,
bool  smoothEdge[4],
bool  cornerOnBind[4]
[private]
 

Definition at line 111 of file zone_corner_smoother.cpp.

References NL3D::CZoneCornerSmoother::CVertexSmoothInfo::NPatchShared, NL3D::CZoneCornerSmoother::CVertexSmoothInfo::Smoothed, uint, VertexMap, and NL3D::CZoneCornerSmoother::CVertexSmoothInfo::VertexOnBind.

Referenced by computeAllCornerSmoothFlags().

00112 {
00113         // get or insert into map (with default).
00114         CVertexSmoothInfo       &vert= VertexMap[idVert];
00115 
00116         // inc the number of patch binded to this point.
00117         vert.NPatchShared++;
00118 
00119         // get the smooth flag of edge before and after this corner.
00120         uint    e0= (4+corner-1)&3;
00121         uint    e1= corner;
00122         // if any one of those edge is not smoothed, then this vertex is not smoothed.
00123         if( !smoothEdge[e0] || !smoothEdge[e1] )
00124                 vert.Smoothed= false;
00125 
00126         
00127         // Are we a vertex on a bind??
00128         if(cornerOnBind[corner])
00129                 vert.VertexOnBind= true;
00130 }


Field Documentation

TIdVertexMap NL3D::CZoneCornerSmoother::IdVertexMap [private]
 

Definition at line 100 of file zone_corner_smoother.h.

Referenced by computeAllCornerSmoothFlags().

TVertexMap NL3D::CZoneCornerSmoother::VertexMap [private]
 

Definition at line 99 of file zone_corner_smoother.h.

Referenced by computeAllCornerSmoothFlags(), and updateVertex().


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