HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimPolygon.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_PrimPolygon.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_PrimPolygon__
12 #define __GT_PrimPolygon__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include <UT/UT_Vector3.h>
17 
18 /// @brief Single closed polygon
19 ///
20 /// @section GT_Polygon_RParms Refine Parameters: PrimPolygon
21 /// The parameters inspected for refining a polygon are
22 /// - @c bool convex @n
23 /// Whether convexing is required
24 /// - @c int maxsides @n
25 /// The maximum sides allowed for a polygon
27 {
28 public:
31  const GT_AttributeListHandle &uniform)
32  {
33  init(vertex, uniform);
34  }
36  : myVertex(src.myVertex),
37  myUniform(src.myUniform),
38  GT_Primitive(src)
39  {
40  }
41  ~GT_PrimPolygon() override;
42 
43  const char *className() const override { return "GT_PrimPolygon"; }
44  bool save(UT_JSONWriter &w) const override
45  {
46  jsonWriter j(w, "Polygon");
47  return saveAttributeLists(*j);
48  }
49 
50  /// @param vertex
51  /// The length of this array determines the number of vertices. There is
52  /// one entry per vertex.
53  /// @param uniform
54  /// Data which is constant across the polygon
56  const GT_AttributeListHandle &uniform)
57  {
58  myVertex = vertex;
59  myUniform = uniform;
60  return true;
61  }
62 
63  GT_Size getVertexCount() const;
64 
65  /// Get the varying data array. There is one entry for each vertex
67  { return myVertex; }
68  /// Get the unfirom data. There should be one entry in the array.
70  { return myUniform; }
71  /// @{
72  /// Access attributes
74  { return myVertex; }
76  { return myUniform; }
77  /// @}
78 
79  /// @{
80  /// Methods defined on GT_Primitive
81  int getPrimitiveType() const override;
82  void enlargeBounds(UT_BoundingBox boxes[],
83  int nsegment) const override;
84  int getMotionSegments() const override;
85  int64 getMemoryUsage() const override;
86  /// @}
87 
88  /// @{
89  /// Methods for GEO/GU support.
90  fpreal computePerimeter(int seg) const override;
91  fpreal computeSurfaceArea(int seg) const override;
92  fpreal computeVolume(const UT_Vector3 &ref_P,
93  int seg) const override;
94  /// @}
95 
96  /// Convex the polygon. Possible return primitives are
97  /// - NULL (degenerate polygon)
98  /// - a handle to this polygon (this polygon is already convex)
99  /// - a handle to a polygon mesh (multiple polygons)
100  GT_PrimitiveHandle convex(int max_sides=3) const;
101 
102  /// Utility method to compute the normal for an indexed face
103  /// @note If dim(P) == 2, the normal will be (0,0,1)
104  static void computeNormal(UT_Vector3F &N, const GT_DataArray &vertexlist,
105  const GT_DataArray &P)
106  {
107  return computeNormal(N, vertexlist,
108  vertexlist.entries(), 0, P);
109  }
110  /// Utility method to compute the normal for an indexed face
111  /// The face has @c nvtx vertices in the @c vertexlist and the first vertex
112  /// is offset by @c vtxoff.
113  /// @note If dim(P) == 2, the normal will be (0,0,1)
114  static void computeNormal(UT_Vector3F &N,
115  const GT_DataArray &vertexlist,
116  GT_Size nvtx, GT_Size vtxoff,
117  const GT_DataArray &P);
118  static void computeNormal(UT_Vector3D &N,
119  const GT_DataArray &vertexlist,
120  GT_Size nvtx, GT_Size vtxoff,
121  const GT_DataArray &P);
122  /// @{
123  /// Utility method to compute the normal for a face
124  static void computeNormal(UT_Vector3F &N, const GT_DataArray &P);
125  static void computeNormal(UT_Vector3D &N, const GT_DataArray &P);
126  /// @}
127 
128  /// Compute a normal quickly. The resulting normal will be unit length
129  static void computeFastNormal(UT_Vector3F &N,
130  const GT_DataArray &vertexlist,
131  GT_Size nvtx, GT_Size vtxoff,
132  const GT_DataArray &P);
133  static void computeFastNormal(UT_Vector3D &N,
134  const GT_DataArray &vertexlist,
135  GT_Size nvtx, GT_Size vtxoff,
136  const GT_DataArray &P);
137  /// Compute a frame of reference for the polygon
138  static void computeFrameOfReference(UT_Vector3 &X, UT_Vector3 &Y,
139  const GT_DataArray &vertexlist,
140  GT_Size nvtx, GT_Size vtxoff,
141  const GT_DataArray &P);
142 
143  /// @{
144  /// Compute perimeter of a face or an indexed face
145  static fpreal facePerimeter(const GT_DataArray &P,
146  const UT_Matrix4D *xform = nullptr);
147  static fpreal facePerimeter(const GT_DataArray &vertexlist,
148  GT_Size nvtx, GT_Size vtxoff,
149  const GT_DataArray &P,
150  const UT_Matrix4D *xform = nullptr);
151  /// @}
152  /// @{
153  /// Compute surface area of a face or an indexed face
154  static fpreal faceSurfaceArea(const GT_DataArray &P,
155  const UT_Matrix4D *xform = nullptr);
156  static fpreal faceSurfaceArea(const GT_DataArray &vertexlist,
157  GT_Size nvtx, GT_Size vtxoff,
158  const GT_DataArray &P,
159  const UT_Matrix4D *xform = nullptr);
160  /// @}
161  /// @{
162  /// Compute signed volume of a face or an indexed face (given a reference
163  /// point)
164  static fpreal faceVolume(const UT_Vector3 &ref_pt,
165  const GT_DataArray &P,
166  const UT_Matrix4D *xform = nullptr);
167  static fpreal faceVolume(const UT_Vector3 &ref_pt,
168  const GT_DataArray &vertexlist,
169  GT_Size nvtx, GT_Size vtxoff,
170  const GT_DataArray &P,
171  const UT_Matrix4D *xform = nullptr);
172  /// @}
173 
174  /// Harden all attributes so there are no dangling dependencies
175  GT_PrimitiveHandle doHarden() const override;
177  { return new GT_PrimPolygon(*this); }
178 
179  /// The virtual implementation of attribute merging
181  const GT_Primitive &src,
182  const UT_StringMMPattern *vertex,
183  const UT_StringMMPattern *point,
184  const UT_StringMMPattern *uniform,
185  const UT_StringMMPattern *detail
186  ) const override;
187 private:
188  GT_AttributeListHandle myVertex;
189  GT_AttributeListHandle myUniform;
190 };
191 
192 #endif
SIM_API const UT_StringHolder vertex
virtual int getMotionSegments() const =0
virtual int getPrimitiveType() const
virtual fpreal computePerimeter(int seg=0) const
virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg=0) const
#define GT_API
Definition: GT_API.h:13
bool save(UT_JSONWriter &w) const override
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
const GT_AttributeListHandle & getUniformAttributes() const override
bool init(const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform)
const char * className() const override
const GT_AttributeListHandle & getVertex() const
Get the varying data array. There is one entry for each vertex.
GT_PrimPolygon(const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform)
const GT_AttributeListHandle & getVertexAttributes() const override
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
virtual fpreal computeSurfaceArea(int seg=0) const
static void computeNormal(UT_Vector3F &N, const GT_DataArray &vertexlist, const GT_DataArray &P)
const GT_AttributeListHandle & getUniform() const
Get the unfirom data. There should be one entry in the array.
long long int64
Definition: SYS_Types.h:116
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
virtual GT_PrimitiveHandle doHarden() const
virtual int64 getMemoryUsage() const =0
virtual GT_Size entries() const =0
Number of entries in the array.
GT_PrimPolygon(const GT_PrimPolygon &src)
GLint j
Definition: glad.h:2733
int64 GT_Size
Definition: GT_Types.h:128
fpreal64 fpreal
Definition: SYS_Types.h:278
bool saveAttributeLists(UT_JSONWriter &w) const
GA_API const UT_StringHolder N
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GT_PrimitiveHandle doSoftCopy() const override
virtual GT_PrimitiveHandle doAttributeMerge(const GT_Primitive &src, const UT_StringMMPattern *vertex, const UT_StringMMPattern *point, const UT_StringMMPattern *uniform, const UT_StringMMPattern *detail) const
The virtual implementation of attribute merging.
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
Single closed polygon.
GLenum src
Definition: glcorearb.h:1793