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  virtual ~GU_PrimPolySoup() {}
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  virtual int64 getMemoryUsage() const;
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  virtual void countMemory(UT_MemoryCounter &counter) const;
44 
45  virtual const GA_PrimitiveDefinition &getTypeDef() const
46  {
47  UT_ASSERT(theDefinition);
48  return *theDefinition;
49  }
50 
51  // Conversion Methods
52  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
53  GA_PointGroup *usedpts = 0);
54  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
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 
138  virtual void normal(NormalComp &output) const;
139 
140  /// Sorts the polygons in the polysoup spatially
141  void sortSpatial();
142 
143  virtual void convex(GA_Size maxpts = 3, const GA_Detail *restgdp = nullptr,
144  bool flipedges = false, bool avoiddegeneracy = false) final;
145 
146 protected:
147 private:
148  static GA_PrimitiveDefinition *theDefinition;
149  friend class GU_PrimitiveFactory;
150 
151  // This function calls the constructor for GU_PrimitiveFactory
152  //template<typename>
153  //friend GA_Primitive *gu_NewPrimitive(GA_Detail &gdp,GA_Offset offset,
154  // const GA_PrimitiveDefinition &);
156 };
158 
159 #endif
160 
GT_API const UT_StringHolder filename
#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.
3D Vector class.
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:201
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
virtual void normal(NormalComp &output) const =0
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:107
virtual ~GU_PrimPolySoup()
virtual void countMemory(UT_MemoryCounter &counter) const
GLintptr offset
Definition: glcorearb.h:664
#define GU_API
Definition: GU_API.h:12
virtual void convex(GA_Size maxpts=3, const GA_Detail *restgdp=nullptr, bool flipedges=false, bool avoiddegeneracy=false)=0
virtual const GA_PrimitiveDefinition & getTypeDef() const
Container class for all geometry.
Definition: GA_Detail.h:95
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:126
Definition of a geometric primitive.
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0