# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

chain.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_CHAIN_H
00027 #define NL_CHAIN_H
00028 
00029 #include <vector>
00030 #include "nel/misc/types_nl.h"
00031 #include "nel/misc/vector.h"
00032 #include "pacs/vector_2s.h"
00033 #include "nel/misc/file.h"
00034 
00035 namespace NLPACS
00036 {
00037 class COrderedChain;
00038 
00048 class COrderedChain3f
00049 {
00050 protected:
00051         friend class CChain;
00052         friend class CRetrievableSurface;
00053 
00055         std::vector<NLMISC::CVector>            _Vertices;
00056 
00058         bool                                                            _Forward;
00059 
00061         uint16                                                          _ParentId;
00062 
00064         uint16                                                          _IndexInParent;
00065 
00066 public:
00068         const std::vector<NLMISC::CVector>      &getVertices() const { return _Vertices; }
00069 
00071         bool                                                            isForward() const { return _Forward; }
00072 
00074         uint16                                                          getParentId() const { return _ParentId; }
00075 
00077         uint16                                                          getIndexInParent() const { return _IndexInParent; }
00078 
00080         const NLMISC::CVector                           &operator[] (uint n) const { return _Vertices[n]; }
00081 
00083         void                                                            unpack(const COrderedChain &ochain);
00084 
00086         void                                                            translate(const NLMISC::CVector &translation)
00087         {
00088                 uint    i;
00089                 for (i=0; i<_Vertices.size(); ++i)
00090                         _Vertices[i] += translation;
00091         }
00092 
00093         void                                                            serial(NLMISC::IStream &f);
00094 };
00095 
00107 class COrderedChain
00108 {
00109 protected:
00110         friend class CChain;
00111         friend class CRetrievableSurface;
00112 
00114         std::vector<CVector2s>                          _Vertices;
00115 
00117         bool                                                            _Forward;
00118 
00120         uint16                                                          _ParentId;
00121 
00123         uint16                                                          _IndexInParent;
00124 
00126         float                                                           _Length;
00127 
00129         CVector2s                                                       _Min, _Max;
00130 
00131 public:
00133         const std::vector<CVector2s>            &getVertices() const { return _Vertices; }
00134 
00136         bool                                                            isForward() const { return _Forward; }
00137 
00139         uint16                                                          getParentId() const { return _ParentId; }
00140 
00142         uint16                                                          getIndexInParent() const { return _IndexInParent; }
00143 
00145         float                                                           getLength() const { return _Length; }
00146 
00148         const CVector2s                                         &operator[] (uint n) const { return _Vertices[n]; }
00149 
00151         const CVector2s                                         &getMin() const { return _Min; };
00152 
00154         const CVector2s                                         &getMax() const { return _Max; };
00155 
00156 
00158         void                                                            translate(const NLMISC::CVector &translation);
00159 
00161         void                                                            pack(const COrderedChain3f &chain)
00162         {
00163                 uint    i;
00164                 const std::vector<NLMISC::CVector>      &vertices = chain.getVertices();
00165                 _Vertices.resize(vertices.size());
00166                 _Forward = chain.isForward();
00167                 _ParentId = chain.getParentId();
00168                 _IndexInParent = chain.getIndexInParent();
00169                 for (i=0; i<vertices.size(); ++i)
00170                 {
00171                         _Vertices[i] = CVector2s(vertices[i]);
00172                         _Min.minof(_Min, _Vertices[i]);
00173                         _Max.maxof(_Max, _Vertices[i]);
00174                 }
00175         }
00176 
00178         void                                                            computeMinMax()
00179         {
00180                 _Min = _Max = CVector2s(0, 0);
00181 
00182                 if (_Vertices.empty())
00183                         return;
00184 
00185                 _Min = _Max = _Vertices[0];
00186                 uint    i;
00187                 for (i=1; i<_Vertices.size(); ++i)
00188                 {
00189                         _Min.minof(_Min, _Vertices[i]);
00190                         _Max.maxof(_Max, _Vertices[i]);
00191                 }
00192         }
00193 
00195         void                                                            traverse(sint from, sint to, bool forward, std::vector<CVector2s> &path) const;
00196 
00198         float                                                           distance(const NLMISC::CVector &position) const;
00199 
00201         void                                                            serial(NLMISC::IStream &f);
00202 };
00203 
00210 class CChain
00211 {
00212 protected:
00213         friend class CRetrievableSurface;
00214         friend class CLocalRetriever;
00215 
00217         std::vector<uint16>                                     _SubChains;
00218 
00220         sint32                                                          _Left;
00221 
00223         sint32                                                          _Right;
00224 
00226         uint16                                                          _StartTip;
00227         uint16                                                          _StopTip;
00228 
00230         float                                                           _Length;
00231 
00232         uint8                                                           _LeftLoop, _LeftLoopIndex;
00233         uint8                                                           _RightLoop, _RightLoopIndex;
00234 
00235 protected:
00237         void                                                            make(const std::vector<NLMISC::CVector> &vertices, sint32 left, sint32 right, std::vector<COrderedChain> &chains, uint16 thisId,
00238                                                                                          std::vector<COrderedChain3f> &fullChains);
00239 
00240         void                                                            setLoopIndexes(sint32 surface, uint loop, uint loopIndex)
00241         {
00242                 if (_Left == surface)
00243                 {
00244                         _LeftLoop = loop;
00245                         _LeftLoopIndex = loopIndex;
00246                 }
00247                 else
00248                 {
00249                         _RightLoop = loop;
00250                         _RightLoopIndex = loopIndex;
00251                 }
00252         }
00253 
00254         void                                                            setBorderChainIndex(sint32 id)  { _Right = convertBorderChainId(id); }
00255 
00256 public:
00257 
00259         CChain() :      _Left(-1), _Right(-1), _StartTip(0xffff), _StopTip(0xffff), _Length(0.0f),
00260                                 _LeftLoop(0), _LeftLoopIndex(0), _RightLoop(0), _RightLoopIndex(0) {}
00261 
00263         const std::vector<uint16>                       &getSubChains() const { return _SubChains; }
00264 
00266         uint16                                                          getSubChain(uint n) const { return _SubChains[n]; }
00267 
00269         sint32                                                          getLeft() const { return _Left; }
00270         uint8                                                           getLeftLoop() const { return _LeftLoop; }
00271         uint8                                                           getLeftLoopIndex() const { return _LeftLoopIndex; }
00272 
00274         sint32                                                          getRight() const { return _Right; }
00275         uint8                                                           getRightLoop() const { return _RightLoop; }
00276         uint8                                                           getRightLoopIndex() const { return _RightLoopIndex; }
00277 
00279         float                                                           getLength() const { return _Length; }
00280 
00282         sint32                                                          getBorderChainIndex() const
00283         {
00284                 return (isBorderChainId(_Right)) ? convertBorderChainId(_Right) : -1;
00285         }
00286 
00288         static bool                                                     isBorderChainId(sint32 id) { return id <= -256; }
00289 
00291         static sint32                                           convertBorderChainId(sint32 id) { return -(id+256); }
00292 
00294         bool                                                            isBorderChain() const { return isBorderChainId(_Right); }
00295 
00297         static sint32                                           getDummyBorderChainId() { return convertBorderChainId(0); }
00298 
00300         uint16                                                          getStartTip() const { return _StartTip; }
00301 
00303         uint16                                                          getStopTip() const { return _StopTip; }
00304 
00306         void                                                            serial(NLMISC::IStream &f);
00307 
00308 protected:
00310         void                                                            unify(std::vector<COrderedChain> &ochains);
00311 
00313         void                                                            setStartVector(const CVector2s &v, std::vector<COrderedChain> &ochains);
00314 
00316         void                                                            setStopVector(const CVector2s &v, std::vector<COrderedChain> &ochains);
00317 
00319         CVector2s                                                       getStartVector(std::vector<COrderedChain> &ochains);
00320 
00321         //
00322         CVector2s                                                       getStopVector(std::vector<COrderedChain> &ochains);
00323 };
00324 
00325 
00326 
00327 
00328 
00329 //
00330 inline void                                                             COrderedChain3f::unpack(const COrderedChain &chain)
00331 {
00332         uint    i, mx;
00333         const std::vector<CVector2s>    &vertices = chain.getVertices();
00334         mx = _Vertices.size();
00335         _Vertices.resize(vertices.size());
00336         _Forward = chain.isForward();
00337         _ParentId = chain.getParentId();
00338         _IndexInParent = chain.getIndexInParent();
00339         for (i=0; i<vertices.size(); ++i)
00340         {
00341                 _Vertices[i] = vertices[i].unpack3f(i >= mx ? 0.0f : _Vertices[i].z);
00342         }
00343 }
00344 
00345 }; // NLPACS
00346 
00347 #endif // NL_CHAIN_H
00348 
00349 /* End of chain.h */