Hugin trunk 0.1
Loading...
Searching...
No Matches
CPImageCtrl.h
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
24#ifndef _CPIMAGECTRL_H
25#define _CPIMAGECTRL_H
26
27#include <string>
28#include <vector>
29
32#include <wx/overlay.h>
33
34class CPEditorPanel;
35class CPImageCtrl;
36
40class CPEvent : public wxCommandEvent
41{
43
45
46public:
47 CPEvent( );
49 CPEvent(wxWindow* win, CPEventMode mode);
51 CPEvent(wxWindow* win, hugin_utils::FDiff2D & p);
53 CPEvent(wxWindow *win, unsigned int cpNr);
55 CPEvent(wxWindow* win, unsigned int cpNr, const hugin_utils::FDiff2D & p);
57 CPEvent(wxWindow* win, const hugin_utils::FDiff2D & p1, const hugin_utils::FDiff2D & p2);
59 CPEvent(wxWindow* win, CPEventMode mode, const hugin_utils::FDiff2D & p);
63 CPEvent(wxWindow* win, CPEventMode mode, size_t cpNr, const HuginBase::ControlPoint cp);
64
65 virtual wxEvent* Clone() const;
66
70 { return mode; };
71
72 const wxRect & getRect()
73 { return region; }
74
76 { return point; }
77
78 unsigned int getPointNr()
79 { return pointNr; }
80
83private:
89};
90
92
95{
96public:
106 void SetControl(CPImageCtrl* control);
108 void Draw(wxDC& dc, const wxRect& visibleRect, bool selected, bool newPoint=false);
110 const bool isOccupiedLabel(const wxPoint mousePos) const;
112 const bool isOccupiedPos(const hugin_utils::FDiff2D &p) const;
118 const bool IsMirrored() const { return m_mirrored; };
120 const wxString GetLabel() const { return m_label; };
122 void UpdateControlPointX(double x);
124 void UpdateControlPointY(double y);
137private:
141 void DrawLine(wxDC& dc);
143 void DrawLineSegment(wxDC& dc);
145 bool IsDrawingLine() const;
162 bool m_line;
163};
164
169class CPImageCtrl : public wxScrolledWindow
170{
171public:
221
227
228 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = "panel");
229
230 void Init(CPEditorPanel * parent);
231
232
235 ~CPImageCtrl();
236
242
245 void setImage (const std::string & filename, ImageRotation rot);
246 void setSameImage(bool sameImage);
252
254 void setCtrlPoint(const HuginBase::ControlPoint& cp, const bool mirrored);
256 void clearCtrlPointList();
257
259 void clearNewPoint();
260
262 void setNewPoint(const hugin_utils::FDiff2D & p);
263
265 void selectPoint(unsigned int, bool scrollTo = true);
266
268 void deselect();
269
277
278 wxSize DoGetBestSize() const;
279// virtual wxSize GetBestSize() const
280// { return DoGetBestSize(); }
281
286 void setScale(double factor);
287
289 double getScale()
290 { return fitToWindow ? 0 : scaleFactor; }
291
298 void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false);
299
303 void showSearchArea(bool show=true);
304
305 void showTemplateArea(bool show=true);
306
309
311 void ScrollDelta(const wxPoint & delta);
312
315
316 int scale(int x) const
317 { return (int) (x * getScaleFactor() + 0.5); }
318
319 double scale(double x) const
320 { return x * getScaleFactor(); }
321
323 {
325 r.x = scale(p.x);
326 r.y = scale(p.y);
327 return r;
328 }
329
330 wxPoint scale(const wxPoint & p) const
331 {
332 wxPoint r;
333 r.x = scale(p.x);
334 r.y = scale(p.y);
335 return r;
336 }
337
338 int invScale(int x) const
339 { return (int) (x / getScaleFactor() + 0.5); }
340
341 double invScale(double x) const
342 { return x / getScaleFactor(); }
343
345 {
347 r.x = invScale(p.x);
348 r.y = invScale(p.y);
349 return r;
350 }
351
352 wxPoint invScale(const wxPoint & p) const
353 {
354 wxPoint r;
355 r.x = invScale(p.x);
356 r.y = invScale(p.y);
357 return r;
358 }
359
361 {
363 }
364
365 // rotate coordinate to fit possibly rotated image display
366 // useful for drawing something on the rotated display
367 template <class T>
368 T applyRot(const T & p) const
369 {
370 switch (m_imgRotation) {
371 case ROT0:
372 return p;
373 break;
374 case ROT90:
375 return T(m_realSize.GetHeight()-1 - p.y, p.x);
376 break;
377 case ROT180:
378 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
379 break;
380 case ROT270:
381 return T(p.y, m_realSize.GetWidth()-1 - p.x);
382 break;
383 default:
384 return p;
385 break;
386 }
387 }
388
389 // rotate coordinate to fit possibly rotated image display
390 // useful for converting rotated display coordinates to image coordinates
391 template <class T>
392 T applyRotInv(const T & p) const
393 {
394 switch (m_imgRotation) {
395 case ROT90:
396 return T(p.y, m_realSize.GetHeight()-1 - p.x);
397 break;
398 case ROT180:
399 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
400 break;
401 case ROT270:
402 return T(m_realSize.GetWidth()-1 - p.y, p.x);
403 break;
404 case ROT0:
405 default:
406 return p;
407 break;
408 }
409 }
410 // some helper function for DisplayedControlPoint
411 const bool GetMouseInWindow() const { return m_mouseInWindow; };
412 const bool GetForceMagnifier() const { return m_forceMagnifier; };
418 const wxSize GetRealImageSize() const { return m_realSize; };
420 const wxSize GetBitmapSize() const;
421
422 // setting/getting option if line cp should be shown as separate line
423 void ShowLines(bool isShown);
424 bool IsShowingLines() const;
425protected:
426 // display the image when loading finishes
427 void OnImageLoaded(ImageCache::EntryPtr entry, std::string filename, bool load_small);
428 void OnSize(wxSizeEvent & e);
430 void OnKey(wxKeyEvent & e);
431 void OnKeyDown(wxKeyEvent & e);
432 void OnMouseLeave(wxMouseEvent & e);
433 void OnMouseEnter(wxMouseEvent & e);
434 void OnTimer(wxTimerEvent & e);
437 void OnPaint(wxPaintEvent& e);
438
440 bool emit(CPEvent & ev);
441
443 double getScaleFactor() const;
444
446 double calcAutoScaleFactor(wxSize size);
447
448 // rescale image
449 void rescaleImage();
450
451private:
453 std::string imageFilename;
454 // size of displayed (probably scaled) image
456 // size of real image
458 // for drawing overlay
460 // cache mag image
463 // should line cp shown as line
464 bool m_showLines { true };
465 // timer for resizing only once at end of resizing
467
468 std::vector<DisplayedControlPoint> m_points;
469
472
473 // this is only valid during MOVE_POINT
474 unsigned int selectedPointNr;
475 // valid during MOVE_POINT and CREATE_POINT
482
483 // only valid during SELECT_DELETE_REGION
485 // draw a selection rectangle from pos1 to pos2
487
489 // store pointer to transformation object to draw line control points
493 // store pointer to transformation for drawing the magnifier
496
497 // colors for the different points
498 std::vector<wxColour> pointColors;
499 std::vector<wxColour> textColours;
502
505
508
511
514 EditorState isOccupied(wxPoint mousePos, const hugin_utils::FDiff2D & point, unsigned int & pointNr) const;
515
517
519
520 ImageCache::EntryPtr m_img;
521 ImageCache::RequestPtr m_imgRequest;
522
525 wxTimer m_timer;
526
528};
529
531class CPImageCtrlXmlHandler : public wxXmlResourceHandler
532{
534
535public:
537 virtual wxObject *DoCreateResource();
538 virtual bool CanHandle(wxXmlNode *node);
539};
540
541
542#endif // _CPIMAGECTRL_H
wxDECLARE_EVENT(EVT_CPEVENT, CPEvent)
#define shift
control point editor panel.
Events to notify about new point / region / point change.
Definition CPImageCtrl.h:41
CPEventMode mode
Definition CPImageCtrl.h:84
const hugin_utils::FDiff2D & getPoint()
Definition CPImageCtrl.h:75
hugin_utils::FDiff2D point
Definition CPImageCtrl.h:86
unsigned int getPointNr()
Definition CPImageCtrl.h:78
const wxRect & getRect()
Definition CPImageCtrl.h:72
@ POINT_CHANGED
Definition CPImageCtrl.h:44
@ DELETE_REGION_SELECTED
Definition CPImageCtrl.h:44
@ RIGHT_CLICK
Definition CPImageCtrl.h:44
@ NEW_LINE_ADDED
Definition CPImageCtrl.h:44
@ NEW_POINT_CHANGED
Definition CPImageCtrl.h:44
@ POINT_SELECTED
Definition CPImageCtrl.h:44
HuginBase::ControlPoint m_cp
Definition CPImageCtrl.h:87
const HuginBase::ControlPoint & getControlPoint()
Definition CPImageCtrl.h:81
CPEventMode getMode()
accessor functions (they could check mode to see if a getXYZ() is allowed
Definition CPImageCtrl.h:69
int pointNr
Definition CPImageCtrl.h:88
wxRect region
Definition CPImageCtrl.h:85
virtual wxEvent * Clone() const
virtual bool CanHandle(wxXmlNode *node)
virtual wxObject * DoCreateResource()
brief description.
void mouseReleaseLMBEvent(wxMouseEvent &mouse)
void showSearchArea(bool show=true)
show/hide the search area rectangle
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
wxPoint roundP(const hugin_utils::FDiff2D &p) const
void mousePressLMBEvent(wxMouseEvent &mouse)
ImageRotation
image rotation.
const wxSize GetRealImageSize() const
return the real size of the image in the control
DisplayedControlPoint m_selectedPoint
const bool GetMouseInWindow() const
double scaleFactor
void mousePressMMBEvent(wxMouseEvent &mouse)
void clearNewPoint()
clear new point
CPImageCtrl()
ctor.
EditorState isOccupied(wxPoint mousePos, const hugin_utils::FDiff2D &point, unsigned int &pointNr) const
check if p is over a known point, if it is, pointNr contains the point
wxCursor * m_CPSelectCursor
void setTransforms(HuginBase::PTools::Transform *firstTrans, HuginBase::PTools::Transform *firstInvTrans, HuginBase::PTools::Transform *secondInvTrans)
HuginBase::PTools::Transform * getFirstTrans() const
unsigned int selectedPointNr
void mouseReleaseMMBEvent(wxMouseEvent &mouse)
wxOverlay m_overlay
int m_searchRectWidth
bool m_mouseInWindow
hugin_utils::FDiff2D invScale(const hugin_utils::FDiff2D &p) const
std::vector< wxColour > pointColors
~CPImageCtrl()
dtor.
hugin_utils::FDiff2D newPoint
void clearCtrlPointList()
clear internal control point list
wxPoint MaxScrollDelta(wxPoint delta)
calculate maximum delta that is allowed when scrolling
double invScale(double x) const
EditorState
state machine for selection process:
bool IsShowingLines() const
HuginBase::PTools::Transform * getFirstInvTrans() const
wxCursor * m_ScrollCursor
HuginBase::PTools::Transform * getSecondInvTrans() const
void rescaleImage()
EditorState editState
bool emit(CPEvent &ev)
helper func to emit a region
const wxSize GetBitmapSize() const
return the size of the drawn bitmap (possible rotate is applied)
void setSameImage(bool sameImage)
wxPoint scale(const wxPoint &p) const
void mousePressRMBEvent(wxMouseEvent &mouse)
void Init(CPEditorPanel *parent)
wxSize imageSize
void setImage(const std::string &filename, ImageRotation rot)
display img.
hugin_utils::FDiff2D rectStartPos
wxSize m_realSize
double getScale()
return scale factor, 0 for autoscale
hugin_utils::FDiff2D getNewPoint()
get the new point
bool m_showTemplateArea
void OnKeyDown(wxKeyEvent &e)
HuginBase::ImageCache::ImageCacheRGB8Ptr GetImg()
get pointer to image, for DisplayedControlPoint
double getScaleFactor() const
get scale factor (calculates factor when fit to window is active)
HuginBase::PTools::Transform * m_secondInvTrans
ImageCache::RequestPtr m_imgRequest
void setCtrlPoint(const HuginBase::ControlPoint &cp, const bool mirrored)
add control piont to internal cp list
void deselect()
remove selection.
int m_templateRectWidth
void OnSize(wxSizeEvent &e)
void OnPaint(wxPaintEvent &e)
paint event
void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false)
Show point x, y.
void DrawSelectionRectangle(hugin_utils::FDiff2D pos1, hugin_utils::FDiff2D pos2)
void OnSizeFinished(wxTimerEvent &e)
HuginBase::PTools::Transform * m_firstTrans
std::string imageFilename
void setNewPoint(const hugin_utils::FDiff2D &p)
set new point to a specific point
bool m_forceMagnifier
wxBitmap & GetMagBitmap(hugin_utils::FDiff2D point)
draw the magnified view of a selected control point
CPEditorPanel * m_editPanel
ImageRotation m_imgRotation
void showTemplateArea(bool show=true)
HuginBase::PTools::Transform * m_firstInvTrans
void ShowLines(bool isShown)
hugin_utils::FDiff2D m_mousePos
void setScale(double factor)
set the scaling factor for cp display.
wxPoint invScale(const wxPoint &p) const
hugin_utils::FDiff2D scale(const hugin_utils::FDiff2D &p) const
hugin_utils::FDiff2D m_magImgCenter
int scale(int x) const
void mouseReleaseRMBEvent(wxMouseEvent &mouse)
void setMagTransforms(HuginBase::PTools::Transform *magTrans, HuginBase::PTools::Transform *magInvTrans)
T applyRotInv(const T &p) const
HuginBase::PTools::Transform * m_magTrans
wxTimer m_resizeTimer
T applyRot(const T &p) const
wxBitmap bitmap
void ScrollDelta(const wxPoint &delta)
scroll the window by delta pixels
int invScale(int x) const
void OnImageLoaded(ImageCache::EntryPtr entry, std::string filename, bool load_small)
void OnScrollWin(wxScrollWinEvent &e)
const bool GetForceMagnifier() const
wxSize DoGetBestSize() const
void selectPoint(unsigned int, bool scrollTo=true)
select a point for usage
void OnTimer(wxTimerEvent &e)
bool m_sameImage
true, if in control point tab the same image is selected 2 times in this case a special treatment for...
double calcAutoScaleFactor(wxSize size)
calculate new scale factor for this image
void OnMouseLeave(wxMouseEvent &e)
HuginBase::PTools::Transform * m_magInvTrans
wxPoint m_mouseScrollPos
std::vector< DisplayedControlPoint > m_points
wxTimer m_timer
void OnKey(wxKeyEvent &e)
void mouseMoveEvent(wxMouseEvent &mouse)
void OnMouseEnter(wxMouseEvent &e)
wxBitmap m_magImg
double scale(double x) const
ImageCache::EntryPtr m_img
std::vector< wxColour > textColours
bool m_showSearchArea
helper class to display and manipulate cp in cp tab
Definition CPImageCtrl.h:95
void SetLabel(wxString newLabel)
set label to given wxString
wxColour m_pointColour
colour of the point
wxColour m_textColour
colour of the text background
bool m_mirrored
is first or second image in cp used
const HuginBase::ControlPoint GetControlPoint() const
returns the control point
wxRect m_labelPos
position of the point labels (in screen coordinates)
void UpdateControlPointX(double x)
update x coordinate of selected cp coordinate
DisplayedControlPoint()
default constructor
Definition CPImageCtrl.h:98
bool m_line
true, if line control point on same image
void StartLineControlPoint(hugin_utils::FDiff2D newPoint)
starts a new line control point with given coodinates
const bool isOccupiedPos(const hugin_utils::FDiff2D &p) const
check if the given point is over the drawn cp, using image coordinates
void CheckSelection(const wxPoint mousePos, const hugin_utils::FDiff2D &p)
used by manipulating line control points, remember if the selected point given in screen coordinates
void UpdateControlPoint(hugin_utils::FDiff2D newPoint)
update selected cp coordinate
bool IsDrawingLine() const
return true, if line cp should be drawn as separate line
HuginBase::ControlPoint m_cp
representation of underlying control point
wxString m_label
label of displayed control point: number or new
CPImageCtrl * m_control
pointer to control to access some functions
void SetColour(wxColour pointColour, wxColour textColour)
set colours for drawing control points
void DrawLineSegment(wxDC &dc)
draw line control point over different images
bool operator==(const DisplayedControlPoint other)
compare operator
hugin_utils::FDiff2D GetPos() const
returns selected position
const bool isOccupiedLabel(const wxPoint mousePos) const
check if given point is over label of cp, using screen coordinates
void ShiftControlPoint(hugin_utils::FDiff2D shift)
shift selected cp coordinate by given
void Draw(wxDC &dc, const wxRect &visibleRect, bool selected, bool newPoint=false)
draw the control points to the given device context
void DrawLine(wxDC &dc)
draw line control point on same image
const wxString GetLabel() const
return label
wxRect DrawTextMag(wxDC &dc, wxPoint p, hugin_utils::FDiff2D pointInput, bool drawMag, wxColour pointColour, wxColour textColour)
draw magnified area
void UpdateControlPointY(double y)
update y coordinate of selected cp coordinate
const bool IsMirrored() const
return true, if cp is used with mirrored coordinates by current CPImageCtrl
void SetControl(CPImageCtrl *control)
remember the control, where the information should be drawn
represents a control point
std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
use reference counted pointers
Definition ImageCache.h:57
Holds transformations for Image -> Pano and the other way.
int roundi(T x)
Definition hugin_math.h:73
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