HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_CaptureData.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_PointCapture.h ( GEO Library, C++)
7  *
8  * COMMENTS: This class handles the data management of point capture
9  * attributes. Point capture attributes consist of two numbers,
10  * an index and a weight.
11  * It transfers this data to a gdp using the transferToGdp()
12  * method
13  */
14 
15 #ifndef __GEO_CaptureData__
16 #define __GEO_CaptureData__
17 
18 #include "GEO_API.h"
19 #include "GEO_Detail.h"
20 #include <GA/GA_Types.h>
21 #include <UT/UT_FloatArray.h>
22 #include <UT/UT_IntArray.h>
23 #include <UT/UT_Matrix4.h>
24 #include <UT/UT_Array.h>
25 #include <UT/UT_String.h>
26 #include <SYS/SYS_TypeDecorate.h>
27 #include <iosfwd>
28 
30 
31 #define GEO_CAPTUREDATA_DEFAULT_VALUE -1.0F
32 
34 {
37  GEO_CAPTUREDATA_PT_ATR_ENTRY_SZ // should always be last
38 };
39 
40 class GEO_Detail;
41 class GA_PointGroup;
42 
43 
45 {
46 public:
49 
50  const UT_String &getPath() const { return myPath; }
51  int changeString( const char *from, const char *to, bool fullword )
52  { return myPath.changeString( from, to, fullword ); }
53  const UT_Matrix4 &getXform() const { return myXform; }
54  float getXtaper() const { return myXtaper; }
55  float getZtaper() const { return myZtaper; }
56  float getTopCapHeight() const { return myTopCapHeight; }
57  float getBotCapHeight() const { return myBotCapHeight; }
58  float getMinWeight() const { return myMinWeight; }
59  float getMaxWeight() const { return myMaxWeight; }
60  int getID() const { return myID; }
61  int getPrimNum() const { return myPrimNum; }
62 
63  void setPath (const UT_String &path) { myPath.harden(path); }
64  void setXform(const UT_Matrix4 &xf) { myXform = xf; }
65  void setXZtapers(float x, float z) { myXtaper = x; myZtaper=z; }
66  void setTopCapHeight(float h) { myTopCapHeight = h; }
67  void setBotCapHeight(float h) { myBotCapHeight = h; }
68  void setMinWeight(float m) { myMinWeight = m; }
69  void setMaxWeight(float m) { myMaxWeight = m; }
70  void setID(int id) { myID = id; }
71  void setPrimNum(int pn) { myPrimNum = pn; }
72 
73  // this operators are need for UT_Array<GEO_CaptureRegionData> to work
75  bool operator== (const GEO_CaptureRegionData &d) const;
76  bool operator!=(const GEO_CaptureRegionData &d) const
77  { return !(*this == d); }
78 
79 private:
80  UT_String myPath; // tube full paths
81  UT_Matrix4 myXform; // tube xform
82  float myXtaper; // tube tapers
83  float myZtaper;
84  float myTopCapHeight; // tube end cap heights
85  float myBotCapHeight;
86  float myMinWeight;
87  float myMaxWeight;
88  int myID; // tube unique ID
89  int myPrimNum; // tube prim number, can be -1
90 };
91 
93 {
94 public:
96  ~GEO_CaptureData();
97 
98  void initialize( const UT_String &sop_path,
99  float capture_frame, int num_pts=0, int num_regions=0,
100  int num_entries_per_pnt=0 );
101 
102  ///
103  /// Capture Region Methods
104  ///
105  unsigned int getNumRegions() const { return myRegionData.entries(); }
106 
107  const UT_String &regionPath (unsigned i) const
108  { return myRegionData(i).getPath();}
109  const UT_Matrix4 &regionXform(unsigned i)const
110  { return myRegionData(i).getXform();}
111  int regionID (unsigned i) const
112  { return myRegionData(i).getID();}
113  int regionPrimNum(unsigned i) const
114  { return myRegionData(i).getPrimNum(); }
115  float taperX(unsigned i) const
116  { return myRegionData(i).getXtaper(); }
117  float taperZ(unsigned i) const
118  { return myRegionData(i).getZtaper(); }
119  float topCap(unsigned i) const
120  { return myRegionData(i).getTopCapHeight(); }
121  float botCap(unsigned i) const
122  { return myRegionData(i).getBotCapHeight(); }
123  float minWeight(unsigned i) const
124  { return myRegionData(i).getMinWeight(); }
125  float maxWeight(unsigned i) const
126  { return myRegionData(i).getMaxWeight(); }
127 
128  int changeString( const char *from, const char *to,
129  bool fullword );
130 
131  void updateRegionPath(unsigned int i,
132  const UT_String &new_path,
133  int new_op_id);
134 
135  /// returns the CaptureData index for the given OP path/ID
136  int findRegion(const UT_String &region_path, int prim_num) const;
137  int findRegion(int OPuniqueID, int prim_num) const;
138 
139  void getRegionList(int OPuniqueID, UT_IntArray &regions) const;
140 
141  /// create space for new region and return the new index
142  int appendRegion( int opID, const UT_String &path,
143  int tube_prim_num, const UT_Matrix4 &xform,
144  float taperx, float taperz,
145  float bot_cap, float top_cap,
146  float min_weight, float max_weight );
147 
148  int saveOverrideFile( const UT_String &filename,
149  const GA_PointGroup *pt_group=0,
150  const GEO_Detail *gdp=0,
151  int binary=0) const;
152  int saveOverrideFile( std::ostream &os,
153  const GA_PointGroup *pt_group=0,
154  const GEO_Detail *gdp=0,
155  int binary=0) const;
156  // returns 0 if file not found, the negative of the line_number
157  // if there was a problem with the file format. Otherwise return
158  // the number of lines read from the file.
159  bool loadOverrideFile( const char *filename, int &line_num );
160 
161  ///
162  /// Per point Data methods
163  ///
164 
165  /// adds a non-zero weighted point entry. assumes that we're inserting
166  /// in sorted order without duplicates.
167  void appendSortedPtEntry(GA_Index point_num, int idx, float weight);
168 
169  /// Sort and normalize weights
170  void sortAndNormalizePtWeights();
171 
172  int getNumEntriesPerPt() const { return myMaxEntriesPerPt; }
173  int getNumStoredPts() const { return myPtEntry.entries(); }
174 
175  /// puts our data into the given gdp's point and detail attributes
176  /// returns 1 on success, 0 otherwise
177  /// transferToGdp doesn't have any failure case so doesn't return anything.
178  void transferToGdp( GEO_Detail *gdp, bool destroy, float blend,
179  bool relative_skel_root ) const;
180  int transferFromGdp(const GEO_Detail *gdp,const GA_PointGroup *pt_group);
181 
182  /// verb method to get the region data out of the raw float array data from
183  /// a gdp's detail attribute
184  static void parsePointData( const float *data, int idx,
185  int &region_idx, float &weight );
186 
187  /// Retrieves the weight of the point at the specified index. The weight
188  /// corresponds to the region at region_idx index.
189  /// @param prev_array_idx - an optional speed optimization param. If
190  /// this is called in a loop for consecutive points, set to 0
191  /// initially and pass the same variable to this function while
192  /// in the loop.
193  float getPointWeight(int point_idx, int region_idx, int *prev_array_idx = NULL);
194 
195  /// constructs a capture region detail attribute data using the given
196  /// parameters into tube_data which must have
197  /// GB_AttributeCaptureRegion::getBoneSize() number of floats
198  static int constructCaptureRegionDetailData(
199  const char *cregion_name,
200  const UT_Matrix4 &parent_xform,
201  const GEO_Detail *tube_gdp,
202  GEO_CaptureBoneStorage &tube_data );
203 
204  int getDetailDataFromGdp( const GEO_Detail *gdp );
205 
206  /// Checks if given point capture attribute is valid.
207  /// When strict is false, it will not check for pCaptData which defines
208  /// the skeleton capture pose.
209  static bool isValidCaptureAttribute(
210  const GA_Attribute *atr,
212  bool strict = true);
213 
214 private: // methods
215  bool loadOverrideFile( UT_IStream &is, int &line_num );
216 
217  int savePointEntry(std::ostream &os, int i, const float *pt_data,
218  bool binary) const;
219 
220  /// helper methods for transferDataToGdp()
221  void computeSkelRootPath( UT_String &root_path ) const;
222  int putDetailDataInGdp( GEO_Detail *gdp, bool replace,
223  bool relative_skel_root,
224  UT_IntArray &region_map ) const;
225  int putPointDataInGdp( GEO_Detail *gdp, bool replace, float blend,
226  const UT_IntArray &region_map ) const;
227  int getPointDataFromGdp( const GEO_Detail *gdp,
228  const GA_PointGroup *pt_group );
229 
230 private: // data
231 
232  struct PtEntry
233  {
234  PtEntry() { } // ctor leaves data uninitialized for speed
235  GA_Index pt_num; // point number
236  int num_entries; // number of non-zero weighted entries for pt
237  };
238 
239  float myCaptureFrame;
240  UT_String mySopPath;
241  UT_Array<GEO_CaptureRegionData> myRegionData;
242  UT_Array<PtEntry> myPtEntry;
243  UT_FloatArray myPtData;
244  int myMaxEntriesPerPt;
245 };
246 
247 ///////////////////////////////////////////////////////////////////////////////
248 //
249 // Inline Implementations
250 //
251 
252 inline void
253 GEO_CaptureData::appendSortedPtEntry(GA_Index point_num, int idx, float weight)
254 {
255  // this functions assume that we're appending in sorted order
256  // and without duplicates
257  UT_ASSERT_P(myPtEntry.entries() == 0
258  || point_num >= myPtEntry.last().pt_num);
259 
260  if (myPtEntry.entries() == 0 || point_num != myPtEntry.last().pt_num)
261  {
262  myPtEntry.append();
263  myPtEntry.last().pt_num = point_num;
264  myPtEntry.last().num_entries = 0;
265  }
266 
267  myPtData.append(float(idx)); // Append the capture region index
268  myPtData.append(weight); // Append the corresponding weight
269 
270  myPtEntry.last().num_entries++;
271  if (myPtEntry.last().num_entries > myMaxEntriesPerPt)
272  myMaxEntriesPerPt = myPtEntry.last().num_entries;
273 }
274 
276 
277 #endif
T & last()
Definition: UT_Array.h:840
Definition of a geometry attribute.
Definition: GA_Attribute.h:203
GT_API const UT_StringHolder filename
GEO_CaptureData_PtAtr_Entry
const UT_String & getPath() const
int getNumEntriesPerPt() const
float getXtaper() const
float getMinWeight() const
void setXform(const UT_Matrix4 &xf)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
void setTopCapHeight(float h)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
Convenience class to store a bone capture region.
int regionPrimNum(unsigned i) const
void setMaxWeight(float m)
const UT_Matrix4 & getXform() const
float getBotCapHeight() const
int regionID(unsigned i) const
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4949
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
int getNumStoredPts() const
CaptureType
Methods for manipulating capture weights (GEO_CaptureWeight.C)
Definition: GEO_Detail.h:1016
float getMaxWeight() const
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:164
std::string OIIO_UTIL_API replace(string_view str, string_view pattern, string_view replacement, bool global=false)
#define GEO_API
Definition: GEO_API.h:14
float getTopCapHeight() const
GLuint id
Definition: glcorearb.h:655
void setPath(const UT_String &path)
bool operator!=(const GEO_CaptureRegionData &d) const
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
SYS_DECLARE_LEGACY_TR(GU_Detail)
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:647
GLint GLenum GLint x
Definition: glcorearb.h:409
float topCap(unsigned i) const
const UT_Matrix4 & regionXform(unsigned i) const
exint append()
Definition: UT_Array.h:142
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:669
unsigned int getNumRegions() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
float botCap(unsigned i) const
float taperX(unsigned i) const
LeafData & operator=(const LeafData &)=delete
int changeString(const char *from, const char *to, bool fullword)
void setXZtapers(float x, float z)
float maxWeight(unsigned i) const
void appendSortedPtEntry(GA_Index point_num, int idx, float weight)
GU_API void xform(CE_Context &context, bool recompile, int npts, const cl::Buffer &outPos, const cl::Buffer &inPos, const cl::Buffer &surfacexform, const cl::Buffer *grp=nullptr)
const UT_String & regionPath(unsigned i) const
float taperZ(unsigned i) const
void setMinWeight(float m)
float getZtaper() const
Definition: format.h:1821
float minWeight(unsigned i) const
void setBotCapHeight(float h)