Hugin trunk 0.1
Loading...
Searching...
No Matches
MaskImageCtrl.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 _MaskImageCtrl_H
27#define _MaskImageCtrl_H
28
30#include <wx/overlay.h>
31
32class MaskEditorPanel;
33
38class MaskImageCtrl : public wxScrolledWindow
39{
40public:
46
47 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = "panel");
48
50
56
58 void setPreviewOnly() { m_previewOnly=true; };
66 vigra::Rect2D getCrop() { return m_cropRect; };
68 void setActiveMask(unsigned int newMask, bool doUpdate=true);
72 void selectAllMarkers();
73
93 void OnKeyUp(wxKeyEvent &e);
95 void OnChar(wxKeyEvent& e);
100 void OnKillFocus(wxFocusEvent &e);
102 void OnScroll(wxScrollWinEvent &e);
103
105 void startNewPolygon();
107 wxSize DoGetBestSize() const override;
108
110 void SetMaskMode(bool newMaskMode);
111
116 void setScale(double factor);
117
119 double getScale()
120 { return m_fitToWindow ? 0 : m_scaleFactor; }
121
124
127
133
135 void OnPaint(wxPaintEvent& e);
136protected:
138 void OnSize(wxSizeEvent & e);
141
143 double getScaleFactor() const;
145 double calcAutoScaleFactor(wxSize size);
147 void rescaleImage();
148
149 private:
150
151 //scaled bitmap
154 //filename of current editing file
155 std::string m_imageFilename;
156 // stores rotation of image
158 // size of displayed (probably scaled) image
160 // size of real image
162 // variables for crop
164 vigra::Rect2D m_cropRect;
168 // draw active masks
170 // mask or crop mode
172 // timer to resize image only once at end of resize
174
176 int scale(int x) const
177 { return (int) (x * getScaleFactor() + 0.5); }
178
179 double scale(double x) const
180 { return x * getScaleFactor(); }
181
183 int transform(int x) const
184 { return (int) ((x+HuginBase::maskOffset) * getScaleFactor() + 0.5); }
185
186 double transform(double x) const
187 { return (x+HuginBase::maskOffset) * getScaleFactor(); }
188
190 {
191 wxPoint r;
192 r.x = transform(p.x);
193 r.y = transform(p.y);
194 return r;
195 };
196
198 int invtransform(int x) const
199 { return (int) (x/getScaleFactor()-HuginBase::maskOffset + 0.5); };
200
201 double invtransform(double x) const
202 { return (x/getScaleFactor()-HuginBase::maskOffset); };
203
205 {
207 r.x = invtransform(p.x);
208 r.y = invtransform(p.y);
209 return r;
210 };
211
212 // rotate coordinate to fit possibly rotated image display
213 // useful for drawing something on the rotated display
214 template <class T>
215 T applyRot(const T & p) const
216 {
217 switch (m_imgRotation) {
218 case ROT0:
219 return p;
220 break;
221 case ROT90:
222 return T(m_realSize.GetHeight()-1 - p.y, p.x);
223 break;
224 case ROT180:
225 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
226 break;
227 case ROT270:
228 return T(p.y, m_realSize.GetWidth()-1 - p.x);
229 break;
230 default:
231 return p;
232 break;
233 }
234 }
235
236 // rotate coordinate to fit possibly rotated image display
237 // useful for converting rotated display coordinates to image coordinates
238 template <class T>
239 T applyRotInv(const T & p) const
240 {
241 switch (m_imgRotation) {
242 case ROT90:
243 return T(p.y, m_realSize.GetHeight()-1 - p.x);
244 break;
245 case ROT180:
246 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
247 break;
248 case ROT270:
249 return T(m_realSize.GetWidth()-1 - p.y, p.x);
250 break;
251 case ROT0:
252 default:
253 return p;
254 break;
255 }
256 }
257
258 //draw the given polygon
260 //draw a selection rectange, when called the second time the rectangle is deleted
262 // draws the crop rectangle and/or circle
263 void DrawCrop(wxDC & dc);
264 // find the polygon for which the point p is inside the polygon
266 // returns a set of points which are in the selection rectangle
268 // updates the crop
270
271 // where the cursor is
276 // test, where the curos is
277 ClickPos GetClickPos(vigra::Point2D pos);
278
281 {
282 NO_IMAGE=0, // no image selected
283 NO_MASK, // image loaded, but none active mask
284 NO_SELECTION, // active polygon, but no point selected
285 POINTS_SELECTED, // points selected
286 POINTS_MOVING, // dragging points
287 POINTS_DELETING, // remove points inside rect
288 POINTS_ADDING, // adding new points add mouse position
289 POLYGON_SELECTING, // selecting an region to select another polygon
290 REGION_SELECTING, // currently selecting an region
291 NEW_POLYGON_STARTED, // modus is new polygon, but no point setted yet
292 NEW_POLYGON_CREATING, // currently creating new polygon
293 CROP_SHOWING, // only showing the crop
294 CROP_MOVING, // dragging crop
295 CROP_CIRCLE_SCALING, // circular crop changing
296 CROP_LEFT_MOVING, // dragging left border of crop
297 CROP_RIGHT_MOVING, // dragging right border of crop
298 CROP_TOP_MOVING, // dragging top border of crop
299 CROP_BOTTOM_MOVING // dragging bottom border of crop
300 };
302
306
310 unsigned int m_activeMask;
311 // the active masks, the one which is currently editing
313 // all selected points
315
316 ImageCache::EntryPtr m_img;
317
318 // positions of mouse drag
321 // variable for saving scrolling state
324
325 // colours for different parts
333
335};
336
338class MaskImageCtrlXmlHandler : public wxXmlResourceHandler
339{
341
342public:
344 virtual wxObject *DoCreateResource();
345 virtual bool CanHandle(wxXmlNode *node);
346};
347
348
349#endif // _MaskImageCtrl_H
base class, which stores one mask polygon
Definition Mask.h:53
mask editor panel.
xrc handler for mask editor
virtual wxObject * DoCreateResource()
virtual bool CanHandle(wxXmlNode *node)
mask editor
unsigned int m_activeMask
void setActiveMask(unsigned int newMask, bool doUpdate=true)
mark mask with image as beeing editing
hugin_utils::FDiff2D m_cropCenter
MaskEditorState m_maskEditState
void SetUserColourPointUnselected(wxColour newColour)
void setImage(const std::string &filename, HuginBase::MaskPolygonVector newMask, HuginBase::MaskPolygonVector masksToDraw, ImageRotation rot)
set the current image and mask list, this loads also the image from cache
void UpdateCrop(hugin_utils::FDiff2D delta)
bool SelectPointsInsideMouseRect(HuginBase::UIntSet &points, const bool considerSelectedOnly)
double getScale()
return scale factor, 0 for autoscale
int scale(int x) const
scale of width/height
std::string m_imageFilename
void OnPaint(wxPaintEvent &e)
drawing routine
void SetUserColourPolygonPositive(wxColour newColour)
T applyRotInv(const T &p) const
double invtransform(double x) const
void setScale(double factor)
set the scaling factor for mask editing display.
wxPoint m_scrollPos
HuginBase::MaskPolygonVector getNewMask() const
returns the vector of all mask (including new created mask)
void setDrawingActiveMasks(bool newDrawActiveMasks)
set if active masks should be drawn
void setNewMasks(HuginBase::MaskPolygonVector newMasks, HuginBase::MaskPolygonVector masksToDraw)
updates masks for currently selected image
HuginBase::MaskPolygonVector m_imageMask
MaskEditorPanel * m_editPanel
void startNewPolygon()
starts creating a new polygon
wxColor m_colour_polygon_positive
ImageCache::EntryPtr m_img
vigra::Rect2D m_cropRect
ImageRotation
image rotation.
wxPoint m_currentPos
void DrawSelectionRectangle()
void OnLeftMouseDblClick(wxMouseEvent &mouse)
event handler for left double click
void FindPolygon(hugin_utils::FDiff2D p)
void Init(MaskEditorPanel *parent)
vigra::Rect2D getCrop()
returns the current crop rect
void DrawCrop(wxDC &dc)
double calcAutoScaleFactor(wxSize size)
calculate new scale factor for this image
void DrawPolygon(wxDC &dc, HuginBase::MaskPolygon poly, bool isSelected, bool drawMarker)
void OnKeyUp(wxKeyEvent &e)
event handler for keyboard
ClickPos GetClickPos(vigra::Point2D pos)
void OnRightMouseUp(wxMouseEvent &mouse)
event handler when right mouse button is released
wxBitmap m_bitmap
void OnKillFocus(wxFocusEvent &e)
event handler, when editor lost focus, mainly cancels creating new polygon
double getScaleFactor() const
get scale factor (calculates factor when fit to window is active)
HuginBase::MaskPolygonVector m_masksToDraw
void OnMouseMove(wxMouseEvent &mouse)
event handler when mouse is moving
void OnSizeFinished(wxTimerEvent &e)
handler called at end of all resize
void OnMiddleMouseUp(wxMouseEvent &mouse)
event handler for middle mouse button, end scrolling
void OnLeftMouseDown(wxMouseEvent &mouse)
event handler when left mouse button is pressed
int transform(int x) const
convert image coordinate to screen coordinates, considers additional added border
wxOverlay m_overlay
wxColour m_color_selection
wxPoint transform(const hugin_utils::FDiff2D &p) const
wxColor m_colour_point_selected
wxPoint m_dragStartPos
void OnLeftMouseUp(wxMouseEvent &mouse)
event handler when right mouse button is released
ImageRotation m_imgRotation
void rescaleImage()
rescale the image
double scale(double x) const
wxSize DoGetBestSize() const override
returns size of currently scaled image
HuginBase::MaskPolygon m_editingMask
wxColor m_colour_point_unselected
void SetMaskMode(bool newMaskMode)
sets the control to mask (newMaskMode=true) or crop (newMaskMode=false) mode
void OnChar(wxKeyEvent &e)
event handler for scrolling with keyboard
ImageRotation getCurrentRotation()
returns the current rotation of displayed image
hugin_utils::FDiff2D invtransform(const wxPoint &p) const
void OnMouseWheel(wxMouseEvent &mouse)
event handler for mouse wheel
wxBitmap m_disabledBitmap
MaskImageCtrl()
ctor.
void selectAllMarkers()
select all points of active mask
wxTimer m_resizeTimer
void SetUserColourPointSelected(wxColour newColour)
void setPreviewOnly()
if called, the mouse handlers are deactivated
void setCrop(HuginBase::SrcPanoImage::CropMode newCropMode, vigra::Rect2D newCropRect, bool isCentered, hugin_utils::FDiff2D center, bool isCircleCrop)
updates the crop mode and crop rect
T applyRot(const T &p) const
void SetUserColourPolygonNegative(wxColour newColour)
sets the colour for different parts
void OnSize(wxSizeEvent &e)
handler called when size of control was changed
void OnCaptureLost(wxMouseCaptureLostEvent &e)
event handler, when mouse capture is lost, e.g.
HuginBase::UIntSet m_selectedPoints
void OnScroll(wxScrollWinEvent &e)
event handler for remember scroll position
void OnRightMouseDown(wxMouseEvent &mouse)
event handler when right mouse button is pressed
MaskEditorState
different states of the editor
double transform(double x) const
int invtransform(int x) const
translate screen coordinates to image coordinates, considers additional added border
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
wxColor m_colour_polygon_negative
HuginBase::SrcPanoImage::CropMode m_cropMode
void OnMiddleMouseDown(wxMouseEvent &mouse)
event handler for middle mouse button, start scrolling
std::vector< MaskPolygon > MaskPolygonVector
Definition Mask.h:150
const int maskOffset
polygon can exceed the image maximal maskOffset pixels in each direction bigger polygons will be clip...
Definition Mask.h:44
std::set< unsigned int > UIntSet
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