Mudbox/topology.h Source File

topology.h
Go to the documentation of this file.
1 
2 //**************************************************************************/
3 // Copyright (c) 2008 Autodesk, Inc.
4 // All rights reserved.
5 //
6 // Use of this software is subject to the terms of the Autodesk license
7 // agreement provided at the time of installation or download, or which
8 // otherwise accompanies this software in either electronic or hard copy form.
9 //
10 //**************************************************************************/
11 // DESCRIPTION:
12 // CREATED: October 2008
13 //**************************************************************************/
14 
15 #include <memory.h>
16 
17 namespace mudbox {
18 
20 typedef short int tnormal;
22 typedef unsigned long long tnormalv;
23 
25 struct Normal
26 {
27  union
28  {
29  tnormal m_vNormal[4];
30  tnormalv m_iNormal;
31  };
32 };
33 
35 
45 class MBDLL_DECL Topology : virtual public TreeNode
46 {
47 public:
48  enum FaceState
49  {
50  fsSelected = 0x01,
51  fsVisible = 0x02,
52  fsFake = 0x04,
53  fsActive = 0x08,
54  fsMapped = 0x10,
55  fsIsolated = 0x20 // this bit is used to store the previous Visible state when mudbox is in Isolate mode (and vice-versa)
56  };
57 
59  {
60  fcIndex = 1,
61  fcAdjacency = 2,
62  fcTCIndex = 4,
63  fcNormal = 8,
64  fcID = 16,
65  fcOctree = 32,
66  fcFreeze = 64,
67  fcState = 128
68  };
69 
70  enum FaceType
71  {
73  typeQuadric
74  };
75 
77  {
79  eDynamicTopology
80  };
81 
82 protected:
86 public:
88 private:
89  Store<unsigned char> m_pFaceState;
90  Store<unsigned char> m_pFaceTemp; // this is split out from the state byte for performance reasons. -- I.A.
91  Store<unsigned int> m_pFaceIDs;
92 
93  FaceType m_eType;
94  int m_eFaceComponents;
95  unsigned int m_iFaceCount;
96 
97 protected:
99 
101  Topology( void );
103  Topology( FaceType eType );
104 public:
106 
109  void MoveTo( Topology *pDestination );
111 
112 
118  void CopyTo( Node *pNode ) const;
120  void Serialize( Stream &s );
122  inline FaceType Type( void ) const { return m_eType; };
124  void SetType( FaceType eType );
126  int SideCount( void ) const { return Type() == typeTriangular ? 3 : 4; };
127 
128  // basic data access
130  inline unsigned int FaceCount( void ) const { return m_iFaceCount; };
132  virtual Vector FaceNormal( unsigned int iFaceIndex ) const;
134  inline void SetFaceID( unsigned int iFaceIndex, unsigned int iID ) { m_pFaceIDs[iFaceIndex] = iID; };
136  inline unsigned int FaceID( unsigned int iFaceIndex ) const { return m_pFaceIDs[iFaceIndex]; };
137 
140  virtual void SetFakeTriangleCount( unsigned int iFakeTriangleCount );
141 
144  inline unsigned int QuadIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pIndices[iFaceIndex*4+iCornerIndex]; };
147  inline void SetQuadIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pIndices[iFaceIndex*4+iCornerIndex] = iValue; };
152  inline unsigned int QuadCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pNormalIndices[iFaceIndex*4+iCornerIndex]; }
154  inline void SetQuadCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pNormalIndices[iFaceIndex*4+iCornerIndex] = iValue; }
156  inline unsigned int QuadTCI( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pTCI[iFaceIndex*4+iCornerIndex]; }
158  inline void SetQuadTCI( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pTCI[iFaceIndex*4+iCornerIndex] = iValue; }
162  virtual inline unsigned int QuadAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*4+iSideIndex]; }
163  inline unsigned int QuadAdjacency_ForcedInline( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*4+iSideIndex]; }
165  virtual inline void SetQuadAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue )
166  { m_pAdjacency[iFaceIndex*4+iSideIndex] = iValue; }
168  inline bool HasAdjacentQuad( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return QuadAdjacency( iFaceIndex, iSideIndex ) < 0x80000000; };
169 
173  inline unsigned int TriangleIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pIndices[iFaceIndex*3+iCornerIndex]; };
175  inline void SetTriangleIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pIndices[iFaceIndex*3+iCornerIndex] = iValue; };
180  inline unsigned int TriangleCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pNormalIndices[iFaceIndex*3+iCornerIndex]; }
182  inline void SetTriangleCreaseNormalIndex( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pNormalIndices[iFaceIndex*3+iCornerIndex] = iValue; }
184  inline unsigned int TriangleTCI( unsigned int iFaceIndex, unsigned int iCornerIndex ) const { return m_pTCI[iFaceIndex*3+iCornerIndex]; }
187  inline void SetTriangleTCI( unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue ) { m_pTCI[iFaceIndex*3+iCornerIndex] = iValue; }
191  virtual inline unsigned int TriangleAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex ) const { return m_pAdjacency[iFaceIndex*3+iSideIndex]; }
193  virtual inline void SetTriangleAdjacency( unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue )
194  { m_pAdjacency[iFaceIndex*3+iSideIndex] = iValue; }
196  inline bool HasAdjacentTriangle( unsigned int iFaceIndex, unsigned int iSideIndex ) const
197  { return TriangleAdjacency( iFaceIndex, iSideIndex ) < 0x80000000; };
198 
200  inline unsigned char &FaceState( unsigned int iFaceIndex ) { return m_pFaceState[iFaceIndex]; };
202  inline unsigned char FaceState( unsigned int iFaceIndex ) const { return m_pFaceState[iFaceIndex]; };
203 
205  inline bool IsFaceSelected( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsSelected) != 0; };
210  virtual void SetFaceSelected( unsigned int iFaceIndex, bool bSelected = true, bool bUpdateVertexSelection = false, bool bBatchSelection = false );
211 
213  virtual unsigned int SelectedFaceCount() const;
214 
216  inline bool IsFaceVisible( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsVisible) != 0; };
218  inline virtual void SetFaceVisible( unsigned int iFaceIndex, bool bVisible = true )
219  { if ( bVisible ) FaceState( iFaceIndex ) |= fsVisible; else FaceState( iFaceIndex ) &= 0xff-fsVisible; };
220  inline bool IsFaceActive( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsActive) != 0; };
221  inline void SetFaceActive( unsigned int iFaceIndex, bool bSelected = true )
222  { if ( bSelected ) FaceState( iFaceIndex ) |= fsActive; else FaceState( iFaceIndex ) &= 0xff-fsActive; };
224  inline bool IsFaceMapped( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsMapped) != 0; };
226  inline void SetFaceMapped( unsigned int iFaceIndex, bool bSelected = true )
227  { if ( bSelected ) FaceState( iFaceIndex ) |= fsMapped; else FaceState( iFaceIndex ) &= 0xff-fsMapped; };
229  inline bool IsFaceIsolated( unsigned int iFaceIndex ) const { return (FaceState( iFaceIndex ) & fsIsolated) != 0; };
231  inline virtual void SetFaceIsolated( unsigned int iFaceIndex, bool bIsolated = true )
232  { if ( bIsolated ) FaceState( iFaceIndex ) |= fsIsolated; else FaceState( iFaceIndex ) &= 0xff-fsIsolated; };
233 
239  inline bool IsFakeTriangle( unsigned int iTriangleIndex ) const
240  { return iTriangleIndex < FaceCount() && (FaceState( iTriangleIndex ) & fsFake); };
241  inline void SetFakeTriangle( unsigned int iTriangleIndex, bool b )
242  { if( iTriangleIndex < FaceCount() ) {
243  if ( b ) FaceState( iTriangleIndex ) |= fsFake;
244  else FaceState( iTriangleIndex ) &= 0xff-fsFake;
245  };
246  };
247 
248  inline bool IsFaceTemp( unsigned int iFaceIndex ) const { return m_pFaceTemp[iFaceIndex]; };
249  inline void SetFaceTemp( unsigned int iFaceIndex, bool bSelected = true )
250  { m_pFaceTemp[iFaceIndex] = bSelected; }
251 
252  // do a fast clear of all the temp state flags for all the faces.
253  inline void ClearFaceTempStates()
254  {
255  MB_ASSERT(m_iFaceCount <= m_pFaceTemp.ItemCount());
256  if( m_iFaceCount <= m_pFaceTemp.ItemCount() &&
257  m_pFaceTemp.ItemCount() > 0 )
258  memset(&m_pFaceTemp[0], 0, m_iFaceCount); // memset is the fastest way to clear the array.
259  }
260 
263  virtual void AddFaceComponent( FaceComponent eComponentToAdd );
265 
266  virtual void RemoveFaceComponent( FaceComponent eComponentToRemove );
268  inline unsigned int FaceComponents( void ) const { return m_eFaceComponents; };
270  virtual void SetFaceCount( unsigned int iFaceCount );
272  virtual bool SetAdjacencyCount( unsigned int iCount, bool bKeepContent = true, bool bForced = false );
274  inline unsigned int AdjacencyCount( void ) const { return m_pAdjacency.ItemCount(); };
275 
277  virtual bool HasTShape() const;
279  virtual const Store<unsigned int> &TShapeFaces( void ) const;
280 
283  virtual void SetTopologyHint( TopologyHint eHint );
284 
285  virtual enum TopologyHint TopologyHint() const;
286 
287  virtual void CheckValidity( DiagnosticLevel iLevel = dgnLevel2 ) const;
288 
289  // Used only to solve some old compatibility issues
290 
291  friend class ::XMesh;
292 };
293 
294 }; // end of namespace mudbox
void SetQuadTCI(unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue)
Sets the vertex texture coordinate index of a corner of a quad.
Definition: topology.h:158
unsigned char FaceState(unsigned int iFaceIndex) const
Sets the state of a face.
Definition: topology.h:202
bool HasAdjacentTriangle(unsigned int iFaceIndex, unsigned int iSideIndex) const
Returns true if the given edge of a triangle has an adjacent triangle on the other side...
Definition: topology.h:196
Represents a 3D vector or point with S23E8 floating point elements.
Definition: math.h:35
Store< unsigned int > m_pIndices
Definition: topology.h:87
#define MB_ASSERT(condition)
Definition: mudbox.h:73
bool IsFaceActive(unsigned int iFaceIndex) const
Definition: topology.h:220
unsigned int FaceCount(void) const
Returns the number of faces in the topology.
Definition: topology.h:130
FaceType Type(void) const
Returns the type of the topology. Can be full triangular or full quadric.
Definition: topology.h:122
void SetQuadCreaseNormalIndex(unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue)
Sets the vertex normal index of a corner of a quad.
Definition: topology.h:154
virtual void SetTriangleAdjacency(unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue)
Sets the adjacency info for a side of a triangle. See TriangleAdjacency for details.
Definition: topology.h:193
unsigned int AdjacencyCount(void) const
Returns the size of the adjacency matrix.
Definition: topology.h:274
virtual void SetFaceIsolated(unsigned int iFaceIndex, bool bIsolated=true)
Sets the Isolation state of a given face.
Definition: topology.h:231
virtual unsigned int QuadAdjacency(unsigned int iFaceIndex, unsigned int iSideIndex) const
Returns the vertex adjacency information index of a side of a quad.
Definition: topology.h:162
int SideCount(void) const
Returns the number of sides in the faces. This is three if the topology is triangle based...
Definition: topology.h:126
Normal vector with 16 bit components.
Definition: topology.h:25
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
tnormal m_vNormal[4]
Definition: topology.h:29
unsigned long long tnormalv
Type of the whole normal vector.
Definition: topology.h:22
unsigned int QuadIndex(unsigned int iFaceIndex, unsigned int iCornerIndex) const
Returns the vertex position index of a corner of a quad.
Definition: topology.h:144
bool IsFaceVisible(unsigned int iFaceIndex) const
Returns true if the given face is visible.
Definition: topology.h:216
short int tnormal
Type of one component in a normal vector.
Definition: topology.h:20
void SetFakeTriangle(unsigned int iTriangleIndex, bool b)
Definition: topology.h:241
virtual void SetQuadAdjacency(unsigned int iFaceIndex, unsigned int iSideIndex, unsigned int iValue)
Sets the adjacency info for a side of a quad. See QuadAdjacency for details.
Definition: topology.h:165
void SetTriangleIndex(unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue)
Sets the vertex position index of a corner of a triangle.
Definition: topology.h:175
virtual unsigned int TriangleAdjacency(unsigned int iFaceIndex, unsigned int iSideIndex) const
Returns the vertex adjacency information index of a side of a triangle.
Definition: topology.h:191
unsigned int TriangleCreaseNormalIndex(unsigned int iFaceIndex, unsigned int iCornerIndex) const
Returns the vertex crease/hard normal index of a corner of triangle, if there is crease/hard normal o...
Definition: topology.h:180
unsigned int QuadCreaseNormalIndex(unsigned int iFaceIndex, unsigned int iCornerIndex) const
Returns the vertex crease/hard normal index of a corner of quad, if there is crease/hard normal of th...
Definition: topology.h:152
Store< unsigned int > m_pTCI
Definition: topology.h:83
void SetTriangleCreaseNormalIndex(unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue)
Sets the vertex normal index of a corner of a triangle.
Definition: topology.h:182
bool IsFakeTriangle(unsigned int iTriangleIndex) const
This function can only be used for triangular meshes.
Definition: topology.h:239
bool HasAdjacentQuad(unsigned int iFaceIndex, unsigned int iSideIndex) const
Returns true if the given edge of a quad has an adjacent quad on the other side.
Definition: topology.h:168
virtual void SetFaceVisible(unsigned int iFaceIndex, bool bVisible=true)
Sets the visibility of a given face.
Definition: topology.h:218
void SetQuadIndex(unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue)
Sets the vertex position index of a corner of a quad.
Definition: topology.h:147
GLubyte GLubyte b
Definition: GLee.h:5404
unsigned int ItemCount(void) const
Returns the number of items in the array.
Definition: array.h:645
bool IsFaceMapped(unsigned int iFaceIndex) const
Used only internally.
Definition: topology.h:224
bool IsFaceTemp(unsigned int iFaceIndex) const
Definition: topology.h:248
TopologyHint m_eTopologyHint
Definition: topology.h:98
Store< unsigned int > m_pAdjacency
Definition: topology.h:84
Class: ConvolutionKernel.
Definition: array.h:15
This class is the base of all node types that can be structured in a hierarchy.
Definition: treenode.h:18
unsigned char & FaceState(unsigned int iFaceIndex)
Returns the state of a face. See FaceState.
Definition: topology.h:200
void SetFaceMapped(unsigned int iFaceIndex, bool bSelected=true)
Used only internally.
Definition: topology.h:226
unsigned int TriangleIndex(unsigned int iFaceIndex, unsigned int iCornerIndex) const
Returns the vertex position index of a corner of a triangle.
Definition: topology.h:173
void SetTriangleTCI(unsigned int iFaceIndex, unsigned int iCornerIndex, unsigned int iValue)
Sets the vertex texture coordinate index of a corner of a triangle.
Definition: topology.h:187
unsigned int FaceID(unsigned int iFaceIndex) const
This function is used only internally.
Definition: topology.h:136
tnormalv m_iNormal
Definition: topology.h:30
void SetFaceTemp(unsigned int iFaceIndex, bool bSelected=true)
Definition: topology.h:249
unsigned int FaceComponents(void) const
Returns the current face components for the object.
Definition: topology.h:268
unsigned int TriangleTCI(unsigned int iFaceIndex, unsigned int iCornerIndex) const
Returns the vertex texture coordinate index of a corner of a triangle.
Definition: topology.h:184
Streams are used to read information from a file, or to write it to a file.
Definition: stream.h:39
void SetFaceActive(unsigned int iFaceIndex, bool bSelected=true)
Definition: topology.h:221
void SetFaceID(unsigned int iFaceIndex, unsigned int iID)
This function is used only internally.
Definition: topology.h:134
bool IsFaceSelected(unsigned int iFaceIndex) const
Returns true if the given face is selected.
Definition: topology.h:205
GLdouble s
Definition: GLee.h:1173
Store< unsigned int > m_pNormalIndices
Definition: topology.h:85
Represents the topology data of a mesh, providing information about the structure of a surface...
Definition: topology.h:45
unsigned int QuadTCI(unsigned int iFaceIndex, unsigned int iCornerIndex) const
Returns the vertex texture coordinate index of a corner of a quad.
Definition: topology.h:156
#define MBDLL_DECL
Definition: dllinterface.h:35
bool IsFaceIsolated(unsigned int iFaceIndex) const
Returns true if the given face is in the set of Isolated faces.
Definition: topology.h:229
void ClearFaceTempStates()
Definition: topology.h:253
unsigned int QuadAdjacency_ForcedInline(unsigned int iFaceIndex, unsigned int iSideIndex) const
Definition: topology.h:163