HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GD_Detail.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: Geometry Library (C++)
7  *
8  * COMMENTS:
9  * This defines the detail class (the container for all points/primitives)
10  */
11 
12 #ifndef __GD_Detail_h__
13 #define __GD_Detail_h__
14 
15 #include "GD_API.h"
16 #include <UT/UT_BoundingRect.h>
17 #include <UT/UT_ValArray.h>
18 #include <GA/GA_Detail.h>
19 #include "GD_Primitive.h"
20 #include "GD_Macros.h"
21 
22 #include <UT/UT_VectorTypes.h>
23 class UT_BoundingSphere;
24 class GD_TrimRegion;
25 class GD_TrimLoop;
26 class GD_Primitive;
27 class UT_MemoryCounter;
28 
29 class GD_API GD_Detail : public GA_Detail
30 {
31 public:
32  GD_Detail();
33  virtual ~GD_Detail();
34 
35  static void registerFactory();
36 
37  //
38  // Clear all the points/primitives out of this detail
39  //
40  void clearAndDestroy();
41 
42  //
43  // Stream I/O METHODS
44  //
45  GA_Detail::IOStatus saveH9Stream(std::ostream& os, bool binary,
46  const GA_SaveOptions *options) const;
47  GA_Detail::IOStatus loadH9(UT_IStream &is, const GA_LoadOptions *options);
48 
49  //
50  // Merge the source detail into us.
51  //
52  void merge(const GD_Detail &src, bool onlyvisible = false);
53 
54  //
55  // Transform/translate all or some of the primitives. The methods will run
56  // more efficiently if you happen to know the point closure apriori.
57  // If 'quickxform' is true, we don't transform the attributes and don't
58  // check for reflection matrix.
59  //
60  void transform(const UT_Matrix3 &matx,
61  GA_PrimitiveGroup *primgroup = 0,
62  GA_PointGroup *pointclosure = 0);
63  void translate(const UT_Vector2 &delta,
64  GA_PrimitiveGroup *primgroup = 0,
65  GA_PointGroup *pointclosure = 0);
66 
67  //
68  // Transform/translate all or some of the points.
69  //
70  void transformPoints(const UT_Matrix3 &matx,
71  GA_PointGroup *pointgroup = 0);
72  void translatePoints(const UT_Vector2 &delta,
73  GA_PointGroup *pointGroup = 0);
74 
75  //
76  // Methods for adding to the point list.
77  //
78  GA_Offset insertPointOffset(GA_Index before = GA_INVALID_INDEX);
79  GA_Offset insertPointOffset(const UT_Vector3 &pos,
80  GA_Index before = GA_INVALID_INDEX);
82  { return insertPointOffset(); }
84  { return insertPointOffset(pos); }
85 
87  {
88  if (!GAisValid(offset))
89  return NULL;
90  return static_cast<GD_Primitive *>(getPrimitiveList().get(offset));
91  }
93  {
94  if (!GAisValid(offset))
95  return NULL;
96  return static_cast<const GD_Primitive *>(getPrimitiveList().get(offset));
97  }
98 
99  //
100  // Inserting and appending a new primitive
101  // Insertion works the same way as insertion of points. However,
102  // The primitive is not allocated since the type is determined
103  // by the allocator.
104  //
105  GD_Primitive *insertPrimitive(const GA_PrimitiveTypeId &type,
106  const GD_Primitive *before = 0);
108  {
109  return insertPrimitive(type, 0);
110  }
112  bool and_points = false);
113  virtual GA_Size destroyPrimitiveOffsets(const GA_Range &it,
114  bool and_points = false);
115 
116  //
117  // Appending and deleting a trimming region:
118  //
119  // opencasual true will preserve direction of open profiles.
120  GD_TrimRegion *appendTrimRegion(int opencasual = 0);
121  void deleteTrimRegion(GD_TrimRegion &region);
122  void deleteTrimRegion(unsigned int num);
123  GD_TrimLoop *generateTrimLoops(const UT_BoundingRect &brect,
124  float offset=1e-4F,
125  float tol=1e-4F);
126  void destroyTrimRegions(int deletecurves=1);
127  void createTrimRegion(GD_TrimLoop *loop);
128 
129 
130  //
131  // Find the bounding box (optionally of a group of points)
132  // instantiation. Return 0 if the box is empty and 1 otherwise.
133  //
134  int getPointBBox(UT_BoundingBox *bbox,
135  const GA_PointGroup *g = 0) const;
136  int getPointBBox(UT_BoundingBox& bbox,
137  const UT_Matrix4R& transform,
138  const GA_PointGroup *g=0) const;
139  int getPointBSphere(UT_BoundingSphere *bsphere,
140  const GA_PointGroup *g = 0,
141  int updateRequired = 0) const;
142 
143  //
144  // Return the bounds of the valid interval of the surface we're defined
145  // for.
146  //
147  virtual void getDomainBBox(float &u0, float &v0,
148  float &u1, float &v1) const = 0;
150  {
151  getDomainBBox(rect.vals[0][0], rect.vals[1][0],
152  rect.vals[0][1], rect.vals[1][1]);
153  }
154 
155  // Return the number of (visible) faces.
156  int getNumFaces(int *visible = 0) const;
157 
158  // Find out if it is a valid trimmer. At least one trim loop must have
159  // already been computed from the trim regions for this method to return
160  // true.
161  int hasTrimLoops(void) const;
162 
163  // Find out if there are any trim regions. A short-cut for
164  // trimRegions().entries().
165  int hasTrimRegions(void) const;
166 
167  // *Const* handle to the trimming regions:
169  { return myTrimRegions; }
170 
171  // Build an outer trim loop to allow us to punch holes into the surface.
172  // Return loop if OK and 0 otherwise. The method does not check if the
173  // outer loop already exists. The size of the loop will be increased by
174  // the tolerance. The direction of the loop is counter-clockwise.
175  GD_TrimRegion *appendOuterLoop(float tol = 0, int checkduplicate = 1);
176 
177  // Get or set the altitude flag, which affects the level where we start
178  // counting the nested loops for trimming. Typically, it's sea-level: zero.
179  int altitude(void ) const { return myAltitude; }
180  void altitude(int a) { myAltitude = a; }
181 
182  // Typedefs for the GA_Detail::GB_MACRO_CAST() static methods.
184 
185  // The trimming regions:
186  UT_ValArray<GD_TrimRegion*> &trimRegions(void) { return myTrimRegions; }
187 
188  // TODO: Deprecate internal groups with user-specified names.
189  GA_PointGroup *newPointGroup(const char *name, int internal);
190  GA_PrimitiveGroup *newPrimitiveGroup(const char *name, int internal);
194  { destroyElementGroup(g); }
196  { destroyElementGroup(g); }
197  bool destroyPointGroup(const char *name)
198  { return
200  bool destroyPrimitiveGroup(const char *name)
201  { return
203 
204  // Load and save the list of trimming regions:
205  bool loadTrimRegions(int n, UT_IStream &is);
206  int saveTrimRegions(int n, std::ostream &os, int b=0) const;
207 
208  bool loadTrimRegions(UT_JSONParser &p, const GA_LoadMap &map);
209  bool saveTrimRegions(UT_JSONWriter &w, const GA_SaveMap &map) const;
210 
211  virtual int64 getMemoryUsage(bool inclusive) const;
212 
213  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
214 
215 private:
216  UT_ValArray<GD_TrimRegion*> myTrimRegions; // list of trim regions
217  int myAltitude; // sea-level for nested loops
218 
219  bool loadPointsH9(UT_IStream &is, int count);
220  bool savePointsH9(std::ostream &os, int binary) const;
221  bool savePointH9(std::ostream &os, int binary, GA_Offset offset) const;
222 
223  void setPos2(GA_Offset index, const UT_Vector2 &p);
224 
225  // Friends:
226  friend std::ostream &operator<<(std::ostream &os, const GD_Detail &d)
227  {
228  d.saveClassic(os, false, NULL);
229  return os;
230  }
231 };
232 
233 #endif
bool destroyPrimitiveGroup(const char *name)
Definition: GD_Detail.h:200
UT_ValArray< GD_TrimRegion * > & trimRegions(void)
Definition: GD_Detail.h:186
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_PointGroup * newInternalPointGroup()
Definition: GA_Detail.h:1234
bool GAisValid(GA_Size v)
Definition: GA_Types.h:625
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLboolean GLboolean g
Definition: glcorearb.h:1221
GD_Primitive * appendPrimitive(const GA_PrimitiveTypeId &type)
Definition: GD_Detail.h:107
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GD_Primitive * getGDPrimitive(GA_Offset offset)
Definition: GD_Detail.h:86
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
IOStatus saveClassic(const char *, const GA_SaveOptions *) const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
const GD_Primitive * getGDPrimitive(GA_Offset offset) const
Definition: GD_Detail.h:92
GA_PrimitiveGroup * newInternalPrimitiveGroup()
Definition: GA_Detail.h:1242
GA_PointGroup * newPointGroup(const UT_StringHolder &name)
Definition: GA_Detail.h:1211
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual int64 getMemoryUsage(bool inclusive) const
Compute memory usage (includes all shared memory)
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_PrimitiveGroup * newPrimitiveGroup(const UT_StringHolder &name)
Definition: GA_Detail.h:1219
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
GD_Primitive GB_MACRO_PRIM_TYPE
Definition: GD_Detail.h:183
GLdouble n
Definition: glcorearb.h:2007
void destroyPrimitiveGroup(GA_PrimitiveGroup *g)
Definition: GD_Detail.h:195
SYS_FORCE_INLINE bool destroyElementGroup(GA_AttributeOwner owner, const UT_StringRef &name)
Definition: GA_Detail.h:1158
GLintptr offset
Definition: glcorearb.h:664
Options during loading.
Definition: GA_LoadMap.h:42
int altitude(void) const
Definition: GD_Detail.h:179
GLuint const GLchar * name
Definition: glcorearb.h:785
GA_Offset appendPointOffset()
Definition: GD_Detail.h:81
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
GA_API const UT_StringHolder transform
GLint GLsizei count
Definition: glcorearb.h:404
GLfloat v0
Definition: glcorearb.h:815
void getDomainBounds(UT_BoundingRect &rect) const
Definition: GD_Detail.h:149
friend std::ostream & operator<<(std::ostream &os, const GD_Detail &d)
Definition: GD_Detail.h:226
SYS_FORCE_INLINE const GA_Primitive * get(GA_Offset off) const
#define GD_API
Definition: GD_API.h:10
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const
virtual GA_Size destroyPrimitiveOffsets(const GA_Range &it, bool and_points=false)
GLuint index
Definition: glcorearb.h:785
GLfloat GLfloat v1
Definition: glcorearb.h:816
const GA_PrimitiveList & getPrimitiveList() const
Definition: GA_Detail.h:715
#define GA_INVALID_INDEX
Definition: GA_Types.h:653
GA_Offset appendPointOffset(const UT_Vector3 &pos)
Definition: GD_Detail.h:83
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
void altitude(int a)
Definition: GD_Detail.h:180
Container class for all geometry.
Definition: GA_Detail.h:96
void destroyPointGroup(GA_PointGroup *g)
Definition: GD_Detail.h:193
png_infop png_uint_32 int num
Definition: png.h:2158
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual bool destroyPrimitiveOffset(GA_Offset offset, bool and_points=false)
void setPos2(GA_Offset ptoff, const UT_Vector2 &P)
Set P from a UT_Vector2.
Definition: GA_Detail.h:196
Class to specify options for loading geometry.
bool destroyPointGroup(const char *name)
Definition: GD_Detail.h:197
const UT_ValArray< GD_TrimRegion * > & trimRegions(void) const
Definition: GD_Detail.h:168
GLenum src
Definition: glcorearb.h:1792