MaskLoadDialog.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00013 /*  This is free software; you can redistribute it and/or
00014  *  modify it under the terms of the GNU General Public
00015  *  License as published by the Free Software Foundation; either
00016  *  version 2 of the License, or (at your option) any later version.
00017  *
00018  *  This software is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  *  Lesser General Public License for more details.
00022  *
00023  *  You should have received a copy of the GNU General Public
00024  *  License along with this software; if not, write to the Free Software
00025  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  */
00028 
00029 #include "hugin/MaskLoadDialog.h"
00030 #include "base_wx/wxPlatform.h"
00031 #ifdef __APPLE__
00032 #include "panoinc_WX.h"
00033 #include "panoinc.h"
00034 #endif
00035 #include <hugin/config_defaults.h>
00036 #include "hugin/huginApp.h"
00037 
00038 BEGIN_EVENT_TABLE(MaskLoadDialog,wxDialog)
00039 EVT_RADIOBOX(XRCID("mask_rescale"),MaskLoadDialog::ProcessMask)
00040 EVT_RADIOBOX(XRCID("mask_rotate"),MaskLoadDialog::ProcessMask)
00041 END_EVENT_TABLE()
00042 
00043 MaskLoadDialog::MaskLoadDialog(wxWindow *parent)
00044 {
00045     wxXmlResource::Get()->LoadDialog(this, parent, wxT("mask_load_dialog"));
00046 
00047 #ifdef __WXMSW__
00048     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00049 #else
00050     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00051 #endif
00052     SetIcon(myIcon);
00053     m_image=XRCCTRL(*this,"mask_preview",MaskImageCtrl);
00054     m_image->setPreviewOnly();
00055     //load and set colours
00056     wxColour defaultColour;
00057     defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_NEGATIVE));
00058     wxColour colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonNegative"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
00059     m_image->SetUserColourPolygonNegative(colour);
00060     defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POLYGON_POSITIVE));
00061     colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPolygonPositive"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
00062     m_image->SetUserColourPolygonPositive(colour);
00063     defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_SELECTED));
00064     colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointSelected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
00065     m_image->SetUserColourPointSelected(colour);
00066     defaultColour.Set(wxT(HUGIN_MASK_COLOUR_POINT_UNSELECTED));
00067     colour=wxConfigBase::Get()->Read(wxT("/MaskEditorPanel/ColourPointUnselected"),defaultColour.GetAsString(wxC2S_HTML_SYNTAX));
00068     m_image->SetUserColourPointUnselected(colour);
00069 
00070     m_maskScaleMode=XRCCTRL(*this,"mask_rescale",wxRadioBox);
00071     m_maskRotateMode=XRCCTRL(*this,"mask_rotate",wxRadioBox);
00072 
00073     RestoreFramePosition(this, wxT("MaskLoadDialog"));
00074     if(GetSize().GetWidth()<400)
00075         SetClientSize(400,GetSize().GetHeight());
00076 };
00077 
00078 MaskLoadDialog::~MaskLoadDialog()
00079 {
00080     StoreFramePosition(this, wxT("MaskLoadDialog"));
00081 };
00082 
00083 void MaskLoadDialog::initValues(const HuginBase::SrcPanoImage image, const HuginBase::MaskPolygonVector newMask, const vigra::Size2D maskSize)
00084 {
00085     HuginBase::MaskPolygonVector emptyMask;
00086     m_image->setImage(image.getFilename(),newMask,emptyMask,MaskImageCtrl::ROT0);
00087     m_image->setScale(0);
00088     m_loadedMask=newMask;
00089     m_imageSize=image.getSize();
00090     m_maskSize=maskSize;
00091     // set dummy value
00092     if(m_imageSize.width()==0)
00093         m_imageSize.setWidth(100);
00094     if(m_imageSize.height()==0)
00095         m_imageSize.setHeight(100);
00096     if((m_maskSize.width()==0) || (m_maskSize.height()==0))
00097         m_maskSize=m_imageSize;
00098     XRCCTRL(*this,"label_image_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_imageSize.width(),m_imageSize.height()));
00099     XRCCTRL(*this,"label_mask_size",wxStaticText)->SetLabel(wxString::Format(wxT("%d x %d"),m_maskSize.width(),m_maskSize.height()));
00100     //if image is rotated, set rotation to clockwise
00101     if((m_maskSize.width()==m_imageSize.height()) && (m_maskSize.height()==m_imageSize.width()))
00102         m_maskRotateMode->SetSelection(1);
00103     wxCommandEvent dummy;
00104     ProcessMask(dummy);
00105 };
00106 
00107 void MaskLoadDialog::ProcessMask(wxCommandEvent &e)
00108 {
00109     m_processedMask=m_loadedMask;
00110     if(m_processedMask.size()==0)
00111     {
00112         UpdatePreviewImage();
00113         return;
00114     };
00115     double maskWidth;
00116     double maskHeight;
00117     if(m_maskRotateMode->GetSelection()==0)
00118     {
00119         maskWidth=m_maskSize.width();
00120         maskHeight=m_maskSize.height();
00121     }
00122     else
00123     {
00124         maskWidth=m_maskSize.height();
00125         maskHeight=m_maskSize.width();
00126         bool clockwise=(m_maskRotateMode->GetSelection()==1);
00127         for(unsigned int i=0;i<m_processedMask.size();i++)
00128             m_processedMask[i].rotate90(clockwise,m_maskSize.width(),m_maskSize.height());
00129     };
00130     switch(m_maskScaleMode->GetSelection())
00131     {
00132         case 0:
00133             // clip mask
00134             for(unsigned int i=0;i<m_processedMask.size();i++)
00135                 m_processedMask[i].clipPolygon(vigra::Rect2D(-0.5*HuginBase::maskOffset,-0.5*HuginBase::maskOffset,
00136                     m_imageSize.width()+0.5*HuginBase::maskOffset,m_imageSize.height()+0.5*HuginBase::maskOffset));
00137             break;
00138         case 1:
00139             // scale mask
00140             for(unsigned int i=0;i<m_processedMask.size();i++)
00141                 m_processedMask[i].scale((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
00142             break;
00143         case 2:
00144             // proportional scale mask
00145             {
00146                 double factor=std::min((double)m_imageSize.width()/maskWidth,(double)m_imageSize.height()/maskHeight);
00147                 for(unsigned int i=0;i<m_processedMask.size();i++)
00148                     m_processedMask[i].scale(factor);
00149             };
00150             break;
00151     };
00152 
00153     UpdatePreviewImage();
00154 };
00155 
00156 void MaskLoadDialog::UpdatePreviewImage()
00157 {
00158     HuginBase::MaskPolygonVector emptyMask;
00159     m_image->setNewMasks(m_processedMask,emptyMask);
00160 };

Generated on 24 Oct 2014 for Hugintrunk by  doxygen 1.4.7