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