source: tags/release-1.1.5/src/Cubes/cubes.hh @ 1441

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

Added another allocation flag, this time for the pixel array itself.

File size: 26.9 KB
Line 
1// -----------------------------------------------------------------------
2// cubes.hh: Definitions of the DataArray, Cube and Image classes.
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 CUBES_H
29#define CUBES_H
30
31#include <iostream>
32#include <string>
33#include <vector>
34
35#include <duchamp/param.hh>
36#include <duchamp/fitsHeader.hh>
37#include <duchamp/Detection/detection.hh>
38#include <duchamp/Detection/columns.hh>
39#include <duchamp/Cubes/plots.hh>
40#include <duchamp/Utils/Statistics.hh>
41#include <duchamp/PixelMap/Scan.hh>
42#include <duchamp/PixelMap/Object2D.hh>
43
44
45namespace duchamp
46{
47
48
49  /** Search a reconstructed array for significant detections. */
50  std::vector <Detection>
51  searchReconArray(long *dim, float *originalArray, float *reconArray,
52                   Param &par, Statistics::StatsContainer<float> &stats);
53  std::vector <Detection>
54  searchReconArraySimple(long *dim, float *originalArray, float *reconArray,
55                         Param &par, Statistics::StatsContainer<float> &stats);
56
57  /** Search a 3-dimensional array for significant detections. */
58  std::vector <Detection>
59  search3DArray(long *dim, float *Array, Param &par,
60                Statistics::StatsContainer<float> &stats);
61  std::vector <Detection>
62  search3DArraySimple(long *dim, float *Array, Param &par,
63                      Statistics::StatsContainer<float> &stats);
64
65  /**
66   * Base class for the image container.
67   *
68   * Definition of an n-dimensional data array:
69   *     array of pixel values, size & dimensions
70   *     array of Detection objects
71   */
72
73  class DataArray
74  {
75  public:
76    DataArray();  ///< Basic DataArray constructor
77    DataArray(short int nDim); ///< Basic nDim-dimensional DataArray constructor
78    DataArray(short int nDim, long size);///< Basic nDim-dimensional DataArray constructor, specifying size.
79    DataArray(short int nDim, long *dimensions); ///< Basic nDim-dimensional DataArray constructor, specifying size of dimensions.
80    virtual ~DataArray(); ///< Basic DataArray constructor
81
82    //-----------------------------------------
83    // Obvious inline accessor functions.
84    //
85    long               getDimX(){if(numDim>0) return axisDim[0];else return 0;};
86    long               getDimY(){if(numDim>1) return axisDim[1];else return 1;};
87    long               getDimZ(){if(numDim>2) return axisDim[2];else return 1;};
88    long               getSize(){ return numPixels; };
89    short int          getNumDim(){ return numDim; };
90    virtual float      getPixValue(long pos){ return array[pos]; };
91    virtual void       setPixValue(long pos, float f){array[pos] = f;};
92    Detection          getObject(long number){ return objectList->at(number); };
93    Detection *        pObject(long number){ return &(objectList->at(number));};
94    std::vector <Detection> getObjectList(){ return *objectList; };
95    std::vector <Detection> *pObjectList(){ return objectList; };
96    std::vector <Detection> &ObjectList(){ std::vector<Detection> &rlist = *objectList; return rlist; };
97    long               getNumObj(){ return objectList->size(); };
98
99    /** Delete all objects from the list of detections. */
100    void               clearDetectionList(){
101      //objectList->clear();
102      delete objectList;
103      objectList = new std::vector<Detection>;
104    };
105
106    /** Read a parameter set from file. */
107    int                readParam(std::string paramfile){
108      /**
109       *  Uses Param::readParams() to read parameters from a file.
110       *  \param paramfile The file to be read.
111       */
112      return par.readParams(paramfile);
113    };
114
115    //-----------------------------------------
116    // Related to the various arrays
117    //
118    /**  Return first three dimensional axes. */
119    void               getDim(long &x, long &y, long &z);
120    /** Return array of dimensional sizes.*/
121    void               getDimArray(long *output);
122    long *             getDimArray(){return axisDim;};
123
124    /** Return pixel value array. */
125    void               getArray(float *output);
126    float *            getArray(){return array;};
127
128    /** Save pixel value array. */
129    virtual void       saveArray(float *input, long size);
130
131    //-----------------------------------------
132    // Related to the object lists
133    //
134    /** Adds a single detection to the object list.*/
135    void               addObject(Detection object);
136
137    /** Adds all objects in a detection list to the object list. */
138    void               addObjectList(std::vector <Detection> newlist);   
139
140    /** Add pixel offsets to object coordinates. */
141    void               addObjectOffsets();
142
143    //-----------------------------------------
144    // Parameter list related.
145    //
146    /** Output the Param set.*/
147    void               showParam(std::ostream &stream){ stream << par; };
148    /** Return the Param set.*/
149    Param              getParam(){ return par; };
150    /** Save a Param set to the Cube.*/
151    void               saveParam(Param &newpar){par = newpar;};
152    /** Provides a reference to the Param set.*/
153    Param&             pars(){ Param &rpar = par; return rpar; };
154    /** Is the voxel number given by vox a BLANK value?*/
155    bool               isBlank(int vox);
156
157    // --------------------------------------------
158    // Statistics
159    //
160    /**  Returns the StatsContainer. */
161    Statistics::StatsContainer<float> getStats(){ return Stats; };
162
163    /** Provides a reference to the StatsContainer. */
164    Statistics::StatsContainer<float>& stats(){
165      Statistics::StatsContainer<float> &rstats = Stats;  return rstats;
166    };
167 
168    /** Save a StatsContainer to the Cube. */
169    void saveStats(Statistics::StatsContainer<float> newStats){ Stats = newStats;};
170
171    /** A detection test for value. */
172    bool isDetection(float value);
173
174    /**  A detection test for pixel.  */
175    bool isDetection(long voxel);
176
177
178    /** Output operator for DataArray.*/
179    friend std::ostream& operator<< (std::ostream& theStream, DataArray &array);
180 
181
182  protected:
183    short int                numDim;     ///< Number of dimensions.
184    long                    *axisDim;    ///< Array of axis dimensions of cube
185    bool                     axisDimAllocated; ///< has axisDim been allocated?
186    long                     numPixels;  ///< Total number of pixels in cube.
187    float                   *array;      ///< Array of data.
188    bool                     arrayAllocated; ///< has the array been allocated?
189    std::vector <Detection> *objectList; ///< The list of detected objects.
190    Param                    par;        ///< A parameter list.
191    Statistics::StatsContainer<float> Stats; ///< The statistics for the DataArray.
192  };
193
194
195
196  //=========================================================================
197
198  /**
199   * Definition of an data-cube object (3D):
200   *     a DataArray object limited to dim=3
201   */
202
203  class Cube : public DataArray
204  {
205  public:
206    Cube();                 ///< Basic Cube constructor.
207    Cube(long nPix);        ///< Alternative Cube constructor.
208    Cube(long *dimensions); ///< Alternative Cube constructor.
209    virtual ~Cube();        ///< Basic Cube destructor.
210
211    // INLINE functions -- definitions included after class declaration.
212    /** Is the voxel number given by vox a BLANK value? */
213    bool        isBlank(int vox){ return par.isBlank(array[vox]); };
214
215    /** Is the voxel at (x,y,z) a BLANK value? */
216    bool        isBlank(long x, long y, long z){
217      return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]); };
218
219    /** Does the Cube::recon array exist? */
220    bool        isRecon(){ return reconExists; };
221
222    float       getPixValue(long pos){ return array[pos]; };
223    float       getPixValue(long x, long y, long z){
224      return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
225    short       getDetectMapValue(long pos){ return detectMap[pos]; };
226    short       getDetectMapValue(long x, long y){ return detectMap[y*axisDim[0]+x]; };
227    float       getReconValue(long pos){ return recon[pos]; };
228    float       getReconValue(long x, long y, long z){
229      return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
230    float       getBaselineValue(long pos){ return baseline[pos]; };
231    float       getBaselineValue(long x, long y, long z){
232      return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
233    void        setPixValue(long pos, float f){array[pos] = f;};
234    void        setPixValue(long x, long y, long z, float f){
235      array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
236    void        setDetectMapValue(long pos, short f){ detectMap[pos] = f;};
237    void        setDetectMapValue(long x, long y, short f){ detectMap[y*axisDim[0] + x] = f;};
238    void        setReconValue(long pos, float f){recon[pos] = f;};
239    void        setReconValue(long x, long y, long z, float f){
240      recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; };
241    void        setReconFlag(bool f){reconExists = f;};
242
243    std::vector<Column::Col> getLogCols(){return logCols;};
244    void        setLogCols(std::vector<Column::Col> C){logCols=C;};
245    std::vector<Column::Col> getFullCols(){return fullCols;};
246    void        setFullCols(std::vector<Column::Col> C){fullCols=C;};
247
248    // additional functions -- in Cubes/cubes.cc
249    /** Allocate memory correctly, with WCS defining the correct axes. */
250    void        initialiseCube(long *dimensions);
251
252    /** Read in a FITS file, with subsection correction. */
253    int         getCube();
254    /** Read in a FITS file, with subsection correction. */
255    int         getMetadata();
256
257    /** Read in command-line options. */
258    //   int         getopts(int argc, char ** argv);
259    int         getopts(int argc, char ** argv){return par.getopts(argc,argv);};
260
261    /** Read in reconstructed & smoothed arrays from FITS files on disk. */
262    void        readSavedArrays();
263
264    /** Save an external array to the Cube's pixel array */
265    void        saveArray(float *input, long size);
266
267    /** Save an external array to the Cube's reconstructed array. */
268    void        saveRecon(float *input, long size);
269
270    /** Save reconstructed array to an external array. */
271    void        getRecon(float *output);
272    float *     getRecon(){return recon; };
273
274    /** Set Milky Way channels to zero. */
275    void        removeMW();
276
277    //------------------------
278    // Statistics for cube
279    //
280
281    /** Calculate the statistics for the Cube (older version). */
282    void        setCubeStatsOld();
283
284    /** Calculate the statistics for the Cube. */
285    void        setCubeStats();
286
287    /** Set up thresholds for the False Discovery Rate routine. */
288    void        setupFDR();
289    /** Set up thresholds for the False Discovery Rate routine using a
290        particular array. */
291    void        setupFDR(float *input);
292
293    /** A detection test for a given voxel. */
294    bool        isDetection(long x, long y, long z);
295
296    //-----------------------------
297    // Dealing with the detections
298    //
299
300    /** Calculate the object fluxes */
301    void        calcObjectFluxes();
302
303    /** Calculate the WCS parameters for each Cube Detection. */
304    void        calcObjectWCSparams();
305    /** Calculate the WCS parameters for each Cube Detection, using flux information in Voxels. */
306    void        calcObjectWCSparams(std::vector< std::vector<PixelInfo::Voxel> > bigVoxList);
307
308    /** Sort the list of detections. */
309    void        sortDetections();
310
311    /** Update the map of detected pixels. */
312    void        updateDetectMap();
313
314    /** Update the map of detected pixels for a given Detection. */
315    void        updateDetectMap(Detection obj);
316
317    /** Clear the map of detected pixels. */
318    void        clearDetectMap(){
319      for(int i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0;
320    };
321
322    /** Find the flux enclosed by a Detection. */
323    float       enclosedFlux(Detection obj);
324
325    /** Set up the output column definitions for the Cube and its
326        Detection list. */
327    void        setupColumns();
328
329    /** Is the object at the edge of the image? */
330    bool        objAtSpatialEdge(Detection obj);
331
332    /** Is the object at an end of the spectrum? */
333    bool        objAtSpectralEdge(Detection obj);
334
335    /** Set warning flags for the detections. */
336    void        setObjectFlags();
337
338    // ----------------------------
339    // Dealing with the WCS
340    //
341    /** Return the FitsHeader object. */
342    FitsHeader  getHead(){ return head; };
343    /** Define the FitsHeader object. */
344    void        setHead(FitsHeader F){head = F;};
345    /** Provide a reference to the FitsHeader object.*/
346    FitsHeader& header(){ FitsHeader &h = head; return h; };
347
348    /** Convert a point from WCS to Pixel coords. */
349    int         wcsToPix(const double *world, double *pix);
350
351    /** Convert a set of points from WCS to Pixel coords. */
352    int         wcsToPix(const double *world, double *pix, const int npts);
353
354    /** Convert a point from Pixel to WCS coords. */
355    int         pixToWCS(const double *pix, double *world);
356
357    /** Convert a set of points from Pixel to WCS coords. */
358    int         pixToWCS(const double *pix, double *world, const int npts);
359
360    //-------------------------------------------
361    // FITS-I/O related functions -- not in cubes.cc
362    //
363    /** Function to read in FITS file.*/
364    int         getMetadata(std::string fname);  // in Cubes/getImage.cc
365    int         getCube(std::string fname);  // in Cubes/getImage.cc
366
367    /** Convert the flux units to something user-specified.*/
368    void        convertFluxUnits(); // in Cubes/getImage.cc
369
370    /** Function to retrieve FITS data array */
371    int         getFITSdata(std::string fname);   // in FitsIO/dataIO.cc
372
373    /** Save a mask array to disk.*/
374    void        saveMaskCube();       // in Cubes/saveImage.cc
375
376    /** Save Smoothed array to disk.*/
377    void        saveSmoothedCube();       // in Cubes/saveImage.cc
378
379    /** Save Reconstructed array to disk. */
380    void        saveReconstructedCube();  // in Cubes/saveImage.cc
381
382    /** Read in reconstructed array from FITS file. */
383    int         readReconCube();  // in Cubes/readRecon.cc
384 
385    /** Read in Hanning-smoothed array from FITS file. */
386    int         readSmoothCube();     // in Cubes/readSmooth.cc 
387
388    //-------------------------------------
389    // Functions that act on the cube
390    //
391
392    /** Remove excess BLANK pixels from spatial edge of cube. */
393    void        trimCube();         // in Cubes/trimImage.cc
394
395    /** Replace BLANK pixels to spatial edge of cube. */
396    void        unTrimCube();       // in Cubes/trimImage.cc
397
398    /** Removes the baselines from the spectra, and stores in Cube::baseline */
399    void        removeBaseline();   // in Cubes/baseline.cc
400
401    /** Replace the baselines stored in Cube::baseline */
402    void        replaceBaseline();  // in Cubes/baseline.cc
403
404    /** Multiply all pixel values by -1. */
405    void        invert();           // in Cubes/invertCube.cc
406
407    /** Undo the inversion, and invert fluxes of all detected objects. */
408    void        reInvert();         // in Cubes/invertCube.cc
409
410    //-------------------------------------
411    // Reconstruction, Searching and Merging functions
412    //
413    // in ATrous/ReconSearch.cc
414    /** Front-end to reconstruction & searching functions.*/
415    void        ReconSearch();
416    /** Switcher to reconstruction functions */
417    void        ReconCube();
418    /** Performs 1-dimensional a trous reconstruction on the Cube. */
419    void        ReconCube1D();
420    /** Performs 2-dimensional a trous reconstruction on the Cube. */
421    void        ReconCube2D();
422    /** Performs 3-dimensional a trous reconstruction on the Cube. */
423    void        ReconCube3D();
424
425    // in Cubes/CubicSearch.cc
426    /** Front-end to the cubic searching routine. */
427    void        CubicSearch();
428
429    // in Cubes/smoothCube.cc
430    /** Smooth the cube with the requested method.*/
431    void        SmoothCube();
432    /** Front-end to the smoothing and searching functions. */
433    void        SmoothSearch();
434    /** A function to spatially smooth the cube and search the result. */
435    void        SpatialSmoothNSearch();
436    /** A function to Hanning-smooth the cube. */
437    void        SpectralSmooth();
438    /** A function to spatially-smooth the cube. */
439    void        SpatialSmooth();
440
441    void        Simple3DSearch(){
442      /**
443       * Basic front-end to the simple 3d searching function -- does
444       * nothing more.
445       *
446       * This function just runs the search3DArraySimple function,
447       * storing the results in the Cube::objectList vector. No stats
448       * are calculated beforehand, and no logging or detection map
449       * updating is done.
450       */
451      *objectList = search3DArraySimple(axisDim,array,par,Stats);
452    };
453
454    void        Simple3DSearchRecon(){
455      /**
456       * Basic front-end to the 3d searching function used in the
457       * reconstruction case -- does nothing more.
458       *
459       * This function just runs the searchReconArraySimple function,
460       * storing the results in the Cube::objectList vector. No stats
461       * are calculated beforehand, and no logging or detection map
462       * updating is done. The recon array is assumed to have been
463       * defined already.
464       */
465      *objectList = searchReconArraySimple(axisDim,array,recon,par,Stats);
466    };
467
468    void        Simple3DSearchSmooth(){
469      /**
470       * Basic front-end to the simple 3d searching function run on the
471       * smoothed array -- does nothing more.
472       *
473       * This function just runs the search3DArraySimple function on the
474       * recon array (which contains the smoothed array), storing the
475       * results in the Cube::objectList vector. No stats are calculated
476       * beforehand, and no logging or detection map updating is
477       * done. The recon array is assumed to have been defined already.
478       */
479      *objectList = search3DArraySimple(axisDim,recon,par,Stats);
480    };
481
482    // in Cubes/Merger.cc
483    /** Merge all objects in the detection list so that only distinct
484        ones are left. */
485    void        ObjectMerger();
486 
487    //-------------------------------------
488    // Text outputting of detected objects.
489    //   in Cubes/detectionIO.cc
490    //
491    /** Set up the output file with parameters and stats. */
492    void        prepareOutputFile();
493
494    /** Write the statistical information to the output file. */
495    void        outputStats();
496
497    /** Output detections to the output file and standard output. */
498    void        outputDetectionList();
499
500    /** Prepare the log file for output. */
501    void        prepareLogFile(int argc, char *argv[]);
502
503    /** Output detections to the log file. */
504    void        logDetectionList();
505
506    /** Output a single detection to the log file. */
507    void        logDetection(Detection obj, int counter);
508
509    /** Output detections to a Karma annotation file. */
510    void        outputDetectionsKarma(std::ostream &stream);
511
512    /** Output detections to a VOTable. */
513    void        outputDetectionsVOTable(std::ostream &stream);
514
515    // ----------------------------------
516    // Graphical plotting of the cube and the detections.
517    //
518    //  in Cubes/plotting.cc
519    /** Plot a spatial map of detections based on number of detected
520        channels. */
521    void        plotDetectionMap(std::string pgDestination);
522
523    /** Plot a spatial map of detections based on 0th moment map of each
524        object. */
525    void        plotMomentMap(std::string pgDestination);
526
527    /** Plot a spatial map of detections based on 0th moment map of each
528        object to a number of PGPLOT devices. */
529    void        plotMomentMap(std::vector<std::string> pgDestination);
530
531    /** Draw WCS axes over a PGPLOT map. */
532    void        plotWCSaxes();
533
534    //  in Cubes/outputSpectra.cc
535    /** Print spectra of each detected object. */
536    void        outputSpectra();
537
538    /** Write out text file of all spectra. */
539    void        writeSpectralData();
540
541    /** Print spectrum of a single object */
542    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
543    /** Plot the image cutout for a single object */
544    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
545
546    /** Get the spectral arrays */
547    void        getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase);
548
549    //  in Cubes/drawMomentCutout.cc
550    /** Draw the 0th moment map for a single object. */
551    void        drawMomentCutout(Detection &object);
552
553    /** Draw a scale bar indicating angular size of the cutout. */
554    void        drawScale(float xstart,float ystart,float channel);
555
556    /** Draw a yellow line around the edge of the spatial extent of
557        pixels. */
558    void        drawFieldEdge();
559
560  private:
561    float      *recon;            ///< reconstructed array - used when
562    ///   doing a trous reconstruction.
563    bool        reconExists;      ///< flag saying whether there is a
564    ///   reconstruction
565    short      *detectMap;        ///< "moment map" - x,y locations of
566    ///   detected pixels
567    float      *baseline;         ///< array of spectral baseline
568    ///   values.
569                             
570    bool        reconAllocated;   ///< have we allocated memory for the
571    ///   recon array?
572    bool        baselineAllocated;///< have we allocated memory for the
573    ///   baseline array?
574    FitsHeader  head;             ///< the WCS and other header
575    ///   information.
576    std::vector<Column::Col> fullCols;    ///< the list of all columns as
577    ///   printed in the results file
578    std::vector<Column::Col> logCols;     ///< the list of columns as printed in
579    ///   the log file
580
581  };
582
583  ////////////
584  //// Cube inline function definitions
585  ////////////
586
587  inline int Cube::wcsToPix(const double *world, double *pix)
588  {
589    /**
590     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
591     *   a single point.
592     *  \param world The world coordinates.
593     *  \param pix The returned pixel coordinates.
594     */
595    return this->head.wcsToPix(world,pix);
596  }
597  inline int Cube::wcsToPix(const double *world, double *pix, const int npts)
598  {
599    /**
600     *  Use the WCS in the FitsHeader to convert from WCS to pixel coords for
601     *   a set of points.
602     *  \param world The world coordinates.
603     *  \param pix The returned pixel coordinates.
604     *  \param npts The number of points being converted.
605     */
606    return this->head.wcsToPix(world,pix,npts);
607  }
608  inline int Cube::pixToWCS(const double *pix, double *world)
609  {
610    /**
611     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
612     *   a single point.
613     *  \param pix The pixel coordinates.
614     *  \param world The returned world coordinates.
615     */
616    return this->head.pixToWCS(pix,world);
617  }
618  inline int Cube::pixToWCS(const double *pix, double *world, const int npts)
619  {
620    /**
621     *  Use the WCS in the FitsHeader to convert from pixel to WCS coords for
622     *   a set of points.
623     *  \param pix The pixel coordinates.
624     *  \param world The returned world coordinates.
625     *  \param npts The number of points being converted.
626     */
627    return this->head.pixToWCS(pix,world,npts);
628  }
629
630
631  //============================================================================
632
633  /**
634   *  A DataArray object limited to two dimensions, and with some additional
635   *   special functions.
636   *
637   *  It is used primarily for searching a 1- or 2-D array with
638   *   lutz_detect() and spectrumDetect().
639   */
640
641  class Image : public DataArray
642  {
643  public:
644    Image(){numPixels=0; numDim=2;};
645    Image(long nPix);
646    Image(long *dimensions);
647    virtual ~Image(){};
648
649    //--------------------
650    // Defining the array
651    //
652    /** Save an external array to the Cube's pixel array */
653    void      saveArray(float *input, long size);
654
655    /** Extract a spectrum from an array and save to the local pixel array. */
656    void      extractSpectrum(float *Array, long *dim, long pixel);
657
658    /** Extract an image from an array and save to the local pixel array. */
659    void      extractImage(float *Array, long *dim, long channel);
660
661    /** Extract a spectrum from a cube and save to the local pixel array. */
662    void      extractSpectrum(Cube &cube, long pixel);
663
664    /** Extract an image from a cube and save to the local pixel array. */
665    void      extractImage(Cube &cube, long channel);
666
667    //--------------------
668    // Accessing the data.
669    //
670    float     getPixValue(long pos){ return array[pos]; };
671    float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
672    // the next few should have checks against array overflow...
673    void      setPixValue(long pos, float f){array[pos] = f;};
674    void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
675    bool      isBlank(int vox){return par.isBlank(array[vox]);};
676    bool      isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);};
677
678    //-----------------------
679    // Detection-related
680    //
681    // in Detection/lutz_detect.cc:
682    /** Detect objects in a 2-D image */
683    std::vector<PixelInfo::Object2D> lutz_detect();
684
685    // in Detection/spectrumDetect.cc:
686    /** Detect objects in a 1-D spectrum */
687    std::vector<PixelInfo::Scan> spectrumDetect();
688
689    int       getMinSize(){return minSize;};
690    void      setMinSize(int i){minSize=i;};
691
692    /**  A detection test for a pixel location.  */
693    bool      isDetection(long x, long y){
694      /**
695       * Test whether a pixel (x,y) is a statistically significant detection,
696       * according to the set of statistics in the local StatsContainer object.
697       */
698      long voxel = y*axisDim[0] + x;
699      if(isBlank(x,y)) return false;
700      else return Stats.isDetection(array[voxel]);
701    }; 
702
703    /** Blank out a set of channels marked as being Milky Way channels */
704    void      removeMW();
705
706  private:
707    int       minSize;    ///< the minimum number of pixels for a
708    ///   detection to be accepted.
709  };
710
711
712  /****************************************************************/
713  //////////////////////////////////////////////////////
714  // Prototypes for functions that use above classes
715  //////////////////////////////////////////////////////
716
717  /** Grow an object to a lower threshold */
718  void growObject(Detection &object, Cube &cube);
719
720  /** Draw the edge of the BLANK region on a map.*/
721  void drawBlankEdges(float *dataArray, int xdim, int ydim, Param &par);
722
723}
724
725#endif
Note: See TracBrowser for help on using the repository browser.