source: branches/pixel-map-branch/src/Detection/growObject.cc @ 1213

Last change on this file since 1213 was 252, checked in by Matthew Whiting, 17 years ago
  • Have put all classes in the files in src/PixelMap/ into a PixelInfo? namespace.
  • Added "using namespace PixelInfo?" to all necessary files.
  • Removed "friend class Detection" from Voxel and Object3D classes -- not necessary and complicated now by them being in the namespace
  • Various minor changes, including fixing up commentary.
File size: 2.7 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <vector>
4#include <Cubes/cubes.hh>
5#include <Utils/utils.hh>
6#include <Utils/Statistics.hh>
7#include <PixelMap/Voxel.hh>
8#include <Detection/detection.hh>
9
10using std::vector;
11using std::setw;
12
13using namespace PixelInfo;
14
15void growObject(Detection &object, Cube &cube)
16{
17  /**
18   *    A function to grow an object (given by the Detection) by
19   *    including neighbouring voxels out to some lower threshold than
20   *    what was previously used in the detection. 
21   *
22   *    Each pixel has each of its neighbours examined, and if one of
23   *    them is not in the object but above the growth threshold, it
24   *    is added to the object.
25   *
26   *    \param object Object to be grown.
27   *    \param cube  Necessary to see both the Param list, containing the growth
28   *    threshold, and the actual array of pixel fluxes. 
29   */
30
31
32  vector <bool> isInObj(cube.getSize(),false);
33  float thresh1;
34  float thresh2;
35  long  chanpos;
36
37  for(int i=0;i<object.getSize();i++) {
38    Voxel vox = object.getPixel(i);
39    long pos = vox.getX() + vox.getY()*cube.getDimX() +
40      vox.getZ()*cube.getDimX()*cube.getDimY();
41    isInObj[pos] = true;
42  }
43 
44  StatsContainer<float> growthStats = cube.getStats();
45
46  growthStats.setThresholdSNR(cube.pars().getGrowthCut());
47  growthStats.setUseFDR(false);
48 
49  for(int pix=0; pix<object.getSize(); pix++){ // for each pixel in the object
50
51    for(int xnbr=-1; xnbr<=1; xnbr++){
52      for(int ynbr=-1; ynbr<=1; ynbr++){
53        for(int znbr=-1; znbr<=1; znbr++){
54
55          if((xnbr!=0)||(ynbr!=0)||(znbr!=0)){
56            // ignore when all=0 ie. the current object pixel
57
58            Voxel pixnew = object.getPixel(pix);
59            long newx = pixnew.getX() + xnbr;
60            long newy = pixnew.getY() + ynbr;
61            long newz = pixnew.getZ() + znbr;
62         
63            if((newx<cube.getDimX())&&(newx>=0)&&
64               (newy<cube.getDimY())&&(newy>=0)&&
65               (newz<cube.getDimZ())&&(newz>=0)){
66           
67              pixnew.setX(newx);
68              pixnew.setY(newy);
69              pixnew.setZ(newz);
70
71              float flux;
72              if(cube.isRecon()) flux = cube.getReconValue(newx,newy,newz);
73              else               flux = cube.getPixValue(newx,newy,newz);
74              pixnew.setF(flux);
75
76              long chanpos = newx + newy * cube.getDimX();
77              long pos = newx + newy * cube.getDimX() +
78                newz * cube.getDimX() * cube.getDimY();
79              if( (!isInObj[pos]) && growthStats.isDetection(flux) ){
80                isInObj[pos] = true;
81                object.addPixel(pixnew);
82              } // end of if
83
84            } // end of if clause regarding newx, newy, newz
85
86          } // end of if clause regarding xnbr, ynbr, znbr
87
88        } // end of znbr loop
89      } // end of ynbr loop
90    } // end of xnbr loop
91     
92  } // end of pix loop
93
94  object.calcFluxes(cube.getArray(), cube.getDimArray());
95
96  isInObj.clear();
97
98}
99
Note: See TracBrowser for help on using the repository browser.