HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_Region.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_Region.h (Tile Image Library, C++)
7  *
8  * COMMENTS:
9  * Handles arbitrary sized regions of planes, for algorithms that
10  * require more information than just a tile.
11  */
12 #ifndef TIL_REGION_H
13 #define TIL_REGION_H
14 
15 #include "TIL_API.h"
16 #include "TIL_Defines.h"
17 
18 #include <UT/UT_SmallObject.h>
19 
20 class TIL_Plane;
21 class TIL_Tile;
22 class TIL_TileList;
23 
25 {
26  TIL_BLACK = 0,
29  TIL_HOLD_TOP = 0x4,
31  TIL_HOLD = 0xF
32 };
33 
35  : public UT_SmallObject<TIL_Region,
36  UT_SMALLOBJECT_CLEANPAGES_OFF, 32,
37  UT_SMALLOBJECT_THREADSAFE_ON, 1024>
38 {
39 public:
40  // Do NOT derive classes from this method, or add virtual functions.
41 
42  // region allocation routines.
43  static TIL_Region *allocRegion();
44  static void freeRegion(TIL_Region *&freeme);
45 
46 
47  void init(const TIL_Plane *parent, int input_index,
48  int array_index, float time, int xres, int yres,
49  int x1, int y1, int x2, int y2,
50  int bx1, int by1, int bx2, int by2,
52  int share_count = 1, int nid = 0,
53  bool output = false, int xpad = 0);
54 
55  void reset();
56 
57  // sets the image data to zero. Does not set the constant flags.
58  void clear();
59 
60  int getID() const { return myID; }
61  int getNodeID() const { return myNodeID; }
62 
63  // call to init and destroy (regions are ref-counted). If you supply your
64  // own memory regions, pass the pointers (you are responsible for freeing
65  // them, unlike the automatically alloced memory which is freed for you).
66  int open(void *regionlist[PLANE_MAX_VECTOR_SIZE] = 0);
67  int close();
68 
69  // info accessors
70 
71  // identification
72  const TIL_Plane *getParent() const { return myParent; }
73  int getInputRef() const { return myInputRef; }
74  int getArrayIndex() const { return myArrayIndex; }
75  float getTime() const { return myCookTime; }
76  void getRegionRes(int &x, int &y) const
77  { x=myXres; y=myYres; }
78  //
79  void getRegionBounds(int &x1, int &y1, int &x2, int &y2) const
80  { x1 = myX1+myXShift; y1 = myY1+myYShift;
81  x2 = myX2+myXShift; y2 = myY2+myYShift; }
82 
83  // for output regions, allows you to mark the region as filled.
84  void markFilled(bool filled = true) { myRemainingTiles = filled ? 0 : 1; }
85 
86  // tells you if the regions is completely filled.
87  int isFilled() const { return myRemainingTiles == 0; }
88  int remainingTiles() const { return myRemainingTiles; }
89  bool isInitialized() const { return myRegionInit; }
90 
91  bool workOnRegion();
92 
93  // tells you which tile needs to be cooked next, if 0 is returned,
94  // all the remaining tiles in the process of being cooked.
95  int getNextNeededTile(int &xoff,int &yoff,
96  int &xshift, int &yshift);
97 
98  // call when you're done filling the region with the tile recommended by
99  // getNextNeededTile.
100  void finishedTile(int xoff, int yoff);
101 
102  // checks to see if the region is still constant.
103  void checkConstant(const TIL_Tile *tile, int component);
104  bool isConstantChecked() const { return myConstantChecked; }
105  bool isConstant(bool force_check = false);
106  bool isConstantValue() const;
107  void getConstantColor(float color[4]) const;
108  // does not set the color for the region, only the constant flag & color.
109  void setConstantColor(float color[4]);
110 
111  // can't cook a tile that getNextNeededTile passed (likely due to a
112  // write lock on the tile held by another thread).
113  void rejectTile(int xoff, int yoff);
114 
115  // returns the data associated with index or component name 'compname'
116  void * getImageData(int index);
117  const void *getImageData(int index) const;
118 
119  void * getImageData(const char *compname);
120  const void *getImageData(const char *compname) const;
121 
122  void setImageData(void *data, int index, bool reference = true);
123 
124  // Returns the size, in bytes, of the image data. The result is the size
125  // for one component, not for all components.
126  exint getImageDataSizePerComponent() const;
127 
128  // Total memory size of this region (approx).
129  exint getMemSize();
130 
131  bool isSharedRegion() const { return myRegionShared; }
132  bool isSharedRegionDone() const { return myRegionUnshared; }
133  int getCurrentRefCount() const { return myRefCount; }
134  int getCurrentShareCount() const { return myShareCount; }
135  void unshareRegion();
136 
137  // Region hash routines - return this region's hash code.
138  unsigned getHash() const { return myHashCode; }
139 
140  // Return a hash code would correspond to the hash code of a region
141  // created with these parms.
142  static unsigned getHash(const TIL_Plane *plane, int aindex, int inref,
143  float t, int x1, int y1, int x2, int y2,
144  int xres, int yres, int nid, bool output);
145 
146  // Use these methods to get a tile list which corresponds to this region.
147  // The region should be equal to or less than the current tile size.
148  // Please note that the extra information in the tiles, such as the offset
149  // and other information, may not be accurate.
150  // Call cleanupTiles to free the tilelist. Do NOT call
151  // COP2_Node::releaseTile or freeTile on this tilelist!
152  TIL_TileList *getTilesFromRegion();
153  void cleanupTiles(TIL_TileList *&tiles);
154 
155  // sets the time to cook this region (mostly for output regions where you
156  // want to distribute the time spent filling it across all the tiles)
157  void setWorkTime(float cooktime) { myWorkTime = cooktime; }
158  float getWorkTime() const { return myWorkTime; }
159 
160 private:
161  TIL_Region();
162  ~TIL_Region();
163 
164  void fillOutsideData();
165  float fillOutsideBlack(unsigned char *region);
166  void fillOutsideHold(unsigned char *region);
167  void determineIfConstant();
168 
169 private:
170  // Parent plane (and allocation routine next ptr).
171  union {
174  };
175 
176  // more image id.
177  short myArrayIndex;
178  short myInputRef;
179  int myID;
180  int myNodeID;
181  float myCookTime;
182 
183  // parent image res
184  int myXres, myYres;
185 
186  // region coordinates
187  int myX1, myY1;
188  int myX2, myY2;
189 
190  // coordinates clipped to canvas bounds
191  int myRX1, myRY1;
192  int myRX2, myRY2;
193 
194  // coordinates clipped to (0,0)->(xres-1,yres-1)
195  int myBX1, myBY1;
196  int myBX2, myBY2;
197 
198  int myXShift, myYShift;
199 
200  // region image data
201  void *myRegion[PLANE_MAX_VECTOR_SIZE];
202  void *myRawRegion[PLANE_MAX_VECTOR_SIZE];
203  char myRegionAlloced[PLANE_MAX_VECTOR_SIZE];
204 
205  // cooperative cooking
206  UT_Lock myLock;
207  int myRefCount;
208  int myShareCount;
209 
210  int myTileOffX;
211  int myTileOffY;
212  int myTileX2;
213  int myTileY2;
214  int myTileXCount;
215  int myTileYCount;
216  int myRemainingTiles;
217  int myAvailableTiles;
218  int myTileStride;
219  unsigned char *myTileStates;
220  float myWorkTime;
221 
222  float myConstantColor[4];
223 
224  unsigned myHashCode;
225  unsigned int myRegionOutside :1,
226  myHold :4,
227  myConstantChecked : 1,
228  myConstantFlag :1,
229  myConstantColorSetR : 1,
230  myConstantColorSetG : 1,
231  myConstantColorSetB : 1,
232  myConstantColorSetA : 1,
233  myRegionInit :1,
234  myRegionWorkFlag : 1,
235  myRegionShared : 1,
236  myRegionUnshared : 1;
237 };
238 
239 #endif
GT_API const UT_StringHolder time
bool isInitialized() const
Definition: TIL_Region.h:89
int getID() const
Definition: TIL_Region.h:60
int getArrayIndex() const
Definition: TIL_Region.h:74
TIL_RegionExtend
Definition: TIL_Region.h:24
int64 exint
Definition: SYS_Types.h:125
unsigned getHash() const
Definition: TIL_Region.h:138
GLint y
Definition: glcorearb.h:103
void getRegionBounds(int &x1, int &y1, int &x2, int &y2) const
Definition: TIL_Region.h:79
void close() override
const TIL_Plane * getParent() const
Definition: TIL_Region.h:72
GLdouble GLdouble x2
Definition: glad.h:2349
int getCurrentShareCount() const
Definition: TIL_Region.h:134
float getTime() const
Definition: TIL_Region.h:75
TIL_Region * myNext
Definition: TIL_Region.h:173
int isFilled() const
Definition: TIL_Region.h:87
GLboolean reset
Definition: glad.h:5138
int open(float queuesize) override
int remainingTiles() const
Definition: TIL_Region.h:88
void setWorkTime(float cooktime)
Definition: TIL_Region.h:157
GLdouble y1
Definition: glad.h:2349
#define PLANE_MAX_VECTOR_SIZE
Definition: TIL_Defines.h:167
int getCurrentRefCount() const
Definition: TIL_Region.h:133
const TIL_Plane * myParent
Definition: TIL_Region.h:172
bool isConstantChecked() const
Definition: TIL_Region.h:104
GLint GLenum GLint x
Definition: glcorearb.h:409
void getRegionRes(int &x, int &y) const
Definition: TIL_Region.h:76
GLdouble t
Definition: glad.h:2397
int getInputRef() const
Definition: TIL_Region.h:73
GLuint color
Definition: glcorearb.h:1261
GLuint index
Definition: glcorearb.h:786
bool isSharedRegion() const
Definition: TIL_Region.h:131
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
float getWorkTime() const
Definition: TIL_Region.h:158
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression reference
#define TIL_API
Definition: TIL_API.h:10
bool isSharedRegionDone() const
Definition: TIL_Region.h:132
int getNodeID() const
Definition: TIL_Region.h:61
Definition: format.h:895
void markFilled(bool filled=true)
Definition: TIL_Region.h:84