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