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 = "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 ScrollDelta(const wxPoint & delta);
312 
314  wxPoint MaxScrollDelta(wxPoint delta);
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 
360  wxPoint roundP(const hugin_utils::FDiff2D & p) const
361  {
362  return wxPoint(hugin_utils::roundi(p.x), hugin_utils::roundi(p.y));
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; };
416  wxBitmap& GetMagBitmap(hugin_utils::FDiff2D point);
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;
425 protected:
426  // display the image when loading finishes
427  void OnImageLoaded(ImageCache::EntryPtr entry, std::string filename, bool load_small);
428  void OnSize(wxSizeEvent & e);
429  void OnKey(wxKeyEvent & e);
430  void OnKeyDown(wxKeyEvent & e);
431  void OnMouseLeave(wxMouseEvent & e);
432  void OnMouseEnter(wxMouseEvent & e);
433  void OnTimer(wxTimerEvent & e);
434  void OnScrollWin(wxScrollWinEvent & e);
436  void OnPaint(wxPaintEvent& e);
437 
439  bool emit(CPEvent & ev);
440 
442  double getScaleFactor() const;
443 
445  double calcAutoScaleFactor(wxSize size);
446 
447  // rescale image
448  void rescaleImage();
449 
450 private:
451  wxBitmap bitmap;
452  std::string imageFilename;
453  // size of displayed (probably scaled) image
454  wxSize imageSize;
455  // size of real image
456  wxSize m_realSize;
457  // for drawing overlay
458  wxOverlay m_overlay;
459  // cache mag image
460  wxBitmap m_magImg;
462  // should line cp shown as line
463  bool m_showLines { true };
464 
465  std::vector<DisplayedControlPoint> m_points;
466 
467  wxCursor * m_CPSelectCursor;
468  wxCursor * m_ScrollCursor;
469 
470  // this is only valid during MOVE_POINT
471  unsigned int selectedPointNr;
472  // valid during MOVE_POINT and CREATE_POINT
479 
480  // only valid during SELECT_DELETE_REGION
482  // draw a selection rectangle from pos1 to pos2
484 
486  // store pointer to transformation object to draw line control points
490  // store pointer to transformation for drawing the magnifier
493 
494  // colors for the different points
495  std::vector<wxColour> pointColors;
496  std::vector<wxColour> textColours;
497  double scaleFactor;
499 
502 
505 
508 
511  EditorState isOccupied(wxPoint mousePos, const hugin_utils::FDiff2D & point, unsigned int & pointNr) const;
512 
514 
516 
517  ImageCache::EntryPtr m_img;
518  ImageCache::RequestPtr m_imgRequest;
519 
522  wxTimer m_timer;
523 
524  DECLARE_DYNAMIC_CLASS(CPImageCtrl)
525 };
526 
528 class CPImageCtrlXmlHandler : public wxXmlResourceHandler
529 {
530  DECLARE_DYNAMIC_CLASS(CPImageCtrlXmlHandler)
531 
532 public:
534  virtual wxObject *DoCreateResource();
535  virtual bool CanHandle(wxXmlNode *node);
536 };
537 
538 
539 #endif // _CPIMAGECTRL_H
int pointNr
Definition: CPImageCtrl.h:88
int m_templateRectWidth
Definition: CPImageCtrl.h:507
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:352
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:344
DisplayedControlPoint()
default constructor
Definition: CPImageCtrl.h:98
int scale(int x) const
Definition: CPImageCtrl.h:316
wxSize DoGetBestSize() const
int m_searchRectWidth
Definition: CPImageCtrl.h:501
int invScale(int x) const
Definition: CPImageCtrl.h:338
wxSize imageSize
Definition: CPImageCtrl.h:454
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:515
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:518
const bool GetForceMagnifier() const
Definition: CPImageCtrl.h:412
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:451
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:478
void DrawSelectionRectangle(hugin_utils::FDiff2D pos1, hugin_utils::FDiff2D pos2)
hugin_utils::FDiff2D m_magImgCenter
Definition: CPImageCtrl.h:461
bool m_forceMagnifier
Definition: CPImageCtrl.h:521
double scaleFactor
Definition: CPImageCtrl.h:497
double scale(double x) const
Definition: CPImageCtrl.h:319
bool m_showLines
Definition: CPImageCtrl.h:463
wxBitmap m_magImg
Definition: CPImageCtrl.h:460
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:467
void mousePressRMBEvent(wxMouseEvent &mouse)
wxPoint m_mouseScrollPos
Definition: CPImageCtrl.h:504
void mouseMoveEvent(wxMouseEvent &mouse)
void DrawLineSegment(wxDC &dc)
draw line control point over different images
ImageCache::EntryPtr m_img
Definition: CPImageCtrl.h:517
const wxSize GetRealImageSize() const
return the real size of the image in the control
Definition: CPImageCtrl.h:418
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:411
void mouseReleaseLMBEvent(wxMouseEvent &mouse)
std::vector< DisplayedControlPoint > m_points
Definition: CPImageCtrl.h:465
void clearNewPoint()
clear new point
std::string imageFilename
Definition: CPImageCtrl.h:452
void OnMouseLeave(wxMouseEvent &e)
double getScale()
return scale factor, 0 for autoscale
Definition: CPImageCtrl.h:289
bool m_showTemplateArea
Definition: CPImageCtrl.h:506
wxCursor * m_ScrollCursor
Definition: CPImageCtrl.h:468
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 ...
void Init(CPEditorPanel *parent)
void clearCtrlPointList()
clear internal control point list
HuginBase::PTools::Transform * m_firstInvTrans
Definition: CPImageCtrl.h:488
wxPoint scale(const wxPoint &p) const
Definition: CPImageCtrl.h:330
std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
use reference counted pointers
Definition: ImageCache.h:57
std::vector< wxColour > pointColors
Definition: CPImageCtrl.h:495
virtual wxObject * DoCreateResource()
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
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:368
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:322
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:481
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:522
void mouseReleaseRMBEvent(wxMouseEvent &mouse)
T applyRotInv(const T &p) const
Definition: CPImageCtrl.h:392
#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:456
const HuginBase::ControlPoint GetControlPoint() const
returns the control point
Definition: CPImageCtrl.h:134
void OnPaint(wxPaintEvent &e)
paint event
wxColour m_textColour
colour of the text background
Definition: CPImageCtrl.h:155
HuginBase::PTools::Transform * m_magTrans
Definition: CPImageCtrl.h:491
bool m_mouseInWindow
Definition: CPImageCtrl.h:520
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:492
void DrawLine(wxDC &dc)
draw line control point on same image
std::vector< wxColour > textColours
Definition: CPImageCtrl.h:496
HuginBase::PTools::Transform * m_secondInvTrans
Definition: CPImageCtrl.h:489
virtual bool CanHandle(wxXmlNode *node)
bool fitToWindow
Definition: CPImageCtrl.h:498
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:474
void mousePressMMBEvent(wxMouseEvent &mouse)
void setScale(double factor)
set the scaling factor for cp display.
EditorState editState
Definition: CPImageCtrl.h:485
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:473
void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false)
Show point x, y.
CPEditorPanel * m_editPanel
Definition: CPImageCtrl.h:513
wxOverlay m_overlay
Definition: CPImageCtrl.h:458
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:360
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:500
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:471
hugin_utils::FDiff2D m_mousePos
Definition: CPImageCtrl.h:503
void ShowLines(bool isShown)
double invScale(double x) const
Definition: CPImageCtrl.h:341
HuginBase::PTools::Transform * m_firstTrans
Definition: CPImageCtrl.h:487
void SetLabel(wxString newLabel)
set label to given wxString