HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PrimPolySoup.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_PrimPolySoup.h (GU Library, C++)
7  *
8  * COMMENTS: Declarations of utility functions of the polygon soup primitive
9  */
10 
11 #ifndef __GU_PrimPolySoup__
12 #define __GU_PrimPolySoup__
13 
14 #include "GU_API.h"
15 #include <GEO/GEO_PrimPolySoup.h>
16 
17 //#define SOUP_FILE_TESTING
18 
19 class GA_Detail;
20 class GEO_PolyCounts;
21 class UT_MemoryCounter;
22 class GEO_ConvertParms;
23 
25 {
26 protected:
27  /// NOTE: Primitives should not be deleted directly. They are managed
28  /// by the GA_PrimitiveList and the stash.
29  ~GU_PrimPolySoup() override {}
30 
31 public:
32  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
34  : GEO_PrimPolySoup(gdp, offset)
35  {}
36 
37  /// Report approximate memory usage.
38  int64 getMemoryUsage() const override;
39 
40  /// Count memory usage using a UT_MemoryCounter in order to count
41  /// shared memory correctly.
42  /// NOTE: This should always include sizeof(*this).
43  void countMemory(UT_MemoryCounter &counter) const override;
44 
45  const GA_PrimitiveDefinition &getTypeDef() const override
46  {
47  UT_ASSERT(theDefinition);
48  return *theDefinition;
49  }
50 
51  // Conversion Methods
53  GA_PointGroup *usedpts = 0) override;
54  GEO_Primitive *convertNew(GEO_ConvertParms &parms) override;
55 
56  // NOTE: For static member functions please call in the following
57  // manner. <ptrvalue> = GU_PrimPolySoup::<functname>
58  // i.e. partptr = GU_PrimPolySoup::build(params...);
59 
60  // Optional Build Methods
61 
62  /// Builds an empty polygon soup (i.e. contains no vertices or polygons)
63  static GU_PrimPolySoup *build(GA_Detail *detail);
64  /// Builds npoints new points with the specified positions, and then creates
65  /// a polygon soup that uses those points, as dictated by polygonsizelist
66  /// and polygonpointnumbers, in parallel. polygonpointnumbers lists the
67  /// numbers of the points used by each polygon, relative to the first point
68  /// created by this method. The offset of the polysoup is returned.
69  ///
70  /// If sharedvertices is false, there will be
71  /// polygonsizelist.getNumVertices() vertices, and they won't be shared
72  /// by any polygons in the polygon soup. If sharedvertices is true,
73  /// there will be npoints vertices, and each will be shared by all
74  /// polygons using the corresponding point.
75  ///
76  /// NOTE: If sharedvertices is true, it's necessary for the polysoup to
77  /// use all points created. If sharedvertices is false, this limitation
78  /// is lifted, although doing so probably isn't useful.
79  /// @{
80  static GA_Offset build(GA_Detail *detail,
81  const UT_Vector3 *points,
82  const GA_Size npoints,
83  const GEO_PolyCounts &polygonsizelist,
84  const int *polygonpointnumbers,
85  const bool sharedvertices = true);
86  static GA_Offset build(GA_Detail *detail,
87  const UT_Vector3 *points,
88  const GA_Size npoints,
89  const GA_PolyCounts &polygonsizelist,
90  const int *polygonpointnumbers,
91  const bool sharedvertices = true);
92  /// @}
93 
94  /// Builds a polygon soup using the specified range of point offsets,
95  /// as dictated by polygonsizelist and polygonpointnumbers, in parallel.
96  /// polygonpointnumbers lists the *offsets* of the points used by
97  /// each polygon *MINUS* startpt, i.e. they are offsets relative to startpt,
98  /// *not* indices relative to startpt. The offset of the polysoup is
99  /// returned. All polygonpointnumbers must be between 0 (inclusive) and
100  /// npoints (exclusive).
101  ///
102  /// If sharedvertices is false, there will be
103  /// polygonsizelist.getNumVertices() vertices, and they won't be shared
104  /// by any polygons in the polygon soup. If sharedvertices is true,
105  /// there will be npoints vertices, and each will be shared by all
106  /// polygons using the corresponding point.
107  ///
108  /// NOTE: If sharedvertices is true, *no primitives* can be using the points
109  /// in the specified range already, and polygons in the polygon soup being
110  /// created should use all of them, because the vertices will be wired as
111  /// the only vertices for their corresponding points. If sharedvertices is
112  /// false, these limitations are lifted, allowing multiple primitives
113  /// to use the same points, and allowing the polysoup being created to use
114  /// a subset of the points in the range.
115  /// @{
116  static GA_Offset build(GA_Detail *detail,
117  const GA_Offset startpt,
118  const GA_Size npoints,
119  const GEO_PolyCounts &polygonsizelist,
120  const int *polygonpointnumbers,
121  const bool sharedvertices = true);
122  static GA_Offset build(GA_Detail *detail,
123  const GA_Offset startpt,
124  const GA_Size npoints,
125  const GA_PolyCounts &polygonsizelist,
126  const int *polygonpointnumbers,
127  const bool sharedvertices = true);
128  /// @}
129 
130 #ifdef SOUP_FILE_TESTING
131  bool saveCustom(const char *filename);
132  static GA_Offset loadCustom(GA_Detail *detail,
133  const char *filename);
134 #endif
135 
136  void removeInlinePoints(float tol, GA_PointGroup *&delgrp,
137  const GA_PointGroup *pts);
138 
139  void normal(NormalComp &output) const override;
140  void normal(NormalCompD &output) const override;
141 
142  /// Sorts the polygons in the polysoup spatially
143  void sortSpatial();
144 
145  void convex(GA_Size maxpts = 3,
146  const GA_Detail *restgdp = nullptr,
147  bool flipedges = false,
148  bool avoiddegeneracy = false) override final;
149 
150 protected:
151 private:
152  static GA_PrimitiveDefinition *theDefinition;
153  friend class GU_PrimitiveFactory;
154 
155  // This function calls the constructor for GU_PrimitiveFactory
156  //template<typename>
157  //friend GA_Primitive *gu_NewPrimitive(GA_Detail &gdp,GA_Offset offset,
158  // const GA_PrimitiveDefinition &);
160 };
162 
163 #endif
164 
~GU_PrimPolySoup() override
GT_API const UT_StringHolder filename
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
GU_PrimPolySoup(GA_Detail *gdp, GA_Offset offset=GA_INVALID_OFFSET)
NOTE: This constructor should only be called via GU_PrimitiveFactory.
A soup of polygons.
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
virtual void normal(NormalComp &output) const =0
GA_Size GA_Offset
Definition: GA_Types.h:646
GLintptr offset
Definition: glcorearb.h:665
virtual void countMemory(UT_MemoryCounter &counter) const
const GA_PrimitiveDefinition & getTypeDef() const override
long long int64
Definition: SYS_Types.h:116
#define GU_API
Definition: GU_API.h:14
virtual void convex(GA_Size maxpts=3, const GA_Detail *restgdp=nullptr, bool flipedges=false, bool avoiddegeneracy=false)=0
Container class for all geometry.
Definition: GA_Detail.h:96
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Definition of a geometric primitive.
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0