NLPACS::CChain Class Reference

#include <chain.h>


Detailed Description

A list of ordered chains of vertices, delimiting 2 surfaces.
Author:
Benjamin Legros

Nevrax France

Date:
2001

Definition at line 210 of file chain.h.

Public Member Functions

 CChain ()
 Constructor.

sint32 getBorderChainIndex () const
 Gets the index of the chain on border (in the local retriever object.).

sint32 getLeft () const
 Returns the left surface id.

uint8 getLeftLoop () const
uint8 getLeftLoopIndex () const
float getLength () const
 returns the legnth of the whole chain.

sint32 getRight () const
 Returns the right surface id.

uint8 getRightLoop () const
uint8 getRightLoopIndex () const
uint16 getStartTip () const
 Returns the id of the start tip of the chain.

uint16 getStopTip () const
 Returns the id of the end tip of the chain.

uint16 getSubChain (uint n) const
 Returns the id of the nth ordered chain that composes the chain.

const std::vector< uint16 > & getSubChains () const
 Returns a vector of ordered chain ids that compose the entire chain.

bool isBorderChain () const
 Returns true iff the chaion is a border chain.

void serial (NLMISC::IStream &f)
 Serialises the CChain object.


Static Public Member Functions

sint32 convertBorderChainId (sint32 id)
 Converts the surf id into the real index to the link (in the BorderChainLinks of the CRetrieverInstance.).

sint32 getDummyBorderChainId ()
 Returns true iff the chaion is a border chain.

bool isBorderChainId (sint32 id)
 Returns true iff the given id corresponds to a link on the border.


Protected Member Functions

CVector2s getStartVector (std::vector< COrderedChain > &ochains)
CVector2s getStopVector (std::vector< COrderedChain > &ochains)
void make (const std::vector< NLMISC::CVector > &vertices, sint32 left, sint32 right, std::vector< COrderedChain > &chains, uint16 thisId, std::vector< COrderedChain3f > &fullChains, std::vector< uint > &useOChainId)
 Build the whole surface from a vector of CVector and the left and right surfaces.

void setBorderChainIndex (sint32 id)
void setLoopIndexes (sint32 surface, uint loop, uint loopIndex)
void setStartVector (const CVector2s &v, std::vector< COrderedChain > &ochains)
void setStopVector (const CVector2s &v, std::vector< COrderedChain > &ochains)
void unify (std::vector< COrderedChain > &ochains)

Protected Attributes

sint32 _Left
 The surface on the left of the chain.

uint8 _LeftLoop
uint8 _LeftLoopIndex
float _Length
 The length of the whole chain.

sint32 _Right
 The surface on the right of the chain.

uint8 _RightLoop
uint8 _RightLoopIndex
uint16 _StartTip
 The tips indexes in the retriever object.

uint16 _StopTip
std::vector< uint16_SubChains
 The list of ordered chains that compose the chain.


Friends

class CLocalRetriever
class CRetrievableSurface


Constructor & Destructor Documentation

NLPACS::CChain::CChain  )  [inline]
 

Constructor.

Definition at line 259 of file chain.h.

References _Left, _LeftLoop, _LeftLoopIndex, _Right, _RightLoop, _RightLoopIndex, _StartTip, and _StopTip.

00259                  :      _Left(-1), _Right(-1), _StartTip(0xffff), _StopTip(0xffff), _Length(0.0f),
00260                                 _LeftLoop(0), _LeftLoopIndex(0), _RightLoop(0), _RightLoopIndex(0) {}


Member Function Documentation

sint32 NLPACS::CChain::convertBorderChainId sint32  id  )  [inline, static]
 

Converts the surf id into the real index to the link (in the BorderChainLinks of the CRetrieverInstance.).

Definition at line 291 of file chain.h.

References sint32.

Referenced by getBorderChainIndex(), getDummyBorderChainId(), and setBorderChainIndex().

00291 { return -(id+256); }

sint32 NLPACS::CChain::getBorderChainIndex  )  const [inline]
 

Gets the index of the chain on border (in the local retriever object.).

Definition at line 282 of file chain.h.

References _Right, convertBorderChainId(), isBorderChainId(), and sint32.

Referenced by NLPACS::CGlobalRetriever::check(), and NLPACS::CGlobalRetriever::findCollisionChains().

