00001
00002
00023 #ifdef __WXMAC__
00024 #include "panoinc_WX.h"
00025 #include "panoinc.h"
00026 #endif
00027
00028 #include "TexCoordRemapper.h"
00029 #include "algorithms/nona/ComputeImageROI.h"
00030 #include "ViewState.h"
00031
00032
00033
00034
00035 const double mesh_frequency = 0.07;
00036
00037 TexCoordRemapper::TexCoordRemapper(HuginBase::Panorama *m_pano,
00038 HuginBase::SrcPanoImage * image,
00039 VisualizationState *visualization_state)
00040 : MeshRemapper(m_pano, image, visualization_state)
00041 {
00042
00043 }
00044
00045 void TexCoordRemapper::UpdateAndResetIndex()
00046 {
00047
00048 SetSize();
00049
00050
00051 transform.createTransform(*image, *(visualization_state->GetOptions()));
00052
00053
00054
00055 for (unsigned int x = 0; x < divisions_x; x++)
00056 {
00057 for (unsigned int y = 0; y < divisions_y; y++)
00058 {
00059 transform.transformImgCoord(map[x][y].x,
00060 map[x][y].y,
00061 (double) x * face_width + start_x,
00062 (double) y * face_height + start_y);
00063
00064 map[x][y].x /= width;
00065 map[x][y].y /= height;
00066 }
00067 }
00068 face_index = 0;
00069 SetCrop();
00070 }
00071
00072 bool TexCoordRemapper::GetNextFaceCoordinates(Coords *result)
00073 {
00074 result->tex_c = texture_coords;
00075 result->vertex_c = vertex_coords;
00076
00077 if (GiveClipFaceResult(result)) return true;
00078
00079 while (true)
00080 {
00081 if (face_index == number_of_faces) return false;
00082 unsigned int x_f = face_index % (divisions_x - 1),
00083 y_f = face_index / (divisions_x - 1);
00084 bool all_left = true, all_right = true,
00085 all_above = true, all_below = true;
00086 for (unsigned short int x = 0; x < 2; x++)
00087 {
00088 for (unsigned short int y = 0; y < 2; y++)
00089 {
00090 unsigned int xt = x_f + x, yt = y_f + y;
00091 if (map[xt][yt].x > crop_x1) all_left = false;
00092 if (map[xt][yt].x < crop_x2) all_right = false;
00093 if (map[xt][yt].y > crop_y1) all_above = false;
00094 if (map[xt][yt].y < crop_y2) all_below = false;
00095 }
00096 }
00097
00098
00099
00100
00101 if (!(all_left || all_right || all_above || all_below)) break;
00102 face_index++;
00103 }
00104
00105 unsigned int x_f = face_index % (divisions_x - 1),
00106 y_f = face_index / (divisions_x - 1);
00107 for (unsigned short int x = 0; x < 2; x++)
00108 {
00109 for (unsigned short int y = 0; y < 2; y++)
00110 {
00111 unsigned int xt = x_f + x, yt = y_f + y;
00112 result->tex_c[x][y][0] = map[xt][yt].x;
00113 result->tex_c[x][y][1] = map[xt][yt].y;
00114 result->vertex_c[x][y][0] = (double) xt * face_width + start_x;
00115 result->vertex_c[x][y][1] = (double) yt * face_height + start_y;
00116 }
00117 }
00118 face_index++;
00119
00120
00121
00122
00123
00124
00125 if ( image->isInside(vigra::Point2D(int(result->tex_c[0][0][0] * width),
00126 int(result->tex_c[0][0][1] * height)))
00127 && image->isInside(vigra::Point2D(int(result->tex_c[0][1][0] * width),
00128 int(result->tex_c[0][1][1] * height)))
00129 && image->isInside(vigra::Point2D(int(result->tex_c[1][0][0] * width),
00130 int(result->tex_c[1][0][1] * height)))
00131 && image->isInside(vigra::Point2D(int(result->tex_c[1][1][0] * width),
00132 int(result->tex_c[1][1][1] * height))))
00133 {
00134
00135
00136
00137
00138 return true;
00139 }
00140
00141
00142
00143
00144 ClipFace(result);
00145 if (GiveClipFaceResult(result))
00146 {
00147 return true;
00148 } else {
00149 return GetNextFaceCoordinates(result);
00150 }
00151 }
00152
00153 void TexCoordRemapper::SetSize()
00154 {
00155
00156 width = (double) image->getSize().width();
00157 height = (double) image->getSize().height();
00158
00159
00160
00161
00162
00163
00164 vigra::Rect2D visible_area = visualization_state->GetVisibleArea();
00165 start_x = (double) visible_area.left() - 0.5;
00166 start_y = (double) visible_area.top() - 0.5;
00167 end_x = (double) visible_area.right() - 0.5;
00168 end_y = (double) visible_area.bottom() - 0.5;
00169 o_width = end_x - start_x;
00170 o_height = end_y - start_y;
00171
00172 scale = visualization_state->GetScale() * mesh_frequency;
00173
00174 divisions_x = (int) ((end_x - start_x) * scale + 0.5);
00175 if (divisions_x < 2) divisions_x = 2;
00176 divisions_y = (int) ((end_y - start_y) * scale + 0.5);
00177 if (divisions_y < 2) divisions_y = 2;
00178
00179
00180
00181
00182
00183
00184
00185
00186 face_width = o_width / (double) (divisions_x - 1);
00187 face_height = o_height / (double) (divisions_y - 1);
00188
00189 number_of_faces = (divisions_x - 1) * (divisions_y - 1);
00190
00191 map.resize(divisions_x);
00192 for (unsigned int column = 0; column < divisions_x; column++)
00193 {
00194 map[column].resize(divisions_y);
00195 }
00196 }
00197