HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_CopResolver.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: TIL_CopResolver.h ( TIL Library, C++)
7  *
8  * COMMENTS:
9  * Class to get a pointer to a COPs raster. This class is used by the
10  * texture mapping code to resolve names of the form:
11  *
12  * op:/comp/cop2net/cop{C,A}[frame]
13  * file:filename{xres,yres}
14  *
15  * The frame is optional. Sub-classes don't need to worry about parsing
16  * out the [frame], this is all handled by the static methods.
17  */
18 
19 #ifndef __TIL_CopResolver__
20 #define __TIL_CopResolver__
21 
22 #include "TIL_API.h"
23 #include "TIL_Defines.h"
24 #include <IMG/IMG_FileTypes.h>
25 #include <UT/UT_NonCopyable.h>
26 #include <UT/UT_ValArray.h>
27 #include <UT/UT_WorkBuffer.h>
28 #include <UT/UT_SharedPtr.h>
29 #include <UT/UT_NonCopyable.h>
30 #include <stddef.h>
31 
32 
33 #define TIL_DEFAULT_COLOR_PLANE "(Default Color)"
34 #define TIL_DEFAULT_ALPHA_PLANE "(Default Alpha)"
35 #define TIL_NO_PLANE "(None)"
36 
37 class TIL_Raster;
38 class TIL_Sequence;
39 class TIL_ImageSource;
40 class UT_String;
41 class IMX_Layer;
42 
44 {
45 public:
47  virtual ~TIL_CopResolver();
48 
50 
51  /// Class to push/pop the enable state
54  {
55  public:
56  autoEnableCache(bool enable)
57  {
58  myOldEnabled = TIL_CopResolver::enableThreadResolverCache(enable);
59  }
61  {
63  }
64  private:
65  bool myOldEnabled;
66  };
67 
68  /// Class to push/pop the evaluate time
71  {
72  public:
74  {
75  if (getResolver())
76  {
77  myOldSeconds = getResolver()->getGlobalTime();
78  getResolver()->setGlobalTime(time);
79  }
80  }
82  {
83  if (getResolver())
84  {
85  getResolver()->setGlobalTime(myOldSeconds);
86  }
87  }
88 
89  private:
90  fpreal myOldSeconds;
91  };
92 
93  static void setResolver(TIL_CopResolver *resolver);
94  static TIL_CopResolver *getResolver();
95 
96  /// Turns on resolver cache for THIS thread. This allows in process
97  /// renders to only hit op: once per render.
98  /// Returns old value.
99  static bool enableThreadResolverCache(bool enable);
100 
101  /// Returns true if this thread has the resolver enabled
102  static bool threadResolverCacheEnabled();
103 
104  /// Provides a watermark for the resolver cache, bumped on every
105  /// clear. So if you acquired with a similar water mark you don't
106  /// need to check for dirty.
107  static exint threadResolverCacheWatermark();
108 
109  /// Clears any out of date resolver cache, ie, where cop version
110  /// doesn't match the stashed version. The force_full_clear flag can be
111  /// set to true to clear everything out of the cache. This is necessary
112  /// if a time change happens and a time dependent COP texture is in the
113  /// cache. The "version" will be unchanged, but we need to clear anyway.
114  static void clearResolverCache(bool force_full_clear);
115 
116  /// Gets node ids of any COPs with textures in the resolver cache.
117  static void getResolverCacheNodeIds(UT_IntArray &ids);
118 
119  // Get an TIL_Raster associated with the COP in the path specified
120  // YOU MUST CALL doneWithRaster or returnRaster when done!
121  // Do not free it, and do not dangle it.
122  static TIL_Raster *getRaster(const char *fullpath,
123  int &opid,
124  bool *specific_frame = nullptr);
125  static fpreal getRasterTime(int opid);
126  static size_t getRasterVersion(int opid);
127 
128  static fpreal getTimeFromFrame(fpreal frame);
129 
130  /// Tell the resolver we're done with the raster.
131  /// Some resolvers will delete rasters, others will hold onto them. If the
132  /// raster actually dirties/deletes the raster, @c doneWithRaster() will
133  /// return true.
134  static bool doneWithRaster(const TIL_Raster *r);
135 
136  /// Returns shared IMX_Layer with COW semantics. Only works
137  /// for copernicus, will need getRaster for Images or COP2.
138  static UT_SharedPtr<const IMX_Layer> getLayer(const char *fullpath,
139  int &opid,
140  bool *specific_frame = nullptr);
141 
142  // Returns 1 if the frame is specified in the filename. The id will be -1
143  // if there is no such path.
144  static int getIdFrame(const char *fullpath, int &id,
145  fpreal &frame);
146  static void splitFile(const char *fullpath,
147  UT_String &name,
148  int &xres,int &yres,
149  float &quality);
150 
151  // These split net/node methods are now out of style with networks
152  // within networks. Now you should specify full, absolute, paths.
153  static int getNodeId(const char *net, const char *node);
154  static void getNodeRes(const char *net, const char *node,
155  int &xres, int &yres);
156 
157  static int getNodeId(const char *fullpath);
158  static void getNodeRes(const char *fullpath,
159  int &xres, int &yres);
160 
161  static void getFileRes(const char *file,
162  int &xres, int &yres);
163 
164  static int splitPath(const char *cpath, int &id,
165  fpreal &frame,
166  UT_WorkBuffer &color, int &cindex,
167  UT_WorkBuffer &alpha, int &aindex,
168  int &xres, int &yres);
169 
170  // builds menus for plane selection (COPs2 only).
171  static void buildColorMenu(const char *net,
172  const char *node,
173  UT_ValArray<char *> &items);
174 
175  static void buildAlphaMenu(const char *net,
176  const char *node,
177  UT_ValArray<char *> &items);
178 
179  static bool canResolve(const char *fullpath);
180 
181  // These methods should really only be used inside the TIL_CopResolver
182  // class. They shouldn't be called directly.
183  virtual int resolveId(const char *fullpath) = 0;
184 
185  virtual TIL_Raster *resolveRaster(int id) = 0;
186  virtual TIL_Raster *resolveRasterFrame(int id, fpreal frame,
187  int xres=0, int yres=0) = 0;
188  virtual TIL_Raster *resolveRasterPlane(int id, fpreal frame,
189  const char *color, int cindex,
190  const char *alpha, int aindex,
191  int xres=0, int yres = 0,
192  TIL_DataFormat f =
194 
195  virtual UT_SharedPtr<const IMX_Layer> resolveLayer(int id) = 0;
196  virtual UT_SharedPtr<const IMX_Layer> resolveLayerFrame(int id, fpreal frame) = 0;
197  virtual UT_SharedPtr<const IMX_Layer> resolveLayerPlane(int id, fpreal frame,
198  const char *color) = 0;
199  // Returns whether or not the resolver knows how to handle this path.
200  virtual bool resolveIsPossible(const char *fullpath) = 0;
201 
202  /// You gain ownership of a FileRaster and must delete it:
203  virtual TIL_Raster *getFileRaster(const char *file,
205  int xres = 0, int yres = 0);
206  /// You do not gain ownershipo of a node raster, and must call
207  /// returnRaster or doneWithRaster on it.
208  /// @param fullpath The path to the COP node, eg "op:/path/to/cop"
209  /// @param cmenu The name of the color plane, eg "C" or
210  /// TIL_DEFAULT_COLOR_PLANE.
211  /// @param amenu The name of the alpha plane, eg "A" or
212  /// TIL_DEFAULT_ALPHA_PLANE, or TIL_NO_PLANE.
213  /// @param override_frame If true, the current time frame is used
214  /// for cooking the COP node to obtain the raster
215  /// (ie, the following 'frame' parameter is ignored).
216  /// @param frame Frame at which to cook the COP node to obtain the raster
217  /// @param f Desired data format (bit precision) of the returned
218  /// raster.
219  /// @param xres Width that the raster will be scaled to. If set to 0,
220  /// will use the node's default width.
221  /// @param yres Height that the raster will be scaled to. If set to 0,
222  /// will use the node's default height.
223  virtual TIL_Raster *getNodeRaster(const char *fullpath,
224  const char *cmenu, const char *amenu,
225  bool override_frame = false,
226  fpreal frame = 1.0,
227  TIL_DataFormat f =
229  int xres = 0, int yres = 0);
230 
231  virtual void getRes(int id, int &xres, int &yres);
232 
233  virtual TIL_Sequence *getSequence(int id);
234 
235  /// This cooks a bunch of planes simulataneously, and adds the created
236  /// rasters to 'new_rasters'. You are responsible for deleting them.
237  virtual bool resolveRasters(int id,
238  const UT_StringArray &plane_names,
239  fpreal t,
240  UT_ValArray<TIL_Raster *> &new_rasters,
242 
243 
244  virtual void buildPlaneMenu(const char *net, const char *node,
245  UT_ValArray<char *> &items);
246 
247  virtual TIL_ImageSource *resolveImageSource(int id);
248 
249  /// Caller is finished with the raster for now, so delete memory if
250  /// possible. Returns true if the raster is no longer valid, but false if
251  /// the raster hasn't been touched (and is still valid). This is
252  /// implementation dependent.
253  virtual bool returnRaster(const TIL_Raster *raster);
254 
255  // If the id returned is really an OP_Node, then this will return 1.
256  virtual int isOpBased();
257 
258  virtual fpreal getTimeForRaster(int id);
259  virtual size_t getVersionForRaster(int id);
260 
261 protected:
262  // Returns 1 if the frame is defined, 0 otherwise. It's possible that
263  // the name returned may be a reference to the path. Please harden if
264  // you need to keep it around.
265  int splitPath(const char *fullpath,
266  UT_String &name, fpreal &frame);
267 
268  virtual fpreal timeFromFrame(fpreal frame);
269  virtual fpreal getGlobalTime();
270  virtual void setGlobalTime(fpreal time);
271 };
272 
273 #endif
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
GT_API const UT_StringHolder time
int64 exint
Definition: SYS_Types.h:125
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
#define TIL_DataFormat
Definition: TIL_Defines.h:64
#define TILE_MAX_DATA_FORMAT
Definition: TIL_Defines.h:70
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
static bool enableThreadResolverCache(bool enable)
IMG_DataType
Definition: IMG_FileTypes.h:17
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
HUSD_API const char * raster()
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble t
Definition: glad.h:2397
Class to push/pop the enable state.
Class to push/pop the evaluate time.
GLuint color
Definition: glcorearb.h:1261
fpreal64 fpreal
Definition: SYS_Types.h:278
GLboolean r
Definition: glcorearb.h:1222
#define TIL_API
Definition: TIL_API.h:10
GLuint * ids
Definition: glcorearb.h:652