HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_GEOPrimitive.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: GT_GEOPrimitive.h ( GEO Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_GEOPrimitive__
12 #define __GT_GEOPrimitive__
13 
14 #include "GT_API.h"
15 #include <UT/UT_Assert.h>
16 #include <UT/UT_BoundingBox.h>
17 #include <GA/GA_Types.h>
18 #include <GU/GU_DetailHandle.h>
19 #include "GT_Primitive.h"
20 #include "GT_Handles.h"
21 #include "GT_GEOSupport.h"
22 
23 class GA_PrimitiveTypeId;
24 class GEO_Primitive;
25 class GEO_Primitive;
26 class GEO_Quadric;
27 class GEO_Curve;
28 class GEO_Face;
29 class GEO_Hull;
30 class GEO_TPSurf;
31 class GEO_PrimTube;
32 class GEO_PrimParticle;
33 class GT_GEOPrimCollect;
34 
35 /// Base class for many of the GEO_Primitive objects
37 {
38 public:
39  /// GT holds onto GU_DetailHandle objects. However, it's possible for a
40  /// user (SOP) to change the GU_Detail stored in the GU_DetailHandle
41  /// without changing the GU_DetailHandle. This can leave stale primitive
42  /// pointers. The GEOPrimitivePair object has a method to refresh the
43  /// pointer to ensure it remains valid.
45  {
46  public:
48  { init(nullptr); }
50  { init(prim); }
52  { init(gdh, idx); }
53 
54  void init(const GEO_Primitive *prim);
55  void init(const GU_ConstDetailHandle &gdh, GA_Index idx);
56  void init(const GU_Detail *gdp, GA_Index idx);
57 
58  /// @{
59  /// Reports true if the primitive pointer has changed
60  bool update(const GU_ConstDetailHandle &dtl);
61  bool update(const GU_Detail *gdp);
62  /// @}
63 
64  const GEO_Primitive *primitive() const { return myPrim; }
65  template <typename T> const T *primitiveAs() const
66  { return UTverify_cast<const T *>(myPrim); }
67  GA_Index mapIndex() const { return myMapIndex; }
68 
69  private:
70  const GEO_Primitive *myPrim;
71  GA_Index myMapIndex;
72  };
73 
75  const GEO_Primitive *const*primlist,
76  int nsegments)
77  : myDetails(NULL)
78  , myPrimitives(NULL)
79  , mySegmentCount(0)
80  {
81  init(dlist, primlist, nsegments);
82  }
85  int nsegments)
86  : myDetails(nullptr)
87  , myPrimitives(nullptr)
88  , mySegmentCount(0)
89  {
90  init(dlist, offset, nsegments);
91  }
93  : myDetails(NULL)
94  , myPrimitives(NULL)
95  , mySegmentCount(0)
96  , GT_Primitive(src)
97  {
98  init(src.myDetails, src.myPrimitives, src.mySegmentCount);
99  }
100  ~GT_GEOPrimitive() override;
101 
102  const char *className() const override { return "GT_GEOPrimitive"; }
103 
104  static void makePairArray(UT_Array<GEOPrimitivePair> &array,
105  const GU_ConstDetailHandle &gdh,
106  const GT_GEOOffsetList &offsets);
107 
108  /// Initialize the primitive lists
109  void init(const GU_ConstDetailHandle *dlist,
111  int nsegments);
112  void init(const GU_ConstDetailHandle *dlist,
113  const GEO_Primitive *const*primlist,
114  int nsegments);
115  void init(const GU_ConstDetailHandle *dlist,
116  const GEOPrimitivePair *primlist,
117  int nsegments);
118 
119  /// @{
120  /// Interface from GT_Primitive implemented using methods on GEO_Primitive
121  int getPrimitiveType() const override
122  { return GT_GEO_PRIMITIVE; }
123  void enlargeBounds(UT_BoundingBox boxes[],
124  int nsegments) const override;
125  int getMotionSegments() const override
126  { return mySegmentCount; }
127  int64 getMemoryUsage() const override;
129  { return new GT_GEOPrimitive(*this); }
130  /// @}
131 
132  /// @{
133  /// Interface from GT_Primitive required by subclass
134  bool refine(GT_Refine &refiner,
135  const GT_RefineParms *parms=NULL) const override;
136  /// @}
137 
138  /// Update the primitive pointers
139  bool updateGeoPrim(const GU_ConstDetailHandle &dtl,
140  const GT_RefineParms &refine) override;
141 
142  /// @{
143  /// Access to GEO primitives
144  const GU_ConstDetailHandle *detailHandles() const { return myDetails; }
145  const GU_ConstDetailHandle &detail(int seg) const
146  { return myDetails[seg];}
147  const GEO_Primitive *getPrimitive(int seg) const;
148  template <typename T> const T *getPrimAs(int seg) const
149  {
150  return UTverify_cast<const T *>(getPrimitive(seg));
151  }
152  /// @}
153 
154  /// Given a GEO_Quadric, create the GT transform
155  static GT_TransformHandle makeQuadricTransform(
156  const GEO_Quadric *prim
157  );
158 
159  /// Given a single-vertex primitive, create an attribute list for all
160  /// point, vertex and primitive attributes.
161  static GT_AttributeListHandle makeQuadricAttributes(
162  const GU_ConstDetailHandle &gdp,
163  const GEO_Primitive *prims
164  );
165 protected:
166  void clearLists();
167  /// Get an attribute list for the primitive attributes, optionally
168  /// including the detail attributes in the same list.
169  /// These attributes will be "shared" with the GEO objects.
170  GT_AttributeListHandle getPrimitiveAttributes(
171  bool include_detail_attributes=true) const;
172 
176 };
177 
178 #endif
GT_GEOPrimitive(const GT_GEOPrimitive &src)
Base class for many of the GEO_Primitive objects.
const char * className() const override
GEOPrimitivePair(const GEO_Primitive *prim)
virtual bool updateGeoPrim(const GU_ConstDetailHandle &dtl, const GT_RefineParms &parms)
update any cached data for geometry and its attributes
GT_PrimitiveHandle doSoftCopy() const override
const GEO_Primitive * primitive() const
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
GEOPrimitivePair(const GU_ConstDetailHandle &gdh, GA_Index idx)
#define GT_API
Definition: GT_API.h:13
GEOPrimitivePair * myPrimitives
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
int getMotionSegments() const override
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
GA_Size GA_Offset
Definition: GA_Types.h:646
GLintptr offset
Definition: glcorearb.h:665
GT_GEOPrimitive(const GU_ConstDetailHandle *dlist, GA_Offset offset, int nsegments)
const T * getPrimAs(int seg) const
long long int64
Definition: SYS_Types.h:116
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
virtual int64 getMemoryUsage() const =0
const GU_ConstDetailHandle & detail(int seg) const
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
GU_ConstDetailHandle * myDetails
GT_GEOPrimitive(const GU_ConstDetailHandle *dlist, const GEO_Primitive *const *primlist, int nsegments)
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
int getPrimitiveType() const override
const GU_ConstDetailHandle * detailHandles() const
GLenum src
Definition: glcorearb.h:1793