HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GT_PrimPolygon();
41 
42  virtual const char *className() const { return "GT_PrimPolygon"; }
43  virtual bool save(UT_JSONWriter &w) const
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  virtual int getPrimitiveType() const;
81  virtual void enlargeBounds(UT_BoundingBox boxes[],
82  int nsegment) const;
83  virtual int getMotionSegments() const;
84  virtual int64 getMemoryUsage() const;
85  /// @}
86 
87  /// @{
88  /// Methods for GEO/GU support.
89  virtual fpreal computePerimeter(int seg) const;
90  virtual fpreal computeSurfaceArea(int seg) const;
91  virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg) const;
92  /// @}
93 
94  /// Convex the polygon. Possible return primitives are
95  /// - NULL (degenerate polygon)
96  /// - a handle to this polygon (this polygon is already convex)
97  /// - a handle to a polygon mesh (multiple polygons)
98  GT_PrimitiveHandle convex(int max_sides=3) const;
99 
100  /// Utility method to compute the normal for an indexed face
101  /// @note If dim(P) == 2, the normal will be (0,0,1)
102  static void computeNormal(UT_Vector3F &N, const GT_DataArray &vertexlist,
103  const GT_DataArray &P)
104  {
105  return computeNormal(N, vertexlist,
106  vertexlist.entries(), 0, P);
107  }
108  /// Utility method to compute the normal for an indexed face
109  /// The face has @c nvtx vertices in the @c vertexlist and the first vertex
110  /// is offset by @c vtxoff.
111  /// @note If dim(P) == 2, the normal will be (0,0,1)
112  static void computeNormal(UT_Vector3F &N,
113  const GT_DataArray &vertexlist,
114  GT_Size nvtx, GT_Size vtxoff,
115  const GT_DataArray &P);
116  static void computeNormal(UT_Vector3D &N,
117  const GT_DataArray &vertexlist,
118  GT_Size nvtx, GT_Size vtxoff,
119  const GT_DataArray &P);
120  /// @{
121  /// Utility method to compute the normal for a face
122  static void computeNormal(UT_Vector3F &N, const GT_DataArray &P);
123  static void computeNormal(UT_Vector3D &N, const GT_DataArray &P);
124  /// @}
125 
126  /// Compute a normal quickly. The resulting normal will be unit length
127  static void computeFastNormal(UT_Vector3F &N,
128  const GT_DataArray &vertexlist,
129  GT_Size nvtx, GT_Size vtxoff,
130  const GT_DataArray &P);
131  static void computeFastNormal(UT_Vector3D &N,
132  const GT_DataArray &vertexlist,
133  GT_Size nvtx, GT_Size vtxoff,
134  const GT_DataArray &P);
135  /// Compute a frame of reference for the polygon
136  static void computeFrameOfReference(UT_Vector3 &X, UT_Vector3 &Y,
137  const GT_DataArray &vertexlist,
138  GT_Size nvtx, GT_Size vtxoff,
139  const GT_DataArray &P);
140 
141  /// @{
142  /// Compute perimeter of a face or an indexed face
143  static fpreal facePerimeter(const GT_DataArray &P,
144  const UT_Matrix4D *xform = NULL);
145  static fpreal facePerimeter(const GT_DataArray &vertexlist,
146  GT_Size nvtx, GT_Size vtxoff,
147  const GT_DataArray &P,
148  const UT_Matrix4D *xform = NULL);
149  /// @}
150  /// @{
151  /// Compute surface area of a face or an indexed face
152  static fpreal faceSurfaceArea(const GT_DataArray &P,
153  const UT_Matrix4D *xform = NULL);
154  static fpreal faceSurfaceArea(const GT_DataArray &vertexlist,
155  GT_Size nvtx, GT_Size vtxoff,
156  const GT_DataArray &P,
157  const UT_Matrix4D *xform = NULL);
158  /// @}
159  /// @{
160  /// Compute signed volume of a face or an indexed face (given a reference
161  /// point)
162  static fpreal faceVolume(const UT_Vector3 &ref_pt,
163  const GT_DataArray &P,
164  const UT_Matrix4D *xform = NULL);
165  static fpreal faceVolume(const UT_Vector3 &ref_pt,
166  const GT_DataArray &vertexlist,
167  GT_Size nvtx, GT_Size vtxoff,
168  const GT_DataArray &P,
169  const UT_Matrix4D *xform = NULL);
170  /// @}
171 
172  /// Harden all attributes so there are no dangling dependencies
173  virtual GT_PrimitiveHandle doHarden() const;
175  { return new GT_PrimPolygon(*this); }
176 
177  /// The virtual implementation of attribute merging
179  const UT_StringMMPattern *vertex,
180  const UT_StringMMPattern *point,
181  const UT_StringMMPattern *uniform,
182  const UT_StringMMPattern *detail) const;
183 private:
184  GT_AttributeListHandle myVertex;
185  GT_AttributeListHandle myUniform;
186 };
187 
188 #endif
virtual bool save(UT_JSONWriter &w) const
virtual int getMotionSegments() const =0
virtual const GT_AttributeListHandle & getVertexAttributes() const
virtual int getPrimitiveType() const
virtual const GT_AttributeListHandle & getUniformAttributes() const
virtual fpreal computePerimeter(int seg=0) const
virtual fpreal computeVolume(const UT_Vector3 &ref_P, int seg=0) const
virtual const char * className() const
#define GT_API
Definition: GT_API.h:11
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
3D Vector class.
bool init(const GT_AttributeListHandle &vertex, const GT_AttributeListHandle &uniform)
virtual GT_PrimitiveHandle doSoftCopy() const
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)
long long int64
Definition: SYS_Types.h:100
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
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.
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
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)
double fpreal
Definition: SYS_Types.h:263
bool saveAttributeLists(UT_JSONWriter &w) const
GA_API const UT_StringHolder N
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
int64 GT_Size
Definition: GT_Types.h:109
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:1792