HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~GD_Detail() override;
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  }
113  bool and_points = false) override;
115  const GA_Range &it,
116  bool and_points = false) override;
117 
118  //
119  // Appending and deleting a trimming region:
120  //
121  // opencasual true will preserve direction of open profiles.
122  GD_TrimRegion *appendTrimRegion(int opencasual = 0);
123  void deleteTrimRegion(GD_TrimRegion &region);
124  void deleteTrimRegion(unsigned int num);
125  GD_TrimLoop *generateTrimLoops(const UT_BoundingRect &brect,
126  float offset=1e-4F,
127  float tol=1e-4F);
128  void destroyTrimRegions(int deletecurves=1);
129  void createTrimRegion(GD_TrimLoop *loop);
130 
131 
132  //
133  // Find the bounding box (optionally of a group of points)
134  // instantiation. Return 0 if the box is empty and 1 otherwise.
135  //
136  int getPointBBox(UT_BoundingBox *bbox,
137  const GA_PointGroup *g = 0) const;
138  int getPointBBox(UT_BoundingBox& bbox,
139  const UT_Matrix4R& transform,
140  const GA_PointGroup *g=0) const;
141  int getPointBSphere(UT_BoundingSphere *bsphere,
142  const GA_PointGroup *g = 0,
143  int updateRequired = 0) const;
144 
145  //
146  // Return the bounds of the valid interval of the surface we're defined
147  // for.
148  //
149  virtual void getDomainBBox(float &u0, float &v0,
150  float &u1, float &v1) const = 0;
152  {
153  getDomainBBox(rect.vals[0][0], rect.vals[1][0],
154  rect.vals[0][1], rect.vals[1][1]);
155  }
156 
157  // Return the number of (visible) faces.
158  int getNumFaces(int *visible = 0) const;
159 
160  // Find out if it is a valid trimmer. At least one trim loop must have
161  // already been computed from the trim regions for this method to return
162  // true.
163  int hasTrimLoops() const;
164 
165  // Find out if there are any trim regions. A short-cut for
166  // trimRegions().entries().
167  int hasTrimRegions() const;
168 
169  // *Const* handle to the trimming regions:
171  { return myTrimRegions; }
172 
173  // Build an outer trim loop to allow us to punch holes into the surface.
174  // Return loop if OK and 0 otherwise. The method does not check if the
175  // outer loop already exists. The size of the loop will be increased by
176  // the tolerance. The direction of the loop is counter-clockwise.
177  GD_TrimRegion *appendOuterLoop(float tol = 0, int checkduplicate = 1);
178 
179  // Get or set the altitude flag, which affects the level where we start
180  // counting the nested loops for trimming. Typically, it's sea-level: zero.
181  int altitude() const { return myAltitude; }
182  void altitude(int a) { myAltitude = a; }
183 
184  // Typedefs for the GA_Detail::GB_MACRO_CAST() static methods.
186 
187  // The trimming regions:
188  UT_ValArray<GD_TrimRegion*> &trimRegions() { return myTrimRegions; }
189 
190  // TODO: Deprecate internal groups with user-specified names.
191  GA_PointGroup *newPointGroup(const char *name, int internal);
192  GA_PrimitiveGroup *newPrimitiveGroup(const char *name, int internal);
196  { destroyElementGroup(g); }
198  { destroyElementGroup(g); }
199  bool destroyPointGroup(const char *name)
200  { return
202  bool destroyPrimitiveGroup(const char *name)
203  { return
205 
206  // Load and save the list of trimming regions:
207  bool loadTrimRegions(int n, UT_IStream &is);
208  int saveTrimRegions(int n, std::ostream &os, int b=0) const;
209 
210  bool loadTrimRegions(UT_JSONParser &p, const GA_LoadMap &map);
211  bool saveTrimRegions(UT_JSONWriter &w, const GA_SaveMap &map) const;
212 
213  int64 getMemoryUsage(bool inclusive) const override;
214 
216  bool inclusive) const override;
217 
218 private:
219  UT_ValArray<GD_TrimRegion*> myTrimRegions; // list of trim regions
220  int myAltitude; // sea-level for nested loops
221 
222  bool loadPointsH9(UT_IStream &is, int count);
223  bool savePointsH9(std::ostream &os, int binary) const;
224  bool savePointH9(std::ostream &os, int binary, GA_Offset offset) const;
225 
226  void setPos2(GA_Offset index, const UT_Vector2 &p);
227 
228  // Friends:
229  friend std::ostream &operator<<(std::ostream &os, const GD_Detail &d)
230  {
231  d.saveClassic(os, false, NULL);
232  return os;
233  }
234 };
235 
236 #endif
bool destroyPrimitiveGroup(const char *name)
Definition: GD_Detail.h:202
GLenum src
Definition: glew.h:2410
UT_ValArray< GD_TrimRegion * > & trimRegions()
Definition: GD_Detail.h:188
GLuint const GLchar * name
Definition: glew.h:1814
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_PointGroup * newInternalPointGroup()
Definition: GA_Detail.h:1254
GLuint GLenum GLenum transform
Definition: glew.h:14742
GLuint index
Definition: glew.h:1814
GLuint GLdouble u1
Definition: glew.h:3446
bool GAisValid(GA_Size v)
Definition: GA_Types.h:647
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
GD_Primitive * appendPrimitive(const GA_PrimitiveTypeId &type)
Definition: GD_Detail.h:107
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:76
IOStatus saveClassic(const char *, const GA_SaveOptions *) const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
const GD_Primitive * getGDPrimitive(GA_Offset offset) const
Definition: GD_Detail.h:92
GA_PrimitiveGroup * newInternalPrimitiveGroup()
Definition: GA_Detail.h:1262
GA_PointGroup * newPointGroup(const UT_StringHolder &name)
Definition: GA_Detail.h:1231
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:233
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:1239
GA_Size GA_Offset
Definition: GA_Types.h:639
GD_Primitive GB_MACRO_PRIM_TYPE
Definition: GD_Detail.h:185
void destroyPrimitiveGroup(GA_PrimitiveGroup *g)
Definition: GD_Detail.h:197
SYS_FORCE_INLINE bool destroyElementGroup(GA_AttributeOwner owner, const UT_StringRef &name)
Definition: GA_Detail.h:1178
const GLuint GLenum const void * binary
Definition: glew.h:3502
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
GLsizei n
Definition: glew.h:4040
const UT_ValArray< GD_TrimRegion * > & trimRegions() const
Definition: GD_Detail.h:170
long long int64
Definition: SYS_Types.h:116
Options during loading.
Definition: GA_LoadMap.h:42
GA_Offset appendPointOffset()
Definition: GD_Detail.h:81
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
void getDomainBounds(UT_BoundingRect &rect) const
Definition: GD_Detail.h:151
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
friend std::ostream & operator<<(std::ostream &os, const GD_Detail &d)
Definition: GD_Detail.h:229
SYS_FORCE_INLINE const GA_Primitive * get(GA_Offset off) const
GLuint counter
Definition: glew.h:2740
#define GD_API
Definition: GD_API.h:10
GLuint num
Definition: glew.h:2690
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const
virtual GA_Size destroyPrimitiveOffsets(const GA_Range &it, bool and_points=false)
GLuint GLuint GLsizei count
Definition: glew.h:1253
GLfloat v0
Definition: glew.h:1848
const GA_PrimitiveList & getPrimitiveList() const
Definition: GA_Detail.h:735
#define GA_INVALID_INDEX
Definition: GA_Types.h:675
GA_Offset appendPointOffset(const UT_Vector3 &pos)
Definition: GD_Detail.h:83
void altitude(int a)
Definition: GD_Detail.h:182
Container class for all geometry.
Definition: GA_Detail.h:95
void destroyPointGroup(GA_PointGroup *g)
Definition: GD_Detail.h:195
virtual bool destroyPrimitiveOffset(GA_Offset offset, bool and_points=false)
PUGI__FN char_t * translate(char_t *buffer, const char_t *from, const char_t *to, size_t to_length)
Definition: pugixml.cpp:8352
void setPos2(GA_Offset ptoff, const UT_Vector2 &P)
Set P from a UT_Vector2.
Definition: GA_Detail.h:200
Class to specify options for loading geometry.
bool destroyPointGroup(const char *name)
Definition: GD_Detail.h:199
int altitude() const
Definition: GD_Detail.h:181
GLfloat GLfloat v1
Definition: glew.h:1852
GLboolean GLboolean g
Definition: glew.h:9477
GLintptr offset
Definition: glew.h:1682