HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_CaptureOverride.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: SOP_CaptureOverride.h (SOP Library, C++)
7  *
8  * COMMENTS: Implements a SOP for manipulating weight overrides
9  *
10  */
11 
12 #ifndef __SOP_CaptureOverride_h__
13 #define __SOP_CaptureOverride_h__
14 
15 #include "SOP_API.h"
16 #include <UT/UT_IntArray.h>
17 #include <UT/UT_ValArray.h>
18 #include <UT/UT_String.h>
19 #include <UT/UT_VectorTypes.h>
20 #include <PRM/PRM_Name.h>
21 #include <PRM/PRM_Parm.h>
22 
23 #include "SOP_CaptureData.h"
24 #include "SOP_Node.h"
25 
26 
27 #define SOP_CAPTUREOVERRIDE_GRP_IDX 0
28 
29 class OP_Context;
30 
34 class SOP_UndoCaptureOverride;
35 
37 {
38 friend class SOP_UndoCaptureOverride;
39 friend class SOP_UndoCaptureOverrideOpDepend;
40 
41 public:
42  SOP_CaptureOverride(OP_Network *net, const char *name, OP_Operator *entry);
43  virtual ~SOP_CaptureOverride();
44 
45  const UT_String & getUndoLabel() const { return myNewOpLabel; }
46 
47  static OP_Node * ourConstructor(OP_Network*, const char*, OP_Operator*);
48  static PRM_Template ourTemplateList[];
49 
50  virtual bool updateParmsFlags() override;
51 
52  // This function allows an external caller to tell us to start a new
53  // operation. This involves apply the current operaation and starting
54  // a new one.
55  void beginNewOperation();
56 
57  virtual OP_ERROR cookInputGroups( OP_Context &context,
58  int alone ) override;
59 
60  // Rebuild the group and/or the selection if necessary:
61  OP_ERROR updateInputGroups( OP_Context &context,
62  bool changed_input, bool changed_group );
63 
64  // This will rebuild the selection if it is necessary to do so. It
65  // should be called in code paths where we don't do cookInputGroups.
66  void updateCookSelection(
67  bool changed_input, bool changed_group );
68 
69  // Checks if the sop currently overrides the capture weights for the
70  // specified point. Note that this has to take into account both the
71  // current and temporary overrides.
72  bool hasWeightOverride( int point_num ) const;
73 
74  void startNewChange( const int *points, int num_points,
75  int clamp_negative, int normalize = 0 );
76  void changeWeight( fpreal t, const char *cregion,
77  float weight, int add_weight );
78  void changeWeight( fpreal t,
79  const UT_ValArray<const char *> &cregions,
80  float weight, int add_weight );
81  void normalizeWeights( fpreal t,
82  const UT_ValArray<const char *> &cregions );
83 
84  void createCaptureWeightOverride( const int *points,
85  int num_points, fpreal t );
86  void removeCaptureWeightOverride( const int *points,
87  int num_points, fpreal t );
88 
89  int addAverageCaptureWeight( OP_Context &context,
90  const UT_IntArray &points,
91  UT_StringMap<float *> &averages );
92 
93  virtual void setVisualization( int onoff ) override;
94 
95 protected:
96  void applyPermanentOverrides(OP_Context *ctx = 0);
97 
98  virtual OP_ERROR cookMySop( OP_Context &context ) override;
99 
100  void applyAndClearCurrentDelta();
101 
102  void clearAllDeltas(fpreal t);
103 
104  virtual void buildOpDependencies() override;
105  virtual void buildParmDependency( int parm_index ) override;
106  virtual void handleOpDependency( int referenced_op_id,
107  const OP_Dependency &op_dep,
108  OP_InterestType interest_type,
109  bool &need_cook,
110  const char *old_fullpath,
111  const char *old_cwd,
112  const char *old_chan_name ) override;
113 
114  //
115  // I/O methods
116  //
117  virtual OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags,
118  const char *path_prefix,
119  const UT_String &name_override = UT_String()
120  ) override;
121  virtual bool load(UT_IStream &is, const char *extension,
122  const char *path=0) override;
123 
124 private: // methods
125  PRM_Parm & getParmByName( PRM_Name &name )
126  { return getParm( name.getToken() ); }
127  const PRM_Parm & getParmByName( PRM_Name &name ) const
128  { return getParm( name.getToken() ); }
129 
130  void fixParmCRegionPathsForRootChange(
131  const UT_String &old_full_root_path,
132  const UT_String &full_root_path );
133 
134  void setCRegionsParm( fpreal t,
135  const UT_ValArray<const char *> &cregions );
136 
137  OP_ERROR createCurrentDelta( OP_Context &context,
138  const GA_PointGroup *pt_group );
139 
140  int addCaptureRegion( UT_String &cregion_name );
141 
142  // parm callbacks
143  static void buildCregionMenu(
144  void *, PRM_Name *, int,
145  const PRM_SpareData *, const PRM_Parm * );
146  static int getCaptureRegionDetailData( void *user_data,
147  char *full_cregion_path,
148  char *rel_cregion_path,
149  GEO_CaptureBoneStorage &tube_data );
150 
151  // Get the selection group string:
152  void getSelString(UT_String &str)
153  { evalString(str, SOP_CAPTUREOVERRIDE_GRP_IDX, 0, 0.0f); }
154 
155  // Apply current delta to permanent overrides
156  static int applyStatic(void *, int idx,
157  fpreal t, const PRM_Template *);
158  // Respond to button press to clear all overrides
159  static int clearallStatic(void *, int idx,
160  fpreal t, const PRM_Template *);
161 
162  static int openSpreadsheetStatic(void *, int idx,
163  fpreal t, const PRM_Template *);
164 
165  void checkCaptureRegions();
166 
167  bool checkChangedSource(unsigned idx, OP_Context &context);
168 
169  void rollbackCurrentOverridesDelta();
170 
171  void ensureCaptureAttributesExist();
172 
173  // Undo/Redo
174  void undoOverrideDeltas(
175  GEO_CaptureOverrideDelta *delta);
176  void redoOverrideDeltas(
177  GEO_CaptureOverrideDelta *delta);
178  void undoClearOverrides(
179  SOP_UndoCaptureOverride *undo);
180  void redoClearOverrides(
181  SOP_UndoCaptureOverride *undo);
182 
183 private: // data
184  UT_String myNewOpLabel; // label for undos
185 
186  GEO_CaptureOverrideData *myPermanentOverrides;
187  GEO_CaptureOverrideDelta *myCurrentOverridesDelta;
188 
189  bool myCookedFlag; // have we cooked yet?
190  bool myApplyPermanentFlag;
191 
192  // Selection group
193  const GA_ElementGroup *myGroup;
194 
195  SOP_CaptureData myCaptureData;
196  UT_String myRootPath;
197  unsigned int myUpdatedColors : 1,
198  myForceUpdateColors : 1;
199 
200  static PRM_ChoiceList theCregionMenu;
201  static int theCregionIndex;
202 };
203 
204 #endif // __SOP_CaptureOverride_h__
205 
virtual bool updateParmsFlags()
virtual void buildOpDependencies()
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
virtual OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *pathPrefix, const UT_String &name_override=UT_String()) override
virtual void handleOpDependency(int referenced_op_id, const OP_Dependency &op_dep, OP_InterestType interest_type, bool &need_cook, const char *old_fullpath, const char *old_cwd, const char *old_chan_name)
UT_ErrorSeverity
Definition: UT_Error.h:25
GLbitfield flags
Definition: glcorearb.h:1595
Convenience class to store a bone capture region.
PRM_Parm & getParm(int i)
GLfloat f
Definition: glcorearb.h:1925
virtual bool load(UT_IStream &is, const char *extension, const char *path=0) override
OP_InterestType
Definition: OP_DataTypes.h:44
void evalString(UT_String &val, int pi, int vi, fpreal t) const
GLuint const GLchar * name
Definition: glcorearb.h:785
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
#define SOP_CAPTUREOVERRIDE_GRP_IDX
virtual OP_ERROR cookInputGroups(OP_Context &context, int alone=0)
double fpreal
Definition: SYS_Types.h:263
#define SOP_API
Definition: SOP_API.h:10
virtual void setVisualization(int)
Definition: SOP_Node.h:835
virtual void buildParmDependency(int parm_index)
virtual OP_ERROR cookMySop(OP_Context &context)=0
const UT_String & getUndoLabel() const
const char * getToken() const
Definition: PRM_Name.h:40