HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_Sequence.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_Sequence.h (Tile Image Library, C++)
7  *
8  * COMMENTS:
9  * Defines the information for a series of images.
10  */
11 #ifndef TIL_SEQUENCE_H
12 #define TIL_SEQUENCE_H
13 
14 #include "TIL_API.h"
15 #include <iosfwd>
16 #include <UT/UT_Options.h>
17 #include <UT/UT_SmallObject.h>
18 #include <UT/UT_ValArray.h>
19 #include <UT/UT_String.h>
20 #include <UT/UT_Vector2.h>
21 #include <UT/UT_Rect.h>
22 
23 #include "TIL_Defines.h"
24 
25 // image rounding
26 #define SEQUENCE_NEAREST 0
27 #define SEQUENCE_PREVIOUS 1
28 #define SEQUENCE_NEXT 2
29 
30 class UT_WorkBuffer;
31 class UT_JSONWriter;
32 class UT_InfoTree;
33 class TIL_Plane;
34 class IMG_Stat;
35 
36 /* additional data about the image space that a COP operator originally
37  * had this image in.
38  */
40 {
41  bool valid = false;
44  UT_Vector2D imageToPixelScale, imageToPixelTranslate;
45 
47  { return v * imageToPixelScale + imageToPixelTranslate; }
48 
50  { return (v - imageToPixelTranslate) / imageToPixelScale; }
51 
53  {
54  UT_Vector2D pixel_coord = imageToPixel(v);
55 
56  return UT_Vector2D(pixel_coord.x() - dataWindow.x() + displayWindow.x(),
57  pixel_coord.y() - dataWindow.y() + displayWindow.y());
58  }
59 
61  {
62  UT_Vector2D coord = UT_Vector2D(v.x() + dataWindow.x() - displayWindow.x(),
63  v.y() + dataWindow.y() - displayWindow.y());
64 
65  return pixelToImage(coord);
66  }
67 };
68 
70  public UT_SmallObject<TIL_Sequence,
71  UT_SMALLOBJECT_CLEANPAGES_OFF, 196,
72  UT_SMALLOBJECT_THREADSAFE_ON>
73 
74 {
75 public:
76  TIL_Sequence();
77  TIL_Sequence(const TIL_Sequence &);
78 
79  ~TIL_Sequence();
80 
81  int64 getMemoryUsage(bool inclusive) const;
82 
83  void reset();
84  bool isValid() const { return myValidFlag; }
85  void setValid(bool valid) { myValidFlag = valid; }
86 
87  // copies everything.
89 
90  bool operator==(const TIL_Sequence &) const;
91 
92  bool matches(const TIL_Sequence &other_seq,
93  bool metdata_tool = true) const;
94 
95  void copyFrom(const IMG_Stat &stat);
96  void copyTo(IMG_Stat &stat) const;
97 
98  // copies everything but the plane information.
99  void copyAttributes(const TIL_Sequence &);
100 
101  void getInfoText(UT_WorkBuffer &info,
102  bool timedep = true,
103  bool mark_unscoped = false) const;
104  void getInfoTree(UT_InfoTree &tree,
105  bool timeDep) const;
106 
107  // querying/setting
108 
109  bool isSingleImage() const { return mySingleImage;}
110  void setSingleImage(bool on) { mySingleImage = on; }
111 
112  double getFrameRate() const { return myRate; }
113  void setFrameRate(double rate) { myRate = rate; }
114 
115  exint getLength() const { return myLength; }
116  void setLength(exint n) { myLength = n; }
117 
118  double getStart() const { return myStart; }
119  void setStart(double start) { myStart = start; }
120 
121  double getEnd() const { return myStart+myLength-1; }
122 
123  double getStartTime() const { return (myStart-1) / myRate; }
124  double getEndTime() const
125  { return (myStart + myLength -2) / myRate; }
126 
127  // 'Res' is the visible resolution of the image. 'Size' is the actual
128  // size of the image, which is equal to or greater than the res.
129  void getRes(int &x,int &y) const
130  { x = myXRes; y = myYRes; }
131  int getXres() const { return myXRes; }
132  int getYres() const { return myYRes; }
133 
134  void setRes(int x, int y);
135 
136  void setAspectRatio(float aspect)
137  { myAspect = (aspect > 0.0f) ? aspect : 1.0f; }
138  float getAspectRatio() const { return myAspect; }
139  float getVAspectRatio() const
140  { return (getInterlace()==INTERLACE_HALF) ? 2.0f:1.0f; }
141 
143  { return myRenderTime; }
145  { myRenderTime = t; }
147  { return myRenderMemory; }
149  { myRenderMemory = mem; }
150 
152  { b = myPreExtend; a = myPostExtend; }
153  void getTemporalHold(int &before, int &after) const
154  { before = myPreHold; after = myPostHold; }
155 
157  { myPreExtend = before; myPostExtend = after; }
158  void setTemporalHold(int before, int after)
159  { myPreHold = before; myPostHold = after; }
160 
161  // utility functions
162 
163  // These return the actual image index, from 0 to N-1
164  exint getImageIndex(double t, int clamp_range = 1,
165  int round_off = SEQUENCE_NEAREST) const;
166  double getImageTime(double t, int clamp_range =1,
167  int round_off = SEQUENCE_NEAREST) const;
168 
169  // These return the frame index for interlaced frames (imageindex/2)
170  exint getFrameIndex(double t, int clamp_range = 1,
171  int round_off = SEQUENCE_NEAREST) const;
172  double getFrameTime(double t,int clamp_range =1,
173  int round_off = SEQUENCE_NEAREST) const;
174 
175  // returns the time of image at image_index (in the range 0 - length-1)
176  double getIndexTime(exint image_index) const;
177 
178  exint checkIndexBounds(exint image_index) const;
179 
180  // plane management
181  int getNumPlanes() const { return myPlanes.entries(); }
182 
183  // If reorder is true, then addPlane can re-order the plane and the
184  // caller cannot assume that we will append the plane to the end
185  TIL_Plane * addPlane(const char *name, TIL_DataFormat format,
186  const char *vn1 = 0,
187  const char *vn2 = 0,
188  const char *vn3 = 0,
189  const char *vn4 = 0,
190  bool reorder=false);
191  TIL_Plane * addPlane(const TIL_Plane *plane,
192  bool reorder=false);
193 
194  // removes and delete a plane.
195  void removePlane(int index);
196  void removePlane(const char *name);
197 
198  void clearAllPlanes();
199 
200  // plane accessor functions.
201  TIL_Plane * getPlane(int index);
202  const TIL_Plane * getPlane(int index) const;
203 
204  TIL_Plane * getPlane(const char *name);
205  const TIL_Plane * getPlane(const char *name) const;
206 
207  TIL_Plane * getPlaneWithElement(const char *elem_name);
208  const TIL_Plane * getPlaneWithElement(const char *elem_name) const;
209 
210  int getPlaneByName(const char *name) const;
211 
212  // Interlacing
213  void setInterlace(TIL_Interlace i, TIL_Dominance d);
214  TIL_Interlace getInterlace() const { return myInterlace; }
215  TIL_Dominance getFieldDominance() const { return myDominance; }
216 
217  void print(std::ostream &os) const;
218  void dump() const;
219  void dump(UT_JSONWriter &w) const;
220 
221  void bumpColorAlphaToFront();
222 
223  // metadata support
224  UT_Options &metaData() { return myMetaData; }
225  const UT_Options &metaData() const { return myMetaData; }
226 
227  void clearMetaData() { myMetaData.clear(); }
228 
229  void setHandleBounds(const UT_Vector2D& bl, const UT_Vector2D& tr)
230  {
231  myHandleBoundsLB = bl;
232  myHandleBoundsRT = tr;
233  }
235  {
236  return myHandleBoundsLB;
237  }
239  {
240  return myHandleBoundsRT;
241  }
242 
243  void setImageSpaceData(const TIL_SequenceImageSpaceData& imageSpaceData)
244  {
245  myImageSpaceData = imageSpaceData;
246  }
247 
249  {
250  return myImageSpaceData;
251  }
252 
253 private:
254  void makeUnique(UT_String &name);
255 
256  unsigned myValidFlag :1,
257  mySingleImage : 1;
258 
259  // sequence rate, start & length
260  exint myLength;
261  double myStart;
262  double myRate;
263 
264  // image resolution.
265  int myXRes;
266  int myYRes;
267  float myAspect;
268 
269  UT_Vector2D myHandleBoundsLB, myHandleBoundsRT;
270 
271  // Possible information about the original image space
272  TIL_SequenceImageSpaceData myImageSpaceData;
273 
274  // Temporal extend conditions
275  TIL_Extend myPreExtend;
276  TIL_Extend myPostExtend;
277 
278  int myPreHold;
279  int myPostHold;
280 
281  // sequence planes (r,g,b, etc)
282  UT_ValArray<TIL_Plane *> myPlanes;
283 
284  TIL_Interlace myInterlace;
285  TIL_Dominance myDominance;
286 
287  UT_Options myMetaData;
288 
289  // TODO: Move these into a generic metadata structure
290  fpreal myRenderTime;
291  int64 myRenderMemory;
292 };
293 
294 #endif
void setRenderMemory(int64 mem)
Definition: TIL_Sequence.h:148
TIL_Dominance getFieldDominance() const
Definition: TIL_Sequence.h:215
exint getLength() const
Definition: TIL_Sequence.h:115
void setFrameRate(double rate)
Definition: TIL_Sequence.h:113
const GLdouble * v
Definition: glcorearb.h:837
void setTemporalExtend(TIL_Extend before, TIL_Extend after)
Definition: TIL_Sequence.h:156
void setStart(double start)
Definition: TIL_Sequence.h:119
UT_Vector2T< fpreal64 > UT_Vector2D
void setSingleImage(bool on)
Definition: TIL_Sequence.h:110
GLuint start
Definition: glcorearb.h:475
void setTemporalHold(int before, int after)
Definition: TIL_Sequence.h:158
void clearMetaData()
Definition: TIL_Sequence.h:227
const UT_Vector2D & handleBoundsLB() const
Definition: TIL_Sequence.h:234
int64 exint
Definition: SYS_Types.h:125
TIL_Interlace
Definition: TIL_Defines.h:84
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
UT_Vector2D imageToPixelTranslate
Definition: TIL_Sequence.h:44
void getRes(int &x, int &y) const
Definition: TIL_Sequence.h:129
UT_Vector2D imageToDataWindowPixel(const UT_Vector2D &v) const
Definition: TIL_Sequence.h:52
GLint y
Definition: glcorearb.h:103
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
bool isSingleImage() const
Definition: TIL_Sequence.h:109
UT_Vector2D imageToPixel(const UT_Vector2D &v) const
Definition: TIL_Sequence.h:46
UT_Vector2D pixelToImage(const UT_Vector2D &v) const
Definition: TIL_Sequence.h:49
double getStartTime() const
Definition: TIL_Sequence.h:123
const UT_Options & metaData() const
Definition: TIL_Sequence.h:225
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector2.h:426
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
fpreal getRenderTime() const
Definition: TIL_Sequence.h:142
GLdouble n
Definition: glcorearb.h:2008
void setLength(exint n)
Definition: TIL_Sequence.h:116
GLfloat f
Definition: glcorearb.h:1926
#define TIL_DataFormat
Definition: TIL_Defines.h:64
GLboolean reset
Definition: glad.h:5138
TIL_Interlace getInterlace() const
Definition: TIL_Sequence.h:214
UT_Vector2D dataWindowPixelToImage(const UT_Vector2D &v) const
Definition: TIL_Sequence.h:60
double getFrameRate() const
Definition: TIL_Sequence.h:112
int getXres() const
Definition: TIL_Sequence.h:131
#define SEQUENCE_NEAREST
Definition: TIL_Sequence.h:26
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
double getEndTime() const
Definition: TIL_Sequence.h:124
void getTemporalExtend(TIL_Extend &b, TIL_Extend &a) const
Definition: TIL_Sequence.h:151
TIL_Dominance
Definition: TIL_Defines.h:92
long long int64
Definition: SYS_Types.h:116
float getAspectRatio() const
Definition: TIL_Sequence.h:138
const TIL_SequenceImageSpaceData & getImageSpaceData() const
Definition: TIL_Sequence.h:248
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
GLdouble t
Definition: glad.h:2397
double getEnd() const
Definition: TIL_Sequence.h:121
double getStart() const
Definition: TIL_Sequence.h:118
A map of string to various well defined value types.
Definition: UT_Options.h:87
fpreal64 fpreal
Definition: SYS_Types.h:283
const UT_Vector2D & handleBoundsRT() const
Definition: TIL_Sequence.h:238
LeafData & operator=(const LeafData &)=delete
GLuint index
Definition: glcorearb.h:786
void setAspectRatio(float aspect)
Definition: TIL_Sequence.h:136
int64 getRenderMemory() const
Definition: TIL_Sequence.h:146
Contains the details of a specific image file, used by IMG_File. This class contains all the high-lev...
Definition: IMG_Stat.h:38
void setValid(bool valid)
Definition: TIL_Sequence.h:85
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void setImageSpaceData(const TIL_SequenceImageSpaceData &imageSpaceData)
Definition: TIL_Sequence.h:243
bool isValid() const
Definition: TIL_Sequence.h:84
void getTemporalHold(int &before, int &after) const
Definition: TIL_Sequence.h:153
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2903
void setRenderTime(fpreal t)
Definition: TIL_Sequence.h:144
#define TIL_API
Definition: TIL_API.h:10
int getYres() const
Definition: TIL_Sequence.h:132
int getNumPlanes() const
Definition: TIL_Sequence.h:181
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector2.h:428
UT_Options & metaData()
Definition: TIL_Sequence.h:224
float getVAspectRatio() const
Definition: TIL_Sequence.h:139
TIL_Extend
Definition: TIL_Defines.h:102
void setHandleBounds(const UT_Vector2D &bl, const UT_Vector2D &tr)
Definition: TIL_Sequence.h:229