[476] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // existingDetections.cc: Functions to read in previously-made |
---|
| 3 | // detections from an existing log file |
---|
| 4 | // ----------------------------------------------------------------------- |
---|
| 5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 6 | // |
---|
| 7 | // This program is free software; you can redistribute it and/or modify it |
---|
| 8 | // under the terms of the GNU General Public License as published by the |
---|
| 9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 10 | // option) any later version. |
---|
| 11 | // |
---|
| 12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 15 | // for more details. |
---|
| 16 | // |
---|
| 17 | // You should have received a copy of the GNU General Public License |
---|
| 18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 20 | // |
---|
| 21 | // Correspondence concerning Duchamp may be directed to: |
---|
| 22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 23 | // Postal address: Dr. Matthew Whiting |
---|
| 24 | // Australia Telescope National Facility, CSIRO |
---|
| 25 | // PO Box 76 |
---|
| 26 | // Epping NSW 1710 |
---|
| 27 | // AUSTRALIA |
---|
| 28 | // ----------------------------------------------------------------------- |
---|
| 29 | #include <iostream> |
---|
| 30 | #include <fstream> |
---|
| 31 | #include <sstream> |
---|
| 32 | #include <string> |
---|
| 33 | |
---|
| 34 | #include <duchamp/Cubes/cubes.hh> |
---|
| 35 | #include <duchamp/param.hh> |
---|
| 36 | #include <duchamp/PixelMap/Scan.hh> |
---|
| 37 | #include <duchamp/Detection/detection.hh> |
---|
| 38 | |
---|
| 39 | using namespace PixelInfo; |
---|
| 40 | |
---|
| 41 | namespace duchamp |
---|
| 42 | { |
---|
| 43 | |
---|
| 44 | int Cube::getExistingDetections() |
---|
| 45 | { |
---|
| 46 | |
---|
| 47 | std::ifstream logfile(this->par.getLogFile().c_str()); |
---|
| 48 | |
---|
| 49 | if(!logfile.is_open()){ |
---|
| 50 | std::stringstream errmsg; |
---|
| 51 | errmsg << "Unable to open log file " << this->par.getLogFile(); |
---|
| 52 | duchampError("getExistingDetections",errmsg.str()); |
---|
| 53 | return FAILURE; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | std::cout << "Reading from logfile : " << this->par.getLogFile() << "\n"; |
---|
| 57 | |
---|
| 58 | std::string temp,filename; |
---|
| 59 | std::stringstream ss; |
---|
| 60 | |
---|
| 61 | // first check filename, just to be sure |
---|
| 62 | while(getline(logfile,temp), temp.substr(0,11)!="Image to be"){} |
---|
| 63 | ss.str(temp); |
---|
| 64 | ss >> temp >> temp >> temp >> temp>> temp >> filename; |
---|
| 65 | if(filename != this->par.getFullImageFile()){ |
---|
| 66 | std::stringstream errmsg; |
---|
| 67 | errmsg << "The image file given the log file (" << filename |
---|
| 68 | <<") is different to that in the parameter file (" << this->par.getFullImageFile()<<")."; |
---|
| 69 | duchampError("getExistingDetections", errmsg.str()); |
---|
| 70 | return FAILURE; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | // read down until first Detection # line |
---|
| 74 | while(getline(logfile,temp), temp.substr(0,9)!="Threshold"){} |
---|
| 75 | float threshold,middle,spread; |
---|
| 76 | bool robust; |
---|
| 77 | logfile >> threshold >> middle >> spread >> robust; |
---|
| 78 | std::cout << "Detection threshold used was " << threshold << "\n"; |
---|
| 79 | this->Stats.setRobust(robust); |
---|
| 80 | this->Stats.setThreshold(threshold); |
---|
| 81 | this->Stats.setMiddle(middle); |
---|
| 82 | this->Stats.setSpread(spread); |
---|
| 83 | getline(logfile,temp); |
---|
| 84 | getline(logfile,temp); |
---|
| 85 | int x1,x2, ypix, zpix; |
---|
| 86 | while(!logfile.eof()){ |
---|
| 87 | Detection obj; |
---|
| 88 | while(getline(logfile,temp), temp.substr(0,3)!="---"){ |
---|
[541] | 89 | for(unsigned int i=0;i<temp.size();i++) |
---|
[476] | 90 | if(temp[i]=='-' || temp[i]==',') temp[i] = ' '; |
---|
| 91 | std::stringstream ss; |
---|
| 92 | ss.str(temp); |
---|
| 93 | ss >> x1 >> x2 >> ypix >> zpix; |
---|
| 94 | Scan scn(ypix,x1,x2-x1+1); |
---|
[549] | 95 | // obj.pixels().addScan(scn,zpix); |
---|
| 96 | obj.addScan(scn,zpix); |
---|
[476] | 97 | } |
---|
| 98 | obj.setOffsets(this->par); |
---|
| 99 | obj.calcParams(); |
---|
| 100 | if(obj.getSize()>0) this->addObject(obj); |
---|
| 101 | getline(logfile,temp); // reads next line -- should be Detection #... |
---|
| 102 | if(temp.substr(0,11)!="Detection #"){ |
---|
| 103 | // if it is, then read two lines to finish off the file. This should trigger the eof flag above. |
---|
| 104 | getline(logfile,temp); |
---|
| 105 | getline(logfile,temp); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | std::cout<<"Final object count = "<<this->objectList->size()<<std::endl; |
---|
| 110 | |
---|
| 111 | return SUCCESS; |
---|
| 112 | |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | } |
---|