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