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 private:
00076     Store<unsigned int>  m_pTCI;
00077     Store<unsigned int>  m_pAdjacency;
00078 public:
00079     Store<unsigned int>  m_pIndices;
00080 private:
00081     Store<unsigned char> m_pFaceState;
00082     Store<unsigned char> m_pFaceTemp; // this is split out from the state byte for performance reasons. -- I.A.
00083     Store<unsigned int>  m_pFaceIDs;
00084 
00085     FaceType m_eType;
00086     int m_eFaceComponents;
00087     unsigned int m_iFaceCount;
00088 
00089 protected:
00091     Topology( void );
00093     Topology( FaceType eType );
00094 public:
00096 
00099     void MoveTo( Topology *pDestination );
00101 
00102 
00108     void CopyTo( Topology *pDestination ) const;
00110     void Serialize( Stream &s );
00112     inline FaceType Type( void ) const { return m_eType; };
00114     void SetType( FaceType eType );
00116     int SideCount( void ) const { return Type() == typeTriangular ? 3 : 4; };
00117 
00118     // basic data access
00120     inline unsigned int FaceCount( void ) const { return m_iFaceCount; };
00122     virtual Vector FaceNormal( unsigned int iFaceIndex ) const;
00124     inline void SetFaceID( unsigned int iFaceIndex, unsigned int iID ) { m_pFaceIDs[iFaceIndex] = iID; };
00126     inline unsigned int FaceID( unsigned int iFaceIndex ) const { return m_pFaceIDs[iFaceIndex]; };
00127 
00130     virtual void SetFakeTriangleCount( unsigned int iFakeTriangleCount );
00131 
00134     inline unsigned int QuadIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pIndices[iFaceIndex*4+iCornerIndex]; };
00137     inline void SetQuadIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pIndices[iFaceIndex*4+iCornerIndex] = iValue; };
00139     inline unsigned int QuadTCI( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pTCI[iFaceIndex*4+iCornerIndex]; }
00141     inline void SetQuadTCI( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pTCI[iFaceIndex*4+iCornerIndex] = iValue; }
00145     virtual inline unsigned int QuadAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*4+iSideIndex]; }
00146     inline unsigned int QuadAdjacency_ForcedInline( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*4+iSideIndex]; }
00148     virtual inline void SetQuadAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue ) 
00149         { m_pAdjacency[iFaceIndex*4+iSideIndex] = iValue; }
00151     inline bool HasAdjacentQuad( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return QuadAdjacency( iFaceIndex, iSideIndex ) < 0x80000000; };
00152 
00156     inline unsigned int TriangleIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pIndices[iFaceIndex*3+iCornerIndex]; };
00158     inline void SetTriangleIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pIndices[iFaceIndex*3+iCornerIndex] = iValue; };
00160     inline unsigned int TriangleTCI( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pTCI[iFaceIndex*3+iCornerIndex]; }
00163     inline void SetTriangleTCI( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pTCI[iFaceIndex*3+iCornerIndex] = iValue; }
00167     virtual inline unsigned int TriangleAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*3+iSideIndex]; }
00169     virtual inline void SetTriangleAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue ) 
00170         { m_pAdjacency[iFaceIndex*3+iSideIndex] = iValue; }
00172     inline bool HasAdjacentTriangle( unsigned int iFaceIndex, unsigned int iSideIndex ) const 
00173         { return TriangleAdjacency( iFaceIndex, iSideIndex ) < 0x80000000; };
00174 
00176     inline unsigned char &FaceState( unsigned int iFaceIndex ) { return m_pFaceState[iFaceIndex]; };
00178     inline unsigned char FaceState( unsigned int iFaceIndex ) const { return m_pFaceState[iFaceIndex]; };
00179 
00181     inline bool IsFaceSelected( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsSelected) != 0; };
00186     virtual void SetFaceSelected( unsigned int iFaceIndex, bool bSelected = true, bool bUpdateVertexSelection = false, bool bBatchSelection = false );
00187 
00189     virtual unsigned int SelectedFaceCount() const;
00190 
00192     inline bool IsFaceVisible( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsVisible) != 0; };
00194     inline void SetFaceVisible( unsigned int iFaceIndex, bool bSelected = true ) 
00195         { if ( bSelected ) FaceState( iFaceIndex ) |= fsVisible; else FaceState( iFaceIndex ) &= 0xff-fsVisible; };
00196     inline bool IsFaceActive( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsActive) != 0; };
00197     inline void SetFaceActive( unsigned int iFaceIndex, bool bSelected = true ) 
00198         { if ( bSelected ) FaceState( iFaceIndex ) |= fsActive; else FaceState( iFaceIndex ) &= 0xff-fsActive; };
00200     inline bool IsFaceMapped( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsMapped) != 0; };
00202     inline void SetFaceMapped( unsigned int iFaceIndex, bool bSelected = true ) 
00203         { if ( bSelected ) FaceState( iFaceIndex ) |= fsMapped; else FaceState( iFaceIndex ) &= 0xff-fsMapped; };
00204 
00210     inline bool IsFakeTriangle( unsigned int iTriangleIndex ) const 
00211         { return iTriangleIndex < FaceCount() && (FaceState( iTriangleIndex ) & fsFake); };
00212     inline void SetFakeTriangle( unsigned int iTriangleIndex, bool b ) 
00213         { if( iTriangleIndex < FaceCount() ) { 
00214             if ( b ) FaceState( iTriangleIndex ) |= fsFake; 
00215             else     FaceState( iTriangleIndex ) &= 0xff-fsFake; 
00216           }; 
00217         };
00218 
00219     inline bool IsFaceTemp( unsigned int iFaceIndex ) const { return m_pFaceTemp[iFaceIndex]; };
00220     inline void SetFaceTemp( unsigned int iFaceIndex, bool bSelected = true ) 
00221         { m_pFaceTemp[iFaceIndex] = bSelected; }
00222 
00223     // do a fast clear of all the temp state flags for all the faces.
00224     inline void ClearFaceTempStates()
00225     {
00226         MB_ASSERT(m_iFaceCount <= m_pFaceTemp.ItemCount()); 
00227         memset(&m_pFaceTemp[0], 0, m_iFaceCount);  // memset is the fastest way to clear the array.
00228     }
00229 
00232     virtual void AddFaceComponent( FaceComponent eComponentToAdd );
00234 
00235     virtual void RemoveFaceComponent( FaceComponent eComponentToRemove );
00237     inline unsigned int FaceComponents( void ) const { return m_eFaceComponents; };
00239     void SetFaceCount( unsigned int iFaceCount );
00241     virtual bool SetAdjacencyCount( unsigned int iCount, bool bKeepContent = true, bool bForced = false );
00243     inline unsigned int AdjacencyCount( void ) const { return m_pAdjacency.ItemCount(); };
00244 
00246     virtual bool HasTShape() const;
00247     virtual void SetHasTShape( bool bHasTShape );
00248 
00249     // Used only to solve some old compatibility issues
00250 
00251     friend class ::XMesh;
00252 };
00253 
00254 }; // end of namespace mudbox
00255