From: <hug...@li...> - 2010-07-16 10:16:50
|
details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/e69fa0b7683e changeset: 4139:e69fa0b7683e user: dmakreshanski <dma...@us...> date: Fri Jul 16 12:16:35 2010 +0200 description: finished canvas and crop outline tool for the overview diffstat: src/hugin1/hugin/CMakeLists.txt | 4 +- src/hugin1/hugin/GLPreviewFrame.cpp | 4 + src/hugin1/hugin/GLPreviewFrame.h | 4 + src/hugin1/hugin/GLRenderer.cpp | 11 +- src/hugin1/hugin/MeshManager.cpp | 27 +- src/hugin1/hugin/MeshManager.h | 1 + src/hugin1/hugin/OverviewOutlinesTool.cpp | 435 ++++++++++++++++++++++++++++++ src/hugin1/hugin/OverviewOutlinesTool.h | 69 ++++ src/hugin1/hugin/PreviewCropTool.cpp | 15 + src/hugin1/hugin/ProjectionGridTool.cpp | 73 +++- 10 files changed, 603 insertions(+), 40 deletions(-) diffs (truncated from 829 to 500 lines): diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/CMakeLists.txt --- a/src/hugin1/hugin/CMakeLists.txt Wed Jul 14 12:13:05 2010 +0200 +++ b/src/hugin1/hugin/CMakeLists.txt Fri Jul 16 12:16:35 2010 +0200 @@ -31,7 +31,7 @@ LocalizedFileTipProvider.cpp wxPanoCommand.cpp AssistantPanel.cpp HFOVDialog.cpp TextureManager.cpp MeshRemapper.cpp VertexCoordRemapper.cpp TexCoordRemapper.cpp ChoosyRemapper.cpp MeshManager.cpp ViewState.cpp -OutputProjectionInfo.cpp ToolHelper.cpp Tool.cpp OverviewCameraTool.cpp ProjectionGridTool.cpp +OutputProjectionInfo.cpp ToolHelper.cpp Tool.cpp OverviewCameraTool.cpp ProjectionGridTool.cpp OverviewOutlinesTool.cpp PreviewCropTool.cpp PreviewDragTool.cpp PreviewIdentifyTool.cpp PreviewDifferenceTool.cpp PreviewPanoMaskTool.cpp PreviewControlPointTool.cpp GreatCircles.cpp AboutDialog.cpp LayoutRemapper.cpp PreviewLayoutLinesTool.cpp @@ -47,7 +47,7 @@ LocalizedFileTipProvider.h wxPanoCommand.h AssistantPanel.h HFOVDialog.h TextureManager.h MeshRemapper.h VertexCoordRemapper.h TexCoordRemapper.h ChoosyRemapper.h MeshManager.h ViewState.h -OutputProjectionInfo.h ToolHelper.h Tool.h OverviewCameraTool.h ProjectionGridTool.h +OutputProjectionInfo.h ToolHelper.h Tool.h OverviewCameraTool.h ProjectionGridTool.h OverviewOutlinesTool.h PreviewCropTool.h PreviewDragTool.h PreviewIdentifyTool.h PreviewDifferenceTool.h PreviewPanoMaskTool.h PreviewControlPointTool.h GreatCircles.h AboutDialog.h LayoutRemapper.h PreviewLayoutLinesTool.h diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/GLPreviewFrame.cpp --- a/src/hugin1/hugin/GLPreviewFrame.cpp Wed Jul 14 12:13:05 2010 +0200 +++ b/src/hugin1/hugin/GLPreviewFrame.cpp Fri Jul 16 12:16:35 2010 +0200 @@ -77,6 +77,7 @@ #include "ProjectionGridTool.h" #include "OverviewCameraTool.h" +#include "OverviewOutlinesTool.h" #include <wx/progdlg.h> @@ -1417,6 +1418,7 @@ preview_projection_grid = new PreviewProjectionGridTool(preview_helper); preview_helper->ActivateTool(preview_projection_grid); + // activate tools that are always active. preview_helper->ActivateTool(pano_mask_tool); @@ -1435,6 +1437,8 @@ overview_identify_tool = new PreviewIdentifyTool(overview_helper, this); overview_projection_grid = new OverviewProjectionGridTool(overview_helper); overview_helper->ActivateTool(overview_projection_grid); + overview_outlines_tool = new OverviewOutlinesTool(overview_helper, m_GLPreview); + overview_helper->ActivateTool(overview_outlines_tool); } void GLPreviewFrame::OnIdentify(wxCommandEvent & e) diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/GLPreviewFrame.h --- a/src/hugin1/hugin/GLPreviewFrame.h Wed Jul 14 12:13:05 2010 +0200 +++ b/src/hugin1/hugin/GLPreviewFrame.h Fri Jul 16 12:16:35 2010 +0200 @@ -61,6 +61,8 @@ class OverviewProjectionGridTool; class PreviewProjectionGridTool; +class OverviewOutlinesTool; + class GLPreviewFrame; class GLwxAuiManager; @@ -308,6 +310,8 @@ OverviewDragTool *overview_drag_tool; OverviewCameraTool *overview_camera_tool; + OverviewOutlinesTool *overview_outlines_tool; + void TurnOffTools(std::set<Tool*> tools); void CleanButtonColours(); diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/GLRenderer.cpp --- a/src/hugin1/hugin/GLRenderer.cpp Wed Jul 14 12:13:05 2010 +0200 +++ b/src/hugin1/hugin/GLRenderer.cpp Fri Jul 16 12:16:35 2010 +0200 @@ -201,7 +201,8 @@ void GLOverviewRenderer::Redraw() { - + + glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); @@ -214,6 +215,9 @@ gluLookAt(R * cos(angy) * cos(angx), R * sin(angy), R * cos(angy) * sin(angx), 0, 0, 0, 0, 1, 0); + //for look from inside +// gluLookAt(0,0,0,R * cos(angy) * cos(angx), R * sin(angy), R * cos(angy) * sin(angx), 0, 1, 0); + // draw things under the preview images m_tool_helper->BeforeDrawImages(); // draw each active image. @@ -224,7 +228,7 @@ glColor3f(0.5,0.5,0.5); - double side = 5; + double side = 150; glBegin(GL_LINE_LOOP); glVertex3f(-side,side,0); @@ -238,7 +242,7 @@ glBegin(GL_LINES); glColor3f(1,0,0); - glVertex3f(0,0,0); + glVertex3f(-axis,0,0); glVertex3f(axis,0,0); glColor3f(0,1,0); @@ -256,6 +260,7 @@ glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); + ((OverviewToolHelper*)m_tool_helper)->BeforeDrawImagesBack(); m_tex_man->Begin(); diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/MeshManager.cpp --- a/src/hugin1/hugin/MeshManager.cpp Wed Jul 14 12:13:05 2010 +0200 +++ b/src/hugin1/hugin/MeshManager.cpp Fri Jul 16 12:16:35 2010 +0200 @@ -302,21 +302,28 @@ double th, ph; th = ((coords.vertex_c[x][y][0] / width) * hfov - hfov / 2.0); - ph = -((coords.vertex_c[x][y][1] / height) * vfov - vfov / 2.0); + ph = ((coords.vertex_c[x][y][1] / height) * vfov - vfov / 2.0); - th /= 180.0; - th *= M_PI; - ph /= 180.0; - ph *= M_PI; - - vertex_coords[x][y][0] = r * sin(th) * cos(ph); - vertex_coords[x][y][1] = r * sin(ph); - vertex_coords[x][y][2] = r * cos(th) * cos(ph); - + Convert( + vertex_coords[x][y][0], + vertex_coords[x][y][1], + vertex_coords[x][y][2], + th,-ph,r); } } } +void MeshManager::PanosphereOverviewMeshInfo::Coords3D::Convert(double &x, double &y, double &z, double th, double ph, double r) +{ + th /= 180.0; + th *= M_PI; + ph /= 180.0; + ph *= M_PI; + + x = r * sin(th) * cos(ph); + y = r * sin(ph); + z = r * cos(th) * cos(ph); +} void MeshManager::PanosphereOverviewMeshInfo::CompileList() { diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/MeshManager.h --- a/src/hugin1/hugin/MeshManager.h Wed Jul 14 12:13:05 2010 +0200 +++ b/src/hugin1/hugin/MeshManager.h Fri Jul 16 12:16:35 2010 +0200 @@ -116,6 +116,7 @@ Coords3D(const MeshRemapper::Coords & coords, VisualizationState * state); double tex_coords[2][2][2]; double vertex_coords[2][2][3]; + static void Convert(double &x, double &y, double &z, double th, double ph, double r); }; void CompileList(); diff -r 86c4470b4cf6 -r e69fa0b7683e src/hugin1/hugin/OverviewOutlinesTool.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hugin1/hugin/OverviewOutlinesTool.cpp Fri Jul 16 12:16:35 2010 +0200 @@ -0,0 +1,435 @@ + +#include <GL/glew.h> +#ifdef __WXMAC__ +#include <OpenGL/gl.h> +#include <OpenGL/glu.h> +#else +#include <GL/gl.h> +#include <GL/glu.h> +#endif +#include <GL/glut.h> + +#include "GLViewer.h" + +#include "OverviewOutlinesTool.h" + +OverviewOutlinesTool::OverviewOutlinesTool(OverviewToolHelper * helper, GLViewer * viewer) : OverviewTool(helper), preview(viewer), + display_list_number_canvas(glGenLists(1)), + display_list_number_crop(glGenLists(1)), + display_list_number_canvas_outline(glGenLists(1)), + display_list_number_crop_outline(glGenLists(1)), + dirty_meshes(true) +{ + helper->GetPanoramaPtr()->addObserver(this); +} + +OverviewOutlinesTool::~OverviewOutlinesTool() +{ + +} + +void OverviewOutlinesTool::panoramaChanged(HuginBase::PanoramaData &pano) +{ + + dirty_meshes = true; + helper->GetVisualizationStatePtr()->ForceRequireRedraw(); + +} + +void OverviewOutlinesTool::Activate() +{ + helper->NotifyMe(ToolHelper::MOUSE_MOVE, this); + ((ToolHelper*)helper)->NotifyMe(ToolHelper::DRAW_OVER_IMAGES, (Tool*)this); +} + +void OverviewOutlinesTool::MouseMoveEvent(double x, double y, wxMouseEvent & e) +{ +// std::cout << "outlines tool " << x << " " << y << std::endl; + double xp, yp; + HuginBase::PTools::Transform transform; + HuginBase::SrcPanoImage image; + image.setSize(vigra::Size2D(360,180)); + image.setHFOV(360); + image.setProjection(HuginBase::BaseSrcPanoImage::EQUIRECTANGULAR); + if (helper->GetPanoramaPtr()->getNrOfImages() > 0) { +// transform.createTransform(*helper->GetViewStatePtr()->GetSrcImage(0), *(helper->GetVisualizationStatePtr()->GetOptions())); + transform.createTransform(image, *(helper->GetVisualizationStatePtr()->GetOptions())); + transform.transformImgCoord(xp,yp,x,y); +// std::cout << "outlines tool " << xp << " " << yp << std::endl; + } +} + +struct Rec { + Rec(double left, double top, double right, double bottom) : left(left), top(top), right(right), bottom(bottom) {} + Rec() {} + double left; + double top; + double right; + double bottom; +}; + +//#define WIREFRAME + +void OverviewOutlinesTool::AfterDrawImagesEvent() +{ + + if (!preview->m_visualization_state) { + return; + } + + if (dirty_meshes) { + +// std::cout << "outlines after draw images\n"; + vigra::Rect2D rect = preview->m_visualization_state->GetVisibleArea(); + glNewList(display_list_number_canvas,GL_COMPILE); + DrawRect(rect.left(), rect.top(), rect.right(), rect.bottom(),false); + glEndList(); + glNewList(display_list_number_canvas_outline,GL_COMPILE); + DrawRect(rect.left(), rect.top(), rect.right(), rect.bottom(),true); + glEndList(); + + vigra::Rect2D roi = helper->GetViewStatePtr()->GetOptions()->getROI(); + glNewList(display_list_number_crop,GL_COMPILE); + DrawRect(roi.left(), roi.top(), roi.right(), roi.bottom(),false); + glEndList(); + glNewList(display_list_number_crop_outline,GL_COMPILE); + DrawRect(roi.left(), roi.top(), roi.right(), roi.bottom(),true); + glEndList(); + + dirty_meshes = false; + + std::cout << "outlines adi " << rect.left() << " " << rect.top() << " " << rect.right() << " " << rect.bottom() << std::endl; + std::cout << "outlines adi " << roi.left() << " " << roi.top() << " " << roi.right() << " " << roi.bottom() << std::endl; + } + + + double radius = ((PanosphereOverviewVisualizationState*)helper->GetVisualizationStatePtr())->getSphereRadius(); + + glDisable(GL_TEXTURE_2D); + + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + + + glColor4f(0,0,0,0.25); + glBlendFunc(GL_ZERO, GL_SRC_ALPHA); + GLUquadric* grid = gluNewQuadric(); + gluSphere(grid, radius+1,40,20); + + glColor4f(1.0,1.0,1.0,1.0); + glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA); + glCallList(display_list_number_canvas); + +// std::cout << "outlines " << roi.left() << " " << roi.top() << " " << roi.right() << " " << roi.bottom() << std::endl; + + glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA); + glCallList(display_list_number_crop); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0.6,0.6,0.6,0.5); + glCallList(display_list_number_canvas_outline); + glColor4f(0.6,0.6,0.6,0.8); + glCallList(display_list_number_crop_outline); + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); +} + +void OverviewOutlinesTool::DrawRect(double left, double top, double right, double bottom, bool outline) +{ + + double safety = 1; + left += safety; + top += safety; + right -= safety; + bottom -= safety; + + HuginBase::PTools::Transform transform; + HuginBase::SrcPanoImage image; + image.setSize(vigra::Size2D(360,180)); + image.setHFOV(360); + image.setProjection(HuginBase::BaseSrcPanoImage::EQUIRECTANGULAR); + transform.createTransform(image, *(preview->m_visualization_state->GetOptions())); + + HuginBase::PanoramaOptions::ProjectionFormat proj = helper->GetViewStatePtr()->GetOptions()->getProjection(); + + double radius = ((PanosphereOverviewVisualizationState*)helper->GetVisualizationStatePtr())->getSphereRadius(); + + switch(proj) { + + case HuginBase::PanoramaOptions::SINUSOIDAL: + case HuginBase::PanoramaOptions::LAMBERT: + case HuginBase::PanoramaOptions::LAMBERT_AZIMUTHAL: + case HuginBase::PanoramaOptions::FULL_FRAME_FISHEYE: + case HuginBase::PanoramaOptions::ALBERS_EQUAL_AREA_CONIC: + case HuginBase::PanoramaOptions::ORTHOGRAPHIC: + case HuginBase::PanoramaOptions::EQUISOLID: + + + { + + float steps = 40; + + double x,y,xs,ys,xd,yd; + + double wstep = (float)(right - left) / steps; + double hstep = (float)(bottom - top) / steps; + + for(int w = 0 ; w < steps ; w++) { + for(int h = 0 ; h < steps ; h++) { + + if (outline) { + if (!(w == 0 || h == 0 || w == steps - 1 || steps - 1)) { + continue; + } + } + + Rect rec(left + w * wstep, top + h * hstep, left + (w+1) * wstep, top + (h+1)* hstep); + Rect tr = rec.transformImgCoord(&transform); + + double edge1 = (tr.val[0][0]-tr.val[1][0])*(tr.val[0][0]-tr.val[1][0]) + (tr.val[0][1]-tr.val[1][1])*(tr.val[0][1]-tr.val[1][1]); + double edge2 = (tr.val[1][0]-tr.val[2][0])*(tr.val[1][0]-tr.val[2][0]) + (tr.val[1][1]-tr.val[2][1])*(tr.val[1][1]-tr.val[2][1]); + double edge3 = (tr.val[2][0]-tr.val[3][0])*(tr.val[2][0]-tr.val[3][0]) + (tr.val[2][1]-tr.val[3][1])*(tr.val[2][1]-tr.val[3][1]); + double edge4 = (tr.val[3][0]-tr.val[0][0])*(tr.val[3][0]-tr.val[0][0]) + (tr.val[3][1]-tr.val[0][1])*(tr.val[3][1]-tr.val[0][1]); + + double maxlimit = (radius/2.0)*(radius/2.0); + if ( + proj == HuginBase::PanoramaOptions::SINUSOIDAL || + proj == HuginBase::PanoramaOptions::ALBERS_EQUAL_AREA_CONIC + ) + if (edge1 > maxlimit || edge2 > maxlimit || edge3 > maxlimit || edge4 > maxlimit) { + continue; + } + + if (outline) { + + glBegin(GL_LINES); + bool edges[4] = {false,false,false,false}; + if (w == 0) { + edges[0] = true; + } + if (w == steps - 1) { + edges[2] = true; + } + if (h == 0) { + edges[3] = true; + } + if (h == steps - 1) { + edges[1] = true; + } + for (int i = 0 ; i < 4 ; i++) { + if (edges[i]) { + for (int j = 0 ; j < 2 ; j++) { + int plus = i+j; + if (plus == 4) plus = 0; + double x,y,z; + double tx,ty; + tx = tr.val[plus][0]; + ty = tr.val[plus][1]; + ty = ty - 90; + tx = tx - 180; + ty *= -1; + MeshManager::PanosphereOverviewMeshInfo::Coords3D::Convert(x,y,z,tx,ty,radius); + glVertex3f(x,y,z); + } + } + } + glEnd(); + + } else { + + #ifdef WIREFRAME + glBegin(GL_LINE_LOOP); + #else + glBegin(GL_POLYGON); + #endif + for (int s = 0 ; s < 4 ; s++) { + double x,y,z; + double tx,ty; + tx = tr.val[s][0]; + ty = tr.val[s][1]; + ty = ty - 90; + tx = tx - 180; + ty *= -1; + MeshManager::PanosphereOverviewMeshInfo::Coords3D::Convert(x,y,z,tx,ty,radius); + glVertex3f(x,y,z); + } + glEnd(); + + } + + } + } + + } + + break; + + case HuginBase::PanoramaOptions::RECTILINEAR: + case HuginBase::PanoramaOptions::EQUIRECTANGULAR: + case HuginBase::PanoramaOptions::CYLINDRICAL: + case HuginBase::PanoramaOptions::STEREOGRAPHIC: + case HuginBase::PanoramaOptions::MERCATOR: + case HuginBase::PanoramaOptions::TRANSVERSE_MERCATOR: + case HuginBase::PanoramaOptions::MILLER_CYLINDRICAL: + case HuginBase::PanoramaOptions::PANINI: + case HuginBase::PanoramaOptions::EQUI_PANINI: + case HuginBase::PanoramaOptions::BIPLANE: + case HuginBase::PanoramaOptions::TRIPLANE: + case HuginBase::PanoramaOptions::GENERAL_PANINI: + case HuginBase::PanoramaOptions::ARCHITECTURAL: + + std::vector<Rec> stack; + + stack.push_back(Rec(left,top,right,bottom)); + if (outline) { + stack.push_back(Rec(true, true, true, true)); + } + + while(stack.size() > 0) { + + Rec edge; + if (outline) { + edge = stack[stack.size() - 1]; + stack.pop_back(); + } + + Rec top_rec = stack[stack.size() - 1]; + stack.pop_back(); + + if (outline) { + if (!(edge.left || edge.top || edge.right || edge.bottom )) { + continue; + } + } + + Rect rect(top_rec.left, top_rec.top, top_rec.right, top_rec.bottom); + + Rect tr = rect.transformImgCoord(&transform); + + double xcs,ycs,xcd,ycd; + + double edge1 = (tr.val[0][0]-tr.val[1][0])*(tr.val[0][0]-tr.val[1][0]) + (tr.val[0][1]-tr.val[1][1])*(tr.val[0][1]-tr.val[1][1]); + double edge2 = (tr.val[1][0]-tr.val[2][0])*(tr.val[1][0]-tr.val[2][0]) + (tr.val[1][1]-tr.val[2][1])*(tr.val[1][1]-tr.val[2][1]); + double edge3 = (tr.val[2][0]-tr.val[3][0])*(tr.val[2][0]-tr.val[3][0]) + (tr.val[2][1]-tr.val[3][1])*(tr.val[2][1]-tr.val[3][1]); + double edge4 = (tr.val[3][0]-tr.val[0][0])*(tr.val[3][0]-tr.val[0][0]) + (tr.val[3][1]-tr.val[0][1])*(tr.val[3][1]-tr.val[0][1]); + +// std::cout << "outlines " << top_rec.left << " " << top_rec.top << " " << top_rec.right << " " << top_rec.bottom << std::endl; +// std::cout << "outlines " << edge1 << " " << edge2 << " " << edge3 << " " << edge4 << std::endl; + +// std::cout << "outlines " << tr.val[0][0] << " " << tr.val[0][1] << std::endl; +// std::cout << "outlines " << tr.val[1][0] << " " << tr.val[1][1] << std::endl; +// std::cout << "outlines " << tr.val[2][0] << " " << tr.val[2][1] << std::endl; +// std::cout << "outlines " << tr.val[3][0] << " " << tr.val[3][1] << std::endl; + |