1 | #include <iostream> |
---|
2 | #include <cpgplot.h> |
---|
3 | #include <math.h> |
---|
4 | #include <wcs.h> |
---|
5 | #include <Cubes/cubes.hh> |
---|
6 | #include <Utils/utils.hh> |
---|
7 | |
---|
8 | void drawMomentCutout(Cube &cube, Detection &object) |
---|
9 | { |
---|
10 | float x1,x2,y1,y2; |
---|
11 | cpgqwin(&x1,&x2,&y1,&y2); |
---|
12 | |
---|
13 | long size = (object.getXmax()-object.getXmin()+1); |
---|
14 | if(size<(object.getYmax()-object.getYmin()+1)) |
---|
15 | size = object.getYmax()-object.getYmin()+1; |
---|
16 | size += 20; |
---|
17 | |
---|
18 | float blankVal = cube.pars().getBlankPixVal(); |
---|
19 | |
---|
20 | long xmin = (object.getXmax()+object.getXmin())/2 - size/2 + 1; |
---|
21 | long xmax = (object.getXmax()+object.getXmin())/2 + size/2; |
---|
22 | long ymin = (object.getYmax()+object.getYmin())/2 - size/2 + 1; |
---|
23 | long ymax = (object.getYmax()+object.getYmin())/2 + size/2; |
---|
24 | long zmin = object.getZmin(); |
---|
25 | long zmax = object.getZmax(); |
---|
26 | |
---|
27 | float *image = new float[size*size]; |
---|
28 | for(int i=0;i<size*size;i++) image[i]=blankVal; |
---|
29 | long *dim = new long[3]; |
---|
30 | cube.getDimArray(dim); |
---|
31 | |
---|
32 | int imPos,cubePos; |
---|
33 | float val; |
---|
34 | for(int z=zmin; z<=zmax; z++){ |
---|
35 | for(int x=xmin; x<=xmax; x++){ |
---|
36 | for(int y=ymin; y<=ymax; y++){ |
---|
37 | imPos = (y-ymin) * size + (x-xmin); |
---|
38 | cubePos = (z)*dim[0]*dim[1]+(y)*dim[0]+(x); |
---|
39 | if((x<0)||(x>=dim[0])||(y<0)||(y>=dim[1])) // if outside the boundaries |
---|
40 | image[imPos] = blankVal; |
---|
41 | else{ |
---|
42 | val = cube.getPixValue(cubePos); |
---|
43 | if (!cube.pars().isBlank(val)) // if pixel's not blank |
---|
44 | image[imPos] += val; |
---|
45 | } |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | for(int i=0;i<size*size;i++){ |
---|
51 | if(image[i]!=blankVal){ // if there is some signal on this pixel |
---|
52 | image[i]-=blankVal; // remove the starting value so we just have the signal |
---|
53 | image[i] /= float(zmax-zmin+1); // normalise by the velocity width |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | // now work out the greyscale display limits, excluding blank pixels where necessary. |
---|
58 | float z1,z2,median,madfm; |
---|
59 | int ct=0; |
---|
60 | while(image[ct]==cube.pars().getBlankPixVal()) ct++; |
---|
61 | z1 = z2 = image[ct]; |
---|
62 | for(int i=1;i<size*size;i++){ |
---|
63 | if(// (!cube.pars().getFlagBlankPix())|| |
---|
64 | (image[i]!=blankVal)){ |
---|
65 | if(image[i]<z1) z1=image[i]; |
---|
66 | if(image[i]>z2) z2=image[i]; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | float tr[6] = {xmin-1,1.,0.,ymin-1,0.,1.}; |
---|
71 | |
---|
72 | cpgswin(xmin-0.5,xmax-0.5,ymin-0.5,ymax-0.5); |
---|
73 | cpggray(image, size, size, 1, size, 1, size, z1, z2, tr); |
---|
74 | |
---|
75 | delete [] image; |
---|
76 | delete [] dim; |
---|
77 | |
---|
78 | // Draw the borders around the object |
---|
79 | int ci; |
---|
80 | cpgqci(&ci); |
---|
81 | cpgsci(4); |
---|
82 | cpgsfs(2); |
---|
83 | if(cube.pars().drawBorders()) |
---|
84 | object.drawBorders(xmin,ymin); |
---|
85 | else |
---|
86 | cpgrect(object.getXmin()-xmin+0.5,object.getXmax()-xmin+1.5, |
---|
87 | object.getYmin()-ymin+0.5,object.getYmax()-ymin+1.5); |
---|
88 | /* |
---|
89 | To get the borders localised correctly, we need to subtract (xmin-1) from the |
---|
90 | X values. We then subtract 0.5 for the left hand border (to place it on the |
---|
91 | pixel border), and add 0.5 for the right hand border. Similarly for y. |
---|
92 | */ |
---|
93 | cpgsci(ci); |
---|
94 | |
---|
95 | // Now draw a tick mark to indicate size -- 30 arcmin in length |
---|
96 | wcsprm *wcs = new wcsprm; |
---|
97 | wcs = cube.getWCS(); |
---|
98 | |
---|
99 | double *pix = new double[3]; |
---|
100 | double *world = new double[3]; |
---|
101 | pix[0] = double(xmin) + double(object.getXOffset()) + 2.; |
---|
102 | pix[1] = double(ymin) + double(object.getYOffset()) + 2.; |
---|
103 | pix[2] = object.getZcentre(); |
---|
104 | pixToWCSSingle(wcs,pix,world); |
---|
105 | world[0] -= 0.25; |
---|
106 | wcsToPixSingle(wcs,world,pix); |
---|
107 | wcsfree(wcs); |
---|
108 | |
---|
109 | float tickpt1 = xmin + 2.; |
---|
110 | float tickpt2 = pix[0] - object.getXOffset(); |
---|
111 | float tickpt3 = ymin + 2.; |
---|
112 | cpgsci(2); |
---|
113 | int thick; |
---|
114 | cpgqlw(&thick); |
---|
115 | cpgslw(3); |
---|
116 | cpgerrx(1,&tickpt1,&tickpt2,&tickpt3,2.); |
---|
117 | // cpgtext(0.5*(tickpt1+tickpt2)-1,tickpt3+2.,"30\'"); |
---|
118 | cpgslw(thick); |
---|
119 | cpgsci(1); |
---|
120 | |
---|
121 | delete [] pix; |
---|
122 | delete [] world; |
---|
123 | |
---|
124 | cpgsci(1); |
---|
125 | cpgswin(x1,x2,y1,y2); |
---|
126 | |
---|
127 | } |
---|
128 | |
---|
129 | // void Detection::drawBorders(Detection &object, int xoffset, int yoffset) |
---|
130 | void Detection::drawBorders(int xoffset, int yoffset) |
---|
131 | { |
---|
132 | |
---|
133 | float x1,x2,y1,y2; |
---|
134 | cpgqwin(&x1,&x2,&y1,&y2); |
---|
135 | int xsize = int(x2 - x1) + 1; |
---|
136 | int ysize = int(y2 - y1) + 1; |
---|
137 | |
---|
138 | bool *isObj = new bool[xsize*ysize]; |
---|
139 | for(int i=0;i<xsize*ysize;i++) isObj[i]=false; |
---|
140 | for(int i=0;i<this->pix.size();i++) |
---|
141 | isObj[ (this->pix[i].getY()-yoffset)*xsize + (this->pix[i].getX()-xoffset) ] = true; |
---|
142 | |
---|
143 | |
---|
144 | cpgswin(0,xsize-1,0,ysize-1); |
---|
145 | for(int x=this->xmin; x<=this->xmax; x++){ |
---|
146 | // for each column... |
---|
147 | for(int y=1;y<ysize;y++){ |
---|
148 | int current = y*xsize + (x-xoffset); |
---|
149 | int previous = (y-1)*xsize + (x-xoffset); |
---|
150 | if((isObj[current]&&!isObj[previous])||(!isObj[current]&&isObj[previous])){ |
---|
151 | cpgmove(x-xoffset+0, y+0); |
---|
152 | cpgdraw(x-xoffset+1, y+0); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | for(int y=this->ymin; y<=this->ymax; y++){ |
---|
157 | // now for each row... |
---|
158 | for(int x=1;x<xsize;x++){ |
---|
159 | int current = (y-yoffset)*xsize + x; |
---|
160 | int previous = (y-yoffset)*xsize + x - 1; |
---|
161 | if((isObj[current]&&!isObj[previous])||(!isObj[current]&&isObj[previous])){ |
---|
162 | cpgmove(x+0, y-yoffset+0); |
---|
163 | cpgdraw(x+0, y-yoffset+1); |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | cpgswin(x1,x2,y1,y2); |
---|
168 | |
---|
169 | delete [] isObj; |
---|
170 | |
---|
171 | } |
---|