[301] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // Section.hh: Definition of the Section class, used to store |
---|
| 3 | // definitions of subsections of a FITS file. |
---|
| 4 | // ----------------------------------------------------------------------- |
---|
| 5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 6 | // |
---|
| 7 | // This program is free software; you can redistribute it and/or modify it |
---|
| 8 | // under the terms of the GNU General Public License as published by the |
---|
| 9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 10 | // option) any later version. |
---|
| 11 | // |
---|
| 12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 15 | // for more details. |
---|
| 16 | // |
---|
| 17 | // You should have received a copy of the GNU General Public License |
---|
| 18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 20 | // |
---|
| 21 | // Correspondence concerning Duchamp may be directed to: |
---|
| 22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 23 | // Postal address: Dr. Matthew Whiting |
---|
| 24 | // Australia Telescope National Facility, CSIRO |
---|
| 25 | // PO Box 76 |
---|
| 26 | // Epping NSW 1710 |
---|
| 27 | // AUSTRALIA |
---|
| 28 | // ----------------------------------------------------------------------- |
---|
[254] | 29 | #ifndef SECTION_H |
---|
| 30 | #define SECTION_H |
---|
| 31 | |
---|
| 32 | #include <string> |
---|
| 33 | #include <vector> |
---|
| 34 | |
---|
[378] | 35 | namespace duchamp |
---|
[254] | 36 | { |
---|
| 37 | |
---|
[378] | 38 | /** |
---|
| 39 | * A class to store information on subsections of a cube. This keeps |
---|
| 40 | * the subsection itself as a string, plus the parsed information in |
---|
| 41 | * the format of vectors of starting positions and lengths of each |
---|
| 42 | * dimension. |
---|
| 43 | */ |
---|
[254] | 44 | |
---|
[378] | 45 | class Section |
---|
| 46 | { |
---|
| 47 | public: |
---|
| 48 | Section(); |
---|
| 49 | Section(std::string &s){subsection=s;}; |
---|
| 50 | Section(const Section& s); |
---|
| 51 | Section& operator= (const Section& s); |
---|
| 52 | virtual ~Section(){}; |
---|
[254] | 53 | |
---|
[378] | 54 | /** Convert the subsection string into the lists of numerical values. */ |
---|
| 55 | int parse(std::vector<long> dimAxes); |
---|
[254] | 56 | |
---|
[378] | 57 | /** Test whether a given voxel (x,y,z) lies within the subsection */ |
---|
| 58 | bool isInside(int x, int y, int z){ |
---|
| 59 | return ( ( (x>=starts[0])&&(x<starts[0]+dims[0]) ) && |
---|
| 60 | ( (y>=starts[1])&&(y<starts[1]+dims[1]) ) && |
---|
| 61 | ( (z>=starts[2])&&(z<starts[2]+dims[2]) ) ); |
---|
| 62 | } |
---|
[254] | 63 | |
---|
[378] | 64 | /** Save the subsection string */ |
---|
| 65 | void setSection(std::string s){subsection=s;}; |
---|
| 66 | /** Return the subsection string */ |
---|
| 67 | std::string getSection(){return subsection;}; |
---|
[254] | 68 | |
---|
[378] | 69 | /** Return a particular starting value */ |
---|
| 70 | int getStart(int i){return starts[i];}; |
---|
| 71 | /** Set a particular starting value */ |
---|
| 72 | void setStart(int i, int val){starts[i]=val;}; |
---|
[254] | 73 | |
---|
[378] | 74 | /** Return a particular dimension length */ |
---|
| 75 | int getDim(int i){return dims[i];}; |
---|
| 76 | /** Set a particular dimension length */ |
---|
| 77 | void setDim(int i, int val){dims[i]=val;}; |
---|
[254] | 78 | |
---|
[378] | 79 | /** Return a particular ending value */ |
---|
| 80 | int getEnd(int i){return starts[i]+dims[i]-1;}; |
---|
| 81 | /** Set a particular ending value, using the current starting value */ |
---|
| 82 | void setEnd(int i, int val){dims[i]=val-starts[i]+1;}; |
---|
| 83 | |
---|
| 84 | /** Return the full list of start values */ |
---|
| 85 | std::vector<int> getStartList(){return starts;}; |
---|
| 86 | /** Return the full list of dimension lengths */ |
---|
| 87 | std::vector<int> getDimList(){return dims;}; |
---|
| 88 | |
---|
| 89 | private: |
---|
| 90 | std::string subsection; ///< The string indicating the subsection, |
---|
| 91 | /// of the format [a:b,c:d,e:f] etc. |
---|
| 92 | int numSections; ///< The number of sections in the string. |
---|
| 93 | std::vector<int> starts; ///< The list of starting values (a,c,e) |
---|
| 94 | std::vector<int> dims; ///< The list of lengths of each dimension |
---|
| 95 | /// (b-a+1,d-c+1,f-e+1) |
---|
| 96 | }; |
---|
| 97 | |
---|
| 98 | } |
---|
| 99 | |
---|
[254] | 100 | #endif //SECTION_H |
---|