Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
31 #include <base_wx/wxImageCache.h>
32 #include <wx/overlay.h>
33 
34 class CPEditorPanel;
35 class CPImageCtrl;
36 
40 class CPEvent : public wxCommandEvent
41 {
42  DECLARE_DYNAMIC_CLASS(CPEvent)
43 
45 
46 public:
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);
61  CPEvent(wxWindow* win, CPEventMode mode, const HuginBase::ControlPoint cp);
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 
82  { return m_cp; };
83 private:
85  wxRect region;
88  int pointNr;
89 };
90 
91 typedef void (wxEvtHandler::*CPEventFunction)(CPEvent&);
92 
93 BEGIN_DECLARE_EVENT_TYPES()
94 #if defined _WIN32 && defined Hugin_shared
95  DECLARE_LOCAL_EVENT_TYPE(EVT_CPEVENT,1)
96 #else
97  DECLARE_EVENT_TYPE(EVT_CPEVENT,1)
98 #endif
99 END_DECLARE_EVENT_TYPES()
100 
101 #define EVT_CPEVENT(func) \
102  DECLARE_EVENT_TABLE_ENTRY( EVT_CPEVENT, \
103  -1, \
104  -1, \
105  (wxObjectEventFunction) \
106  (CPEventFunction) & func, \
107  (wxObject *) NULL ),
108 
109 
112 {
113 public:
117  DisplayedControlPoint(const HuginBase::ControlPoint& cp, CPImageCtrl* control, bool mirrored);
119  void SetColour(wxColour pointColour, wxColour textColour);
121  void SetLabel(wxString newLabel);
123  void SetControl(CPImageCtrl* control);
125  void Draw(wxDC& dc, const wxRect& visibleRect, bool selected, bool newPoint=false);
127  const bool isOccupiedLabel(const wxPoint mousePos) const;
129  const bool isOccupiedPos(const hugin_utils::FDiff2D &p) const;
133  void CheckSelection(const wxPoint mousePos, const hugin_utils::FDiff2D& p);
135  const bool IsMirrored() const { return m_mirrored; };
137  const wxString GetLabel() const { return m_label; };
139  void UpdateControlPointX(double x);
141  void UpdateControlPointY(double y);
151  const HuginBase::ControlPoint GetControlPoint() const { return m_cp; };
153  bool operator==(const DisplayedControlPoint other);
154 private:
156  wxRect DrawTextMag(wxDC& dc, wxPoint p, hugin_utils::FDiff2D pointInput, bool drawMag, wxColour pointColour, wxColour textColour);
158  void DrawLine(wxDC& dc);
160  void DrawLineSegment(wxDC& dc);
162  bool IsDrawingLine() const;
170  wxColour m_pointColour;
172  wxColour m_textColour;
174  wxString m_label;
176  wxRect m_labelPos;
177  wxRect m_labelPos2;
179  bool m_line;
180 };
181 
186 class CPImageCtrl : public wxScrolledWindow
187 {
188 public:
238 
242  : scaleFactor(1),fitToWindow(false)
243  { }
244 
245  bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxT("panel"));
246 
247  void Init(CPEditorPanel * parent);
248 
249 
252  ~CPImageCtrl();
253 
259 
262  void setImage (const std::string & filename, ImageRotation rot);
263  void setSameImage(bool sameImage);
269 
271  void setCtrlPoint(const HuginBase::ControlPoint& cp, const bool mirrored);
273  void clearCtrlPointList();
274 
276  void clearNewPoint();
277 
279  void setNewPoint(const hugin_utils::FDiff2D & p);
280 
282  void selectPoint(unsigned int, bool scrollTo = true);
283 
285  void deselect();
286 
287  void mousePressLMBEvent(wxMouseEvent& mouse);
288  void mouseReleaseLMBEvent(wxMouseEvent& mouse);
289  void mousePressRMBEvent(wxMouseEvent& mouse);
290  void mouseReleaseRMBEvent(wxMouseEvent& mouse);
291  void mouseMoveEvent(wxMouseEvent& mouse);
292  void mousePressMMBEvent(wxMouseEvent& mouse);
293  void mouseReleaseMMBEvent(wxMouseEvent& mouse);
294 
295  wxSize DoGetBestSize() const;
296 // virtual wxSize GetBestSize() const
297 // { return DoGetBestSize(); }
298 
303  void setScale(double factor);
304 
306  double getScale()
307  { return fitToWindow ? 0 : scaleFactor; }
308 
315  void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false);
316 
320  void showSearchArea(bool show=true);
321 
322  void showTemplateArea(bool show=true);
323 
326 
328  void update();
329 
331  void ScrollDelta(const wxPoint & delta);
332 
334  wxPoint MaxScrollDelta(wxPoint delta);
335 
336  int scale(int x) const
337  { return (int) (x * getScaleFactor() + 0.5); }
338 
339  double scale(double x) const
340  { return x * getScaleFactor(); }
341 
343  {
345  r.x = scale(p.x);
346  r.y = scale(p.y);
347  return r;
348  }
349 
350  wxPoint scale(const wxPoint & p) const
351  {
352  wxPoint r;
353  r.x = scale(p.x);
354  r.y = scale(p.y);
355  return r;
356  }
357 
358  int invScale(int x) const
359  { return (int) (x / getScaleFactor() + 0.5); }
360 
361  double invScale(double x) const
362  { return x / getScaleFactor(); }
363 
365  {
367  r.x = invScale(p.x);
368  r.y = invScale(p.y);
369  return r;
370  }
371 
372  wxPoint invScale(const wxPoint & p) const
373  {
374  wxPoint r;
375  r.x = invScale(p.x);
376  r.y = invScale(p.y);
377  return r;
378  }
379 
380  wxPoint roundP(const hugin_utils::FDiff2D & p) const
381  {
382  return wxPoint(hugin_utils::roundi(p.x), hugin_utils::roundi(p.y));
383  }
384 
385  // rotate coordinate to fit possibly rotated image display
386  // useful for drawing something on the rotated display
387  template <class T>
388  T applyRot(const T & p) const
389  {
390  switch (m_imgRotation) {
391  case ROT0:
392  return p;
393  break;
394  case ROT90:
395  return T(m_realSize.GetHeight()-1 - p.y, p.x);
396  break;
397  case ROT180:
398  return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
399  break;
400  case ROT270:
401  return T(p.y, m_realSize.GetWidth()-1 - p.x);
402  break;
403  default:
404  return p;
405  break;
406  }
407  }
408 
409  // rotate coordinate to fit possibly rotated image display
410  // useful for converting rotated display coordinates to image coordinates
411  template <class T>
412  T applyRotInv(const T & p) const
413  {
414  switch (m_imgRotation) {
415  case ROT90:
416  return T(p.y, m_realSize.GetHeight()-1 - p.x);
417  break;
418  case ROT180:
419  return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
420  break;
421  case ROT270:
422  return T(m_realSize.GetWidth()-1 - p.y, p.x);
423  break;
424  case ROT0:
425  default:
426  return p;
427  break;
428  }
429  }
430  // some helper function for DisplayedControlPoint
431  const bool GetMouseInWindow() const { return m_mouseInWindow; };
432  const bool GetForceMagnifier() const { return m_forceMagnifier; };
436  wxBitmap& GetMagBitmap(hugin_utils::FDiff2D point);
438  const wxSize GetRealImageSize() const { return m_realSize; };
440  const wxSize GetBitmapSize() const;
441 
442  virtual void OnDraw(wxDC& dc);
443 
444  // setting/getting option if line cp should be shown as separate line
445  void ShowLines(bool isShown);
446  bool IsShowingLines() const;
447 protected:
448  // display the image when loading finishes
449  void OnImageLoaded(ImageCache::EntryPtr entry, std::string filename, bool load_small);
450  void OnSize(wxSizeEvent & e);
451  void OnKey(wxKeyEvent & e);
452  void OnKeyDown(wxKeyEvent & e);
453  void OnMouseLeave(wxMouseEvent & e);
454  void OnMouseEnter(wxMouseEvent & e);
455  void OnTimer(wxTimerEvent & e);
456  void OnScrollWin(wxScrollWinEvent & e);
457 
459  bool emit(CPEvent & ev);
460 
462  double getScaleFactor() const;
463 
465  double calcAutoScaleFactor(wxSize size);
466 
467  // rescale image
468  void rescaleImage();
469 
470 private:
471  wxBitmap bitmap;
472  std::string imageFilename;
473  // size of displayed (probably scaled) image
474  wxSize imageSize;
475  // size of real image
476  wxSize m_realSize;
477  // for drawing overlay
478  wxOverlay m_overlay;
479  // cache mag image
480  wxBitmap m_magImg;
482  // should line cp shown as line
483  bool m_showLines { true };
484 
485  std::vector<DisplayedControlPoint> m_points;
486 
487  wxCursor * m_CPSelectCursor;
488  wxCursor * m_ScrollCursor;
489 
490  // this is only valid during MOVE_POINT
491  unsigned int selectedPointNr;
492  // valid during MOVE_POINT and CREATE_POINT
499 
500  // only valid during SELECT_DELETE_REGION
502  // draw a selection rectangle from pos1 to pos2
504 
506  // store pointer to transformation object to draw line control points
510  // store pointer to transformation for drawing the magnifier
513 
514  // colors for the different points
515  std::vector<wxColour> pointColors;
516  std::vector<wxColour> textColours;
517  double scaleFactor;
519 
522 
525 
528 
531  EditorState isOccupied(wxPoint mousePos, const hugin_utils::FDiff2D & point, unsigned int & pointNr) const;
532 
534 
536 
537  ImageCache::EntryPtr m_img;
538  ImageCache::RequestPtr m_imgRequest;
539 
542  wxTimer m_timer;
543 
545  DECLARE_DYNAMIC_CLASS(CPImageCtrl)
546 };
547 
549 class CPImageCtrlXmlHandler : public wxXmlResourceHandler
550 {
551  DECLARE_DYNAMIC_CLASS(CPImageCtrlXmlHandler)
552 
553 public:
555  virtual wxObject *DoCreateResource();
556  virtual bool CanHandle(wxXmlNode *node);
557 };
558 
559 
560 #endif // _CPIMAGECTRL_H
int pointNr
Definition: CPImageCtrl.h:88
int m_templateRectWidth
Definition: CPImageCtrl.h:527
void ScrollDelta(const wxPoint &delta)
scroll the window by delta pixels
CPEventMode mode
Definition: CPImageCtrl.h:82
wxPoint invScale(const wxPoint &p) const
Definition: CPImageCtrl.h:372
double calcAutoScaleFactor(wxSize size)
calculate new scale factor for this image
wxColour m_pointColour
colour of the point
Definition: CPImageCtrl.h:170
HuginBase::PTools::Transform * getFirstInvTrans() const
Definition: CPImageCtrl.h:267
hugin_utils::FDiff2D invScale(const hugin_utils::FDiff2D &p) const
Definition: CPImageCtrl.h:364
DisplayedControlPoint()
default constructor
Definition: CPImageCtrl.h:115
int scale(int x) const
Definition: CPImageCtrl.h:336
wxSize DoGetBestSize() const
int m_searchRectWidth
Definition: CPImageCtrl.h:521
int invScale(int x) const
Definition: CPImageCtrl.h:358
wxSize imageSize
Definition: CPImageCtrl.h:474
int roundi(T x)
Definition: hugin_math.h:73
void setNewPoint(const hugin_utils::FDiff2D &p)
set new point to a specific point
ImageRotation m_imgRotation
Definition: CPImageCtrl.h:535
CPEventMode getMode()
accessor functions (they could check mode to see if a getXYZ() is allowed
Definition: CPImageCtrl.h:69
hugin_utils::FDiff2D GetPos() const
returns selected position
void deselect()
remove selection.
void SetColour(wxColour pointColour, wxColour textColour)
set colours for drawing control points
void OnKeyDown(wxKeyEvent &e)
double getScaleFactor() const
get scale factor (calculates factor when fit to window is active)
ImageCache::RequestPtr m_imgRequest
Definition: CPImageCtrl.h:538
const bool GetForceMagnifier() const
Definition: CPImageCtrl.h:432
control point editor panel.
Definition: CPEditorPanel.h:64
bool operator==(const DisplayedControlPoint other)
compare operator
wxBitmap & GetMagBitmap(hugin_utils::FDiff2D point)
draw the magnified view of a selected control point
void Draw(wxDC &dc, const wxRect &visibleRect, bool selected, bool newPoint=false)
draw the control points to the given device context
const bool IsMirrored() const
return true, if cp is used with mirrored coordinates by current CPImageCtrl
Definition: CPImageCtrl.h:135
virtual wxEvent * Clone() const
wxBitmap bitmap
Definition: CPImageCtrl.h:471
void selectPoint(unsigned int, bool scrollTo=true)
select a point for usage
Events to notify about new point / region / point change.
Definition: CPImageCtrl.h:40
void mousePressLMBEvent(wxMouseEvent &mouse)
bool m_sameImage
true, if in control point tab the same image is selected 2 times in this case a special treatment for...
Definition: CPImageCtrl.h:498
void DrawSelectionRectangle(hugin_utils::FDiff2D pos1, hugin_utils::FDiff2D pos2)
hugin_utils::FDiff2D m_magImgCenter
Definition: CPImageCtrl.h:481
bool m_forceMagnifier
Definition: CPImageCtrl.h:541
double scaleFactor
Definition: CPImageCtrl.h:517
double scale(double x) const
Definition: CPImageCtrl.h:339
bool m_showLines
Definition: CPImageCtrl.h:483
wxBitmap m_magImg
Definition: CPImageCtrl.h:480
helper class to display and manipulate cp in cp tab
Definition: CPImageCtrl.h:111
brief description.
Definition: CPImageCtrl.h:186
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
EditorState
state machine for selection process:
Definition: CPImageCtrl.h:237
unsigned int getPointNr()
Definition: CPImageCtrl.h:78
represents a control point
Definition: ControlPoint.h:38
wxCursor * m_CPSelectCursor
Definition: CPImageCtrl.h:487
void mousePressRMBEvent(wxMouseEvent &mouse)
wxPoint m_mouseScrollPos
Definition: CPImageCtrl.h:524
void mouseMoveEvent(wxMouseEvent &mouse)
void DrawLineSegment(wxDC &dc)
draw line control point over different images
ImageCache::EntryPtr m_img
Definition: CPImageCtrl.h:537
const wxSize GetRealImageSize() const
return the real size of the image in the control
Definition: CPImageCtrl.h:438
bool m_mirrored
is first or second image in cp used
Definition: CPImageCtrl.h:166
void OnImageLoaded(ImageCache::EntryPtr entry, std::string filename, bool load_small)
~CPImageCtrl()
dtor.
HuginBase::ImageCache::ImageCacheRGB8Ptr GetImg()
get pointer to image, for DisplayedControlPoint
void SetControl(CPImageCtrl *control)
remember the control, where the information should be drawn
void UpdateControlPointY(double y)
update y coordinate of selected cp coordinate
const bool isOccupiedLabel(const wxPoint mousePos) const
check if given point is over label of cp, using screen coordinates
const bool GetMouseInWindow() const
Definition: CPImageCtrl.h:431
void mouseReleaseLMBEvent(wxMouseEvent &mouse)
std::vector< DisplayedControlPoint > m_points
Definition: CPImageCtrl.h:485
void clearNewPoint()
clear new point
std::string imageFilename
Definition: CPImageCtrl.h:472
void OnMouseLeave(wxMouseEvent &e)
double getScale()
return scale factor, 0 for autoscale
Definition: CPImageCtrl.h:306
bool m_showTemplateArea
Definition: CPImageCtrl.h:526
wxCursor * m_ScrollCursor
Definition: CPImageCtrl.h:488
CPImageCtrl * m_control
pointer to control to access some functions
Definition: CPImageCtrl.h:168
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 ...
virtual void OnDraw(wxDC &dc)
void Init(CPEditorPanel *parent)
void clearCtrlPointList()
clear internal control point list
HuginBase::PTools::Transform * m_firstInvTrans
Definition: CPImageCtrl.h:508
wxPoint scale(const wxPoint &p) const
Definition: CPImageCtrl.h:350
std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
use reference counted pointers
Definition: ImageCache.h:57
std::vector< wxColour > pointColors
Definition: CPImageCtrl.h:515
virtual wxObject * DoCreateResource()
void ShiftControlPoint(hugin_utils::FDiff2D shift)
shift selected cp coordinate by given
HuginBase::PTools::Transform * getSecondInvTrans() const
Definition: CPImageCtrl.h:268
void rescaleImage()
T applyRot(const T &p) const
Definition: CPImageCtrl.h:388
void showTemplateArea(bool show=true)
wxPoint MaxScrollDelta(wxPoint delta)
calculate maximum delta that is allowed when scrolling
void OnMouseEnter(wxMouseEvent &e)
hugin_utils::FDiff2D scale(const hugin_utils::FDiff2D &p) const
Definition: CPImageCtrl.h:342
wxRect m_labelPos
position of the point labels (in screen coordinates)
Definition: CPImageCtrl.h:176
hugin_utils::FDiff2D rectStartPos
Definition: CPImageCtrl.h:501
void update()
initiate redraw
const wxString GetLabel() const
return label
Definition: CPImageCtrl.h:137
const hugin_utils::FDiff2D & getPoint()
Definition: CPImageCtrl.h:75
wxRect region
Definition: CPImageCtrl.h:85
wxTimer m_timer
Definition: CPImageCtrl.h:542
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxT("panel"))
void mouseReleaseRMBEvent(wxMouseEvent &mouse)
T applyRotInv(const T &p) const
Definition: CPImageCtrl.h:412
#define shift
void setTransforms(HuginBase::PTools::Transform *firstTrans, HuginBase::PTools::Transform *firstInvTrans, HuginBase::PTools::Transform *secondInvTrans)
void showSearchArea(bool show=true)
show/hide the search area rectangle
const wxSize GetBitmapSize() const
return the size of the drawn bitmap (possible rotate is applied)
wxSize m_realSize
Definition: CPImageCtrl.h:476
const HuginBase::ControlPoint GetControlPoint() const
returns the control point
Definition: CPImageCtrl.h:151
wxColour m_textColour
colour of the text background
Definition: CPImageCtrl.h:172
HuginBase::PTools::Transform * m_magTrans
Definition: CPImageCtrl.h:511
bool m_mouseInWindow
Definition: CPImageCtrl.h:540
HuginBase::ControlPoint m_cp
Definition: CPImageCtrl.h:87
void OnKey(wxKeyEvent &e)
hugin_utils::FDiff2D getNewPoint()
get the new point
void OnSize(wxSizeEvent &e)
CPImageCtrl()
ctor.
Definition: CPImageCtrl.h:241
HuginBase::PTools::Transform * m_magInvTrans
Definition: CPImageCtrl.h:512
void DrawLine(wxDC &dc)
draw line control point on same image
std::vector< wxColour > textColours
Definition: CPImageCtrl.h:516
HuginBase::PTools::Transform * m_secondInvTrans
Definition: CPImageCtrl.h:509
void(wxEvtHandler::* CPEventFunction)(CPEvent &)
Definition: CPImageCtrl.h:91
virtual bool CanHandle(wxXmlNode *node)
bool fitToWindow
Definition: CPImageCtrl.h:518
void StartLineControlPoint(hugin_utils::FDiff2D newPoint)
starts a new line control point with given coodinates
Holds transformations for Image -&gt; Pano and the other way.
bool IsDrawingLine() const
return true, if line cp should be drawn as separate line
bool emit(CPEvent &ev)
helper func to emit a region
HuginBase::ControlPoint m_cp
representation of underlying control point
Definition: CPImageCtrl.h:164
void setCtrlPoint(const HuginBase::ControlPoint &cp, const bool mirrored)
add control piont to internal cp list
wxRect DrawTextMag(wxDC &dc, wxPoint p, hugin_utils::FDiff2D pointInput, bool drawMag, wxColour pointColour, wxColour textColour)
draw magnified area
const bool isOccupiedPos(const hugin_utils::FDiff2D &p) const
check if the given point is over the drawn cp, using image coordinates
hugin_utils::FDiff2D newPoint
Definition: CPImageCtrl.h:494
void mousePressMMBEvent(wxMouseEvent &mouse)
void setScale(double factor)
set the scaling factor for cp display.
EditorState editState
Definition: CPImageCtrl.h:505
const HuginBase::ControlPoint & getControlPoint()
Definition: CPImageCtrl.h:81
void OnTimer(wxTimerEvent &e)
void setImage(const std::string &filename, ImageRotation rot)
display img.
#define EVT_CPEVENT(func)
Definition: CPImageCtrl.h:101
void setMagTransforms(HuginBase::PTools::Transform *magTrans, HuginBase::PTools::Transform *magInvTrans)
DisplayedControlPoint m_selectedPoint
Definition: CPImageCtrl.h:493
void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false)
Show point x, y.
CPEditorPanel * m_editPanel
Definition: CPImageCtrl.h:533
wxOverlay m_overlay
Definition: CPImageCtrl.h:478
const wxRect & getRect()
Definition: CPImageCtrl.h:72
void setSameImage(bool sameImage)
void OnScrollWin(wxScrollWinEvent &e)
bool m_line
true, if line control point on same image
Definition: CPImageCtrl.h:179
hugin_utils::FDiff2D point
Definition: CPImageCtrl.h:86
HuginBase::PTools::Transform * getFirstTrans() const
Definition: CPImageCtrl.h:266
wxPoint roundP(const hugin_utils::FDiff2D &p) const
Definition: CPImageCtrl.h:380
void UpdateControlPoint(hugin_utils::FDiff2D newPoint)
update selected cp coordinate
void UpdateControlPointX(double x)
update x coordinate of selected cp coordinate
void mouseReleaseMMBEvent(wxMouseEvent &mouse)
bool m_showSearchArea
Definition: CPImageCtrl.h:520
bool IsShowingLines() const
ImageRotation
image rotation.
Definition: CPImageCtrl.h:258
wxString m_label
label of displayed control point: number or new
Definition: CPImageCtrl.h:174
unsigned int selectedPointNr
Definition: CPImageCtrl.h:491
hugin_utils::FDiff2D m_mousePos
Definition: CPImageCtrl.h:523
void ShowLines(bool isShown)
double invScale(double x) const
Definition: CPImageCtrl.h:361
HuginBase::PTools::Transform * m_firstTrans
Definition: CPImageCtrl.h:507
void SetLabel(wxString newLabel)
set label to given wxString