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 <GA/GA_Types.h>
20 #include <UT/UT_FloatArray.h>
21 #include <UT/UT_IntArray.h>
22 #include <UT/UT_Matrix4.h>
23 #include <UT/UT_Array.h>
24 #include <UT/UT_String.h>
25 #include <SYS/SYS_TypeDecorate.h>
26 #include <iosfwd>
27 
29 
30 #define GEO_CAPTUREDATA_DEFAULT_VALUE -1.0F
31 
33 {
36  GEO_CAPTUREDATA_PT_ATR_ENTRY_SZ // should always be last
37 };
38 
39 class GEO_Detail;
40 class GA_PointGroup;
41 
42 
44 {
45 public:
48 
49  const UT_String &getPath() const { return myPath; }
50  int changeString( const char *from, const char *to, bool fullword )
51  { return myPath.changeString( from, to, fullword ); }
52  const UT_Matrix4 &getXform() const { return myXform; }
53  float getXtaper() const { return myXtaper; }
54  float getZtaper() const { return myZtaper; }
55  float getTopCapHeight() const { return myTopCapHeight; }
56  float getBotCapHeight() const { return myBotCapHeight; }
57  float getMinWeight() const { return myMinWeight; }
58  float getMaxWeight() const { return myMaxWeight; }
59  int getID() const { return myID; }
60  int getPrimNum() const { return myPrimNum; }
61 
62  void setPath (const UT_String &path) { myPath.harden(path); }
63  void setXform(const UT_Matrix4 &xf) { myXform = xf; }
64  void setXZtapers(float x, float z) { myXtaper = x; myZtaper=z; }
65  void setTopCapHeight(float h) { myTopCapHeight = h; }
66  void setBotCapHeight(float h) { myBotCapHeight = h; }
67  void setMinWeight(float m) { myMinWeight = m; }
68  void setMaxWeight(float m) { myMaxWeight = m; }
69  void setID(int id) { myID = id; }
70  void setPrimNum(int pn) { myPrimNum = pn; }
71 
72  // this operators are need for UT_Array<GEO_CaptureRegionData> to work
73  GEO_CaptureRegionData &operator= (const GEO_CaptureRegionData &d);
74  bool operator== (const GEO_CaptureRegionData &d) const;
75  bool operator!=(const GEO_CaptureRegionData &d) const
76  { return !(*this == d); }
77 
78 private:
79  UT_String myPath; // tube full paths
80  UT_Matrix4 myXform; // tube xform
81  float myXtaper; // tube tapers
82  float myZtaper;
83  float myTopCapHeight; // tube end cap heights
84  float myBotCapHeight;
85  float myMinWeight;
86  float myMaxWeight;
87  int myID; // tube unique ID
88  int myPrimNum; // tube prim number, can be -1
89 };
90 
92 {
93 public:
95  ~GEO_CaptureData();
96 
97  void initialize( const UT_String &sop_path,
98  float capture_frame, int num_pts=0, int num_regions=0,
99  int num_entries_per_pnt=0 );
100 
101  ///
102  /// Capture Region Methods
103  ///
104  unsigned int getNumRegions() const { return myRegionData.entries(); }
105 
106  const UT_String &regionPath (unsigned i) const
107  { return myRegionData(i).getPath();}
108  const UT_Matrix4 &regionXform(unsigned i)const
109  { return myRegionData(i).getXform();}
110  int regionID (unsigned i) const
111  { return myRegionData(i).getID();}
112  int regionPrimNum(unsigned i) const
113  { return myRegionData(i).getPrimNum(); }
114  float taperX(unsigned i) const
115  { return myRegionData(i).getXtaper(); }
116  float taperZ(unsigned i) const
117  { return myRegionData(i).getZtaper(); }
118  float topCap(unsigned i) const
119  { return myRegionData(i).getTopCapHeight(); }
120  float botCap(unsigned i) const
121  { return myRegionData(i).getBotCapHeight(); }
122  float minWeight(unsigned i) const
123  { return myRegionData(i).getMinWeight(); }
124  float maxWeight(unsigned i) const
125  { return myRegionData(i).getMaxWeight(); }
126 
127  int changeString( const char *from, const char *to,
128  bool fullword );
129 
130  void updateRegionPath(unsigned int i,
131  const UT_String &new_path,
132  int new_op_id);
133 
134  /// returns the CaptureData index for the given OP path/ID
135  int findRegion(const UT_String &region_path, int prim_num) const;
136  int findRegion(int OPuniqueID, int prim_num) const;
137 
138  void getRegionList(int OPuniqueID, UT_IntArray &regions) const;
139 
140  /// create space for new region and return the new index
141  int appendRegion( int opID, const UT_String &path,
142  int tube_prim_num, const UT_Matrix4 &xform,
143  float taperx, float taperz,
144  float bot_cap, float top_cap,
145  float min_weight, float max_weight );
146 
147  int saveOverrideFile( const UT_String &filename,
148  const GA_PointGroup *pt_group=0,
149  const GEO_Detail *gdp=0,
150  int binary=0) const;
151  int saveOverrideFile( std::ostream &os,
152  const GA_PointGroup *pt_group=0,
153  const GEO_Detail *gdp=0,
154  int binary=0) const;
155  // returns 0 if file not found, the negative of the line_number
156  // if there was a problem with the file format. Otherwise return
157  // the number of lines read from the file.
158  bool loadOverrideFile( const char *filename, int &line_num );
159 
160  ///
161  /// Per point Data methods
162  ///
163 
164  /// adds a non-zero weighted point entry. assumes that we're inserting
165  /// in sorted order without duplicates.
166  void appendSortedPtEntry(GA_Index point_num, int idx, float weight);
167 
168  /// Sort and normalize weights
169  void sortAndNormalizePtWeights();
170 
171  int getNumEntriesPerPt() const { return myMaxEntriesPerPt; }
172  int getNumStoredPts() const { return myPtEntry.entries(); }
173 
174  /// puts our data into the given gdp's point and detail attributes
175  /// returns 1 on success, 0 otherwise
176  /// transferToGdp doesn't have any failure case so doesn't return anything.
177  void transferToGdp( GEO_Detail *gdp, bool destroy, float blend,
178  bool relative_skel_root ) const;
179  int transferFromGdp(const GEO_Detail *gdp,const GA_PointGroup *pt_group);
180 
181  /// verb method to get the region data out of the raw float array data from
182  /// a gdp's detail attribute
183  static void parsePointData( const float *data, int idx,
184  int &region_idx, float &weight );
185 
186  /// Retrieves the weight of the point at the specified index. The weight
187  /// corresponds to the region at region_idx index.
188  /// @param prev_array_idx - an optional speed optimization param. If
189  /// this is called in a loop for consecutive points, set to 0
190  /// initially and pass the same variable to this function while
191  /// in the loop.
192  float getPointWeight(int point_idx, int region_idx, int *prev_array_idx = NULL);
193 
194  /// constructs a capture region detail attribute data using the given
195  /// parameters into tube_data which must have
196  /// GB_AttributeCaptureRegion::getBoneSize() number of floats
197  static int constructCaptureRegionDetailData(
198  const char *cregion_name,
199  const UT_Matrix4 &parent_xform,
200  const GEO_Detail *tube_gdp,
201  GEO_CaptureBoneStorage &tube_data );
202 
203  int getDetailDataFromGdp( const GEO_Detail *gdp );
204 
205 private: // methods
206  bool loadOverrideFile( UT_IStream &is, int &line_num );
207 
208  int savePointEntry(std::ostream &os, int i, const float *pt_data,
209  bool binary) const;
210 
211  /// helper methods for transferDataToGdp()
212  void computeSkelRootPath( UT_String &root_path ) const;
213  int putDetailDataInGdp( GEO_Detail *gdp, bool replace,
214  bool relative_skel_root,
215  UT_IntArray &region_map ) const;
216  int putPointDataInGdp( GEO_Detail *gdp, bool replace, float blend,
217  const UT_IntArray &region_map ) const;
218  int getPointDataFromGdp( const GEO_Detail *gdp,
219  const GA_PointGroup *pt_group );
220 
221 private: // data
222 
223  struct PtEntry
224  {
225  PtEntry() { } // ctor leaves data uninitialized for speed
226  GA_Index pt_num; // point number
227  int num_entries; // number of non-zero weighted entries for pt
228  };
229 
230  float myCaptureFrame;
231  UT_String mySopPath;
232  UT_Array<GEO_CaptureRegionData> myRegionData;
233  UT_Array<PtEntry> myPtEntry;
234  UT_FloatArray myPtData;
235  int myMaxEntriesPerPt;
236 };
237 
238 ///////////////////////////////////////////////////////////////////////////////
239 //
240 // Inline Implementations
241 //
242 
243 inline void
244 GEO_CaptureData::appendSortedPtEntry(GA_Index point_num, int idx, float weight)
245 {
246  // this functions assume that we're appending in sorted order
247  // and without duplicates
248  UT_ASSERT_P(myPtEntry.entries() == 0
249  || point_num >= myPtEntry.last().pt_num);
250 
251  if (myPtEntry.entries() == 0 || point_num != myPtEntry.last().pt_num)
252  {
253  myPtEntry.append();
254  myPtEntry.last().pt_num = point_num;
255  myPtEntry.last().num_entries = 0;
256  }
257 
258  myPtData.append(float(idx)); // Append the capture region index
259  myPtData.append(weight); // Append the corresponding weight
260 
261  myPtEntry.last().num_entries++;
262  if (myPtEntry.last().num_entries > myMaxEntriesPerPt)
263  myMaxEntriesPerPt = myPtEntry.last().num_entries;
264 }
265 
267 
268 #endif
T & last()
Definition: UT_Array.h:796
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:4784
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
int getNumStoredPts() const
float getMaxWeight() const
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
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:635
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:648
unsigned int getNumRegions() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
float botCap(unsigned i) const
float taperX(unsigned i) const
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)
const UT_String & regionPath(unsigned i) const
float taperZ(unsigned i) const
void setMinWeight(float m)
float getZtaper() const
Definition: format.h:895
float minWeight(unsigned i) const
void setBotCapHeight(float h)