Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
PerspectiveImageCtrl Class Reference

image previewer for perspective correction More...

#include <PerspectiveImageCtrl.h>

Inheritance diagram for PerspectiveImageCtrl:
Inheritance graph

Classes

class  Line
 

Public Types

enum  ImageRotation { ROT0 = 0, ROT90, ROT180, ROT270 }
 image rotation. More...
 

Public Member Functions

bool Create (wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
 creates the control More...
 
void setOriginalMode ()
 if called, the mouse handlers are deactivated More...
 
bool IsOriginalShown () const
 
void setImage (const std::string &filename, ImageRotation rot)
 set the current image and mask list, this loads also the image from cache More...
 
void ChangeRotation (ImageRotation newRot)
 
void OnMouseMove (wxMouseEvent &mouse)
 event handler when mouse is moving More...
 
void OnLeftMouseDown (wxMouseEvent &mouse)
 event handler when left mouse button is pressed More...
 
void OnLeftMouseUp (wxMouseEvent &mouse)
 event handler when right mouse button is released More...
 
void OnRightMouseUp (wxMouseEvent &mouse)
 event handler when right mouse button is released More...
 
void OnMiddleMouseDown (wxMouseEvent &mouse)
 event handler for middle mouse button, start scrolling More...
 
void OnMiddleMouseUp (wxMouseEvent &mouse)
 event handler for middle mouse button, end scrolling More...
 
void OnCaptureLost (wxMouseCaptureLostEvent &e)
 event handler, when mouse capture is lost, e.g. More...
 
void OnKillFocus (wxFocusEvent &e)
 event handler, when editor lost focus, mainly cancels creating new polygon More...
 
void setScale (double factor)
 set the scaling factor for mask editing display. More...
 
double getScale () const
 return scale factor, 0 for autoscale More...
 
ImageRotation getCurrentRotation ()
 returns the current rotation of displayed image More...
 
void update ()
 initiate redraw More...
 
void SetLineColour (wxColour newColour)
 sets the colour for the lines More...
 
virtual void OnDraw (wxDC &dc) wxOVERRIDE
 drawing routine More...
 
void SetRectMode (bool newMode)
 set line or rect mode More...
 
HuginBase::CPVector GetControlPoints (const unsigned int index)
 return list of control points More...
 
void SetRemappedMode (const HuginBase::Panorama &pano)
 set the panorama object for remapping More...
 
ImageCache::EntryPtr getCachedImage ()
 return pointer to ImageCache More...
 
void AddLines (const HuginBase::CPVector &lines)
 add the lines to the list More...
 

Protected Member Functions

void OnSize (wxSizeEvent &e)
 handler called when size of control was changed More...
 
double getScaleFactor () const
 get scale factor (calculates factor when fit to window is active) More...
 
double calcAutoScaleFactor (wxSize size)
 calculate new scale factor for this image More...
 
void rescaleImage ()
 rescale the image More...
 

Private Types

enum  PerspectiveEditorState {
  NO_IMAGE = 0, SHOW_IMAGE, POINT_MOVING, SEGMENT_MOVING,
  RECT_MOVING, LINE_CREATE, LINE_POINT_MOVING, LINE_MOVING
}
 different states of the editor More...
 

Private Member Functions

HuginBase::ControlPoint GetCP (const unsigned int index, const hugin_utils::FDiff2D &p1, const hugin_utils::FDiff2D &p2)
 return the HuginBase::ControlPoint, using index as image index, p1 and p2 as position, take image rotation into account to decide if control point is horizontal or vertical More...
 
void ClipPos (hugin_utils::FDiff2D &pos)
 clip the given pos to image size + offset More...
 
int GetNearestRectanglePoint (const hugin_utils::FDiff2D &p)
 return index of nearest rectangle point or -1 if the point is too far from rectangle More...
 
int GetNearestRectangleLine (const hugin_utils::FDiff2D &p)
 return index of nearest rectangle line or -1 if the point is too far from the rectangle lines More...
 
bool IsInsideRect (const hugin_utils::FDiff2D &p)
 return true, if the point p is inside the rect More...
 
int GetNearestLinePoint (const hugin_utils::FDiff2D &p, bool &isStart)
 return index of nearest line or -1 if the point to far from line More...
 
int GetNearestLine (const hugin_utils::FDiff2D &p)
 return index of nearest line or -1 if the point is too far from all lines More...
 
void GenerateRemappedImage (const unsigned int newWidth, const unsigned int newHeight)
 generates the remapped image suitable for wxBitmap More...
 
void DrawRect (wxDC &dc, const std::vector< hugin_utils::FDiff2D > &rect)
 
void DrawLines (wxDC &dc, const std::vector< Line > &lines)
 
int scale (int x) const
 helper function for scale, offset and rotation More...
 
double scale (double x) const
 
int transform (int x) const
 convert image coordinate to screen coordinates, considers additional added border More...
 
double transform (double x) const
 
wxPoint transform (const hugin_utils::FDiff2D &p) const
 
int invtransform (int x) const
 translate screen coordinates to image coordinates, considers additional added border More...
 
double invtransform (double x) const
 
hugin_utils::FDiff2D invtransform (const wxPoint &p) const
 
template<class T >
applyRot (const T &p) const
 
template<class T >
applyRotInv (const T &p) const
 

Private Attributes

wxBitmap m_bitmap
 
wxBitmap m_remappedImg
 the remapped image as wxBitmap More...
 
std::string m_imageFilename
 
ImageRotation m_imgRotation { ROT0 }
 
wxSize m_imageSize
 
wxSize m_realSize
 
PerspectiveEditorState m_editorState { NO_IMAGE }
 
double m_scaleFactor { 1.0 }
 
bool m_fitToWindow { false }
 
bool m_showRemappedImage { false }
 
bool m_showRect { true }
 
ImageCache::EntryPtr m_img
 image cache entry for current image More...
 
HuginBase::Panorama m_pano
 HuginBase::Panorama object for calculation of remapped image. More...
 
wxPoint m_dragStartPos
 
wxPoint m_currentPos
 
int m_movingPoint { -1 }
 
bool m_middleMouseScroll { false }
 
wxPoint m_scrollPos
 
wxColor m_colour_selected
 
std::vector< hugin_utils::FDiff2Dm_rectPoints
 
std::vector< hugin_utils::FDiff2Dm_rectPointsStartDrag
 
std::vector< Linem_lines
 
std::vector< Linem_currentLine
 
Line m_lineStartDrag
 

Detailed Description

image previewer for perspective correction

Definition at line 43 of file PerspectiveImageCtrl.h.

Member Enumeration Documentation

image rotation.

Useful to display images depending on their roll setting. rotation is clockwise

Enumerator
ROT0 
ROT90 
ROT180 
ROT270 

Definition at line 74 of file PerspectiveImageCtrl.h.

different states of the editor

Enumerator
NO_IMAGE 
SHOW_IMAGE 
POINT_MOVING 
SEGMENT_MOVING 
RECT_MOVING 
LINE_CREATE 
LINE_POINT_MOVING 
LINE_MOVING 

Definition at line 267 of file PerspectiveImageCtrl.h.

Member Function Documentation

void PerspectiveImageCtrl::AddLines ( const HuginBase::CPVector lines)

add the lines to the list

Definition at line 616 of file PerspectiveImageCtrl.cpp.

References m_lines, and update().

Referenced by PerspectivePanel::OnFindLines().

template<class T >
T PerspectiveImageCtrl::applyRot ( const T &  p) const
inlineprivate

Definition at line 224 of file PerspectiveImageCtrl.h.

References m_imgRotation, m_realSize, ROT0, ROT180, ROT270, and ROT90.

Referenced by DrawLines(), and DrawRect().

template<class T >
T PerspectiveImageCtrl::applyRotInv ( const T &  p) const
inlineprivate
double PerspectiveImageCtrl::calcAutoScaleFactor ( wxSize  size)
protected

calculate new scale factor for this image

Definition at line 915 of file PerspectiveImageCtrl.cpp.

References DEBUG_DEBUG, vigra_ext::EMoR::h, m_imgRotation, ROT270, and ROT90.

Referenced by rescaleImage(), and setScale().

void PerspectiveImageCtrl::ChangeRotation ( ImageRotation  newRot)

Definition at line 110 of file PerspectiveImageCtrl.cpp.

References m_imgRotation, rescaleImage(), and update().

Referenced by PerspectivePanel::OnRotationChanged().

void PerspectiveImageCtrl::ClipPos ( hugin_utils::FDiff2D pos)
private

clip the given pos to image size + offset

Definition at line 276 of file PerspectiveImageCtrl.cpp.

References m_realSize, PerspectiveOffset, hugin_utils::TDiff2D< T >::x, and hugin_utils::TDiff2D< T >::y.

Referenced by OnLeftMouseUp(), and OnMouseMove().

bool PerspectiveImageCtrl::Create ( wxWindow *  parent,
wxWindowID  id = wxID_ANY,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxTAB_TRAVERSAL,
const wxString &  name = "panel" 
)
void PerspectiveImageCtrl::DrawLines ( wxDC &  dc,
const std::vector< Line > &  lines 
)
private

Definition at line 494 of file PerspectiveImageCtrl.cpp.

References applyRot(), m_colour_selected, polygonPointSize, and transform().

Referenced by OnDraw().

void PerspectiveImageCtrl::DrawRect ( wxDC &  dc,
const std::vector< hugin_utils::FDiff2D > &  rect 
)
private

Definition at line 471 of file PerspectiveImageCtrl.cpp.

References applyRot(), m_colour_selected, polygonPointSize, and transform().

Referenced by OnDraw().

void PerspectiveImageCtrl::GenerateRemappedImage ( const unsigned int  newWidth,
const unsigned int  newHeight 
)
private
ImageCache::EntryPtr PerspectiveImageCtrl::getCachedImage ( )
inline

return pointer to ImageCache

Definition at line 126 of file PerspectiveImageCtrl.h.

References m_img.

Referenced by PerspectivePanel::OnFindLines().

HuginBase::CPVector PerspectiveImageCtrl::GetControlPoints ( const unsigned int  index)

return list of control points

Definition at line 585 of file PerspectiveImageCtrl.cpp.

References GetCP(), m_lines, m_rectPoints, and m_showRect.

Referenced by PerspectivePanel::GetPanorama().

HuginBase::ControlPoint PerspectiveImageCtrl::GetCP ( const unsigned int  index,
const hugin_utils::FDiff2D p1,
const hugin_utils::FDiff2D p2 
)
private
ImageRotation PerspectiveImageCtrl::getCurrentRotation ( )
inline

returns the current rotation of displayed image

Definition at line 110 of file PerspectiveImageCtrl.h.

References m_imgRotation.

int PerspectiveImageCtrl::GetNearestLine ( const hugin_utils::FDiff2D p)
private

return index of nearest line or -1 if the point is too far from all lines

Definition at line 866 of file PerspectiveImageCtrl.cpp.

References GetDistance(), getScaleFactor(), m_lines, and maxSelectionDistance.

Referenced by OnLeftMouseDown(), and OnRightMouseUp().

int PerspectiveImageCtrl::GetNearestLinePoint ( const hugin_utils::FDiff2D p,
bool &  isStart 
)
private

return index of nearest line or -1 if the point to far from line

Parameters
ppoint for testing
isStart(out): return true if the pos is near the start of the line, otherwise false, unchanged if not line is near the given point*

Definition at line 820 of file PerspectiveImageCtrl.cpp.

References getScaleFactor(), m_lines, maxSelectionDistance, and hugin_utils::TDiff2D< T >::squareDistance().

Referenced by OnLeftMouseDown().

int PerspectiveImageCtrl::GetNearestRectangleLine ( const hugin_utils::FDiff2D p)
private

return index of nearest rectangle line or -1 if the point is too far from the rectangle lines

Definition at line 783 of file PerspectiveImageCtrl.cpp.

References GetDistance(), getScaleFactor(), m_rectPoints, and maxSelectionDistance.

Referenced by OnLeftMouseDown().

int PerspectiveImageCtrl::GetNearestRectanglePoint ( const hugin_utils::FDiff2D p)
private

return index of nearest rectangle point or -1 if the point is too far from rectangle

Definition at line 760 of file PerspectiveImageCtrl.cpp.

References getScaleFactor(), m_rectPoints, maxSelectionDistance, and hugin_utils::TDiff2D< T >::squareDistance().

Referenced by OnLeftMouseDown().

double PerspectiveImageCtrl::getScale ( ) const

return scale factor, 0 for autoscale

Definition at line 910 of file PerspectiveImageCtrl.cpp.

References m_fitToWindow, and m_scaleFactor.

double PerspectiveImageCtrl::getScaleFactor ( ) const
protected

get scale factor (calculates factor when fit to window is active)

Definition at line 934 of file PerspectiveImageCtrl.cpp.

References m_scaleFactor.

Referenced by GetNearestLine(), GetNearestLinePoint(), GetNearestRectangleLine(), GetNearestRectanglePoint(), invtransform(), rescaleImage(), scale(), and transform().

int PerspectiveImageCtrl::invtransform ( int  x) const
inlineprivate

translate screen coordinates to image coordinates, considers additional added border

Definition at line 206 of file PerspectiveImageCtrl.h.

References getScaleFactor(), and PerspectiveOffset.

Referenced by invtransform(), OnLeftMouseDown(), OnLeftMouseUp(), OnMouseMove(), and OnRightMouseUp().

double PerspectiveImageCtrl::invtransform ( double  x) const
inlineprivate

Definition at line 210 of file PerspectiveImageCtrl.h.

References getScaleFactor(), and PerspectiveOffset.

hugin_utils::FDiff2D PerspectiveImageCtrl::invtransform ( const wxPoint &  p) const
inlineprivate
bool PerspectiveImageCtrl::IsInsideRect ( const hugin_utils::FDiff2D p)
private

return true, if the point p is inside the rect

Definition at line 806 of file PerspectiveImageCtrl.cpp.

References m_rectPoints, hugin_utils::TDiff2D< T >::x, and hugin_utils::TDiff2D< T >::y.

Referenced by OnLeftMouseDown().

bool PerspectiveImageCtrl::IsOriginalShown ( ) const
inline
void PerspectiveImageCtrl::OnCaptureLost ( wxMouseCaptureLostEvent &  e)

event handler, when mouse capture is lost, e.g.

user click outside of window cancels creating of new mask

Definition at line 443 of file PerspectiveImageCtrl.cpp.

References OnKillFocus().

Referenced by Create().

void PerspectiveImageCtrl::OnDraw ( wxDC &  dc)
virtual
void PerspectiveImageCtrl::OnKillFocus ( wxFocusEvent &  e)

event handler, when editor lost focus, mainly cancels creating new polygon

Definition at line 449 of file PerspectiveImageCtrl.cpp.

Referenced by Create(), and OnCaptureLost().

void PerspectiveImageCtrl::OnLeftMouseDown ( wxMouseEvent &  mouse)
void PerspectiveImageCtrl::OnLeftMouseUp ( wxMouseEvent &  mouse)
void PerspectiveImageCtrl::OnMiddleMouseDown ( wxMouseEvent &  mouse)

event handler for middle mouse button, start scrolling

Definition at line 405 of file PerspectiveImageCtrl.cpp.

References m_editorState, m_middleMouseScroll, m_scrollPos, m_showRemappedImage, and SHOW_IMAGE.

Referenced by Create().

void PerspectiveImageCtrl::OnMiddleMouseUp ( wxMouseEvent &  mouse)

event handler for middle mouse button, end scrolling

Definition at line 430 of file PerspectiveImageCtrl.cpp.

References m_middleMouseScroll, and m_showRemappedImage.

Referenced by Create().

void PerspectiveImageCtrl::OnMouseMove ( wxMouseEvent &  mouse)
void PerspectiveImageCtrl::OnRightMouseUp ( wxMouseEvent &  mouse)

event handler when right mouse button is released

Definition at line 378 of file PerspectiveImageCtrl.cpp.

References applyRotInv(), DEBUG_DEBUG, GetNearestLine(), invtransform(), m_editorState, m_lines, m_middleMouseScroll, m_showRect, m_showRemappedImage, SHOW_IMAGE, and update().

Referenced by Create().

void PerspectiveImageCtrl::OnSize ( wxSizeEvent &  e)
protected

handler called when size of control was changed

Definition at line 626 of file PerspectiveImageCtrl.cpp.

References GenerateRemappedImage(), m_fitToWindow, m_imageFilename, m_showRemappedImage, and setScale().

Referenced by Create().

void PerspectiveImageCtrl::rescaleImage ( )
protected
int PerspectiveImageCtrl::scale ( int  x) const
inlineprivate

helper function for scale, offset and rotation

scale of width/height

Definition at line 181 of file PerspectiveImageCtrl.h.

References getScaleFactor().

Referenced by GenerateRemappedImage(), OnDraw(), and rescaleImage().

double PerspectiveImageCtrl::scale ( double  x) const
inlineprivate

Definition at line 185 of file PerspectiveImageCtrl.h.

References getScaleFactor().

void PerspectiveImageCtrl::setImage ( const std::string &  filename,
ImageRotation  rot 
)

set the current image and mask list, this loads also the image from cache

Definition at line 59 of file PerspectiveImageCtrl.cpp.

References m_bitmap, m_editorState, m_imageFilename, m_img, m_imgRotation, m_lines, m_realSize, m_rectPoints, m_showRemappedImage, NO_IMAGE, rescaleImage(), ROT0, SHOW_IMAGE, and update().

Referenced by PerspectivePanel::SetImage().

void PerspectiveImageCtrl::SetLineColour ( wxColour  newColour)

sets the colour for the lines

Definition at line 464 of file PerspectiveImageCtrl.cpp.

References m_colour_selected, and update().

Referenced by PerspectivePanel::Create(), and PerspectivePanel::OnColourChanged().

void PerspectiveImageCtrl::setOriginalMode ( )
inline

if called, the mouse handlers are deactivated

Definition at line 77 of file PerspectiveImageCtrl.h.

References m_showRemappedImage.

Referenced by PerspectivePanel::OnPreview().

void PerspectiveImageCtrl::SetRectMode ( bool  newMode)

set line or rect mode

Definition at line 576 of file PerspectiveImageCtrl.cpp.

References m_showRect, and update().

Referenced by PerspectivePanel::OnModeChanged().

void PerspectiveImageCtrl::SetRemappedMode ( const HuginBase::Panorama pano)

set the panorama object for remapping

Definition at line 607 of file PerspectiveImageCtrl.cpp.

References HuginBase::Panorama::duplicate(), GenerateRemappedImage(), m_pano, m_showRemappedImage, and update().

Referenced by PerspectivePanel::OnPreview().

void PerspectiveImageCtrl::setScale ( double  factor)

set the scaling factor for mask editing display.

Parameters
factorzoom factor, 0 means fit to window.

Definition at line 889 of file PerspectiveImageCtrl.cpp.

References calcAutoScaleFactor(), DEBUG_DEBUG, m_fitToWindow, m_imageSize, m_scaleFactor, and rescaleImage().

Referenced by PerspectivePanel::Create(), OnSize(), and PerspectivePanel::OnZoom().

int PerspectiveImageCtrl::transform ( int  x) const
inlineprivate

convert image coordinate to screen coordinates, considers additional added border

Definition at line 190 of file PerspectiveImageCtrl.h.

References getScaleFactor(), and PerspectiveOffset.

Referenced by DrawLines(), DrawRect(), and transform().

double PerspectiveImageCtrl::transform ( double  x) const
inlineprivate

Definition at line 194 of file PerspectiveImageCtrl.h.

References getScaleFactor(), and PerspectiveOffset.

wxPoint PerspectiveImageCtrl::transform ( const hugin_utils::FDiff2D p) const
inlineprivate
void PerspectiveImageCtrl::update ( )

Member Data Documentation

wxBitmap PerspectiveImageCtrl::m_bitmap
private

Definition at line 167 of file PerspectiveImageCtrl.h.

Referenced by OnDraw(), rescaleImage(), and setImage().

wxColor PerspectiveImageCtrl::m_colour_selected
private

Definition at line 299 of file PerspectiveImageCtrl.h.

Referenced by DrawLines(), DrawRect(), and SetLineColour().

std::vector<Line> PerspectiveImageCtrl::m_currentLine
private

Definition at line 302 of file PerspectiveImageCtrl.h.

Referenced by OnDraw(), OnLeftMouseDown(), OnLeftMouseUp(), and OnMouseMove().

wxPoint PerspectiveImageCtrl::m_currentPos
private

Definition at line 292 of file PerspectiveImageCtrl.h.

Referenced by OnLeftMouseDown().

wxPoint PerspectiveImageCtrl::m_dragStartPos
private

Definition at line 291 of file PerspectiveImageCtrl.h.

Referenced by OnLeftMouseDown(), OnLeftMouseUp(), and OnMouseMove().

PerspectiveEditorState PerspectiveImageCtrl::m_editorState { NO_IMAGE }
private
bool PerspectiveImageCtrl::m_fitToWindow { false }
private

Definition at line 281 of file PerspectiveImageCtrl.h.

Referenced by getScale(), OnSize(), rescaleImage(), and setScale().

std::string PerspectiveImageCtrl::m_imageFilename
private

Definition at line 172 of file PerspectiveImageCtrl.h.

Referenced by OnSize(), and setImage().

wxSize PerspectiveImageCtrl::m_imageSize
private

Definition at line 176 of file PerspectiveImageCtrl.h.

Referenced by rescaleImage(), and setScale().

ImageCache::EntryPtr PerspectiveImageCtrl::m_img
private

image cache entry for current image

Definition at line 286 of file PerspectiveImageCtrl.h.

Referenced by GenerateRemappedImage(), getCachedImage(), rescaleImage(), and setImage().

ImageRotation PerspectiveImageCtrl::m_imgRotation { ROT0 }
private
std::vector<Line> PerspectiveImageCtrl::m_lines
private
Line PerspectiveImageCtrl::m_lineStartDrag
private

Definition at line 303 of file PerspectiveImageCtrl.h.

Referenced by OnLeftMouseDown(), OnLeftMouseUp(), and OnMouseMove().

bool PerspectiveImageCtrl::m_middleMouseScroll { false }
private
int PerspectiveImageCtrl::m_movingPoint { -1 }
private

Definition at line 293 of file PerspectiveImageCtrl.h.

Referenced by OnLeftMouseDown(), OnLeftMouseUp(), and OnMouseMove().

HuginBase::Panorama PerspectiveImageCtrl::m_pano
private

HuginBase::Panorama object for calculation of remapped image.

Definition at line 288 of file PerspectiveImageCtrl.h.

Referenced by GenerateRemappedImage(), and SetRemappedMode().

wxSize PerspectiveImageCtrl::m_realSize
private

Definition at line 178 of file PerspectiveImageCtrl.h.

Referenced by applyRot(), applyRotInv(), ClipPos(), rescaleImage(), and setImage().

std::vector<hugin_utils::FDiff2D> PerspectiveImageCtrl::m_rectPoints
private
std::vector<hugin_utils::FDiff2D> PerspectiveImageCtrl::m_rectPointsStartDrag
private

Definition at line 301 of file PerspectiveImageCtrl.h.

Referenced by OnLeftMouseDown(), OnLeftMouseUp(), and OnMouseMove().

wxBitmap PerspectiveImageCtrl::m_remappedImg
private

the remapped image as wxBitmap

Definition at line 169 of file PerspectiveImageCtrl.h.

Referenced by GenerateRemappedImage(), and OnDraw().

double PerspectiveImageCtrl::m_scaleFactor { 1.0 }
private

Definition at line 280 of file PerspectiveImageCtrl.h.

Referenced by getScale(), getScaleFactor(), rescaleImage(), and setScale().

wxPoint PerspectiveImageCtrl::m_scrollPos
private

Definition at line 296 of file PerspectiveImageCtrl.h.

Referenced by OnMiddleMouseDown(), and OnMouseMove().

bool PerspectiveImageCtrl::m_showRect { true }
private
bool PerspectiveImageCtrl::m_showRemappedImage { false }
private

The documentation for this class was generated from the following files: