HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Decompose.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU_Csup.h (GU Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 
13 #ifndef __GU_Decompose_h__
14 #define __GU_Decompose_h__
15 
16 #include "GU_API.h"
17 #include <UT/UT_Classifier.h>
18 #include <UT/UT_Map.h>
19 #include <UT/UT_Set.h>
20 #include <GA/GA_Handle.h>
21 #include <SYS/SYS_Types.h>
22 
23 class GU_Detail;
25 class GA_Group;
26 class GEO_Hedge;
27 
28 class GA_VertexGroup;
29 class GA_EdgeGroup;
30 class GA_PrimitiveGroup;
31 class GA_PointGroup;
32 
34 {
35 public:
36 
38  {
39  MAXIMAL_MANIFOLD = 0,
40  EULER_TRAVERSAL
41  };
42 
43  GU_Decompose(const GU_Detail *gdp,
44  const GA_Group *grp,
45  const GA_Group *split_grp = NULL,
46  bool split_all = false,
47  const GEO_DetachedHedgeInterface *hip = NULL,
48  DecompositionType dectype = MAXIMAL_MANIFOLD);
49 
50  ~GU_Decompose();
51 
52 
53  int fillComponentIDAttribute(GA_RWHandleI &attrib);
54 
55  /// Returns the number of maximal manifold components.
56  int getNumComponents();
57 
58  /// Returns the total number of boundary chains (cycles) in all the
59  /// components.
60  /// Note that some components may have no boundary chains and other may
61  /// have multiple. For a 2-manifold maximal patch, i.e. one made of
62  /// primitives, each boundary chain is a closed cycle of edges. For
63  /// a 1-manifold maximal patch, i.e. oen made of edges, the boundary chain
64  /// (when non-empty) consists of the two endpoints.
65  int getNumBoundaries();
66 
67  /// Returns the number of boundary components of a given component.
68  int getComponentNumBoundaries(int comp);
69 
70  /// Returns index of the primitive component to which the idx-th
71  /// boundary cycle belongs.
72  int getBoundaryComponentID(int idx);
73 
74  bool isComponentClosed(int idx);
75 
76  GA_Offset *getComponent(int idx, int &length);
77  int getComponentSize(int idx);
78  int getComponentSizesSum();
79 
80  int getBoundarySize(int idx);
81  /// Returns a pointer to an array of half-edges which form the
82  /// boundary cycle of numbered idx among all boundary cycles.
83  GA_Offset *getBoundary(int idx, int &length);
84 
85  int getComponentBoundarySize(int comp, int i);
86  /// Returns a pointer to an array of half-edges which form the
87  /// idx-th boundary cycle among all boundary chains for the patch comp.
88  /// (first index is zero).
89  GA_Offset *getComponentBoundary(int comp, int idx, int &length);
90 
91  int getBoundarySizesSum();
92 
94  { return myGroupType; }
95 
96  struct Iterator
97  {
98  Iterator(GU_Decompose *dec, int k, int b) :
99  myIdx(0)
100  {
101  myOffsets = b < 0 ?
102  dec->getComponent(k, mySize) :
103  k < 0 ?
104  dec->getBoundary(b, mySize):
105  dec->getComponentBoundary(k, b, mySize);
106 
107  myClosed = b < 0 ?
108  dec->isComponentClosed(k) : true;
109  }
110 
111  Iterator(const Iterator &it) :
112  myIdx(it.myIdx), mySize(it.mySize),
113  myOffsets(it.myOffsets), myClosed(it.myClosed) {}
114 
115  Iterator(int i, int s, GA_Offset *offs, bool closed) :
116  myIdx(i), mySize(s), myOffsets(offs),
117  myClosed(closed) {}
118 
119  inline bool operator==(const Iterator &it) const
120  { return myIdx == it.myIdx; }
121 
122  inline bool operator!=(const Iterator &it) const
123  { return myIdx != it.myIdx;}
124 
125  /// Pre-increment operator
126  Iterator &operator++() { advance(); return *this; }
127  Iterator &operator--() { retreat(); return *this; }
128 
129  inline bool atStart() const { return (myIdx == 0); }
130  inline bool atEnd() const { return (myIdx == mySize); }
131 
132  inline void advance() { myIdx += (myIdx < mySize); }
133  inline void retreat() { myIdx -= (myIdx > 0); }
134 
135  inline void rewind() { myIdx = 0; }
136  inline void forward() { myIdx = mySize; }
137 
139  { return Iterator(0, mySize, myOffsets, myClosed); }
141  { return Iterator(mySize - 1, mySize, myOffsets,
142  myClosed); }
143 
145  { return ((myIdx < mySize - 1 || !myClosed) ?
146  Iterator(myIdx + 1, mySize, myOffsets,
147  myClosed) : first());
148  }
149 
151  { return ((myIdx > 0 || !myClosed) ?
152  Iterator(myIdx - 1, mySize, myOffsets,
153  myClosed) : last()); }
154 
156  { return ((myIdx >= 0 && myIdx <= mySize) ?
157  myOffsets[myIdx] : GA_INVALID_OFFSET); }
158 
159  bool isClosed() const { return myClosed; }
160 
161 
162  int myIdx, mySize;
164  bool myClosed;
165  };
166 
168  { return Iterator(this, comp, -1); }
169 
171  { return Iterator(this, -1, bd); }
172 
174  { return Iterator(this, comp, bd); }
175 
176 private:
177  void setRanksInGroup();
178  void buildPrimComponents();
179 
180  int rankInGroup(GA_Offset prim_off,
181  bool check_in_group = false) const;
182 
183  bool isPrimComponentClosed(int idx) { return false; }
184  int extractPatches();
185  int extractPrimBoundaries();
186  int componentRank(GEO_Hedge h);
187 
188  bool isPathClosed(int idx);
189  GA_Offset *getPath(int idx, int &length);
190  GA_Offset *getPrimComponent(int idx, int &length);
191  GA_Offset *getPrimComponentBoundary(int idx, int &length);
192 
193  int extractPaths();
194  int extractMaximalPaths();
195  int extractEulerPaths();
196 
197  int getPrimComponentSizesSum();
198  int getEdgeComponentSizesSum();
199 
200  void reversePath(int i);
201 
202  const GU_Detail *myGdp;
203  GA_GroupType myGroupType;
204  bool mySplitAll;
205 
206  bool myOwnHedgeInterface;
207 
209  myPrimRankInGroup;
210 
211  UT_Classifier myPrimClasses;
212  UT_IntArray myPatchRank;
213  UT_Array<GEO_Hedge> myBoundaryHedges;
214  UT_Set<GA_Offset> myBoundarySrcVertices;
215 
216  int myNumPatches;
217 
218  UT_IntArray myPatchBoundaryStart;
219  UT_IntArray myPatchBoundaryEnd;
220  UT_IntArray myBoundaryPatchID;
221  UT_IntArray myPatchFirstBoundary;
222  UT_IntArray myPatchLastBoundary;
223 
224  GA_OffsetArray myPatchPrims;
225  UT_IntArray myPatchStart;
226  UT_IntArray myPatchEnd;
227  UT_Array<GEO_Hedge> myCycleHedges;
228 
229  const GA_EdgeGroup *mySplitEdges;
230  const GA_PointGroup *mySplitPoints;
231 
232  int myNumPaths;
233  UT_IntArray myPathStarts;
234  UT_IntArray myPathEnds;
235  UT_Array<bool> myPathClosed;
236  GA_OffsetArray myPathPoints;
237 
238  DecompositionType myDecompositionType;
239 
240  const GA_EdgeGroup *myEdges;
241 
242  const GA_VertexGroup *myHedges;
243  const GA_PrimitiveGroup *myPrims;
244  const GEO_DetachedHedgeInterface *myHip;
245 
246 
247 };
248 #endif
GLint first
Definition: glcorearb.h:404
bool operator==(const Iterator &it) const
Definition: GU_Decompose.h:119
GA_GroupType getGroupType()
Definition: GU_Decompose.h:93
Iterator(const Iterator &it)
Definition: GU_Decompose.h:111
bool isClosed() const
Definition: GU_Decompose.h:159
Iterator & operator++()
Pre-increment operator.
Definition: GU_Decompose.h:126
png_uint_32 i
Definition: png.h:2877
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
Iterator getBoundaryIterator(int bd)
Definition: GU_Decompose.h:170
GA_Size GA_Offset
Definition: GA_Types.h:617
bool isComponentClosed(int idx)
Iterator & operator--()
Definition: GU_Decompose.h:127
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
bool operator!=(const Iterator &it) const
Definition: GU_Decompose.h:122
Iterator getComponentIterator(int comp)
Definition: GU_Decompose.h:167
bool atStart() const
Definition: GU_Decompose.h:129
#define GU_API
Definition: GU_API.h:12
Iterator(int i, int s, GA_Offset *offs, bool closed)
Definition: GU_Decompose.h:115
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GA_Offset operator*() const
Definition: GU_Decompose.h:155
GA_Offset * getComponentBoundary(int comp, int idx, int &length)
Iterator(GU_Decompose *dec, int k, int b)
Definition: GU_Decompose.h:98
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:138
Iterator getComponentBoundaryIterator(int comp, int bd)
Definition: GU_Decompose.h:173
GA_Offset * getComponent(int idx, int &length)
GA_Offset * getBoundary(int idx, int &length)
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794