[4] | 1 | /****************************************************************************** |
---|
| 2 | * Program: GlobalCoordinatesToFileMapper |
---|
| 3 | * Module: GlobalCoordinatesToFileMapper.h |
---|
| 4 | * Authors: Nicholas Schwarz, schwarz@evl.uic.edu |
---|
| 5 | * Date: 21 September 2004 |
---|
| 6 | * |
---|
| 7 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 8 | * University of Illinois at Chicago |
---|
| 9 | * |
---|
| 10 | * All rights reserved. |
---|
| 11 | * |
---|
| 12 | * Redistribution and use in source and binary forms, with or without |
---|
| 13 | * modification, are permitted provided that the following conditions are met: |
---|
| 14 | * |
---|
| 15 | * * Redistributions of source code must retain the above copyright |
---|
| 16 | * notice, this list of conditions and the following disclaimer. |
---|
| 17 | * * Redistributions in binary form must reproduce the above |
---|
| 18 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 19 | * in the documentation and/or other materials provided with the distribution. |
---|
| 20 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 21 | * the names of its contributors may be used to endorse or promote |
---|
| 22 | * products derived from this software without specific prior written permission. |
---|
| 23 | * |
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 35 | * |
---|
| 36 | * Direct questions, comments etc to schwarz@evl.uic.edu or |
---|
| 37 | * http://www.evl.uic.edu/cavern/forum/ |
---|
| 38 | * |
---|
| 39 | *****************************************************************************/ |
---|
| 40 | // .NAME GlobalCoordinatesToFileMapper |
---|
| 41 | // .SECTION Description |
---|
| 42 | // GlobalCoordinatesToFileMapper is a class that maps from the global |
---|
| 43 | // coordinate space, usually pixels, of an image formed from a montage of |
---|
| 44 | // smaller, identically sized, rectangular images to the real image files |
---|
| 45 | // that the larger images consists of. |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | #ifndef GLOBAL_COORDINATES_TO_FILE_MAPPER_H |
---|
| 49 | #define GLOBAL_COORDINATES_TO_FILE_MAPPER_H |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | // Preprocessor definition error code for invalid extent |
---|
| 53 | #define GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_INVALID_EXTENT 0 |
---|
| 54 | |
---|
| 55 | // Preporcessor definition error code for invalid file name |
---|
| 56 | #define GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_INVALID_FILE 1 |
---|
| 57 | |
---|
| 58 | // Preprocessor definition error code for un-initialized mapper |
---|
| 59 | #define GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_NOT_INITIALIZED 2 |
---|
| 60 | |
---|
| 61 | // Preprocessor definition to indicate operation success |
---|
| 62 | #define GLOBAL_COORDINATES_TO_FILE_MAPPER_SUCCESS 3 |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | #include <fstream.h> |
---|
| 66 | #include <stddef.h> |
---|
| 67 | #include <string.h> |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | // class FileInfo holds information about individual files. |
---|
| 71 | #include "FileInfo.h" |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | class GlobalCoordinatesToFileMapper { |
---|
| 75 | |
---|
| 76 | public: |
---|
| 77 | |
---|
| 78 | // Description: |
---|
| 79 | // Constructor |
---|
| 80 | GlobalCoordinatesToFileMapper(); |
---|
| 81 | |
---|
| 82 | // Description: |
---|
| 83 | // Get description of the global image. |
---|
| 84 | const char* GetDescription(); |
---|
| 85 | |
---|
| 86 | // Description: |
---|
| 87 | // Get height of a single file that makes up the global image in coordinates |
---|
| 88 | // local to the file, usually pixels. We assume that all files are the same |
---|
| 89 | // size. |
---|
| 90 | long GetFileCoordinateDimensionH(); |
---|
| 91 | |
---|
| 92 | // Description: |
---|
| 93 | // Get width of a single file that makes up the global image in coordinates |
---|
| 94 | // local to the file, usually pixels. We assume that all files are the same |
---|
| 95 | // size. |
---|
| 96 | long GetFileCoordinateDimensionW(); |
---|
| 97 | |
---|
| 98 | // Description: |
---|
| 99 | // Get height of the global image in global coordinates, usually pixels. |
---|
| 100 | long GetGlobalCoordinateDimensionH(); |
---|
| 101 | |
---|
| 102 | // Description: |
---|
| 103 | // Get width of the global image in global coordinates, usually pixels. |
---|
| 104 | long GetGlobalCoordinateDimensionW(); |
---|
| 105 | |
---|
| 106 | // Description: |
---|
| 107 | // Get extent for a given file that makes up the global image in global |
---|
| 108 | // coordinates, usually pixels. |
---|
| 109 | long GetGlobalCoordinates(const char* name, |
---|
| 110 | long* x, |
---|
| 111 | long* y, |
---|
| 112 | long* w, |
---|
| 113 | long* h); |
---|
| 114 | |
---|
| 115 | // Description: |
---|
| 116 | // Get the GlobalFileLayoutArray, and its corresponding dimensions.The |
---|
| 117 | // GlobalFileLayoutArray is an adjacency matrix that specifies the layout of |
---|
| 118 | // files in the global image. The matrix starts in the upper left of the |
---|
| 119 | // global image, and is stored in column, row order. The matrix is an array |
---|
| 120 | // of pointers to character strings. Each character string contains the name |
---|
| 121 | // of its corresponding file. This class allocates and deallocates storage |
---|
| 122 | // for this array. |
---|
| 123 | char** GetGlobalFileLayoutArray(long* cols, |
---|
| 124 | long* rows); |
---|
| 125 | |
---|
| 126 | // Description: |
---|
| 127 | // Get the dimensions of the GlobalFileArray. The GlobalFileLayoutArray is |
---|
| 128 | // an adjacency matrix that specifies the layout of files in the global |
---|
| 129 | // image. The matrix starts in the upper left of the global image, and is |
---|
| 130 | // stored in column, row order. The matrix is an array of pointers to |
---|
| 131 | // character strings. Each character string contains the name of its |
---|
| 132 | // corresponding file. This class allocates and deallocates storage for this |
---|
| 133 | // array. |
---|
| 134 | void GetGlobalFileLayoutDimensions(long* cols, |
---|
| 135 | long* rows); |
---|
| 136 | |
---|
| 137 | // Description: |
---|
| 138 | // Get the height of the current query's extent in global coordinates, |
---|
| 139 | // usually pixels. |
---|
| 140 | long GetQueryExtentH(); |
---|
| 141 | |
---|
| 142 | // Description: |
---|
| 143 | // Get the width of the current query's extent in global coordinates, |
---|
| 144 | // usually pixels. |
---|
| 145 | long GetQueryExtentW(); |
---|
| 146 | |
---|
| 147 | // Description: |
---|
| 148 | // Get the starting x position of the current query's extent in global |
---|
| 149 | // coordinates, usually pixels. We assume that position (0,0) is in the |
---|
| 150 | // upper left corner. |
---|
| 151 | long GetQueryExtentX(); |
---|
| 152 | |
---|
| 153 | // Description: |
---|
| 154 | // Get the starting y position of the current query's extent in global |
---|
| 155 | // coordinates, usually pixels. We assume that position (0,0) is in the |
---|
| 156 | // upper left corner. |
---|
| 157 | long GetQueryExtentY(); |
---|
| 158 | |
---|
| 159 | // Description: |
---|
| 160 | // Get the FileInfoArray, and its corresponding dimensions. The FileInfoArray |
---|
| 161 | // is a 1D array of type FileInfo stored in column, row order. The FileInfo |
---|
| 162 | // array is updated by the Query() method. When making a query this array is |
---|
| 163 | // its result. |
---|
| 164 | FileInfo* GetQueryFileInfoArray(long* cols, |
---|
| 165 | long* rows); |
---|
| 166 | |
---|
| 167 | // Description: |
---|
| 168 | // Get the dimensions of the FileInfoArray. The FileInfoArray is a 1D array |
---|
| 169 | // of type FileInfo stored in column, row order. The FileInfo array is |
---|
| 170 | // updated by the Query() method. |
---|
| 171 | void GetQueryFileInfoDimensions(long* cols, |
---|
| 172 | long* rows); |
---|
| 173 | |
---|
| 174 | // Description: |
---|
| 175 | // Initialize the class based on information in the file given. |
---|
| 176 | int Initialize(const char* name); |
---|
| 177 | |
---|
| 178 | // Description: |
---|
| 179 | // Returns whether this instance of the class has been initialized. |
---|
| 180 | bool IsInitialized(); |
---|
| 181 | |
---|
| 182 | // Description: |
---|
| 183 | // Print self. |
---|
| 184 | void PrintSelf(ostream& os); |
---|
| 185 | |
---|
| 186 | // Description: |
---|
| 187 | // Query this instance of the class. Returns an error if the instance is |
---|
| 188 | // not initialized, or the data extent is not within the global coordinate |
---|
| 189 | // space. Call this method each time the query extent is changed. When the |
---|
| 190 | // query is complete, the FileInfoArray is updated. |
---|
| 191 | int Query(); |
---|
| 192 | |
---|
| 193 | // Description: |
---|
| 194 | // Set description for the global image. |
---|
| 195 | void SetDescription(const char* string); |
---|
| 196 | |
---|
| 197 | // Description: |
---|
| 198 | // Set the dimensions of a single file that makes up the global image in |
---|
| 199 | // coordinates local to the file, usually pixels. We assume that all files |
---|
| 200 | // are the same size. |
---|
| 201 | void SetFileCoordinateDimensions(long w, |
---|
| 202 | long h); |
---|
| 203 | |
---|
| 204 | // Description: |
---|
| 205 | // Set the state of this instance to not initialized. This method should only |
---|
| 206 | // be invoked by the Initialize(...) method. |
---|
| 207 | void SetInitializedFalse(); |
---|
| 208 | |
---|
| 209 | // Description: |
---|
| 210 | // Set the state of this instance to initialized. This method should only be |
---|
| 211 | // invoked by the Initialize(...) method. |
---|
| 212 | void SetInitializedTrue(); |
---|
| 213 | |
---|
| 214 | // Description: |
---|
| 215 | // Set the dimensions of the global image in global coordinates, usually |
---|
| 216 | // pixels. |
---|
| 217 | void SetGlobalCoordinateDimensions(long w, |
---|
| 218 | long h); |
---|
| 219 | |
---|
| 220 | // Description: |
---|
| 221 | // Set the GlobalFileLayoutArray, along with its dimensions in columns and |
---|
| 222 | // rows. The GlobalFileLayoutArray is an adjacency matrix that specifies |
---|
| 223 | // the layout of files in the global image. The matrix starts in the upper |
---|
| 224 | // left of the global image, and is stored in column, row order. The matrix |
---|
| 225 | // is an array of pointers to character strings. Each character string |
---|
| 226 | // contains the name of its corresponding file. This class allocates and |
---|
| 227 | // deallocates storage for this array. This method should only be invoked by |
---|
| 228 | // the Initialize(...) method. |
---|
| 229 | void SetGlobalFileLayoutArray(char** array, |
---|
| 230 | long cols, |
---|
| 231 | long rows); |
---|
| 232 | |
---|
| 233 | // Description: |
---|
| 234 | // Set the dimensions of the GlobalFileArray. The GlobalFileLayoutArray is |
---|
| 235 | // an adjacency matrix that specifies the layout of files in the global |
---|
| 236 | // image. The matrix starts in the upper left of the global image, and is |
---|
| 237 | // stored in column, row order. The matrix is an array of pointers to |
---|
| 238 | // character strings. Each character string contains the name of its |
---|
| 239 | // corresponding file. This class allocates and deallocates storage for this |
---|
| 240 | // array. This method should only be invoked by the Initialize(...), or |
---|
| 241 | // SetGlobalFileLayoutArray(...) methods. |
---|
| 242 | void SetGlobalFileLayoutDimensions(long cols, |
---|
| 243 | long rows); |
---|
| 244 | |
---|
| 245 | // Description: |
---|
| 246 | // Set the extent of the current query. Set this information before calling |
---|
| 247 | // the Query() method. |
---|
| 248 | void SetQueryExtent(long x, long y, |
---|
| 249 | long w, long h); |
---|
| 250 | |
---|
| 251 | // Description: |
---|
| 252 | // Set the FileInfoArray, and its corresponding dimensions. The FileInfoArray |
---|
| 253 | // is a 1D array of type FileInfo stored in column, row order. This method |
---|
| 254 | // should only be invoked by the Query() method. |
---|
| 255 | void SetQueryFileInfoArray(FileInfo* array, |
---|
| 256 | long cols, |
---|
| 257 | long rows); |
---|
| 258 | |
---|
| 259 | // Description: |
---|
| 260 | // Set the dimensions of the FileInfoArray. The FileInfoArray is a 1D array |
---|
| 261 | // of type FileInfo stored in column, row order. This method should only be |
---|
| 262 | // invoked by the Query(), or SetQueryFileInfoArray(...) methods. |
---|
| 263 | void SetQueryFileInfoDimensions(long cols, |
---|
| 264 | long rows); |
---|
| 265 | |
---|
| 266 | // Description: |
---|
| 267 | // Destructor |
---|
| 268 | ~GlobalCoordinatesToFileMapper(); |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | private: |
---|
| 272 | |
---|
| 273 | // Description: |
---|
| 274 | // Description of the global image. |
---|
| 275 | char* Description; |
---|
| 276 | |
---|
| 277 | // Description: |
---|
| 278 | // The width and height of a single file that makes up the global image in |
---|
| 279 | // coordinates local to the file, usually pixels. We assume that all files |
---|
| 280 | // are the same size. |
---|
| 281 | long FileCoordinateDimensions[2]; |
---|
| 282 | |
---|
| 283 | // Description: |
---|
| 284 | // The width and height of the global image in global coordinates, usually |
---|
| 285 | // pixels. |
---|
| 286 | long GlobalCoordinateDimensions[2]; |
---|
| 287 | |
---|
| 288 | // Description: |
---|
| 289 | // The GlobalFileLayoutArray is an adjacency matrix that specifies the |
---|
| 290 | // layout of files in the global image. The matrix starts in the upper left |
---|
| 291 | // of the global image, and is stored in column, row order. The matrix is an |
---|
| 292 | // array of pointers to character strings. Each character string contains |
---|
| 293 | // the name of its corresponding file. This class allocates and deallocates |
---|
| 294 | // storage for this array. |
---|
| 295 | char** GlobalFileLayoutArray; |
---|
| 296 | |
---|
| 297 | // Description: |
---|
| 298 | // The number of columns and rows of files that make up the global image. |
---|
| 299 | long GlobalFileLayoutDimensions[2]; |
---|
| 300 | |
---|
| 301 | // Description: |
---|
| 302 | // Flag indicating whether the instance of the class is initialized. |
---|
| 303 | bool Initialized; |
---|
| 304 | |
---|
| 305 | // Description: |
---|
| 306 | // The extent of the current query as the x and y locations of the upper |
---|
| 307 | // left corner of the extent, and the width and height of the extent in |
---|
| 308 | // global coordinates, usually pixels. |
---|
| 309 | long QueryExtent[4]; |
---|
| 310 | |
---|
| 311 | // Description: |
---|
| 312 | // The FileInfoArray is a 1D array of type FileInfo stored in column, row |
---|
| 313 | // order. The FileInfo array is updated by the Query() method. When making a |
---|
| 314 | // query this array is its result. |
---|
| 315 | FileInfo* QueryFileInfoArray; |
---|
| 316 | |
---|
| 317 | // Description: |
---|
| 318 | // The number of columns and rows in the FileInfoArray. Updated by the |
---|
| 319 | // Query() method. |
---|
| 320 | long QueryFileInfoDimensions[2]; |
---|
| 321 | |
---|
| 322 | }; |
---|
| 323 | |
---|
| 324 | |
---|
| 325 | #endif |
---|