Commit 71e75ab184ebfd68edc1b083ac602e67ce47005c
1 parent
46a76e03
new base class implementation
Showing
3 changed files
with
174 additions
and
24 deletions
include/GFitsImage.hpp
| ... | ... | @@ -47,26 +47,26 @@ public: |
| 47 | 47 | |
| 48 | 48 | // Pure virtual methods |
| 49 | 49 | virtual void* pixels(void) = 0; |
| 50 | - virtual double pixel(const int& ix) = 0; | |
| 51 | - virtual double pixel(const int& ix, const int& iy) = 0; | |
| 50 | + virtual double pixel(const int& ix) const = 0; | |
| 51 | + virtual double pixel(const int& ix, const int& iy) const = 0; | |
| 52 | + virtual double pixel(const int& ix, const int& iy, const int& iz) const = 0; | |
| 53 | + virtual double pixel(const int& ix, const int& iy, const int& iz, const int& it) const = 0; | |
| 52 | 54 | virtual GFitsImage* clone(void) const = 0; |
| 53 | 55 | |
| 54 | 56 | // Implemented pure virtual methods |
| 55 | 57 | HDUType exttype(void) const { return HT_IMAGE; } |
| 56 | 58 | |
| 57 | 59 | // Base class methods |
| 58 | - int bitpix(void) const; | |
| 59 | - int naxis(void) const; | |
| 60 | - int naxes(int axis) const; | |
| 61 | - int num_pixels(void) const; | |
| 62 | - int anynul(void) const; | |
| 63 | - void nulval(const void* value); | |
| 60 | + int size(void) const; | |
| 61 | + int bitpix(void) const; | |
| 62 | + int naxis(void) const; | |
| 63 | + int naxes(int axis) const; | |
| 64 | + int anynul(void) const; | |
| 65 | + void nulval(const void* value); | |
| 66 | + void* nulval(void); | |
| 64 | 67 | |
| 65 | 68 | protected: |
| 66 | 69 | // Protected methods |
| 67 | - void init_members(void); | |
| 68 | - void copy_members(const GFitsImage& image); | |
| 69 | - void free_members(void); | |
| 70 | 70 | void init_image_header(void); |
| 71 | 71 | void data_open(void* vptr); |
| 72 | 72 | void data_save(void); |
| ... | ... | @@ -78,15 +78,18 @@ protected: |
| 78 | 78 | void save_image(int datatype, const void* pixels); |
| 79 | 79 | void fetch_data(void); |
| 80 | 80 | int offset(const int& ix) const; |
| 81 | + int offset(const int& ix, const int& iy) const; | |
| 82 | + int offset(const int& ix, const int& iy, const int& iz) const; | |
| 83 | + int offset(const int& ix, const int& iy, const int& iz, const int& it) const; | |
| 81 | 84 | |
| 82 | 85 | // Pure virtual protected methods |
| 83 | 86 | virtual void alloc_data(void) = 0; |
| 84 | 87 | virtual void init_data(void) = 0; |
| 85 | 88 | virtual void release_data(void) = 0; |
| 86 | 89 | virtual void alloc_nulval(const void* value) = 0; |
| 87 | - virtual int type(void) const = 0; | |
| 88 | 90 | virtual void* ptr_data(void) = 0; |
| 89 | 91 | virtual void* ptr_nulval(void) = 0; |
| 92 | + virtual int type(void) const = 0; | |
| 90 | 93 | |
| 91 | 94 | // Protected data area |
| 92 | 95 | int m_bitpix; //!< Number of Bits/pixel |
| ... | ... | @@ -94,6 +97,11 @@ protected: |
| 94 | 97 | long* m_naxes; //!< Number of pixels in each dimension |
| 95 | 98 | int m_num_pixels; //!< Number of image pixels |
| 96 | 99 | int m_anynul; //!< Number of NULLs encountered |
| 100 | + | |
| 101 | + // Private methods | |
| 102 | + void init_members(void); | |
| 103 | + void copy_members(const GFitsImage& image); | |
| 104 | + void free_members(void); | |
| 97 | 105 | }; |
| 98 | 106 | |
| 99 | 107 | #endif /* GFITSIMAGE_HPP */ | ... | ... |
pyext/GFitsImage.i
| ... | ... | @@ -35,14 +35,20 @@ public: |
| 35 | 35 | |
| 36 | 36 | // Pure virtual methods |
| 37 | 37 | virtual void* pixels(void) = 0; |
| 38 | + virtual double pixel(const int& ix) const = 0; | |
| 39 | + virtual double pixel(const int& ix, const int& iy) const = 0; | |
| 40 | + virtual double pixel(const int& ix, const int& iy, const int& iz) const = 0; | |
| 41 | + virtual double pixel(const int& ix, const int& iy, const int& iz, const int& it) const = 0; | |
| 38 | 42 | virtual GFitsImage* clone(void) const = 0; |
| 39 | 43 | |
| 40 | 44 | // Implemented pure virtual methods |
| 41 | 45 | HDUType exttype(void) const { return HT_IMAGE; } |
| 42 | 46 | |
| 43 | 47 | // Methods |
| 44 | - virtual int bitpix(void) const; | |
| 45 | - virtual int naxis(void) const; | |
| 46 | - virtual int naxes(int axis) const; | |
| 47 | - virtual int num_pixels(void) const; | |
| 48 | + int size(void) const; | |
| 49 | + int bitpix(void) const; | |
| 50 | + int naxis(void) const; | |
| 51 | + int naxes(int axis) const; | |
| 52 | + int anynul(void) const; | |
| 53 | + void nulval(const void* value); | |
| 48 | 54 | }; | ... | ... |
src/fits/GFitsImage.cpp
| ... | ... | @@ -25,6 +25,10 @@ |
| 25 | 25 | #define G_OPEN_IMAGE "GFitsImage::open(void*)" |
| 26 | 26 | #define G_LOAD_IMAGE "GFitsImage::load_image(int,void*,void*,int*)" |
| 27 | 27 | #define G_SAVE_IMAGE "GFitsImage::save_image(int,void*)" |
| 28 | +#define G_OFFSET_1D "GFitsImage::offset(int&)" | |
| 29 | +#define G_OFFSET_2D "GFitsImage::offset(int&,int&)" | |
| 30 | +#define G_OFFSET_3D "GFitsImage::offset(int&,int&,int&)" | |
| 31 | +#define G_OFFSET_4D "GFitsImage::offset(int&,int&,int&,int&)" | |
| 28 | 32 | |
| 29 | 33 | /* __ Macros _____________________________________________________________ */ |
| 30 | 34 | |
| ... | ... | @@ -169,6 +173,16 @@ GFitsImage& GFitsImage::operator= (const GFitsImage& image) |
| 169 | 173 | ==========================================================================*/ |
| 170 | 174 | |
| 171 | 175 | /***********************************************************************//** |
| 176 | + * @brief Return size of pixel array | |
| 177 | + ***************************************************************************/ | |
| 178 | +int GFitsImage::size(void) const | |
| 179 | +{ | |
| 180 | + // Return number of pixels | |
| 181 | + return m_num_pixels; | |
| 182 | +} | |
| 183 | + | |
| 184 | + | |
| 185 | +/***********************************************************************//** | |
| 172 | 186 | * @brief Return number of Bits per pixel (negative=floating point) |
| 173 | 187 | ***************************************************************************/ |
| 174 | 188 | int GFitsImage::bitpix(void) const |
| ... | ... | @@ -215,12 +229,13 @@ int GFitsImage::naxes(int axis) const |
| 215 | 229 | /***********************************************************************//** |
| 216 | 230 | * @brief Return number of pixels |
| 217 | 231 | ***************************************************************************/ |
| 232 | +/* | |
| 218 | 233 | int GFitsImage::num_pixels(void) const |
| 219 | 234 | { |
| 220 | 235 | // Return number of pixels |
| 221 | 236 | return m_num_pixels; |
| 222 | 237 | } |
| 223 | - | |
| 238 | +*/ | |
| 224 | 239 | |
| 225 | 240 | /***********************************************************************//** |
| 226 | 241 | * @brief Return number of nul values envountered during loading |
| ... | ... | @@ -255,6 +270,16 @@ void GFitsImage::nulval(const void* value) |
| 255 | 270 | } |
| 256 | 271 | |
| 257 | 272 | |
| 273 | +/***********************************************************************//** | |
| 274 | + * @brief Return nul value | |
| 275 | + ***************************************************************************/ | |
| 276 | +void* GFitsImage::nulval(void) | |
| 277 | +{ | |
| 278 | + // Return | |
| 279 | + return (ptr_nulval()); | |
| 280 | +} | |
| 281 | + | |
| 282 | + | |
| 258 | 283 | /*========================================================================== |
| 259 | 284 | = = |
| 260 | 285 | = Protected methods = |
| ... | ... | @@ -588,12 +613,12 @@ void GFitsImage::save_image(int datatype, const void* pixels) |
| 588 | 613 | * that pixels existed already before they will be deleted before fetching |
| 589 | 614 | * new ones. |
| 590 | 615 | * There are two possibilities to fetch the pixels: |
| 591 | - * (1) In case that a FITS file is attached to the image the pixel array | |
| 592 | - * will be loaded from the file. | |
| 593 | - * (2) In case that no FITS file is attached a new pixel array will be | |
| 594 | - * allocated that is initalised to 0. | |
| 616 | + * (1) In case that a FITS file is attached to the image, the pixel array | |
| 617 | + * will be loaded from the FITS file using the load_image() method. | |
| 618 | + * (2) In case that no FITS file is attached, a new pixel array will be | |
| 619 | + * allocated that is initalised to zero. | |
| 595 | 620 | ***************************************************************************/ |
| 596 | -void GFitsImageDouble::fetch_data(void) | |
| 621 | +void GFitsImage::fetch_data(void) | |
| 597 | 622 | { |
| 598 | 623 | // Fetch only if there are pixels in image |
| 599 | 624 | if (m_num_pixels > 0) { |
| ... | ... | @@ -611,20 +636,22 @@ void GFitsImageDouble::fetch_data(void) |
| 611 | 636 | // Return |
| 612 | 637 | return; |
| 613 | 638 | } |
| 639 | + | |
| 640 | + | |
| 614 | 641 | /***********************************************************************//** |
| 615 | 642 | * @brief Return pixel offset |
| 616 | 643 | * |
| 617 | 644 | * @param[in] ix Pixel index (starting from 0). |
| 618 | 645 | * |
| 619 | 646 | * @exception GException::out_of_range |
| 620 | - * Image axis not valid. | |
| 647 | + * Pixel index is outside valid range. | |
| 621 | 648 | ***************************************************************************/ |
| 622 | 649 | int GFitsImage::offset(const int& ix) const |
| 623 | 650 | { |
| 624 | 651 | // Check if axis is within the range |
| 625 | 652 | #if defined(G_RANGE_CHECK) |
| 626 | 653 | if (ix < 0 || ix >= m_num_pixels) |
| 627 | - throw GException::out_of_range(G_NAXES, ix, 0, m_num_pixels-1); | |
| 654 | + throw GException::out_of_range(G_OFFSET_1D, ix, 0, m_num_pixels-1); | |
| 628 | 655 | #endif |
| 629 | 656 | |
| 630 | 657 | // Return index |
| ... | ... | @@ -632,6 +659,115 @@ int GFitsImage::offset(const int& ix) const |
| 632 | 659 | } |
| 633 | 660 | |
| 634 | 661 | |
| 662 | +/***********************************************************************//** | |
| 663 | + * @brief Return 2D pixel offset | |
| 664 | + * | |
| 665 | + * @param[in] ix Pixel index in first dimension (starting from 0). | |
| 666 | + * @param[in] iy Pixel index in second dimension (starting from 0). | |
| 667 | + * | |
| 668 | + * @exception GException::fits_wrong_image_operator | |
| 669 | + * Pixel array has less than 2 dimensions. | |
| 670 | + * @exception GException::out_of_range | |
| 671 | + * Image axis not valid. | |
| 672 | + * | |
| 673 | + * Computes of offset in the pixel array of a 2D coordinate. This method is | |
| 674 | + * only applicable to pixels arrays that have at least 2 dimenions. | |
| 675 | + ***************************************************************************/ | |
| 676 | +int GFitsImage::offset(const int& ix, const int& iy) const | |
| 677 | +{ | |
| 678 | + // Operator is only valid for 2D images | |
| 679 | + if (m_naxis < 2) | |
| 680 | + throw GException::fits_wrong_image_operator(G_OFFSET_2D, m_naxis, 2); | |
| 681 | + | |
| 682 | + // Check if axis is within the range | |
| 683 | + #if defined(G_RANGE_CHECK) | |
| 684 | + if (ix < 0 || ix >= m_naxes[0]) | |
| 685 | + throw GException::out_of_range(G_OFFSET_2D, ix, 0, m_naxes[0]-1); | |
| 686 | + if (iy < 0 || iy >= m_naxes[1]) | |
| 687 | + throw GException::out_of_range(G_OFFSET_2D, iy, 0, m_naxes[1]-1); | |
| 688 | + #endif | |
| 689 | + | |
| 690 | + // Return offset | |
| 691 | + return (ix + iy * m_naxes[0]); | |
| 692 | +} | |
| 693 | + | |
| 694 | + | |
| 695 | +/***********************************************************************//** | |
| 696 | + * @brief Return 3D pixel offset | |
| 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 | + * @exception GException::fits_wrong_image_operator | |
| 703 | + * Pixel array has less than 3 dimensions. | |
| 704 | + * @exception GException::out_of_range | |
| 705 | + * Image axis not valid. | |
| 706 | + * | |
| 707 | + * Computes of offset in the pixel array of a 3D coordinate. This method is | |
| 708 | + * only applicable to pixels arrays that have at least 3 dimenions. | |
| 709 | + ***************************************************************************/ | |
| 710 | +int GFitsImage::offset(const int& ix, const int& iy, const int& iz) const | |
| 711 | +{ | |
| 712 | + // Operator is only valid for 3D images | |
| 713 | + if (m_naxis < 3) | |
| 714 | + throw GException::fits_wrong_image_operator(G_OFFSET_3D, m_naxis, 3); | |
| 715 | + | |
| 716 | + // Check if axis is within the range | |
| 717 | + #if defined(G_RANGE_CHECK) | |
| 718 | + if (ix < 0 || ix >= m_naxes[0]) | |
| 719 | + throw GException::out_of_range(G_OFFSET_3D, ix, 0, m_naxes[0]-1); | |
| 720 | + if (iy < 0 || iy >= m_naxes[1]) | |
| 721 | + throw GException::out_of_range(G_OFFSET_3D, iy, 0, m_naxes[1]-1); | |
| 722 | + if (iz < 0 || iz >= m_naxes[2]) | |
| 723 | + throw GException::out_of_range(G_OFFSET_3D, iz, 0, m_naxes[2]-1); | |
| 724 | + #endif | |
| 725 | + | |
| 726 | + // Return offset | |
| 727 | + return (ix + m_naxes[0] * (iy + iz * m_naxes[1])); | |
| 728 | +} | |
| 729 | + | |
| 730 | + | |
| 731 | +/***********************************************************************//** | |
| 732 | + * @brief Return 4D pixel offset | |
| 733 | + * | |
| 734 | + * @param[in] ix Pixel index in first dimension (starting from 0). | |
| 735 | + * @param[in] iy Pixel index in second dimension (starting from 0). | |
| 736 | + * @param[in] iz Pixel index in third dimension (starting from 0). | |
| 737 | + * @param[in] iz Pixel index in forth dimension (starting from 0). | |
| 738 | + * | |
| 739 | + * @exception GException::fits_wrong_image_operator | |
| 740 | + * Pixel array has less than 4 dimensions. | |
| 741 | + * @exception GException::out_of_range | |
| 742 | + * Image axis not valid. | |
| 743 | + * | |
| 744 | + * Computes of offset in the pixel array of a 4D coordinate. This method is | |
| 745 | + * only applicable to pixels arrays that have at least 4 dimenions. | |
| 746 | + ***************************************************************************/ | |
| 747 | +int GFitsImage::offset(const int& ix, const int& iy, const int& iz, | |
| 748 | + const int& it) const | |
| 749 | +{ | |
| 750 | + // Operator is only valid for 4D images | |
| 751 | + if (m_naxis < 4) | |
| 752 | + throw GException::fits_wrong_image_operator(G_OFFSET_4D, m_naxis, 4); | |
| 753 | + | |
| 754 | + // Check if axis is within the range | |
| 755 | + #if defined(G_RANGE_CHECK) | |
| 756 | + if (ix < 0 || ix >= m_naxes[0]) | |
| 757 | + throw GException::out_of_range(G_OFFSET_4D, ix, 0, m_naxes[0]-1); | |
| 758 | + if (iy < 0 || iy >= m_naxes[1]) | |
| 759 | + throw GException::out_of_range(G_OFFSET_4D, iy, 0, m_naxes[1]-1); | |
| 760 | + if (iz < 0 || iz >= m_naxes[2]) | |
| 761 | + throw GException::out_of_range(G_OFFSET_4D, iz, 0, m_naxes[2]-1); | |
| 762 | + if (it < 0 || it >= m_naxes[3]) | |
| 763 | + throw GException::out_of_range(G_OFFSET_4D, it, 0, m_naxes[3]-1); | |
| 764 | + #endif | |
| 765 | + | |
| 766 | + // Return offset | |
| 767 | + return (ix + m_naxes[0] * (iy + m_naxes[1] * (iz + it * m_naxes[2]))); | |
| 768 | +} | |
| 769 | + | |
| 770 | + | |
| 635 | 771 | /*========================================================================== |
| 636 | 772 | = = |
| 637 | 773 | = Friends = | ... | ... |