[3] | 1 | #include <fstream> |
---|
| 2 | #include <iostream> |
---|
| 3 | #include <iomanip> |
---|
| 4 | //#include <Cubes/cubes.hh> |
---|
| 5 | #include <Utils/utils.hh> |
---|
| 6 | |
---|
| 7 | using namespace std; |
---|
| 8 | |
---|
| 9 | DetectionList *searchSpatially(Cube &cube, Param &par) |
---|
| 10 | { |
---|
| 11 | DetectionList *objectList = new DetectionList; |
---|
| 12 | long xdim = cube.getDimX(); |
---|
| 13 | long ydim = cube.getDimY(); |
---|
| 14 | long zdim = cube.getDimZ(); |
---|
| 15 | long *dim = new long[2]; |
---|
| 16 | dim[0] = xdim; |
---|
| 17 | dim[1] = ydim; |
---|
| 18 | bool flagMW = par.getFlagMW(); |
---|
| 19 | int minMW=zdim,maxMW=zdim; |
---|
| 20 | if(flagMW){ |
---|
| 21 | minMW = par.getMinMW(); |
---|
| 22 | maxMW = par.getMaxMW(); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | ofstream fout(par.getLogFile().c_str(),ios::app); |
---|
| 26 | outputDetectionTextHeader(fout); |
---|
| 27 | // outputDetectionTextHeader(cerr); |
---|
| 28 | |
---|
| 29 | for(long numChannel=0;numChannel<zdim;numChannel++){ |
---|
| 30 | // at each frequency channel, search the image... |
---|
| 31 | |
---|
| 32 | if((100*numChannel/zdim)%5==0) cout<<setw(3)<<100*numChannel/zdim<<"% done"<<"\b\b\b\b\b\b\b\b\b"<<flush; |
---|
| 33 | |
---|
| 34 | if((!flagMW)||(numChannel<minMW)||(numChannel>maxMW)){ |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | Image *slice = new Image(dim); |
---|
| 38 | // for(long j=0;j<slice->getSize();j++){ |
---|
| 39 | float *array = new float[xdim*ydim]; |
---|
| 40 | for(int pos=0; pos<xdim*ydim; pos++){ |
---|
| 41 | long cubepos = pos + numChannel*xdim*ydim; |
---|
| 42 | array[pos] = cube.getPixValue(cubepos); |
---|
| 43 | } |
---|
| 44 | slice->saveArray(array,xdim*ydim); |
---|
| 45 | |
---|
| 46 | /* This was the old way of doing it */ |
---|
| 47 | //findSources(*slice,par); |
---|
| 48 | |
---|
| 49 | /* This is the new way using the atrous reconstruction */ |
---|
| 50 | findSourcesAtrous2D(*slice,par); |
---|
| 51 | |
---|
| 52 | Image *newslice = new Image(dim); |
---|
| 53 | newslice->saveArray(array,xdim*ydim); |
---|
| 54 | for(int i=0;i<slice->getNumObj();i++){ |
---|
| 55 | Detection *thisobj = new Detection; |
---|
| 56 | *thisobj = slice->getObject(i); |
---|
| 57 | for(int j=0;j<slice->getObject(i).getSize();j++){ |
---|
| 58 | // slice->getObject(i).setZ(j,numChannel); |
---|
| 59 | thisobj->setZ(j,numChannel); |
---|
| 60 | } |
---|
| 61 | thisobj->calcParams(); |
---|
| 62 | newslice->addObject(*thisobj); |
---|
| 63 | delete thisobj; |
---|
| 64 | } |
---|
| 65 | for(int pos=0; pos<xdim*ydim; pos++){ |
---|
| 66 | short int mask = slice->getMaskValue(pos); |
---|
| 67 | newslice->setMaskValue(pos,mask); |
---|
| 68 | } |
---|
| 69 | delete slice; |
---|
| 70 | slice = newslice; |
---|
| 71 | delete [] array; |
---|
| 72 | |
---|
| 73 | for(int i=0;i<slice->getNumObj();i++) { |
---|
| 74 | Detection *thisobj = new Detection; |
---|
| 75 | *thisobj = slice->getObject(i); |
---|
| 76 | outputDetectionText(fout,*thisobj,objectList->getSize()+1+i); |
---|
| 77 | // outputDetectionText(cerr,*thisobj,objectList->getSize()+1+i); |
---|
| 78 | delete thisobj; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | for(int i=0;i<slice->getSize();i++){ |
---|
| 82 | short detect = cube.getDetectMapValue(i); |
---|
| 83 | detect += slice->getMaskValue(i); |
---|
| 84 | cube.setDetectMapValue(i, detect); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | // add the newly found objects to the list |
---|
| 88 | for(int i=0;i<slice->getNumObj();i++) |
---|
| 89 | objectList->addObject(slice->getObject(i)); |
---|
| 90 | |
---|
| 91 | delete slice; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | fout<<endl<<endl; |
---|
| 96 | fout.close(); |
---|
| 97 | |
---|
| 98 | return objectList; |
---|
| 99 | |
---|
| 100 | } |
---|