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 
39 {
40  wxXmlResource::Get()->LoadDialog(this, parent, wxT("mask_load_dialog"));
41 
42  m_image=XRCCTRL(*this,"mask_preview",MaskImageCtrl);
44  //load and set colours
45  wxColour defaultColour;
46  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_NEGATIVE));
47  wxColour colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonNegative"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
49  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_POSITIVE));
50  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonPositive"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
52  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_SELECTED));
53  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointSelected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
55  defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_UNSELECTED));
56  colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointUnselected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
58 
59  m_maskScaleMode=XRCCTRL(*this,"mask_rescale",wxRadioBox);
60  m_maskScaleMode->Bind(wxEVT_RADIOBOX, &MaskLoadDialog::ProcessMask, this);
61  m_maskRotateMode=XRCCTRL(*this,"mask_rotate",wxRadioBox);
62  m_maskRotateMode->Bind(wxEVT_RADIOBOX, &MaskLoadDialog::ProcessMask, this);
63 
64  RestoreFramePosition(this, wxT("MaskLoadDialog"));
65  if(GetSize().GetWidth()<400)
66  SetClientSize(400,GetSize().GetHeight());
67 };
68 
70 {
71  StoreFramePosition(this, wxT("MaskLoadDialog"));
72 };
73 
74 void MaskLoadDialog::initValues(const HuginBase::SrcPanoImage image, const HuginBase::MaskPolygonVector newMask, const vigra::Size2D maskSize)
75 {
77  m_image->setImage(image.getFilename(),newMask,emptyMask,MaskImageCtrl::ROT0);
78  m_image->setScale(0);
79  m_loadedMask=newMask;
80  m_imageSize=image.getSize();
81  m_maskSize=maskSize;
82  // set dummy value
83  if(m_imageSize.width()==0)
84  m_imageSize.setWidth(100);
85  if(m_imageSize.height()==0)
86  m_imageSize.setHeight(100);
87  if((m_maskSize.width()==0) || (m_maskSize.height()==0))
89  XRCCTRL(*this,"label_image_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_imageSize.width(),m_imageSize.height()));
90  XRCCTRL(*this,"label_mask_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_maskSize.width(),m_maskSize.height()));
91  //if image is rotated, set rotation to clockwise
92  if((m_maskSize.width()==m_imageSize.height()) && (m_maskSize.height()==m_imageSize.width()))
93  m_maskRotateMode->SetSelection(1);
94  wxCommandEvent dummy;
95  ProcessMask(dummy);
96 };
97 
98 void MaskLoadDialog::ProcessMask(wxCommandEvent &e)
99 {
101  if(m_processedMask.empty())
102  {
104  return;
105  };
106  double maskWidth;
107  double maskHeight;
108  if(m_maskRotateMode->GetSelection()==0)
109  {
110  maskWidth=m_maskSize.width();
111  maskHeight=m_maskSize.height();
112  }
113  else
114  {
115  maskWidth=m_maskSize.height();
116  maskHeight=m_maskSize.width();
117  bool clockwise=(m_maskRotateMode->GetSelection()==1);
118  for(unsigned int i=0;i<m_processedMask.size();i++)
119  m_processedMask[i].rotate90(clockwise,m_maskSize.width(),m_maskSize.height());
120  };
121  switch(m_maskScaleMode->GetSelection())
122  {
123  case 0:
124  // clip mask
125  for(unsigned int i=0;i<m_processedMask.size();i++)
126  m_processedMask[i].clipPolygon(vigra::Rect2D(-0.5*HuginBase::maskOffset,-0.5*HuginBase::maskOffset,
128  break;
129  case 1:
130  // scale mask
131  for(unsigned int i=0;i<m_processedMask.size();i++)
132  m_processedMask[i].scale((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
133  break;
134  case 2:
135  // proportional scale mask
136  {
137  double factor=std::min((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
138  for(unsigned int i=0;i<m_processedMask.size();i++)
139  m_processedMask[i].scale(factor);
140  };
141  break;
142  };
143 
145 };
146 
148 {
150  m_image->setNewMasks(m_processedMask,emptyMask);
151 };
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
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: LensCalApp.cpp:210
MaskImageCtrl * m_image
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: LensCalApp.cpp:156
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