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  bool getPointBBox(
137  UT_BoundingBox *bbox,
138  const GA_PointGroup *g = nullptr) const;
139  bool getPointBBox(
140  UT_BoundingBox& bbox,
141  const UT_Matrix4R& transform,
142  const GA_PointGroup *g = nullptr) const;
143  bool getPointBSphere(
144  UT_BoundingSphere *bsphere,
145  const GA_PointGroup *g = nullptr,
146  bool accurate_bounds = false) const;
147 
148  //
149  // Return the bounds of the valid interval of the surface we're defined
150  // for.
151  //
152  virtual void getDomainBBox(float &u0, float &v0,
153  float &u1, float &v1) const = 0;
155  {
156  getDomainBBox(rect.vals[0][0], rect.vals[1][0],
157  rect.vals[0][1], rect.vals[1][1]);
158  }
159 
160  // Return the number of (visible) faces.
161  int getNumFaces(int *visible = 0) const;
162 
163  // Find out if it is a valid trimmer. At least one trim loop must have
164  // already been computed from the trim regions for this method to return
165  // true.
166  int hasTrimLoops() const;
167 
168  // Find out if there are any trim regions. A short-cut for
169  // trimRegions().entries().
170  int hasTrimRegions() const;
171 
172  // *Const* handle to the trimming regions:
174  { return myTrimRegions; }
175 
176  // Build an outer trim loop to allow us to punch holes into the surface.
177  // Return loop if OK and 0 otherwise. The method does not check if the
178  // outer loop already exists. The size of the loop will be increased by
179  // the tolerance. The direction of the loop is counter-clockwise.
180  GD_TrimRegion *appendOuterLoop(float tol = 0, int checkduplicate = 1);
181 
182  // Get or set the altitude flag, which affects the level where we start
183  // counting the nested loops for trimming. Typically, it's sea-level: zero.
184  int altitude() const { return myAltitude; }
185  void altitude(int a) { myAltitude = a; }
186 
187  // Typedefs for the GA_Detail::GB_MACRO_CAST() static methods.
189 
190  // The trimming regions:
191  UT_ValArray<GD_TrimRegion*> &trimRegions() { return myTrimRegions; }
192 
193  // TODO: Deprecate internal groups with user-specified names.
194  GA_PointGroup *newPointGroup(const char *name, int internal);
195  GA_PrimitiveGroup *newPrimitiveGroup(const char *name, int internal);
199  { destroyElementGroup(g); }
201  { destroyElementGroup(g); }
202  bool destroyPointGroup(const char *name)
203  { return
205  bool destroyPrimitiveGroup(const char *name)
206  { return
208 
209  // Load and save the list of trimming regions:
210  bool loadTrimRegions(int n, UT_IStream &is);
211  int saveTrimRegions(int n, std::ostream &os, int b=0) const;
212 
213  bool loadTrimRegions(UT_JSONParser &p, const GA_LoadMap &map);
214  bool saveTrimRegions(UT_JSONWriter &w, const GA_SaveMap &map) const;
215 
216  int64 getMemoryUsage(bool inclusive) const override;
217 
218  void countMemory(UT_MemoryCounter &counter,
219  bool inclusive) const override;
220 
221 private:
222  UT_ValArray<GD_TrimRegion*> myTrimRegions; // list of trim regions
223  int myAltitude; // sea-level for nested loops
224 
225  bool loadPointsH9(UT_IStream &is, int count);
226  bool savePointsH9(std::ostream &os, int binary) const;
227  bool savePointH9(std::ostream &os, int binary, GA_Offset offset) const;
228 
229  void setPos2(GA_Offset index, const UT_Vector2 &p);
230 
231  // Friends:
232  friend std::ostream &operator<<(std::ostream &os, const GD_Detail &d)
233  {
234  d.saveClassic(os, false, NULL);
235  return os;
236  }
237 };
238 
239 #endif
bool destroyPrimitiveGroup(const char *name)
Definition: GD_Detail.h:205
UT_ValArray< GD_TrimRegion * > & trimRegions()
Definition: GD_Detail.h:191
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_PointGroup * newInternalPointGroup()
Definition: GA_Detail.h:1314
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLboolean GLboolean g
Definition: glcorearb.h:1222
GD_Primitive * appendPrimitive(const GA_PrimitiveTypeId &type)
Definition: GD_Detail.h:107
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
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:87
IOStatus saveClassic(const char *, const GA_SaveOptions *) const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
const GD_Primitive * getGDPrimitive(GA_Offset offset) const
Definition: GD_Detail.h:92
GA_PrimitiveGroup * newInternalPrimitiveGroup()
Definition: GA_Detail.h:1322
GA_PointGroup * newPointGroup(const UT_StringHolder &name)
Definition: GA_Detail.h:1291
GLdouble u1
Definition: glad.h:2676
SYS_FORCE_INLINE bool GAisValid(GA_Size v)
Definition: GA_Types.h:655
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
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:1299
GA_Size GA_Offset
Definition: GA_Types.h:646
GD_Primitive GB_MACRO_PRIM_TYPE
Definition: GD_Detail.h:188
GLdouble n
Definition: glcorearb.h:2008
GLintptr offset
Definition: glcorearb.h:665
void destroyPrimitiveGroup(GA_PrimitiveGroup *g)
Definition: GD_Detail.h:200
SYS_FORCE_INLINE bool destroyElementGroup(GA_AttributeOwner owner, const UT_StringRef &name)
Definition: GA_Detail.h:1238
const UT_ValArray< GD_TrimRegion * > & trimRegions() const
Definition: GD_Detail.h:173
long long int64
Definition: SYS_Types.h:116
Options during loading.
Definition: GA_LoadMap.h:42
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_Offset appendPointOffset()
Definition: GD_Detail.h:81
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GA_API const UT_StringHolder transform
GLfloat v0
Definition: glcorearb.h:816
void getDomainBounds(UT_BoundingRect &rect) const
Definition: GD_Detail.h:154
friend std::ostream & operator<<(std::ostream &os, const GD_Detail &d)
Definition: GD_Detail.h:232
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:786
GLfloat GLfloat v1
Definition: glcorearb.h:817
const GA_PrimitiveList & getPrimitiveList() const
Definition: GA_Detail.h:795
#define GA_INVALID_INDEX
Definition: GA_Types.h:686
GA_Offset appendPointOffset(const UT_Vector3 &pos)
Definition: GD_Detail.h:83
void altitude(int a)
Definition: GD_Detail.h:185
Container class for all geometry.
Definition: GA_Detail.h:96
void destroyPointGroup(GA_PointGroup *g)
Definition: GD_Detail.h:198
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
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 &pos)
Set P from a UT_Vector2.
Definition: GA_Detail.h:225
type
Definition: core.h:1059
Class to specify options for loading geometry.
bool destroyPointGroup(const char *name)
Definition: GD_Detail.h:202
int altitude() const
Definition: GD_Detail.h:184
GLint GLsizei count
Definition: glcorearb.h:405
GLenum src
Definition: glcorearb.h:1793