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