source: tags/release-1.1.9/src/PixelMap/Object3D.hh @ 1441

Last change on this file since 1441 was 658, checked in by MatthewWhiting, 14 years ago

Fixed a bug in addOffsets that didn't add some offsets.

Also made a new function to return a subsection that bounds the object.

File size: 5.6 KB
Line 
1// -----------------------------------------------------------------------
2// Object3D.hh: Definition of the Object3D class that holds
3//              pixel information for a three-dimensional object.
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 OBJECT3D_H
30#define OBJECT3D_H
31
32#include <duchamp/PixelMap/Voxel.hh>
33#include <duchamp/PixelMap/Scan.hh>
34#include <duchamp/PixelMap/Object2D.hh>
35#include <duchamp/Utils/Section.hh>
36#include <vector>
37#include <algorithm>
38#include <map>
39#include <iostream>
40
41namespace PixelInfo
42{
43
44  /// @brief A set of pixels in 3D. 
45  ///
46  /// @details This stores the pixels in a STL map, connecting a
47  /// channel number (z-value) to a unique Object2D. Also recorded
48  /// are the average x-, y- and z-values (via their sums), as well as
49  /// their extrema.
50
51  class Object3D
52  {
53  public:
54    Object3D();
55    Object3D(const Object3D& o);
56    Object3D& operator= (const Object3D& o); 
57    virtual ~Object3D(){};
58
59    /// @brief Is a 3-D voxel in the Object?
60    bool isInObject(long x, long y, long z);
61    /// @brief Is a 3-D voxel in the Object?
62    bool isInObject(Voxel v){return isInObject(v.getX(),v.getY(),v.getZ());};
63 
64    /// @brief Add a single 3-D voxel to the Object.
65    virtual void addPixel(long x, long y, long z);
66    /// @brief Add a single 3-D voxel to the Object.
67    virtual void addPixel(Voxel v){addPixel(v.getX(),v.getY(),v.getZ());};
68    /// @brief Add a scan to the object
69    void addScan(Scan s, long z);
70    /// @brief Add a full channel map to the Object.
71    void addChannel(const long &z, Object2D &obj);
72
73    /// @brief Calculate the averages and extrema of the three coordinates.
74    void calcParams();
75    /// @brief Return the average x-value.
76    float getXaverage();
77    /// @brief Return the average y-value.
78    float getYaverage();
79    /// @brief Return the average z-value.
80    float getZaverage();
81    /// @brief Return the minimum x-value.
82    long getXmin(){return xmin;};
83    /// @brief Return the minimum y-value.
84    long getYmin(){return ymin;};
85    /// @brief Return the minimum z-value.
86    long getZmin(){return zmin;};
87    /// @brief Return the maximum x-value.
88    long getXmax(){return xmax;};
89    /// @brief Return the maximum y-value.
90    long getYmax(){return ymax;};
91    /// @brief Return the maximum z-value.
92    long getZmax(){return zmax;};
93
94    /// @brief Return the number of distinct voxels in the Object.
95    unsigned int getSize(){return numVox;};
96
97    /// @brief Return the number of distinct channels in the Object.
98    long getNumDistinctZ(){return chanlist.size();};
99
100    /// @brief Return the number of channels in the Object.
101    long getNumChanMap(){return chanlist.size();};
102
103    /// @brief Return the number of spatial pixels -- ie. the number of distinct (x,y) sets in the Object.
104    unsigned long getSpatialSize();
105
106    /// @brief Return a vector set of all voxels in the Object.
107    std::vector<Voxel> getPixelSet();
108
109    /// @brief Return a vector list of the channel numbers in the Object
110    std::vector<long> getChannelList();
111
112    /// @brief Return the largest number of adjacent channels in the Object.
113    int getMaxAdjacentChannels();
114
115    /// @brief Get the channel map for channel z.
116    Object2D getChanMap(long z);
117
118    /// @brief Return an Object2D showing the spatial (x,y) distribution of voxels in the Object
119    Object2D getSpatialMap();
120
121    /// @brief Add constant offsets to each of the dimensions, changing the parameters at the same time.
122    virtual void addOffsets(long xoff, long yoff, long zoff);
123
124    /// @brief Return the bounding box for the object, as a duchamp::Section object
125    duchamp::Section getBoundingSection(int boundary=1);
126
127    /// @brief Output operator for the Object3D.
128    friend std::ostream& operator<< ( std::ostream& theStream, Object3D& obj);
129
130    /// @brief Add two Object3Ds. Overlapping channels are combined using addChannel().
131    friend Object3D operator+ (Object3D lhs, Object3D rhs);
132
133  protected:
134    std::map<long,Object2D> chanlist;  ///< The list of 2D channel maps
135    unsigned long           numVox;    ///< How many voxels in the Object?
136    float                   xSum;      ///< Sum of the x-values
137    float                   ySum;      ///< Sum of the y-values
138    float                   zSum;      ///< Sum of the z-values
139    long                    xmin,xmax; ///< min and max x-values of object
140    long                    ymin,ymax; ///< min and max y-values of object
141    long                    zmin,zmax; ///< min and max z-values of object
142  };
143
144}
145
146#endif //OBJECT3D_H
Note: See TracBrowser for help on using the repository browser.