[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin1/hugin/MaskImageCtrl.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00010 /*  This is free software; you can redistribute it and/or
00011  *  modify it under the terms of the GNU General Public
00012  *  License as published by the Free Software Foundation; either
00013  *  version 2 of the License, or (at your option) any later version.
00014  *
00015  *  This software is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *  Lesser General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public
00021  *  License along with this software; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 #ifndef _MaskImageCtrl_H
00027 #define _MaskImageCtrl_H
00028 
00029 #include <base_wx/ImageCache.h>
00030 
00031 class MaskEditorPanel;
00032 
00037 class MaskImageCtrl : public wxScrolledWindow
00038 {
00039 public:
00042     MaskImageCtrl()
00043         : scaleFactor(1),fitToWindow(false),maskEditState(NO_IMAGE)
00044         { }
00045 
00046     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"));
00047 
00048     void Init(MaskEditorPanel * parent);
00049 
00054     enum ImageRotation { ROT0=0, ROT90, ROT180, ROT270 };
00055 
00057     void setPreviewOnly() { m_previewOnly=true; };
00059     void setImage (const std::string & filename, HuginBase::MaskPolygonVector newMask, ImageRotation rot);
00061     void setNewMasks(HuginBase::MaskPolygonVector newMasks);
00063     void setActiveMask(unsigned int newMask, bool doUpdate=true);
00065     HuginBase::MaskPolygonVector getNewMask() const { return m_imageMask; };
00067     void selectAllMarkers();
00068 
00070     void mouseMoveEvent(wxMouseEvent& mouse);
00072     void mousePressLMBEvent(wxMouseEvent& mouse);
00074     void mouseReleaseLMBEvent(wxMouseEvent& mouse);
00076     void mouseDblClickLeftEvent(wxMouseEvent& mouse);
00078     void mousePressRMBEvent(wxMouseEvent& mouse);
00080     void mouseReleaseRMBEvent(wxMouseEvent& mouse);
00082     void OnKeyUp(wxKeyEvent &e);
00085     void OnCaptureLost(wxMouseCaptureLostEvent &e);
00087     void OnKillFocus(wxFocusEvent &e);
00088 
00090     void startNewPolygon();
00092     wxSize DoGetBestSize() const;
00093 
00098     void setScale(double factor);
00099 
00101     double getScale()
00102         { return fitToWindow ? 0 : scaleFactor; }
00103 
00105     ImageRotation getCurrentRotation() { return m_imgRotation; };
00106     
00108     void update();
00109 
00111     void SetUserColourPolygonNegative(wxColour newColour) { m_colour_polygon_negative=newColour; };
00112     void SetUserColourPolygonPositive(wxColour newColour) { m_colour_polygon_positive=newColour; };
00113     void SetUserColourPointSelected(wxColour newColour) { m_colour_point_selected=newColour; };
00114     void SetUserColourPointUnselected(wxColour newColour) { m_colour_point_unselected=newColour; };
00115 
00116 protected:
00118     void OnDraw(wxDC& dc);
00120     void OnSize(wxSizeEvent & e);
00121 
00123     double getScaleFactor() const;
00125     double calcAutoScaleFactor(wxSize size);
00127     void rescaleImage();
00128 
00129  private:
00130 
00131     //scaled bitmap
00132     wxBitmap bitmap;
00133     //filename of current editing file
00134     std::string imageFilename;
00135     // stores rotation of image
00136     ImageRotation m_imgRotation;
00137     // size of displayed (probably scaled) image
00138     wxSize imageSize;
00139     // size of real image
00140     wxSize m_realSize;
00141 
00143     int scale(int x) const
00144         {  return (int) (x * getScaleFactor() + 0.5); }
00145 
00146     double scale(double x) const
00147         {  return x * getScaleFactor(); }
00148 
00150     int transform(int x) const
00151         {  return (int) ((x+HuginBase::maskOffset) * getScaleFactor() + 0.5); }
00152 
00153     double transform(double x) const
00154         {  return (x+HuginBase::maskOffset) * getScaleFactor(); }
00155 
00156     wxPoint transform(hugin_utils::FDiff2D p) const
00157         {
00158             wxPoint r;
00159             r.x = transform(p.x);
00160             r.y = transform(p.y);
00161             return r;
00162         };
00163 
00165     int invtransform(int x) const
00166         {  return (int) (x/getScaleFactor()-HuginBase::maskOffset + 0.5); };
00167 
00168     double invtransform(double x) const
00169         {  return (x/getScaleFactor()-HuginBase::maskOffset); };
00170 
00171     hugin_utils::FDiff2D invtransform(const wxPoint & p) const
00172         {
00173             hugin_utils::FDiff2D r;
00174             r.x = invtransform(p.x);
00175             r.y = invtransform(p.y);
00176             return r;
00177         };
00178     
00179     // rotate coordinate to fit possibly rotated image display
00180     // useful for drawing something on the rotated display
00181     template <class T>
00182     T applyRot(const T & p) const
00183     {
00184         switch (m_imgRotation) {
00185             case ROT0:
00186                 return p;
00187                 break;
00188             case ROT90:
00189                 return T(m_realSize.GetHeight()-1 - p.y, p.x);
00190                 break;
00191             case ROT180:
00192                 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
00193                 break;
00194             case ROT270:
00195                 return T(p.y, m_realSize.GetWidth()-1 - p.x);
00196                 break;
00197             default:
00198                 return p;
00199                 break;
00200         }
00201     }
00202 
00203     // rotate coordinate to fit possibly rotated image display
00204     // useful for converting rotated display coordinates to image coordinates
00205     template <class T>
00206     T applyRotInv(const T & p) const
00207     {
00208         switch (m_imgRotation) {
00209             case ROT90:
00210                 return T(p.y, m_realSize.GetHeight()-1 - p.x);
00211                 break;
00212             case ROT180:
00213                 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y);
00214                 break;
00215             case ROT270:
00216                 return T(m_realSize.GetWidth()-1 - p.y, p.x);
00217                 break;
00218             case ROT0:
00219             default:
00220                 return p;
00221                 break;
00222         }
00223     }
00224 
00225     //draw the given polygon
00226     void DrawPolygon(wxDC &dc, HuginBase::MaskPolygon poly, bool isSelected, bool drawMarker);
00227     //draw a selection rectange, when called the second time the rectangle is deleted
00228     void DrawSelectionRectangle();
00229     // find the polygon for which the point p is inside the polygon
00230     void FindPolygon(hugin_utils::FDiff2D p);
00231     // returns a set of points which are in the selection rectangle 
00232     bool SelectPointsInsideMouseRect(HuginBase::UIntSet &points,const bool considerSelectedOnly);
00233 
00235     enum MaskEditorState
00236     {
00237         NO_IMAGE=0, // no image selected
00238         NO_MASK, // image loaded, but none active mask
00239         NO_SELECTION, // active polygon, but no point selected
00240         POINTS_SELECTED, // points selected
00241         POINTS_MOVING, // dragging points
00242         POINTS_DELETING,  // remove points inside rect
00243         POINTS_ADDING,  // adding new points add mouse position
00244         POLYGON_SELECTING, // selecting an region to select an other polygon
00245         REGION_SELECTING, // currently selecting an region
00246         NEW_POLYGON_STARTED, // modus is new polygon, but no point setted yet
00247         NEW_POLYGON_CREATING  // currently creating new polygon
00248     };
00249     MaskEditorState maskEditState;
00250 
00251     double scaleFactor;
00252     bool fitToWindow;
00253     bool m_previewOnly;
00254 
00255     MaskEditorPanel * m_editPanel;
00256     HuginBase::MaskPolygonVector m_imageMask;
00257     unsigned int m_activeMask;
00258     // the active masks, the one which is currently editing
00259     HuginBase::MaskPolygon m_editingMask;
00260     // all selected points
00261     HuginBase::UIntSet m_selectedPoints;
00262 
00263     ImageCache::EntryPtr m_img;
00264 
00265     // positions of mouse drag
00266     wxPoint m_dragStartPos;
00267     wxPoint m_currentPos;
00268 
00269     // colours for different parts
00270     wxColor m_colour_polygon_negative;
00271     wxColor m_colour_polygon_positive;
00272     wxColor m_colour_point_selected;
00273     wxColor m_colour_point_unselected;
00274 
00275     DECLARE_EVENT_TABLE();
00276     DECLARE_DYNAMIC_CLASS(MaskImageCtrl)
00277 };
00278 
00280 class MaskImageCtrlXmlHandler : public wxXmlResourceHandler
00281 {
00282     DECLARE_DYNAMIC_CLASS(MaskImageCtrlXmlHandler)
00283 
00284 public:
00285     MaskImageCtrlXmlHandler();
00286     virtual wxObject *DoCreateResource();
00287     virtual bool CanHandle(wxXmlNode *node);
00288 };
00289 
00290 
00291 #endif // _MaskImageCtrl_H

Generated on Mon Sep 20 01:01:26 2010 for Hugintrunk by doxygen 1.3.9.1