source: trunk/src/Utils/Section.hh @ 368

Last change on this file since 368 was 365, checked in by MatthewWhiting, 17 years ago
  • Mainly fixing up copy constructors & assignment operators
  • Improved the testing of whether there is a spectral or third axis, including giving FitsHeader? a new function. Also improved the tabular output of VEL/WVEL.
  • Improved the F_int column -- made sure its width is always calculated, and gave it default units
  • Improved the printSpace etc functions, to accept an arbitrary stream
  • Removed some unnecessary comments
File size: 3.2 KB
Line 
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// -----------------------------------------------------------------------
29#ifndef SECTION_H
30#define SECTION_H
31
32#include <string>
33#include <vector>
34
35/**
36 * A class to store information on subsections of a cube. This keeps
37 * the subsection itself as a string, plus the parsed information in
38 * the format of vectors of starting positions and lengths of each
39 * dimension.
40 */
41
42class Section
43{
44public:
45  Section();
46  Section(std::string &s){subsection=s;};
47  Section(const Section& s);
48  Section& operator= (const Section& s);
49  virtual ~Section(){};
50
51  /** Convert the subsection string into the lists of numerical values. */
52  int parse(std::vector<long> dimAxes);
53
54  /** Test whether a given voxel (x,y,z) lies within the subsection */
55  bool isInside(int x, int y, int z){
56    return (  ( (x>=starts[0])&&(x<starts[0]+dims[0])  ) &&
57              ( (y>=starts[1])&&(y<starts[1]+dims[1])  ) &&
58              ( (z>=starts[2])&&(z<starts[2]+dims[2])  )   );
59  }
60
61  /** Save the subsection string */
62  void setSection(std::string s){subsection=s;};
63  /** Return the subsection string */
64  std::string getSection(){return subsection;};
65
66  /** Return a particular starting value */
67  int getStart(int i){return starts[i];};
68  /** Return a particular dimension length */
69  int getDim(int i){return dims[i];};
70  /** Return a particular ending value */
71  int getEnd(int i){return starts[i]+dims[i]-1;};
72
73  /** Return the full list of start values */
74  std::vector<int> getStartList(){return starts;};
75  /** Return the full list of dimension lengths */
76  std::vector<int> getDimList(){return dims;};
77
78private:
79  std::string subsection;   ///< The string indicating the subsection,
80                            ///   of the format [a:b,c:d,e:f] etc.
81  int numSections;          ///< The number of sections in the string.
82  std::vector<int> starts;  ///< The list of starting values (a,c,e)
83  std::vector<int> dims;    ///< The list of lengths of each dimension
84                            ///   (b-a+1,d-c+1,f-e+1)
85};
86
87
88#endif //SECTION_H
Note: See TracBrowser for help on using the repository browser.