HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GD_TrimRegion.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: This is the trimming region class.
9  *
10  */
11 
12 #ifndef __GD_TrimRegion_h__
13 #define __GD_TrimRegion_h__
14 
15 #include "GD_API.h"
16 #include <GA/GA_Types.h>
17 #include <UT/UT_LinkList.h>
18 #include <UT/UT_BoundingRect.h>
19 #include <SYS/SYS_Math.h>
20 
21 class UT_IStream;
22 class GA_PrimitiveGroup;
23 class GD_Detail;
24 class GD_Face;
25 class GD_Primitive;
26 class GD_TrimLoop;
27 class GA_LoadMap;
28 class GA_SaveMap;
29 
31 {
32 public:
33  GD_TrimFace(GD_Face &face, float ustart, float ustop) : myFace(face)
34  {
35  myUstart = ustart;
36  myUstop = ustop;
37  }
38  ~GD_TrimFace() override;
39 
40  const GD_Face &face() const { return myFace; }
41  float uStop() const { return myUstop; }
42  float uStart() const { return myUstart; }
43 
44  int operator==(const GD_TrimFace &tface) const
45  {
46  return (&myFace == &tface.myFace ) &&
47  SYSisEqual( myUstart, tface.myUstart) &&
48  SYSisEqual( myUstop, tface.myUstop );
49  }
50 
51  void reverse();
52  GD_TrimLoop *buildLoop() const;
53 
54  int save(std::ostream &os, int binary) const;
55  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &map) const;
56 
57  // Load information for a face from a JSON file.
58  static bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &map,
59  GA_Offset &face_offset, fpreal &u0, fpreal &u1);
60 
61 private:
62  GD_Face &myFace;
63  float myUstart;
64  float myUstop;
65 };
66 
67 
69 {
70 public:
71  GD_TrimRegionFlags() { dirty = 1; opencasual = 0; domainclipped=0; }
72  unsigned opencasual:1,
73  dirty:1,
74  domainclipped:1;
75 };
76 
77 
79 {
80 public:
81  GD_TrimRegion(int opencasual = 0); // keep direction of open faces
82  ~GD_TrimRegion() override;
83 
84  virtual int64 getMemoryUsage(bool inclusive) const;
85 
86  // Reverse the order of the trim faces in the region
87  void reverse() override;
88 
89  // Find out about our flags:
90  int isDirty() const { return myFlags.dirty; }
91  int isOpenCasual()const { return myFlags.opencasual; }
92  int isValid() const { return myLoop &&
93  !myFlags.dirty; }
94 
95  int getNum () const { return myNum; }
96 
97  // Grab a handle to the loop of curve pieces. The non-const method
98  // builds it if necessary.
99  const GD_TrimLoop *getLoop() const { return myLoop; }
100  GD_TrimLoop *getLoop(const UT_BoundingRect &brect,
101  float tolerance = 1e-4F,
102  int doDomainClip = 1);
103 
104  // Find out if the region contains the given primitive or any primitive
105  // in the group:
106  int contains(const GD_Primitive &prim ) const;
107  int contains(const GA_PrimitiveGroup &group,
108  int count_how_many = 0 ) const;
109 
110  // Returns the number of GD_TrimFaces removed or 0 if none.
111  int remove(const GD_Primitive &prim );
112  int remove(const GA_PrimitiveGroup &group);
113 
114  // Merges into the given group all faces inside this trimregion:
115  void merge(GA_PrimitiveGroup *group) const;
116 
117  // Copy from source. Return 0 if OK and -1 otherwise.
118  int copy(GD_Detail &gdp, const GD_TrimRegion &src,
119  int primoffset);
120 
121  // I/O stuff:
122  bool load(GD_Detail &gdp, UT_IStream &is);
123  int save(std::ostream &os, int binary) const;
124 
125 
126  /// @{
127  /// JSON IO
128  ///
129  bool jsonLoad(GD_Detail &gdp, UT_JSONParser &p, const GA_LoadMap &map);
130  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &map) const;
131  /// @}
132 
133 protected:
134  void setNum(int num) { myNum = num; }
135  void initialize();
136 
137 private:
138  int myNum; // Only the detail can set this...
139  GD_TrimRegionFlags myFlags;
140  GD_TrimLoop *myLoop;
141 
142  friend class GD_Detail;
143 };
144 
145 #endif
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
int getNum() const
Definition: GD_TrimRegion.h:95
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
void reverse(I begin, I end)
Definition: pugixml.cpp:7190
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
float uStop() const
Definition: GD_TrimRegion.h:41
GLdouble u1
Definition: glad.h:2676
GA_Size GA_Offset
Definition: GA_Types.h:641
int operator==(const GD_TrimFace &tface) const
Definition: GD_TrimRegion.h:44
int isValid() const
Definition: GD_TrimRegion.h:92
float uStart() const
Definition: GD_TrimRegion.h:42
long long int64
Definition: SYS_Types.h:116
Options during loading.
Definition: GA_LoadMap.h:42
GD_TrimFace(GD_Face &face, float ustart, float ustop)
Definition: GD_TrimRegion.h:33
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
const GD_TrimLoop * getLoop() const
Definition: GD_TrimRegion.h:99
#define GD_API
Definition: GD_API.h:10
void setNum(int num)
fpreal64 fpreal
Definition: SYS_Types.h:277
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
int isOpenCasual() const
Definition: GD_TrimRegion.h:91
int isDirty() const
Definition: GD_TrimRegion.h:90
const GD_Face & face() const
Definition: GD_TrimRegion.h:40
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
Definition: UT_Vector2.h:674
bool OIIO_UTIL_API contains(string_view a, string_view b)
Does 'a' contain the string 'b' within it?
GLenum src
Definition: glcorearb.h:1793