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 #ifdef __APPLE__
32 #include "panoinc_WX.h"
33 #include "panoinc.h"
34 #endif
35 #include <hugin/config_defaults.h>
36 #include "hugin/huginApp.h"
37 
38 BEGIN_EVENT_TABLE(MaskLoadDialog,wxDialog)
39 EVT_RADIOBOX(XRCID("mask_rescale"),MaskLoadDialog::ProcessMask)
40 EVT_RADIOBOX(XRCID("mask_rotate"),MaskLoadDialog::ProcessMask)
42 
43 MaskLoadDialog::MaskLoadDialog(wxWindow *parent)
44 {
45  wxXmlResource::Get()->LoadDialog(this, parent, wxT("mask_load_dialog"));
46 
47 #ifdef __WXMSW__
48  wxIconBundle myIcons(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
49  SetIcons(myIcons);
50 #else
51  wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
52  SetIcon(myIcon);
53 #endif
54 
55  m_image=XRCCTRL(*this,"mask_preview",MaskImageCtrl);
56  m_image->setPreviewOnly();
57  //load and set colours
58  wxColour defaultColour;
59  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_NEGATIVE));
60  wxColour colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonNegative"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
61  m_image->SetUserColourPolygonNegative(colour);
62  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_POSITIVE));
63  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonPositive"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
64  m_image->SetUserColourPolygonPositive(colour);
65  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_SELECTED));
66  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointSelected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
67  m_image->SetUserColourPointSelected(colour);
68  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_UNSELECTED));
69  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointUnselected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
70  m_image->SetUserColourPointUnselected(colour);
71 
72  m_maskScaleMode=XRCCTRL(*this,"mask_rescale",wxRadioBox);
73  m_maskRotateMode=XRCCTRL(*this,"mask_rotate",wxRadioBox);
74 
75  RestoreFramePosition(this, wxT("MaskLoadDialog"));
76  if(GetSize().GetWidth()<400)
77  SetClientSize(400,GetSize().GetHeight());
78 };
79 
81 {
82  StoreFramePosition(this, wxT("MaskLoadDialog"));
83 };
84 
85 void MaskLoadDialog::initValues(const HuginBase::SrcPanoImage image, const HuginBase::MaskPolygonVector newMask, const vigra::Size2D maskSize)
86 {
88  m_image->setImage(image.getFilename(),newMask,emptyMask,MaskImageCtrl::ROT0);
89  m_image->setScale(0);
90  m_loadedMask=newMask;
91  m_imageSize=image.getSize();
92  m_maskSize=maskSize;
93  // set dummy value
94  if(m_imageSize.width()==0)
95  m_imageSize.setWidth(100);
96  if(m_imageSize.height()==0)
97  m_imageSize.setHeight(100);
98  if((m_maskSize.width()==0) || (m_maskSize.height()==0))
100  XRCCTRL(*this,"label_image_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_imageSize.width(),m_imageSize.height()));
101  XRCCTRL(*this,"label_mask_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_maskSize.width(),m_maskSize.height()));
102  //if image is rotated, set rotation to clockwise
103  if((m_maskSize.width()==m_imageSize.height()) && (m_maskSize.height()==m_imageSize.width()))
104  m_maskRotateMode->SetSelection(1);
105  wxCommandEvent dummy;
106  ProcessMask(dummy);
107 };
108 
109 void MaskLoadDialog::ProcessMask(wxCommandEvent &e)
110 {
112  if(m_processedMask.empty())
113  {
115  return;
116  };
117  double maskWidth;
118  double maskHeight;
119  if(m_maskRotateMode->GetSelection()==0)
120  {
121  maskWidth=m_maskSize.width();
122  maskHeight=m_maskSize.height();
123  }
124  else
125  {
126  maskWidth=m_maskSize.height();
127  maskHeight=m_maskSize.width();
128  bool clockwise=(m_maskRotateMode->GetSelection()==1);
129  for(unsigned int i=0;i<m_processedMask.size();i++)
130  m_processedMask[i].rotate90(clockwise,m_maskSize.width(),m_maskSize.height());
131  };
132  switch(m_maskScaleMode->GetSelection())
133  {
134  case 0:
135  // clip mask
136  for(unsigned int i=0;i<m_processedMask.size();i++)
137  m_processedMask[i].clipPolygon(vigra::Rect2D(-0.5*HuginBase::maskOffset,-0.5*HuginBase::maskOffset,
139  break;
140  case 1:
141  // scale mask
142  for(unsigned int i=0;i<m_processedMask.size();i++)
143  m_processedMask[i].scale((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
144  break;
145  case 2:
146  // proportional scale mask
147  {
148  double factor=std::min((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
149  for(unsigned int i=0;i<m_processedMask.size();i++)
150  m_processedMask[i].scale(factor);
151  };
152  break;
153  };
154 
156 };
157 
159 {
161  m_image->setNewMasks(m_processedMask,emptyMask);
162 };
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
END_EVENT_TABLE()
include file for the hugin project
static huginApp * Get()
hack.. kind of a pseudo singleton...
Definition: huginApp.cpp:649
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
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: LensCalApp.cpp:212
MaskImageCtrl * m_image
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: LensCalApp.cpp:158
vigra::Size2D m_maskSize
std::vector< MaskPolygon > MaskPolygonVector
Definition: Mask.h:147
virtual ~MaskLoadDialog()
#define HUGIN_MASK_COLOUR_POINT_UNSELECTED
Dialog for loading masks.
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
#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