Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PreviewGuideTool.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /* This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This software is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this software. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifdef _WIN32
28 #include "wx/msw/wrapwin.h"
29 #endif
30 #include "PreviewGuideTool.h"
31 #ifdef __WXMAC__
32 #include <OpenGL/gl.h>
33 #else
34 #include <GL/gl.h>
35 #endif
36 
38 {
39 }
40 
42 {
44 }
45 
46 void DrawThirds(const vigra::Rect2D roi)
47 {
48  double width3 = (double) roi.width()/3.0;
49  double height3 = (double) roi.height()/3.0;
50  glBegin(GL_LINES);
51  glVertex2f((double)roi.left()+width3,roi.top());
52  glVertex2f((double)roi.left()+width3,roi.bottom());
53  glVertex2f((double)roi.left()+2.0*width3,roi.top());
54  glVertex2f((double)roi.left()+2.0*width3,roi.bottom());
55  glVertex2f(roi.left(), (double)roi.top()+height3);
56  glVertex2f(roi.right(),(double)roi.top()+height3);
57  glVertex2f(roi.left(), (double)roi.top()+2.0*height3);
58  glVertex2f(roi.right(),(double)roi.top()+2.0*height3);
59  glEnd();
60 };
61 
62 void DrawGoldenRatio(const vigra::Rect2D roi)
63 {
64  double width = (double) roi.width();
65  double height = (double) roi.height();
66  glBegin(GL_LINES);
67  glVertex2f((double)roi.left()+width*0.382,roi.top());
68  glVertex2f((double)roi.left()+width*0.382,roi.bottom());
69  glVertex2f((double)roi.left()+width*0.618,roi.top());
70  glVertex2f((double)roi.left()+width*0.618,roi.bottom());
71  glVertex2f(roi.left(), (double)roi.top()+height*0.382);
72  glVertex2f(roi.right(),(double)roi.top()+height*0.382);
73  glVertex2f(roi.left(), (double)roi.top()+height*0.618);
74  glVertex2f(roi.right(),(double)roi.top()+height*0.618);
75  glEnd();
76 };
77 
78 void DrawDiagonal(const vigra::Rect2D roi)
79 {
80  glBegin(GL_LINES);
81  glVertex2f(roi.left(), roi.top());
82  glVertex2f(roi.right(), roi.bottom());
83  glVertex2f(roi.left(), roi.bottom());
84  glVertex2f(roi.right(), roi.top());
85  glVertex2f(roi.left(), roi.top()+roi.height()/2.0);
86  glVertex2f(roi.right(), roi.top()+roi.height()/2.0);
87  glVertex2f(roi.left()+roi.width()/2.0, roi.top());
88  glVertex2f(roi.left()+roi.width()/2.0, roi.bottom());
89  glEnd();
90 };
91 
92 void DrawTriangle(const vigra::Rect2D roi, const bool up)
93 {
94  double w=roi.width();
95  double h=roi.height();
96  double x=w/(1+pow(w/h,2));
97  double y=h/(1+pow(w/h,2));
98  glBegin(GL_LINES);
99  if(up)
100  {
101  glVertex2f(roi.left(), roi.bottom());
102  glVertex2f(roi.right(), roi.top());
103  glVertex2f(roi.right()-x, roi.top()+y);
104  glVertex2f(roi.right(), roi.bottom());
105  glVertex2f(roi.left()+x, roi.bottom()-y);
106  glVertex2f(roi.left(), roi.top());
107  }
108  else
109  {
110  glVertex2f(roi.left(), roi.top());
111  glVertex2f(roi.right(), roi.bottom());
112  glVertex2f(roi.right()-x, roi.bottom()-y);
113  glVertex2f(roi.right(), roi.top());
114  glVertex2f(roi.left()+x, roi.top()+y);
115  glVertex2f(roi.left(), roi.bottom());
116  }
117  glEnd();
118 };
119 
120 void DrawDiagonalMethod(const vigra::Rect2D roi)
121 {
122  double w=roi.width();
123  double h=roi.height();
124  glBegin(GL_LINES);
125  glVertex2f(roi.left(), roi.top());
126  if(w>h)
127  {
128  glVertex2f(roi.left()+h, roi.bottom());
129  }
130  else
131  {
132  glVertex2f(roi.right(), roi.top()+w);
133  };
134  glVertex2f(roi.left(), roi.bottom());
135  if(w>h)
136  {
137  glVertex2f(roi.left()+h, roi.top());
138  }
139  else
140  {
141  glVertex2f(roi.right(), roi.bottom()-w);
142  };
143  glVertex2f(roi.right(), roi.top());
144  if(w>h)
145  {
146  glVertex2f(roi.right()-h, roi.bottom());
147  }
148  else
149  {
150  glVertex2f(roi.left(), roi.top()+w);
151  };
152  glVertex2f(roi.right(), roi.bottom());
153  if(w>h)
154  {
155  glVertex2f(roi.right()-h, roi.top());
156  }
157  else
158  {
159  glVertex2f(roi.left(), roi.bottom()-w);
160  };
161  glEnd();
162 };
163 
165 {
166  if(m_guide==NONE)
167  {
168  return;
169  };
171  vigra::Rect2D roi = opts->getROI();
172  glDisable(GL_TEXTURE_2D);
173  glColor3f(1,1,0);
174  switch(m_guide)
175  {
176  case THIRDS:
177  DrawThirds(roi);
178  break;
179  case GOLDENRATIO:
180  DrawGoldenRatio(roi);
181  break;
182  case DIAGONAL:
183  DrawDiagonal(roi);
184  break;
185  case TRIANGLE_DOWN:
186  DrawTriangle(roi,false);
187  break;
188  case TRIANGLE_UP:
189  DrawTriangle(roi,true);
190  break;
191  case DIAGONAL_METHOD:
192  DrawDiagonalMethod(roi);
193  break;
194  case NONE:
195  break;
196  };
197  glEnable(GL_TEXTURE_2D);
198 }
199 
200 void PreviewGuideTool::SetGuideStyle(const Guides newGuideStyle)
201 {
202  m_guide=newGuideStyle;
204 };
205 
207 {
208  return m_guide;
209 };
210 
PreviewGuideTool(PreviewToolHelper *helper)
constructor
void DrawDiagonalMethod(const vigra::Rect2D roi)
void DrawTriangle(const vigra::Rect2D roi, const bool up)
ViewState * GetViewStatePtr()
Definition: ToolHelper.cpp:305
void DrawDiagonal(const vigra::Rect2D roi)
void Redraw()
Definition: ViewState.cpp:345
const Guides GetGuideStyle() const
returns the current guide style
void NotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:315
void ReallyAfterDrawImagesEvent()
draws the lines
HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:273
ToolHelper * helper
The PreviewToolHelper that uses the same preview window and panorama as the tool should.
Definition: Tool.h:102
const vigra::Rect2D & getROI() const
void DrawGoldenRatio(const vigra::Rect2D roi)
interface to ToolHelper for drawing guide lines over pano
float pow(float a, double b)
Definition: utils.h:181
IMPEX double h[25][1024]
Definition: emor.cpp:169
void SetGuideStyle(const Guides newGuideStyle)
sets the guide style to the given style
void Activate()
activate the tool
void DrawThirds(const vigra::Rect2D roi)
Panorama image options.