1 // ------------------------------------------------------------------------------------------------ 2 // 3 // IMAGE VIEW TOOLKIT 4 // 5 // MODULE : AdvancedIVUE 6 // LANGUAGE : C++ 7 // AUTHOR : Philippe BOSSUT 8 // DATE : Tuesday 23 November 1993 9 // DESCRIPTION : 10 // SCCSID : @(#)viewimg.h 1.2 14:49:52 06 Jan 1997 11 // ---------------------------------------------------------------------------- 12 // Copyright (c) 1999 Digital Imaging Group, Inc. 13 // For conditions of distribution and use, see copyright notice 14 // in Flashpix.h 15 // ---------------------------------------------------------------------------- 16 #ifndef AdvancedIVUE_h 17 #define AdvancedIVUE_h 18 19 #ifndef Commun_h 20 #include "common.h" 21 #endif 22 23 // ------------------------------------------------------------------------------------------------ 24 25 // Includes 26 // -------- 27 28 #ifndef SystemIVUE_h 29 #include "ri_sys.h" 30 #endif 31 32 #ifndef Geometrie_h 33 #include "geometry.h" 34 #endif 35 36 #ifndef FPXBaselineIO_h 37 #include "fpxlibio.h" 38 #endif 39 40 41 // Avoid to include ColorTwist.h 42 class PColorTwist; 43 44 // Constants 45 // --------- 46 47 #define ViewStateNumber 5 48 49 // Class declarations 50 // ------------------ 51 52 class PRIImage; 53 54 class ViewWorld; 55 class ViewImage; 56 class ViewWindow; 57 58 // Substructures declaration 59 60 struct ViewWorldRect; 61 struct ViewState; 62 struct ViewTransfoState; 63 64 // Class definitions 65 // ----------------- 66 67 68 // Substructures : 69 // BE CAREFUL : if you derivate one of the classes where delete is redefined : the destructor should be virtual 70 71 // World rectangles used to manage modification area optimization chained in ViewState 72 73 struct ViewWorldRect : public PToolkitObject { 74 public: 75 ViewWorldRect (); 76 ~ViewWorldRect (); 77 78 RectangleMv rectangle; // Rectangle in World coordinates 79 ViewWorldRect* previous; // Pointer to previous state rectangle 80 ViewWorldRect* next; // Pointer to next state rectangle 81 }; 82 83 struct ViewState : public PToolkitObject { 84 public: 85 ViewState (float x0, float y0, float x1, float y1); 86 ~ViewState (); 87 88 void Increment (); 89 void Increment (const PositionMv& p0, const PositionMv& p1); 90 void Increment (const RectangleMv& r); 91 long GetState (); 92 RectangleMv GetRectangle (long fromState); 93 private: 94 ViewWorldRect modRectangles[ViewStateNumber]; // Array of state rectangles : modRectangles is organised as a closed loop of states 95 ViewWorldRect* lastModRectangle; // Pointer to last modified rectangle in modRectangles 96 RectangleMv largestRectangle; // Largest rectangle manage by state 97 long stateNumber; // Current number of the World's state 98 }; 99 100 // Integral transformation matrices chained in Windows 101 102 struct ViewTransfoState : public PToolkitObject { 103 public: 104 ViewTransfoState (); 105 ~ViewTransfoState (); 106 107 void Update (float x0, float y0, float resolution, ViewImage* image); 108 109 long imageState; // State of the image when matrice was computed 110 IntegralTransfo pixelPosition; // Direct Window pixel to image pixel transformation 111 ViewTransfoState* next; // Pointer to the next transformation matrice 112 }; 113 114 // Main objects : 115 116 // World definition object : contains ViewImages positioned in it 117 118 class ViewWorld : public PToolkitObject { 119 120 friend class ViewWindow; 121 122 public : 123 ViewWorld (float width, float height, Pixel color); 124 ~ViewWorld (); 125 126 // View Images list management : 127 FPXStatus AddImage (ref_FicNom refNom); 128 FPXStatus AddImage (PRIImage* theImage); 129 FPXStatus AddImage (ViewImage* image); 130 FPXStatus DeleteImage (ViewImage* theImage, Boolean doNotCloseFile = FALSE); 131 132 long First (ViewImage** theImage); 133 long Last (ViewImage** theImage); 134 long Next (ViewImage** theImage); 135 long Previous (ViewImage** theImage); 136 long Current (ViewImage** theImage); 137 138 long GetState (); 139 140 private : 141 float height; // Size y of the world in mm 142 float width; // Size x of the world in mm 143 144 ViewImage* first; // First ViewImage within World 145 ViewImage* last; // Last ViewImage within World 146 ViewImage* current; // Current ViewImage within World 147 148 ViewState state; // World state record 149 }; 150 151 // View Image positioning definition object : point to an PRIImage object (see PRIImage.h) 152 153 class ViewImage : public PToolkitObject { 154 155 friend class ViewWorld; 156 friend struct ViewTransfoState; 157 158 public: 159 ViewImage (ref_FicNom refNom); 160 ViewImage (PRIImage* theImage); 161 ViewImage (); 162 virtual ~ViewImage (); 163 164 // Read a rectangle of the transformed image 165 FPXStatus Read4x4Points(float x0, float y0, // Rectangle in mm of the image 166 float x1, float y1, 167 Pixel* bufPix); // Out buffer 168 169 // Allow access to Image members : 170 PRIImage* operator->(); GetImage()171 PRIImage* GetImage() { return image; } 172 FPXStatus FileStatus (); 173 174 // Position setting tools : 175 FPXStatus UseAlphaChannel (Boolean useAlpha); 176 FPXStatus InvertAlphaChannel (Boolean inverseAlpha); 177 FPXStatus SetImageSize (float width, float height); 178 void SetPosition (TransfoPerspective& position); 179 void SetPosition (float x0, float y0, float m11, float m12, float m21, float m22); 180 void GetPosition (float* x0, float* y0, float* m11, float* m12, float* m21, float* m22); 181 void ApplyTransform (TransfoPerspective& trans); 182 void ApplyTransform (float x0, float y0, float m11, float m12, float m21, float m22); 183 void Translate (float dx, float dy); 184 void Rotate (float x0, float y0, float theta); 185 void Scale (float x0, float y0, float sx, float sy); 186 void ShearHorizontal (float x0, float y0, float sh); 187 void ShearVertical (float x0, float y0, float sh); 188 void FlipHorizontal (float x0, float y0); 189 void FlipVertical (float x0, float y0); 190 FPXStatus SetImageCrop(float x0, float y0, float x1, float y1); 191 void ResetImageCrop(); 192 193 // Get geometric information tools : 194 long GetOutlineParallelogram (float* x0, float* y0, float* x1, float* y1, 195 float* x2, float* y2, float* x3, float* y3); 196 void GetOutlineRectangle (float* x0, float* y0, float* x1, float* y1); 197 void GetOrigin (float* x0, float* y0); 198 float GetNormalizationRatio(); 199 200 long GetState (); 201 202 // Other parameters setting tools 203 void SetContrast (float theContrastValue); 204 void GetContrast (float* theContrastValue); HasContrastValue()205 Boolean HasContrastValue () { return hasContrastValue; } 206 207 void SetFiltering (float theFilteringValue); 208 void GetFiltering (float* theFilteringValue); HasFilteringValue()209 Boolean HasFilteringValue () { return hasFilteringValue; } 210 211 long SetFinalDimensions (float theFinalWidth, float theFinalHeight); 212 void GetFinalDimensions (float* theFinalWidth, float* theFinalHeight); 213 214 void SetColorTwist (PColorTwist* theColorTwist); 215 void GetColorTwist (PColorTwist* theColorTwist); HasColorTwist()216 Boolean HasColorTwist () { return hasColorTwist; } 217 SetAutoResize(Boolean theAutoResize)218 long SetAutoResize (Boolean theAutoResize) 219 { resizeFinalDimensions = theAutoResize; return 0; } GetAutoResize()220 Boolean GetAutoResize () { return resizeFinalDimensions; } 221 222 long GetDirtyCount (); 223 224 protected: 225 // Private tools : used by ViewWindow 226 void InitViewParameters(); 227 void GetOutlineParallelogram (PositionMv* p0, PositionMv* p1, PositionMv* p2, PositionMv* p3); 228 void GetOutlineRectangle (PositionMv* p0, PositionMv* p1); 229 void GetOrigin (PositionMv* p0); 230 231 PRIImage* image; // Used Image 232 Boolean doNotDelete; // The image is not deleted if the pointer is passed 233 234 // Geometric informations: these informations are mandatory in a ViewImage object 235 float originHeight, originWidth; // Original image size within the World in mm 236 float height, width; // Cropped image size within the World in mm 237 float cropX0, cropY0; // Cropping rectangle 1st point in mm 238 float cropX1, cropY1; // Cropping rectangle 2nd point in mm 239 TransfoPerspective position; // Image position within World in mm 240 Boolean resizeFinalDimensions; // By default, finalWidth and finalHeight are resized according to position 241 float finalHeight, finalWidth; // Resulting image size within the World in mm 242 float normalizationRatio; // The image is sometimes renormalized to 1 in height, this ratio allows to go back to the original height 243 244 // Color trasnformations: these informations are optionnal 245 Boolean hasContrastValue; // True if the contrast adjustement has to be taken into account 246 float contrastValue; // Contrast adjustement value 247 248 Boolean hasFilteringValue; // True if the filtering value has to be taken into account 249 float filteringValue; // Filtering value 250 251 Boolean hasColorTwist; // True if the color twist has to be taken into account 252 PColorTwist* colorTwist; // Color transformation matrix 253 254 ViewImage* previous; // Previous image within World 255 ViewImage* next; // Next image within World 256 257 ViewState state; // ViewImage state record 258 259 long dirtyCount; // # of contrast, filtering, colorTwist, and Aspect Ratio transforms applied 260 }; 261 262 // View Window Object : window is defined in a particular World 263 264 class ViewWindow : public PToolkitObject { 265 266 public : 267 ViewWindow (ViewWorld* world, float x0, float y0, float width, float height, float resolution); 268 ~ViewWindow (); 269 270 // Basic access tools : 271 FPXStatus ReadSample (long x0, long y0, Pixel* sample, FPXBaselineColorSpace space = SPACE_32_BITS_RGB); 272 FPXStatus Refresh (Pixel* map, FPXBaselineColorSpace space, long pixWidth, long pixHeight); 273 274 // Modifying Window tools : 275 void Translate (float dx, float dy); 276 void Resize (float width, float height); 277 FPXStatus Zoom (float zoomRatio); 278 279 // Get usefull information : 280 void GetWindowDefinition (float* x0, float* y0, float* width, float* height, float* resolution); 281 void GetWindowDefinition (int* width, int* height); 282 void WorldToWindow (float x, float y, int* i, int* j); 283 void WindowToWorld (int i, int j, float* x, float* y); 284 285 private : 286 void UpdateTransfoChain(); // Update integral transformation chain 287 288 ViewWorld* world; // Pointer to viewed world 289 290 int pix_height, pix_width; // Size of the window in real pixels 291 292 float height, width; // Window size within the World in mm 293 float x0, y0; // Window origin within World in mm 294 float resolution; // Window resolution in pixel per mm 295 296 Boolean modifiedWindow; // Flag of modification since last ReadSample() 297 long worldState; // World state taken into account in transfo chain 298 ViewTransfoState* first; // First pointer to integral transformation matrices 299 }; 300 301 302 // 'inline' Functions 303 // ----------------- 304 ~ViewState()305 inline ViewState::~ViewState () 306 { 307 } 308 GetState()309 inline long ViewState::GetState() 310 { 311 return(stateNumber); 312 } 313 GetState()314 inline long ViewImage::GetState() 315 { 316 return(state.GetState()); 317 } 318 GetState()319 inline long ViewWorld::GetState() 320 { 321 return(state.GetState()); 322 } 323 324 325 // ViewImage inline functions : 326 327 inline PRIImage* ViewImage::operator->() 328 { 329 return(image); 330 } 331 GetNormalizationRatio()332 inline float ViewImage::GetNormalizationRatio() 333 { 334 return normalizationRatio; 335 } 336 337 // Substructures inline functions 338 ViewWorldRect()339 inline ViewWorldRect::ViewWorldRect() : previous(0), next(0) 340 { 341 342 } 343 ViewTransfoState()344 inline ViewTransfoState::ViewTransfoState() : next(0) 345 { 346 347 } 348 ~ViewTransfoState()349 inline ViewTransfoState::~ViewTransfoState () 350 { 351 352 } 353 GetWindowDefinition(int * width,int * height)354 inline void ViewWindow::GetWindowDefinition (int* width, int* height) 355 { 356 *width = pix_width; 357 *height = pix_height; 358 } 359 360 361 // 'extern' Variables 362 // ----------------- 363 364 // ------------------------------------------------------------------------------------------------ 365 #endif // AdvancedIVUE_h 366 // ------------------------------------------------------------------------------------------------ 367