source: ATrous/search_velocity.cc @ 3

Last change on this file since 3 was 2, checked in by Matthew Whiting, 18 years ago

Initial commit of ATrous

File size: 3.0 KB
Line 
1#include <fstream>
2#include <iostream>
3#include <iomanip>
4//#include <Cubes/cubes.hh>
5using namespace std;
6
7//void searchVelocity(Cube &cube, Detection *objectList, int &numObjects)
8DetectionList *searchVelocity(Cube &cube, Param &par)
9{
10  DetectionList *objectList = new DetectionList;
11  int xdim=cube.getDimX(),ydim=cube.getDimY(),zdim = cube.getDimZ();
12  long *dim = new long[2];
13  dim[0] = zdim;
14  dim[1] = 1;
15
16  ofstream fout(par.getLogFile().c_str(),ios::app);
17  outputDetectionTextHeader(fout);
18//   outputDetectionTextHeader(cerr);
19  for(int npixel=0;npixel<xdim*ydim;npixel++){
20    //    at each spatial pixel in the cube, search in the spectrum
21
22    if((100*npixel/(xdim*ydim))%5==0)
23      cout<<setw(3)<<100*npixel/(xdim*ydim)<<"% done"<<"\b\b\b\b\b\b\b\b\b"<<flush;
24
25    Image *spectrum = new Image(dim);
26    float *array = new float[zdim];
27    for(long zpos=0;zpos<zdim;zpos++){
28      int cubepos = npixel + zpos*xdim*ydim;
29      array[zpos] = cube.getPixValue(cubepos);
30    }
31    spectrum->saveArray(array,zdim);
32
33    /* This was the old way of doing it */
34    //findSources(*spectrum,par);
35
36    /* This is the new way using the atrous reconstruction */
37    for(int i=0;i<zdim;i++) spectrum->setMaskValue(i,0);
38    findSourcesAtrous1D(*spectrum,par);
39    for(long zpos=0;zpos<zdim;zpos++) {
40      int mask = spectrum->getMaskValue(zpos);
41      if(mask>1) cerr << "**** "<<npixel<<" "<<zpos<<" "<<mask<<endl;
42    }
43   
44    Image *newSpectrum = new Image(dim);
45    newSpectrum->saveArray(array,zdim);
46    // set the proper positional parameters for each object
47    for(int objCtr=0;objCtr<spectrum->getNumObj();objCtr++){
48      Detection *obj = new Detection;
49      *obj = spectrum->getObject(objCtr);
50
51      for(int pixCtr=0;pixCtr<obj->getSize();pixCtr++){
52        int zpos = obj->getX(pixCtr);
53        int xpos = npixel%xdim;
54        int ypos = npixel/xdim;
55        obj->setZ(pixCtr,zpos);
56        obj->setY(pixCtr,ypos);
57        obj->setX(pixCtr,xpos);
58      }
59      obj->calcParams();
60      newSpectrum->addObject(*obj);
61      delete obj;
62    }
63    for(long zpos=0;zpos<zdim;zpos++) {
64      int mask = spectrum->getMaskValue(zpos);
65      if(mask>1) cerr << "**** "<<zpos<<" "<<mask<<endl;
66      newSpectrum->setMaskValue(zpos, mask );
67    }
68    delete spectrum;
69    spectrum = newSpectrum;
70    delete [] array;
71 
72    for(int objCtr=0;objCtr<spectrum->getNumObj();objCtr++){
73      Detection *obj = new Detection;
74      *obj = spectrum->getObject(objCtr);
75      outputDetectionText(fout,*obj,objectList->getSize()+1+objCtr);
76//       outputDetectionText(cerr,*obj,objectList->getSize()+1+objCtr);
77      delete obj;
78    }
79
80    short detect = cube.getDetectMapValue(npixel);
81    for(int i=0;i<zdim;i++){
82      short mask = spectrum->getMaskValue(i);
83      detect += mask;
84    }
85    cube.setDetectMapValue(npixel, detect);
86
87    // add the newly found objects to the list
88    for(int i=0;i<spectrum->getNumObj();i++)
89      objectList->addObject(spectrum->getObject(i));
90
91    delete spectrum;
92 
93  }
94  delete [] dim;
95  fout<<endl<<endl;
96  fout.close();
97
98  return objectList;
99
100}
Note: See TracBrowser for help on using the repository browser.