HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~SOP_CaptureOverride() override;
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  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 
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  bool addAverageCaptureWeight( OP_Context &context,
90  const UT_IntArray &points,
91  UT_StringMap<float *> &averages );
92 
93  void setVisualization(bool onoff) override;
94 
95 protected:
96  void applyPermanentOverrides(OP_Context *ctx = 0);
97 
98  OP_ERROR cookMySop(OP_Context &context) override;
99 
100  void applyAndClearCurrentDelta();
101 
102  void clearAllDeltas(fpreal t);
103 
104  void updateParmsAfterClear();
105 
106  void buildOpDependencies() override;
107  void buildParmDependency( int parm_index ) override;
108  void handleOpDependency( int referenced_op_id,
109  const OP_Dependency &op_dep,
110  OP_InterestType interest_type,
111  bool &need_cook,
112  const char *old_fullpath,
113  const char *old_cwd,
114  const char *old_chan_name ) override;
115 
116  //
117  // I/O methods
118  //
119  OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags,
120  const char *path_prefix,
121  const UT_String &name_override = UT_String()
122  ) override;
123  bool load(UT_IStream &is, const char *extension,
124  const char *path=0) override;
125 
126 private: // methods
127  PRM_Parm & getParmByName( PRM_Name &name )
128  { return getParm( name.getToken() ); }
129  const PRM_Parm & getParmByName( PRM_Name &name ) const
130  { return getParm( name.getToken() ); }
131 
132  void fixParmCRegionPathsForRootChange(
133  const UT_String &old_full_root_path,
134  const UT_String &full_root_path );
135 
136  void setCRegionsParm( fpreal t,
137  const UT_ValArray<const char *> &cregions );
138 
139  OP_ERROR createCurrentDelta( OP_Context &context,
140  const GA_PointGroup *pt_group );
141 
142  int addCaptureRegion( UT_String &cregion_name );
143 
144  // parm callbacks
145  static void buildCregionMenu(
146  void *, PRM_Name *, int,
147  const PRM_SpareData *, const PRM_Parm * );
148  static int getCaptureRegionDetailData( void *user_data,
149  char *full_cregion_path,
150  char *rel_cregion_path,
151  GEO_CaptureBoneStorage &tube_data );
152 
153  // Get the selection group string:
154  void getSelString(UT_String &str)
155  { evalString(str, SOP_CAPTUREOVERRIDE_GRP_IDX, 0, 0.0f); }
156 
157  // Apply current delta to permanent overrides
158  static int applyStatic(void *, int idx,
159  fpreal t, const PRM_Template *);
160  // Respond to button press to clear all overrides
161  static int clearallStatic(void *, int idx,
162  fpreal t, const PRM_Template *);
163 
164  static int openSpreadsheetStatic(void *, int idx,
165  fpreal t, const PRM_Template *);
166 
167  void checkCaptureRegions();
168 
169  bool checkChangedSource(unsigned idx, OP_Context &context);
170 
171  void rollbackCurrentOverridesDelta();
172 
173  void ensureCaptureAttributesExist();
174 
175  // Undo/Redo
176  void undoOverrideDeltas(
177  GEO_CaptureOverrideDelta *delta);
178  void redoOverrideDeltas(
179  GEO_CaptureOverrideDelta *delta);
180  void undoClearOverrides(
181  SOP_UndoCaptureOverride *undo);
182  void redoClearOverrides(
183  SOP_UndoCaptureOverride *undo);
184 
185 private: // data
186  UT_String myNewOpLabel; // label for undos
187 
188  GEO_CaptureOverrideData *myPermanentOverrides;
189  GEO_CaptureOverrideDelta *myCurrentOverridesDelta;
190 
191  bool myCookedFlag; // have we cooked yet?
192  bool myApplyPermanentFlag;
193 
194  // Selection group
195  const GA_ElementGroup *myGroup;
196 
197  SOP_CaptureData myCaptureData;
198  UT_String myRootPath;
199  bool myUpdatedColors;
200  bool myForceUpdateColors;
201 
202  static PRM_ChoiceList theCregionMenu;
203  static int theCregionIndex;
204 };
205 
206 #endif // __SOP_CaptureOverride_h__
207 
virtual void setVisualization(bool)
Definition: SOP_Node.h:863
virtual bool updateParmsFlags()
GLbitfield flags
Definition: glcorearb.h:1596
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
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
Convenience class to store a bone capture region.
bool load(UT_IStream &is, const char *extension, const char *path=0) override
PRM_Parm & getParm(int i)
GLfloat f
Definition: glcorearb.h:1926
OP_InterestType
Definition: OP_DataTypes.h:45
void buildOpDependencies() override
void evalString(UT_String &val, int pi, int vi, fpreal t) const
GLuint const GLchar * name
Definition: glcorearb.h:786
#define SOP_CAPTUREOVERRIDE_GRP_IDX
virtual OP_ERROR cookInputGroups(OP_Context &context, int alone=0)
GLdouble t
Definition: glad.h:2397
fpreal64 fpreal
Definition: SYS_Types.h:277
#define SOP_API
Definition: SOP_API.h:10
virtual void buildParmDependency(int parm_index)
virtual OP_ERROR cookMySop(OP_Context &context)=0
OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *pathPrefix, const UT_String &name_override=UT_String()) override
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
const UT_String & getUndoLabel() const
const char * getToken() const
Definition: PRM_Name.h:79