00283         {
00284                 return (isBorderChainId(_Right)) ? convertBorderChainId(_Right) : -1;
00285         }

sint32 NLPACS::CChain::getDummyBorderChainId  )  [inline, static]
 

Returns true iff the chaion is a border chain.

Definition at line 297 of file chain.h.

References convertBorderChainId(), and sint32.

00297 { return convertBorderChainId(0); }

sint32 NLPACS::CChain::getLeft  )  const [inline]
 

Returns the left surface id.

Definition at line 269 of file chain.h.

References _Left, and sint32.

Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CLocalRetriever::computeTopologies(), NLPACS::CLocalRetriever::dumpSurface(), NLPACS::CGlobalRetriever::findAStarPath(), NLPACS::CLocalRetriever::findPath(), NLPACS::CGlobalRetriever::getBorders(), and NLPACS::CLocalRetriever::insurePosition().

00269 { return _Left; }

uint8 NLPACS::CChain::getLeftLoop  )  const [inline]
 

Definition at line 270 of file chain.h.

References _LeftLoop, and uint8.

Referenced by NLPACS::CLocalRetriever::findPath().

00270 { return _LeftLoop; }

uint8 NLPACS::CChain::getLeftLoopIndex  )  const [inline]
 

Definition at line 271 of file chain.h.

References _LeftLoopIndex, and uint8.

Referenced by NLPACS::CLocalRetriever::findPath().

00271 { return _LeftLoopIndex; }

float NLPACS::CChain::getLength  )  const [inline]
 

returns the legnth of the whole chain.

Definition at line 279 of file chain.h.

Referenced by NLPACS::CLocalRetriever::findPath(), and NLPACS::CGlobalRetriever::findPath().

00279 { return _Length; }

sint32 NLPACS::CChain::getRight  )  const [inline]
 

Returns the right surface id.

Definition at line 274 of file chain.h.

References _Right, and sint32.

Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CLocalRetriever::computeTopologies(), NLPACS::CLocalRetriever::dumpSurface(), NLPACS::CGlobalRetriever::findAStarPath(), and NLPACS::CGlobalRetriever::getBorders().

00274 { return _Right; }

uint8 NLPACS::CChain::getRightLoop  )  const [inline]
 

Definition at line 275 of file chain.h.

References _RightLoop, and uint8.

Referenced by NLPACS::CLocalRetriever::findPath().

00275 { return _RightLoop; }

uint8 NLPACS::CChain::getRightLoopIndex  )  const [inline]
 

Definition at line 276 of file chain.h.

References _RightLoopIndex, and uint8.

Referenced by NLPACS::CLocalRetriever::findPath().

00276 { return _RightLoopIndex; }

uint16 NLPACS::CChain::getStartTip  )  const [inline]
 

Returns the id of the start tip of the chain.

Definition at line 300 of file chain.h.

References _StartTip, and uint16.

Referenced by NLPACS::CLocalRetriever::dumpSurface().

00300 { return _StartTip; }

NLPACS::CVector2s NLPACS::CChain::getStartVector std::vector< COrderedChain > &  ochains  )  [protected]
 

Definition at line 339 of file chain.cpp.

References _SubChains.

00340 {
00341         if (ochains[_SubChains.front()].isForward())
00342                 return ochains[_SubChains.front()]._Vertices.front();
00343         else
00344                 return ochains[_SubChains.front()]._Vertices.back();
00345 }

uint16 NLPACS::CChain::getStopTip  )  const [inline]
 

Returns the id of the end tip of the chain.

Definition at line 303 of file chain.h.

References _StopTip, and uint16.

Referenced by NLPACS::CLocalRetriever::dumpSurface().

00303 { return _StopTip; }

NLPACS::CVector2s NLPACS::CChain::getStopVector std::vector< COrderedChain > &  ochains  )  [protected]
 

Definition at line 348 of file chain.cpp.

References _SubChains.

00349 {
00350         if (ochains[_SubChains.back()].isForward())
00351                 return ochains[_SubChains.back()]._Vertices.back();
00352         else
00353                 return ochains[_SubChains.back()]._Vertices.front();
00354 }

uint16 NLPACS::CChain::getSubChain uint  n  )  const [inline]
 

