HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PrimTube.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: Geometry Library (C++)
7  *
8  * COMMENTS:
9  * This is a cylinder. There are two ways of storing a cylinder/tube:
10  * a) By setting two point references for the base and top
11  * of the cylinder. In this method, the height of the
12  * cylinder is locked. As well, the axes are fixed.
13  * This is the least preferred method since the X and Y
14  * axes are undefined (too many degrees of freedom).
15  * b) The preferred way is to specify a single point. The tube
16  * will extend in the Z axis according to the height
17  * specified. The tube may then be rotated or whatever
18  * and the X and Y axes will always be well defined.
19  *
20  */
21 
22 #ifndef __GEO_PrimTube_H__
23 #define __GEO_PrimTube_H__
24 
25 #include "GEO_API.h"
26 #include "GEO_Quadric.h"
27 #include "GEO_PrimType.h"
28 #include "GEO_Vertex.h"
29 
30 #define GEO_TUBE_XSECT_BOT_XP 0
31 #define GEO_TUBE_XSECT_BOT_XN 1
32 #define GEO_TUBE_XSECT_BOT_ZP 2
33 #define GEO_TUBE_XSECT_BOT_ZN 3
34 #define GEO_TUBE_XSECT_MID_XP 4
35 #define GEO_TUBE_XSECT_MID_XN 5
36 #define GEO_TUBE_XSECT_MID_ZP 6
37 #define GEO_TUBE_XSECT_MID_ZN 7
38 #define GEO_TUBE_XSECT_TOP_XP 8
39 #define GEO_TUBE_XSECT_TOP_XN 9
40 #define GEO_TUBE_XSECT_TOP_ZP 10
41 #define GEO_TUBE_XSECT_TOP_ZN 11
42 #define GEO_TUBE_XSECT_BOT_XN2 12
43 #define GEO_TUBE_XSECT_TOP_XN2 13
44 #define GEO_TUBE_XSECT_BOT_XP2 14
45 #define GEO_TUBE_XSECT_TOP_XP2 15
46 #define GEO_TUBE_XSECT_BOT_ZN2 16
47 #define GEO_TUBE_XSECT_TOP_ZN2 17
48 #define GEO_TUBE_XSECT_BOT_ZP2 18
49 #define GEO_TUBE_XSECT_TOP_ZP2 19
50 #define GEO_TUBE_XSECT_BOT_CTR 20
51 #define GEO_TUBE_XSECT_TOP_CTR 21
52 
53 #define GEO_TUBE_GUIDEEDGE_BX 0
54 #define GEO_TUBE_GUIDEEDGE_BZ 1
55 #define GEO_TUBE_GUIDEEDGE_MX 2
56 #define GEO_TUBE_GUIDEEDGE_MZ 3
57 #define GEO_TUBE_GUIDEEDGE_TX 4
58 #define GEO_TUBE_GUIDEEDGE_TZ 5
59 #define GEO_TUBE_GUIDEEDGE_XN 6
60 #define GEO_TUBE_GUIDEEDGE_XP 7
61 #define GEO_TUBE_GUIDEEDGE_ZN 8
62 #define GEO_TUBE_GUIDEEDGE_ZP 9
63 #define GEO_TUBE_GUIDEEDGE_Z 10
64 
66 {
67 public:
69  {
70  endcaps = 0;
71  }
72  unsigned endcaps:1; // Tube has end caps
73 };
74 
76 {
77 protected:
78  /// NOTE: The constructor should only be called from subclass
79  /// constructors.
81 
82  /// NOTE: The destructor should only be called from subclass
83  /// destructors.
84  ~GEO_PrimTube() override {}
85 
86 public:
88  UT_Vector3 &nml,
89  float u, float v=0, float w=0) const override;
90  bool getBBox(UT_BoundingBox *bbox) const override;
91  void addToBSphere(
92  UT_BoundingSphere *bsphere) const override;
93  // UT_Vector3 baryCenter() const override;
94  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
95  void copyPrimitive(const GEO_Primitive *src) override;
96 
97  void copySubclassData(const GA_Primitive *source) override;
98 
99  bool hasGuideEdge(int edgeid, UT_Vector3 &a,
100  UT_Vector3 &b) const override;
101  bool hasXsectPoint(int pointid,
102  UT_Vector3 &p) const override;
103 
104 //
105 // End cap handling for tube primitive
106  unsigned endcaps() const { return flags.endcaps; }
107  void setEndCaps(int onOff) { flags.endcaps = onOff; }
108  float getTaper() const { return myTaper; }
109  void setTaper(float t) { myTaper = t; }
110 
111 //
112 // Tube Capture Region handling
113 //
114 
115 // computes weight of point in this capture region tube. If the point
116 // is outside the region, the weight is zero. Otherwise the weight is
117 // .0 at the edge of the region, 1.0 along the center bone line of the
118 // region.
119 // pos must be in tube's SOP space, i.e. you've multiplied by the
120 // inverse of getTransform4()
121  float getCaptureRegionWeight( const UT_Vector3 &pos,
122  const GA_ROAttributeRef &tubeCaptAtrOffset) const;
123  static float computeCaptureRegionWeight( const UT_Vector3 &pos,
124  float bcap, float tcap, float taperx,
125  float taperz, float min_weight,
126  float max_weight );
127 
128  fpreal calcVolume(const UT_Vector3 &refpt) const override;
129  fpreal calcArea() const override;
130  fpreal calcPerimeter() const override;
131 
132  const GA_PrimitiveJSON *getJSON() const override;
133 
134 protected:
136  { return GEO_Quadric::buildFamilyMask(); }
137 
138  GA_DECLARE_INTRINSICS(override)
139 
140  // Save and load the privates of this class.
141  bool savePrivateH9(std::ostream &os,
142  bool binary) const override;
143  bool loadPrivateH9(UT_IStream &is) override;
144 
145  // Evaluate the position or the derivative at domain point (u,v), where
146  // u and v MUST be in [0,1]. "v" and "dv" will be ignored when dealing
147  // with one-dimensional types such as circles and polygons. Return 0 if
148  // OK and -1 otherwise.
149  bool evaluatePointRefMap(
150  GA_Offset result_vtx,
151  GA_AttributeRefMap &hlist,
152  fpreal u, fpreal v,
153  uint du, uint dv) const override;
154  int evaluatePointV4(
155  UT_Vector4 &pos,
156  float u, float v = 0,
157  unsigned du=0, unsigned dv=0) const override;
158 
159 private:
161  // The taper is the radius of the bottom half of the default tube.
162  // The top half's radius is one. These radii are then modified by
163  // myXform.
164  float myTaper;
165 
166  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimTube &d)
167  {
168  d.saveH9(os, 0,
171  return os;
172  }
173 };
174 #endif
fpreal calcPerimeter() const override
GLbitfield flags
Definition: glcorearb.h:1596
const GLdouble * v
Definition: glcorearb.h:837
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
fpreal calcVolume(const UT_Vector3 &) const override
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
~GEO_PrimTube() override
Definition: GEO_PrimTube.h:84
fpreal calcArea() const override
void copyPrimitive(const GEO_Primitive *src) override
GA_PrimitiveFamilyMask
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
GA_Size GA_Offset
Definition: GA_Types.h:646
void setEndCaps(int onOff)
Definition: GEO_PrimTube.h:107
GLintptr offset
Definition: glcorearb.h:665
This class provides a way to manage a reference to an attribute permitting Read-Only access...
virtual const GA_PrimitiveJSON * getJSON() const =0
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
Provide a JSON interface to a primitive.
#define GEO_API
Definition: GEO_API.h:14
A handle to simplify manipulation of multiple attributes.
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
unsigned endcaps() const
Definition: GEO_PrimTube.h:106
GLdouble t
Definition: glad.h:2397
void setTaper(float t)
Definition: GEO_PrimTube.h:109
void copySubclassData(const GA_Primitive *source) override
GEO_Primitive * copy(int preserve_shared_pts=0) const override
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_PrimTube.h:135
fpreal64 fpreal
Definition: SYS_Types.h:277
static GA_PrimitiveFamilyMask buildFamilyMask()
Return the family mask for all quadric sub-classes.
Definition: GEO_Quadric.h:220
virtual int evaluateNormalVector(UT_Vector3 &nml, float u, float v=0, float w=0) const
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
bool getBBox(UT_BoundingBox *bbox) const override=0
virtual bool hasGuideEdge(int edgeid, UT_Vector3 &a, UT_Vector3 &b) const
unsigned int uint
Definition: SYS_Types.h:45
float getTaper() const
Definition: GEO_PrimTube.h:108
GA_DECLARE_INTRINSICS(override)
virtual bool hasXsectPoint(int pointid, UT_Vector3 &p) const
GLenum src
Definition: glcorearb.h:1793