source: trunk/src/Detection/ObjectGrower.cc @ 759

Last change on this file since 759 was 759, checked in by MatthewWhiting, 14 years ago

Non-functional change - only doxygen comments.

File size: 5.0 KB
Line 
1#include <iostream>
2#include <duchamp/duchamp.hh>
3#include <Detection/ObjectGrower.hh>
4#include <Detection/detection.hh>
5#include <Cubes/cubes.hh>
6#include <duchamp/Utils/Statistics.hh>
7#include <duchamp/PixelMap/Voxel.hh>
8
9
10namespace duchamp {
11
12  ObjectGrower::ObjectGrower() {
13  }
14
15  ObjectGrower::ObjectGrower(ObjectGrower &o)
16  {
17    this->operator=(o);
18  }
19
20  ObjectGrower& ObjectGrower::operator=(const ObjectGrower &o)
21  {
22    if(this == &o) return *this;
23    this->itsFlagArray = o.itsFlagArray;
24    this->itsArrayDim = o.itsArrayDim;
25    this->itsGrowthStats = o.itsGrowthStats;
26    this->itsSpatialThresh = o.itsSpatialThresh;
27    this->itsVelocityThresh = o.itsVelocityThresh;
28    this->itsFluxArray = o.itsFluxArray;
29    return *this;
30  }
31
32  void ObjectGrower::define( Cube *theCube )
33  {
34    /// @details This copies all necessary information from the Cube
35    /// and its parameters & statistics. It also defines the array of
36    /// pixel flags, which involves looking at each object to assign
37    /// them as detected, all blank & "milky-way" pixels to assign
38    /// them appropriately, and all others to "available". It is only
39    /// the latter that will be considered in the growing function.
40    /// @param theCube A pointer to a duchamp::Cube
41
42    this->itsGrowthStats = Statistics::StatsContainer<float>(theCube->stats());
43    if(theCube->pars().getFlagUserGrowthThreshold())
44      this->itsGrowthStats.setThreshold(theCube->pars().getGrowthThreshold());
45    else
46      this->itsGrowthStats.setThresholdSNR(theCube->pars().getGrowthCut());   
47    this->itsGrowthStats.setUseFDR(false);
48
49    if(theCube->isRecon()) this->itsFluxArray = theCube->getRecon();
50    else this->itsFluxArray = theCube->getArray();
51
52    this->itsArrayDim = std::vector<long>(3);
53    this->itsArrayDim[0]=theCube->getDimX();
54    this->itsArrayDim[1]=theCube->getDimY();
55    this->itsArrayDim[2]=theCube->getDimZ();
56    size_t spatsize=this->itsArrayDim[0]*this->itsArrayDim[1];
57    size_t fullsize=spatsize*this->itsArrayDim[2];
58
59    if(theCube->pars().getFlagAdjacent())
60      this->itsSpatialThresh = 1;
61    else
62      this->itsSpatialThresh = int(theCube->pars().getThreshS());
63    this->itsVelocityThresh = int(theCube->pars().getThreshV());
64
65    this->itsFlagArray = std::vector<STATE>(fullsize,AVAILABLE);
66
67    for(int o=0;o<theCube->getNumObj();o++){
68      std::vector<Voxel> voxlist = theCube->getObject(o).getPixelSet();
69      for(size_t i=0; i<voxlist.size(); i++){
70        long pos = voxlist[i].getX() + voxlist[i].getY()*this->itsArrayDim[0] + voxlist[i].getZ()*spatsize;
71        this->itsFlagArray[pos] = DETECTED;
72      }
73    }
74
75    if(theCube->pars().getFlagMW()){
76      long minz=theCube->pars().getMinMW();
77      long maxz=theCube->pars().getMaxMW();
78      for(size_t i=minz*spatsize;i<maxz*spatsize;i++) this->itsFlagArray[i]=MW;
79    }
80
81    for(size_t i=0;i<fullsize;i++)
82      if(theCube->isBlank(i)) this->itsFlagArray[i]=BLANK;
83
84  }
85
86  void ObjectGrower::grow(Detection *theObject)
87  {
88    /// @details This function grows the provided object out to the
89    /// secondary threshold provided in itsGrowthStats. For each pixel
90    /// in an object, all surrounding pixels are considered and, if
91    /// their flag is AVAILABLE, their flux is examined. If it's above
92    /// the threshold, that pixel is added to the list to be looked at
93    /// and their flag is changed to DETECTED.
94    /// @param theObject The duchamp::Detection object to be grown. It
95    /// is returned with new pixels in place. Only the basic
96    /// parameters that belong to PixelInfo::Object3D are
97    /// recalculated.
98
99    long spatsize=this->itsArrayDim[0]*this->itsArrayDim[1];
100    long zero = 0;
101    std::vector<Voxel> voxlist = theObject->getPixelSet();
102    int origSize = voxlist.size();
103    for(size_t i=0; i<voxlist.size(); i++){
104     
105      long xpt=voxlist[i].getX();
106      long ypt=voxlist[i].getY();
107      long zpt=voxlist[i].getZ();
108     
109      int xmin = std::max(xpt - this->itsSpatialThresh, zero);
110      int xmax = std::min(xpt + this->itsSpatialThresh, this->itsArrayDim[0]-1);
111      int ymin = std::max(ypt - this->itsSpatialThresh, zero);
112      int ymax = std::min(ypt + this->itsSpatialThresh, this->itsArrayDim[1]-1);
113      int zmin = std::max(zpt - this->itsVelocityThresh, zero);
114      int zmax = std::min(zpt + this->itsVelocityThresh, this->itsArrayDim[2]-1);
115     
116      //loop over surrounding pixels.
117      for(int x=xmin; x<=xmax; x++){
118        for(int y=ymin; y<=ymax; y++){
119          for(int z=zmin; z<=zmax; z++){
120
121            int pos=x+y*this->itsArrayDim[0]+z*spatsize;
122            if( ((x!=xpt) || (y!=ypt) || (z!=zpt))
123                && this->itsFlagArray[pos]==AVAILABLE ) {
124
125              if(this->itsGrowthStats.isDetection(this->itsFluxArray[pos])){
126                this->itsFlagArray[pos]=DETECTED;
127                voxlist.push_back(Voxel(x,y,z));
128              }
129            }
130
131          } //end of z loop
132        } // end of y loop
133      } // end of x loop
134
135    } // end of i loop (voxels)
136
137    // Add in new pixels to the Detection
138    for(size_t i=origSize; i<voxlist.size(); i++){
139      theObject->addPixel(voxlist[i]);
140    }
141   
142
143  }
144
145
146}
Note: See TracBrowser for help on using the repository browser.