source: trunk/src/Utils/Section.hh

Last change on this file was 1263, checked in by MatthewWhiting, 11 years ago

Extra types for the subsection parsing functions.

File size: 5.5 KB
RevLine 
[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>
[698]34#include <duchamp/duchamp.hh>
[254]35
[378]36namespace duchamp
[254]37{
38
[528]39  /// @brief A class to store information on subsections of a cube.
40  ///
41  /// @details This keeps the subsection itself as a string, plus the
42  /// parsed information in the format of vectors of starting
43  /// positions and lengths of each dimension.
[254]44
[378]45  class Section
46  {
47  public:
48    Section();
[880]49    Section(std::string &s){subsection=s; numSections=0; flagParsed=false;};
[378]50    Section(const Section& s);
51    Section& operator= (const Section& s);
52    virtual ~Section(){};
[254]53
[816]54    /// @brief Has the section been defined by a parse() call?
55    bool isDefined(){return numSections>0;};
56
57    /// @brief Are all axis sections of length >0?
58    bool isValid();
59
[528]60    /// @brief Convert the subsection string into the lists of numerical values.
[884]61    OUTCOME parse(std::vector<size_t> dimAxes);
[698]62    OUTCOME parse(std::vector<long> dimAxes);
63    OUTCOME parse(std::vector<int> dimAxes);
[884]64    OUTCOME parse(size_t *dim, int size);
[698]65    OUTCOME parse(long *dim, int size);
[254]66
[880]67    bool isParsed(){return flagParsed;};
68
[528]69    /// @brief Test whether a given voxel (x,y,z) lies within the subsection
[378]70    bool isInside(int x, int y, int z){
71      return (  ( (x>=starts[0])&&(x<starts[0]+dims[0])  ) &&
72                ( (y>=starts[1])&&(y<starts[1]+dims[1])  ) &&
73                ( (z>=starts[2])&&(z<starts[2]+dims[2])  )   );
74    }
[254]75
[528]76    /// @brief Save the subsection string
[378]77    void setSection(std::string s){subsection=s;};
[528]78    /// @brief Return the subsection string
[378]79    std::string getSection(){return subsection;};
[254]80
[528]81    /// @brief Save a single dimension's subsection string
[537]82    void setSection(unsigned int i, std::string s){sections[i] = s;};
[528]83    /// @brief Return a particular dimension's subsection string
[537]84    std::string getSection(unsigned int i){if(i>=numSections) return "*"; else return sections[i];};
[507]85
[528]86    /// @brief Return a particular starting value
[537]87    int getStart(unsigned int i){if(i>=numSections) return 0; else return starts[i];};
[528]88    /// @brief Set a particular starting value
[537]89    void setStart(unsigned int i, unsigned int val){starts[i]=val;};
[254]90
[528]91    /// @brief Return a particular dimension length
[537]92    int getDim(unsigned int i){if(i>=numSections) return 1; else return dims[i];};
[528]93    /// @brief Set a particular dimension length
[537]94    void setDim(unsigned int i, unsigned int val){dims[i]=val;};
[254]95
[528]96    /// @brief Return a particular ending value
[537]97    int getEnd(unsigned int i){if(i>=numSections) return 0; else return starts[i]+dims[i]-1;};
[528]98    /// @brief Set a particular ending value, using the current starting value
[537]99    void setEnd(unsigned int i, unsigned int val){dims[i]=val-starts[i]+1;};
[378]100
[528]101    /// @brief Return the full list of start values
[378]102    std::vector<int> getStartList(){return starts;};
[528]103    /// @brief Return the full list of dimension lengths
[378]104    std::vector<int> getDimList(){return dims;};
105
[818]106    /// @brief Return a section that is the intersection of this with another
107    Section intersect(Section &other);
108
[828]109    /// @brief Return a section that is the intersection of this with the full section given by a set of axis dimensions
[1263]110    Section intersect(std::vector<size_t> dimAxes);
[828]111    Section intersect(std::vector<long> dimAxes);
112    Section intersect(std::vector<int> dimAxes);
113    Section intersect(long *dim, int size);
114
[880]115    /// @brief Return a section that is the result of applying some subseection of the current one, where the "other" subsection acts in the coordinates of this.
116    friend Section operator* (Section &lhs, Section &rhs);
117
[378]118  private:
[880]119    bool flagParsed;            ///< Has the Section been parsed yet?
[507]120    std::string subsection;   ///< The string indicating the subsection, of the format [a:b,c:d,e:f] etc.
121    std::vector<std::string> sections; // The individual section strings for each dimension
[623]122    size_t numSections;         ///< The number of sections in the string.
[378]123    std::vector<int> starts;  ///< The list of starting values (a,c,e)
[507]124    std::vector<int> dims;    ///< The list of lengths of each dimension (b-a+1,d-c+1,f-e+1)
[378]125  };
126
[507]127  std::string nullSection(int ndim);
128
[378]129}
130
[254]131#endif //SECTION_H
Note: See TracBrowser for help on using the repository browser.