topology.h

Go to the documentation of this file.
00001 
00002 //**************************************************************************/
00003 // Copyright (c) 2008 Autodesk, Inc.
00004 // All rights reserved.
00005 //
00006 // Use of this software is subject to the terms of the Autodesk license
00007 // agreement provided at the time of installation or download, or which
00008 // otherwise accompanies this software in either electronic or hard copy form.
00009 //
00010 //**************************************************************************/
00011 // DESCRIPTION:
00012 // CREATED: October 2008
00013 //**************************************************************************/
00014 
00015 #include <memory.h>
00016 
00017 namespace mudbox {
00018     
00020 typedef short int tnormal;
00022 typedef unsigned long long tnormalv;
00023 
00025 struct Normal
00026 {
00027     union
00028     {
00029         tnormal m_vNormal[4];
00030         tnormalv m_iNormal;
00031     };
00032 };
00033 
00035 
00045 class MBDLL_DECL Topology : virtual public TreeNode
00046 {
00047 public:
00048     enum FaceState
00049     {
00050         fsSelected = 0x01,
00051         fsVisible = 0x02,
00052         fsFake = 0x04,
00053         fsActive = 0x08,
00054         fsMapped = 0x10,
00055         // fsTemp = 0x20    // for performance reasons, the temp state is split into a seperate vector
00056     };
00057 
00058     enum FaceComponent
00059     {
00060         fcIndex = 1,
00061         fcAdjacency = 2,
00062         fcTCIndex = 4,
00063         fcNormal = 8,
00064         fcID = 16,
00065         fcOctree = 32,
00066         fcFreeze = 64,
00067         fcState = 128
00068     };
00069     enum FaceType
00070     {
00071         typeTriangular,
00072         typeQuadric
00073     };
00074 
00075 protected:
00076     Store<unsigned int>  m_pTCI;
00077     Store<unsigned int>  m_pAdjacency;
00078     Store<unsigned int>  m_pNormalIndices;
00079 public:
00080     Store<unsigned int>  m_pIndices;
00081 private:
00082     Store<unsigned char> m_pFaceState;
00083     Store<unsigned char> m_pFaceTemp; // this is split out from the state byte for performance reasons. -- I.A.
00084     Store<unsigned int>  m_pFaceIDs;
00085 
00086     FaceType m_eType;
00087     int m_eFaceComponents;
00088     unsigned int m_iFaceCount;
00089 
00090 protected:
00092     Topology( void );
00094     Topology( FaceType eType );
00095 public:
00097 
00100     void MoveTo( Topology *pDestination );
00102 
00103 
00109     void CopyTo( Node *pNode ) const;
00111     void Serialize( Stream &s );
00113     inline FaceType Type( void ) const { return m_eType; };
00115     void SetType( FaceType eType );
00117     int SideCount( void ) const { return Type() == typeTriangular ? 3 : 4; };
00118 
00119     // basic data access
00121     inline unsigned int FaceCount( void ) const { return m_iFaceCount; };
00123     virtual Vector FaceNormal( unsigned int iFaceIndex ) const;
00125     inline void SetFaceID( unsigned int iFaceIndex, unsigned int iID ) { m_pFaceIDs[iFaceIndex] = iID; };
00127     inline unsigned int FaceID( unsigned int iFaceIndex ) const { return m_pFaceIDs[iFaceIndex]; };
00128 
00131     virtual void SetFakeTriangleCount( unsigned int iFakeTriangleCount );
00132 
00135     inline unsigned int QuadIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pIndices[iFaceIndex*4+iCornerIndex]; };
00138     inline void SetQuadIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pIndices[iFaceIndex*4+iCornerIndex] = iValue; };
00143     inline unsigned int QuadCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pNormalIndices[iFaceIndex*4+iCornerIndex]; }
00145     inline void SetQuadCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pNormalIndices[iFaceIndex*4+iCornerIndex] = iValue; }
00147     inline unsigned int QuadTCI( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pTCI[iFaceIndex*4+iCornerIndex]; }
00149     inline void SetQuadTCI( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pTCI[iFaceIndex*4+iCornerIndex] = iValue; }
00153     virtual inline unsigned int QuadAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*4+iSideIndex]; }
00154     inline unsigned int QuadAdjacency_ForcedInline( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*4+iSideIndex]; }
00156     virtual inline void SetQuadAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue ) 
00157         { m_pAdjacency[iFaceIndex*4+iSideIndex] = iValue; }
00159     inline bool HasAdjacentQuad( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return QuadAdjacency( iFaceIndex, iSideIndex ) < 0x80000000; };
00160 
00164     inline unsigned int TriangleIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pIndices[iFaceIndex*3+iCornerIndex]; };
00166     inline void SetTriangleIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pIndices[iFaceIndex*3+iCornerIndex] = iValue; };
00171     inline unsigned int TriangleCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pNormalIndices[iFaceIndex*3+iCornerIndex]; }
00173     inline void SetTriangleCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pNormalIndices[iFaceIndex*3+iCornerIndex] = iValue; }
00175     inline unsigned int TriangleTCI( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pTCI[iFaceIndex*3+iCornerIndex]; }
00178     inline void SetTriangleTCI( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pTCI[iFaceIndex*3+iCornerIndex] = iValue; }
00182     virtual inline unsigned int TriangleAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*3+iSideIndex]; }
00184     virtual inline void SetTriangleAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue ) 
00185         { m_pAdjacency[iFaceIndex*3+iSideIndex] = iValue; }
00187     inline bool HasAdjacentTriangle( unsigned int iFaceIndex, unsigned int iSideIndex ) const 
00188         { return TriangleAdjacency( iFaceIndex, iSideIndex ) < 0x80000000; };
00189 
00191     inline unsigned char &FaceState( unsigned int iFaceIndex ) { return m_pFaceState[iFaceIndex]; };
00193     inline unsigned char FaceState( unsigned int iFaceIndex ) const { return m_pFaceState[iFaceIndex]; };
00194 
00196     inline bool IsFaceSelected( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsSelected) != 0; };
00201     virtual void SetFaceSelected( unsigned int iFaceIndex, bool bSelected = true, bool bUpdateVertexSelection = false, bool bBatchSelection = false );
00202 
00204     virtual unsigned int SelectedFaceCount() const;
00205 
00207     inline bool IsFaceVisible( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsVisible) != 0; };
00209     inline virtual void SetFaceVisible( unsigned int iFaceIndex, bool bVisible = true ) 
00210         { if ( bVisible ) FaceState( iFaceIndex ) |= fsVisible; else FaceState( iFaceIndex ) &= 0xff-fsVisible; };
00211     inline bool IsFaceActive( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsActive) != 0; };
00212     inline void SetFaceActive( unsigned int iFaceIndex, bool bSelected = true ) 
00213         { if ( bSelected ) FaceState( iFaceIndex ) |= fsActive; else FaceState( iFaceIndex ) &= 0xff-fsActive; };
00215     inline bool IsFaceMapped( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsMapped) != 0; };
00217     inline void SetFaceMapped( unsigned int iFaceIndex, bool bSelected = true ) 
00218         { if ( bSelected ) FaceState( iFaceIndex ) |= fsMapped; else FaceState( iFaceIndex ) &= 0xff-fsMapped; };
00219 
00225     inline bool IsFakeTriangle( unsigned int iTriangleIndex ) const 
00226         { return iTriangleIndex < FaceCount() && (FaceState( iTriangleIndex ) & fsFake); };
00227     inline void SetFakeTriangle( unsigned int iTriangleIndex, bool b ) 
00228         { if( iTriangleIndex < FaceCount() ) { 
00229             if ( b ) FaceState( iTriangleIndex ) |= fsFake; 
00230             else     FaceState( iTriangleIndex ) &= 0xff-fsFake; 
00231           }; 
00232         };
00233 
00234     inline bool IsFaceTemp( unsigned int iFaceIndex ) const { return m_pFaceTemp[iFaceIndex]; };
00235     inline void SetFaceTemp( unsigned int iFaceIndex, bool bSelected = true ) 
00236         { m_pFaceTemp[iFaceIndex] = bSelected; }
00237 
00238     // do a fast clear of all the temp state flags for all the faces.
00239     inline void ClearFaceTempStates()
00240     {
00241         MB_ASSERT(m_iFaceCount <= m_pFaceTemp.ItemCount()); 
00242         memset(&m_pFaceTemp[0], 0, m_iFaceCount);  // memset is the fastest way to clear the array.
00243     }
00244 
00247     virtual void AddFaceComponent( FaceComponent eComponentToAdd );
00249 
00250     virtual void RemoveFaceComponent( FaceComponent eComponentToRemove );
00252     inline unsigned int FaceComponents( void ) const { return m_eFaceComponents; };
00254     void SetFaceCount( unsigned int iFaceCount );
00256     virtual bool SetAdjacencyCount( unsigned int iCount, bool bKeepContent = true, bool bForced = false );
00258     inline unsigned int AdjacencyCount( void ) const { return m_pAdjacency.ItemCount(); };
00259 
00261     virtual bool HasTShape() const;
00262     virtual void SetHasTShape( bool bHasTShape );
00263 
00264     virtual void CheckValidity( DiagnosticLevel iLevel = dgnLevel2 ) const;
00265 
00266     // Used only to solve some old compatibility issues
00267 
00268     friend class ::XMesh;
00269 };
00270 
00271 }; // end of namespace mudbox