HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_TriMesh.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: GEO_PrimTriMesh.h (GEO Library, C++)
7  *
8  * COMMENTS: This is the base class for all triangle mesh types.
9  */
10 
11 #pragma once
12 
13 #ifndef __GEO_TriMesh__
14 #define __GEO_TriMesh__
15 
16 #include "GEO_API.h"
17 #include "GEO_Primitive.h"
18 #include "GEO_Vertex.h"
19 #include <UT/UT_Array.h>
20 #include <SYS/SYS_Inline.h>
21 #include <iosfwd>
22 
23 class GA_Detail;
24 class UT_JSONWriter;
25 class UT_JSONParser;
26 class UT_JSONValue;
27 class GA_SaveMap;
28 class GA_LoadMap;
29 
31 
33 {
34 protected:
35  /// NOTE: The constructor should only be called from subclass
36  /// constructors.
39  : GEO_Primitive(d, offset)
40  {}
41 
42 public:
43  bool getBBox(UT_BoundingBox *bbox) const override;
44  void addToBSphere(UT_BoundingSphere *bsphere) const override;
45  UT_Vector3 baryCenter() const override;
46  UT_Vector3D baryCenterD() const override;
47  bool saveH9(std::ostream &os, bool binary,
48  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
49  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs
50  ) const override;
51  bool loadH9(UT_IStream &is,
52  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
53  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs
54  ) override;
55 
56  /// @{
57  /// Method to load/save basis values. Default methods return false (fail)
58  virtual bool jsonSaveBasis(UT_JSONWriter &w) const;
59  virtual bool jsonSaveBasis(UT_JSONValue &v) const;
60  virtual bool jsonLoadBasis(UT_JSONParser &p);
61  virtual bool jsonLoadBasis(UT_JSONParser &p, const UT_JSONValue &v);
62  /// @}
63 
64  /// @{
65  /// Save/Load vertex list to a JSON stream
66  bool saveVertexArray(UT_JSONWriter &w,
67  const GA_SaveMap &map) const;
68  bool loadVertexArray(UT_JSONParser &p,
69  const GA_LoadMap &map);
70  /// @}
71 
72  virtual bool changePointRef(GA_Offset from, GA_Offset to);
73 
74  bool isDegenerate() const override;
75 
76  // Adjust the size of the vertex array.
78  void setSize(GA_Size nvertices)
79  { setNumVertices(nvertices); }
80 
81  // Take the whole set of points into consideration when applying the
82  // point removal operation to this primitive. The method returns 0 if
83  // successful, -1 if it failed because it would have become degenerate,
84  // and -2 if it failed because it would have had to remove the primitive
85  // altogether.
86  int detachPoints(GA_PointGroup &grp) override;
87 
88  /// Before a point is deleted, all primitives using the point will be
89  /// notified. The method should return "false" if it's impossible to
90  /// delete the point. Otherwise, the vertices should be removed.
91  GA_DereferenceStatus dereferencePoint(GA_Offset point,
92  bool dry_run=false) override;
93  GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q,
94  bool dry_run=false) override;
95 
96  // Insert or delete vertices. The insertion methods return the index if
97  // successful and -1 otherwise. The deletion methods return 0 if ok and
98  // -1 otherwise.
99  virtual GA_Size insertVertex(GA_Offset ppt, GA_Size where=0);
100  virtual GA_Size appendVertex(GA_Offset ppt);
101  virtual int deleteVertex(GA_Size num);
102 
103  /// Remove all vertices listed in the array.
104  /// The array must be in order, contain no duplicates, and all
105  /// numbers must be in the range [0, getVertexCount()).
106  virtual void deleteVertices(const UT_Array<GA_Size> &nums);
107 
108  /// return the index of a vertex within our vertex list
109  GA_Size findVertex(GA_Offset vtx) const { return myVertexList.find(vtx); }
110 
111  /// Steal a vertex from its current primitive and insert it into our vertex list.
112  ///
113  /// @param vtx Vertex to be stolen
114  /// @param insert_before_vtx (Optional) the vertex before which to insert the stolen vertex
115  /// If unspecified (negative) or if the vertex doesn't exist, the stolen vertex is
116  /// appended at the end of the vertex list.
117  /// @return The position at which vtx is inserted if successful, or -1 otherwise.
118  virtual GA_Size stealVertex(GA_Offset vtx,
119  GA_Offset insert_before_vtx = GA_INVALID_OFFSET);
120 
121  // Query the number of vertices in the array. This number may be smaller
122  // than the actual size of the array.
124  { return myVertexList.size(); }
125 
127  {
128  UT_ASSERT_P(index >= 0 && index < myVertexList.size());
129  return myVertexList(index);
130  }
131 
132  // Find the index of the given vertex that refers to pt.
133  // Return -1 if not found.
134  GA_Size find(GA_Offset pt) const;
135 
136  // Subscript operators. The () operator does not check the boundaries.
137  SYS_DEPRECATED_HDK(13.0)
138  const GEO_Vertex operator()(GA_Size i) const
139  { return getVertexElement(i); }
140  SYS_DEPRECATED_HDK(13.0)
141  GEO_Vertex operator()(GA_Size i)
142  { return getVertexElement(i); }
143  SYS_DEPRECATED_HDK(13.0)
144  const GEO_Vertex operator[](GA_Size i) const
145  { return getVertexElement(i); }
146  SYS_DEPRECATED_HDK(13.0)
147  GEO_Vertex operator[](GA_Size i)
148  { return getVertexElement(i); }
149 
151  {
152  if (i < myVertexList.entries())
153  wireVertex(myVertexList(i), pt);
154  }
155 
156  // Methods to handle vertex attributes for the attribute dictionary
157  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
158  void *data = 0) const final;
159 
160  // Map the normalized length (distance value [0,1]) parameter to the unit
161  // parameterization of the primitve
162  void unitLengthToUnitPair(
163  float ulength, float vlength,
164  float &uparm, float &vparm) const override;
165  void unitLengthToUnitPair(
166  float ulength, float vlength,
167  float &uparm, float &vparm,
168  float tolerance) const override;
169 
170  void unitToUnitLengthPair(
171  float uparm, float vparm,
172  float &ulength, float &vlength) const override;
173 
174  /// Replaces the entire vertex list.
175  /// Use with *utmost* caution. It probably won't work with Nurbs or
176  /// Polysoups, and possibly other primitives and is only tested for
177  /// Polygons.
178  ///
179  /// @param destroy_existing
180  /// If set, existing vertex offsets are destroyed.
181  /// @param update_topology
182  /// If set, new vertices are wired to the primitive.
183  void assignVertexList(const GA_OffsetList &list,
184  bool destroy_existing = true,
185  bool update_topology = true);
186 
187 protected:
188  static GA_PrimitiveFamilyMask buildFamilyMask() { return GA_FAMILY_NONE; }
189 
190  /// All subclasses should call this method to register the curve intrinsics.
191  /// @see GA_IntrinsicManager
194  { return GEO_Primitive::registerIntrinsics(defn); }
195 
196  virtual bool savePrivateH9(std::ostream &os, bool binary) const = 0;
197  virtual bool loadPrivateH9(UT_IStream &is) = 0;
198 
199  // Check the validity of the data. Meant to be called especially at loading
200  // time.
201  virtual bool validate() const;
202 
203  // Allow derived classes to override the minimum number of vertices needed
204  // for a non-degenerate primitive.
205  virtual GA_Size getMinVertexCount() const { return 3; }
206 
207  // Insert a vertex multiple times in the list. Return the index.
208  GA_Size multipleInsert(GA_Size where,
209  GA_Size count,
210  bool append_pointsss = true);
211 
212  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
214  { return getDetail().vertexPoint(myVertexList(i)); }
215 
216  /// @warning swapVertices() doesn't check the bounds, nor that j != i. Use
217  /// with caution.
219  {
220  GA_Offset tmp = myVertexList(i);
221  myVertexList.set(i, myVertexList(j));
222  myVertexList.set(j, tmp);
223  }
224 
225  bool evaluatePointRefMap(
226  GA_Offset result_vertex,
227  GA_AttributeRefMap &hlist,
228  fpreal u, fpreal v,
229  uint du, uint dv) const override;
231  UT_Vector4 &pos,
232  float u, float v = 0,
233  unsigned du=0, unsigned dv=0) const override
234  { return GEO_Primitive::evaluatePointV4(pos, u, v, du, dv); }
235 
236  bool evaluateBaryCenterRefMap(
237  GA_Offset result_vertex,
238  GA_AttributeRefMap &hlist) const override;
239 
240  /// Release the vertex vtx, i.e. deletes it from myVertexList but doesn't delete
241  /// the offset itself. Consequently, topology information and attributes are preserved.
242  /// It's meant to be used by stealVertex
243  /// @see stealVertex
244  /// @note overriding from GA_Primitive
245  GA_Offset releaseVertex(GA_Offset vtx) override;
246 
247 private:
248 
249 
250  friend std::ostream &operator<<(std::ostream &os, const GEO_TriMesh &d)
251  {
252  d.saveH9(os, 0,
255  return os;
256  }
257 };
258 
260 
261 #endif
262 
void setVertexPoint(GA_Size i, GA_Offset pt)
Definition: GEO_TriMesh.h:150
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
Definition: GEO_TriMesh.h:193
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
const GLdouble * v
Definition: glcorearb.h:837
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
SYS_FORCE_INLINE GEO_TriMesh(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
Definition: GEO_TriMesh.h:38
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
Abstract base class for a range membership query object.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
GA_PrimitiveFamilyMask
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
SYS_FORCE_INLINE GA_Offset getFastVertexOffset(GA_Size index) const
Definition: GEO_TriMesh.h:126
GA_Size GA_Offset
Definition: GA_Types.h:646
GLintptr offset
Definition: glcorearb.h:665
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
#define GEO_API
Definition: GEO_API.h:14
A handle to simplify manipulation of multiple attributes.
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Size i) const
Definition: GEO_TriMesh.h:213
Options during loading.
Definition: GA_LoadMap.h:42
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Offset vertex) const
Given a vertex, return the point it references.
Definition: GA_Detail.h:529
#define SYS_DEPRECATED_HDK(__V__)
GA_Detail & getDetail() const
Get the geometry being loaded.
Definition: GA_LoadMap.h:59
GLint j
Definition: glad.h:2733
void swapVertices(GA_Size i, GA_Size j)
Definition: GEO_TriMesh.h:218
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
GA_Size findVertex(GA_Offset vtx) const
return the index of a vertex within our vertex list
Definition: GEO_TriMesh.h:109
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
Container class for all geometry.
Definition: GA_Detail.h:96
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
SYS_FORCE_INLINE GA_Size getFastVertexCount() const
Definition: GEO_TriMesh.h:123
Definition of a geometric primitive.
friend std::ostream & operator<<(std::ostream &os, const GEO_TriMesh &d)
Definition: GEO_TriMesh.h:250
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const override
Definition: GEO_TriMesh.h:230
unsigned int uint
Definition: SYS_Types.h:45
virtual GA_Size getMinVertexCount() const
Definition: GEO_TriMesh.h:205
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
SYS_FORCE_INLINE void setSize(GA_Size nvertices)
Definition: GEO_TriMesh.h:78
GLint GLsizei count
Definition: glcorearb.h:405
Definition: format.h:895
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2089