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 
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  bool close_rounded = true);
78  GEO_PrimCircle *convertToCircleNew();
79 
80  // Converts tris into triangle beziers by the PN method.
81  GEO_PrimTriBezier *convertToTriBezier(GA_ElementWranglerCache &wranglers);
82 
83 
84  // Cut a wedge of the primitive given a domain range
85  // ind1 and ind2 are indices to the refined values
86  // They are updated if negative on input, else used as is.
87  // If keep is zero the curve is only refined and the indices
88  // updated.
89  GU_PrimPoly *cut(float u1, float u2,
90  int &ind1, int &ind2, int keep);
91 
92  // Open the primitive at the given domain value
93  void openAt(float u);
94 
95  // This is more powerful than convertNew. It always returns a NEW
96  // object, so free it when you're done with it. It may return a polygon,
97  // a NURB curve or a Bezier curve depending on the type.
98  GEO_Face *reconfigure(unsigned type, int order, bool open,
99  bool nonrational) const;
100 
101  int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d,
102  float tmax = 1E17F, float tol = 1E-12F,
103  float *distance = 0, UT_Vector3 *pos = 0,
104  UT_Vector3 *nml = 0, int accurate = 0,
105  float *u = 0, float *v = 0,
106  int ignoretrim=1) const override;
107 
108  // Returns number of hits appended, or minus one if error.
109  // t values in hitList are paramter on poly of hits, assuming
110  // uniform parameterization.
111  int intersect(const GEO_Primitive &prim,
112  UT_Array<GU_RayInfoHit> &hitList,
113  float tol = 0.01F,
114  int ignoretrim=1) const override;
115 
116  void clip(UT_Vector3 normal, float distance=0,
117  GA_PrimitiveGroup *clipgrp = NULL) override;
118 
119  void crease(UT_Vector3 &normal, float d=0, int normalize=1,
120  int outputGroups=0,
121  GA_PrimitiveGroup*above=0,
122  GA_PrimitiveGroup*below=0);
123 
124  /// Optional Build Method
125  /// You may call it in the following manner,
126  /// ptr = GU_PrimPoly::build(bla, bla, bla);
127  static GU_PrimPoly *build(GA_Detail *gdp, int npts,
128  int open=0,
129  int appendpts=1)
130  { return (GU_PrimPoly *)GEO_PrimPoly::build(gdp, npts, open, appendpts); }
131 
132  /// Given a bit array representing the edges in the poly (1 meaning
133  /// delete and 0 meaning keep) delete as many edges as possible.
134  /// If a particular edge cannot be deleted then negate the value
135  /// in removededges[edgenum]. DO NOT CHANGE THE MAGNITUDE!
136  /// Returns 0 if successful, -1 if the poly becomes degenerate, and
137  /// -2 if the poly should be removed. The signature for this method
138  /// is consistent with those in other classes, but note that there is
139  /// never a case where an edge cannot be removed from a polygon.
140  int removeEdges(const UT_BitArray &edgemap,
141  UT_IntArray &, bool del_bridges = true)
142  {
143  GEO_Face *dummy;
144  return removeEdges(edgemap, dummy, del_bridges);
145  }
146 
147  /// Same as above method, but instead of accepting an (unused) array
148  /// of edge indices, it returns one (possibly one of many) polygons
149  /// created because this polygon had to be split.
150  int removeEdges(const UT_BitArray &edgemap,
151  GEO_Face *&newpoly,
152  bool del_bridges=true);
153 
154  /// Same as above, but it returns all polygons created because of polysplit
155  int removeEdges(const UT_BitArray &edgemap,
156  UT_Array<GEO_Face*> &newpoly,
157  bool del_bridges=true);
158 
159 
160  // Looks at the first shared edge between us and poly and checks their
161  // orientation. Returns 0 if they are pointing in opposite directions and
162  // 1 if they are pointing in the same direction and -1 if no shared edge
163  // could be found.
164  int isWindingReversed(const GEO_PrimPoly &poly);
165 
166 private:
167  // Vertex sides is 1 or 0 for each vertex depending on whether
168  // it is above the plane.
169  void makeClippedPoly(const UT_Vector3 &n, float d,
170  int *vtxsides,
171  int bothSides=0,
172  int outputGroups = 0,
173  GA_PrimitiveGroup *above = 0,
174  GA_PrimitiveGroup *below = 0,
175  GA_PrimitiveGroup *delgrp = 0);
176 
177  void computeVertices(GEO_Face &face) const;
178 
179 // Don't warn about overriding deprecated virtual methods
181 };
183 
184 #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:694
GA_Size GA_Offset
Definition: GA_Types.h:653
GLdouble n
Definition: glcorearb.h:2008
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
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:140
static GU_PrimPoly * build(GA_Detail *gdp, int npts, int open=0, int appendpts=1)
Definition: GU_PrimPoly.h:127
#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)
GA_API const UT_StringHolder parms
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
FMT_CONSTEXPR basic_fp< F > normalize(basic_fp< F > value)
Definition: format.h:1701
Container class for all geometry.
Definition: GA_Detail.h:105
GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0) override
Definition: GEO_PrimPoly.h:291
SIM_API const UT_StringHolder distance
static GEO_PrimPoly * build(GA_Detail *gdp, GA_Size nvertices, bool open=false, bool appendpts=true)