Returns the id of the nth ordered chain that composes the chain.

Definition at line 266 of file chain.h.

References _SubChains, uint, and uint16.

Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CLocalRetriever::distanceToBorder(), NLPACS::CLocalRetriever::dumpSurface(), NLPACS::CGlobalRetriever::findPath(), NLPACS::CLocalRetriever::CIterator::get3d(), NLPACS::CLocalRetriever::insurePosition(), NLPACS::linkExteriorToInterior(), NLPACS::CLocalRetriever::CIterator::operator *(), and NLPACS::CLocalRetriever::CIterator::setupIndex().

00266 { return _SubChains[n]; }

const std::vector<uint16>& NLPACS::CChain::getSubChains  )  const [inline]
 

Returns a vector of ordered chain ids that compose the entire chain.

Definition at line 263 of file chain.h.

References _SubChains.

Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CLocalRetriever::distanceToBorder(), NLPACS::CLocalRetriever::dumpSurface(), NLPACS::CLocalRetriever::CIterator::end(), NLPACS::CGlobalRetriever::findPath(), NLPACS::CLocalRetriever::insurePosition(), NLPACS::linkExteriorToInterior(), NLPACS::CLocalRetriever::CIterator::operator++(), and NLPACS::CLocalRetriever::CIterator::setupIndex().

00263 { return _SubChains; }

bool NLPACS::CChain::isBorderChain  )  const [inline]
 

Returns true iff the chaion is a border chain.

Definition at line 294 of file chain.h.

References _Right, and isBorderChainId().

Referenced by NLPACS::CGlobalRetriever::findCollisionChains(), and NLPACS::CGlobalRetriever::getBorders().

00294 { return isBorderChainId(_Right); }

bool NLPACS::CChain::isBorderChainId sint32  id  )  [inline, static]
 

Returns true iff the given id corresponds to a link on the border.

Definition at line 288 of file chain.h.

References sint32.

Referenced by NLPACS::CGlobalRetriever::findCollisionChains(), getBorderChainIndex(), and isBorderChain().

00288 { return id <= -256; }

void NLPACS::CChain::make const std::vector< NLMISC::CVector > &  vertices,
sint32  left,
sint32  right,
std::vector< COrderedChain > &  chains,
uint16  thisId,
std::vector< COrderedChain3f > &  fullChains,
std::vector< uint > &  useOChainId
[protected]
 

Build the whole surface from a vector of CVector and the left and right surfaces.

Definition at line 199 of file chain.cpp.

References NLPACS::COrderedChain3f::_Forward, NLPACS::COrderedChain3f::_IndexInParent, _Left, NLPACS::COrderedChain::_Length, NLPACS::COrderedChain3f::_ParentId, _Right, _SubChains, NLPACS::COrderedChain::_Vertices, NLPACS::COrderedChain3f::_Vertices, NLPACS::COrderedChain::computeMinMax(), NLPACS::isStrictlyGreater(), NLPACS::isStrictlyLess(), nlerror, NLPACS::COrderedChain::pack(), sint, sint32, uint16, and uint32.

Referenced by NLPACS::CLocalRetriever::addChain(), and NLPACS::CLocalRetriever::replaceChain().

