00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef TIL_REGION_H
00021 #define TIL_REGION_H
00022
00023 #include "TIL_API.h"
00024 #include "TIL_Defines.h"
00025
00026 #include <UT/UT_SmallObject.h>
00027
00028 class TIL_Plane;
00029 class TIL_Tile;
00030 class TIL_TileList;
00031
00032 enum TIL_RegionExtend
00033 {
00034 TIL_BLACK = 0,
00035 TIL_HOLD_LEFT = 0x1,
00036 TIL_HOLD_RIGHT = 0x2,
00037 TIL_HOLD_TOP = 0x4,
00038 TIL_HOLD_BOTTOM = 0x8,
00039 TIL_HOLD = 0xF
00040 };
00041
00042 class TIL_API TIL_Region
00043 : public UT_SmallObject<TIL_Region,
00044 UT_SMALLOBJECT_CLEANPAGES_OFF, 32,
00045 UT_SMALLOBJECT_THREADSAFE_ON, 1024>
00046 {
00047 public:
00048
00049
00050
00051 static TIL_Region *allocRegion();
00052 static void freeRegion(TIL_Region *&freeme);
00053
00054
00055 void init(const TIL_Plane *parent, int input_index,
00056 int array_index, float time, int xres, int yres,
00057 int x1, int y1, int x2, int y2,
00058 int bx1, int by1, int bx2, int by2,
00059 TIL_RegionExtend hold = TIL_BLACK,
00060 int share_count = 1, int nid = 0,
00061 bool output = false, int xpad = 0);
00062
00063 void reset();
00064
00065
00066 void clear();
00067
00068 int getID() const { return myID; }
00069 int getNodeID() const { return myNodeID; }
00070
00071
00072
00073
00074 int open(void *regionlist[PLANE_MAX_VECTOR_SIZE] = 0);
00075 int close();
00076
00077
00078
00079
00080 const TIL_Plane *getParent() const { return myParent; }
00081 int getInputRef() const { return myInputRef; }
00082 int getArrayIndex() const { return myArrayIndex; }
00083 float getTime() const { return myCookTime; }
00084 void getRegionRes(int &x, int &y) const
00085 { x=myXres; y=myYres; }
00086
00087 void getRegionBounds(int &x1, int &y1, int &x2, int &y2) const
00088 { x1 = myX1+myXShift; y1 = myY1+myYShift;
00089 x2 = myX2+myXShift; y2 = myY2+myYShift; }
00090
00091
00092 void markFilled(bool filled = true) { myRemainingTiles = filled ? 0 : 1; }
00093
00094
00095 int isFilled() const { return myRemainingTiles == 0; }
00096 int remainingTiles() const { return myRemainingTiles; }
00097 bool isInitialized() const { return myRegionInit; }
00098
00099 bool workOnRegion();
00100
00101
00102
00103 int getNextNeededTile(int &xoff,int &yoff,
00104 int &xshift, int &yshift);
00105
00106
00107
00108 void finishedTile(int xoff, int yoff);
00109
00110
00111 void checkConstant(const TIL_Tile *tile, int component);
00112 bool isConstantChecked() const { return myConstantChecked; }
00113 bool isConstant(bool force_check = false);
00114 bool isConstantValue() const;
00115 void getConstantColor(float color[4]) const;
00116
00117 void setConstantColor(float color[4]);
00118
00119
00120
00121 void rejectTile(int xoff, int yoff);
00122
00123
00124 void * getImageData(int index);
00125 const void *getImageData(int index) const;
00126
00127 void * getImageData(const char *compname);
00128 const void *getImageData(const char *compname) const;
00129
00130 void setImageData(void *data, int index, bool reference = true);
00131
00132
00133 int getMemSize();
00134
00135 bool isSharedRegion() const { return myRegionShared; }
00136 bool isSharedRegionDone() const { return myRegionUnshared; }
00137 int getCurrentRefCount() const { return myRefCount; }
00138 int getCurrentShareCount() const { return myShareCount; }
00139 void unshareRegion();
00140
00141
00142 unsigned getHash() const { return myHashCode; }
00143
00144
00145
00146 static unsigned getHash(const TIL_Plane *plane, int aindex, int inref,
00147 float t, int x1, int y1, int x2, int y2,
00148 int xres, int yres, int nid, bool output);
00149
00150
00151
00152
00153
00154
00155
00156 TIL_TileList *getTilesFromRegion();
00157 void cleanupTiles(TIL_TileList *&tiles);
00158
00159
00160
00161 void setWorkTime(float cooktime) { myWorkTime = cooktime; }
00162 float getWorkTime() const { return myWorkTime; }
00163
00164 private:
00165 TIL_Region();
00166 ~TIL_Region();
00167
00168 void fillOutsideData();
00169 float fillOutsideBlack(unsigned char *region);
00170 void fillOutsideHold(unsigned char *region);
00171 void determineIfConstant();
00172
00173 private:
00174
00175 union {
00176 const TIL_Plane *myParent;
00177 TIL_Region *myNext;
00178 };
00179
00180
00181 short myArrayIndex;
00182 short myInputRef;
00183 int myID;
00184 int myNodeID;
00185 float myCookTime;
00186
00187
00188 int myXres, myYres;
00189
00190
00191 int myX1, myY1;
00192 int myX2, myY2;
00193
00194
00195 int myRX1, myRY1;
00196 int myRX2, myRY2;
00197
00198
00199 int myBX1, myBY1;
00200 int myBX2, myBY2;
00201
00202 int myXShift, myYShift;
00203
00204
00205 void *myRegion[PLANE_MAX_VECTOR_SIZE];
00206 void *myRawRegion[PLANE_MAX_VECTOR_SIZE];
00207 char myRegionAlloced[PLANE_MAX_VECTOR_SIZE];
00208
00209
00210 UT_Lock myLock;
00211 int myRefCount;
00212 int myShareCount;
00213
00214 int myTileOffX;
00215 int myTileOffY;
00216 int myTileX2;
00217 int myTileY2;
00218 int myTileXCount;
00219 int myTileYCount;
00220 int myRemainingTiles;
00221 int myAvailableTiles;
00222 int myTileStride;
00223 unsigned char *myTileStates;
00224 float myWorkTime;
00225
00226 float myConstantColor[4];
00227
00228 unsigned myHashCode;
00229 unsigned int myRegionOutside :1,
00230 myHold :4,
00231 myConstantChecked : 1,
00232 myConstantFlag :1,
00233 myConstantColorSetR : 1,
00234 myConstantColorSetG : 1,
00235 myConstantColorSetB : 1,
00236 myConstantColorSetA : 1,
00237 myRegionInit :1,
00238 myRegionWorkFlag : 1,
00239 myRegionShared : 1,
00240 myRegionUnshared : 1;
00241 };
00242
00243 #endif