source: trunk/src/PixelMap/Object3D.hh @ 1441

Last change on this file since 1441 was 1293, checked in by MatthewWhiting, 11 years ago

Ticket #200 - Largely resolved. The getVertexSet function now resides in Object3D, and returns a set of Voxel vectors, that describe the bounding vertices of the object (in 2D projection). Changes also made to the functions that call this, and to the verification outputs that are affected (notably the .ann and .reg files).

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