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 wxDECLARE_EVENT(EVT_CPEVENT, CPEvent);
92 
95 {
96 public:
98  DisplayedControlPoint() { m_mirrored=false; m_control=NULL; m_line=false; };
100  DisplayedControlPoint(const HuginBase::ControlPoint& cp, CPImageCtrl* control, bool mirrored);
102  void SetColour(wxColour pointColour, wxColour textColour);
104  void SetLabel(wxString newLabel);
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;
116  void CheckSelection(const wxPoint mousePos, const hugin_utils::FDiff2D& p);
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);
134  const HuginBase::ControlPoint GetControlPoint() const { return m_cp; };
136  bool operator==(const DisplayedControlPoint other);
137 private:
139  wxRect DrawTextMag(wxDC& dc, wxPoint p, hugin_utils::FDiff2D pointInput, bool drawMag, wxColour pointColour, wxColour textColour);
141  void DrawLine(wxDC& dc);
143  void DrawLineSegment(wxDC& dc);
145  bool IsDrawingLine() const;
153  wxColour m_pointColour;
155  wxColour m_textColour;
157  wxString m_label;
159  wxRect m_labelPos;
160  wxRect m_labelPos2;
162  bool m_line;
163 };
164 
169 class CPImageCtrl : public wxScrolledWindow
170 {
171 public:
221 
225  : scaleFactor(1),fitToWindow(false)
226  { }
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 = wxT("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 
270  void mousePressLMBEvent(wxMouseEvent& mouse);
271  void mouseReleaseLMBEvent(wxMouseEvent& mouse);
272  void mousePressRMBEvent(wxMouseEvent& mouse);
273  void mouseReleaseRMBEvent(wxMouseEvent& mouse);
274  void mouseMoveEvent(wxMouseEvent& mouse);
275  void mousePressMMBEvent(wxMouseEvent& mouse);
276  void mouseReleaseMMBEvent(wxMouseEvent& mouse);
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 update();
312 
314  void ScrollDelta(const wxPoint & delta);
315 
317  wxPoint MaxScrollDelta(wxPoint delta);
318 
319  int scale(int x) const
320  { return (int) (x * getScaleFactor() + 0.5); }
321 
322  double scale(double x) const
323  { return x * getScaleFactor(); }
324 
326  {
328  r.x = scale(p.x);
329  r.y = scale(p.y);
330  return r;
331  }
332 
333  wxPoint scale(const wxPoint & p) const
334  {
335  wxPoint r;
336  r.x = scale(p.x);
337  r.y = scale(p.y);
338  return r;
339  }
340 
341  int invScale(int x) const
342  { return (int) (x / getScaleFactor() + 0.5); }
343 
344  double invScale(double x) const
345  { return x / getScaleFactor(); }
346 
348  {
350  r.x = invScale(p.x);
351  r.y = invScale(p.y);
352  return r;
353  }
354 
355  wxPoint invScale(const wxPoint & p) const
356  {
357  wxPoint r;
358  r.x = invScale(p.x);
359  r.y = invScale(p.y);
360  return r;
361  }
362 
363  wxPoint roundP(const hugin_utils::FDiff2D & p) const
364  {
365  return wxPoint(hugin_utils::roundi(p.x), hugin_utils::roundi(p.y));
366  }
367 
368  // rotate coordinate to fit possibly rotated image display
369  // useful for drawing something on the rotated display
370  template <class T>
371  T applyRot(const T & p) const
372  {
373  switch (m_imgRotation) {
374  case ROT0:
375  return p;
376  break;
377  case ROT90:
378  return T(m_realSize.GetHeight()-1 - p.y, p.x);
379  break;
380  case ROT180:
381  return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
382  break;
383  case ROT270:
384  return T(p.y, m_realSize.GetWidth()-1 - p.x);
385  break;
386  default:
387  return p;
388  break;
389  }
390  }
391 
392  // rotate coordinate to fit possibly rotated image display
393  // useful for converting rotated display coordinates to image coordinates
394  template <class T>
395  T applyRotInv(const T & p) const
396  {
397  switch (m_imgRotation) {
398  case ROT90:
399  return T(p.y, m_realSize.GetHeight()-1 - p.x);
400  break;
401  case ROT180:
402  return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
403  break;
404  case ROT270:
405  return T(m_realSize.GetWidth()-1 - p.y, p.x);
406  break;
407  case ROT0:
408  default:
409  return p;
410  break;
411  }
412  }
413  // some helper function for DisplayedControlPoint
414  const bool GetMouseInWindow() const { return m_mouseInWindow; };
415  const bool GetForceMagnifier() const { return m_forceMagnifier; };
419  wxBitmap& GetMagBitmap(hugin_utils::FDiff2D point);
421  const wxSize GetRealImageSize() const { return m_realSize; };
423  const wxSize GetBitmapSize() const;
424 
425  virtual void OnDraw(wxDC& dc);
426 
427  // setting/getting option if line cp should be shown as separate line
428  void ShowLines(bool isShown);
429  bool IsShowingLines() const;
430 protected:
431  // display the image when loading finishes
432  void OnImageLoaded(ImageCache::EntryPtr entry, std::string filename, bool load_small);
433  void OnSize(wxSizeEvent & e);
434  void OnKey(wxKeyEvent & e);
435  void OnKeyDown(wxKeyEvent & e);
436  void OnMouseLeave(wxMouseEvent & e);
437  void OnMouseEnter(wxMouseEvent & e);
438  void OnTimer(wxTimerEvent & e);
439  void OnScrollWin(wxScrollWinEvent & e);
440 
442  bool emit(CPEvent & ev);
443 
445  double getScaleFactor() const;
446 
448  double calcAutoScaleFactor(wxSize size);
449 
450  // rescale image
451  void rescaleImage();
452 
453 private:
454  wxBitmap bitmap;
455  std::string imageFilename;
456  // size of displayed (probably scaled) image
457  wxSize imageSize;
458  // size of real image
459  wxSize m_realSize;
460  // for drawing overlay
461  wxOverlay m_overlay;
462  // cache mag image
463  wxBitmap m_magImg;
465  // should line cp shown as line
466  bool m_showLines { true };
467 
468  std::vector<DisplayedControlPoint> m_points;
469 
470  wxCursor * m_CPSelectCursor;
471  wxCursor * m_ScrollCursor;
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;
500  double scaleFactor;
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  DECLARE_DYNAMIC_CLASS(CPImageCtrl)
529 };
530 
532 class CPImageCtrlXmlHandler : public wxXmlResourceHandler
533 {
534  DECLARE_DYNAMIC_CLASS(CPImageCtrlXmlHandler)
535 
536 public:
538  virtual wxObject *DoCreateResource();
539  virtual bool CanHandle(wxXmlNode *node);
540 };
541 
542 
543 #endif // _CPIMAGECTRL_H
int pointNr
Definition: CPImageCtrl.h:88
int m_templateRectWidth
Definition: CPImageCtrl.h:510
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:355
double calcAutoScaleFactor(wxSize size)
calculate new scale factor for this image
wxColour m_pointColour
colour of the point
Definition: CPImageCtrl.h:153
HuginBase::PTools::Transform * getFirstInvTrans() const
Definition: CPImageCtrl.h:250
hugin_utils::FDiff2D invScale(const hugin_utils::FDiff2D &p) const
Definition: CPImageCtrl.h:347
DisplayedControlPoint()
default constructor
Definition: CPImageCtrl.h:98
int scale(int x) const
Definition: CPImageCtrl.h:319
wxSize DoGetBestSize() const
int m_searchRectWidth
Definition: CPImageCtrl.h:504
int invScale(int x) const
Definition: CPImageCtrl.h:341
wxSize imageSize
Definition: CPImageCtrl.h:457
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:518
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:521
const bool GetForceMagnifier() const
Definition: CPImageCtrl.h:415
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:118
virtual wxEvent * Clone() const
wxBitmap bitmap
Definition: CPImageCtrl.h:454
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:481
void DrawSelectionRectangle(hugin_utils::FDiff2D pos1, hugin_utils::FDiff2D pos2)
hugin_utils::FDiff2D m_magImgCenter
Definition: CPImageCtrl.h:464
bool m_forceMagnifier
Definition: CPImageCtrl.h:524
double scaleFactor
Definition: CPImageCtrl.h:500
double scale(double x) const
Definition: CPImageCtrl.h:322
bool m_showLines
Definition: CPImageCtrl.h:466
wxBitmap m_magImg
Definition: CPImageCtrl.h:463
helper class to display and manipulate cp in cp tab
Definition: CPImageCtrl.h:94
brief description.
Definition: CPImageCtrl.h:169
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:220
unsigned int getPointNr()
Definition: CPImageCtrl.h:78
represents a control point
Definition: ControlPoint.h:38
wxCursor * m_CPSelectCursor
Definition: CPImageCtrl.h:470
void mousePressRMBEvent(wxMouseEvent &mouse)
wxPoint m_mouseScrollPos
Definition: CPImageCtrl.h:507
void mouseMoveEvent(wxMouseEvent &mouse)
void DrawLineSegment(wxDC &dc)
draw line control point over different images
ImageCache::EntryPtr m_img
Definition: CPImageCtrl.h:520
const wxSize GetRealImageSize() const
return the real size of the image in the control
Definition: CPImageCtrl.h:421
bool m_mirrored
is first or second image in cp used
Definition: CPImageCtrl.h:149
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:414
void mouseReleaseLMBEvent(wxMouseEvent &mouse)
std::vector< DisplayedControlPoint > m_points
Definition: CPImageCtrl.h:468
void clearNewPoint()
clear new point
std::string imageFilename
Definition: CPImageCtrl.h:455
void OnMouseLeave(wxMouseEvent &e)
double getScale()
return scale factor, 0 for autoscale
Definition: CPImageCtrl.h:289
bool m_showTemplateArea
Definition: CPImageCtrl.h:509
wxCursor * m_ScrollCursor
Definition: CPImageCtrl.h:471
CPImageCtrl * m_control
pointer to control to access some functions
Definition: CPImageCtrl.h:151
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:491
wxPoint scale(const wxPoint &p) const
Definition: CPImageCtrl.h:333
std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
use reference counted pointers
Definition: ImageCache.h:57
std::vector< wxColour > pointColors
Definition: CPImageCtrl.h:498
virtual wxObject * DoCreateResource()
void ShiftControlPoint(hugin_utils::FDiff2D shift)
shift selected cp coordinate by given
HuginBase::PTools::Transform * getSecondInvTrans() const
Definition: CPImageCtrl.h:251
void rescaleImage()
T applyRot(const T &p) const
Definition: CPImageCtrl.h:371
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:325
wxRect m_labelPos
position of the point labels (in screen coordinates)
Definition: CPImageCtrl.h:159
wxDECLARE_EVENT(wxEVT_COMMAND_THUMBNAILTHREAD_UPDATE, wxCommandEvent)
hugin_utils::FDiff2D rectStartPos
Definition: CPImageCtrl.h:484
void update()
initiate redraw
const wxString GetLabel() const
return label
Definition: CPImageCtrl.h:120
const hugin_utils::FDiff2D & getPoint()
Definition: CPImageCtrl.h:75
wxRect region
Definition: CPImageCtrl.h:85
wxTimer m_timer
Definition: CPImageCtrl.h:525
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:395
#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:459
const HuginBase::ControlPoint GetControlPoint() const
returns the control point
Definition: CPImageCtrl.h:134
wxColour m_textColour
colour of the text background
Definition: CPImageCtrl.h:155
HuginBase::PTools::Transform * m_magTrans
Definition: CPImageCtrl.h:494
bool m_mouseInWindow
Definition: CPImageCtrl.h:523
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:224
HuginBase::PTools::Transform * m_magInvTrans
Definition: CPImageCtrl.h:495
void DrawLine(wxDC &dc)
draw line control point on same image
std::vector< wxColour > textColours
Definition: CPImageCtrl.h:499
HuginBase::PTools::Transform * m_secondInvTrans
Definition: CPImageCtrl.h:492
virtual bool CanHandle(wxXmlNode *node)
bool fitToWindow
Definition: CPImageCtrl.h:501
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:147
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:477
void mousePressMMBEvent(wxMouseEvent &mouse)
void setScale(double factor)
set the scaling factor for cp display.
EditorState editState
Definition: CPImageCtrl.h:488
const HuginBase::ControlPoint & getControlPoint()
Definition: CPImageCtrl.h:81
void OnTimer(wxTimerEvent &e)
void setImage(const std::string &filename, ImageRotation rot)
display img.
void setMagTransforms(HuginBase::PTools::Transform *magTrans, HuginBase::PTools::Transform *magInvTrans)
DisplayedControlPoint m_selectedPoint
Definition: CPImageCtrl.h:476
void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false)
Show point x, y.
CPEditorPanel * m_editPanel
Definition: CPImageCtrl.h:516
wxOverlay m_overlay
Definition: CPImageCtrl.h:461
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:162
hugin_utils::FDiff2D point
Definition: CPImageCtrl.h:86
HuginBase::PTools::Transform * getFirstTrans() const
Definition: CPImageCtrl.h:249
wxPoint roundP(const hugin_utils::FDiff2D &p) const
Definition: CPImageCtrl.h:363
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:503
bool IsShowingLines() const
ImageRotation
image rotation.
Definition: CPImageCtrl.h:241
wxString m_label
label of displayed control point: number or new
Definition: CPImageCtrl.h:157
unsigned int selectedPointNr
Definition: CPImageCtrl.h:474
hugin_utils::FDiff2D m_mousePos
Definition: CPImageCtrl.h:506
void ShowLines(bool isShown)
double invScale(double x) const
Definition: CPImageCtrl.h:344
HuginBase::PTools::Transform * m_firstTrans
Definition: CPImageCtrl.h:490
void SetLabel(wxString newLabel)
set label to given wxString