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 | // ----------------------------------------------------------------------- |
---|
29 | #include <math.h> |
---|
30 | #include <duchamp/Detection/detection.hh> |
---|
31 | #include <duchamp/PixelMap/Scan.hh> |
---|
32 | #include <duchamp/PixelMap/Object3D.hh> |
---|
33 | #include <duchamp/param.hh> |
---|
34 | |
---|
35 | using namespace PixelInfo; |
---|
36 | |
---|
37 | namespace duchamp |
---|
38 | { |
---|
39 | /* |
---|
40 | bool areAdj(Object2D &obj1, Object2D &obj2); |
---|
41 | bool areClose(Object2D &obj1, Object2D &obj2, float threshold); |
---|
42 | |
---|
43 | bool areClose(Object2D &obj1, Object2D &obj2, float threshold) |
---|
44 | { |
---|
45 | bool close = false; |
---|
46 | |
---|
47 | long nscan1 = obj1.getNumScan(); |
---|
48 | long nscan2 = obj2.getNumScan(); |
---|
49 | |
---|
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); |
---|
53 | Scan Yoverlap = intersect(temp1,temp2); |
---|
54 | |
---|
55 | // Yoverlap has the scans that overlap with a padding of width threshold |
---|
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. |
---|
58 | |
---|
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 |
---|
65 | |
---|
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 |
---|
70 | |
---|
71 | for(int scanct1=0; (!close && (scanct1<nscan1)); scanct1++){ |
---|
72 | temp1 = obj1.getScan(scanct1); |
---|
73 | if(abs(temp1.getY()-temp2.getY())<threshold){ |
---|
74 | |
---|
75 | close = (minSep(temp1,temp2) < threshold); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | } |
---|
86 | return close; |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | bool areAdj(Object2D &obj1, Object2D &obj2) |
---|
92 | { |
---|
93 | bool close = false; |
---|
94 | |
---|
95 | long nscan1 = obj1.getNumScan(); |
---|
96 | long nscan2 = obj2.getNumScan(); |
---|
97 | |
---|
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"; |
---|
106 | |
---|
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(); |
---|
111 | |
---|
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()); |
---|
116 | |
---|
117 | if(dy<= 1){ |
---|
118 | |
---|
119 | temp3.define(temp2.getY(),temp1.getX(),temp1.getXlen()); |
---|
120 | if(touching(temp3,temp2)) close = true; |
---|
121 | |
---|
122 | } |
---|
123 | } |
---|
124 | } // end of for loop over scanct2 |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | } // end of for loop over scanct1 |
---|
129 | |
---|
130 | } |
---|
131 | return close; |
---|
132 | } |
---|
133 | */ |
---|
134 | } |
---|