HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_VolumeElementBase.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: GEO_VolumeElementBase.h (GEO Library, C++)
7  *
8  * COMMENTS: This is the base class for all volume element types.
9  */
10 
11 #pragma once
12 
13 #ifndef __GEO_VolumeElementBase__
14 #define __GEO_VolumeElementBase__
15 
16 #include "GEO_API.h"
17 #include "GEO_Primitive.h"
18 #include <GA/GA_Defines.h>
19 #include <GA/GA_PrimitiveTypes.h>
20 #include <SYS/SYS_Inline.h>
21 #include <UT/UT_Array.h>
22 
23 class GA_Detail;
24 
26 {
27 public:
30  : GEO_Primitive(d, offset)
31  {}
32 
33  /// The number of faces that make up this volume
34  virtual GA_Size getFaceCount() const = 0;
35  /// Returns the indices to the vertices, not the vertex offsets!
36  virtual int getFaceIndices(GA_Size faceno, UT_Array<int> &vtxlist) const = 0;
37  /// Returns the number of indices in specified face.
38  virtual int getFaceIndexCount(GA_Size faceno) const = 0;
39 
40  /// Returns any primitive sharing the face of the same type,
41  /// so tet only returns tet and hex only returns hex.
42  /// See volumelement for a more general version.
43  virtual GA_Offset findSharedFace(GA_Size faceno) const = 0;
44 
45  /// The number of edges in this volume.
46  virtual GA_Size getEdgeCount() const = 0;
47  /// Returns the indices of the edge. Note each edge shows up once
48  /// and due to the nature of volumes, is undirected.
49  virtual void getEdgeIndices(GA_Size edgeno, int &e0, int &e1) const = 0;
50  bool hasEdge(const GA_Edge &edge) const override
51  {
52  for (GA_Size i = 0, nedge = getEdgeCount(); i < nedge; ++i)
53  {
54  int i0, i1;
55  getEdgeIndices(i, i0, i1);
56  GA_Offset p0 = getPointOffset(i0);
57  GA_Offset p1 = getPointOffset(i1);
58  if ((edge.p0() == p0 && edge.p1() == p1) ||
59  (edge.p0() == p1 && edge.p1() == p0))
60  return true;
61  }
62  return false;
63  }
64 
65  void iterateEdges(GA_IterateEdgesFunc apply_func) const override
66  {
67  for (int i = 0, nedge = getEdgeCount(); i < nedge; ++i)
68  {
69  int i0; int i1;
70  getEdgeIndices(i, i0, i1);
71  // Both directions are present
72  if (!apply_func(GA_Edge(getPointOffset(i0), getPointOffset(i1))))
73  return;
74  if (!apply_func(GA_Edge(getPointOffset(i1), getPointOffset(i0))))
75  return;
76  }
77  }
78 
79  void iterateEdgesByVertex(GA_IterateEdgesByVertexFunc apply_func) const override
80  {
81  for (int i = 0, nedge = getEdgeCount(); i < nedge; ++i)
82  {
83  int i0; int i1;
84  getEdgeIndices(i, i0, i1);
85 
86  // Both directions are present
87  if (!apply_func(i0, i1) || !apply_func(i1, i0))
88  return;
89  }
90  }
91 
92  bool getBBox(UT_BoundingBox *bbox) const override;
93  void addToBSphere(UT_BoundingSphere *bsphere) const override;
94  UT_Vector3 baryCenter() const override;
95  UT_Vector3D baryCenterD() const override;
96  UT_Vector3 computeNormal() const override;
97  UT_Vector3D computeNormalD() const override;
98 
99 #if !GA_PRIMITIVE_VERTEXLIST
100  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
101 
102  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
103  void *data = 0) const;
104 #endif
105 
106  /// Builds volumeelements using the specified range of point offsets,
107  /// as dictated by nprims and primpointnumbers, in parallel.
108  /// primpointnumbers lists the *offsets* of the points used by
109  /// each volumeelemnt *MINUS* startpt, i.e. they are offsets relative to
110  /// startpt, *not* indices relative to startpt. The offset of the first
111  /// hexahedron is returned, and the rest are at consecutive offsets. All
112  /// hexpointnumbers must be between 0 (inclusive) and npoints (exclusive).
113  ///
114  /// NOTE: Existing primitives *are* allowed to be using the points in
115  /// the specified range already, and the elements being created do not
116  /// do not need to use all of the points in the range. However,
117  /// these cases may impact performance.
118  static GA_Offset buildBlock(GA_Detail *detail,
119  const GA_Offset startpt,
120  const GA_Size npoints,
121  const GA_Size nprims,
122  GA_PrimitiveTypeId primtype,
123  int vertexperprim,
124  const int *primpointnumbers);
125 
126 protected:
128  { return GA_FAMILY_VOLUMEELEMENT; }
129 
130  /// All subclasses should call this method to register the intrinsics.
131  /// @see GA_IntrinsicManager
134  { return GEO_Primitive::registerIntrinsics(defn); }
135 
136  bool evaluatePointRefMap(
137  GA_Offset result_vtx,
138  GA_AttributeRefMap &hlist,
139  fpreal u, fpreal v,
140  uint du, uint dv) const override;
142  UT_Vector4 &pos,
143  float u, float v = 0,
144  unsigned du=0, unsigned dv=0) const override
145  {
146  return GEO_Primitive::evaluatePointV4(pos, u, v,
147  du, dv);
148  }
150  GA_Offset result_vertex,
151  GA_AttributeRefMap &hlist) const override;
152 
154 };
156 
157 #endif
158 
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:254
virtual UT_Vector3 baryCenter() const
virtual UT_Vector3D computeNormalD() const =0
int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const override
const GLdouble * v
Definition: glcorearb.h:837
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
UT_Function< bool(const GA_Edge &edge)> GA_IterateEdgesFunc
Definition: GA_Primitive.h:73
GA_EdgeT< GA_Offset, false > GA_Edge
Definition: GA_Edge.h:90
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
GA_PrimitiveFamilyMask
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:678
void iterateEdgesByVertex(GA_IterateEdgesByVertexFunc apply_func) const override
GA_Size GA_Offset
Definition: GA_Types.h:641
GLintptr offset
Definition: glcorearb.h:665
virtual UT_Vector3D baryCenterD() const
static GA_PrimitiveFamilyMask buildFamilyMask()
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Function< bool(GA_Size, GA_Size)> GA_IterateEdgesByVertexFunc
Definition: GA_Primitive.h:74
#define GEO_API
Definition: GEO_API.h:14
SYS_FORCE_INLINE GEO_VolumeElementBase(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
A handle to simplify manipulation of multiple attributes.
GLint i1
Definition: glad.h:2724
T p1() const
Definition: GA_Edge.h:32
void addPointRefToGroup(GA_PointGroup &grp) const
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
bool hasEdge(const GA_Edge &edge) const override
Method to determine if a primitive has an edge (undirected).
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual bool getBBox(UT_BoundingBox *bbox) const =0
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
Container class for all geometry.
Definition: GA_Detail.h:96
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
void iterateEdges(GA_IterateEdgesFunc apply_func) const override
T p0() const
Definition: GA_Edge.h:30
Definition of a geometric primitive.
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
unsigned int uint
Definition: SYS_Types.h:45
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
Definition: format.h:895