HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PrimPoly.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: GU_PrimPoly.h (C++)
7  *
8  * COMMENTS:
9  * Header file for GU_PrimPoly.h class...
10  *
11  */
12 
13 #pragma once
14 
15 #ifndef __GU_PrimPoly_h__
16 #define __GU_PrimPoly_h__
17 
18 #include "GU_API.h"
19 #include <GEO/GEO_PrimPoly.h>
20 #include <UT/UT_Vector3.h>
21 
23 class GA_Detail;
24 class GEO_ConvertParms;
25 class GEO_Hull;
26 class GEO_PrimCircle;
27 class GEO_PrimRBezCurve;
28 class GEO_PrimNURBCurve;
29 class GEO_PrimTriBezier;
30 class GU_RayInfoHit;
31 class UT_MemoryCounter;
32 
33 /////////////////////////////////////////////////////////////
34 // //
35 // Class: GU_PrimPoly //
36 // Descr: This class is responsible for operations //
37 // done on polygon primitives. As we need to access //
38 // the GA_Detail, the pointer is passed in the //
39 // constructor. The second constructor creates a //
40 // polygon with a given number of points (npts) and //
41 // a flag indicating if it is open or not. //
42 // //
43 /////////////////////////////////////////////////////////////
44 
46 {
47 public:
48  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
51  : GEO_PrimPoly(gdp, offset)
52  {}
53 
54  /// This constructor is for making a representation of a polygon
55  /// on the stack, so that you can call GU_PrimPoly functions on
56  /// the polygon without needing the detail to allocate one.
59  : GEO_PrimPoly(gdp, offset)
60  { myVertexList = vertex_list; }
61 
62  // Conversion Methods
63 
65  GA_PointGroup *usedpts = 0) override;
66 
67  GEO_Primitive *convertNew(GEO_ConvertParms &parms) override;
68 
69  GEO_Hull *convertToSurfNew(GEO_ConvertParms &parms);
70  GEO_Hull *convertToPotatoChip();
71  GEO_Hull *convertToTrim(GEO_ConvertParms &parms);
72 
73  GEO_PrimRBezCurve *convertToBezierNew(GA_ElementWranglerCache &wranglers,
74  int order, int interphull = 1);
75  GEO_PrimNURBCurve *convertToNURBNew(GA_ElementWranglerCache &wranglers,
76  int order, int interphull = 1);
77  GEO_PrimCircle *convertToCircleNew();
78 
79  // Converts tris into triangle beziers by the PN method.
80  GEO_PrimTriBezier *convertToTriBezier(GA_ElementWranglerCache &wranglers);
81 
82 
83  // Cut a wedge of the primitive given a domain range
84  // ind1 and ind2 are indices to the refined values
85  // They are updated if negative on input, else used as is.
86  // If keep is zero the curve is only refined and the indices
87  // updated.
88  GU_PrimPoly *cut(float u1, float u2,
89  int &ind1, int &ind2, int keep);
90 
91  // Open the primitive at the given domain value
92  void openAt(float u);
93 
94  // This is more powerful than convertNew. It always returns a NEW
95  // object, so free it when you're done with it. It may return a polygon,
96  // a NURB curve or a Bezier curve depending on the type.
97  GEO_Face *reconfigure(unsigned type, int order, bool open,
98  bool nonrational) const;
99 
100  int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d,
101  float tmax = 1E17F, float tol = 1E-12F,
102  float *distance = 0, UT_Vector3 *pos = 0,
103  UT_Vector3 *nml = 0, int accurate = 0,
104  float *u = 0, float *v = 0,
105  int ignoretrim=1) const override;
106 
107  // Returns number of hits appended, or minus one if error.
108  // t values in hitList are paramter on poly of hits, assuming
109  // uniform parameterization.
110  int intersect(const GEO_Primitive &prim,
111  UT_Array<GU_RayInfoHit> &hitList,
112  float tol = 0.01F,
113  int ignoretrim=1) const override;
114 
115  void clip(UT_Vector3 normal, float distance=0,
116  GA_PrimitiveGroup *clipgrp = NULL) override;
117 
118  void crease(UT_Vector3 &normal, float d=0, int normalize=1,
119  int outputGroups=0,
120  GA_PrimitiveGroup*above=0,
121  GA_PrimitiveGroup*below=0);
122 
123  /// Optional Build Method
124  /// You may call it in the following manner,
125  /// ptr = GU_PrimPoly::build(bla, bla, bla);
126  static GU_PrimPoly *build(GA_Detail *gdp, int npts,
127  int open=0,
128  int appendpts=1)
129  { return (GU_PrimPoly *)GEO_PrimPoly::build(gdp, npts, open, appendpts); }
130 
131  /// Given a bit array representing the edges in the poly (1 meaning
132  /// delete and 0 meaning keep) delete as many edges as possible.
133  /// If a particular edge cannot be deleted then negate the value
134  /// in removededges[edgenum]. DO NOT CHANGE THE MAGNITUDE!
135  /// Returns 0 if successful, -1 if the poly becomes degenerate, and
136  /// -2 if the poly should be removed. The signature for this method
137  /// is consistent with those in other classes, but note that there is
138  /// never a case where an edge cannot be removed from a polygon.
139  int removeEdges(const UT_BitArray &edgemap,
140  UT_IntArray &, bool del_bridges = true)
141  {
142  GEO_Face *dummy;
143  return removeEdges(edgemap, dummy, del_bridges);
144  }
145 
146  /// Same as above method, but instead of accepting an (unused) array
147  /// of edge indices, it returns one (possibly one of many) polygons
148  /// created because this polygon had to be split.
149  int removeEdges(const UT_BitArray &edgemap,
150  GEO_Face *&newpoly,
151  bool del_bridges=true);
152 
153  /// Same as above, but it returns all polygons created because of polysplit
154  int removeEdges(const UT_BitArray &edgemap,
155  UT_Array<GEO_Face*> &newpoly,
156  bool del_bridges=true);
157 
158 
159  // Looks at the first shared edge between us and poly and checks their
160  // orientation. Returns 0 if they are pointing in opposite directions and
161  // 1 if they are pointing in the same direction and -1 if no shared edge
162  // could be found.
163  int isWindingReversed(const GEO_PrimPoly &poly);
164 
165 private:
166  // Vertex sides is 1 or 0 for each vertex depending on whether
167  // it is above the plane.
168  void makeClippedPoly(const UT_Vector3 &n, float d,
169  int *vtxsides,
170  int bothSides=0,
171  int outputGroups = 0,
172  GA_PrimitiveGroup *above = 0,
173  GA_PrimitiveGroup *below = 0,
174  GA_PrimitiveGroup *delgrp = 0);
175 
176  void computeVertices(GEO_Face &face) const;
177 
178 // Don't warn about overriding deprecated virtual methods
180 };
182 
183 #endif
int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d, float tmax=1E17F, float tol=1E-12F, float *distance=0, UT_Vector3 *pos=0, UT_Vector3 *nml=0, int accurate=0, float *u=0, float *v=0, int ignoretrim=1) const override
Definition: GEO_PrimPoly.h:304
const GLdouble * v
Definition: glcorearb.h:837
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
int intersect(const GEO_Primitive &prim, UT_Array< GU_RayInfoHit > &hit_list, float tol=0.01F, int ignoretrim=1) const override
Definition: GEO_PrimPoly.h:315
GLdouble u1
Definition: glad.h:2676
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
GA_Size GA_Offset
Definition: GA_Types.h:646
GLdouble n
Definition: glcorearb.h:2008
GLintptr offset
Definition: glcorearb.h:665
int open(float queuesize) override
int removeEdges(const UT_BitArray &edgemap, UT_IntArray &, bool del_bridges=true)
Definition: GU_PrimPoly.h:139
static GU_PrimPoly * build(GA_Detail *gdp, int npts, int open=0, int appendpts=1)
Definition: GU_PrimPoly.h:126
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
constexpr enabler dummy
An instance to use in EnableIf.
Definition: CLI11.h:985
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
#define GU_API
Definition: GU_API.h:14
GLdouble GLdouble u2
Definition: glad.h:2676
GEO_Primitive * convertNew(GEO_ConvertParms &parms) override
Definition: GEO_PrimPoly.h:298
void clip(UT_Vector3 normal, float distance=0, GA_PrimitiveGroup *clipgrp=NULL) override
Definition: GEO_PrimPoly.h:323
ImageBuf OIIO_API cut(const ImageBuf &src, ROI roi={}, int nthreads=0)
SYS_FORCE_INLINE GU_PrimPoly(GA_Detail *gdp, GA_Offset offset=GA_INVALID_OFFSET)
NOTE: This constructor should only be called via GU_PrimitiveFactory.
Definition: GU_PrimPoly.h:50
SYS_FORCE_INLINE GU_PrimPoly(GA_Detail *gdp, GA_Offset offset, const GA_OffsetListRef &vertex_list)
Definition: GU_PrimPoly.h:58
Container class for all geometry.
Definition: GA_Detail.h:96
GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0) override
Definition: GEO_PrimPoly.h:291
SIM_API const UT_StringHolder distance
type
Definition: core.h:1059
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
static GEO_PrimPoly * build(GA_Detail *gdp, GA_Size nvertices, bool open=false, bool appendpts=true)