Commit 2b2b756e4638df4b58b4e1fc8014c4df67b183cc
1 parent
5bb02694
renamed
Showing
2 changed files
with
0 additions
and
781 deletions
include/GFitsDblImage.hpp deleted
| 1 | -/*************************************************************************** | |
| 2 | - * GFitsDblImage.hpp - FITS double precision image class * | |
| 3 | - * ----------------------------------------------------------------------- * | |
| 4 | - * copyright (C) 2008 by Jurgen Knodlseder * | |
| 5 | - * ----------------------------------------------------------------------- * | |
| 6 | - * * | |
| 7 | - * This program is free software; you can redistribute it and/or modify * | |
| 8 | - * it under the terms of the GNU General Public License as published by * | |
| 9 | - * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | - * (at your option) any later version. * | |
| 11 | - * * | |
| 12 | - ***************************************************************************/ | |
| 13 | -/** | |
| 14 | - * @file GFitsDblImage.hpp | |
| 15 | - * @brief GFitsDblImage class definition. | |
| 16 | - * @author J. Knodlseder | |
| 17 | - */ | |
| 18 | - | |
| 19 | -#ifndef GFITSDBLIMAGE_HPP | |
| 20 | -#define GFITSDBLIMAGE_HPP | |
| 21 | - | |
| 22 | -/* __ Includes ___________________________________________________________ */ | |
| 23 | -#include "GFitsCfitsio.hpp" | |
| 24 | -#include "GFitsData.hpp" | |
| 25 | -#include "GFitsImage.hpp" | |
| 26 | - | |
| 27 | -/* __ Namespaces _________________________________________________________ */ | |
| 28 | - | |
| 29 | - | |
| 30 | -/***********************************************************************//** | |
| 31 | - * @class GFitsDblImage | |
| 32 | - * | |
| 33 | - * @brief Implements a FITS double precision image | |
| 34 | - * | |
| 35 | - ***************************************************************************/ | |
| 36 | -class GFitsDblImage : public GFitsImage { | |
| 37 | - | |
| 38 | -public: | |
| 39 | - // Constructors and destructors | |
| 40 | - GFitsDblImage(); | |
| 41 | - GFitsDblImage(int naxis, const int* naxes); | |
| 42 | - GFitsDblImage(int naxis, const int* naxes, const double* pixels); | |
| 43 | - GFitsDblImage(const GFitsDblImage& image); | |
| 44 | - ~GFitsDblImage(); | |
| 45 | - | |
| 46 | - // Operators | |
| 47 | - GFitsDblImage& operator= (const GFitsDblImage& image); | |
| 48 | - double& operator() (const int& ix); | |
| 49 | - const double& operator() (const int& ix) const; | |
| 50 | - double& operator() (const int& ix, const int& iy); | |
| 51 | - const double& operator() (const int& ix, const int& iy) const; | |
| 52 | - double& operator() (const int& ix, const int& iy, const int& iz); | |
| 53 | - const double& operator() (const int& ix, const int& iy, const int& iz) | |
| 54 | - const; | |
| 55 | - double& operator() (const int& ix, const int& iy, const int& iz, | |
| 56 | - const int& it); | |
| 57 | - const double& operator() (const int& ix, const int& iy, const int& iz, | |
| 58 | - const int& it) const; | |
| 59 | - | |
| 60 | - // Methods | |
| 61 | - void link(double* pixels); | |
| 62 | - void set_nullval(const double* value); | |
| 63 | - | |
| 64 | -private: | |
| 65 | - // Private methods | |
| 66 | - void init_members(void); | |
| 67 | - void copy_members(const GFitsDblImage& image); | |
| 68 | - void free_members(void); | |
| 69 | - void fetch_pixels(void); | |
| 70 | - void open(__fitsfile* fptr); | |
| 71 | - void save(void); | |
| 72 | - void close(void); | |
| 73 | - GFitsDblImage* clone(void) const; | |
| 74 | - | |
| 75 | - // Private data area | |
| 76 | - int m_linked; // Pixels are linked (don't delete them!) | |
| 77 | - double* m_pixels; // Pixels | |
| 78 | - double* m_nulval; // NULL value | |
| 79 | - int m_anynul; // Number of NULLs encountered | |
| 80 | -}; | |
| 81 | - | |
| 82 | -#endif /* GFITSDBLIMAGE_HPP */ |
src/fits/GFitsDblImage.cpp deleted
| 1 | -/*************************************************************************** | |
| 2 | - * GFitsDblImage.cpp - FITS double precision image class * | |
| 3 | - * ----------------------------------------------------------------------- * | |
| 4 | - * copyright : (C) 2008 by Jurgen Knodlseder * | |
| 5 | - * ----------------------------------------------------------------------- * | |
| 6 | - * * | |
| 7 | - * This program is free software; you can redistribute it and/or modify * | |
| 8 | - * it under the terms of the GNU General Public License as published by * | |
| 9 | - * the Free Software Foundation; either version 2 of the License, or * | |
| 10 | - * (at your option) any later version. * | |
| 11 | - * * | |
| 12 | - * ----------------------------------------------------------------------- * | |
| 13 | - ***************************************************************************/ | |
| 14 | - | |
| 15 | -/* __ Includes ___________________________________________________________ */ | |
| 16 | -#include <iostream> | |
| 17 | -#include "GException.hpp" | |
| 18 | -#include "GFitsDblImage.hpp" | |
| 19 | - | |
| 20 | -/* __ Namespaces _________________________________________________________ */ | |
| 21 | - | |
| 22 | -/* __ Method name definitions ____________________________________________ */ | |
| 23 | -#define G_OPERATOR2 "GFitsDblImage::operator() (int, int)" | |
| 24 | -#define G_OPEN "GFitsDblImage::open(fitsfile*)" | |
| 25 | -#define G_SAVE "GFitsDblImage::save()" | |
| 26 | - | |
| 27 | -/* __ Macros _____________________________________________________________ */ | |
| 28 | - | |
| 29 | -/* __ Coding definitions _________________________________________________ */ | |
| 30 | - | |
| 31 | -/* __ Debug definitions __________________________________________________ */ | |
| 32 | - | |
| 33 | - | |
| 34 | - | |
| 35 | -/*========================================================================== | |
| 36 | - = = | |
| 37 | - = GFitsDblImage constructors/destructors = | |
| 38 | - = = | |
| 39 | - ==========================================================================*/ | |
| 40 | - | |
| 41 | -/***********************************************************************//** | |
| 42 | - * @brief Constructor | |
| 43 | - ***************************************************************************/ | |
| 44 | -GFitsDblImage::GFitsDblImage() : GFitsImage() | |
| 45 | -{ | |
| 46 | - // Initialise class members for clean destruction | |
| 47 | - init_members(); | |
| 48 | - | |
| 49 | - // Set bitpix | |
| 50 | - m_bitpix = -64; | |
| 51 | - | |
| 52 | - // Return | |
| 53 | - return; | |
| 54 | -} | |
| 55 | - | |
| 56 | - | |
| 57 | -/***********************************************************************//** | |
| 58 | - * @brief Constructor | |
| 59 | - * | |
| 60 | - * @param naxis Image dimension (0,1,2,3,4) | |
| 61 | - * @param naxes Number of pixels in each dimension | |
| 62 | - * | |
| 63 | - * Construct instance of GFitsDblImage by specifying the image dimension and | |
| 64 | - * the number of pixels in each dimension. Note that this constructor does | |
| 65 | - * not allocate any memory for the actual image. | |
| 66 | - ***************************************************************************/ | |
| 67 | -GFitsDblImage::GFitsDblImage(int naxis, const int* naxes) : GFitsImage(naxis, naxes) | |
| 68 | -{ | |
| 69 | - // Initialise class members for clean destruction | |
| 70 | - init_members(); | |
| 71 | - | |
| 72 | - // Set bitpix | |
| 73 | - m_bitpix = -64; | |
| 74 | - | |
| 75 | - // Return | |
| 76 | - return; | |
| 77 | -} | |
| 78 | - | |
| 79 | - | |
| 80 | -/***********************************************************************//** | |
| 81 | - * @brief Constructor | |
| 82 | - * | |
| 83 | - * @param naxis Image dimension (0,1,2,3,4) | |
| 84 | - * @param naxes Number of pixels in each dimension | |
| 85 | - * @param pixels Pointer to image pixel array | |
| 86 | - * | |
| 87 | - * Construct instance of GFitsDblImage by specifying the image dimension, the | |
| 88 | - * number of pixels in each dimension and an image pixel array. If the | |
| 89 | - * 'pixels' pointer is valid (i.e. not NULL) the pixel data is indeed copied | |
| 90 | - * by this constructor. In case of memory shortage a combination of | |
| 91 | - * GFitsDblImage::GFitsDblImage(int naxis, const int* naxes) | |
| 92 | - * and | |
| 93 | - * GFitsDblImage::link(double* pixels) | |
| 94 | - * may be prefered to avoid duplication of the pixel data. | |
| 95 | - ***************************************************************************/ | |
| 96 | -GFitsDblImage::GFitsDblImage(int naxis, const int* naxes, const double* pixels) | |
| 97 | - : GFitsImage(naxis, naxes) | |
| 98 | -{ | |
| 99 | - // Initialise class members for clean destruction | |
| 100 | - init_members(); | |
| 101 | - | |
| 102 | - // Copy pixels into object | |
| 103 | - if (m_num_pixels > 0 && pixels != NULL) { | |
| 104 | - m_pixels = new double[m_num_pixels]; | |
| 105 | - memcpy(m_pixels, pixels, m_num_pixels*sizeof(double)); | |
| 106 | - } | |
| 107 | - | |
| 108 | - // Set bitpix | |
| 109 | - m_bitpix = -64; | |
| 110 | - | |
| 111 | - // Return | |
| 112 | - return; | |
| 113 | -} | |
| 114 | - | |
| 115 | - | |
| 116 | -/***********************************************************************//** | |
| 117 | - * @brief Copy constructor | |
| 118 | - * | |
| 119 | - * @param image FITS image which should be used for construction | |
| 120 | - ***************************************************************************/ | |
| 121 | -GFitsDblImage::GFitsDblImage(const GFitsDblImage& image) : GFitsImage(image) | |
| 122 | -{ | |
| 123 | - // Initialise class members for clean destruction | |
| 124 | - init_members(); | |
| 125 | - | |
| 126 | - // Copy members | |
| 127 | - copy_members(image); | |
| 128 | - | |
| 129 | - // Return | |
| 130 | - return; | |
| 131 | -} | |
| 132 | - | |
| 133 | - | |
| 134 | -/***********************************************************************//** | |
| 135 | - * @brief Destructor | |
| 136 | - ***************************************************************************/ | |
| 137 | -GFitsDblImage::~GFitsDblImage() | |
| 138 | -{ | |
| 139 | - // Free members | |
| 140 | - free_members(); | |
| 141 | - | |
| 142 | - // Return | |
| 143 | - return; | |
| 144 | -} | |
| 145 | - | |
| 146 | - | |
| 147 | -/*========================================================================== | |
| 148 | - = = | |
| 149 | - = GFitsDblImage operators = | |
| 150 | - = = | |
| 151 | - ==========================================================================*/ | |
| 152 | - | |
| 153 | -/***********************************************************************//** | |
| 154 | - * @brief Assignment operator | |
| 155 | - * | |
| 156 | - * @param image FITS image to be assigned | |
| 157 | - ***************************************************************************/ | |
| 158 | -GFitsDblImage& GFitsDblImage::operator= (const GFitsDblImage& image) | |
| 159 | -{ | |
| 160 | - // Execute only if object is not identical | |
| 161 | - if (this != &image) { | |
| 162 | - | |
| 163 | - // Copy base class members | |
| 164 | - this->GFitsImage::operator=(image); | |
| 165 | - | |
| 166 | - // Free members | |
| 167 | - free_members(); | |
| 168 | - | |
| 169 | - // Initialise private members for clean destruction | |
| 170 | - init_members(); | |
| 171 | - | |
| 172 | - // Copy members | |
| 173 | - copy_members(image); | |
| 174 | - | |
| 175 | - } // endif: object was not identical | |
| 176 | - | |
| 177 | - // Return this object | |
| 178 | - return *this; | |
| 179 | -} | |
| 180 | - | |
| 181 | - | |
| 182 | -/***********************************************************************//** | |
| 183 | - * @brief 1D image pixel access operator | |
| 184 | - * | |
| 185 | - * @param[in] ix Pixel index | |
| 186 | - * | |
| 187 | - * @exception GException::fits_wrong_image_operator | |
| 188 | - * Image is not a 1D image | |
| 189 | - * | |
| 190 | - * Provides access to a pixel of a 1D image. No range checking is performed. | |
| 191 | - * Use the at(ix) method if range checking is required. | |
| 192 | - ***************************************************************************/ | |
| 193 | -double& GFitsDblImage::operator() (const int& ix) | |
| 194 | -{ | |
| 195 | - // Operator is only valid for 1D images | |
| 196 | - if (m_naxis != 1) | |
| 197 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 1); | |
| 198 | - | |
| 199 | - // If image pixels are not available then allocate them now | |
| 200 | - if (m_pixels == NULL) fetch_pixels(); | |
| 201 | - | |
| 202 | - // Return image pixel | |
| 203 | - return m_pixels[ix]; | |
| 204 | -} | |
| 205 | - | |
| 206 | - | |
| 207 | -/***********************************************************************//** | |
| 208 | - * @brief 1D image pixel access operator (const variant) | |
| 209 | - * | |
| 210 | - * @param[in] ix Pixel index | |
| 211 | - * | |
| 212 | - * @exception GException::fits_wrong_image_operator | |
| 213 | - * Image is not a 1D image | |
| 214 | - * | |
| 215 | - * Provides access to a pixel of a 1D image. No range checking is performed. | |
| 216 | - * Use the at(ix) method if range checking is required. | |
| 217 | - ***************************************************************************/ | |
| 218 | -const double& GFitsDblImage::operator() (const int& ix) const | |
| 219 | -{ | |
| 220 | - // Operator is only valid for 1D images | |
| 221 | - if (m_naxis != 1) | |
| 222 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 1); | |
| 223 | - | |
| 224 | - // If image pixels are not available then allocate them now | |
| 225 | - if (m_pixels == NULL) ((GFitsDblImage*)this)->fetch_pixels(); | |
| 226 | - | |
| 227 | - // Return image pixel | |
| 228 | - return m_pixels[ix]; | |
| 229 | -} | |
| 230 | - | |
| 231 | - | |
| 232 | -/***********************************************************************//** | |
| 233 | - * @brief 2D image pixel access operator | |
| 234 | - * | |
| 235 | - * @param[in] ix Pixel index in first dimension | |
| 236 | - * @param[in] iy Pixel index in second dimension | |
| 237 | - * | |
| 238 | - * @exception GException::fits_wrong_image_operator | |
| 239 | - * Image is not a 2D image | |
| 240 | - * | |
| 241 | - * Provides access to a pixel of a 2D image. No range checking is performed. | |
| 242 | - * Use the at(ix,iy) method if range checking is required. | |
| 243 | - ***************************************************************************/ | |
| 244 | -double& GFitsDblImage::operator() (const int& ix, const int& iy) | |
| 245 | -{ | |
| 246 | - // Operator is only valid for 2D images | |
| 247 | - if (m_naxis != 2) | |
| 248 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 2); | |
| 249 | - | |
| 250 | - // If image pixels are not available then allocate them now | |
| 251 | - if (m_pixels == NULL) fetch_pixels(); | |
| 252 | - | |
| 253 | - // Calculate pixel offset | |
| 254 | - int offset = ix + iy * m_naxes[0]; | |
| 255 | - | |
| 256 | - // Return image pixel | |
| 257 | - return m_pixels[offset]; | |
| 258 | -} | |
| 259 | - | |
| 260 | - | |
| 261 | -/***********************************************************************//** | |
| 262 | - * @brief 2D image pixel access operator (const variant) | |
| 263 | - * | |
| 264 | - * @param[in] ix Pixel index in first dimension | |
| 265 | - * @param[in] iy Pixel index in second dimension | |
| 266 | - * | |
| 267 | - * @exception GException::fits_wrong_image_operator | |
| 268 | - * Image is not a 2D image | |
| 269 | - * | |
| 270 | - * Provides access to a pixel of a 2D image. No range checking is performed. | |
| 271 | - * Use the at(ix,iy) method if range checking is required. | |
| 272 | - ***************************************************************************/ | |
| 273 | -const double& GFitsDblImage::operator() (const int& ix, const int& iy) const | |
| 274 | -{ | |
| 275 | - // Operator is only valid for 2D images | |
| 276 | - if (m_naxis != 2) | |
| 277 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 2); | |
| 278 | - | |
| 279 | - // If image pixels are not available then allocate them now | |
| 280 | - if (m_pixels == NULL) ((GFitsDblImage*)this)->fetch_pixels(); | |
| 281 | - | |
| 282 | - // Calculate pixel offset | |
| 283 | - int offset = ix + iy * m_naxes[0]; | |
| 284 | - | |
| 285 | - // Return image pixel | |
| 286 | - return m_pixels[offset]; | |
| 287 | -} | |
| 288 | - | |
| 289 | - | |
| 290 | -/***********************************************************************//** | |
| 291 | - * @brief 3D image pixel access operator | |
| 292 | - * | |
| 293 | - * @param[in] ix Pixel index in first dimension | |
| 294 | - * @param[in] iy Pixel index in second dimension | |
| 295 | - * @param[in] iz Pixel index in third dimension | |
| 296 | - * | |
| 297 | - * @exception GException::fits_wrong_image_operator | |
| 298 | - * Image is not a 3D image | |
| 299 | - * | |
| 300 | - * Provides access to a pixel of a 3D image. No range checking is performed. | |
| 301 | - * Use the at(ix,iy,iz) method if range checking is required. | |
| 302 | - ***************************************************************************/ | |
| 303 | -double& GFitsDblImage::operator() (const int& ix, const int& iy, const int& iz) | |
| 304 | -{ | |
| 305 | - // Operator is only valid for 3D images | |
| 306 | - if (m_naxis != 3) | |
| 307 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 3); | |
| 308 | - | |
| 309 | - // If image pixels are not available then allocate them now | |
| 310 | - if (m_pixels == NULL) fetch_pixels(); | |
| 311 | - | |
| 312 | - // Calculate pixel offset | |
| 313 | - int offset = ix + m_naxes[0] * (iy + iz * m_naxes[1]); | |
| 314 | - | |
| 315 | - // Return image pixel | |
| 316 | - return m_pixels[offset]; | |
| 317 | -} | |
| 318 | - | |
| 319 | - | |
| 320 | -/***********************************************************************//** | |
| 321 | - * @brief 3D image pixel access operator (const variant) | |
| 322 | - * | |
| 323 | - * @param[in] ix Pixel index in first dimension | |
| 324 | - * @param[in] iy Pixel index in second dimension | |
| 325 | - * @param[in] iz Pixel index in third dimension | |
| 326 | - * | |
| 327 | - * @exception GException::fits_wrong_image_operator | |
| 328 | - * Image is not a 3D image | |
| 329 | - * | |
| 330 | - * Provides access to a pixel of a 3D image. No range checking is performed. | |
| 331 | - * Use the at(ix,iy,iz) method if range checking is required. | |
| 332 | - ***************************************************************************/ | |
| 333 | -const double& GFitsDblImage::operator() (const int& ix, const int& iy, const int& iz) const | |
| 334 | -{ | |
| 335 | - // Operator is only valid for 3D images | |
| 336 | - if (m_naxis != 3) | |
| 337 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 3); | |
| 338 | - | |
| 339 | - // If image pixels are not available then allocate them now | |
| 340 | - if (m_pixels == NULL) ((GFitsDblImage*)this)->fetch_pixels(); | |
| 341 | - | |
| 342 | - // Calculate pixel offset | |
| 343 | - int offset = ix + m_naxes[0] * (iy + iz * m_naxes[1]); | |
| 344 | - | |
| 345 | - // Return image pixel | |
| 346 | - return m_pixels[offset]; | |
| 347 | -} | |
| 348 | - | |
| 349 | - | |
| 350 | -/***********************************************************************//** | |
| 351 | - * @brief 4D image pixel access operator | |
| 352 | - * | |
| 353 | - * @param[in] ix Pixel index in first dimension | |
| 354 | - * @param[in] iy Pixel index in second dimension | |
| 355 | - * @param[in] iz Pixel index in third dimension | |
| 356 | - * @param[in] it Pixel index in forth dimension | |
| 357 | - * | |
| 358 | - * @exception GException::fits_wrong_image_operator | |
| 359 | - * Image is not a 4D image | |
| 360 | - * | |
| 361 | - * Provides access to a pixel of a 4D image. No range checking is performed. | |
| 362 | - * Use the at(ix,iy,iz,it) method if range checking is required. | |
| 363 | - ***************************************************************************/ | |
| 364 | -double& GFitsDblImage::operator() (const int& ix, const int& iy, const int& iz, const int& it) | |
| 365 | -{ | |
| 366 | - // Operator is only valid for 4D images | |
| 367 | - if (m_naxis != 4) | |
| 368 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 4); | |
| 369 | - | |
| 370 | - // If image pixels are not available then allocate them now | |
| 371 | - if (m_pixels == NULL) fetch_pixels(); | |
| 372 | - | |
| 373 | - // Calculate pixel offset | |
| 374 | - int offset = ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2])); | |
| 375 | - | |
| 376 | - // Return image pixel | |
| 377 | - return m_pixels[offset]; | |
| 378 | -} | |
| 379 | - | |
| 380 | - | |
| 381 | -/***********************************************************************//** | |
| 382 | - * @brief 4D image pixel access operator (const variant) | |
| 383 | - * | |
| 384 | - * @param[in] ix Pixel index in first dimension | |
| 385 | - * @param[in] iy Pixel index in second dimension | |
| 386 | - * @param[in] iz Pixel index in third dimension | |
| 387 | - * @param[in] it Pixel index in forth dimension | |
| 388 | - * | |
| 389 | - * @exception GException::fits_wrong_image_operator | |
| 390 | - * Image is not a 4D image | |
| 391 | - * | |
| 392 | - * Provides access to a pixel of a 4D image. No range checking is performed. | |
| 393 | - * Use the at(ix,iy,iz,it) method if range checking is required. | |
| 394 | - ***************************************************************************/ | |
| 395 | -const double& GFitsDblImage::operator() (const int& ix, const int& iy, const int& iz, const int& it) const | |
| 396 | -{ | |
| 397 | - // Operator is only valid for 4D images | |
| 398 | - if (m_naxis != 4) | |
| 399 | - throw GException::fits_wrong_image_operator(G_OPERATOR2, m_naxis, 4); | |
| 400 | - | |
| 401 | - // If image pixels are not available then allocate them now | |
| 402 | - if (m_pixels == NULL) ((GFitsDblImage*)this)->fetch_pixels(); | |
| 403 | - | |
| 404 | - // Calculate pixel offset | |
| 405 | - int offset = ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2])); | |
| 406 | - | |
| 407 | - // Return image pixel | |
| 408 | - return m_pixels[offset]; | |
| 409 | -} | |
| 410 | - | |
| 411 | - | |
| 412 | -/*========================================================================== | |
| 413 | - = = | |
| 414 | - = GFitsDblImage public methods = | |
| 415 | - = = | |
| 416 | - ==========================================================================*/ | |
| 417 | - | |
| 418 | -/***********************************************************************//** | |
| 419 | - * @brief Link external pixel array to image | |
| 420 | - * | |
| 421 | - * @param pixels Pointer to external pixel array that should be linked | |
| 422 | - * | |
| 423 | - * This method allows to use an externally allocated pixel array within | |
| 424 | - * the class. No control over the existence of this pixel array is performed | |
| 425 | - * hence the user has to assure its existence over the entire lifetime of | |
| 426 | - * the class instance. Using of an externally allocated array may be | |
| 427 | - * preferred in case of large image arrays that are created outside the | |
| 428 | - * class. In this case linking prevents a duplication of the image array. | |
| 429 | - * In all other cases, linking should be better avoided. | |
| 430 | - ***************************************************************************/ | |
| 431 | -void GFitsDblImage::link(double* pixels) | |
| 432 | -{ | |
| 433 | - // Free any existing pixels | |
| 434 | - if (!m_linked) { | |
| 435 | - if (m_pixels != NULL) delete [] m_pixels; | |
| 436 | - } | |
| 437 | - | |
| 438 | - // Link pixel array to image | |
| 439 | - m_pixels = pixels; | |
| 440 | - | |
| 441 | - // Flag that pixels have been linked | |
| 442 | - m_linked = 1; | |
| 443 | - | |
| 444 | - // Return | |
| 445 | - return; | |
| 446 | -} | |
| 447 | - | |
| 448 | - | |
| 449 | -/***********************************************************************//** | |
| 450 | - * @brief Clone FITS image | |
| 451 | - * | |
| 452 | - * Cloning provides a copy of the FITS file. Cloning is used to allocate | |
| 453 | - * derived classes into a base class pointer. | |
| 454 | - ***************************************************************************/ | |
| 455 | -GFitsDblImage* GFitsDblImage::clone(void) const | |
| 456 | -{ | |
| 457 | - // Clone this image | |
| 458 | - return new GFitsDblImage(*this); | |
| 459 | -} | |
| 460 | - | |
| 461 | - | |
| 462 | -/***********************************************************************//** | |
| 463 | - * @brief Set NULL value | |
| 464 | - * | |
| 465 | - * @param value Value to which NULL pixels should be set | |
| 466 | - * | |
| 467 | - * NOTE: FOR THE MOMENT THE IMAGE IS NOT RE-LOADED IF THE NULL VALUE IS | |
| 468 | - * CHANGED !!!! | |
| 469 | - ***************************************************************************/ | |
| 470 | -void GFitsDblImage::set_nullval(const double* value) | |
| 471 | -{ | |
| 472 | - // If NULL value is empty then reset the NULL value | |
| 473 | - if (value == NULL) { | |
| 474 | - if (m_nulval != NULL) delete m_nulval; | |
| 475 | - m_nulval = NULL; | |
| 476 | - } | |
| 477 | - | |
| 478 | - // ... otherwise copy value into NULL value | |
| 479 | - else { | |
| 480 | - if (m_nulval != NULL) delete m_nulval; | |
| 481 | - m_nulval = new double; | |
| 482 | - *m_nulval = *value; | |
| 483 | - } | |
| 484 | - | |
| 485 | - // Re-load image | |
| 486 | - // NOTE: THIS WILL LEAD TO A LOSS OF MODIFICATIONS; ISSUE SAVE BEFORE !!! | |
| 487 | - //if (m_data != NULL) { | |
| 488 | - // //save(); | |
| 489 | - // load(); | |
| 490 | - //} | |
| 491 | - | |
| 492 | - // Return | |
| 493 | - return; | |
| 494 | -} | |
| 495 | - | |
| 496 | - | |
| 497 | -/*========================================================================== | |
| 498 | - = = | |
| 499 | - = GFitsDblImage private methods = | |
| 500 | - = = | |
| 501 | - ==========================================================================*/ | |
| 502 | - | |
| 503 | -/***********************************************************************//** | |
| 504 | - * @brief Initialise class members | |
| 505 | - ***************************************************************************/ | |
| 506 | -void GFitsDblImage::init_members(void) | |
| 507 | -{ | |
| 508 | - // Initialise members | |
| 509 | - m_linked = 0; | |
| 510 | - m_pixels = NULL; | |
| 511 | - m_anynul = 0; | |
| 512 | - m_nulval = NULL; | |
| 513 | - | |
| 514 | - // Return | |
| 515 | - return; | |
| 516 | -} | |
| 517 | - | |
| 518 | - | |
| 519 | -/***********************************************************************//** | |
| 520 | - * @brief Copy class members | |
| 521 | - * | |
| 522 | - * @param image FITS image to copy | |
| 523 | - * | |
| 524 | - * Copy class members. If the pixel array is linked the pointer to the array | |
| 525 | - * is copied. Otherwise a copy of the image pixels will be created. | |
| 526 | - ***************************************************************************/ | |
| 527 | -void GFitsDblImage::copy_members(const GFitsDblImage& image) | |
| 528 | -{ | |
| 529 | - // Copy attributes | |
| 530 | - m_linked = image.m_linked; | |
| 531 | - m_anynul = image.m_anynul; | |
| 532 | - | |
| 533 | - // Copy pixels | |
| 534 | - if (m_linked) | |
| 535 | - m_pixels = image.m_pixels; | |
| 536 | - else { | |
| 537 | - if (m_num_pixels > 0 && image.m_pixels != NULL) { | |
| 538 | - m_pixels = new double[m_num_pixels]; | |
| 539 | - memcpy(m_pixels, image.m_pixels, m_num_pixels*sizeof(double)); | |
| 540 | - } | |
| 541 | - } | |
| 542 | - | |
| 543 | - // Copy NULL value | |
| 544 | - if (image.m_nulval != NULL) { | |
| 545 | - if (m_nulval != NULL) delete m_nulval; | |
| 546 | - m_nulval = new double; | |
| 547 | - *m_nulval = *image.m_nulval; | |
| 548 | - } | |
| 549 | - | |
| 550 | - // Return | |
| 551 | - return; | |
| 552 | -} | |
| 553 | - | |
| 554 | - | |
| 555 | -/***********************************************************************//** | |
| 556 | - * @brief Delete class members | |
| 557 | - ***************************************************************************/ | |
| 558 | -void GFitsDblImage::free_members(void) | |
| 559 | -{ | |
| 560 | - // If we have proper pixels then free them now | |
| 561 | - if (!m_linked) { | |
| 562 | - if (m_pixels != NULL) delete [] m_pixels; | |
| 563 | - } | |
| 564 | - | |
| 565 | - // Free NULL value | |
| 566 | - if (m_nulval != NULL) delete m_nulval; | |
| 567 | - | |
| 568 | - // Mark memory as free | |
| 569 | - m_linked = 0; | |
| 570 | - m_pixels = NULL; | |
| 571 | - m_nulval = NULL; | |
| 572 | - | |
| 573 | - // Return | |
| 574 | - return; | |
| 575 | -} | |
| 576 | - | |
| 577 | - | |
| 578 | -/***********************************************************************//** | |
| 579 | - * @brief Fetch image pixels | |
| 580 | - * | |
| 581 | - * Fetch the image pixels. This function is in general called if pixel | |
| 582 | - * values should be read or written yet no pixel array is allocated. In case | |
| 583 | - * that pixels existed already before they will be deleted before fetching | |
| 584 | - * new ones. | |
| 585 | - * There are two possibilities to fetch the pixels: | |
| 586 | - * (1) In case that a FITS file is attached to the image the pixel array | |
| 587 | - * will be loaded from the file. | |
| 588 | - * (2) In case that no FITS file is attached a new pixel array will be | |
| 589 | - * allocated that is initalised to 0. | |
| 590 | - ***************************************************************************/ | |
| 591 | -void GFitsDblImage::fetch_pixels(void) | |
| 592 | -{ | |
| 593 | - // Fetch only if there are pixels in image | |
| 594 | - if (m_num_pixels > 0) { | |
| 595 | - | |
| 596 | - // If we have pixels allocated then free them now | |
| 597 | - if (!m_linked) { | |
| 598 | - if (m_pixels != NULL) delete [] m_pixels; | |
| 599 | - } | |
| 600 | - | |
| 601 | - // Allocate fresh image pixels | |
| 602 | - m_pixels = new double[m_num_pixels]; | |
| 603 | - | |
| 604 | - // Case 1: A FITS is attached. Load pixels now. | |
| 605 | - if (m_fitsfile.Fptr != NULL) | |
| 606 | - load_image(__TDOUBLE, m_pixels, m_nulval, &m_anynul); | |
| 607 | - | |
| 608 | - // Case 2: No FITS file is attached. Allocate pixels and set them all to 0.0 | |
| 609 | - else { | |
| 610 | - for (int i = 0; i < m_num_pixels; ++i) | |
| 611 | - m_pixels[i] = 0.0; | |
| 612 | - } | |
| 613 | - | |
| 614 | - // Mark pixel as proper to the class instance | |
| 615 | - m_linked = 0; | |
| 616 | - } | |
| 617 | - | |
| 618 | - // Return | |
| 619 | - return; | |
| 620 | -} | |
| 621 | - | |
| 622 | - | |
| 623 | -/***********************************************************************//** | |
| 624 | - * @brief Open FITS image | |
| 625 | - * | |
| 626 | - * @param fptr FITS file pointer | |
| 627 | - * | |
| 628 | - * Open FITS image in FITS file. Opening means connecting the FITS file | |
| 629 | - * pointer to the image and reading the image and axes dimensions. | |
| 630 | - ***************************************************************************/ | |
| 631 | -void GFitsDblImage::open(__fitsfile* fptr) | |
| 632 | -{ | |
| 633 | - // Initialise base class members | |
| 634 | - GFitsImage::init_members(); | |
| 635 | - | |
| 636 | - // Initialise class members | |
| 637 | - init_members(); | |
| 638 | - | |
| 639 | - // Open image | |
| 640 | - open_image(fptr); | |
| 641 | - | |
| 642 | - // Return | |
| 643 | - return; | |
| 644 | -} | |
| 645 | - | |
| 646 | - | |
| 647 | -/***********************************************************************//** | |
| 648 | - * @brief Save FITS image | |
| 649 | - * | |
| 650 | - * Saves the image into the FITS file. | |
| 651 | - ***************************************************************************/ | |
| 652 | -void GFitsDblImage::save(void) | |
| 653 | -{ | |
| 654 | - // Save a double precision image | |
| 655 | - save_image(__TDOUBLE, m_pixels); | |
| 656 | - | |
| 657 | - // Return | |
| 658 | - return; | |
| 659 | -} | |
| 660 | - | |
| 661 | - | |
| 662 | -/***********************************************************************//** | |
| 663 | - * @brief Close FITS image | |
| 664 | - * | |
| 665 | - * Closing a FITS image resets the object into its initial state. Closing | |
| 666 | - * does NOT save the image into the FITS file. Use the save method for this | |
| 667 | - * purpose. | |
| 668 | - ***************************************************************************/ | |
| 669 | -void GFitsDblImage::close(void) | |
| 670 | -{ | |
| 671 | - // Free members | |
| 672 | - free_members(); | |
| 673 | - | |
| 674 | - // Initialise members | |
| 675 | - init_members(); | |
| 676 | - | |
| 677 | - // Free base class members | |
| 678 | - GFitsImage::free_members(); | |
| 679 | - | |
| 680 | - // Initialise base class members | |
| 681 | - GFitsImage::init_members(); | |
| 682 | - | |
| 683 | - // Return | |
| 684 | - return; | |
| 685 | -} | |
| 686 | - | |
| 687 | - | |
| 688 | -/*========================================================================== | |
| 689 | - = = | |
| 690 | - = GFitsDblImage friends = | |
| 691 | - = = | |
| 692 | - ==========================================================================*/ | |
| 693 | - | |
| 694 | - | |
| 695 | -/*========================================================================== | |
| 696 | - = = | |
| 697 | - = Other functions used by GFitsDblImage = | |
| 698 | - = = | |
| 699 | - ==========================================================================*/ |