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