GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsImageShort.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFitsImageShort.cpp - Short 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 GFitsImageShort.cpp
23  * @brief Short 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 "GFitsImageShort.hpp"
34 
35 /* __ Method name definitions ____________________________________________ */
36 
37 /* __ Macros _____________________________________________________________ */
38 #define G_BITPIX 16 //!< 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 GFitsImageShort::GFitsImageShort(const int& nx, const short* 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 GFitsImageShort::GFitsImageShort(const int& nx, const int& ny,
97  const short* 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 GFitsImageShort::GFitsImageShort(const int& nx, const int& ny, const int& nz,
122  const short* 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 GFitsImageShort::GFitsImageShort(const int& nx, const int& ny, const int& nz,
148  const int& nt, const short* pixels) :
149  GFitsImage(G_BITPIX, nx, ny, nz, nt)
150 {
151  // Initialise class members
152  init_members();
153 
154  // Construct data
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 GFitsImageShort by specifying the image dimension and
169  * the number of pixels in each dimension.
170  ***************************************************************************/
171 GFitsImageShort::GFitsImageShort(const std::vector<int>& naxes,
172  const short* pixels) :
173  GFitsImage(G_BITPIX, naxes)
174 {
175  // Initialise class members
176  init_members();
177 
178  // Construct data
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 short
192  * integer 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 short[m_num_pixels];
203  for (int i = 0; i < m_num_pixels; ++i) {
204  m_pixels[i] = (short)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 short& GFitsImageShort::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 short& GFitsImageShort::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 short& GFitsImageShort::operator()(const int& ix, const int& iy, const int& iz)
339 {
340  // Load data
341  load_data();
342 
343  // Calculate pixel offset
344  int offset = ix + m_naxes[0] * (iy + iz * m_naxes[1]);
345 
346  // Return image pixel
347  return m_pixels[offset];
348 }
349 
350 
351 /***********************************************************************//**
352  * @brief 4D image pixel access operator
353  *
354  * @param[in] ix Pixel index in first dimension (starting from 0).
355  * @param[in] iy Pixel index in second dimension (starting from 0).
356  * @param[in] iz Pixel index in third dimension (starting from 0).
357  * @param[in] it Pixel index in forth dimension (starting from 0).
358  *
359  * Provides access to a pixel of a 4D image. No range checking or image
360  * dimension verification is performed. Use the at(ix,iy) method if range
361  * checking and image dimension verification is required.
362  ***************************************************************************/
363 short& GFitsImageShort::operator()(const int& ix, const int& iy,
364  const int& iz, const int& it)
365 {
366  // Load data
367  load_data();
368 
369  // Calculate pixel offset
370  int offset = ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2]));
371 
372  // Return image pixel
373  return m_pixels[offset];
374 }
375 
376 
377 /***********************************************************************//**
378  * @brief Image pixel access operator (const variant)
379  *
380  * @param[in] ix Pixel index (starting from 0).
381  *
382  * Provides access to an image pixel. No range checking is performed.
383  * Use the at(ix) method if range checking is required.
384  ***************************************************************************/
385 const short& GFitsImageShort::operator()(const int& ix) const
386 {
387  // Load data
388  load_data();
389 
390  // Return image pixel
391  return m_pixels[ix];
392 }
393 
394 
395 /***********************************************************************//**
396  * @brief 2D image pixel access operator (const variant)
397  *
398  * @param[in] ix Pixel index in first dimension (starting from 0).
399  * @param[in] iy Pixel index in second dimension (starting from 0).
400  *
401  * Provides access to a pixel of a 2D image. No range checking or image
402  * dimension verification is performed. Use the at(ix,iy) method if range
403  * checking and image dimension verification is required.
404  ***************************************************************************/
405 const short& GFitsImageShort::operator()(const int& ix, const int& iy) const
406 {
407  // Load data
408  load_data();
409 
410  // Calculate pixel offset
411  int offset = ix + iy * m_naxes[0];
412 
413  // Return image pixel
414  return m_pixels[offset];
415 }
416 
417 
418 /***********************************************************************//**
419  * @brief 3D image pixel access operator (const variant)
420  *
421  * @param[in] ix Pixel index in first dimension (starting from 0).
422  * @param[in] iy Pixel index in second dimension (starting from 0).
423  * @param[in] iz Pixel index in third dimension (starting from 0).
424  *
425  * Provides access to a pixel of a 3D image. No range checking or image
426  * dimension verification is performed. Use the at(ix,iy) method if range
427  * checking and image dimension verification is required.
428  ***************************************************************************/
429 const short& GFitsImageShort::operator()(const int& ix, const int& iy,
430  const int& iz) const
431 {
432  // Load data
433  load_data();
434 
435  // Calculate pixel offset
436  int offset = ix + m_naxes[0] * (iy + iz * m_naxes[1]);
437 
438  // Return image pixel
439  return m_pixels[offset];
440 }
441 
442 
443 /***********************************************************************//**
444  * @brief 4D image pixel access operator (const variant)
445  *
446  * @param[in] ix Pixel index in first dimension (starting from 0).
447  * @param[in] iy Pixel index in second dimension (starting from 0).
448  * @param[in] iz Pixel index in third dimension (starting from 0).
449  * @param[in] it Pixel index in forth dimension (starting from 0).
450  *
451  * Provides access to a pixel of a 4D image. No range checking or image
452  * dimension verification is performed. Use the at(ix,iy) method if range
453  * checking and image dimension verification is required.
454  ***************************************************************************/
455 const short& GFitsImageShort::operator()(const int& ix, const int& iy,
456  const int& iz, const int& it) const
457 {
458  // Load data
459  load_data();
460 
461  // Calculate pixel offset
462  int offset = ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2]));
463 
464  // Return image pixel
465  return m_pixels[offset];
466 }
467 
468 
469 /*==========================================================================
470  = =
471  = Public methods =
472  = =
473  ==========================================================================*/
474 
475 /***********************************************************************//**
476  * @brief Clear instance
477  *
478  * This method properly resets the object to an initial state.
479  ***************************************************************************/
481 {
482  // Free class members (base and derived classes, derived class first)
483  free_members();
484  this->GFitsImage::free_members();
485  this->GFitsHDU::free_members();
486 
487  // Initialise members
488  this->GFitsHDU::init_members();
489  this->GFitsImage::init_members();
490  init_members();
491 
492  // Return
493  return;
494 }
495 
496 
497 /***********************************************************************//**
498  * @brief Clone FITS image
499  *
500  * Cloning provides a copy of the FITS file. Cloning is used to allocate
501  * derived classes into a base class pointer.
502  ***************************************************************************/
504 {
505  // Clone this image
506  return new GFitsImageShort(*this);
507 }
508 
509 
510 /***********************************************************************//**
511  * @brief Image pixel access operator
512  *
513  * @param[in] ix Pixel index (starting from 0).
514  *
515  * Provides access to a pixel of an image including range checking. Note that
516  * this method does not necessarily restrict do 1D images but generally
517  * applies to all image dimensions.
518  ***************************************************************************/
519 short& GFitsImageShort::at(const int& ix)
520 {
521  // Load data
522  load_data();
523 
524  // Return image pixel
525  return (m_pixels[offset(ix)]);
526 }
527 
528 
529 /***********************************************************************//**
530  * @brief 2D image pixel access operator
531  *
532  * @param[in] ix Pixel index in first dimension (starting from 0).
533  * @param[in] iy Pixel index in second dimension (starting from 0).
534  *
535  * Provides access to a pixel of an image including range checking.
536  ***************************************************************************/
537 short& GFitsImageShort::at(const int& ix, const int& iy)
538 {
539  // Load data
540  load_data();
541 
542  // Return image pixel
543  return (m_pixels[offset(ix,iy)]);
544 }
545 
546 
547 /***********************************************************************//**
548  * @brief 3D image pixel access operator
549  *
550  * @param[in] ix Pixel index in first dimension (starting from 0).
551  * @param[in] iy Pixel index in second dimension (starting from 0).
552  * @param[in] iz Pixel index in third dimension (starting from 0).
553  *
554  * Provides access to a pixel of an image including range checking.
555  ***************************************************************************/
556 short& GFitsImageShort::at(const int& ix, const int& iy, const int& iz)
557 {
558  // Load data
559  load_data();
560 
561  // Return image pixel
562  return (m_pixels[offset(ix,iy,iz)]);
563 }
564 
565 
566 /***********************************************************************//**
567  * @brief 4D image pixel access operator
568  *
569  * @param[in] ix Pixel index in first dimension (starting from 0).
570  * @param[in] iy Pixel index in second dimension (starting from 0).
571  * @param[in] iz Pixel index in third dimension (starting from 0).
572  * @param[in] it Pixel index in forth dimension (starting from 0).
573  *
574  * Provides access to a pixel of an image including range checking.
575  ***************************************************************************/
576 short& GFitsImageShort::at(const int& ix, const int& iy, const int& iz,
577  const int& it)
578 {
579  // Load data
580  load_data();
581 
582  // Return image pixel
583  return (m_pixels[offset(ix,iy,iz,it)]);
584 }
585 
586 
587 /***********************************************************************//**
588  * @brief Image pixel access operator (const variant)
589  *
590  * @param[in] ix Pixel index (starting from 0).
591  *
592  * Provides access to a pixel of an image including range checking.
593  ***************************************************************************/
594 const short& GFitsImageShort::at(const int& ix) const
595 {
596  // Load data
597  load_data();
598 
599  // Return image pixel
600  return (m_pixels[offset(ix)]);
601 }
602 
603 
604 /***********************************************************************//**
605  * @brief 2D image pixel access operator (const variant)
606  *
607  * @param[in] ix Pixel index in first dimension (starting from 0).
608  * @param[in] iy Pixel index in second dimension (starting from 0).
609  *
610  * Provides access to a pixel of an image including range checking.
611  ***************************************************************************/
612 const short& GFitsImageShort::at(const int& ix, const int& iy) const
613 {
614  // Load data
615  load_data();
616 
617  // Return image pixel
618  return (m_pixels[offset(ix,iy)]);
619 }
620 
621 
622 /***********************************************************************//**
623  * @brief 3D image pixel access operator (const variant)
624  *
625  * @param[in] ix Pixel index in first dimension (starting from 0).
626  * @param[in] iy Pixel index in second dimension (starting from 0).
627  * @param[in] iz Pixel index in third dimension (starting from 0).
628  *
629  * Provides access to a pixel of an image including range checking.
630  ***************************************************************************/
631 const short& GFitsImageShort::at(const int& ix, const int& iy,
632  const int& iz) const
633 {
634  // Load data
635  load_data();
636 
637  // Return image pixel
638  return (m_pixels[offset(ix,iy,iz)]);
639 }
640 
641 
642 /***********************************************************************//**
643  * @brief 4D image pixel access operator (const variant)
644  *
645  * @param[in] ix Pixel index in first dimension (starting from 0).
646  * @param[in] iy Pixel index in second dimension (starting from 0).
647  * @param[in] iz Pixel index in third dimension (starting from 0).
648  * @param[in] it Pixel index in forth dimension (starting from 0).
649  *
650  * Provides access to a pixel of an image including range checking.
651  ***************************************************************************/
652 const short& GFitsImageShort::at(const int& ix, const int& iy,
653  const int& iz, const int& it) const
654 {
655  // Load data
656  load_data();
657 
658  // Return image pixel
659  return (m_pixels[offset(ix,iy,iz,it)]);
660 }
661 
662 
663 /***********************************************************************//**
664  * @brief Return value of image pixel
665  *
666  * @param[in] ix Pixel index (starting from 0).
667  *
668  * Returns the value of an image pixel as double precision floating point
669  * value. This method performs range checking.
670  ***************************************************************************/
671 double GFitsImageShort::pixel(const int& ix) const
672 {
673  // Return pixel value
674  return (double(this->at(ix)));
675 }
676 
677 
678 /***********************************************************************//**
679  * @brief Return value of image pixel (2D version)
680  *
681  * @param[in] ix Pixel index in first dimension (starting from 0).
682  * @param[in] iy Pixel index in second dimension (starting from 0).
683  *
684  * Returns the value of an image pixel as double precision floating point
685  * value. This method performs range checking.
686  ***************************************************************************/
687 double GFitsImageShort::pixel(const int& ix, const int& iy) const
688 {
689  // Return pixel value
690  return (double(this->at(ix,iy)));
691 }
692 
693 
694 /***********************************************************************//**
695  * @brief Return value of image pixel (3D version)
696  *
697  * @param[in] ix Pixel index in first dimension (starting from 0).
698  * @param[in] iy Pixel index in second dimension (starting from 0).
699  * @param[in] iz Pixel index in third dimension (starting from 0).
700  *
701  * Returns the value of an image pixel as double precision floating point
702  * value. This method performs range checking.
703  ***************************************************************************/
704 double GFitsImageShort::pixel(const int& ix, const int& iy, const int& iz) const
705 {
706  // Return pixel value
707  return (double(this->at(ix,iy,iz)));
708 }
709 
710 
711 /***********************************************************************//**
712  * @brief Return value of image pixel (4D version)
713  *
714  * @param[in] ix Pixel index in first dimension (starting from 0).
715  * @param[in] iy Pixel index in second dimension (starting from 0).
716  * @param[in] iz Pixel index in third dimension (starting from 0).
717  * @param[in] it Pixel index in forth dimension (starting from 0).
718  *
719  * Returns the value of an image pixel as double precision floating point
720  * value. This method performs range checking.
721  ***************************************************************************/
722 double GFitsImageShort::pixel(const int& ix, const int& iy, const int& iz,
723  const int& it) const
724 {
725  // Return pixel value
726  return (double(this->at(ix,iy,iz,it)));
727 }
728 
729 
730 /***********************************************************************//**
731  * @brief Return pointer to image pixel
732  ***************************************************************************/
734 {
735  // Load data
736  load_data();
737 
738  // Return
739  return m_pixels;
740 }
741 
742 
743 /***********************************************************************//**
744  * @brief Return image type
745  ***************************************************************************/
746 int GFitsImageShort::type(void) const
747 {
748  // Return type
749  return __TSHORT;
750 }
751 
752 
753 /*==========================================================================
754  = =
755  = Private methods =
756  = =
757  ==========================================================================*/
758 
759 /***********************************************************************//**
760  * @brief Initialise class members
761  ***************************************************************************/
763 {
764  // Initialise members
765  m_bitpix = G_BITPIX;
766  m_pixels = NULL;
767  m_nulval = NULL;
768 
769  // Return
770  return;
771 }
772 
773 
774 /***********************************************************************//**
775  * @brief Copy class members
776  *
777  * @param image FITS image to copy
778  *
779  * Copy class members. If the pixel array is linked the pointer to the array
780  * is copied. Otherwise a copy of the image pixels will be created.
781  ***************************************************************************/
783 {
784  // Fetch column data if not yet fetched. The casting circumvents the
785  // const correctness
786  bool not_loaded = (image.m_pixels == NULL);
787  if (not_loaded) {
788  const_cast<GFitsImageShort*>(&image)->fetch_data();
789  }
790 
791  // Copy pixels
792  if (m_num_pixels > 0 && image.m_pixels != NULL) {
793  m_pixels = new short[m_num_pixels];
794  for (int i = 0; i < m_num_pixels; ++i) {
795  m_pixels[i] = image.m_pixels[i];
796  }
797  }
798 
799  // Copy NULL value
800  alloc_nulval(image.m_nulval);
801 
802  // Small memory option: release column if it was fetch above
803  #if defined(G_SMALL_MEMORY)
804  if (not_loaded) {
805  const_cast<GFitsImageShort*>(&image)->release_data();
806  }
807  #endif
808 
809  // Return
810  return;
811 }
812 
813 
814 /***********************************************************************//**
815  * @brief Delete class members
816  ***************************************************************************/
818 {
819  // Free memory
820  if (m_pixels != NULL) delete [] m_pixels;
821  if (m_nulval != NULL) delete m_nulval;
822 
823  // Mark memory as free
824  m_pixels = NULL;
825  m_nulval = NULL;
826 
827  // Return
828  return;
829 }
830 
831 
832 /***********************************************************************//**
833  * @brief Allocate data
834  ***************************************************************************/
836 {
837  // Release any existing data
838  release_data();
839 
840  // Allocate new data
841  if (m_num_pixels > 0) {
842  m_pixels = new short[m_num_pixels];
843  }
844 
845  // Return
846  return;
847 }
848 
849 
850 /***********************************************************************//**
851  * @brief Initialise data
852  ***************************************************************************/
854 {
855  // Initialise data if they exist
856  if (m_pixels != NULL) {
857  for (int i = 0; i < m_num_pixels; ++i) {
858  m_pixels[i] = 0;
859  }
860  }
861 
862  // Return
863  return;
864 }
865 
866 
867 /***********************************************************************//**
868  * @brief Release data
869  ***************************************************************************/
871 {
872  // Free any existing memory
873  if (m_pixels != NULL) delete [] m_pixels;
874 
875  // Mark pointer as free
876  m_pixels = NULL;
877 
878  // Return
879  return;
880 }
881 
882 
883 /***********************************************************************//**
884  * @brief Construct data from array
885  *
886  * @param[in] pixels Optional pointer to pixel array.
887  *
888  * Initialise pixel data from an optional pixel array. If the pointer is
889  * NULL the image is simply initialised. This method supports all
890  * constructors.
891  ***************************************************************************/
892 void GFitsImageShort::construct_data(const short* pixels)
893 {
894  // If there are pixels then allocate array
895  if (m_num_pixels > 0) {
896 
897  // Allocate data
898  alloc_data();
899 
900  // If no pixel array has been specified then simply initialise data
901  if (pixels == NULL) {
902  init_data();
903  }
904 
905  // ... otherwise copy pixels
906  else {
907  for (int i = 0; i < m_num_pixels; ++i) {
908  m_pixels[i] = pixels[i];
909  }
910  }
911 
912  } // endif: there are pixels in image
913 
914  // Return
915  return;
916 }
917 
918 
919 /***********************************************************************//**
920  * @brief Load data
921  *
922  * Load the image data if no pixels have been allocated.
923  ***************************************************************************/
925 {
926  // If image pixels are not available then fetch them now.
927  if (m_pixels == NULL) {
928  const_cast<GFitsImageShort*>(this)->fetch_data();
929  }
930 
931  // Return
932  return;
933 }
934 
935 
936 /***********************************************************************//**
937  * @brief Allocates nul value
938  *
939  * @param[in] value Nul value.
940  ***************************************************************************/
941 void GFitsImageShort::alloc_nulval(const void* value)
942 {
943  // Free any existing memory
944  if (m_nulval != NULL) delete m_nulval;
945 
946  // Mark pointer as free
947  m_nulval = NULL;
948 
949  // If we have valid value, allocate and set nul value
950  if (value != NULL) {
951  m_nulval = new short;
952  *m_nulval = *((short*)value);
953  }
954 
955  // Return
956  return;
957 }
Abstract FITS image base class.
Definition: GFitsImage.hpp:43
int offset(const int &ix) const
Return pixel offset.
Definition: GFitsImage.cpp:847
void release_data(void)
Release data.
short * m_pixels
Pixels.
void free_members(void)
Delete class members.
int type(void) const
Return image type.
GFitsImageShort * clone(void) const
Clone FITS image.
short * m_nulval
NULL value.
GFitsImageShort(void)
Void constructor.
void load_data(void) const
Load data.
void clear(void)
Clear instance.
double pixel(const int &ix) const
Return value of image pixel.
void init_data(void)
Initialise data.
int m_num_pixels
Number of image pixels.
Definition: GFitsImage.hpp:115
#define G_BITPIX
Defines the number of bits per pixel.
long * m_naxes
Number of pixels in each dimension.
Definition: GFitsImage.hpp:114
short & operator()(const int &ix)
Image pixel access operator.
#define __TSHORT
CFITSIO interface header.
void copy_members(const GFitsImageShort &image)
Copy class members.
virtual double pixel(const int &ix) const =0
short & at(const int &ix)
Image pixel access operator.
void fetch_data(void)
Fetch image pixels.
Definition: GFitsImage.cpp:818
void init_members(void)
Initialise class members.
Definition: GFitsImage.cpp:442
Short integer FITS image class.
Short integer FITS image class definition.
void init_members(void)
Initialise class members.
Definition: GFitsHDU.cpp:462
void construct_data(const short *pixels)
Construct data from array.
virtual ~GFitsImageShort(void)
Destructor.
void * pixels(void)
Return pointer to image pixel.
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.
void alloc_data(void)
Allocate data.
GFitsImage & operator=(const GFitsImage &image)
Assignment operator.
Definition: GFitsImage.cpp:306
void free_members(void)
Delete class members.
Definition: GFitsHDU.cpp:505
GFitsHeaderCard & card(const int &cardno)
Return header card.
Definition: GFitsHDU.hpp:259
void alloc_nulval(const void *value)
Allocates nul value.
GFitsImageShort & operator=(const GFitsImageShort &image)
Assignment operator.
void free_members(void)
Delete class members.
Definition: GFitsImage.cpp:486
void init_members(void)
Initialise class members.