Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaskLoadDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
13 /* This is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This software is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public
24  * License along with this software. If not, see
25  * <http://www.gnu.org/licenses/>.
26  *
27  */
28 
29 #include "hugin/MaskLoadDialog.h"
30 #include "base_wx/wxPlatform.h"
31 #include "base_wx/wxutils.h"
32 #ifdef __APPLE__
33 #include "panoinc_WX.h"
34 #include "panoinc.h"
35 #endif
36 #include <hugin/config_defaults.h>
37 #include "hugin/huginApp.h"
38 
40 {
41  wxXmlResource::Get()->LoadDialog(this, parent, wxT("mask_load_dialog"));
42 
43  m_image=XRCCTRL(*this,"mask_preview",MaskImageCtrl);
45  //load and set colours
46  wxColour defaultColour;
47  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_NEGATIVE));
48  wxColour colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonNegative"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
50  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_POSITIVE));
51  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonPositive"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
53  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_SELECTED));
54  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointSelected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
56  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_UNSELECTED));
57  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointUnselected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
59 
60  m_maskScaleMode=XRCCTRL(*this,"mask_rescale",wxRadioBox);
61  m_maskScaleMode->Bind(wxEVT_RADIOBOX, &MaskLoadDialog::ProcessMask, this);
62  m_maskRotateMode=XRCCTRL(*this,"mask_rotate",wxRadioBox);
63  m_maskRotateMode->Bind(wxEVT_RADIOBOX, &MaskLoadDialog::ProcessMask, this);
64 
65  RestoreFramePosition(this, wxT("MaskLoadDialog"));
66  if(GetSize().GetWidth()<400)
67  SetClientSize(400,GetSize().GetHeight());
68 };
69 
71 {
72  StoreFramePosition(this, wxT("MaskLoadDialog"));
73 };
74 
75 void MaskLoadDialog::initValues(const HuginBase::SrcPanoImage image, const HuginBase::MaskPolygonVector newMask, const vigra::Size2D maskSize)
76 {
78  m_image->setImage(image.getFilename(),newMask,emptyMask,MaskImageCtrl::ROT0);
79  m_image->setScale(0);
80  m_loadedMask=newMask;
81  m_imageSize=image.getSize();
82  m_maskSize=maskSize;
83  // set dummy value
84  if(m_imageSize.width()==0)
85  m_imageSize.setWidth(100);
86  if(m_imageSize.height()==0)
87  m_imageSize.setHeight(100);
88  if((m_maskSize.width()==0) || (m_maskSize.height()==0))
90  XRCCTRL(*this,"label_image_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_imageSize.width(),m_imageSize.height()));
91  XRCCTRL(*this,"label_mask_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_maskSize.width(),m_maskSize.height()));
92  //if image is rotated, set rotation to clockwise
93  if((m_maskSize.width()==m_imageSize.height()) && (m_maskSize.height()==m_imageSize.width()))
94  m_maskRotateMode->SetSelection(1);
95  wxCommandEvent dummy;
96  ProcessMask(dummy);
97 };
98 
99 void MaskLoadDialog::ProcessMask(wxCommandEvent &e)
100 {
102  if(m_processedMask.empty())
103  {
105  return;
106  };
107  double maskWidth;
108  double maskHeight;
109  if(m_maskRotateMode->GetSelection()==0)
110  {
111  maskWidth=m_maskSize.width();
112  maskHeight=m_maskSize.height();
113  }
114  else
115  {
116  maskWidth=m_maskSize.height();
117  maskHeight=m_maskSize.width();
118  bool clockwise=(m_maskRotateMode->GetSelection()==1);
119  for(unsigned int i=0;i<m_processedMask.size();i++)
120  m_processedMask[i].rotate90(clockwise,m_maskSize.width(),m_maskSize.height());
121  };
122  switch(m_maskScaleMode->GetSelection())
123  {
124  case 0:
125  // clip mask
126  for(unsigned int i=0;i<m_processedMask.size();i++)
127  m_processedMask[i].clipPolygon(vigra::Rect2D(-0.5*HuginBase::maskOffset,-0.5*HuginBase::maskOffset,
129  break;
130  case 1:
131  // scale mask
132  for(unsigned int i=0;i<m_processedMask.size();i++)
133  m_processedMask[i].scale((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
134  break;
135  case 2:
136  // proportional scale mask
137  {
138  double factor=std::min((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
139  for(unsigned int i=0;i<m_processedMask.size();i++)
140  m_processedMask[i].scale(factor);
141  };
142  break;
143  };
144 
146 };
147 
149 {
151  m_image->setNewMasks(m_processedMask,emptyMask);
152 };
wxRadioBox * m_maskScaleMode
const int maskOffset
polygon can exceed the image maximal maskOffset pixels in each direction bigger polygons will be clip...
Definition: Mask.h:44
void SetUserColourPointUnselected(wxColour newColour)
include file for the hugin project
MaskLoadDialog(wxWindow *parent)
Constructor, read from xrc ressource.
void setPreviewOnly()
if called, the mouse handlers are deactivated
Definition: MaskImageCtrl.h:58
void SetUserColourPolygonNegative(wxColour newColour)
sets the colour for different parts
void SetUserColourPointSelected(wxColour newColour)
mask editor
Definition: MaskImageCtrl.h:38
HuginBase::MaskPolygonVector m_processedMask
wxRadioBox * m_maskRotateMode
void setImage(const std::string &filename, HuginBase::MaskPolygonVector newMask, HuginBase::MaskPolygonVector masksToDraw, ImageRotation rot)
set the current image and mask list, this loads also the image from cache
MaskImageCtrl * m_image
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: wxutils.cpp:133
vigra::Size2D m_maskSize
std::vector< MaskPolygon > MaskPolygonVector
Definition: Mask.h:147
virtual ~MaskLoadDialog()
#define HUGIN_MASK_COLOUR_POINT_UNSELECTED
void setNewMasks(HuginBase::MaskPolygonVector newMasks, HuginBase::MaskPolygonVector masksToDraw)
updates masks for currently selected image
include file for the hugin project
void setScale(double factor)
set the scaling factor for mask editing display.
#define HUGIN_MASK_COLOUR_POINT_SELECTED
#define HUGIN_MASK_COLOUR_POLYGON_NEGATIVE
platform/compiler specific stuff.
void ProcessMask(wxCommandEvent &e)
Definition of mask load dialog.
vigra::Size2D m_imageSize
void SetUserColourPolygonPositive(wxColour newColour)
#define HUGIN_MASK_COLOUR_POLYGON_POSITIVE
All variables of a source image.
Definition: SrcPanoImage.h:194
static T min(T x, T y)
Definition: svm.cpp:62
void initValues(const HuginBase::SrcPanoImage image, const HuginBase::MaskPolygonVector newMask, const vigra::Size2D maskSize)
sets the default values
HuginBase::MaskPolygonVector m_loadedMask
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: wxutils.cpp:65