[4] | 1 | /****************************************************************************** |
---|
| 2 | * Program: GlobalCoordinatesToFileMapper |
---|
| 3 | * Module: GlobalCoordinatesToFileMapper.cpp |
---|
| 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 | |
---|
| 41 | |
---|
| 42 | // Include header file for this class |
---|
| 43 | #include "GlobalCoordinatesToFileMapper.h" |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | //----------------------------------------------------------------------------- |
---|
| 47 | GlobalCoordinatesToFileMapper::GlobalCoordinatesToFileMapper() |
---|
| 48 | { |
---|
| 49 | |
---|
| 50 | // Initialize global image description to NULL. |
---|
| 51 | this -> Description = NULL; |
---|
| 52 | |
---|
| 53 | // Initialize file coordinate dimensions to 0 by 0. |
---|
| 54 | this -> FileCoordinateDimensions[0] = 0; |
---|
| 55 | this -> FileCoordinateDimensions[1] = 0; |
---|
| 56 | |
---|
| 57 | // Initialize global coordinate dimensions to 0 by 0. |
---|
| 58 | this -> GlobalCoordinateDimensions[0] = 0; |
---|
| 59 | this -> GlobalCoordinateDimensions[1] = 0; |
---|
| 60 | |
---|
| 61 | // Initalize global file layour array to NULL. |
---|
| 62 | this -> GlobalFileLayoutArray = NULL; |
---|
| 63 | |
---|
| 64 | // Initialize global file layout dimensions to 0. |
---|
| 65 | this -> GlobalFileLayoutDimensions[0] = 0; |
---|
| 66 | this -> GlobalFileLayoutDimensions[1] = 0; |
---|
| 67 | |
---|
| 68 | // Initialize the initialized flag to false. |
---|
| 69 | this -> Initialized = false; |
---|
| 70 | |
---|
| 71 | // Initialize the query extent. |
---|
| 72 | this -> QueryExtent[0] = 0; |
---|
| 73 | this -> QueryExtent[1] = 0; |
---|
| 74 | this -> QueryExtent[2] = 0; |
---|
| 75 | this -> QueryExtent[3] = 0; |
---|
| 76 | |
---|
| 77 | // Initialize the query file info array to NULL. |
---|
| 78 | this -> QueryFileInfoArray = NULL; |
---|
| 79 | |
---|
| 80 | // Initialize the query file info array dimensions to 0 by 0. |
---|
| 81 | this -> QueryFileInfoDimensions[0] = 0; |
---|
| 82 | this -> QueryFileInfoDimensions[1] = 0; |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | //----------------------------------------------------------------------------- |
---|
| 88 | const char* GlobalCoordinatesToFileMapper::GetDescription() |
---|
| 89 | { |
---|
| 90 | |
---|
| 91 | // Return pointer to global image description. |
---|
| 92 | return this -> Description; |
---|
| 93 | |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | //----------------------------------------------------------------------------- |
---|
| 98 | long GlobalCoordinatesToFileMapper::GetFileCoordinateDimensionH() |
---|
| 99 | { |
---|
| 100 | |
---|
| 101 | // Return FileCoordinateDimensionH |
---|
| 102 | return this -> FileCoordinateDimensions[1]; |
---|
| 103 | |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | //----------------------------------------------------------------------------- |
---|
| 108 | long GlobalCoordinatesToFileMapper::GetFileCoordinateDimensionW() |
---|
| 109 | { |
---|
| 110 | |
---|
| 111 | // Return FileCoordinateDimensionW |
---|
| 112 | return this -> FileCoordinateDimensions[0]; |
---|
| 113 | |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | //----------------------------------------------------------------------------- |
---|
| 118 | long GlobalCoordinatesToFileMapper::GetGlobalCoordinateDimensionH() |
---|
| 119 | { |
---|
| 120 | |
---|
| 121 | // Return GlobalCoordinateDimensionH |
---|
| 122 | return this -> GlobalCoordinateDimensions[1]; |
---|
| 123 | |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | //----------------------------------------------------------------------------- |
---|
| 128 | long GlobalCoordinatesToFileMapper::GetGlobalCoordinateDimensionW() |
---|
| 129 | { |
---|
| 130 | |
---|
| 131 | // Return GlobalCoordinateDimensionW |
---|
| 132 | return this -> GlobalCoordinateDimensions[0]; |
---|
| 133 | |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | //----------------------------------------------------------------------------- |
---|
| 138 | long GlobalCoordinatesToFileMapper::GetGlobalCoordinates(const char* name, |
---|
| 139 | long* x, |
---|
| 140 | long* y, |
---|
| 141 | long* w, |
---|
| 142 | long* h) |
---|
| 143 | { |
---|
| 144 | |
---|
| 145 | // Check if instance is initialized |
---|
| 146 | if (this -> Initialized == false) |
---|
| 147 | { |
---|
| 148 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_NOT_INITIALIZED; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | // Loop through the global file layout array. |
---|
| 152 | for (long c = 0, p = 0 ; c < GlobalFileLayoutDimensions[0] ; c++) |
---|
| 153 | { |
---|
| 154 | for (long r = 0 ; r < GlobalFileLayoutDimensions[1] ; r++, p++) |
---|
| 155 | { |
---|
| 156 | // Check for given file. |
---|
| 157 | if (strcmp(this -> GlobalFileLayoutArray[p], name) == 0) |
---|
| 158 | { |
---|
| 159 | *x = this -> FileCoordinateDimensions[0] * c; |
---|
| 160 | *y = this -> FileCoordinateDimensions[1] * r; |
---|
| 161 | *w = this -> FileCoordinateDimensions[0]; |
---|
| 162 | *h = this -> FileCoordinateDimensions[1]; |
---|
| 163 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_SUCCESS; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // Return error is the file does not exist in the mapper. |
---|
| 169 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_INVALID_FILE; |
---|
| 170 | |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | //----------------------------------------------------------------------------- |
---|
| 175 | char** GlobalCoordinatesToFileMapper::GetGlobalFileLayoutArray(long* cols, |
---|
| 176 | long* rows) |
---|
| 177 | { |
---|
| 178 | |
---|
| 179 | // GlobalFileLayoutDimensions |
---|
| 180 | *cols = this -> GlobalFileLayoutDimensions[0]; |
---|
| 181 | *rows = this -> GlobalFileLayoutDimensions[1]; |
---|
| 182 | |
---|
| 183 | // Return pointer to the global file layout array |
---|
| 184 | return this -> GlobalFileLayoutArray; |
---|
| 185 | |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | //----------------------------------------------------------------------------- |
---|
| 190 | void GlobalCoordinatesToFileMapper::GetGlobalFileLayoutDimensions(long* cols, |
---|
| 191 | long* rows) |
---|
| 192 | { |
---|
| 193 | |
---|
| 194 | // GlobalFileLayoutDimensions |
---|
| 195 | *cols = this -> GlobalFileLayoutDimensions[0]; |
---|
| 196 | *rows = this -> GlobalFileLayoutDimensions[1]; |
---|
| 197 | |
---|
| 198 | return; |
---|
| 199 | |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | //----------------------------------------------------------------------------- |
---|
| 204 | long GlobalCoordinatesToFileMapper::GetQueryExtentH() |
---|
| 205 | { |
---|
| 206 | |
---|
| 207 | // Return QueryExtentH |
---|
| 208 | return this -> QueryExtent[3]; |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | //----------------------------------------------------------------------------- |
---|
| 214 | long GlobalCoordinatesToFileMapper::GetQueryExtentW() |
---|
| 215 | { |
---|
| 216 | |
---|
| 217 | // Return QueryExtentW |
---|
| 218 | return this -> QueryExtent[2]; |
---|
| 219 | |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | //----------------------------------------------------------------------------- |
---|
| 224 | long GlobalCoordinatesToFileMapper::GetQueryExtentX() |
---|
| 225 | { |
---|
| 226 | |
---|
| 227 | // Return QueryExtentH |
---|
| 228 | return this -> QueryExtent[0]; |
---|
| 229 | |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | //----------------------------------------------------------------------------- |
---|
| 234 | long GlobalCoordinatesToFileMapper::GetQueryExtentY() |
---|
| 235 | { |
---|
| 236 | |
---|
| 237 | // Return QueryExtentH |
---|
| 238 | return this -> QueryExtent[1]; |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | //----------------------------------------------------------------------------- |
---|
| 244 | FileInfo* GlobalCoordinatesToFileMapper::GetQueryFileInfoArray(long* cols, |
---|
| 245 | long* rows) |
---|
| 246 | { |
---|
| 247 | |
---|
| 248 | // QueryFileInfoArray dimensions |
---|
| 249 | *cols = this -> QueryFileInfoDimensions[0]; |
---|
| 250 | *rows = this -> QueryFileInfoDimensions[1]; |
---|
| 251 | |
---|
| 252 | // Return QueryFileInfoArray |
---|
| 253 | return this -> QueryFileInfoArray; |
---|
| 254 | |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | //----------------------------------------------------------------------------- |
---|
| 259 | void GlobalCoordinatesToFileMapper::GetQueryFileInfoDimensions(long* cols, |
---|
| 260 | long* rows) |
---|
| 261 | { |
---|
| 262 | |
---|
| 263 | // QueryFileInfoArray dimensions |
---|
| 264 | *cols = this -> QueryFileInfoDimensions[0]; |
---|
| 265 | *rows = this -> QueryFileInfoDimensions[1]; |
---|
| 266 | |
---|
| 267 | return; |
---|
| 268 | |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | //----------------------------------------------------------------------------- |
---|
| 273 | int GlobalCoordinatesToFileMapper::Initialize(const char* name) |
---|
| 274 | { |
---|
| 275 | |
---|
| 276 | // Try to open file for reading. |
---|
| 277 | ifstream file(name); |
---|
| 278 | |
---|
| 279 | // Check if file is open. |
---|
| 280 | if (!file.is_open()) |
---|
| 281 | { |
---|
| 282 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_INVALID_FILE; |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | // Read GlobalCoordinateDimensions, GlobalFileLayoutDimensions, and |
---|
| 286 | // FileCoordinateDimensions, respectively. |
---|
| 287 | file >> this -> GlobalCoordinateDimensions[0] |
---|
| 288 | >> this -> GlobalCoordinateDimensions[1] |
---|
| 289 | >> this -> GlobalFileLayoutDimensions[0] |
---|
| 290 | >> this -> GlobalFileLayoutDimensions[1] |
---|
| 291 | >> this -> FileCoordinateDimensions[0] |
---|
| 292 | >> this -> FileCoordinateDimensions[1]; |
---|
| 293 | |
---|
| 294 | // Allocate storage for the GlobalFileLayoutArray |
---|
| 295 | this -> GlobalFileLayoutArray = |
---|
| 296 | new char*[GlobalFileLayoutDimensions[0] * GlobalFileLayoutDimensions[1]]; |
---|
| 297 | |
---|
| 298 | // Read each file in the global image in order. Entries in the file are |
---|
| 299 | // column by column. |
---|
| 300 | for (long i = 0 ; |
---|
| 301 | i < GlobalFileLayoutDimensions[0] * GlobalFileLayoutDimensions[1] ; |
---|
| 302 | i++) |
---|
| 303 | { |
---|
| 304 | this -> GlobalFileLayoutArray[i] = new char[100]; |
---|
| 305 | file >> this -> GlobalFileLayoutArray[i]; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | // Close file |
---|
| 309 | file.close(); |
---|
| 310 | |
---|
| 311 | // Set initialized to true |
---|
| 312 | this -> Initialized = true; |
---|
| 313 | |
---|
| 314 | // Return successfully |
---|
| 315 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_SUCCESS; |
---|
| 316 | |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | //----------------------------------------------------------------------------- |
---|
| 321 | bool GlobalCoordinatesToFileMapper::IsInitialized() |
---|
| 322 | { |
---|
| 323 | |
---|
| 324 | // Return Initialized |
---|
| 325 | return this -> Initialized; |
---|
| 326 | |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | //----------------------------------------------------------------------------- |
---|
| 331 | void GlobalCoordinatesToFileMapper::PrintSelf(ostream& os) |
---|
| 332 | { |
---|
| 333 | |
---|
| 334 | os << "GlobalCoordinatesToFileMapper - Begin PrintSelf ------------------\n"; |
---|
| 335 | |
---|
| 336 | if (this -> Description != NULL) |
---|
| 337 | os << " Description: " << this -> Description << "\n"; |
---|
| 338 | else |
---|
| 339 | os << " Description: null\n"; |
---|
| 340 | |
---|
| 341 | os << " File Coordinate Dimensions: " |
---|
| 342 | << this -> FileCoordinateDimensions[0] << " " |
---|
| 343 | << this -> FileCoordinateDimensions[1] << "\n"; |
---|
| 344 | |
---|
| 345 | os << " Global Coordinate Dimensions: " |
---|
| 346 | << this -> GlobalCoordinateDimensions[0] << " " |
---|
| 347 | << this -> GlobalCoordinateDimensions[1] << "\n"; |
---|
| 348 | |
---|
| 349 | os << " Global File Layout Array:\n"; |
---|
| 350 | for (long i = 0 ; |
---|
| 351 | i < this -> GlobalFileLayoutDimensions[0] * |
---|
| 352 | GlobalFileLayoutDimensions[1] ; |
---|
| 353 | i++) |
---|
| 354 | { |
---|
| 355 | if (this -> GlobalFileLayoutArray != NULL) |
---|
| 356 | { |
---|
| 357 | if (this -> GlobalFileLayoutArray[i] != NULL) |
---|
| 358 | { |
---|
| 359 | os << " " << this -> GlobalFileLayoutArray[i] << "\n"; |
---|
| 360 | } |
---|
| 361 | else |
---|
| 362 | { |
---|
| 363 | os << " null" << endl; |
---|
| 364 | } |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | os << " Global File Layout Dimensions: " |
---|
| 369 | << this -> GlobalFileLayoutDimensions[0] << " " |
---|
| 370 | << this -> GlobalFileLayoutDimensions[1] << "\n"; |
---|
| 371 | |
---|
| 372 | os << " Query Extent: " |
---|
| 373 | << this -> QueryExtent[0] << " " |
---|
| 374 | << this -> QueryExtent[1] << " " |
---|
| 375 | << this -> QueryExtent[2] << " " |
---|
| 376 | << this -> QueryExtent[3] << "\n"; |
---|
| 377 | |
---|
| 378 | os << " Query File Info Dimensions: " |
---|
| 379 | << this -> QueryFileInfoDimensions[0] << " " |
---|
| 380 | << this -> QueryFileInfoDimensions[1] << "\n"; |
---|
| 381 | |
---|
| 382 | os << "GlobalCoordinatesToFileMapper - End PrintSelf --------------------\n" |
---|
| 383 | << endl; |
---|
| 384 | |
---|
| 385 | return; |
---|
| 386 | |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | //----------------------------------------------------------------------------- |
---|
| 391 | int GlobalCoordinatesToFileMapper::Query() |
---|
| 392 | { |
---|
| 393 | |
---|
| 394 | // Check if instance is initialized |
---|
| 395 | if (this -> Initialized == false) |
---|
| 396 | { |
---|
| 397 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_NOT_INITIALIZED; |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | // Check that query extent is within global image bounds |
---|
| 401 | if ((this -> QueryExtent[0] + this -> QueryExtent[2] > |
---|
| 402 | this -> GlobalCoordinateDimensions[0]) || |
---|
| 403 | (this -> QueryExtent[1] + this -> QueryExtent[3] > |
---|
| 404 | this -> GlobalCoordinateDimensions[1])) |
---|
| 405 | { |
---|
| 406 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_ERROR_INVALID_EXTENT; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | // Calculate the first column and row |
---|
| 410 | long fc = this -> QueryExtent[0] / this -> FileCoordinateDimensions[0]; |
---|
| 411 | long fr = this -> QueryExtent[1] / this -> FileCoordinateDimensions[1]; |
---|
| 412 | |
---|
| 413 | // Calculate the last column and row |
---|
| 414 | long lc = (this -> QueryExtent[0] + this -> QueryExtent[2]) / |
---|
| 415 | this -> FileCoordinateDimensions[0]; |
---|
| 416 | long lr = (this -> QueryExtent[1] + this -> QueryExtent[3]) / |
---|
| 417 | this -> FileCoordinateDimensions[1]; |
---|
| 418 | |
---|
| 419 | // Set the query file info dimensions |
---|
| 420 | this -> QueryFileInfoDimensions[0] = lc - fc + 1; |
---|
| 421 | this -> QueryFileInfoDimensions[1] = lr - fr + 1; |
---|
| 422 | |
---|
| 423 | // Calculate the total number of files in the result |
---|
| 424 | long tot = (lc - fc + 1) * (lr - fr + 1); |
---|
| 425 | |
---|
| 426 | // Delete previous query result. |
---|
| 427 | if (this -> QueryFileInfoArray != NULL) |
---|
| 428 | { |
---|
| 429 | delete [] this -> QueryFileInfoArray; |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | // Allocate storage for new query. |
---|
| 433 | this -> QueryFileInfoArray = new FileInfo[tot]; |
---|
| 434 | |
---|
| 435 | // Count number of files in FileInfoArray |
---|
| 436 | long fcnt = 0; |
---|
| 437 | |
---|
| 438 | // Create FileInfoArray for query. Loop through each column, and row |
---|
| 439 | // of the global array specified by the bounds computed above, filling in |
---|
| 440 | // the array. This probably isn't the best way to do this, but it's what |
---|
| 441 | // I came up with in one night. |
---|
| 442 | for (long cgc = fc, clc = 0 ; cgc <= lc ; cgc++, clc++) |
---|
| 443 | { |
---|
| 444 | for (long cgr = fr, clr = 0 ; cgr <= lr ; cgr++, clr++) |
---|
| 445 | { |
---|
| 446 | // Set file dimensions |
---|
| 447 | this -> QueryFileInfoArray[fcnt]. |
---|
| 448 | SetDimensions(this -> FileCoordinateDimensions[0], |
---|
| 449 | this -> FileCoordinateDimensions[1]); |
---|
| 450 | |
---|
| 451 | // Determine file's position in global array |
---|
| 452 | long pos = (cgc * this -> GlobalFileLayoutDimensions[1]) + cgr; |
---|
| 453 | |
---|
| 454 | // Calculate and set the extent for the current individual file. |
---|
| 455 | |
---|
| 456 | // first and last column |
---|
| 457 | if (clc == 0 && lc - fc == 0) |
---|
| 458 | { |
---|
| 459 | if (this -> QueryExtent[0] >= |
---|
| 460 | this -> FileCoordinateDimensions[0]) |
---|
| 461 | { |
---|
| 462 | this -> QueryFileInfoArray[fcnt]. |
---|
| 463 | SetExtentX(this -> QueryExtent[0] - |
---|
| 464 | (cgc * this -> FileCoordinateDimensions[0])); |
---|
| 465 | } |
---|
| 466 | else |
---|
| 467 | { |
---|
| 468 | this -> QueryFileInfoArray[fcnt].SetExtentX(this -> |
---|
| 469 | QueryExtent[0]); |
---|
| 470 | } |
---|
| 471 | this -> QueryFileInfoArray[fcnt].SetExtentW(this -> |
---|
| 472 | QueryExtent[2]); |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | // first and last row |
---|
| 476 | if (clr == 0 && lr - fr == 0) |
---|
| 477 | { |
---|
| 478 | // if first row is from 0 then it's OK, but if it's not |
---|
| 479 | // then subtract number of rows * fileDim |
---|
| 480 | if (this -> QueryExtent[1] >= |
---|
| 481 | this -> FileCoordinateDimensions[1]) |
---|
| 482 | { |
---|
| 483 | this -> QueryFileInfoArray[fcnt]. |
---|
| 484 | SetExtentY(this -> QueryExtent[1] - |
---|
| 485 | (cgr * this -> FileCoordinateDimensions[1])); |
---|
| 486 | } |
---|
| 487 | else |
---|
| 488 | { |
---|
| 489 | this -> QueryFileInfoArray[fcnt].SetExtentY(this -> |
---|
| 490 | QueryExtent[1]); |
---|
| 491 | } |
---|
| 492 | this -> QueryFileInfoArray[fcnt].SetExtentH(this -> |
---|
| 493 | QueryExtent[3]); |
---|
| 494 | |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | // first, but not last, column |
---|
| 498 | if (clc == 0 && lc - fc != 0) |
---|
| 499 | { |
---|
| 500 | long tmp = this -> QueryExtent[0] - |
---|
| 501 | (cgc * this -> FileCoordinateDimensions[0]); |
---|
| 502 | this -> QueryFileInfoArray[fcnt].SetExtentX(tmp); |
---|
| 503 | this -> QueryFileInfoArray[fcnt]. |
---|
| 504 | SetExtentW(this -> FileCoordinateDimensions[0] - tmp); |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | // first, but not last, row |
---|
| 508 | if (clr == 0 && lr - fr != 0) |
---|
| 509 | { |
---|
| 510 | long tmp = this -> QueryExtent[1] - |
---|
| 511 | (cgr * this -> FileCoordinateDimensions[1]); |
---|
| 512 | this -> QueryFileInfoArray[fcnt].SetExtentY(tmp); |
---|
| 513 | this -> QueryFileInfoArray[fcnt]. |
---|
| 514 | SetExtentH(this -> FileCoordinateDimensions[1] - tmp); |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | // last, but not only, column |
---|
| 518 | if (clc == (lc - fc) && clc != 0) |
---|
| 519 | { |
---|
| 520 | long tmp = (this -> QueryExtent[0] + this -> QueryExtent[2]) - |
---|
| 521 | (cgc * this -> FileCoordinateDimensions[0]); |
---|
| 522 | this -> QueryFileInfoArray[fcnt].SetExtentX(0); |
---|
| 523 | this -> QueryFileInfoArray[fcnt].SetExtentW(tmp); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | // last, but not only, row |
---|
| 527 | if (clr == (lr - fr) && clr != 0) |
---|
| 528 | { |
---|
| 529 | long tmp = (this -> QueryExtent[1] + this -> QueryExtent[3]) - |
---|
| 530 | (cgr * this -> FileCoordinateDimensions[1]); |
---|
| 531 | this -> QueryFileInfoArray[fcnt].SetExtentY(0); |
---|
| 532 | this -> QueryFileInfoArray[fcnt].SetExtentH(tmp); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | // Not the first and not the last column |
---|
| 536 | if (clc != 0 && clc != (lc - fc)) |
---|
| 537 | { |
---|
| 538 | this -> QueryFileInfoArray[fcnt].SetExtentX(0); |
---|
| 539 | this -> QueryFileInfoArray[fcnt]. |
---|
| 540 | SetExtentW(this -> FileCoordinateDimensions[0]); |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | // Not the first and not the last row |
---|
| 544 | if (clr != 0 && clr != (lr - fr)) |
---|
| 545 | { |
---|
| 546 | this -> QueryFileInfoArray[fcnt].SetExtentY(0); |
---|
| 547 | this -> QueryFileInfoArray[fcnt]. |
---|
| 548 | SetExtentH(this -> FileCoordinateDimensions[1]); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | // Set file name |
---|
| 552 | this -> QueryFileInfoArray[fcnt]. |
---|
| 553 | SetFileName(this -> GlobalFileLayoutArray[pos]); |
---|
| 554 | |
---|
| 555 | // Set local file position to current local column, |
---|
| 556 | // current local row. |
---|
| 557 | this -> QueryFileInfoArray[fcnt].SetLocalPosition(clc, clr); |
---|
| 558 | |
---|
| 559 | // Increment number of files in FileInfoArray |
---|
| 560 | fcnt++; |
---|
| 561 | } |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | // Return successfully |
---|
| 565 | return GLOBAL_COORDINATES_TO_FILE_MAPPER_SUCCESS; |
---|
| 566 | |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | |
---|
| 570 | //----------------------------------------------------------------------------- |
---|
| 571 | void GlobalCoordinatesToFileMapper::SetDescription(const char* string) |
---|
| 572 | { |
---|
| 573 | |
---|
| 574 | // Delete current description. |
---|
| 575 | if (this -> Description != NULL) |
---|
| 576 | { |
---|
| 577 | delete [] this -> Description; |
---|
| 578 | this -> Description = NULL; |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | // Copy string as new description. |
---|
| 582 | if (string != NULL) |
---|
| 583 | { |
---|
| 584 | this -> Description = new char[strlen(string) + 1]; |
---|
| 585 | strcpy(this -> Description, string); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | return; |
---|
| 589 | |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | |
---|
| 593 | //----------------------------------------------------------------------------- |
---|
| 594 | void GlobalCoordinatesToFileMapper::SetFileCoordinateDimensions(long w, |
---|
| 595 | long h) |
---|
| 596 | { |
---|
| 597 | |
---|
| 598 | // Set FileCoordinateDimensions |
---|
| 599 | this -> FileCoordinateDimensions[0] = w; |
---|
| 600 | this -> FileCoordinateDimensions[1] = h; |
---|
| 601 | |
---|
| 602 | return; |
---|
| 603 | |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | |
---|
| 607 | //----------------------------------------------------------------------------- |
---|
| 608 | void GlobalCoordinatesToFileMapper::SetInitializedFalse() |
---|
| 609 | { |
---|
| 610 | |
---|
| 611 | // Set Initialized to false. |
---|
| 612 | this -> Initialized = false; |
---|
| 613 | |
---|
| 614 | return; |
---|
| 615 | |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | |
---|
| 619 | //----------------------------------------------------------------------------- |
---|
| 620 | void GlobalCoordinatesToFileMapper::SetInitializedTrue() |
---|
| 621 | { |
---|
| 622 | |
---|
| 623 | // Set Initialized to true. |
---|
| 624 | this -> Initialized = true; |
---|
| 625 | |
---|
| 626 | return; |
---|
| 627 | |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | |
---|
| 631 | //----------------------------------------------------------------------------- |
---|
| 632 | void GlobalCoordinatesToFileMapper::SetGlobalCoordinateDimensions(long w, |
---|
| 633 | long h) |
---|
| 634 | { |
---|
| 635 | |
---|
| 636 | // Set GlobalCoordinateDimensions |
---|
| 637 | this -> GlobalCoordinateDimensions[0] = w; |
---|
| 638 | this -> GlobalCoordinateDimensions[1] = h; |
---|
| 639 | |
---|
| 640 | return; |
---|
| 641 | |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | |
---|
| 645 | //----------------------------------------------------------------------------- |
---|
| 646 | void GlobalCoordinatesToFileMapper::SetGlobalFileLayoutArray(char** array, |
---|
| 647 | long cols, |
---|
| 648 | long rows) |
---|
| 649 | { |
---|
| 650 | |
---|
| 651 | // Set GlobalFileLayoutDimensions |
---|
| 652 | this -> GlobalFileLayoutDimensions[0] = cols; |
---|
| 653 | this -> GlobalFileLayoutDimensions[1] = rows; |
---|
| 654 | |
---|
| 655 | return; |
---|
| 656 | |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | |
---|
| 660 | //----------------------------------------------------------------------------- |
---|
| 661 | void GlobalCoordinatesToFileMapper::SetGlobalFileLayoutDimensions(long cols, |
---|
| 662 | long rows) |
---|
| 663 | { |
---|
| 664 | |
---|
| 665 | // Set GlobalFileLayoutDimensions |
---|
| 666 | this -> GlobalFileLayoutDimensions[0] = cols; |
---|
| 667 | this -> GlobalFileLayoutDimensions[1] = rows; |
---|
| 668 | |
---|
| 669 | return; |
---|
| 670 | |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | |
---|
| 674 | //----------------------------------------------------------------------------- |
---|
| 675 | void GlobalCoordinatesToFileMapper::SetQueryExtent(long x, long y, |
---|
| 676 | long w, long h) |
---|
| 677 | { |
---|
| 678 | |
---|
| 679 | // Set QueryExtent |
---|
| 680 | this -> QueryExtent[0] = x; |
---|
| 681 | this -> QueryExtent[1] = y; |
---|
| 682 | this -> QueryExtent[2] = w; |
---|
| 683 | this -> QueryExtent[3] = h; |
---|
| 684 | |
---|
| 685 | return; |
---|
| 686 | |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | |
---|
| 690 | //----------------------------------------------------------------------------- |
---|
| 691 | void GlobalCoordinatesToFileMapper::SetQueryFileInfoArray(FileInfo* array, |
---|
| 692 | long cols, |
---|
| 693 | long rows) |
---|
| 694 | { |
---|
| 695 | |
---|
| 696 | // Check if an array exists, and if so delete it. |
---|
| 697 | if (this -> QueryFileInfoArray != NULL) |
---|
| 698 | { |
---|
| 699 | delete [] this -> QueryFileInfoArray; |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | // Assigned array. NOTE: This is bad, very, very bad. Should be a deep |
---|
| 703 | // copy operation. |
---|
| 704 | this -> QueryFileInfoArray = array; |
---|
| 705 | |
---|
| 706 | // Set QueryFileInfoDimensions |
---|
| 707 | this -> QueryFileInfoDimensions[0] = cols; |
---|
| 708 | this -> QueryFileInfoDimensions[1] = rows; |
---|
| 709 | |
---|
| 710 | return; |
---|
| 711 | |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | |
---|
| 715 | //----------------------------------------------------------------------------- |
---|
| 716 | void GlobalCoordinatesToFileMapper::SetQueryFileInfoDimensions(long cols, |
---|
| 717 | long rows) |
---|
| 718 | { |
---|
| 719 | |
---|
| 720 | // Set QueryFileInfoDimensions |
---|
| 721 | this -> QueryFileInfoDimensions[0] = cols; |
---|
| 722 | this -> QueryFileInfoDimensions[1] = rows; |
---|
| 723 | |
---|
| 724 | return; |
---|
| 725 | |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | |
---|
| 729 | //----------------------------------------------------------------------------- |
---|
| 730 | GlobalCoordinatesToFileMapper::~GlobalCoordinatesToFileMapper() |
---|
| 731 | { |
---|
| 732 | |
---|
| 733 | // Deallocate memory used for description. |
---|
| 734 | if (this -> Description != NULL) |
---|
| 735 | { |
---|
| 736 | delete [] this -> Description; |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | // Deallocate memory used for the GlobalFileLayoutArray |
---|
| 740 | if (this -> GlobalFileLayoutArray != NULL) |
---|
| 741 | { |
---|
| 742 | for (long i = 0 ; |
---|
| 743 | i < this -> GlobalFileLayoutDimensions[0] * |
---|
| 744 | this -> GlobalFileLayoutDimensions[1] ; |
---|
| 745 | i++) |
---|
| 746 | { |
---|
| 747 | if (this -> GlobalFileLayoutArray[i] != NULL) |
---|
| 748 | { |
---|
| 749 | delete [] this -> GlobalFileLayoutArray[i]; |
---|
| 750 | } |
---|
| 751 | } |
---|
| 752 | delete [] this -> GlobalFileLayoutArray; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | // Deallocate memory for QueryFileInfoArray |
---|
| 756 | if (this -> QueryFileInfoArray != NULL) |
---|
| 757 | { |
---|
| 758 | delete [] this -> QueryFileInfoArray; |
---|
| 759 | } |
---|
| 760 | |
---|
| 761 | } |
---|