[300] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // areClose.cc: Determine whether two Detections are close enough to |
---|
| 3 | // be merged. |
---|
| 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 | // ----------------------------------------------------------------------- |
---|
[3] | 29 | #include <math.h> |
---|
[393] | 30 | #include <duchamp/Detection/detection.hh> |
---|
| 31 | #include <duchamp/PixelMap/Scan.hh> |
---|
| 32 | #include <duchamp/PixelMap/Object3D.hh> |
---|
| 33 | #include <duchamp/param.hh> |
---|
[3] | 34 | |
---|
[258] | 35 | using namespace PixelInfo; |
---|
| 36 | |
---|
[378] | 37 | namespace duchamp |
---|
[3] | 38 | { |
---|
[774] | 39 | /* |
---|
[378] | 40 | bool areAdj(Object2D &obj1, Object2D &obj2); |
---|
| 41 | bool areClose(Object2D &obj1, Object2D &obj2, float threshold); |
---|
[221] | 42 | |
---|
[378] | 43 | bool areClose(Object2D &obj1, Object2D &obj2, float threshold) |
---|
| 44 | { |
---|
| 45 | bool close = false; |
---|
[258] | 46 | |
---|
[378] | 47 | long nscan1 = obj1.getNumScan(); |
---|
| 48 | long nscan2 = obj2.getNumScan(); |
---|
[258] | 49 | |
---|
[378] | 50 | Scan temp1(0, obj1.getYmin()-int(threshold), |
---|
| 51 | obj1.getYmax()-obj1.getYmin()+1+2*int(threshold)); |
---|
| 52 | Scan temp2(0, obj2.getYmin(),obj2.getYmax()-obj2.getYmin()+1); |
---|
[505] | 53 | Scan Yoverlap = intersect(temp1,temp2); |
---|
| 54 | |
---|
[744] | 55 | // Yoverlap has the scans that overlap with a padding of width threshold |
---|
[505] | 56 | // If two pixels are separated in Y by threshold, but have the same X, then they match. |
---|
| 57 | // This is the furthest apart they can be in Y. |
---|
[258] | 58 | |
---|
[505] | 59 | if(Yoverlap.getXlen()>0){ |
---|
| 60 | // Grow by a pixel in each direction, to take into account the possibility of fractional thresholds (eg. 7.5) |
---|
| 61 | Yoverlap.growLeft(); |
---|
| 62 | Yoverlap.growRight(); |
---|
| 63 | |
---|
| 64 | // Now look at just these scans pixel by pixel |
---|
[258] | 65 | |
---|
[505] | 66 | // Get the scans from object 2 that lie in the overlap region (these haven't been affected by the threshold gap) |
---|
| 67 | for(int scanct2=0; (!close && (scanct2<nscan2)); scanct2++){ |
---|
| 68 | temp2 = obj2.getScan(scanct2); |
---|
| 69 | if(Yoverlap.isInScan(temp2.getY(),0)){ // if the scan is in the allowed Y range |
---|
[258] | 70 | |
---|
[505] | 71 | for(int scanct1=0; (!close && (scanct1<nscan1)); scanct1++){ |
---|
| 72 | temp1 = obj1.getScan(scanct1); |
---|
[744] | 73 | if(abs(temp1.getY()-temp2.getY())<threshold){ |
---|
[258] | 74 | |
---|
[505] | 75 | close = (minSep(temp1,temp2) < threshold); |
---|
[258] | 76 | |
---|
[505] | 77 | } |
---|
[258] | 78 | |
---|
[505] | 79 | } |
---|
[258] | 80 | |
---|
[505] | 81 | } |
---|
[258] | 82 | |
---|
[505] | 83 | } |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | return close; |
---|
[258] | 87 | |
---|
[378] | 88 | } |
---|
[258] | 89 | |
---|
[505] | 90 | |
---|
[378] | 91 | bool areAdj(Object2D &obj1, Object2D &obj2) |
---|
| 92 | { |
---|
| 93 | bool close = false; |
---|
[258] | 94 | |
---|
[378] | 95 | long nscan1 = obj1.getNumScan(); |
---|
| 96 | long nscan2 = obj2.getNumScan(); |
---|
[258] | 97 | |
---|
[378] | 98 | Scan temp1(0, obj1.getYmin()-1,obj1.getYmax()-obj1.getYmin()+3); |
---|
| 99 | Scan temp2(0, obj2.getYmin(),obj2.getYmax()-obj2.getYmin()+1); |
---|
| 100 | Scan temp3; |
---|
| 101 | Scan commonY = intersect(temp1,temp2); |
---|
| 102 | if(commonY.getXlen()>0){ |
---|
| 103 | commonY.growLeft(); |
---|
| 104 | commonY.growRight(); |
---|
| 105 | // std::cerr << temp1 << " " << temp2 << " " << commonY << "\n"; |
---|
[258] | 106 | |
---|
[378] | 107 | for(int scanct1=0;(!close && scanct1 < nscan1);scanct1++){ |
---|
| 108 | temp1 = obj1.getScan(scanct1); |
---|
| 109 | if(commonY.isInScan(temp1.getY(),0)){ |
---|
| 110 | long y1 = temp1.getY(); |
---|
[258] | 111 | |
---|
[378] | 112 | for(int scanct2=0; (!close && scanct2 < nscan2); scanct2++){ |
---|
| 113 | temp2 = obj2.getScan(scanct2); |
---|
| 114 | if(commonY.isInScan(temp2.getY(),0)){ |
---|
| 115 | long dy = abs(y1 - temp2.getY()); |
---|
[258] | 116 | |
---|
[378] | 117 | if(dy<= 1){ |
---|
[258] | 118 | |
---|
[378] | 119 | temp3.define(temp2.getY(),temp1.getX(),temp1.getXlen()); |
---|
| 120 | if(touching(temp3,temp2)) close = true; |
---|
[258] | 121 | |
---|
[378] | 122 | } |
---|
[258] | 123 | } |
---|
[378] | 124 | } // end of for loop over scanct2 |
---|
[258] | 125 | |
---|
[378] | 126 | } |
---|
[258] | 127 | |
---|
[378] | 128 | } // end of for loop over scanct1 |
---|
[258] | 129 | |
---|
[378] | 130 | } |
---|
| 131 | return close; |
---|
[258] | 132 | } |
---|
[774] | 133 | */ |
---|
[258] | 134 | } |
---|