1 // -*- c-basic-offset: 4 -*-
2
3 /** @file PreviewControlPointTool.cpp
4 *
5 * @author James Legg
6 *
7 * Copyright 2009 James Legg.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This software is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this software. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 */
23
24 #ifdef _WIN32
25 #include "wx/msw/wrapwin.h"
26 #endif
27 #include <hugin/PreviewControlPointTool.h>
28 #include <panodata/ControlPoint.h>
29
30
31 #include <wx/platform.h>
32 #ifdef __WXMAC__
33 #include <OpenGL/gl.h>
34 #else
35 #ifdef __WXMSW__
36 #include <vigra/windows.h>
37 #endif
38 #include <GL/gl.h>
39 #endif
40
PreviewControlPointTool(ToolHelper * helper)41 PreviewControlPointTool::PreviewControlPointTool(ToolHelper *helper)
42 : Tool(helper)
43 {
44 m_greatCircles.setVisualizationState(helper->GetVisualizationStatePtr());
45 }
46
47 // we want to draw over the panorama when in use, so make sure we get notice.
Activate()48 void PreviewControlPointTool::Activate()
49 {
50 helper->NotifyMe(PreviewToolHelper::DRAW_OVER_IMAGES, this);
51 }
52
53 // The panorama has been drawn, draw the control points over the top.
AfterDrawImagesEvent()54 void PreviewControlPointTool::AfterDrawImagesEvent()
55 {
56 // Make Transforms for each image so we don't have to do it twice for each control point.
57 MakeTransforms();
58
59 // get all of the control points:
60 const HuginBase::CPVector &control_points = helper->GetPanoramaPtr()->getCtrlPoints();
61
62 // now draw each control point in turn:
63 helper->GetViewStatePtr()->GetTextureManager()->DisableTexture();
64 glColor3f(1.0, 0.5, 0.0);
65 size_t cp_count = control_points.size();
66 for (size_t cp_index = 0; cp_index < cp_count; cp_index++)
67 {
68 const HuginBase::ControlPoint &cp = control_points[cp_index];
69 // only draw the control point if both images have been enabled.
70 if ( helper->GetPanoramaPtr()->getImage(cp.image1Nr).getActive()
71 && helper->GetPanoramaPtr()->getImage(cp.image2Nr).getActive())
72 {
73 // draw line control points blue instead of orange.
74 bool line = cp.mode != HuginBase::ControlPoint::X_Y;
75 if (line)
76 {
77 glColor3f(0.0, 0.5, 1.0);
78 }
79 else
80 {
81 double red, green, blue;
82 hugin_utils::ControlPointErrorColour(cp.error,red,green,blue);
83 glColor3d(red, green, blue);
84 }
85 // draw a the smallest great circle arc between these two points.
86 double x1, y1, x2, y2;
87 transforms[cp.image1Nr].transformImgCoord(x1, y1, cp.x1, cp.y1);
88 transforms[cp.image2Nr].transformImgCoord(x2, y2, cp.x2, cp.y2);
89 m_greatCircles.drawLineFromSpherical(x1, y1, x2, y2);
90 }
91 }
92 glColor3f(1.0, 1.0, 1.0);
93 glEnable(GL_TEXTURE_2D);
94
95 // free transforms
96 delete [] transforms;
97 }
98
MakeTransforms()99 void PreviewControlPointTool::MakeTransforms()
100 {
101 /// @todo [efficiency] check the ViewState to see if we can keep the last one.
102 const size_t images_count = helper->GetPanoramaPtr()->getNrOfImages();
103 transforms = new HuginBase::PTools::Transform [images_count];
104 // make a pretend output options to get spherical coordinates.
105 HuginBase::PanoramaOptions options;
106 options.setWidth(360);
107 options.setHeight(180);
108 for (unsigned int image_number = 0; image_number < images_count; image_number++)
109 {
110 // we are transforming image coordinates to spherical coordinates.
111 transforms[image_number].createInvTransform(
112 *(helper->GetVisualizationStatePtr()->GetSrcImage(image_number)),
113 options
114 );
115 }
116 }
117
118