00201 {
00202         sint            first = 0, last = 0, i;
00203 
00204         _Left = left;
00205         _Right = right;
00206         _Length = 0.0f;
00207 
00208         // splits the vertices list in ordered sub chains.
00209         while (first < (sint)vertices.size()-1)
00210         {
00211                 last = first+1;
00212                 bool    forward = isStrictlyLess(vertices[first], vertices[last]);
00213 
00214                 // first checks if the subchain goes forward or backward.
00215                 if (forward)
00216                         for (; last < (sint)vertices.size() && isStrictlyLess(vertices[last-1], vertices[last]); ++last)
00217                                 ;
00218                 else
00219                         for (; last < (sint)vertices.size() && isStrictlyGreater(vertices[last-1], vertices[last]); ++last)
00220                                 ;
00221                 --last;
00222 
00223                 // inserts the new subchain id within the CChain.
00224                 uint32  subChainId;
00225 
00226                 if (useOChainId.empty())
00227                 {
00228                         subChainId = chains.size();
00229                         if (subChainId > 65535)
00230                                 nlerror("in NLPACS::CChain::make(): reached the maximum number of ordered chains");
00231 
00232                         chains.resize(chains.size()+1);
00233                         fullChains.resize(fullChains.size()+1);
00234                 }
00235                 else
00236                 {
00237                         subChainId = useOChainId.back();
00238                         useOChainId.pop_back();
00239                 }
00240 
00241                 _SubChains.push_back((uint16)subChainId);
00242 
00243                 // and creates a new COrderedChain
00244                 COrderedChain3f &subchain3f = fullChains[subChainId];
00245                 subchain3f._Vertices.reserve(last-first+1);
00246                 subchain3f._Forward = forward;
00247                 subchain3f._ParentId = thisId;
00248                 subchain3f._IndexInParent = _SubChains.size()-1;
00249 
00250                 // and then copies the vertices (sorted, btw!)
00251                 if (forward)
00252                         for (i=first; i<=last; ++i)
00253                                 subchain3f._Vertices.push_back(vertices[i]);
00254                 else
00255                         for (i=last; i>=first; --i)
00256                                 subchain3f._Vertices.push_back(vertices[i]);
00257 
00258                 first = last;
00259 
00260                 COrderedChain   &subchain = chains[subChainId];
00261                 subchain.pack(subchain3f);
00262                 subchain.computeMinMax();
00263 
00264                 float   length = 0.0f;
00265                 for (i=0; i<(sint)subchain._Vertices.size()-1; ++i)
00266                         length += (subchain._Vertices[i+1]-subchain._Vertices[i]).norm();
00267 
00268                 subchain._Length = length;
00269                 _Length += length;
00270         }
00271 }

void NLPACS::CChain::serial NLMISC::IStream f  ) 
 

Serialises the CChain object.

Definition at line 274 of file chain.cpp.

References _Left, _LeftLoop, _LeftLoopIndex, _Right, _RightLoop, _RightLoopIndex, _StartTip, _StopTip, _SubChains, NLMISC::IStream::serial(), NLMISC::IStream::serialCont(), and NLMISC::IStream::serialVersion().

00275 {
00276         /*
00277         Version 0:
00278                 - base version.
00279         */
00280         (void)f.serialVersion(0);
00281 
00282         f.serialCont(_SubChains);
00283         f.serial(_Left, _Right);
00284         f.serial(_StartTip, _StopTip);
00285         f.serial(_Length);
00286         f.serial(_LeftLoop, _LeftLoopIndex);
00287         f.serial(_RightLoop, _RightLoopIndex);
00288 }

void NLPACS::CChain::setBorderChainIndex sint32  id  )  [inline, protected]
 

Definition at line 254 of file chain.h.

References _Right, convertBorderChainId(), and sint32.

00254 { _Right = convertBorderChainId(id); }

void NLPACS::CChain::setLoopIndexes sint32  surface,
uint  loop,
uint  loopIndex
[inline, protected]
 

Definition at line 240 of file chain.h.

References _Left, _LeftLoop, _LeftLoopIndex, _RightLoop, _RightLoopIndex, sint32, and uint.

00241         {
00242                 if (_Left == surface)
00243                 {
00244                         _LeftLoop = loop;
00245                         _LeftLoopIndex = loopIndex;
00246                 }
00247                 else
00248                 {
00249                         _RightLoop = loop;
00250                         _RightLoopIndex = loopIndex;
00251                 }
00252         }

void NLPACS::CChain::setStartVector const CVector2s v,
std::vector< COrderedChain > &  ochains
[protected]
 

Definition at line 321 of file chain.cpp.

References _SubChains, and v.

00322 {
00323         if (ochains[_SubChains.front()].isForward())
00324                 ochains[_SubChains.front()]._Vertices.front() = v;
00325         else
00326                 ochains[_SubChains.front()]._Vertices.back() = v;
00327 }

void NLPACS::CChain::setStopVector const CVector2s v,
std::vector< COrderedChain > &  ochains
[protected]
 

Definition at line 330 of file chain.cpp.

References _SubChains, and v.

00331 {
00332         if (ochains[_SubChains.back()].isForward())
00333                 ochains[_SubChains.back()]._Vertices.back() = v;
00334         else
00335                 ochains[_SubChains.back()]._Vertices.front() = v;
00336 }

