00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <vector>
00021 #include <algorithm>
00022 #include <cmath>
00023
00024 #include <cvd/vector_image_ref.h>
00025 #include <cvd/image.h>
00026
00027 #include <TooN/TooN.h>
00028
00029 #include <tag/stdpp.h>
00030 #include <tag/fn.h>
00031
00032 #include <gvars3/instances.h>
00033
00034 #include "offsets.h"
00035
00036
00037 using namespace std;
00038 using namespace CVD;
00039 using namespace TooN;
00040 using namespace tag;
00041 using namespace GVars3;
00042
00043
00044
00045
00046
00047
00048
00049 vector<vector<ImageRef> > offsets;
00050
00051
00052 int num_offsets;
00053
00054
00055 pair<ImageRef, ImageRef> offsets_bbox;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 vector<ImageRef> transform_offsets(const vector<ImageRef>& offsets, int angle, bool r)
00067 {
00068 double a = angle * M_PI / 2;
00069
00070 double R_[] = { cos(a), sin(a), -sin(a) , cos(a) };
00071 double F_[] = { 1, 0, 0, r?-1:1};
00072
00073 Matrix<2> R(R_), F(F_);
00074 Matrix<2> T = R*F;
00075
00076 vector<ImageRef> ret;
00077
00078 for(unsigned int i=0; i < offsets.size(); i++)
00079 {
00080 Vector<2> v = vec(offsets[i]);
00081 ret.push_back(ir_rounded(T * v));
00082 }
00083
00084 return ret;
00085 }
00086
00087
00088
00089
00090
00091 void draw_offset_list(const vector<ImageRef>& offsets)
00092 {
00093
00094 cout << "Allowed offsets: " << offsets.size() << endl;
00095
00096 ImageRef min, max;
00097 min.x = *min_element(member_iterator(offsets.begin(), &ImageRef::x), member_iterator(offsets.end(), &ImageRef::x));
00098 max.x = *max_element(member_iterator(offsets.begin(), &ImageRef::x), member_iterator(offsets.end(), &ImageRef::x));
00099 min.y = *min_element(member_iterator(offsets.begin(), &ImageRef::y), member_iterator(offsets.end(), &ImageRef::y));
00100 max.y = *max_element(member_iterator(offsets.begin(), &ImageRef::y), member_iterator(offsets.end(), &ImageRef::y));
00101
00102 cout << print << min <<max << endl;
00103
00104 Image<int> o(max-min+ImageRef(1,1), -1);
00105 for(unsigned int i=0; i <offsets.size(); i++)
00106 o[offsets[i] -min] = i;
00107
00108 for(int y=0; y < o.size().y; y++)
00109 {
00110 for(int x=0; x < o.size().x; x++)
00111 cout << "+------";
00112 cout << "+"<< endl;
00113
00114 for(int x=0; x < o.size().x; x++)
00115 cout << "| ";
00116 cout << "|"<< endl;
00117
00118
00119 for(int x=0; x < o.size().x; x++)
00120 {
00121 if(o[y][x] >= 0)
00122 cout << "| " << setw(2) << o[y][x] << " ";
00123 else if(ImageRef(x, y) == o.size() / 2)
00124 cout << "| " << "#" << " ";
00125 else
00126 cout << "| ";
00127 }
00128 cout << "|" << endl;
00129
00130 for(int x=0; x < o.size().x; x++)
00131 cout << "| ";
00132 cout << "|"<< endl;
00133 }
00134
00135 for(int x=0; x < o.size().x; x++)
00136 cout << "+------";
00137 cout << "+"<< endl;
00138
00139 cout << endl;
00140
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 void create_offsets()
00157 {
00158
00159
00160
00161
00162
00163 offsets.resize(8);
00164 {
00165 double min_r = GV3::get<double>("offsets.min_radius");
00166 double max_r = GV3::get<double>("offsets.max_radius");
00167
00168 ImageRef max((int)ceil(max_r+1), (int)ceil(max_r+1));
00169 ImageRef min = -max, p = min;
00170
00171
00172
00173 do
00174 {
00175 double d = vec(p) * vec(p);
00176
00177 if(d >= min_r*min_r && d <= max_r * max_r)
00178 {
00179 offsets[0].push_back(p);
00180
00181 }
00182 }
00183 while(p.next(min, max));
00184
00185
00186
00187 offsets_bbox = make_pair(min, max);
00188 }
00189 offsets[1] = transform_offsets(offsets[0], 1, 0);
00190 offsets[2] = transform_offsets(offsets[0], 2, 0);
00191 offsets[3] = transform_offsets(offsets[0], 3, 0);
00192 offsets[4] = transform_offsets(offsets[0], 0, 1);
00193 offsets[5] = transform_offsets(offsets[0], 1, 1);
00194 offsets[6] = transform_offsets(offsets[0], 2, 1);
00195 offsets[7] = transform_offsets(offsets[0], 3, 1);
00196 num_offsets=offsets[0].size();
00197 }
00198
00199
00200
00201 void draw_offsets()
00202 {
00203
00204 for(unsigned int i=0; i < 8; i++)
00205 {
00206 cout << "Offsets " << i << endl;
00207 draw_offset_list(offsets[i]);
00208 cout << endl;
00209 }
00210 }