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 public:
30  const GT_AttributeListHandle &uniform)
31  {
32  init(vertex, uniform);
33  }
35  : myVertex(src.myVertex),
36  myUniform(src.myUniform),
37  GT_Primitive(src)
38  {
39  }
40  ~GT_PrimPolygon() override;
41 
42  const char *className() const override { return "GT_PrimPolygon"; }
43  bool save(UT_JSONWriter &w) const override
44  {
45  jsonWriter j(w, "Polygon");
46  return saveAttributeLists(*j);
47  }
48 
49  /// @param vertex
50  /// The length of this array determines the number of vertices. There is
51  /// one entry per vertex.
52  /// @param uniform
53  /// Data which is constant across the polygon
54  bool init(const GT_AttributeListHandle &vertex,
55  const GT_AttributeListHandle &uniform)
56  {
57  myVertex = vertex;
58  myUniform = uniform;
59  return true;
60  }
61 
62  GT_Size getVertexCount() const;
63 
64  /// Get the varying data array. There is one entry for each vertex
66  { return myVertex; }
67  /// Get the unfirom data. There should be one entry in the array.
69  { return myUniform; }
70  /// @{
71  /// Access attributes
73  { return myVertex; }
75  { return myUniform; }
76  /// @}
77 
78  /// @{
79  /// Methods defined on GT_Primitive
80  int getPrimitiveType() const override;
81  void enlargeBounds(UT_BoundingBox boxes[],
82  int nsegment) const override;
83  int getMotionSegments() const override;
84  int64 getMemoryUsage() const override;
85  /// @}
86 
87  /// @{
88  /// Methods for GEO/GU support.
89  fpreal computePerimeter(int seg) const override;
90  fpreal computeSurfaceArea(int seg) const override;
91  fpreal computeVolume(const UT_Vector3 &ref_P,
92  int seg) const override;
93  /// @}
94 
95  /// Convex the polygon. Possible return primitives are
96  /// - NULL (degenerate polygon)
97  /// - a handle to this polygon (this polygon is already convex)
98  /// - a handle to a polygon mesh (multiple polygons)
99  GT_PrimitiveHandle convex(int max_sides=3) const;
100 
101  /// Utility method to compute the normal for an indexed face
102  /// @note If dim(P) == 2, the normal will be (0,0,1)
103  static void computeNormal(UT_Vector3F &N, const GT_DataArray &vertexlist,
104  const GT_DataArray &P)
105  {
106  return computeNormal(N, vertexlist,
107  vertexlist.entries(), 0, P);
108  }
109  /// Utility method to compute the normal for an indexed face
110  /// The face has @c nvtx vertices in the @c vertexlist and the first vertex
111  /// is offset by @c vtxoff.
112  /// @note If dim(P) == 2, the normal will be (0,0,1)
113  static void computeNormal(UT_Vector3F &N,
114  const GT_DataArray &vertexlist,
115  GT_Size nvtx, GT_Size vtxoff,
116  const GT_DataArray &P);
117  static void computeNormal(UT_Vector3D &N,
118  const GT_DataArray &vertexlist,
119  GT_Size nvtx, GT_Size vtxoff,
120  const GT_DataArray &P);
121  /// @{
122  /// Utility method to compute the normal for a face
123  static void computeNormal(UT_Vector3F &N, const GT_DataArray &P);
124  static void computeNormal(UT_Vector3D &N, const GT_DataArray &P);
125  /// @}
126 
127  /// Compute a normal quickly. The resulting normal will be unit length
128  static void computeFastNormal(UT_Vector3F &N,
129  const GT_DataArray &vertexlist,
130  GT_Size nvtx, GT_Size vtxoff,
131  const GT_DataArray &P);
132  static void computeFastNormal(UT_Vector3D &N,
133  const GT_DataArray &vertexlist,
134  GT_Size nvtx, GT_Size vtxoff,
135  const GT_DataArray &P);
136  /// Compute a frame of reference for the polygon
137  static void computeFrameOfReference(UT_Vector3 &X, UT_Vector3 &Y,
138  const GT_DataArray &vertexlist,
139  GT_Size nvtx, GT_Size vtxoff,
140  const GT_DataArray &P);
141 
142  /// @{
143  /// Compute perimeter of a face or an indexed face
144  static fpreal facePerimeter(const GT_DataArray &P,
145  const UT_Matrix4D *xform = NULL);
146  static fpreal facePerimeter(const GT_DataArray &vertexlist,
147  GT_Size nvtx, GT_Size vtxoff,
148  const GT_DataArray &P,
149  const UT_Matrix4D *xform = NULL);
150  /// @}
151  /// @{
152  /// Compute surface area of a face or an indexed face
153  static fpreal faceSurfaceArea(const GT_DataArray &P,
154  const UT_Matrix4D *xform = NULL);
155  static fpreal faceSurfaceArea(const GT_DataArray &vertexlist,
156  GT_Size nvtx, GT_Size vtxoff,
157  const GT_DataArray &P,
158  const UT_Matrix4D *xform = NULL);
159  /// @}
160  /// @{
161  /// Compute signed volume of a face or an indexed face (given a reference
162  /// point)
163  static fpreal faceVolume(const UT_Vector3 &ref_pt,
164  const GT_DataArray &P,
165  const UT_Matrix4D *xform = NULL);
166  static fpreal faceVolume(const UT_Vector3 &ref_pt,
167  const GT_DataArray &vertexlist,
168  GT_Size nvtx, GT_Size vtxoff,
169  const GT_DataArray &P,
170  const UT_Matrix4D *xform = NULL);
171  /// @}
172 
173  /// Harden all attributes so there are no dangling dependencies
174  GT_PrimitiveHandle doHarden() const override;
176  { return new GT_PrimPolygon(*this); }
177 
178  /// The virtual implementation of attribute merging
180  const GT_Primitive &src,
181  const UT_StringMMPattern *vertex,
182  const UT_StringMMPattern *point,
183  const UT_StringMMPattern *uniform,
184  const UT_StringMMPattern *detail
185  ) const override;
186 private:
187  GT_AttributeListHandle myVertex;
188  GT_AttributeListHandle myUniform;
189 };
190 
191 #endif
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:11
bool save(UT_JSONWriter &w) const override
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
const GT_AttributeListHandle & getUniformAttributes() const override
GLenum src
Definition: glcorearb.h:1793
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.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
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)
int64 GT_Size
Definition: GT_Types.h:123
fpreal64 fpreal
Definition: SYS_Types.h:277
bool saveAttributeLists(UT_JSONWriter &w) const
GA_API const UT_StringHolder N
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.