GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsImageULong.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsImageULong.cpp - Unsigned long image FITS class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2018 by Juergen Knoedlseder *
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 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GFitsImageULong.cpp
23  * @brief Unsigned long image FITS class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GFitsCfitsio.hpp"
33 #include "GFitsImageULong.hpp"
34 
35 /* __ Method name definitions ____________________________________________ */
36 
37 /* __ Macros _____________________________________________________________ */
38 #define G_BITPIX 40 //!< Defines the number of bits per pixel
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 
45 
46 /*==========================================================================
47  = =
48  = Constructors/destructors =
49  = =
50  ==========================================================================*/
51 
52 /***********************************************************************//**
53  * @brief Void constructor
54  ***************************************************************************/
56 {
57  // Initialise class members
58  init_members();
59 
60  // Return
61  return;
62 }
63 
64 
65 /***********************************************************************//**
66  * @brief 1D image constructor
67  *
68  * @param[in] nx Number of pixels.
69  * @param[in] pixels Optional pointer to image pixel array
70  *
71  * Construct 1D instance by specifying the number of pixels in the image.
72  ***************************************************************************/
73 GFitsImageULong::GFitsImageULong(const int& nx, const unsigned long* pixels) :
74  GFitsImage(G_BITPIX, nx)
75 {
76  // Initialise class members
77  init_members();
78 
79  // Construct data
80  construct_data(pixels);
81 
82  // Return
83  return;
84 }
85 
86 
87 /***********************************************************************//**
88  * @brief 2D image constructor
89  *
90  * @param[in] nx Number of pixels in first dimension.
91  * @param[in] ny Number of pixels in second dimension.
92  * @param[in] pixels Optional pointer to image pixel array
93  *
94  * Construct 2D image by specifying the number of pixels in each dimension.
95  ***************************************************************************/
96 GFitsImageULong::GFitsImageULong(const int& nx, const int& ny,
97  const unsigned long* pixels) :
98  GFitsImage(G_BITPIX, nx, ny)
99 {
100  // Initialise class members
101  init_members();
102 
103  // Construct data
104  construct_data(pixels);
105 
106  // Return
107  return;
108 }
109 
110 
111 /***********************************************************************//**
112  * @brief 3D image constructor
113  *
114  * @param[in] nx Number of pixels in first dimension.
115  * @param[in] ny Number of pixels in second dimension.
116  * @param[in] nz Number of pixels in third dimension.
117  * @param[in] pixels Optional pointer to image pixel array
118  *
119  * Construct 3D image by specifying the number of pixels in each dimension.
120  ***************************************************************************/
121 GFitsImageULong::GFitsImageULong(const int& nx, const int& ny, const int& nz,
122  const unsigned long* pixels) :
123  GFitsImage(G_BITPIX, nx, ny, nz)
124 {
125  // Initialise class members
126  init_members();
127 
128  // Construct data
129  construct_data(pixels);
130 
131  // Return
132  return;
133 }
134 
135 
136 /***********************************************************************//**
137  * @brief 4D image constructor
138  *
139  * @param[in] nx Number of pixels in first dimension.
140  * @param[in] ny Number of pixels in second dimension.
141  * @param[in] nz Number of pixels in third dimension.
142  * @param[in] nt Number of pixels in forth dimension.
143  * @param[in] pixels Optional pointer to image pixel array
144  *
145  * Construct 4D image by specifying the number of pixels in each dimension.
146  ***************************************************************************/
147 GFitsImageULong::GFitsImageULong(const int& nx, const int& ny, const int& nz,
148  const int& nt,
149  const unsigned long* pixels) :
150  GFitsImage(G_BITPIX, nx, ny, nz, nt)
151 {
152  // Initialise class members
153  init_members();
154 
155  // Construct data
156  construct_data(pixels);
157 
158  // Return
159  return;
160 }
161 
162 
163 /***********************************************************************//**
164  * @brief Pixel array constructor
165  *
166  * @param[in] naxes Vector of number of pixels in each dimension.
167  * @param[in] pixels Optional pointer to image pixel array
168  *
169  * Construct instance of GFitsImageULong by specifying the image dimension and
170  * the number of pixels in each dimension.
171  ***************************************************************************/
172 GFitsImageULong::GFitsImageULong(const std::vector<int>& naxes,
173  const unsigned long* pixels) :
174  GFitsImage(G_BITPIX, naxes)
175 {
176  // Initialise class members
177  init_members();
178 
179  // Construct data
180  construct_data(pixels);
181 
182  // Return
183  return;
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Type conversion constructor
189  *
190  * @param[in] image FITS image.
191  *
192  * This constructor performs the conversion of any image type into an
193  * unsigned long integer image.
194  ***************************************************************************/
196  GFitsImage(image)
197 {
198  // Initialise class members
199  init_members();
200 
201  // Copy pixels
202  if (m_num_pixels > 0) {
203  m_pixels = new unsigned long[m_num_pixels];
204  for (int i = 0; i < m_num_pixels; ++i) {
205  m_pixels[i] = (unsigned long)image.pixel(i);
206  }
207  }
208 
209  // Set number of bits per pixel
210  m_bitpix = G_BITPIX;
211 
212  // Update header card
213  card("BITPIX").value(G_BITPIX);
214 
215  // Return
216  return;
217 }
218 
219 
220 /***********************************************************************//**
221  * @brief Copy constructor
222  *
223  * @param[in] image FITS image.
224  ***************************************************************************/
226  GFitsImage(image)
227 {
228  // Initialise class members
229  init_members();
230 
231  // Copy members
232  copy_members(image);
233 
234  // Return
235  return;
236 }
237 
238 
239 /***********************************************************************//**
240  * @brief Destructor
241  ***************************************************************************/
243 {
244  // Free members
245  free_members();
246 
247  // Return
248  return;
249 }
250 
251 
252 /*==========================================================================
253  = =
254  = Operators =
255  = =
256  ==========================================================================*/
257 
258 /***********************************************************************//**
259  * @brief Assignment operator
260  *
261  * @param[in] image FITS image.
262  ***************************************************************************/
264 {
265  // Execute only if object is not identical
266  if (this != &image) {
267 
268  // Copy base class members
269  this->GFitsImage::operator=(image);
270 
271  // Free members
272  free_members();
273 
274  // Initialise private members for clean destruction
275  init_members();
276 
277  // Copy members
278  copy_members(image);
279 
280  } // endif: object was not identical
281 
282  // Return this object
283  return *this;
284 }
285 
286 
287 /***********************************************************************//**
288  * @brief Image pixel access operator
289  *
290  * @param[in] ix Pixel index (starting from 0).
291  *
292  * Provides access to an image pixel. No range checking is performed.
293  * Use the at(ix) method if range checking is required.
294  ***************************************************************************/
295 unsigned long& GFitsImageULong::operator()(const int& ix)
296 {
297  // Load data
298  load_data();
299 
300  // Return image pixel
301  return m_pixels[ix];
302 }
303 
304 
305 /***********************************************************************//**
306  * @brief 2D image pixel access operator
307  *
308  * @param[in] ix Pixel index in first dimension (starting from 0).
309  * @param[in] iy Pixel index in second dimension (starting from 0).
310  *
311  * Provides access to a pixel of a 2D image. No range checking or image
312  * dimension verification is performed. Use the at(ix,iy) method if range
313  * checking and image dimension verification is required.
314  ***************************************************************************/
315 unsigned long& GFitsImageULong::operator()(const int& ix, const int& iy)
316 {
317  // Load data
318  load_data();
319 
320  // Calculate pixel offset
321  int offset = ix + iy * m_naxes[0];
322 
323  // Return image pixel
324  return m_pixels[offset];
325 }
326 
327 
328 /***********************************************************************//**
329  * @brief 3D image pixel access operator
330  *
331  * @param[in] ix Pixel index in first dimension (starting from 0).
332  * @param[in] iy Pixel index in second dimension (starting from 0).
333  * @param[in] iz Pixel index in third dimension (starting from 0).
334  *
335  * Provides access to a pixel of a 3D image. No range checking or image
336  * dimension verification is performed. Use the at(ix,iy) method if range
337  * checking and image dimension verification is required.
338  ***************************************************************************/
339 unsigned long& GFitsImageULong::operator()(const int& ix, const int& iy,
340  const int& iz)
341 {
342  // Load data
343  load_data();
344 
345  // Calculate pixel offset
346  int offset = ix + m_naxes[0] * (iy + iz * m_naxes[1]);
347 
348  // Return image pixel
349  return m_pixels[offset];
350 }
351 
352 
353 /***********************************************************************//**
354  * @brief 4D image pixel access operator
355  *
356  * @param[in] ix Pixel index in first dimension (starting from 0).
357  * @param[in] iy Pixel index in second dimension (starting from 0).
358  * @param[in] iz Pixel index in third dimension (starting from 0).
359  * @param[in] it Pixel index in forth dimension (starting from 0).
360  *
361  * Provides access to a pixel of a 4D image. No range checking or image
362  * dimension verification is performed. Use the at(ix,iy) method if range
363  * checking and image dimension verification is required.
364  ***************************************************************************/
365 unsigned long& GFitsImageULong::operator()(const int& ix, const int& iy,
366  const int& iz, const int& it)
367 {
368  // Load data
369  load_data();
370 
371  // Calculate pixel offset
372  int offset = ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2]));
373 
374  // Return image pixel
375  return m_pixels[offset];
376 }
377 
378 
379 /***********************************************************************//**
380  * @brief Image pixel access operator (const variant)
381  *
382  * @param[in] ix Pixel index (starting from 0).
383  *
384  * Provides access to an image pixel. No range checking is performed.
385  * Use the at(ix) method if range checking is required.
386  ***************************************************************************/
387 const unsigned long& GFitsImageULong::operator()(const int& ix) const
388 {
389  // Load data
390  load_data();
391 
392  // Return image pixel
393  return m_pixels[ix];
394 }
395 
396 
397 /***********************************************************************//**
398  * @brief 2D image pixel access operator (const variant)
399  *
400  * @param[in] ix Pixel index in first dimension (starting from 0).
401  * @param[in] iy Pixel index in second dimension (starting from 0).
402  *
403  * Provides access to a pixel of a 2D image. No range checking or image
404  * dimension verification is performed. Use the at(ix,iy) method if range
405  * checking and image dimension verification is required.
406  ***************************************************************************/
407 const unsigned long& GFitsImageULong::operator()(const int& ix, const int& iy) const
408 {
409  // Load data
410  load_data();
411 
412  // Calculate pixel offset
413  int offset = ix + iy * m_naxes[0];
414 
415  // Return image pixel
416  return m_pixels[offset];
417 }
418 
419 
420 /***********************************************************************//**
421  * @brief 3D image pixel access operator (const variant)
422  *
423  * @param[in] ix Pixel index in first dimension (starting from 0).
424  * @param[in] iy Pixel index in second dimension (starting from 0).
425  * @param[in] iz Pixel index in third dimension (starting from 0).
426  *
427  * Provides access to a pixel of a 3D image. No range checking or image
428  * dimension verification is performed. Use the at(ix,iy) method if range
429  * checking and image dimension verification is required.
430  ***************************************************************************/
431 const unsigned long& GFitsImageULong::operator()(const int& ix, const int& iy,
432  const int& iz) const
433 {
434  // Load data
435  load_data();
436 
437  // Calculate pixel offset
438  int offset = ix + m_naxes[0] * (iy + iz * m_naxes[1]);
439 
440  // Return image pixel
441  return m_pixels[offset];
442 }
443 
444 
445 /***********************************************************************//**
446  * @brief 4D image pixel access operator (const variant)
447  *
448  * @param[in] ix Pixel index in first dimension (starting from 0).
449  * @param[in] iy Pixel index in second dimension (starting from 0).
450  * @param[in] iz Pixel index in third dimension (starting from 0).
451  * @param[in] it Pixel index in forth dimension (starting from 0).
452  *
453  * Provides access to a pixel of a 4D image. No range checking or image
454  * dimension verification is performed. Use the at(ix,iy) method if range
455  * checking and image dimension verification is required.
456  ***************************************************************************/
457 const unsigned long& GFitsImageULong::operator()(const int& ix, const int& iy,
458  const int& iz, const int& it) const
459 {
460  // Load data
461  load_data();
462 
463  // Calculate pixel offset
464  int offset = ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2]));
465 
466  // Return image pixel
467  return m_pixels[offset];
468 }
469 
470 
471 /*==========================================================================
472  = =
473  = Public methods =
474  = =
475  ==========================================================================*/
476 
477 /***********************************************************************//**
478  * @brief Clear instance
479  *
480  * This method properly resets the object to an initial state.
481  ***************************************************************************/
483 {
484  // Free class members (base and derived classes, derived class first)
485  free_members();
486  this->GFitsImage::free_members();
487  this->GFitsHDU::free_members();
488 
489  // Initialise members
490  this->GFitsHDU::init_members();
491  this->GFitsImage::init_members();
492  init_members();
493 
494  // Return
495  return;
496 }
497 
498 
499 /***********************************************************************//**
500  * @brief Clone FITS image
501  *
502  * Cloning provides a copy of the FITS file. Cloning is used to allocate
503  * derived classes into a base class pointer.
504  ***************************************************************************/
506 {
507  // Clone this image
508  return new GFitsImageULong(*this);
509 }
510 
511 
512 /***********************************************************************//**
513  * @brief Image pixel access operator
514  *
515  * @param[in] ix Pixel index (starting from 0).
516  *
517  * Provides access to a pixel of an image including range checking. Note that
518  * this method does not necessarily restrict do 1D images but generally
519  * applies to all image dimensions.
520  ***************************************************************************/
521 unsigned long& GFitsImageULong::at(const int& ix)
522 {
523  // Load data
524  load_data();
525 
526  // Return image pixel
527  return (m_pixels[offset(ix)]);
528 }
529 
530 
531 /***********************************************************************//**
532  * @brief 2D image pixel access operator
533  *
534  * @param[in] ix Pixel index in first dimension (starting from 0).
535  * @param[in] iy Pixel index in second dimension (starting from 0).
536  *
537  * Provides access to a pixel of an image including range checking.
538  ***************************************************************************/
539 unsigned long& GFitsImageULong::at(const int& ix, const int& iy)
540 {
541  // Load data
542  load_data();
543 
544  // Return image pixel
545  return (m_pixels[offset(ix,iy)]);
546 }
547 
548 
549 /***********************************************************************//**
550  * @brief 3D image pixel access operator
551  *
552  * @param[in] ix Pixel index in first dimension (starting from 0).
553  * @param[in] iy Pixel index in second dimension (starting from 0).
554  * @param[in] iz Pixel index in third dimension (starting from 0).
555  *
556  * Provides access to a pixel of an image including range checking.
557  ***************************************************************************/
558 unsigned long& GFitsImageULong::at(const int& ix, const int& iy, const int& iz)
559 {
560  // Load data
561  load_data();
562 
563  // Return image pixel
564  return (m_pixels[offset(ix,iy,iz)]);
565 }
566 
567 
568 /***********************************************************************//**
569  * @brief 4D image pixel access operator
570  *
571  * @param[in] ix Pixel index in first dimension (starting from 0).
572  * @param[in] iy Pixel index in second dimension (starting from 0).
573  * @param[in] iz Pixel index in third dimension (starting from 0).
574  * @param[in] it Pixel index in forth dimension (starting from 0).
575  *
576  * Provides access to a pixel of an image including range checking.
577  ***************************************************************************/
578 unsigned long& GFitsImageULong::at(const int& ix, const int& iy, const int& iz,
579  const int& it)
580 {
581  // Load data
582  load_data();
583 
584  // Return image pixel
585  return (m_pixels[offset(ix,iy,iz,it)]);
586 }
587 
588 
589 /***********************************************************************//**
590  * @brief Image pixel access operator (const variant)
591  *
592  * @param[in] ix Pixel index (starting from 0).
593  *
594  * Provides access to a pixel of an image including range checking.
595  ***************************************************************************/
596 const unsigned long& GFitsImageULong::at(const int& ix) const
597 {
598  // Load data
599  load_data();
600 
601  // Return image pixel
602  return (m_pixels[offset(ix)]);
603 }
604 
605 
606 /***********************************************************************//**
607  * @brief 2D image pixel access operator (const variant)
608  *
609  * @param[in] ix Pixel index in first dimension (starting from 0).
610  * @param[in] iy Pixel index in second dimension (starting from 0).
611  *
612  * Provides access to a pixel of an image including range checking.
613  ***************************************************************************/
614 const unsigned long& GFitsImageULong::at(const int& ix, const int& iy) const
615 {
616  // Load data
617  load_data();
618 
619  // Return image pixel
620  return (m_pixels[offset(ix,iy)]);
621 }
622 
623 
624 /***********************************************************************//**
625  * @brief 3D image pixel access operator (const variant)
626  *
627  * @param[in] ix Pixel index in first dimension (starting from 0).
628  * @param[in] iy Pixel index in second dimension (starting from 0).
629  * @param[in] iz Pixel index in third dimension (starting from 0).
630  *
631  * Provides access to a pixel of an image including range checking.
632  ***************************************************************************/
633 const unsigned long& GFitsImageULong::at(const int& ix, const int& iy,
634  const int& iz) const
635 {
636  // Load data
637  load_data();
638 
639  // Return image pixel
640  return (m_pixels[offset(ix,iy,iz)]);
641 }
642 
643 
644 /***********************************************************************//**
645  * @brief 4D image pixel access operator (const variant)
646  *
647  * @param[in] ix Pixel index in first dimension (starting from 0).
648  * @param[in] iy Pixel index in second dimension (starting from 0).
649  * @param[in] iz Pixel index in third dimension (starting from 0).
650  * @param[in] it Pixel index in forth dimension (starting from 0).
651  *
652  * Provides access to a pixel of an image including range checking.
653  ***************************************************************************/
654 const unsigned long& GFitsImageULong::at(const int& ix, const int& iy,
655  const int& iz, const int& it) const
656 {
657  // Load data
658  load_data();
659 
660  // Return image pixel
661  return (m_pixels[offset(ix,iy,iz,it)]);
662 }
663 
664 
665 /***********************************************************************//**
666  * @brief Return value of image pixel
667  *
668  * @param[in] ix Pixel index (starting from 0).
669  *
670  * Returns the value of an image pixel as double precision floating point
671  * value. This method performs range checking.
672  ***************************************************************************/
673 double GFitsImageULong::pixel(const int& ix) const
674 {
675  // Return pixel value
676  return (double(this->at(ix)));
677 }
678 
679 
680 /***********************************************************************//**
681  * @brief Return value of image pixel (2D version)
682  *
683  * @param[in] ix Pixel index in first dimension (starting from 0).
684  * @param[in] iy Pixel index in second dimension (starting from 0).
685  *
686  * Returns the value of an image pixel as double precision floating point
687  * value. This method performs range checking.
688  ***************************************************************************/
689 double GFitsImageULong::pixel(const int& ix, const int& iy) const
690 {
691  // Return pixel value
692  return (double(this->at(ix,iy)));
693 }
694 
695 
696 /***********************************************************************//**
697  * @brief Return value of image pixel (3D version)
698  *
699  * @param[in] ix Pixel index in first dimension (starting from 0).
700  * @param[in] iy Pixel index in second dimension (starting from 0).
701  * @param[in] iz Pixel index in third dimension (starting from 0).
702  *
703  * Returns the value of an image pixel as double precision floating point
704  * value. This method performs range checking.
705  ***************************************************************************/
706 double GFitsImageULong::pixel(const int& ix, const int& iy, const int& iz) const
707 {
708  // Return pixel value
709  return (double(this->at(ix,iy,iz)));
710 }
711 
712 
713 /***********************************************************************//**
714  * @brief Return value of image pixel (4D version)
715  *
716  * @param[in] ix Pixel index in first dimension (starting from 0).
717  * @param[in] iy Pixel index in second dimension (starting from 0).
718  * @param[in] iz Pixel index in third dimension (starting from 0).
719  * @param[in] it Pixel index in forth dimension (starting from 0).
720  *
721  * Returns the value of an image pixel as double precision floating point
722  * value. This method performs range checking.
723  ***************************************************************************/
724 double GFitsImageULong::pixel(const int& ix, const int& iy, const int& iz,
725  const int& it) const
726 {
727  // Return pixel value
728  return (double(this->at(ix,iy,iz,it)));
729 }
730 
731 
732 /***********************************************************************//**
733  * @brief Return pointer to image pixel
734  ***************************************************************************/
736 {
737  // Load data
738  load_data();
739 
740  // Return
741  return m_pixels;
742 }
743 
744 
745 /***********************************************************************//**
746  * @brief Return image type
747  ***************************************************************************/
748 int GFitsImageULong::type(void) const
749 {
750  // Return type
751  return __TULONG;
752 }
753 
754 
755 /*==========================================================================
756  = =
757  = Private methods =
758  = =
759  ==========================================================================*/
760 
761 /***********************************************************************//**
762  * @brief Initialise class members
763  ***************************************************************************/
765 {
766  // Initialise members
767  m_bitpix = G_BITPIX;
768  m_pixels = NULL;
769  m_nulval = NULL;
770 
771  // Return
772  return;
773 }
774 
775 
776 /***********************************************************************//**
777  * @brief Copy class members
778  *
779  * @param image FITS image to copy
780  *
781  * Copy class members. If the pixel array is linked the pointer to the array
782  * is copied. Otherwise a copy of the image pixels will be created.
783  ***************************************************************************/
785 {
786  // Fetch column data if not yet fetched. The casting circumvents the
787  // const correctness
788  bool not_loaded = (image.m_pixels == NULL);
789  if (not_loaded) {
790  const_cast<GFitsImageULong*>(&image)->fetch_data();
791  }
792 
793  // Copy pixels
794  if (m_num_pixels > 0 && image.m_pixels != NULL) {
795  m_pixels = new unsigned long[m_num_pixels];
796  for (int i = 0; i < m_num_pixels; ++i) {
797  m_pixels[i] = image.m_pixels[i];
798  }
799  }
800 
801  // Copy NULL value
802  alloc_nulval(image.m_nulval);
803 
804  // Small memory option: release column if it was fetch above
805  #if defined(G_SMALL_MEMORY)
806  if (not_loaded) {
807  const_cast<GFitsImageULong*>(&image)->release_data();
808  }
809  #endif
810 
811  // Return
812  return;
813 }
814 
815 
816 /***********************************************************************//**
817  * @brief Delete class members
818  ***************************************************************************/
820 {
821  // Free memory
822  if (m_pixels != NULL) delete [] m_pixels;
823  if (m_nulval != NULL) delete m_nulval;
824 
825  // Mark memory as free
826  m_pixels = NULL;
827  m_nulval = NULL;
828 
829  // Return
830  return;
831 }
832 
833 
834 /***********************************************************************//**
835  * @brief Allocate data
836  ***************************************************************************/
838 {
839  // Release any existing data
840  release_data();
841 
842  // Allocate new data
843  if (m_num_pixels > 0) {
844  m_pixels = new unsigned long[m_num_pixels];
845  }
846 
847  // Return
848  return;
849 }
850 
851 
852 /***********************************************************************//**
853  * @brief Initialise data
854  ***************************************************************************/
856 {
857  // Initialise data if they exist
858  if (m_pixels != NULL) {
859  for (int i = 0; i < m_num_pixels; ++i) {
860  m_pixels[i] = 0;
861  }
862  }
863 
864  // Return
865  return;
866 }
867 
868 
869 /***********************************************************************//**
870  * @brief Release data
871  ***************************************************************************/
873 {
874  // Free any existing memory
875  if (m_pixels != NULL) delete [] m_pixels;
876 
877  // Mark pointer as free
878  m_pixels = NULL;
879 
880  // Return
881  return;
882 }
883 
884 
885 /***********************************************************************//**
886  * @brief Construct data from array
887  *
888  * @param[in] pixels Optional pointer to pixel array.
889  *
890  * Initialise pixel data from an optional pixel array. If the pointer is
891  * NULL the image is simply initialised. This method supports all
892  * constructors.
893  ***************************************************************************/
894 void GFitsImageULong::construct_data(const unsigned long* pixels)
895 {
896  // If there are pixels then allocate array
897  if (m_num_pixels > 0) {
898 
899  // Allocate data
900  alloc_data();
901 
902  // If no pixel array has been specified then simply initialise data
903  if (pixels == NULL) {
904  init_data();
905  }
906 
907  // ... otherwise copy pixels
908  else {
909  for (int i = 0; i < m_num_pixels; ++i) {
910  m_pixels[i] = pixels[i];
911  }
912  }
913 
914  } // endif: there are pixels in image
915 
916  // Return
917  return;
918 }
919 
920 
921 /***********************************************************************//**
922  * @brief Load data
923  *
924  * Load the image data if no pixels have been allocated.
925  ***************************************************************************/
927 {
928  // If image pixels are not available then fetch them now.
929  if (m_pixels == NULL) {
930  const_cast<GFitsImageULong*>(this)->fetch_data();
931  }
932 
933  // Return
934  return;
935 }
936 
937 
938 /***********************************************************************//**
939  * @brief Allocates nul value
940  *
941  * @param[in] value Nul value.
942  ***************************************************************************/
943 void GFitsImageULong::alloc_nulval(const void* value)
944 {
945  // Free any existing memory
946  if (m_nulval != NULL) delete m_nulval;
947 
948  // Mark pointer as free
949  m_nulval = NULL;
950 
951  // If we have valid value, allocate and set nul value
952  if (value != NULL) {
953  m_nulval = new unsigned long;
954  *m_nulval = *((unsigned long*)value);
955  }
956 
957  // Return
958  return;
959 }
unsigned long & at(const int &ix)
Image pixel access operator.
Abstract FITS image base class.
Definition: GFitsImage.hpp:43
int offset(const int &ix) const
Return pixel offset.
Definition: GFitsImage.cpp:847
#define __TULONG
GFitsImageULong & operator=(const GFitsImageULong &image)
Assignment operator.
void * pixels(void)
Return pointer to image pixel.
unsigned long * m_pixels
Pixels.
Unsigned long image FITS class.
virtual ~GFitsImageULong(void)
Destructor.
void copy_members(const GFitsImageULong &image)
Copy class members.
void alloc_nulval(const void *value)
Allocates nul value.
void release_data(void)
Release data.
#define G_BITPIX
Defines the number of bits per pixel.
int m_num_pixels
Number of image pixels.
Definition: GFitsImage.hpp:115
Unsigned long image FITS class definition.
long * m_naxes
Number of pixels in each dimension.
Definition: GFitsImage.hpp:114
void init_data(void)
Initialise data.
GFitsImageULong * clone(void) const
Clone FITS image.
void load_data(void) const
Load data.
CFITSIO interface header.
void clear(void)
Clear instance.
virtual double pixel(const int &ix) const =0
void fetch_data(void)
Fetch image pixels.
Definition: GFitsImage.cpp:818
void init_members(void)
Initialise class members.
Definition: GFitsImage.cpp:442
void alloc_data(void)
Allocate data.
void init_members(void)
Initialise class members.
Definition: GFitsHDU.cpp:462
unsigned long * m_nulval
NULL value.
GFitsImageULong(void)
Void constructor.
void value(const std::string &value)
Set string value of header card.
double pixel(const int &ix) const
Return value of image pixel.
unsigned long & operator()(const int &ix)
Image pixel access operator.
int m_bitpix
Number of Bits/pixel.
Definition: GFitsImage.hpp:112
void free_members(void)
Delete class members.
Exception handler interface definition.
GFitsImage & operator=(const GFitsImage &image)
Assignment operator.
Definition: GFitsImage.cpp:306
void construct_data(const unsigned long *pixels)
Construct data from array.
void free_members(void)
Delete class members.
Definition: GFitsHDU.cpp:505
int type(void) const
Return image type.
GFitsHeaderCard & card(const int &cardno)
Return header card.
Definition: GFitsHDU.hpp:259
void free_members(void)
Delete class members.
Definition: GFitsImage.cpp:486
void init_members(void)
Initialise class members.