source: tags/release-1.1.3/src/Detection/growObject.cc @ 1391

Last change on this file since 1391 was 393, checked in by MatthewWhiting, 17 years ago

Fixed up headers for trunk as well.

File size: 4.5 KB
Line 
1// -----------------------------------------------------------------------
2// growObject.cc: Grow a detected object down to a lower flux threshold.
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#include <iostream>
29#include <iomanip>
30#include <vector>
31#include <duchamp/Cubes/cubes.hh>
32#include <duchamp/Utils/utils.hh>
33#include <duchamp/Utils/Statistics.hh>
34#include <duchamp/PixelMap/Voxel.hh>
35#include <duchamp/Detection/detection.hh>
36
37using std::vector;
38using std::setw;
39
40using namespace PixelInfo;
41using namespace Statistics;
42
43namespace duchamp
44{
45
46  void growObject(Detection &object, Cube &cube)
47  {
48    /**
49     *    A function to grow an object (given by the Detection) by
50     *    including neighbouring voxels out to some lower threshold than
51     *    what was previously used in the detection. 
52     *
53     *    Each pixel has each of its neighbours examined, and if one of
54     *    them is not in the object but above the growth threshold, it
55     *    is added to the object.
56     *
57     *    \param object Object to be grown.
58     *    \param cube Necessary to see both the Param list, containing
59     *    the growth threshold, and the actual array of pixel fluxes.
60     */
61
62
63    vector <bool> isInObj(cube.getSize(),false);
64    bool flagAdj = cube.pars().getFlagAdjacent();
65    int threshS = int(cube.pars().getThreshS());
66    if(flagAdj) threshS = 1;
67    int threshV = int(cube.pars().getThreshV());
68
69    for(int i=0;i<object.getSize();i++) {
70      Voxel vox = object.getPixel(i);
71      long pos = vox.getX() + vox.getY()*cube.getDimX() +
72        vox.getZ()*cube.getDimX()*cube.getDimY();
73      isInObj[pos] = true;
74    }
75 
76    StatsContainer<float> growthStats = cube.getStats();
77
78    growthStats.setThresholdSNR(cube.pars().getGrowthCut());
79    growthStats.setUseFDR(false);
80 
81    for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object
82
83      for(int xnbr=-1*threshS; xnbr<=1*threshS; xnbr++){
84        for(int ynbr=-1*threshS; ynbr<=1*threshS; ynbr++){
85          for(int znbr=-1*threshV; znbr<=1*threshV; znbr++){
86
87            if((xnbr!=0)||(ynbr!=0)||(znbr!=0)){
88              // ignore when all=0 ie. the current object pixel
89
90              Voxel pixnew = object.getPixel(pix);
91              long newx = pixnew.getX() + xnbr;
92              long newy = pixnew.getY() + ynbr;
93              long newz = pixnew.getZ() + znbr;
94         
95              if((newx<cube.getDimX())&&(newx>=0)&&   // x in cube?
96                 (newy<cube.getDimY())&&(newy>=0)&&   // y in cube?
97                 (newz<cube.getDimZ())&&(newz>=0)&&   // z in cube?
98                 !cube.isBlank(newx,newy,newz)   &&   // pixel not BLANK?
99                 !cube.pars().isInMW(newz)       &&   // pixel not MW?
100                 (flagAdj || hypot(xnbr,ynbr))     ){ // pixel not too far?
101           
102                pixnew.setX(newx);
103                pixnew.setY(newy);
104                pixnew.setZ(newz);
105
106                float flux;
107                if(cube.isRecon()) flux = cube.getReconValue(newx,newy,newz);
108                else               flux = cube.getPixValue(newx,newy,newz);
109                pixnew.setF(flux);
110
111                long pos = newx + newy * cube.getDimX() +
112                  newz * cube.getDimX() * cube.getDimY();
113                if( (!isInObj[pos]) && growthStats.isDetection(flux) ){
114                  isInObj[pos] = true;
115                  object.addPixel(pixnew);
116                } // end of if
117
118              } // end of if clause regarding newx, newy, newz
119
120            } // end of if clause regarding xnbr, ynbr, znbr
121
122          } // end of znbr loop
123        } // end of ynbr loop
124      } // end of xnbr loop
125     
126    } // end of pix loop
127
128    object.calcFluxes(cube.getArray(), cube.getDimArray());
129
130    isInObj.clear();
131
132  }
133
134}
Note: See TracBrowser for help on using the repository browser.