source: tags/release-1.1.5/src/Detection/detection.hh @ 1441

Last change on this file since 1441 was 457, checked in by MatthewWhiting, 16 years ago

private --> protected for member data of Detection (for tagged release 1.1.5)

File size: 15.4 KB
Line 
1// -----------------------------------------------------------------------
2// detection.hh: Definition of the Detection class.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#ifndef DETECTION_H
29#define DETECTION_H
30
31#include <iostream>
32#include <string>
33#include <vector>
34#include <duchamp/param.hh>
35#include <duchamp/PixelMap/Voxel.hh>
36#include <duchamp/PixelMap/Object3D.hh>
37#include <duchamp/Detection/columns.hh>
38
39namespace duchamp
40{
41
42
43  /**
44   * Class to represent a contiguous set of detected voxels.
45   *  This is a detected object, which features:
46   *   a vector of voxels, average and centroid positions, total & peak fluxes,
47   *   the possibility of WCS-calculated parameters (RA, Dec, velocity,
48   *     related widths).
49   *  Also many functions with which to manipulate the Detections.
50   */
51
52  class Detection
53  {
54  public:
55    Detection();
56    Detection(const Detection& d);
57    Detection& operator= (const Detection& d);
58    virtual ~Detection(){};
59    //------------------------------
60    // These are functions in detection.cc.
61    //
62    /** Add all voxels of one object to another. */
63    friend Detection operator+ (Detection lhs, Detection rhs);
64    friend Detection operator+= (Detection lhs, Detection rhs){
65      lhs = lhs + rhs;
66      return lhs;
67    }
68
69    /** Provides a reference to the pixel array. */
70    PixelInfo::Object3D& pixels(){
71      PixelInfo::Object3D &rpix = this->pixelArray;
72      return rpix;
73    };
74
75    /** Calculate basic parameters of the Detection. */
76    void   calcParams(){pixelArray.calcParams();};
77
78    /** Test whether voxel lists match */
79    bool voxelListsMatch(std::vector<PixelInfo::Voxel> voxelList);
80
81    /** Calculate flux-related parameters of the Detection. */
82    void   calcFluxes(float *fluxArray, long *dim);
83    /** Calculate flux-related parameters of the Detection. */
84    void   calcFluxes(std::vector<PixelInfo::Voxel> voxelList);
85
86    /** Calculate parameters related to the World Coordinate System. */
87    //    void   calcWCSparams(float *fluxArray, long *dim, FitsHeader &head);
88    void   calcWCSparams(FitsHeader &head);
89
90    /** Calculate the integrated flux over the entire Detection. */
91    void   calcIntegFlux(float *fluxArray, long *dim, FitsHeader &head);
92    /** Calculate the integrated flux over the entire Detection. */
93    void   calcIntegFlux(std::vector<PixelInfo::Voxel> voxelList, FitsHeader &head);
94
95    /** Set the values of the axis offsets from the cube. */
96    void   setOffsets(Param &par);
97
98    /** Add the offset values to the pixel locations */
99    void   addOffsets(){
100      pixelArray.addOffsets(xSubOffset,ySubOffset,zSubOffset);
101    };
102
103    //
104    friend std::ostream& operator<< ( std::ostream& theStream, Detection& obj);
105    //---------------------------------
106    // Text Output -- all in Detection/outputDetection.cc
107    //
108    /** The spectral output label that contains info on the WCS position
109        & velocity.*/
110    std::string outputLabelWCS(); 
111
112    /** The spectral output label that contains info on the pixel
113        location. */
114    std::string outputLabelPix();
115
116    /** The spectral output label that contains info on fluxes of the
117        Detection. */
118    std::string outputLabelFluxes();
119
120    /** The spectral output label that contains info on widths of the
121        Detection. */
122    std::string outputLabelWidths();
123
124    /** Print all required values for the Detection to a table.*/
125    void printTableRow(std::ostream &stream, std::vector<Column::Col> columns, std::string tableType);
126
127    /** Print a particular value for the Detection to a table.*/
128    void printTableEntry(std::ostream &stream, Column::Col column);
129
130    //----------------------------------
131    // For plotting routines... in Cubes/drawMomentCutout.cc
132    //
133    /** Get the location of the spatial borders. */
134    std::vector<int> getVertexSet();
135    //
136    /** Draw spatial borders for a particular Detection. */
137    void   drawBorders(int xoffset, int yoffset);
138    //
139    /** Sort the pixels by central z-value. */
140    void   SortByZ(){pixelArray.order();};
141    //
142    //----------------------------------
143    // Basic functions
144    //
145    /** Delete all pixel information from Detection. Does not clear
146        other parameters. */
147    //  void   clearDetection(){this->pix.clear();};
148
149    /** Add a single voxel to the pixel list.*/
150    void   addPixel(long x, long y, long z){pixelArray.addPixel(x,y,z);};
151    /** Add a single voxel to the pixel list.*/
152    void   addPixel(PixelInfo::Voxel point){
153      /** This one adds the pixel to the pixelArray, and updates the
154          fluxes according to the Voxel's flux information */
155      pixelArray.addPixel(point);
156      totalFlux += point.getF();
157      if(point.getF()>peakFlux){
158        peakFlux = point.getF();
159        xpeak = point.getX(); ypeak = point.getY(); zpeak = point.getZ();
160      }
161    };
162
163    /** Return a single voxel. */
164    PixelInfo::Voxel getPixel(int i){return pixelArray.getPixel(i);};
165
166    /** Return the set of voxels. */
167    std::vector<PixelInfo::Voxel> getPixelSet(){return pixelArray.getPixelSet();};
168
169    /** How many voxels are in the Detection? */
170    int    getSize(){return pixelArray.getSize();};
171
172    /** How many distinct spatial pixels are there? */
173    int    getSpatialSize(){return pixelArray.getSpatialSize();};
174
175    /** How many channels does the Detection have? */
176    long   getNumChannels(){return pixelArray.getNumDistinctZ();};
177
178    /** Is there at least the acceptable minimum number of channels in
179        the Detection?  */
180    bool   hasEnoughChannels(int minNumber);
181 
182    //-----------------------------------
183    // Basic accessor functions for private members follow...
184    //
185    long        getXOffset(){return xSubOffset;};
186    void        setXOffset(long o){xSubOffset = o;};
187    long        getYOffset(){return ySubOffset;};
188    void        setYOffset(long o){ySubOffset = o;};
189    long        getZOffset(){return zSubOffset;};
190    void        setZOffset(long o){zSubOffset = o;};
191    //       
192    float       getXcentre(){
193      if(centreType=="peak") return xpeak;
194      else if(centreType=="average") return pixelArray.getXcentre();
195      else return xCentroid;
196    };
197    float       getYcentre(){
198      if(centreType=="peak") return ypeak;
199      else if(centreType=="average") return pixelArray.getYcentre();
200      else return yCentroid;
201    };
202    float       getZcentre(){
203      if(centreType=="peak") return zpeak;
204      else if(centreType=="average") return pixelArray.getZcentre();
205      else return zCentroid;
206    };
207    float       getXAverage(){return pixelArray.getXcentre();};
208    float       getYAverage(){return pixelArray.getYcentre();};
209    float       getZAverage(){return pixelArray.getZcentre();};
210    float       getTotalFlux(){return totalFlux;};
211    void        setTotalFlux(float f){totalFlux=f;};
212    double      getIntegFlux(){return intFlux;};
213    void        setIntegFlux(double f){intFlux=f;};
214    float       getPeakFlux(){return peakFlux;};
215    void        setPeakFlux(float f){peakFlux=f;};
216    long        getXPeak(){return xpeak;};
217    long        getYPeak(){return ypeak;};
218    long        getZPeak(){return zpeak;};
219    float       getPeakSNR(){return peakSNR;};
220    void        setPeakSNR(float f){peakSNR = f;};
221    float       getXCentroid(){return xCentroid;};
222    float       getYCentroid(){return yCentroid;};
223    float       getZCentroid(){return zCentroid;};
224    std::string getCentreType(){return centreType;};
225    void        setCentreType(std::string s){centreType=s;};
226    bool        isNegative(){return negSource;};
227    void        setNegative(bool f){negSource = f;};
228    std::string getFlagText(){return flagText;};
229    void        setFlagText(std::string s){flagText = s;};
230    void        addToFlagText(std::string s){flagText += s;};
231    //       
232    long        getXmin(){return pixelArray.getXmin();};
233    long        getYmin(){return pixelArray.getYmin();};
234    long        getZmin(){return pixelArray.getZmin();};
235    long        getXmax(){return pixelArray.getXmax();};
236    long        getYmax(){return pixelArray.getYmax();};
237    long        getZmax(){return pixelArray.getZmax();};
238    //
239    /** Is the WCS good enough to be used?
240        \return Detection::flagWCS =  True/False */
241    bool        isWCS(){return flagWCS;};
242    bool        isSpecOK(){return specOK;};
243    void        setSpecOK(bool b){specOK=b;};
244    std::string getName(){return name;};
245    void        setName(std::string s){name=s;};
246    std::string getRAs(){return raS;};
247    std::string getDecs(){return decS;};
248    float       getRA(){return ra;};
249    float       getDec(){return dec;};
250    float       getRAWidth(){return raWidth;};
251    float       getDecWidth(){return decWidth;};
252    float       getVel(){return vel;};
253    float       getVelWidth(){return velWidth;};
254    float       getVelMin(){return velMin;};
255    float       getVelMax(){return velMax;};
256    int         getID(){return id;};
257    void        setID(int i){id = i;};
258    //
259    int         getPosPrec(){return posPrec;};
260    void        setPosPrec(int i){posPrec=i;};
261    int         getXYZPrec(){return xyzPrec;};
262    void        setXYZPrec(int i){xyzPrec=i;};
263    int         getFintPrec(){return fintPrec;};
264    void        setFintPrec(int i){fintPrec=i;};
265    int         getFpeakPrec(){return fpeakPrec;};
266    void        setFpeakPrec(int i){fpeakPrec=i;};
267    int         getVelPrec(){return velPrec;};
268    void        setVelPrec(int i){velPrec=i;};
269    int         getSNRPrec(){return snrPrec;};
270    void        setSNRPrec(int i){snrPrec=i;};
271    //
272  protected:
273    PixelInfo::Object3D pixelArray;     ///< The pixel locations
274    // Subsection offsets
275    long           xSubOffset;     ///< The x-offset, from subsectioned cube
276    long           ySubOffset;     ///< The y-offset, from subsectioned cube
277    long           zSubOffset;     ///< The z-offset, from subsectioned cube
278    // Flux related
279    float          totalFlux;      ///< sum of the fluxes of all the pixels
280    double         intFlux;        ///< integrated flux : involves
281    ///    integration over velocity.
282    float          peakFlux;       ///< maximum flux over all the pixels
283    long           xpeak;          ///< x-pixel location of peak flux
284    long           ypeak;          ///< y-pixel location of peak flux
285    long           zpeak;          ///< z-pixel location of peak flux
286    float          peakSNR;        ///< signal-to-noise ratio at peak
287    float          xCentroid;      ///< x-pixel location of centroid
288    float          yCentroid;      ///< y-pixel location of centroid
289    float          zCentroid;      ///< z-pixel location of centroid
290    std::string    centreType;     ///< which type of pixel centre to
291    ///   report: "average", "centroid", or
292    ///   "peak" (flux)
293    bool           negSource;      ///< is the source a negative feature?
294    std::string    flagText;       ///< any warning flags about the
295    ///    quality of the detection.
296    // WCS related
297    int            id;             ///< ID -- generally number in list
298    std::string    name;                 ///< IAU-style name (based on position)
299    bool           flagWCS;        ///< A flag indicating whether the
300    ///    WCS parameters have been set.
301    std::string    raS;          ///< Central Right Ascension (or
302                                 ///    Longitude) in form 12:34:23
303    std::string    decS;                 ///< Central Declination(or
304    ///    Latitude), in form -12:23:34
305    float          ra;           ///< Central Right Ascension in degrees
306    float          dec;          ///< Central Declination in degrees
307    float          raWidth;        ///< Width of detection in RA
308    ///   direction in arcmin
309    float          decWidth;       ///< Width of detection in Dec
310    ///   direction in arcmin
311    bool           specOK;         ///< Is the spectral dimension valid?
312    std::string    specUnits;      ///< Units of the spectral dimension
313    std::string    fluxUnits;      ///< Units of flux
314    std::string    intFluxUnits;   ///< Units of integrated flux
315    std::string    lngtype;        ///< Type of longitude axis (RA/GLON)
316    std::string    lattype;        ///< Type of latitude axis (DEC/GLAT)
317    float          vel;          ///< Central velocity (from zCentre)
318    float          velWidth;       ///< Full velocity width
319    float          velMin;         ///< Minimum velocity
320    float          velMax;         ///< Maximum velocity
321    //  The next six are the precision of values printed in the headers
322    //  of the spectral plots
323    int            posPrec;        ///< Precision of WCS positional values
324    int            xyzPrec;        ///< Precision of pixel positional
325    ///   values
326    int            fintPrec;       ///< Precision of F_int/F_tot values
327    int            fpeakPrec;      ///< Precision of F_peak values
328    int            velPrec;        ///< Precision of velocity values.
329    int            snrPrec;        ///< Precision of S/N_max values.
330
331  };
332
333  //==========================================================================
334
335  //////////////////////////////////////////////////////
336  // Prototypes for functions that use above classes
337  //////////////////////////////////////////////////////
338
339  //----------------
340  // These are in sorting.cc
341  //
342  /** Sort a list of Detections by Z-pixel value. */
343  void SortByZ(std::vector <Detection> &inputList);
344
345  /** Sort a list of Detections by Velocity.*/
346  void SortByVel(std::vector <Detection> &inputList);
347
348  //----------------
349  // This is in areClose.cc
350  //
351  /** Determine whether two objects are close according to set parameters.*/
352  bool areClose(Detection &object1, Detection &object2, Param &par);
353
354  //----------------
355  // This is in mergeIntoList.cc
356  //
357  /** Add an object into a list, combining with adjacent objects if need be. */
358  void mergeIntoList(Detection &object, std::vector <Detection> &objList,
359                     Param &par);
360
361  //----------------
362  // These are in Cubes/Merger.cc
363  //
364  /** Merge a list of Detections so that all adjacent voxels are in the same Detection. */
365  void mergeList(std::vector<Detection> &objList, Param &par);   
366  /** Culls a list of Detections that do not meet minimum requirements. */
367  void finaliseList(std::vector<Detection> &objList, Param &par);
368  /** Manage both the merging and the cleaning up of the list. */
369  void ObjectMerger(std::vector<Detection> &objList, Param &par);
370
371  /** Print the header information to a particular table */
372  void outputTableHeader(std::ostream &stream, std::vector<Column::Col> columns, std::string tableType, bool flagWCS);
373
374}
375
376#endif
Note: See TracBrowser for help on using the repository browser.