void NLPACS::CChain::unify std::vector< COrderedChain > &  ochains  )  [protected]
 

Definition at line 293 of file chain.cpp.

References _SubChains, nlwarning, and uint.

00294 {
00295         CVector2s       snap;
00296         uint            i;
00297 
00298         snap = (ochains[_SubChains[0]].isForward()) ? ochains[_SubChains[0]]._Vertices.back() : ochains[_SubChains[0]]._Vertices.front();
00299 
00300         for (i=1; i<_SubChains.size(); ++i)
00301         {
00302                 if (ochains[_SubChains[i]].isForward())
00303                 {
00304                         if (ochains[_SubChains[i]]._Vertices.front() != snap)
00305                                 nlwarning("ochain %d and %d are not stuck together", _SubChains[i-1], _SubChains[i]);
00306                         ochains[_SubChains[i]]._Vertices.front() = snap;
00307                         snap = ochains[_SubChains[i]]._Vertices.back();
00308                 }
00309                 else
00310                 {
00311                         if (ochains[_SubChains[i]]._Vertices.back() != snap)
00312                                 nlwarning("ochain %d and %d are not stuck together", _SubChains[i-1], _SubChains[i]);
00313                         ochains[_SubChains[i]]._Vertices.back() = snap;
00314                         snap = ochains[_SubChains[i]]._Vertices.front();
00315                 }
00316         }
00317 
00318 }


Friends And Related Function Documentation

friend class CLocalRetriever [friend]
 

Definition at line 214 of file chain.h.

friend class CRetrievableSurface [friend]
 

Definition at line 213 of file chain.h.


Field Documentation

sint32 NLPACS::CChain::_Left [protected]
 

The surface on the left of the chain.

Definition at line 220 of file chain.h.

Referenced by NLPACS::CLocalRetriever::build3dSurfacePolygons(), NLPACS::CLocalRetriever::buildSurfacePolygons(), CChain(), getLeft(), make(), serial(), and setLoopIndexes().

uint8 NLPACS::CChain::_LeftLoop [protected]
 

Definition at line 232 of file chain.h.

Referenced by CChain(), getLeftLoop(), serial(), and setLoopIndexes().

uint8 NLPACS::CChain::_LeftLoopIndex [protected]
 

Definition at line 232 of file chain.h.

Referenced by CChain(), getLeftLoopIndex(), serial(), and setLoopIndexes().

float NLPACS::CChain::_Length [protected]
 

The length of the whole chain.

Definition at line 230 of file chain.h.

sint32 NLPACS::CChain::_Right [protected]
 

The surface on the right of the chain.

Definition at line 223 of file chain.h.

Referenced by CChain(), getBorderChainIndex(), getRight(), isBorderChain(), make(), serial(), and setBorderChainIndex().

uint8 NLPACS::CChain::_RightLoop [protected]
 

Definition at line 233 of file chain.h.

Referenced by CChain(), getRightLoop(), serial(), and setLoopIndexes().

uint8 NLPACS::CChain::_RightLoopIndex [protected]
 

Definition at line 233 of file chain.h.

Referenced by CChain(), getRightLoopIndex(), serial(), and setLoopIndexes().

uint16 NLPACS::CChain::_StartTip [protected]
 

The tips indexes in the retriever object.

Definition at line 226 of file chain.h.

Referenced by NLPACS::CLocalRetriever::addChain(), CChain(), getStartTip(), NLPACS::CLocalRetriever::replaceChain(), and serial().

uint16 NLPACS::CChain::_StopTip [protected]
 

Definition at line 227 of file chain.h.

Referenced by NLPACS::CLocalRetriever::addChain(), CChain(), getStopTip(), NLPACS::CLocalRetriever::replaceChain(), and serial().

std::vector<uint16> NLPACS::CChain::_SubChains [protected]
 

The list of ordered chains that compose the chain.

Definition at line 217 of file chain.h.

Referenced by NLPACS::CLocalRetriever::build3dSurfacePolygons(), NLPACS::CLocalRetriever::buildSurfacePolygons(), NLPACS::CLocalRetriever::findPath(), getStartVector(), getStopVector(), getSubChain(), getSubChains(), make(), serial(), setStartVector(), setStopVector(), and unify().


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