NL3D::CZoneSmoother Class Reference

#include <zone_smoother.h>


Detailed Description

A class used to make Bezier patch of zones G1.
Author:
Lionel Berenguier

Nevrax France

Date:
2000

Definition at line 46 of file zone_smoother.h.

Public Member Functions

 CZoneSmoother ()
 Constructor.

void smoothTangents (CZoneInfo zones[5], float angleThreshold=NLMISC::Pi/6, bool continuityC1=false)

Private Types

typedef std::map< sint, CZoneInfoTZoneInfoMap

Private Member Functions

bool smoothTangent (const CVector &tgt, const CVector &int0, const CVector &int1, CVector &tgtres)

Private Attributes

bool _ContinuityC1
float _CosThreshold
TZoneInfoMap _Zones


Member Typedef Documentation

typedef std::map<sint, CZoneInfo> NL3D::CZoneSmoother::TZoneInfoMap [private]
 

Definition at line 90 of file zone_smoother.h.


Constructor & Destructor Documentation

NL3D::CZoneSmoother::CZoneSmoother  )  [inline]
 

Constructor.

Definition at line 66 of file zone_smoother.h.

00066 {}


Member Function Documentation

bool NL3D::CZoneSmoother::smoothTangent const CVector tgt,
const CVector int0,
const CVector int1,
CVector tgtres
[private]
 

Definition at line 36 of file zone_smoother.cpp.

References _ContinuityC1, _CosThreshold, NLMISC::CVector::norm(), and NLMISC::CVector::normalize().

Referenced by smoothTangents().

00037 {
00038         // First, test anglethreshold.
00039         CVector         dir0= tgt-int0;
00040         CVector         dir1= int1-tgt;
00041         float           norm0= dir0.norm();
00042         float           norm1= dir1.norm();
00043         dir0.normalize();
00044         dir1.normalize();
00045         // If not so colinear...
00046         if(dir0*dir1<_CosThreshold)
00047                 return false;
00048 
00049         // Then smooth.
00050         if(_ContinuityC1)
00051         {
00052                 tgtres= (int0+int1)/2;
00053         }
00054         else
00055         {
00056                 // Make it colinear, but not at the middle.
00057                 // Respect the old distance ratio.
00058                 tgtres= (int0*norm1 + int1*norm0)/ (norm0+norm1);
00059         }
00060 
00061 
00062         return true;
00063 }

void NL3D::CZoneSmoother::smoothTangents CZoneInfo  zones[5],
float  angleThreshold = NLMISC::Pi/6,
bool  continuityC1 = false
 

Smooth the tangents of those zones. Zones must be correclty welded. Only all patchs of zones[0] are parsed. But other zones may be modified on their edge (so you must save them).

NB: tangent smoothing is only done on bind 1/1.

Parameters:
zones The 0 is the center zone to be computed. Other are the 4 zones around (no special order needed). Doesn't matter if zones[i].Patchs is NULL. Also, if a neighbor patch is not found on a edge, then no error is generated: this patch edge is not modified. nlstop if zones[0]==NULL.
angleThreshold if angle beetween (patch_interior - tangent) and (neighbor_patch_interior - tangent) is above angleThreshold, no smooth is done on this tangent. Default: 30deg.
continuityC1. when a smooth is done on a tangent, tangent is forced such that the 2 interiors and the tangent are colinear, so continuity G1 is assured. if continuityC1 is true, then tangent is set to the middle of the interiors (continuity C1). If false, tangent is setup so that previous distance ratio are kept.

Definition at line 67 of file zone_smoother.cpp.

References _ContinuityC1, _CosThreshold, NL3D::CPatchInfo::BindEdges, NL3D::CPatchInfo::CBindInfo::Edge, NL3D::CPatchInfo::getSmoothFlag(), NL3D::CBezierPatch::Interiors, NL3D::CPatchInfo::CBindInfo::Next, nlassert, NL3D::CPatchInfo::CBindInfo::NPatchs, NL3D::CPatchInfo::Patch, NL3D::CZoneSmoother::CZoneInfo::Patchs, sint, smoothTangent(), NL3D::CBezierPatch::Tangents, and NL3D::CPatchInfo::CBindInfo::ZoneId.

