HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PrimChannel.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: Channel primitive.
9  */
10 
11 #ifndef __GEO_PrimChannel_H__
12 #define __GEO_PrimChannel_H__
13 
14 #include "GEO_API.h"
15 #include "GEO_Detail.h"
16 #include "GEO_Primitive.h"
17 #include "GEO_PrimType.h"
18 #include "GEO_Vertex.h"
19 
20 #include <GA/GA_Detail.h>
21 #include <UT/UT_StringHolder.h>
22 
23 class CL_SimpleChannel;
24 
26 {
27 protected:
28  /// NOTE: The constructor should only be called from subclass
29  /// constructors.
31 
32  /// NOTE: The destructor should only be called from subclass
33  /// destructors.
34  ~GEO_PrimChannel() override {}
35 
36 public:
37  bool getBBox(UT_BoundingBox *bbox) const override;
38  UT_Vector3 baryCenter() const override;
39  UT_Vector3D computeNormalD() const override;
40  UT_Vector3 computeNormal() const override;
41 
42  /// Before a point is deleted, all primitives using the point will be
43  /// notified. The method should return "false" if it's impossible to
44  /// delete the point. Otherwise, the vertices should be removed.
45  GA_DereferenceStatus dereferencePoint(
46  GA_Offset point,
47  bool dry_run=false) override;
48  GA_DereferenceStatus dereferencePoints(
49  const GA_RangeMemberQuery &pt_q,
50  bool dry_run=false) override;
51 
52 
53  bool isDegenerate() const override;
54  void reverse() override;
55  // Take the whole set of points into consideration when applying the
56  // point removal operation to this primitive. The method returns 0 if
57  // successful, -1 if it failed because it would have become degenerate,
58  // and -2 if it failed because it would have had to remove the primitive
59  // altogether.
60  int detachPoints(GA_PointGroup &grp) override;
61 
62  /// Though not strictly required (i.e. not pure virtual), these methods
63  /// should be implemented for proper behaviour.
64  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
65  void copyPrimitive(const GEO_Primitive *src) override;
66  void copySubclassData(const GA_Primitive *source) override;
67 
68  // Have we been deactivated and stashed?
69  void stashed(bool beingstashed,
71 
72  void normal(NormalComp &output) const override;
73  void normal(NormalCompD &output) const override;
74 
76  int64 getDataId() const { return myDataId; }
77 
79  void assignNewDataId() { myDataId = nextDataId(); }
80 
82  void bumpDataId()
83  {
84  if (myDataId != INVALID_DATA_ID)
85  assignNewDataId();
86  }
87 
88  /// Append a vertex. For the channel primitive, Vertices are used to refer
89  /// to a point which uses the underlying channel.
90  GA_Size appendVertex(GA_Offset ptoff);
91 
92  /// @{
93  /// Save/Load properties to a JSON stream
94  bool saveVertexArray(UT_JSONWriter &w, const GA_SaveMap &map) const;
95  bool loadVertexArray(UT_JSONParser &p, const GA_LoadMap &map);
96  bool saveChannel(UT_JSONWriter &w, const GA_SaveMap &map) const;
97  bool loadChannel(UT_JSONParser &p, const GA_LoadMap &map);
98  /// @}
99 
100  bool saveChannelProperties(UT_JSONWriter &w) const;
101 
102  const GA_PrimitiveJSON *getJSON() const override;
103 
104  static GEO_PrimChannel *build(GA_Detail *gdp,
105  fpreal value,
106  const UT_SharedPtr<CL_SimpleChannel> &channel);
107 
108 protected:
109  /// Register intrinsic attributes
110  GA_DECLARE_INTRINSICS(override)
111 
112  static GA_PrimitiveFamilyMask buildFamilyMask()
113  { return GA_FAMILY_NONE; }
114 
115  // Evaluate the position or the derivative at domain point (u,v), where
116  // u and v MUST be in [0,1]. "v" and "dv" will be ignored here. Return 0 if
117  // OK and -1 otherwise.
118  bool evaluatePointRefMap(
119  GA_Offset result_vtx,
120  GA_AttributeRefMap &hlist,
121  fpreal u_unit, fpreal,
122  uint du, uint) const override;
123  int evaluatePointV4(
124  UT_Vector4 &pos,
125  float u_unit, float=0,
126  unsigned du=0, unsigned = 0) const override;
127 
128  // This should only be called from GU_Primitive
129  // External access to the channel should be done through the GU layer's
130  // getChannel{Read,Write}Handle
131  UT_SharedPtr<CL_SimpleChannel> getChannel();
132 
133  UT_SharedPtr<const CL_SimpleChannel> getConstChannel() const;
134 
135 private:
136  static int64 INVALID_DATA_ID;
137 
139 
140  int64 myDataId;
141 
142  static int64 nextDataId();
143 
144  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimChannel &d)
145  {
146  d.saveH9(os, 0,
149  return os;
150  }
151 };
152 #endif
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimChannel &d)
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
virtual UT_Vector3 baryCenter() const
virtual void copyPrimitive(const GEO_Primitive *src)=0
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
virtual UT_Vector3D computeNormalD() const =0
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:508
SYS_FORCE_INLINE void bumpDataId()
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
void reverse() override=0
Reverse the order of vertices.
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
Abstract base class for a range membership query object.
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
virtual void normal(NormalComp &output) const =0
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:641
~GEO_PrimChannel() override
GLintptr offset
Definition: glcorearb.h:665
SYS_FORCE_INLINE int64 getDataId() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
SYS_FORCE_INLINE void assignNewDataId()
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
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
long long int64
Definition: SYS_Types.h:116
A handle to simplify manipulation of multiple attributes.
Options during loading.
Definition: GA_LoadMap.h:42
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
virtual int detachPoints(GA_PointGroup &grp)=0
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
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
Container class for all geometry.
Definition: GA_Detail.h:96
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Definition: core.h:1131
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
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
GLenum src
Definition: glcorearb.h:1793