Hugin trunk 0.1
Loading...
Searching...
No Matches
PerspectiveImageCtrl.h
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
10/* This 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 * Lesser 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#ifndef PerspectiveImageCtrl_H
27#define PerspectiveImageCtrl_H
28
30#include <panoinc.h>
31#include <lcms2.h>
32
34const int PerspectiveOffset = 200;
36const int maxSelectionDistance = 10;
38const int polygonPointSize = 3;
39
43class PerspectiveImageCtrl : public wxScrolledWindow
44{
45public:
46 // simple struct for lines
47 class Line
48 {
49 public:
51 // constructor for fast creation
52 Line() : start(hugin_utils::FDiff2D()), end(hugin_utils::FDiff2D()) {};
54 {
55 start = p1;
56 end = p2;
57 };
58 // swap start and end point
59 void Mirror()
60 {
62 start = end;
63 end = temp;
64 };
65 };
66
68 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = "panel");
69
75
77 void setOriginalMode();
78 bool IsOriginalShown() const { return !m_showRemappedImage; };
80 void SetRemappedMode(const HuginBase::Panorama& pano);
82 void setImage(const std::string& filename, ImageRotation rot);
84
101 void OnKillFocus(wxFocusEvent& e);
102
107 void setScale(double factor);
109 double getScale() const;
110
115
117 void OnPaint(wxPaintEvent& e);
119 void SetRectMode(bool newMode);
121 HuginBase::CPVector GetControlPoints(const unsigned int index);
122
124 ImageCache::EntryPtr getCachedImage() { return m_img; };
128 void RemoveLines();
129protected:
131 void OnSize(wxSizeEvent& e);
132
134 double getScaleFactor() const;
136 double calcAutoScaleFactor(wxSize size);
138 void rescaleImage();
140 void UpdateVirtualSize();
141
142private:
145 HuginBase::ControlPoint GetCP(const unsigned int index, const hugin_utils::FDiff2D& p1, const hugin_utils::FDiff2D& p2);
153 bool IsInsideRect(const hugin_utils::FDiff2D& p);
162 void GenerateRemappedImage(const unsigned int newWidth, const unsigned int newHeight);
163 //draw the given polygon
164 void DrawRect(wxDC& dc, const std::vector<hugin_utils::FDiff2D>& rect);
165 // draw lines
166 void DrawLines(wxDC& dc, const std::vector<Line>& lines);
167
168 //scaled bitmap
172
173 //filename of current editing file
174 std::string m_imageFilename;
175 // stores rotation of image
177 // size of displayed (probably scaled) image
179 // size of real image
183 int scale(int x) const
184 {
185 return (int)(x * getScaleFactor() + 0.5);
186 };
187 double scale(double x) const
188 {
189 return x * getScaleFactor();
190 };
192 int transform(int x) const
193 {
194 return (int)((x + PerspectiveOffset) * getScaleFactor() + 0.5);
195 };
196 double transform(double x) const
197 {
198 return (x + PerspectiveOffset) * getScaleFactor();
199 };
201 {
202 wxPoint r;
203 r.x = transform(p.x);
204 r.y = transform(p.y);
205 return r;
206 };
208 int invtransform(int x) const
209 {
210 return (int)(x / getScaleFactor() - PerspectiveOffset + 0.5);
211 };
212 double invtransform(double x) const
213 {
214 return (x / getScaleFactor() - PerspectiveOffset);
215 };
217 {
219 r.x = invtransform(p.x);
220 r.y = invtransform(p.y);
221 return r;
222 };
223 // rotate coordinate to fit possibly rotated image display
224 // useful for drawing something on the rotated display
225 template <class T>
226 T applyRot(const T& p) const
227 {
228 switch (m_imgRotation) {
229 case ROT0:
230 return p;
231 break;
232 case ROT90:
233 return T(m_realSize.GetHeight() - 1 - p.y, p.x);
234 break;
235 case ROT180:
236 return T(m_realSize.GetWidth() - 1 - p.x, m_realSize.GetHeight() - 1 - p.y);
237 break;
238 case ROT270:
239 return T(p.y, m_realSize.GetWidth() - 1 - p.x);
240 break;
241 default:
242 return p;
243 break;
244 }
245 }
246 // rotate coordinate to fit possibly rotated image display
247 // useful for converting rotated display coordinates to image coordinates
248 template <class T>
249 T applyRotInv(const T& p) const
250 {
251 switch (m_imgRotation) {
252 case ROT90:
253 return T(p.y, m_realSize.GetHeight() - 1 - p.x);
254 break;
255 case ROT180:
256 return T(m_realSize.GetWidth() - 1 - p.x, m_realSize.GetHeight() - 1 - p.y);
257 break;
258 case ROT270:
259 return T(m_realSize.GetWidth() - 1 - p.y, p.x);
260 break;
261 case ROT0:
262 default:
263 return p;
264 break;
265 }
266 }
267
270 {
271 NO_IMAGE = 0, // no image selected
272 SHOW_IMAGE, // image loaded and rectangle
273 POINT_MOVING, // dragging points of the rectangle
274 SEGMENT_MOVING, // dragging line of the rectangle
275 RECT_MOVING, // dragging the whole rectangle
276 LINE_CREATE, // create a new line
277 LINE_POINT_MOVING, // dragging one point of the line
278 LINE_MOVING // dragging one line
279 };
281
282 double m_scaleFactor{ 1.0 };
283 bool m_fitToWindow{ false };
284 bool m_showRemappedImage{ false };
285 bool m_showRect{ true };
286
288 ImageCache::EntryPtr m_img;
291
292 // positions of mouse drag
295 int m_movingPoint{ -1 };
296 // variable for saving scrolling state
297 bool m_middleMouseScroll{ false };
299
300 // colours for different parts
302 // coordinates of the rectangle
303 std::vector<hugin_utils::FDiff2D> m_rectPoints, m_rectPointsStartDrag;
304 std::vector<Line> m_lines, m_currentLine;
306
308};
309
310#endif // PerspectiveImageCtrl_H
const int maxSelectionDistance
maximal distance for selection of one point
const int polygonPointSize
half size of markers
const int PerspectiveOffset
size of border at all sides
represents a control point
Model for a panorama.
Definition Panorama.h:153
Line(const hugin_utils::FDiff2D &p1, const hugin_utils::FDiff2D &p2)
image previewer for perspective correction
PerspectiveEditorState
different states of the editor
void RemoveLines()
remove all lines from the list
std::vector< hugin_utils::FDiff2D > m_rectPointsStartDrag
std::vector< Line > m_lines
int GetNearestRectanglePoint(const hugin_utils::FDiff2D &p)
return index of nearest rectangle point or -1 if the point is too far from rectangle
T applyRotInv(const T &p) const
PerspectiveEditorState m_editorState
ImageCache::EntryPtr getCachedImage()
return pointer to ImageCache
HuginBase::CPVector GetControlPoints(const unsigned int index)
return list of control points
void DrawRect(wxDC &dc, const std::vector< hugin_utils::FDiff2D > &rect)
void OnMiddleMouseUp(wxMouseEvent &mouse)
event handler for middle mouse button, end scrolling
HuginBase::ControlPoint GetCP(const unsigned int index, const hugin_utils::FDiff2D &p1, const hugin_utils::FDiff2D &p2)
return the HuginBase::ControlPoint, using index as image index, p1 and p2 as position,...
void OnRightMouseUp(wxMouseEvent &mouse)
event handler when right mouse button is released
void AddLines(const HuginBase::CPVector &lines)
add the lines to the list
double getScaleFactor() const
get scale factor (calculates factor when fit to window is active)
double scale(double x) const
void OnSize(wxSizeEvent &e)
handler called when size of control was changed
int GetNearestRectangleLine(const hugin_utils::FDiff2D &p)
return index of nearest rectangle line or -1 if the point is too far from the rectangle lines
ImageRotation getCurrentRotation()
returns the current rotation of displayed image
void setOriginalMode()
show the original images with selected zoom ration, the mouse handlers are activated
void OnMiddleMouseDown(wxMouseEvent &mouse)
event handler for middle mouse button, start scrolling
HuginBase::Panorama m_pano
HuginBase::Panorama object for calculation of remapped image.
void rescaleImage()
rescale the image
double calcAutoScaleFactor(wxSize size)
calculate new scale factor for this image
bool IsInsideRect(const hugin_utils::FDiff2D &p)
return true, if the point p is inside the rect
int GetNearestLine(const hugin_utils::FDiff2D &p)
return index of nearest line or -1 if the point is too far from all lines
ImageCache::EntryPtr m_img
image cache entry for current image
void setScale(double factor)
set the scaling factor for mask editing display.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
creates the control
wxPoint transform(const hugin_utils::FDiff2D &p) const
hugin_utils::FDiff2D invtransform(const wxPoint &p) const
void ChangeRotation(ImageRotation newRot)
int invtransform(int x) const
translate screen coordinates to image coordinates, considers additional added border
wxBitmap m_remappedImg
the remapped image as wxBitmap
double invtransform(double x) const
int transform(int x) const
convert image coordinate to screen coordinates, considers additional added border
double getScale() const
return scale factor, 0 for autoscale
void UpdateVirtualSize()
update the virtual size of the control, necessary for correctly display the scrollbars
void SetLineColour(wxColour newColour)
sets the colour for the lines
void OnLeftMouseUp(wxMouseEvent &mouse)
event handler when right mouse button is released
void OnKillFocus(wxFocusEvent &e)
event handler, when editor lost focus, mainly cancels creating new polygon
std::vector< hugin_utils::FDiff2D > m_rectPoints
void DrawLines(wxDC &dc, const std::vector< Line > &lines)
void GenerateRemappedImage(const unsigned int newWidth, const unsigned int newHeight)
generates the remapped image suitable for wxBitmap
void OnCaptureLost(wxMouseCaptureLostEvent &e)
event handler, when mouse capture is lost, e.g.
int scale(int x) const
helper function for scale, offset and rotation
double transform(double x) const
void OnMouseMove(wxMouseEvent &mouse)
event handler when mouse is moving
void OnPaint(wxPaintEvent &e)
drawing routine
std::vector< Line > m_currentLine
void setImage(const std::string &filename, ImageRotation rot)
set the current image and mask list, this loads also the image from cache
void ClipPos(hugin_utils::FDiff2D &pos)
clip the given pos to image size + offset
void SetRemappedMode(const HuginBase::Panorama &pano)
set the panorama object for remapping, the mouse handler are deactivated
void SetRectMode(bool newMode)
set line or rect mode
T applyRot(const T &p) const
int GetNearestLinePoint(const hugin_utils::FDiff2D &p, bool &isStart)
return index of nearest line or -1 if the point to far from line
void OnLeftMouseDown(wxMouseEvent &mouse)
event handler when left mouse button is pressed
std::vector< ControlPoint > CPVector
namespace for various utils
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