ImageVariableDialog.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00011 /*  This is free software; you can redistribute it and/or
00012  *  modify it under the terms of the GNU General Public
00013  *  License as published by the Free Software Foundation; either
00014  *  version 2 of the License, or (at your option) any later version.
00015  *
00016  *  This software is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  Lesser General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public
00022  *  License along with this software. If not, see
00023  *  <http://www.gnu.org/licenses/>.
00024  *
00025  */
00026 
00027 #include "hugin/ImageVariableDialog.h"
00028 #include "base_wx/wxPlatform.h"
00029 #include "panoinc.h"
00030 #include "photometric/ResponseTransform.h"
00031 #include <map>
00032 #include <string>
00033 
00034 #include "hugin/huginApp.h"
00035 #include "base_wx/CommandHistory.h"
00036 #include "base_wx/PanoCommand.h"
00037 #include "panotools/PanoToolsInterface.h"
00038 
00039 using namespace HuginBase;
00040 
00041 BEGIN_EVENT_TABLE(ImageVariableDialog,wxDialog)
00042     EVT_BUTTON(wxID_OK, ImageVariableDialog::OnOk)
00043     EVT_BUTTON(wxID_HELP, ImageVariableDialog::OnHelp)
00044     EVT_BUTTON(XRCID("image_show_distortion_graph"), ImageVariableDialog::OnShowDistortionGraph)
00045     EVT_BUTTON(XRCID("image_show_vignetting_graph"), ImageVariableDialog::OnShowVignettingGraph)
00046     EVT_BUTTON(XRCID("image_show_response_graph"), ImageVariableDialog::OnShowResponseGraph)
00047 END_EVENT_TABLE()
00048 
00049 ImageVariableDialog::ImageVariableDialog(wxWindow *parent, HuginBase::Panorama* pano, HuginBase::UIntSet imgs)
00050 {
00051     // load our children. some children might need special
00052     // initialization. this will be done later.
00053     wxXmlResource::Get()->LoadDialog(this, parent, wxT("image_variables_dialog"));
00054 
00055 #ifdef __WXMSW__
00056     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00057 #else
00058     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00059 #endif
00060     SetIcon(myIcon);
00061     wxConfigBase * cfg = wxConfigBase::Get();
00062     //position
00063     int x = cfg->Read(wxT("/ImageVariablesDialog/positionX"),-1l);
00064     int y = cfg->Read(wxT("/ImageVariablesDialog/positionY"),-1l);
00065     if ( y >= 0 && x >= 0) 
00066     {
00067         this->Move(x, y);
00068     } 
00069     else 
00070     {
00071         this->Move(0, 44);
00072     };
00073     m_pano=pano;
00074     m_images=imgs;
00075     m_popup=NULL;
00076     InitValues();
00077 };
00078 
00079 ImageVariableDialog::~ImageVariableDialog()
00080 {
00081     wxConfigBase * cfg = wxConfigBase::Get();
00082     wxPoint ps = this->GetPosition();
00083     cfg->Write(wxT("/ImageVariablesDialog/positionX"), ps.x);
00084     cfg->Write(wxT("/ImageVariablesDialog/positionY"), ps.y);
00085     cfg->Flush();
00086 };
00087 
00088 void ImageVariableDialog::SelectTab(size_t i)
00089 {
00090     XRCCTRL(*this, "image_variable_notebook", wxNotebook)->SetSelection(i);
00091 };
00092 
00093 wxTextCtrl* GetImageVariableControl(const wxWindow* parent, const char* varname)
00094 {
00095     return wxStaticCast(
00096                 parent->FindWindow(
00097                     wxXmlResource::GetXRCID(
00098                         wxString(wxT("image_variable_")).append(wxString(varname, wxConvLocal)).c_str()
00099                     )
00100                 ), wxTextCtrl
00101            );
00102 };
00103 
00104 void ImageVariableDialog::InitValues()
00105 {
00106     if(m_images.size()==0)
00107     {
00108         return;
00109     };
00110     BaseSrcPanoImage::ResponseType responseType= m_pano->getImage(*m_images.begin()).getResponseType();
00111     bool identical=true;
00112 
00113     for(UIntSet::const_iterator it=m_images.begin();it!=m_images.end() && identical;++it)
00114     {
00115         identical=(responseType==m_pano->getImage(*it).getResponseType());
00116     };
00117     if(identical)
00118     {
00119         XRCCTRL(*this, "image_variable_responseType", wxChoice)->SetSelection(responseType);
00120     };
00121 
00122     int degDigits = wxConfigBase::Get()->Read(wxT("/General/DegreeFractionalDigitsEdit"),3);
00123     int pixelDigits = wxConfigBase::Get()->Read(wxT("/General/PixelFractionalDigitsEdit"),2);
00124     int distDigitsEdit = wxConfigBase::Get()->Read(wxT("/General/DistortionFractionalDigitsEdit"),5);
00125     
00126     VariableMapVector imgVarVector=m_pano->getVariables();
00127 
00128     for (const char** varname = m_varNames; *varname != 0; ++varname)
00129     {
00130         // update parameters
00131         int ndigits = distDigitsEdit;
00132         if (strcmp(*varname, "y") == 0 || strcmp(*varname, "p") == 0 ||
00133             strcmp(*varname, "r") == 0 || strcmp(*varname, "TrX") == 0 ||
00134             strcmp(*varname, "TrY") == 0 || strcmp(*varname, "TrZ") == 0 )
00135         {
00136             ndigits=degDigits;
00137         };
00138         if (strcmp(*varname, "v") == 0 || strcmp(*varname, "d") == 0 ||
00139             strcmp(*varname, "e") == 0 )
00140         {
00141             ndigits = pixelDigits;
00142         }
00143         double val=const_map_get(imgVarVector[*m_images.begin()],*varname).getValue();
00144         bool identical=true;
00145         for(UIntSet::const_iterator it=m_images.begin();it!=m_images.end() && identical;++it)
00146         {
00147             identical=(val==const_map_get(imgVarVector[*it],*varname).getValue());
00148         };
00149         if(identical)
00150         {
00151             GetImageVariableControl(this, *varname)->SetValue(hugin_utils::doubleTowxString(val,ndigits));
00152         };
00153     };
00154 };
00155 
00156 void ImageVariableDialog::SetGuiLevel(GuiLevel newLevel)
00157 {
00158     // translation
00159     XRCCTRL(*this, "image_variable_text_translation", wxStaticText)->Show(newLevel==GUI_EXPERT);
00160     XRCCTRL(*this, "image_variable_text_translation_x", wxStaticText)->Show(newLevel==GUI_EXPERT);
00161     XRCCTRL(*this, "image_variable_text_translation_y", wxStaticText)->Show(newLevel==GUI_EXPERT);
00162     XRCCTRL(*this, "image_variable_text_translation_z", wxStaticText)->Show(newLevel==GUI_EXPERT);
00163     XRCCTRL(*this, "image_variable_text_translation_Tpy", wxStaticText)->Show(newLevel==GUI_EXPERT);
00164     XRCCTRL(*this, "image_variable_text_translation_Tpp", wxStaticText)->Show(newLevel==GUI_EXPERT);
00165     XRCCTRL(*this, "image_variable_TrX", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00166     XRCCTRL(*this, "image_variable_TrY", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00167     XRCCTRL(*this, "image_variable_TrZ", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00168     XRCCTRL(*this, "image_variable_Tpy", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00169     XRCCTRL(*this, "image_variable_Tpp", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00170     // shear
00171     XRCCTRL(*this, "image_variable_text_shear", wxStaticText)->Show(newLevel==GUI_EXPERT);
00172     XRCCTRL(*this, "image_variable_text_shear_g", wxStaticText)->Show(newLevel==GUI_EXPERT);
00173     XRCCTRL(*this, "image_variable_text_shear_t", wxStaticText)->Show(newLevel==GUI_EXPERT);
00174     XRCCTRL(*this, "image_variable_g", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00175     XRCCTRL(*this, "image_variable_t", wxTextCtrl)->Show(newLevel==GUI_EXPERT);
00176 };
00177 
00178 bool ImageVariableDialog::ApplyNewVariables()
00179 {
00180     std::vector<PanoCommand::PanoCommand*> commands;
00181     VariableMap varMap;
00182     for (const char** varname = m_varNames; *varname != 0; ++varname)
00183     {
00184         wxString s=GetImageVariableControl(this, *varname)->GetValue();
00185         if(!s.empty())
00186         {
00187             double val;
00188             if(str2double(s,val))
00189             {
00190                 if(strcmp(*varname, "v")==0)
00191                 {
00192                     switch(m_pano->getImage(*m_images.begin()).getProjection())
00193                     {
00194                         case SrcPanoImage::RECTILINEAR:
00195                             if(val>179)
00196                             {
00197                                 val=179;
00198                             };
00199                             break;
00200                         case SrcPanoImage::FISHEYE_ORTHOGRAPHIC:
00201                             if(val>190)
00202                             {
00203                                 if(wxMessageBox(
00204                                     wxString::Format(_("You have given a field of view of %.2f degrees.\n But the orthographic projection is limited to a field of view of 180 degress.\nDo you want still use that high value?"), val),
00205 #ifdef __WXMSW__
00206                                     _("Hugin"),
00207 #else
00208                                     wxT(""),
00209 #endif
00210                                     wxICON_EXCLAMATION | wxYES_NO)==wxNO)
00211                                 {
00212                                     return false;
00213                                 };
00214                             };
00215                             break;
00216                         default:
00217                             break;
00218                     };
00219                 };
00220                 varMap.insert(std::make_pair(std::string(*varname), Variable(std::string(*varname), val)));
00221             }
00222             else
00223             {
00224                 wxLogError(_("Value must be numeric."));
00225                 return false;
00226             };
00227         };
00228     };
00229     int sel=XRCCTRL(*this, "image_variable_responseType", wxChoice)->GetSelection();
00230     if(sel!=wxNOT_FOUND)
00231     {
00232         std::vector<SrcPanoImage> SrcImgs;
00233         for (UIntSet::const_iterator it=m_images.begin(); it!=m_images.end(); ++it)
00234         {
00235             HuginBase::SrcPanoImage img=m_pano->getSrcImage(*it);
00236             img.setResponseType((SrcPanoImage::ResponseType)sel);
00237             SrcImgs.push_back(img);
00238         }
00239         commands.push_back(new PanoCommand::UpdateSrcImagesCmd( *m_pano, m_images, SrcImgs ));
00240     }
00241     if(varMap.size()>0)
00242     {
00243         for(UIntSet::const_iterator it=m_images.begin();it!=m_images.end();++it)
00244         {
00245             commands.push_back(
00246                 new PanoCommand::UpdateImageVariablesCmd(*m_pano,*it,varMap)
00247                 );
00248         };
00249     };
00250     if(commands.size()>0)
00251     {
00252         PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::CombinedPanoCommand(*m_pano, commands));
00253         return true;
00254     }
00255     else
00256     {
00257         return false;
00258     };
00259 };
00260 
00261 void ImageVariableDialog::OnOk(wxCommandEvent & e)
00262 {
00263     if(ApplyNewVariables())
00264     {
00265         e.Skip();
00266     };
00267 };
00268 
00269 void ImageVariableDialog::OnHelp(wxCommandEvent & e)
00270 {
00271     // open help on appropriate page
00272     switch(XRCCTRL(*this, "image_variable_notebook", wxNotebook)->GetSelection())
00273     {
00274         //lens parameters
00275         case 1:
00276             MainFrame::Get()->DisplayHelp(wxT("/Lens_correction_model.html"));
00277             break;
00278         case 2:
00279             MainFrame::Get()->DisplayHelp(wxT("/Vignetting.html"));
00280             break;
00281         case 3:
00282             MainFrame::Get()->DisplayHelp(wxT("/Camera_response_curve.html"));
00283             break;
00284         default:
00285             MainFrame::Get()->DisplayHelp(wxT("/Image_positioning_model.html"));
00286             break;
00287     };
00288 };
00289 
00290 const char *ImageVariableDialog::m_varNames[] = { "y", "p", "r", "TrX", "TrY", "TrZ", "Tpy", "Tpp", 
00291                                   "v", "a", "b", "c", "d", "e", "g", "t",
00292                                   "Eev", "Er", "Eb", 
00293                                   "Vb", "Vc", "Vd", "Vx", "Vy",
00294                                   "Ra", "Rb", "Rc", "Rd", "Re", 0};
00295 
00296 IMPLEMENT_CLASS(GraphPopupWindow, wxPopupTransientWindow)
00297 
00298 BEGIN_EVENT_TABLE(GraphPopupWindow, wxPopupTransientWindow)
00299 EVT_LEFT_DOWN(GraphPopupWindow::OnLeftDown)
00300 END_EVENT_TABLE()
00301 
00302 GraphPopupWindow::GraphPopupWindow(wxWindow* parent, wxBitmap bitmap) : wxPopupTransientWindow(parent)
00303 {
00304     wxPanel* panel=new wxPanel(this);
00305     m_bitmapControl=new wxStaticBitmap(panel, wxID_ANY, bitmap);
00306     panel->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(GraphPopupWindow::OnLeftDown), NULL, this);
00307     m_bitmapControl->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(GraphPopupWindow::OnLeftDown), NULL, this);
00308     m_bitmapControl->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(GraphPopupWindow::OnRightDown), NULL, this);
00309     wxBoxSizer* topsizer=new wxBoxSizer(wxHORIZONTAL);
00310     topsizer->Add(m_bitmapControl);
00311     panel->SetSizer(topsizer);
00312     topsizer->Fit(panel);
00313     topsizer->Fit(this);
00314 };
00315 
00316 void GraphPopupWindow::OnLeftDown(wxMouseEvent &e)
00317 {
00318     Dismiss();
00319 };
00320 
00321 void GraphPopupWindow::OnRightDown(wxMouseEvent &e)
00322 {
00323     wxConfigBase* config=wxConfigBase::Get();
00324     wxFileDialog dlg(this,
00325                         _("Save graph"),
00326                         config->Read(wxT("/actualPath"),wxT("")), wxT(""),
00327                         _("Bitmap (*.bmp)|*.bmp|PNG-File (*.png)|*.png"),
00328                         wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
00329     dlg.SetDirectory(config->Read(wxT("/actualPath"),wxT("")));
00330     dlg.SetFilterIndex(config->Read(wxT("/lastImageTypeIndex"), 0l));
00331     if (dlg.ShowModal() == wxID_OK)
00332     {
00333         config->Write(wxT("/actualPath"), dlg.GetDirectory());  // remember for later
00334         wxFileName filename(dlg.GetPath());
00335         int imageType=dlg.GetFilterIndex();
00336         config->Write(wxT("/lastImageTypeIndex"), imageType);
00337         if(!filename.HasExt())
00338         {
00339             switch(imageType)
00340             {
00341                 case 1:
00342                     filename.SetExt(wxT("png"));
00343                     break;
00344                 case 0:
00345                 default:
00346                     filename.SetExt(wxT("bmp"));
00347                     break;
00348             };
00349         };
00350         if (filename.FileExists())
00351         {
00352             int d = wxMessageBox(wxString::Format(_("File %s exists. Overwrite?"), filename.GetFullPath().c_str()),
00353                                  _("Save image"), wxYES_NO | wxICON_QUESTION);
00354             if (d != wxYES)
00355             {
00356                 return;
00357             }
00358         }
00359         switch(imageType)
00360         {
00361             case 1:
00362                 m_bitmapControl->GetBitmap().SaveFile(filename.GetFullPath(), wxBITMAP_TYPE_PNG);
00363                 break;
00364             case 0:
00365             default:
00366                 m_bitmapControl->GetBitmap().SaveFile(filename.GetFullPath(), wxBITMAP_TYPE_BMP);
00367                 break;
00368         };
00369     };
00370 };
00371 
00373 class Graph
00374 {
00375 public:
00377     Graph(int graphWidth, int graphHeight, wxColour backgroundColour)
00378     {
00379         m_width=graphWidth;
00380         m_height=graphHeight;
00381         //create bitmap
00382         m_bitmap=new wxBitmap(m_width, m_height);
00383         m_dc.SelectObject(*m_bitmap);
00384         m_dc.SetBackground(wxBrush(backgroundColour));
00385         m_dc.Clear();
00386         //draw border
00387         m_dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
00388         m_dc.SetBrush(*wxTRANSPARENT_BRUSH);
00389         m_dc.DrawRectangle(0, 0, m_width, m_height);
00390         SetChartArea(0,0, m_width, m_height);
00391         SetChartDisplay(0,0,1,1);
00392     };
00393 
00395     ~Graph()
00396     {
00397         m_dc.SelectObject(wxNullBitmap);
00398     };
00399 
00401     void SetChartArea(int left, int top, int right, int bottom)
00402     {
00403         m_dc.DestroyClippingRegion();
00404         m_left=left;
00405         m_top=top;
00406         m_right=right;
00407         m_bottom=bottom;
00408         m_dc.SetClippingRegion(m_left-1, m_top-1, m_right-m_left+2, m_bottom-m_top+2);
00409     };
00410 
00412     void SetChartDisplay(double xmin, double ymin, double xmax, double ymax)
00413     {
00414         m_xmin=xmin;
00415         m_ymin=ymin;
00416         m_xmax=xmax;
00417         m_ymax=ymax;
00418     };
00419 
00421     void DrawGrid(size_t linesX, size_t linesY)
00422     {
00423         m_dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
00424         for(size_t i=0; i<linesX; i++)
00425         {
00426             int x=TransformX((double)i*(m_xmax-m_xmin)/(linesX-1)+m_xmin);
00427             m_dc.DrawLine(x, m_top, x, m_bottom);
00428         };
00429         for(size_t i=0; i<linesY; i++)
00430         {
00431             int y=TransformY((double)i*(m_ymax-m_ymin)/(linesY-1)+m_ymin);
00432             m_dc.DrawLine(m_left, y, m_right, y);
00433         };
00434     };
00435 
00437     void DrawLine(std::vector<hugin_utils::FDiff2D> points, wxColour colour, int penWidth=1)
00438     {
00439         if(points.size()<2)
00440         {
00441             return;
00442         };
00443         wxPoint *polygonPoints=new wxPoint[points.size()];
00444         for(size_t i=0; i<points.size(); i++)
00445         {
00446             polygonPoints[i].x=TransformX(points[i].x);
00447             polygonPoints[i].y=TransformY(points[i].y);
00448         };
00449         m_dc.SetPen(wxPen(colour, penWidth));
00450         m_dc.DrawLines(points.size(), polygonPoints);
00451         delete []polygonPoints;
00452     };
00453 
00454     const wxBitmap GetGraph() const { return *m_bitmap; };
00455 private:
00456     // prevent copying of class
00457     Graph(const Graph&);
00458     Graph& operator=(const Graph&);
00459     //helper function to transform coordinates from real world to bitmap
00460     int TransformX(double x)
00461     {
00462         return hugin_utils::round((x-m_xmin)/(m_xmax-m_xmin)*(m_right-m_left)+m_left);
00463     };
00464     int TransformY(double y)
00465     {
00466         return hugin_utils::round(m_bottom - (y - m_ymin) / (m_ymax - m_ymin)*(m_bottom - m_top));
00467     };
00468     // area to be drawn
00469     double m_xmin, m_xmax, m_ymin, m_ymax;
00470     // size of canvas
00471     int m_width, m_height;
00472     // chart area
00473     int m_left, m_top, m_right, m_bottom;
00474     // bitmap
00475     wxBitmap* m_bitmap;
00476     wxMemoryDC m_dc;
00477 };
00478 
00479 void ImageVariableDialog::OnShowDistortionGraph(wxCommandEvent & e)
00480 {
00481     wxString stringa=GetImageVariableControl(this, "a")->GetValue();
00482     wxString stringb=GetImageVariableControl(this, "b")->GetValue();
00483     wxString stringc=GetImageVariableControl(this, "c")->GetValue();
00484     if(stringa.empty() || stringb.empty() || stringc.empty())
00485     {
00486         wxBell();
00487         return;
00488     };
00489     std::vector<double> radialDist(4 ,0);
00490     if(!str2double(stringa, radialDist[0]) || !str2double(stringb, radialDist[1]) || !str2double(stringc, radialDist[2]))
00491     {
00492         wxBell();
00493         return;
00494     };
00495     radialDist[3] = 1 - radialDist[0] - radialDist[1] - radialDist[2];
00496 
00497     //create transformation
00498     SrcPanoImage srcImage;
00499 #define NRPOINTS 100
00500     srcImage.setSize(m_pano->getImage(*(m_images.begin())).getSize());
00501     // set projection to rectilinear, just in case, it should be the default value
00502     srcImage.setProjection(SrcPanoImage::RECTILINEAR);
00503     srcImage.setRadialDistortion(radialDist);
00504     PanoramaOptions opts;
00505     opts.setHFOV(srcImage.getHFOV());
00506     opts.setProjection(PanoramaOptions::RECTILINEAR);
00507     opts.setWidth(srcImage.getWidth());
00508     opts.setHeight(srcImage.getHeight());
00509     HuginBase::PTools::Transform transform;
00510     transform.createTransform(srcImage, opts);
00511 
00512     const double minLength = std::min<double>(srcImage.getWidth(), srcImage.getHeight()) / 2.0;
00513     const double maxR = sqrt(srcImage.getWidth()*srcImage.getWidth() + srcImage.getHeight()*srcImage.getHeight()) / (2.0*minLength);
00514     //draw graph
00515     delete m_popup;
00516     Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
00517     graph.SetChartArea(10, 10, 290, 190);
00518     graph.SetChartDisplay(0, -0.1, maxR, 0.1);
00519     graph.DrawGrid(6, 7);
00520     std::vector<hugin_utils::FDiff2D> points;
00521     // draw helper lines
00522     // help line at r=1
00523     points.push_back(hugin_utils::FDiff2D(1, -0.1));
00524     points.push_back(hugin_utils::FDiff2D(1, 0.1));
00525     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1);
00526     points.clear();
00527     // helper line at r=width/height (for landscape images), maximal radius in horizontal (or vertical) direction
00528     // chart goes to r for diagonal
00529     const double rMaxHorzVert = std::max<double>(srcImage.getWidth(), srcImage.getHeight()) / (2.0*minLength);
00530     points.push_back(hugin_utils::FDiff2D(rMaxHorzVert, -0.1));
00531     points.push_back(hugin_utils::FDiff2D(rMaxHorzVert, 0.1));
00532     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1);
00533     points.clear();
00534     // now draw distortion graph
00535     double r = 0;
00536     for(size_t i=0; i<NRPOINTS; i++)
00537     {
00538         double x,y;
00539         if (transform.transform(x, y, r*minLength, 0))
00540         {
00541             points.push_back(hugin_utils::FDiff2D(r, x/minLength - r));
00542         };
00543         r += maxR / (NRPOINTS-1);
00544     };
00545     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00546 
00547     //show popup
00548     m_popup = new GraphPopupWindow(this, graph.GetGraph());
00549     wxWindow *button = (wxWindow*) e.GetEventObject();
00550     wxPoint pos=button->ClientToScreen(wxPoint(0,0));
00551     m_popup->Position(pos, button->GetSize());
00552     m_popup->Popup();
00553 };
00554 
00555 void ImageVariableDialog::OnShowVignettingGraph(wxCommandEvent & e)
00556 {
00557     wxString stringVb=GetImageVariableControl(this, "Vb")->GetValue();
00558     wxString stringVc=GetImageVariableControl(this, "Vc")->GetValue();
00559     wxString stringVd=GetImageVariableControl(this, "Vd")->GetValue();
00560     if(stringVb.empty() || stringVc.empty() || stringVd.empty())
00561     {
00562         wxBell();
00563         return;
00564     };
00565     std::vector<double> vigCorr(4,0);
00566     vigCorr[0]=1.0;
00567     if(!str2double(stringVb, vigCorr[1]) || !str2double(stringVc, vigCorr[2]) || !str2double(stringVd,  vigCorr[3]))
00568     {
00569         wxBell();
00570         return;
00571     };
00572     delete m_popup;
00573     Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
00574     graph.SetChartArea(10, 10, 290, 190);
00575     graph.SetChartDisplay(0, 0.8, 1, 1);
00576     graph.DrawGrid(6, 6);
00577 
00578     //create ResponseTransform with vignetting only
00579     SrcPanoImage srcImage;
00580     srcImage.setRadialVigCorrCoeff(vigCorr);
00581     srcImage.setSize(vigra::Size2D(2*NRPOINTS, 2*NRPOINTS));
00582     Photometric::ResponseTransform<double> transform(srcImage);
00583     transform.enforceMonotonicity();
00584 
00585     //now calc vignetting curve
00586     std::vector<hugin_utils::FDiff2D> points;
00587 #define NRPOINTS 100
00588     for(size_t i=0; i<=NRPOINTS; i++)
00589     {
00590         points.push_back(hugin_utils::FDiff2D(i/double(NRPOINTS),transform(1.0, hugin_utils::FDiff2D(NRPOINTS-i, NRPOINTS-i))));
00591     };
00592     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00593 
00594     //display popup
00595     m_popup = new GraphPopupWindow(this, graph.GetGraph());
00596     wxWindow *button = (wxWindow*) e.GetEventObject();
00597     wxPoint pos=button->ClientToScreen(wxPoint(0,0));
00598     m_popup->Position(pos, button->GetSize());
00599     m_popup->Popup();
00600 };
00601 
00602 void ImageVariableDialog::OnShowResponseGraph(wxCommandEvent & e)
00603 {
00604     SrcPanoImage::ResponseType responseType=(SrcPanoImage::ResponseType)XRCCTRL(*this, "image_variable_responseType", wxChoice)->GetSelection();
00605     wxString stringRa=GetImageVariableControl(this, "Ra")->GetValue();
00606     wxString stringRb=GetImageVariableControl(this, "Rb")->GetValue();
00607     wxString stringRc=GetImageVariableControl(this, "Rc")->GetValue();
00608     wxString stringRd=GetImageVariableControl(this, "Rd")->GetValue();
00609     wxString stringRe=GetImageVariableControl(this, "Re")->GetValue();
00610     if(stringRa.empty() || stringRb.empty() || stringRc.empty() || stringRd.empty() || stringRe.empty())
00611     {
00612         wxBell();
00613         return;
00614     };
00615     double Ra, Rb, Rc, Rd, Re;
00616     if(!str2double(stringRa, Ra) || !str2double(stringRb, Rb) || !str2double(stringRc, Rc) ||
00617         !str2double(stringRd, Rd) || !str2double(stringRe, Re))
00618     {
00619         wxBell();
00620         return;
00621     };
00622     delete m_popup;
00623     Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
00624     graph.SetChartArea(10, 10, 290, 190);
00625     graph.SetChartDisplay(0, 0, 1, 1);
00626     graph.DrawGrid(6, 6);
00627     switch(responseType)
00628     {
00629         case SrcPanoImage::RESPONSE_EMOR:
00630             {
00631                 //draw standard EMOR curve
00632                 std::vector<float> emor(5, 0.0);
00633                 std::vector<double> outLutStd;
00634                 vigra_ext::EMoR::createEMoRLUT(emor, outLutStd);
00635                 vigra_ext::enforceMonotonicity(outLutStd);
00636                 graph.SetChartDisplay(0, 0, outLutStd.size()-1.0, 1.0);
00637                 std::vector<hugin_utils::FDiff2D> points;
00638                 for(size_t i=0; i<outLutStd.size(); i++)
00639                 {
00640                     points.push_back(hugin_utils::FDiff2D(i, outLutStd[i]));
00641                 };
00642                 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 1);
00643                 outLutStd.clear();
00644                 points.clear();
00645                 // now draw our curve
00646                 emor[0]=Ra;
00647                 emor[1]=Rb;
00648                 emor[2]=Rc;
00649                 emor[3]=Rd;
00650                 emor[4]=Re;
00651                 std::vector<double> outLut;
00652                 vigra_ext::EMoR::createEMoRLUT(emor, outLut);
00653                 vigra_ext::enforceMonotonicity(outLut);
00654                 graph.SetChartDisplay(0, 0, outLut.size()-1.0, 1.0);
00655                 for(size_t i=0; i<outLut.size(); i++)
00656                 {
00657                     points.push_back(hugin_utils::FDiff2D(i, outLut[i]));
00658                 };
00659                 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00660             };
00661             break;
00662         case SrcPanoImage::RESPONSE_LINEAR:
00663         default:
00664             {
00665                 std::vector<hugin_utils::FDiff2D> points;
00666                 points.push_back(hugin_utils::FDiff2D(0, 0));
00667                 points.push_back(hugin_utils::FDiff2D(1, 1));
00668                 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00669             };
00670             break;
00671     };
00672     //show popup
00673     m_popup = new GraphPopupWindow(this, graph.GetGraph());
00674     wxWindow *button = (wxWindow*) e.GetEventObject();
00675     wxPoint pos=button->ClientToScreen(wxPoint(0,0));
00676     m_popup->Position(pos, button->GetSize());
00677     m_popup->Popup();
00678 };

Generated on 2 Sep 2015 for Hugintrunk by  doxygen 1.4.7