HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_PrimPacked.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_PrimPacked.h (GEO Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GEO_PrimPacked__
12 #define __GEO_PrimPacked__
13 
14 #include "GEO_API.h"
15 #include "GEO_PackedNameMap.h"
16 #include "GEO_Primitive.h"
17 
18 /// This is the key associated with the name map hash. It should not be used
19 /// by sub-classes for loadSharedLoadData()
20 #define GEO_SHARED_DATA_NAMEMAP (('A'<<24)|('m'<<16)|('a'<<8)|('p'))
21 
23 {
24 public:
25  /// The primitive takes ownership if the @c procedural passed in
28 #if !GA_PRIMITIVE_VERTEXLIST
29  virtual ~GEO_PrimPacked();
30 #endif
31 
32  /// @{
33  /// Required interface methods for GEO primitive
34  virtual bool isDegenerate() const = 0;
35  virtual int getBBox(UT_BoundingBox *bbox) const;
36  virtual void enlargePointBounds(UT_BoundingBox &box) const;
37  virtual void reverse() {}
38  virtual UT_Vector3 computeNormal() const;
39  virtual void copyPrimitive(const GEO_Primitive *src);
40  virtual void copyUnwiredForMerge(const GA_Primitive *src,
41  const GA_MergeMap &map);
42  virtual void copyImplementation(const GEO_PrimPacked &src) = 0;
43 
44 #if !GA_PRIMITIVE_VERTEXLIST
45  // Query the number of vertices in the array. This number may be smaller
46  // than the actual size of the array.
47  virtual GA_Size getVertexCount() const;
48  virtual GA_Offset getVertexOffset(GA_Size) const;
49 #endif
50 
51  // Take the whole set of points into consideration when applying the
52  // point removal operation to this primitive. The method returns 0 if
53  // successful, -1 if it failed because it would have become degenerate,
54  // and -2 if it failed because it would have had to remove the primitive
55  // altogether.
56  virtual int detachPoints(GA_PointGroup &grp);
57  /// Before a point is deleted, all primitives using the point will be
58  /// notified. The method should return "false" if it's impossible to
59  /// delete the point. Otherwise, the vertices should be removed.
60  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
61  bool dry_run=false);
62  virtual GA_DereferenceStatus dereferencePoints(
63  const GA_RangeMemberQuery &pt_q,
64  bool dry_run=false);
65  virtual const GA_PrimitiveJSON *getJSON() const;
66 
67 #if !GA_PRIMITIVE_VERTEXLIST
68  /// Defragmentation
69  virtual void swapVertexOffsets(const GA_Defragment &defrag);
70 #endif
71 
72  /// Evalaute a point given a u,v coordinate (with derivatives)
73  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
74  GA_AttributeRefMap &hlist,
75  fpreal u, fpreal v, uint du, uint dv) const;
76  /// Evalaute position given a u,v coordinate (with derivatives)
77  virtual int evaluatePointV4( UT_Vector4 &pos, float u, float v = 0,
78  unsigned du=0, unsigned dv=0) const
79  {
80  return GEO_Primitive::evaluatePointV4(pos, u, v,
81  du, dv);
82  }
83  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
84  virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET);
85 #if !GA_PRIMITIVE_VERTEXLIST
86  virtual void clearForDeletion();
87 #endif
88  virtual void transform(const UT_Matrix4 &xform) = 0;
89  virtual UT_Vector3 baryCenter() const;
90  virtual fpreal calcVolume(const UT_Vector3 &refpt) const = 0;
91  virtual fpreal calcArea() const = 0;
92  virtual fpreal calcPerimeter() const = 0;
93  virtual void getLocalTransform(UT_Matrix3D &matrix) const;
94  virtual void setLocalTransform(const UT_Matrix3D &matrix);
95  virtual void getPivot(UT_Vector3 &pos) const;
96  virtual void setPivot(const UT_Vector3 &pos);
97  /// @}
98 
99  /// Return the full transform matrix for the primitive. This includes the
100  /// local transform combined with any additional transforms which might be
101  /// implicit to the primitive.
102  /// The default behaviour is to simply call @c getLocalTransform4();
103  virtual void getFullTransform4(UT_Matrix4D &matrix) const = 0;
104 
105  /// @{
106  /// Get the un-transformed bounding box
107  virtual bool getUntransformedBounds(UT_BoundingBox &box) const = 0;
108  virtual bool getUntransformedRenderingBounds(UT_BoundingBox &box) const = 0;
109  virtual void getVelocityRange(UT_Vector3 &vmin, UT_Vector3 &vmax) const = 0;
110  /// @}
111 
112  /// Method to assist with rendering. To get accurate bounding boxes for
113  /// rendering, the "width" of points and curve objects needs to be taken
114  /// into account. These bounds will include the transform on the primitive.
115  ///
116  /// Returns false if the bounds are invalid.
117  bool getRenderingBounds(UT_BoundingBox &box) const;
118 
119  /// Method to assist with rendering. When rendering velocity based motion
120  /// blur, the renderer needs to know the bounds on the velocity to
121  /// accurately compute a bounding box.
122  ///
123  /// These velocities will *not* include any scales applied by the transform
124 
125  /// Set vertex to reference the given point. This will ensure the vertex
126  /// is allocated.
127 #if GA_PRIMITIVE_VERTEXLIST
129  void setVertexPoint(GA_Offset point)
130  {
131  if (getVertexCount() == 0)
132  myVertexList.append(allocateVertex());
133 
134  setPointOffset(0, point);
135  }
136 #else
137  void setVertexPoint(GA_Offset point);
138 #endif
139  /// Called when loading to set the vertex
140  void assignVertex(GA_Offset vtx, bool update_topology);
141 
142  /// @{
143  /// Accessors for viewport LOD
144  GEO_ViewportLOD viewportLOD() const { return myViewportLOD; }
145  void setViewportLOD(GEO_ViewportLOD vlod);
146  /// @}
147 
148  /// @{
149  /// Attribute name mappings
150  void setAttributeNameMap(const GEO_PackedNameMapPtr &m);
152  {
153  if (mySharedNameMapData)
154  {
155  // Need a non const version of ourselves (we want
156  // to be able to access from const prims)
157  GEO_PrimPacked* me = const_cast<GEO_PrimPacked*>(this);
158 
159  // Resolve our shared data
160  const GA_SharedLoadData* item = mySharedNameMapData->resolveSharedData(me);
161  const GEO_PackedNameMap::LoadContainer* data = dynamic_cast<const GEO_PackedNameMap::LoadContainer*>(item);
162  if (data)
163  {
164  me->setAttributeNameMap(data->myNameMap);
165  }
167  }
168  return myAttributeNameMap;
169  }
170  /// @}
171 
172  /// @{
173  /// Faceset name attribute
174  void setFacesetAttribute(const char *s)
175  { myFacesetAttribute.harden(s); }
177  { return myFacesetAttribute; }
178  /// @}
179 
180  /// Fast access to local transform
181  const UT_Matrix3D &localTransform() const { return myLocalTransform; }
182 
183  /// Fast access to pivot transform
184  const UT_Vector3 &pivot() const { return myPivot; }
185  UT_Vector3 &pivot() { return myPivot; }
186 
187  /// @{
188  /// Sub-classes should make sure to call the base class dirty methods
189  virtual void transformDirty();
190  virtual void attributeDirty();
191  virtual void topologyDirty();
192  /// @}
193 
194  virtual bool saveOptions(UT_Options &options,
195  const GA_SaveMap &map) const = 0;
196  virtual bool loadOptions(const UT_Options &options,
197  const GA_LoadMap &map) = 0;
198  virtual bool supportsJSONLoad() const = 0;
199  virtual bool loadOptionsJSON(UT_JSONParser &p,
200  const GA_LoadMap &map) = 0;
201  virtual bool loadOptionsJSONMap(UT_JSONValueMap &options,
202  const GA_LoadMap &map) = 0;
203  virtual bool loadUnknownToken(const char *token,
204  UT_JSONParser &p,
205  const GA_LoadMap &map) = 0;
206 
207  /// @{
208  /// Any sub-classes *must* call the GEO method for shared load data since
209  /// name maps are saved as shared data.
210  ///
211  /// The sub-classes cannot use GEO_SHARED_DATA_NAMEMAP as a key.
212  virtual bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &map, GA_GeometryIndex* geometryIndex) const;
213  virtual bool registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item);
214  /// @}
215 
216  /// Copies the member data of the source packed primitive into this.
217  /// This does not modify the vertex list or any attributes.
218  void copyMemberDataFrom(const GEO_PrimPacked &src);
219 
220 protected:
221  virtual int evaluateInteriorPointV4(UT_Vector4 &pos,
222  fpreal u, fpreal v, fpreal w = 0) const;
223 
228 #if !GA_PRIMITIVE_VERTEXLIST
230 #endif
233 };
234 
235 #endif
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
virtual UT_Vector3 baryCenter() const
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
virtual void copyPrimitive(const GEO_Primitive *src)=0
virtual void clearForDeletion()
Definition: GA_Primitive.h:598
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
SYS_FORCE_INLINE GA_Size getVertexCount() const
Return the number of vertices used by this primitive.
Definition: GA_Primitive.h:227
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
Evalaute position given a u,v coordinate (with derivatives)
const GLdouble * v
Definition: glcorearb.h:836
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
Definition: GA_Primitive.h:255
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
void setFacesetAttribute(const char *s)
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
Abstract base class for a range membership query object.
virtual void reverse()
3D Vector class.
virtual void swapVertexOffsets(const GA_Defragment &defrag)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
virtual bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &save, GA_GeometryIndex *geometryIndex) const
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GEO_ViewportLOD myViewportLOD
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_Offset myVertex
GEO_PackedNameMapPtr myAttributeNameMap
virtual void setLocalTransform(const UT_Matrix3D &matrix)
Set the local transform. The default implementation does nothing.
virtual int evaluateInteriorPointV4(UT_Vector4 &pos, fpreal u, fpreal v, fpreal w=0) const
virtual fpreal calcArea() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
virtual const GA_PrimitiveJSON * getJSON() const =0
GLintptr offset
Definition: glcorearb.h:664
Provide a JSON interface to a primitive.
GA_Offset allocateVertex(GA_Offset point=GA_INVALID_OFFSET)
allocateVertex() will call wireVertex() if the point given is not -1
#define GEO_API
Definition: GEO_API.h:10
const UT_Vector3 & pivot() const
Fast access to pivot transform.
A handle to simplify manipulation of multiple attributes.
UT_Vector3 & pivot()
Options during loading.
Definition: GA_LoadMap.h:42
virtual int getBBox(UT_BoundingBox *bbox) const =0
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
GLboolean * data
Definition: glcorearb.h:130
UT_Vector3 myPivot
virtual fpreal calcPerimeter() const
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
unsigned int uint
Definition: SYS_Types.h:39
void setAttributeNameMap(const GEO_PackedNameMapPtr &m)
GEO_ViewportLOD viewportLOD() const
virtual void transform(const UT_Matrix4 &)
virtual void enlargePointBounds(UT_BoundingBox &box) const
virtual void getLocalTransform(UT_Matrix3D &matrix) const
double fpreal
Definition: SYS_Types.h:269
A map of string to various well defined value types.
Definition: UT_Options.h:42
virtual int detachPoints(GA_PointGroup &grp)=0
void clear()
Convenience method to clear the pointer.
Definition: UT_SharedPtr.h:48
GEO_ViewportLOD
GA_SharedDataHandlePtr mySharedNameMapData
virtual fpreal calcVolume(const UT_Vector3 &) const
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:235
UT_String myFacesetAttribute
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
const UT_Matrix3D & localTransform() const
Fast access to local transform.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const UT_String & facesetAttribute() const
virtual bool registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item)
const GEO_PackedNameMapPtr & attributeNameMap() const
UT_Matrix3D myLocalTransform
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
GLenum src
Definition: glcorearb.h:1792