00068 {
00069         sint i,j;
00070 
00071         nlassert(zones[0].Patchs);
00072 
00073         // Local info.
00074         _CosThreshold= (float)cos(angleThreshold);
00075         _ContinuityC1= continuityC1;
00076 
00077         // 0. fill local Zone map.
00078         //========================
00079         _Zones.clear();
00080         for(i=0;i<5;i++)
00081         {
00082                 // If not NULL
00083                 if(zones[i].Patchs)
00084                 {
00085                         _Zones.insert( TZoneInfoMap::value_type(zones[i].ZoneId, zones[i]) );
00086                 }
00087         }
00088 
00089         // 1. Fot all patchs of zones[0].
00090         //===============================
00091         std::vector<CPatchInfo>         &patchs= *(zones[0].Patchs);
00092         for(i=0;i<(sint)patchs.size();i++)
00093         {
00094                 CPatchInfo      &pat0= patchs[i];
00095 
00096                 // For all edges.
00097                 for(j=0;j<4;j++)
00098                 {
00099                         if (pat0.getSmoothFlag (i))
00100                         {
00101                                 CPatchInfo::CBindInfo   &bd= pat0.BindEdges[j];
00102                                 // If normal bind (1/1), we can do the smooth.
00103                                 if(bd.NPatchs==1)
00104                                 {
00105                                         // Retrieve the good neighbor zone.
00106                                         TZoneInfoMap::iterator  itZone= _Zones.find(bd.ZoneId);
00107                                         // If zone here.
00108                                         if(itZone!=_Zones.end())
00109                                         {
00110                                                 CZoneInfo       &zi= itZone->second;
00111                                                 CPatchInfo      &pat1= (*zi.Patchs)[bd.Next[0]];
00112                                                 // Here, we have the 2 patchs, and we must smooth 2 tangents.
00113                                                 CVector         tgtRes;
00114                                                 sint            edge0= j;
00115                                                 sint            edge1= bd.Edge[0];
00116 
00117                                                 // Make a draw to understand (see Bezier patchs conventions).
00118                                                 // The key is: Patchs are always CCW, so must smooth the patchs one front of the other.
00119 
00120                                                 // a. First tangent.
00121                                                 //==================
00122                                                 if(smoothTangent(pat0.Patch.Tangents[edge0*2], pat0.Patch.Interiors[edge0], 
00123                                                         pat1.Patch.Interiors[(edge1+1)%4], tgtRes))
00124                                                 {
00125                                                         // Set the result on the 2 patchs.
00126                                                         pat0.Patch.Tangents[edge0*2]= tgtRes;
00127                                                         pat1.Patch.Tangents[edge1*2+1]= tgtRes;
00128                                                 }
00129 
00130                                                 // b. Second tangent.
00131                                                 //==================
00132                                                 if(smoothTangent(pat0.Patch.Tangents[edge0*2+1], pat0.Patch.Interiors[(edge0+1)%4], 
00133                                                         pat1.Patch.Interiors[edge1], tgtRes))
00134                                                 {
00135                                                         // Set the result on the 2 patchs.
00136                                                         pat0.Patch.Tangents[edge0*2+1]= tgtRes;
00137                                                         pat1.Patch.Tangents[edge1*2]= tgtRes;
00138                                                 }
00139 
00140                                         }
00141                                 }
00142                         }
00143                 }
00144         }
00145 
00146         // End!!
00147 }


Field Documentation

bool NL3D::CZoneSmoother::_ContinuityC1 [private]
 

Definition at line 93 of file zone_smoother.h.

Referenced by smoothTangent(), and smoothTangents().

float NL3D::CZoneSmoother::_CosThreshold [private]
 

Definition at line 92 of file zone_smoother.h.

Referenced by smoothTangent(), and smoothTangents().

TZoneInfoMap NL3D::CZoneSmoother::_Zones [private]
 

Definition at line 91 of file zone_smoother.h.


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