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 <stddef.h>
30 
31 
32 #define TIL_DEFAULT_COLOR_PLANE "(Default Color)"
33 #define TIL_DEFAULT_ALPHA_PLANE "(Default Alpha)"
34 #define TIL_NO_PLANE "(None)"
35 
36 class TIL_Raster;
37 class TIL_Sequence;
38 class TIL_ImageSource;
39 class UT_String;
40 class IMX_Layer;
41 
43 {
44 public:
46  virtual ~TIL_CopResolver();
47 
49 
51  {
52 public:
54  {
55  if (getResolver())
56  {
57  myOldSeconds = getResolver()->getGlobalTime();
58  getResolver()->setGlobalTime(time);
59  }
60  }
62  {
63  if (getResolver())
64  {
65  getResolver()->setGlobalTime(myOldSeconds);
66  }
67  }
68 
69 private:
70  fpreal myOldSeconds;
71  };
72 
73  static void setResolver(TIL_CopResolver *resolver);
74  static TIL_CopResolver *getResolver();
75 
76  /// Turns on resolver cache for THIS thread. This allows in process
77  /// renders to only hit op: once per render.
78  /// Returns old value.
79  static bool enableThreadResolverCache(bool enable);
80 
81  /// Returns true if this thread has the resolver enabled
82  static bool threadResolverCacheEnabled();
83 
84  /// Provides a watermark for the resolver cache, bumped on every
85  /// clear. So if you acquired with a similar water mark you don't
86  /// need to check for dirty.
87  static exint threadResolverCacheWatermark();
88 
89  /// Clears any out of date resolver cache, ie, where cop version
90  /// doesn't match the stashed version. The force_full_clear flag can be
91  /// set to true to clear everything out of the cache. This is necessary
92  /// if a time change happens and a time dependent COP texture is in the
93  /// cache. The "version" will be unchanged, but we need to clear anyway.
94  static void clearResolverCache(bool force_full_clear);
95 
96  /// Gets node ids of any COPs with textures in the resolver cache.
97  static void getResolverCacheNodeIds(UT_IntArray &ids);
98 
99  // Get an TIL_Raster associated with the COP in the path specified
100  // YOU MUST CALL doneWithRaster or returnRaster when done!
101  // Do not free it, and do not dangle it.
102  static TIL_Raster *getRaster(const char *fullpath,
103  int &opid,
104  bool *specific_frame = nullptr);
105  static fpreal getRasterTime(int opid);
106  static size_t getRasterVersion(int opid);
107 
108  static fpreal getTimeFromFrame(fpreal frame);
109 
110  /// Tell the resolver we're done with the raster.
111  /// Some resolvers will delete rasters, others will hold onto them. If the
112  /// raster actually dirties/deletes the raster, @c doneWithRaster() will
113  /// return true.
114  static bool doneWithRaster(const TIL_Raster *r);
115 
116  /// Returns shared IMX_Layer with COW semantics. Only works
117  /// for copernicus, will need getRaster for Images or COP2.
118  static UT_SharedPtr<const IMX_Layer> getLayer(const char *fullpath,
119  int &opid,
120  bool *specific_frame = nullptr);
121 
122  // Returns 1 if the frame is specified in the filename. The id will be -1
123  // if there is no such path.
124  static int getIdFrame(const char *fullpath, int &id,
125  fpreal &frame);
126  static void splitFile(const char *fullpath,
127  UT_String &name,
128  int &xres,int &yres,
129  float &quality);
130 
131  // These split net/node methods are now out of style with networks
132  // within networks. Now you should specify full, absolute, paths.
133  static int getNodeId(const char *net, const char *node);
134  static void getNodeRes(const char *net, const char *node,
135  int &xres, int &yres);
136 
137  static int getNodeId(const char *fullpath);
138  static void getNodeRes(const char *fullpath,
139  int &xres, int &yres);
140 
141  static void getFileRes(const char *file,
142  int &xres, int &yres);
143 
144  static int splitPath(const char *cpath, int &id,
145  fpreal &frame,
146  UT_WorkBuffer &color, int &cindex,
147  UT_WorkBuffer &alpha, int &aindex,
148  int &xres, int &yres);
149 
150  // builds menus for plane selection (COPs2 only).
151  static void buildColorMenu(const char *net,
152  const char *node,
153  UT_ValArray<char *> &items);
154 
155  static void buildAlphaMenu(const char *net,
156  const char *node,
157  UT_ValArray<char *> &items);
158 
159  static bool canResolve(const char *fullpath);
160 
161  // These methods should really only be used inside the TIL_CopResolver
162  // class. They shouldn't be called directly.
163  virtual int resolveId(const char *fullpath) = 0;
164 
165  virtual TIL_Raster *resolveRaster(int id) = 0;
166  virtual TIL_Raster *resolveRasterFrame(int id, fpreal frame,
167  int xres=0, int yres=0) = 0;
168  virtual TIL_Raster *resolveRasterPlane(int id, fpreal frame,
169  const char *color, int cindex,
170  const char *alpha, int aindex,
171  int xres=0, int yres = 0,
172  TIL_DataFormat f =
174 
175  virtual UT_SharedPtr<const IMX_Layer> resolveLayer(int id) = 0;
176  virtual UT_SharedPtr<const IMX_Layer> resolveLayerFrame(int id, fpreal frame) = 0;
177  virtual UT_SharedPtr<const IMX_Layer> resolveLayerPlane(int id, fpreal frame,
178  const char *color) = 0;
179  // Returns whether or not the resolver knows how to handle this path.
180  virtual bool resolveIsPossible(const char *fullpath) = 0;
181 
182  /// You gain ownership of a FileRaster and must delete it:
183  virtual TIL_Raster *getFileRaster(const char *file,
185  int xres = 0, int yres = 0);
186  /// You do not gain ownershipo of a node raster, and must call
187  /// returnRaster or doneWithRaster on it.
188  virtual TIL_Raster *getNodeRaster(const char *fullpath,
189  const char *cmenu, const char *amenu,
190  bool override_frame = false,
191  fpreal frame = 1.0,
192  TIL_DataFormat f =
194 
195  virtual void getRes(int id, int &xres, int &yres);
196 
197  virtual TIL_Sequence *getSequence(int id);
198 
199  /// This cooks a bunch of planes simulataneously, and adds the created
200  /// rasters to 'new_rasters'. You are responsible for deleting them.
201  virtual bool resolveRasters(int id,
202  const UT_StringArray &plane_names,
203  fpreal t,
204  UT_ValArray<TIL_Raster *> &new_rasters,
206 
207 
208  virtual void buildPlaneMenu(const char *net, const char *node,
209  UT_ValArray<char *> &items);
210 
211  virtual TIL_ImageSource *resolveImageSource(int id);
212 
213  /// Caller is finished with the raster for now, so delete memory if
214  /// possible. Returns true if the raster is no longer valid, but false if
215  /// the raster hasn't been touched (and is still valid). This is
216  /// implementation dependent.
217  virtual bool returnRaster(const TIL_Raster *raster);
218 
219  // If the id returned is really an OP_Node, then this will return 1.
220  virtual int isOpBased();
221 
222  virtual fpreal getTimeForRaster(int id);
223  virtual size_t getVersionForRaster(int id);
224 
225 protected:
226  // Returns 1 if the frame is defined, 0 otherwise. It's possible that
227  // the name returned may be a reference to the path. Please harden if
228  // you need to keep it around.
229  int splitPath(const char *fullpath,
230  UT_String &name, fpreal &frame);
231 
232  virtual fpreal timeFromFrame(fpreal frame);
233  virtual fpreal getGlobalTime();
234  virtual void setGlobalTime(fpreal time);
235 };
236 
237 #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:623
GT_API const UT_StringHolder time
int64 exint
Definition: SYS_Types.h:125
GLfloat f
Definition: glcorearb.h:1926
#define TIL_DataFormat
Definition: TIL_Defines.h:65
#define TILE_MAX_DATA_FORMAT
Definition: TIL_Defines.h:71
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
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
GLuint color
Definition: glcorearb.h:1261
fpreal64 fpreal
Definition: SYS_Types.h:277
GLboolean r
Definition: glcorearb.h:1222
type
Definition: core.h:1059
#define TIL_API
Definition: TIL_API.h:10
GLuint * ids
Definition: glcorearb.h:652