HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TIL_ImageSource.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_ImageSource.h (TIL library, C++)
7  *
8  * COMMENTS:
9  * This is the base class for an image source (ie, COP for Houdini,
10  * or disk files for a standalone viewer).
11  */
12 
13 #ifndef TIL_IMAGESOURCE_H
14 #define TIL_IMAGESOURCE_H
15 
16 #include "TIL_API.h"
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_StringArray.h>
19 #include <UT/UT_ValArray.h>
20 #include <UT/UT_Color.h>
21 #include <PXL/PXL_Common.h>
22 #include <stdlib.h>
23 #include <limits>
24 
25 #define TIL_GLOBAL_TIME (std::numeric_limits<fpreal>::infinity())
26 
27 class UT_String;
28 class UT_StringHolder;
29 class UT_TokenString;
30 class UT_WorkBuffer;
31 class IMG_TileOptions;
32 
33 class TIL_Plane;
34 class TIL_Raster;
35 class TIL_Sequence;
36 class TIL_ColorCurves;
37 
38 class STY_StyleSheet;
39 class OP_Node;
40 
42 {
43  int myID;
44 
45  int myX0, myX1;
46  int myY0, myY1;
47 
50 };
51 
53 
55 {
56 public:
58 
59  void bumpRefCount(int i);
60 
61  void invalidate() { myValidFlag = false; }
62  bool isValid() const { return myValidFlag; }
63 
64  // global stuff... (not source specific).
65  virtual fpreal getGlobalTime() =0;
66  virtual fpreal getSampleRate() =0;
67  virtual fpreal getStartTime() =0;
68  virtual fpreal getEndTime() =0;
69 
70  // returns the image index (0 to length-1) or the frame (start to end)
71  // based on the current time.
72  int getImageIndexFromTime(fpreal t);
73  int getFrameFromTime(fpreal t);
74 
75  virtual int doesImageExist(int /*frame*/,
76  bool /*adjust*/ = true)
77  { return 1; }
78 
79  virtual int getActualFrame(int frame) { return frame; }
80  virtual void removeFrame(int /*frame*/) { }
81  virtual void addFrame(int /*frame*/) { }
82  virtual void removeSequence() {}
83  virtual bool canAddFrame() { return false; }
84 
85  virtual bool isNetwork() { return false; }
86 
87  // allows time mapping (mostly for disk files).
89  bool /*shift_only*/ = false,
90  const TIL_Sequence * /*ref*/ = 0)
91  { return t; }
92  virtual int getFrameShift(int fr,
93  bool /*shift_only*/ = false,
94  const TIL_Sequence * /*ref*/ =0)
95  { return fr; }
96 
97  // Allows you to remap a frame for information purposes (like the Houdini
98  // frame number when rendered to mplay).
99  virtual int getApparentFrame(int fr) { return fr; }
100 
101  // name of the source (cop name, disk file).
102  virtual const char *getName() = 0;
103  virtual void getFullName(UT_String &name) = 0;
104  virtual void getFrameName(int frame, UT_String &name);
105 
106  // ah, well.. whaddayathink
107  virtual int equals(const TIL_ImageSource *) = 0;
108 
109  // Called to open the source (return 0 on failure). if reset is set, all
110  // errors will be cleared.
111  virtual int open(short & /*key*/,
112  int /*reset*/ = 0,
113  fpreal /*t*/ = TIL_GLOBAL_TIME)
114  { return 0; }
115 
116  // called to close the source.
117  virtual void close(short /*key*/) { ; }
118 
119  // returns true if the res & data type are constant for the sequence.
120  virtual bool isConstantSequence() const { return false; }
121 
122  // return a completed TIL_Sequence structure.
123  virtual const TIL_Sequence *getSequence(fpreal t) = 0;
124 
125  // return an identifier that can be used to identify a single frame
126  // out of the source, unique across multiple sources.
127  virtual UT_TokenString *getID(fpreal t, int xres, int yres,
128  const TIL_Plane &plane,
129  int array_index) = 0;
130 
131  virtual void getImageBounds(const TIL_Plane &plane,
132  int array_index,
133  fpreal t, int xres, int yres,
134  int &x1, int &y1,
135  int &x2, int &y2);
136 
137  // Returns a list of regions currently being cooked
138  virtual void getCookRegions(TIL_CookRegionList &region) = 0;
139 
140  /// Returns true iff there is currently a priority circle active.
141  /// If there is, centrex, centrey, and radius are set to those of the circle.
142  virtual bool getPriorityCircle(float &centrex, float &centrey, float &radius) const
143  {
144  return false;
145  }
146 
147  // return an int that uniquely identifies the source.
148  virtual int getID() const = 0;
149 
150  // fill the TIL_Raster with the appropriate image (ie, cook it).
151  // return 0 on failure.
152  virtual int getImage(TIL_Raster *image,
153  fpreal t, int xres, int yres,
154  const TIL_Plane &plane,
155  int array_index,
156  int xstart, int ystart,
157  int xend, int yend, float gamma,
158  bool include_alpha = false,
159  bool is_interactive = false,
160  int fxres = 0, int fyres = 0) = 0;
161 
162  virtual void getInfo(UT_WorkBuffer &infotext);
163 
164  virtual void getComment(UT_String &comment, fpreal t);
165  virtual void setComment(const UT_String &comment, fpreal t);
166 
167  // There's duplicate information in the IMG_TileOptions class, we only use
168  // the Format and FormatOptions in the writing process.
169  virtual int writeImage(const char *filename,
170  const IMG_TileOptions *finfo,
171  const TIL_Sequence *, int step =1,
172  const char *uselut = 0,
173  float gamma = 1.0F,
174  void (*info)(void*, const char*)=0,
175  void *data=0,
176  bool suppress_summary_dialog=false,
177  bool adjust_color_space = true,
178  bool overwrite = false);
179 
180  virtual int writeImage(const char *filename,
181  const IMG_TileOptions *finfo,
182  int xres, int yres,
183  const char *color,
184  const char *alpha,
185  int start, int end, int step =1,
186  const char *uselut = 0,
187  float gamma = 1.0F,
188  void (*info)(void*, const char*)=0,
189  void *data =0,
190  bool suppress_summary_dialog=false,
191  bool adjust_color_space = true,
192  bool overwrite = false);
193 
194  virtual void writeImageComplete(int successcount,
195  int failcount,
196  const UT_String &failedfiles);
197 
198  // normally, once you're done with an image, it will stay cached if there's
199  // room. The parm is the frame index. Return false to have it deallocated
200  // immediately.
201  virtual bool isCachingNeeded(int ) const { return true; }
202 
203  // only really needed for COPs.
204  virtual size_t getVersion() { return 1; }
205  virtual int isFrameLocked(fpreal /*t*/) { return 0; }
206  virtual int isAnythingLocked() { return 0; }
207  virtual int isPlaneLocked(const TIL_Plane *,
208  fpreal /*t*/) { return 0; }
209  virtual const TIL_Plane *getPreviewPlane(int /*index*/) { return 0; }
210 
211  virtual void setMouseLocation(int mx, int my,
212  float radius = 64.0f);
213 
214  virtual void bumpVersion(bool ) { }
215  virtual bool isSlowOperation() const { return false; }
216 
217  virtual bool getColorCurves(const char *planename,
218  int array, fpreal t,
219  TIL_ColorCurves &curves,
220  UT_String &first,
221  bool allnodes, int comp=-1,
222  bool natural_range = true,
223  float start = 0.0f,
224  float end = 1.0f,
225  int evalpoints = 0);
226 
227  virtual bool allowUserSelection() const { return false; }
228 
229  virtual TIL_ImageSource *selectParentSource(int px, int py,
230  const char *planename,
231  int array_index);
232 
233  // Allow the source to have a callback invoked. The function should return
234  // true if a script is run
235  virtual bool hasPixelScript(int slot) const;
236  virtual bool runPixelScript(int px, int py, int slot);
237 
238  // Returns true if the image source is stereoscopic, ie, it can provide
239  // left / right images (as two separate planes).
240  virtual bool isStereoscopicSource(fpreal t) const;
241  virtual int getLeftPlaneIndex(fpreal t) const;
242  virtual const char *getLeftPlaneName(fpreal t) const;
243  virtual int getRightPlaneIndex(fpreal t) const;
244  virtual const char *getRightPlaneName(fpreal t) const;
245 
246  // NOTE: This level has nothing to destruct.
247  virtual int64 getMemoryUsage(bool inclusive) const = 0;
248 
249  virtual fpreal getRenderTime(int frame) const
250  { return -1.0; }
251 
252  virtual int64 getPeakMemUsage(int frame) const
253  { return 0; }
254 
256  { return false; }
257 
258  // Returns the style sheet json string at a given pixel.
259  // By default, there is none
260  virtual bool getStyleSheetJSON(int x, int y, UT_StringHolder& str)
261  { return false; }
262 
263  // Returns the style sheet object at a given pixel.
264  // By default there is none
265  virtual STY_StyleSheet* getStyleSheet(int x, int y)
266  { return NULL; }
267 
268  // Returns the material node at a given pixel
269  virtual OP_Node* getMaterialNode(int x, int y)
270  { return NULL; }
271 
272  // Indicates that an auto update is being performed
273  virtual void onAutoUpdate() {}
274 
275 protected:
276  virtual ~TIL_ImageSource();
277 
278 private:
279  TIL_ImageSource & operator=(const TIL_ImageSource &);
280 
281  int myRefCount;
282  bool myValidFlag;
283 };
284 
285 
286 // Convenience class for opening and closing a source.
288 {
289 public:
290  TIL_Access(TIL_ImageSource &source, int reset=0,
291  fpreal t = TIL_GLOBAL_TIME);
292  ~TIL_Access();
293 
294  bool isOpen() const { return myOpen; }
295 
296 private:
297  TIL_Access & operator=(const TIL_Access &);
298 
299  TIL_ImageSource &mySource;
300  short myAccessKey;
301  bool myOpen;
302 };
303 
304 #endif
virtual bool isConstantSequence() const
virtual STY_StyleSheet * getStyleSheet(int x, int y)
GLint first
Definition: glcorearb.h:404
virtual bool getPreferredViewingPlane(UT_WorkBuffer &buf) const
GLuint start
Definition: glcorearb.h:474
virtual int isAnythingLocked()
GLuint color
Definition: glcorearb.h:1260
virtual void removeSequence()
virtual int getApparentFrame(int fr)
virtual int isPlaneLocked(const TIL_Plane *, fpreal)
GLint y
Definition: glcorearb.h:102
virtual fpreal getFrameTime(fpreal t, bool=false, const TIL_Sequence *=0)
virtual void addFrame(int)
png_uint_32 i
Definition: png.h:2877
png_bytepp image
Definition: png.h:1849
UT_Array< TIL_CookRegion > TIL_CookRegionList
long long int64
Definition: SYS_Types.h:100
virtual bool allowUserSelection() const
bool isValid() const
GLfloat f
Definition: glcorearb.h:1925
virtual const TIL_Plane * getPreviewPlane(int)
virtual bool getPriorityCircle(float &centrex, float &centrey, float &radius) const
#define TIL_GLOBAL_TIME
virtual fpreal getRenderTime(int frame) const
virtual int doesImageExist(int, bool=true)
GLuint GLuint end
Definition: glcorearb.h:474
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual int getFrameShift(int fr, bool=false, const TIL_Sequence *=0)
virtual void close(short)
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:111
virtual void onAutoUpdate()
virtual int isFrameLocked(fpreal)
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual int getActualFrame(int frame)
virtual bool isSlowOperation() const
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
IFDmantra py
Definition: HDK_Image.dox:266
double fpreal
Definition: SYS_Types.h:263
cl_int getInfo(Func f, cl_uint name, T *param)
Definition: cl.hpp:1028
virtual OP_Node * getMaterialNode(int x, int y)
GLint GLenum GLint x
Definition: glcorearb.h:408
virtual size_t getVersion()
bool isOpen() const
virtual int64 getPeakMemUsage(int frame) const
virtual bool canAddFrame()
virtual void bumpVersion(bool)
virtual bool isNetwork()
virtual int open(short &, int=0, fpreal=TIL_GLOBAL_TIME)
virtual void removeFrame(int)
#define TIL_API
Definition: TIL_API.h:10
virtual bool getStyleSheetJSON(int x, int y, UT_StringHolder &str)
virtual bool isCachingNeeded(int) const