Hugin trunk 0.1
Loading...
Searching...
No Matches
GraphTools.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
10/* This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this software. If not, see
22 * <http://www.gnu.org/licenses/>.
23 *
24 */
25
26#include "panoinc_WX.h"
27#include "GraphTools.h"
29#include "base_wx/wxutils.h"
30
31namespace wxGraphTools
32{
33IMPLEMENT_CLASS(GraphPopupWindow, wxPopupTransientWindow)
34
35GraphPopupWindow::GraphPopupWindow(wxWindow* parent, wxBitmap bitmap) : wxPopupTransientWindow(parent)
36{
37 m_bitmapControl = new wxStaticBitmap(this, wxID_ANY, bitmap);
38 m_bitmapControl->Bind(wxEVT_LEFT_DOWN, &GraphPopupWindow::OnLeftDown, this);
39 m_bitmapControl->Bind(wxEVT_RIGHT_DOWN, &GraphPopupWindow::OnRightDown, this);
41 topsizer->Add(m_bitmapControl, wxEXPAND);
43};
44
49
51{
52 wxConfigBase* config = wxConfigBase::Get();
54 _("Save graph"),
55 config->Read("/actualPath", wxEmptyString), wxEmptyString,
56 _("Bitmap (*.bmp)|*.bmp|PNG-File (*.png)|*.png"),
58 dlg.SetDirectory(config->Read("/actualPath", wxEmptyString));
59 dlg.SetFilterIndex(config->Read("/lastImageTypeIndex", 0l));
60 if (dlg.ShowModal() == wxID_OK)
61 {
62 config->Write("/actualPath", dlg.GetDirectory()); // remember for later
63 wxFileName filename(dlg.GetPath());
64 int imageType = dlg.GetFilterIndex();
65 config->Write("/lastImageTypeIndex", imageType);
66 if (!filename.HasExt())
67 {
68 switch (imageType)
69 {
70 case 1:
71 filename.SetExt("png");
72 break;
73 case 0:
74 default:
75 filename.SetExt("bmp");
76 break;
77 };
78 };
79 if (filename.FileExists())
80 {
81 if (!hugin_utils::AskUserOverwrite(filename.GetFullPath(), _("Hugin"), GetParent()))
82 {
83 return;
84 }
85 }
86 switch (imageType)
87 {
88 case 1:
89 m_bitmapControl->GetBitmap().SaveFile(filename.GetFullPath(), wxBITMAP_TYPE_PNG);
90 break;
91 case 0:
92 default:
93 m_bitmapControl->GetBitmap().SaveFile(filename.GetFullPath(), wxBITMAP_TYPE_BMP);
94 break;
95 };
96 };
97};
98
99/*help class to draw charts */
101{
104 //create bitmap
106 m_dc.SelectObject(*m_bitmap);
107 m_dc.SetBackground(wxBrush(backgroundColour));
108 m_dc.Clear();
109 //draw border
110 m_dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
111 m_dc.SetBrush(*wxTRANSPARENT_BRUSH);
112 m_dc.DrawRectangle(0, 0, m_width, m_height);
114 SetChartDisplay(0, 0, 1, 1);
115};
116
119{
120 m_dc.SelectObject(wxNullBitmap);
121};
122
124void Graph::SetChartArea(int left, int top, int right, int bottom)
125{
126 m_dc.DestroyClippingRegion();
127 m_left = left;
128 m_top = top;
129 m_right = right;
130 m_bottom = bottom;
131 m_dc.SetClippingRegion(m_left - 1, m_top - 1, m_right - m_left + 2, m_bottom - m_top + 2);
132};
133
135void Graph::SetChartDisplay(double xmin, double ymin, double xmax, double ymax)
136{
137 m_xmin = xmin;
138 m_ymin = ymin;
139 m_xmax = xmax;
140 m_ymax = ymax;
141};
142
144void Graph::DrawGrid(size_t linesX, size_t linesY)
145{
146 m_dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
147 for (size_t i = 0; i < linesX; i++)
148 {
149 int x = TransformX((double)i*(m_xmax - m_xmin) / (linesX - 1) + m_xmin);
150 m_dc.DrawLine(x, m_top, x, m_bottom);
151 };
152 for (size_t i = 0; i < linesY; i++)
153 {
154 int y = TransformY((double)i*(m_ymax - m_ymin) / (linesY - 1) + m_ymin);
155 m_dc.DrawLine(m_left, y, m_right, y);
156 };
157};
158
160void Graph::DrawLine(std::vector<hugin_utils::FDiff2D> points, wxColour colour, int penWidth)
161{
162 if (points.size() < 2)
163 {
164 return;
165 };
166 wxPoint *polygonPoints = new wxPoint[points.size()];
167 for (size_t i = 0; i < points.size(); i++)
168 {
171 };
172 m_dc.SetPen(wxPen(colour, penWidth));
173 m_dc.DrawLines(points.size(), polygonPoints);
174 delete[]polygonPoints;
175};
176
178{
179 return *m_bitmap;
180};
181
182int Graph::TransformX(double x)
183{
184 return hugin_utils::round((x - m_xmin) / (m_xmax - m_xmin)*(m_right - m_left) + m_left);
185};
186
187int Graph::TransformY(double y)
188{
189 return hugin_utils::round(m_bottom - (y - m_ymin) / (m_ymax - m_ymin)*(m_bottom - m_top));
190};
191
193{
194#define NRPOINTS 100
196 opts.setHFOV(srcImage.getHFOV());
198 opts.setWidth(srcImage.getWidth());
199 opts.setHeight(srcImage.getHeight());
201 transform.createTransform(srcImage, opts);
202
203 const double minLength = std::min<double>(srcImage.getWidth(), srcImage.getHeight()) / 2.0;
204 const double maxR = std::sqrt(static_cast<double>(srcImage.getWidth()*srcImage.getWidth() + srcImage.getHeight()*srcImage.getHeight())) / (2.0*minLength);
205 //draw graph
206 Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
207 graph.SetChartArea(10, 10, 290, 190);
208 graph.SetChartDisplay(0, -0.1, maxR, 0.1);
209 graph.DrawGrid(6, 7);
210 std::vector<hugin_utils::FDiff2D> points;
211 // draw helper lines
212 // help line at r=1
213 points.push_back(hugin_utils::FDiff2D(1, -0.1));
214 points.push_back(hugin_utils::FDiff2D(1, 0.1));
215 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1);
216 points.clear();
217 // helper line at r=width/height (for landscape images), maximal radius in horizontal (or vertical) direction
218 // chart goes to r for diagonal
219 const double rMaxHorzVert = std::max<double>(srcImage.getWidth(), srcImage.getHeight()) / (2.0*minLength);
220 points.push_back(hugin_utils::FDiff2D(rMaxHorzVert, -0.1));
222 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1);
223 points.clear();
224 // now draw distortion graph
225 double r = 0;
226 for (size_t i = 0; i < NRPOINTS; i++)
227 {
228 double x, y;
229 if (transform.transform(x, y, r*minLength, 0))
230 {
231 points.push_back(hugin_utils::FDiff2D(r, x / minLength - r));
232 };
233 r += maxR / (NRPOINTS - 1);
234 };
235 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
236 // return bitmap
237 return graph.GetGraph();
238};
239
240} // namespace
#define NRPOINTS
Holds transformations for Image -> Pano and the other way.
void createTransform(const vigra::Diff2D &srcSize, VariableMap srcVars, Lens::LensProjectionFormat srcProj, const vigra::Diff2D &destSize, PanoramaOptions::ProjectionFormat destProj, const std::vector< double > &destProjParam, double destHFOV, const vigra::Diff2D &origSrcSize)
initialize pano->image transformation
bool transform(double &x_dest, double &y_dest, double x_src, double y_src) const
excecute transform
Panorama image options.
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
void setProjection(ProjectionFormat f)
set the Projection format and adjust the hfov/vfov if nessecary
void setHeight(unsigned int h)
set panorama height
void setWidth(unsigned int w, bool keepView=true)
set panorama width keep the HFOV, if keepView=true
All variables of a source image.
simple popup to show graph
Definition GraphTools.h:39
void OnRightDown(wxMouseEvent &e)
void OnLeftDown(wxMouseEvent &e)
wxStaticBitmap * m_bitmapControl
Definition GraphTools.h:46
help class to draw charts
Definition GraphTools.h:52
int TransformY(double y)
void DrawLine(std::vector< hugin_utils::FDiff2D > points, wxColour colour, int penWidth=1)
draws a line with the coordinates given in points
Graph(int graphWidth, int graphHeight, wxColour backgroundColour)
constructors, set size and background colour of resulting bitmap
void DrawGrid(size_t linesX, size_t linesY)
draws the grid with linesX lines in x-direction and linexY lines in y-direction
wxBitmap * m_bitmap
Definition GraphTools.h:81
int TransformX(double x)
void SetChartArea(int left, int top, int right, int bottom)
set where to draw the chart on the bitmap
void SetChartDisplay(double xmin, double ymin, double xmax, double ymax)
set the real dimension of the chart
const wxBitmap GetGraph() const
bool AskUserOverwrite(const wxString &filename, const wxString &caption, wxWindow *parent)
ask user if the given file should be overwritten, return true if the user confirmed the overwritting
Definition wxutils.cpp:233
double round(double x)
Definition hugin_math.h:50
wxBitmap GetDistortionGraph(const HuginBase::SrcPanoImage &srcImage)
return wxBitmap with graph of distortion for given SrcPanoImage
include file for the hugin project
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41