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 #include <CL/CL_SimpleChannel.h>
23 
25 {
26 protected:
27  /// NOTE: The constructor should only be called from subclass
28  /// constructors.
30 
31  /// NOTE: The destructor should only be called from subclass
32  /// destructors.
33  ~GEO_PrimChannel() override {}
34 
35 public:
36  bool getBBox(UT_BoundingBox *bbox) const override;
37  UT_Vector3 baryCenter() const override;
38  UT_Vector3D computeNormalD() const override;
39  UT_Vector3 computeNormal() const override;
40 
41  /// Before a point is deleted, all primitives using the point will be
42  /// notified. The method should return "false" if it's impossible to
43  /// delete the point. Otherwise, the vertices should be removed.
44  GA_DereferenceStatus dereferencePoint(
45  GA_Offset point,
46  bool dry_run=false) override;
47  GA_DereferenceStatus dereferencePoints(
48  const GA_RangeMemberQuery &pt_q,
49  bool dry_run=false) override;
50 
51 
52  bool isDegenerate() const override;
53  void reverse() override;
54  // Take the whole set of points into consideration when applying the
55  // point removal operation to this primitive. The method returns 0 if
56  // successful, -1 if it failed because it would have become degenerate,
57  // and -2 if it failed because it would have had to remove the primitive
58  // altogether.
59  int detachPoints(GA_PointGroup &grp) override;
60 
61  /// Though not strictly required (i.e. not pure virtual), these methods
62  /// should be implemented for proper behaviour.
63  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
64  void copyPrimitive(const GEO_Primitive *src) override;
65  void copySubclassData(const GA_Primitive *source) override;
66 
67  // Have we been deactivated and stashed?
68  void stashed(bool beingstashed,
70 
71  void normal(NormalComp &output) const override;
72  void normal(NormalCompD &output) const override;
73 
75  int64 getDataId() const { return myDataId; }
76 
78  void assignNewDataId() { myDataId = nextDataId(); }
79 
81  void bumpDataId()
82  {
83  if (myDataId != INVALID_DATA_ID)
84  assignNewDataId();
85  }
86 
87  /// Append a vertex. For the channel primitive, Vertices are used to refer
88  /// to a point which uses the underlying channel.
89  GA_Size appendVertex(GA_Offset ptoff);
90 
91  /// @{
92  /// Save/Load properties to a JSON stream
93  bool saveVertexArray(UT_JSONWriter &w, const GA_SaveMap &map) const;
94  bool loadVertexArray(UT_JSONParser &p, const GA_LoadMap &map);
95  bool saveChannel(UT_JSONWriter &w, const GA_SaveMap &map) const;
96  bool loadChannel(UT_JSONParser &p, const GA_LoadMap &map);
97  /// @}
98 
99  bool saveChannelProperties(UT_JSONWriter &w) const;
100 
101  const GA_PrimitiveJSON *getJSON() const override;
102 
103  static GEO_PrimChannel *build(GA_Detail *gdp,
104  fpreal value,
105  CL_SimpleChannelConstPtr channel);
106 
107  /// Returns a read-only, shared, copy of our channel. This will not
108  /// update live with changes to this GEO_PrimChannel as it is
109  /// copy-on-write.
110  CL_SimpleChannelConstPtr getChannel() const;
111 
112  /// Returns a writable version of our channel. This is made unique,
113  /// so if you have any simultaneous getChannel() or getChannelRW()
114  /// held a new copy will be created internally.
115  /// Bumps our data id.
116  CL_SimpleChannelPtr getChannelRW();
117 
118  /// Replaces our channel with the provided, possibly shared, channel.
119  /// It is expected the caller treates this as COW so does not mutate
120  /// it unless unique.
121  /// Bumps our data id.
122  void setChannel(CL_SimpleChannelConstPtr channel);
123 
124 protected:
125  /// Register intrinsic attributes
126  GA_DECLARE_INTRINSICS(override)
127 
128  static GA_PrimitiveFamilyMask buildFamilyMask()
129  { return GA_FAMILY_NONE; }
130 
131  // Evaluate the position or the derivative at domain point (u,v), where
132  // u and v MUST be in [0,1]. "v" and "dv" will be ignored here. Return 0 if
133  // OK and -1 otherwise.
134  bool evaluatePointRefMap(
135  GA_Offset result_vtx,
136  GA_AttributeRefMap &hlist,
137  fpreal u_unit, fpreal,
138  uint du, uint) const override;
139  int evaluatePointV4(
140  UT_Vector4 &pos,
141  float u_unit, float=0,
142  unsigned du=0, unsigned = 0) const override;
143 
144 private:
145  static int64 INVALID_DATA_ID;
146 
148 
149  int64 myDataId;
150 
151  static int64 nextDataId();
152 
153  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimChannel &d)
154  {
155  d.saveH9(os, 0,
158  return os;
159  }
160 };
161 #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:512
GLsizei const GLfloat * value
Definition: glcorearb.h:824
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:236
UT_SharedPtr< const CL_SimpleChannel > CL_SimpleChannelConstPtr
GA_PrimitiveFamilyMask
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
virtual void normal(NormalComp &output) const =0
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:646
~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
UT_SharedPtr< CL_SimpleChannel > CL_SimpleChannelPtr
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:278
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
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