GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GFitsImage.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GFitsImage.hpp - Abstract FITS image base 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 GFitsImage.hpp
23 * @brief Abstract FITS image base class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GFITSIMAGE_HPP
28#define GFITSIMAGE_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <vector>
32#include <string>
33#include "GFitsHDU.hpp"
34
35
36/***********************************************************************//**
37 * @class GFitsImage
38 *
39 * @brief Abstract FITS image base class
40 *
41 * This class defines the abstract interface for a FITS image.
42 ***************************************************************************/
43class GFitsImage : public GFitsHDU {
44
45public:
46 // Constructors and destructors
47 GFitsImage(void);
48 GFitsImage(const int& bitpix, const int& nx);
49 GFitsImage(const int& bitpix, const int& nx, const int& ny);
50 GFitsImage(const int& bitpix, const int& nx, const int& ny, const int& nz);
51 GFitsImage(const int& bitpix, const int& nx, const int& ny, const int& nz, const int& nt);
52 GFitsImage(const int& bitpix, const std::vector<int>& naxes);
53 GFitsImage(const GFitsImage& image);
54 virtual ~GFitsImage(void);
55
56 // Operators
57 GFitsImage& operator=(const GFitsImage& image);
58
59 // Pure virtual methods
60 virtual void clear(void) = 0;
61 virtual GFitsImage* clone(void) const = 0;
62 virtual std::string classname(void) const = 0;
63 virtual void* pixels(void) = 0;
64 virtual double pixel(const int& ix) const = 0;
65 virtual double pixel(const int& ix, const int& iy) const = 0;
66 virtual double pixel(const int& ix, const int& iy, const int& iz) const = 0;
67 virtual double pixel(const int& ix, const int& iy, const int& iz, const int& it) const = 0;
68 virtual int type(void) const = 0;
69
70 // Implemented pure virtual methods
71 HDUType exttype(void) const;
72
73 // Base class methods
74 const int& npix(void) const;
75 const int& bitpix(void) const;
76 const int& naxis(void) const;
77 int naxes(const int& axis) const;
78 const int& anynul(void) const;
79 void nulval(const void* value);
80 const void* nulval(void) const;
81 const double& bscale(void) const;
82 const double& bzero(void) const;
83 double raw2true(const double& raw) const;
84 std::string print(const GChatter& chatter = NORMAL) const;
85
86protected:
87 // Protected methods
88 void init_members(void);
89 void copy_members(const GFitsImage& image);
90 void free_members(void);
91 void data_open(void* vptr);
92 void data_save(void);
93 void data_close(void);
94 void data_connect(void* vptr);
95 void init_image_header(void);
96 void open_image(void* vptr);
97 void load_image(int datatype, const void* pixels,
98 const void* nulval, int* anynul);
99 void save_image(int datatype, const void* pixels);
100 void fetch_data(void);
101 int offset(const int& ix) const;
102 int offset(const int& ix, const int& iy) const;
103 int offset(const int& ix, const int& iy, const int& iz) const;
104 int offset(const int& ix, const int& iy, const int& iz, const int& it) const;
105
106 // Pure virtual protected methods
107 virtual void alloc_data(void) = 0;
108 virtual void init_data(void) = 0;
109 virtual void release_data(void) = 0;
110 virtual void alloc_nulval(const void* value) = 0;
111 virtual void* ptr_data(void) = 0;
112 virtual void* ptr_nulval(void) = 0;
113
114 // Protected data area
115 int m_bitpix; //!< Number of Bits/pixel
116 int m_naxis; //!< Image dimension
117 long* m_naxes; //!< Number of pixels in each dimension
118 int m_num_pixels; //!< Number of image pixels
119 int m_anynul; //!< Number of NULLs encountered
120 double m_bscale; //!< Scaling for integer pixels
121 double m_bzero; //!< Offset for integer pixels
122};
123
124
125/***********************************************************************//**
126 * @brief Return extension type
127 *
128 * @return Extension type (HT_IMAGE).
129 ***************************************************************************/
130inline
132{
133 return (HT_IMAGE);
134}
135
136
137/***********************************************************************//**
138 * @brief Return size of pixel array
139 ***************************************************************************/
140inline
141const int& GFitsImage::npix(void) const
142{
143 return m_num_pixels;
144}
145
146
147/***********************************************************************//**
148 * @brief Return number of Bits per pixel (negative=floating point)
149 ***************************************************************************/
150inline
151const int& GFitsImage::bitpix(void) const
152{
153 return (m_bitpix);
154}
155
156
157/***********************************************************************//**
158 * @brief Return dimension of image
159 ***************************************************************************/
160inline
161const int& GFitsImage::naxis(void) const
162{
163 return (m_naxis);
164}
165
166
167/***********************************************************************//**
168 * @brief Return number of nul values encountered during loading
169 ***************************************************************************/
170inline
171const int& GFitsImage::anynul(void) const
172{
173 return (m_anynul);
174}
175
176
177/***********************************************************************//**
178 * @brief Return nul value
179 ***************************************************************************/
180inline
181const void* GFitsImage::nulval(void) const
182{
183 return (const_cast<GFitsImage*>(this)->ptr_nulval());
184}
185
186
187/***********************************************************************//**
188 * @brief Return pixel scaling
189 ***************************************************************************/
190inline
191const double& GFitsImage::bscale(void) const
192{
193 return (m_bscale);
194}
195
196
197/***********************************************************************//**
198 * @brief Return pixel offset
199 ***************************************************************************/
200inline
201const double& GFitsImage::bzero(void) const
202{
203 return (m_bzero);
204}
205
206
207/***********************************************************************//**
208 * @brief Convert raw to true pixel value by applying BSCALE and BZERO
209 ***************************************************************************/
210inline
211double GFitsImage::raw2true(const double& raw) const
212{
213 double value = ((m_bscale != 1.0) || (m_bzero != 0.0)) ? raw * m_bscale + m_bzero : raw;
214 return (value);
215}
216
217#endif /* GFITSIMAGE_HPP */
Abstract FITS extension base class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Abstract FITS extension base class.
Definition GFitsHDU.hpp:51
Abstract FITS image base class.
void open_image(void *vptr)
Open Image.
virtual void init_data(void)=0
virtual void * ptr_nulval(void)=0
int m_naxis
Image dimension.
virtual double pixel(const int &ix) const =0
double m_bscale
Scaling for integer pixels.
virtual void release_data(void)=0
int naxes(const int &axis) const
Return dimension of an image axis.
const int & bitpix(void) const
Return number of Bits per pixel (negative=floating point)
int offset(const int &ix) const
Return pixel offset.
void free_members(void)
Delete class members.
const int & npix(void) const
Return size of pixel array.
const double & bscale(void) const
Return pixel scaling.
void load_image(int datatype, const void *pixels, const void *nulval, int *anynul)
Load FITS image.
void fetch_data(void)
Fetch image pixels.
const double & bzero(void) const
Return pixel offset.
long * m_naxes
Number of pixels in each dimension.
const int & naxis(void) const
Return dimension of image.
double m_bzero
Offset for integer pixels.
HDUType exttype(void) const
Return extension type.
virtual void alloc_nulval(const void *value)=0
void data_save(void)
Save FITS image.
virtual void clear(void)=0
Clear object.
void save_image(int datatype, const void *pixels)
Save FITS image.
int m_bitpix
Number of Bits/pixel.
void copy_members(const GFitsImage &image)
Copy class members.
int m_num_pixels
Number of image pixels.
void init_image_header(void)
Initialise image header.
std::string print(const GChatter &chatter=NORMAL) const
Print column information.
void data_open(void *vptr)
Open FITS image.
virtual double pixel(const int &ix, const int &iy, const int &iz) const =0
virtual double pixel(const int &ix, const int &iy) const =0
GFitsImage & operator=(const GFitsImage &image)
Assignment operator.
virtual std::string classname(void) const =0
Return class name.
const int & anynul(void) const
Return number of nul values encountered during loading.
virtual void * ptr_data(void)=0
void data_connect(void *vptr)
Connect FITS image.
GFitsImage(void)
Void constructor.
virtual void alloc_data(void)=0
const void * nulval(void) const
Return nul value.
double raw2true(const double &raw) const
Convert raw to true pixel value by applying BSCALE and BZERO.
virtual double pixel(const int &ix, const int &iy, const int &iz, const int &it) const =0
virtual void * pixels(void)=0
int m_anynul
Number of NULLs encountered.
virtual int type(void) const =0
void data_close(void)
Close FITS image.
virtual ~GFitsImage(void)
Destructor.
virtual GFitsImage * clone(void) const =0
Clones object.
void init_members(void)
Initialise class members.