UVlessPainting/UVMeshGrid.h Source File

UVMeshGrid.h
Go to the documentation of this file.
1 #ifndef __UV_MESH_GRID_H
2 #define __UV_MESH_GRID_H
3 
4 #if defined(JAMBUILD)
5 #include <Mudbox/mudbox.h>
6 #else
7 #include "../../include/Mudbox/mudbox.h"
8 #endif
9 
10 using namespace mudbox;
11 
12 struct Quad
13 {
14  Quad() :
15  m_pMesh(0),
16  m_iFaceIndex(0xffffffff),
17  m_iSide(0xffffffff)
18  {
19  };
20 
21  Quad( const Mesh *pMesh, unsigned int iFaceIndex, int iSide = 0 )
22  {
23  m_pMesh = pMesh;
24  m_iFaceIndex = iFaceIndex;
25  m_iSide = iSide;
26  };
27 
28  // 0 - current side
29  // 1 - left
30  // 2 - opposite
31  // 3 - right
32  //
33  bool Step( int iDirection = 0 )
34  {
35  unsigned int a = m_pMesh->QuadAdjacency( m_iFaceIndex, (m_iSide+iDirection)%4 );
36  if ( a == 0xffffffff )
37  return false;
38  m_iFaceIndex = a/4;
39  m_iSide = (a%4+2-iDirection)%4;
40  return true;
41  };
42  unsigned int Corner( int iIndex ) const
43  {
44  return m_pMesh->QuadIndex( m_iFaceIndex, (m_iSide+iIndex)%4 );
45  };
46  unsigned int CornerTCI( int iIndex )
47  {
48  return m_pMesh->QuadTCI( m_iFaceIndex, (m_iSide+iIndex)%4 );
49  };
50  Vector CornerPosition( int iIndex ) const
51  {
52  return m_pMesh->QuadVertexPosition( m_iFaceIndex, (m_iSide+iIndex)%4 );
53  };
54  Vector Center( void ) const
55  {
56  return (CornerPosition(0)+CornerPosition(1)+CornerPosition(2)+CornerPosition(3))*0.25f;
57  };
58  void TurnRight( void )
59  {
60  m_iSide = (m_iSide+3)%4;
61  };
62  void TurnLeft( void )
63  {
64  m_iSide = (m_iSide+1)%4;
65  };
66  Quad& operator=( const Quad& pOther )
67  {
68  m_pMesh = pOther.m_pMesh;
69  m_iFaceIndex = pOther.m_iFaceIndex;
70  m_iSide = pOther.m_iSide;
71  return *this;
72  };
73 
74  const Mesh *m_pMesh;
75  unsigned int m_iFaceIndex;
76  int m_iSide;
77 };
78 
79 // this is similar to the MudboxMeshGrid,
80 // but different in the following ways:
81 // 1. dimensions of the grid do not need to be POT
82 // 2. grids do not need to be square
83 // 3. all grids do not need to be the same dimensions
84 // 4. vertex/faceIDs are not reordered.
85 // 5. works on non-quad meshes (but only quads are grouped together)
86 // 6. this one probably takes more memory, not to be used on dense meshes.
87 class UVMeshGrid : public Node
88 {
90 
91  struct GridData
92  {
93  QVector< unsigned int > m_iFaces;
94 
95  // TODO: only need 2 bits per face, since there are only 4 possible values.
96  // the other 6 bits are wasted :(
97  QVector< char > m_iOrientations;
98 
99  unsigned int m_iWidth;
100  unsigned int m_iHeight;
101  };
102 
103  struct Solution
104  {
105  QVector< GridData* > m_aGrids;
106  float m_fFitness;
107  ~Solution()
108  {
109  for( int i = 0; i < m_aGrids.size(); ++i )
110  MB_SDN( m_aGrids[i] );
111  };
112  };
113 
114  UVMeshGrid();
115  ~UVMeshGrid();
116 
117  void SetMaxGridDimension( unsigned int iMax ) { m_iMaxDimension = iMax; }
118  void MeshGridDimensions( unsigned int iGrid, unsigned int& iWidth, unsigned int& iHeight ) const;
119  unsigned int MeshGridCount( void ) const { return m_pSolution ? m_pSolution->m_aGrids.size() : 0; }
120  unsigned int MeshGridFaceIndex( unsigned int iGrid, unsigned int iX, unsigned int iY ) const;
121 
122  // returns the bottom-left corner of the face, relative to the bottom-left corner of the grid.
123  unsigned int MeshGridFaceOrientation( unsigned int iGrid, unsigned int iX, unsigned int iY ) const;
124 
125  unsigned int MeshGridBleed( unsigned int iGrid, unsigned int iDefaultBleed ) const;
126 
127  // returns the centerpoint of the grid, in local space
128  Vector MeshGridCenter( unsigned int iGrid ) const;
129 
130  void SetMesh( Mesh* pMesh );
131 
132  // Clear the data.
133  void Clear( void );
134 private:
135  aptr<Mesh> m_pMesh;
136  aptr<Mesh> m_pQuadMesh;
137  unsigned int m_iMaxDimension;
138  Solution* m_pSolution;
139 
140 
141  Solution* FindGrids( int iGridSize, Quad cCorner );
142  float ComputeFitness( const Solution* pSolution );
143  Quad FindEV( const Mesh* pMesh ) const;
144  Mesh *QuadMesh( Mesh *pSource );
145  unsigned int QuadMeshIndex( unsigned int iQuadFaceIndex );
146  const Vector& QuadVertexPosition( unsigned int iTriangleIndex, unsigned int iMeshCorner, unsigned int iFaceOrientation ) const;
147  void AddNonQuadFaces();
148 
149 
150  QVector<unsigned int > m_aQuadMap;
151 };
152 
153 #endif
Represents a 3D vector or point with S23E8 floating point elements.
Definition: math.h:35
A Mesh is a collection of vertices organized into faces, and optional Texture Coordinate information...
Definition: mesh.h:452
Quad()
Definition: UVMeshGrid.h:14
unsigned int Corner(int iIndex) const
Definition: UVMeshGrid.h:42
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
Vector Center(void) const
Definition: UVMeshGrid.h:54
void TurnLeft(void)
Definition: UVMeshGrid.h:62
unsigned int CornerTCI(int iIndex)
Definition: UVMeshGrid.h:46
unsigned int m_iFaceIndex
Definition: UVMeshGrid.h:75
void TurnRight(void)
Definition: UVMeshGrid.h:58
Class: ConvolutionKernel.
Definition: array.h:15
const Mesh * m_pMesh
Definition: UVMeshGrid.h:72
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
bool Step(int iDirection=0)
Definition: UVMeshGrid.h:33
Quad(const Mesh *pMesh, unsigned int iFaceIndex, int iSide=0)
Definition: UVMeshGrid.h:21
int size() const
Definition: qvector.h:137
int m_iSide
Definition: UVMeshGrid.h:76
#define DECLARE_CLASS
This macro should be used in declaration of classes which are inherited from the Node class (or any d...
Definition: node.h:91
Quad & operator=(const Quad &pOther)
Definition: UVMeshGrid.h:66
#define MB_SDN(a)
Utility macro to safely delete and reset a pointer.
Definition: mudbox.h:300
Vector CornerPosition(int iIndex) const
Definition: UVMeshGrid.h:50