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

Generated on 5 Dec 2014 for Hugintrunk by  doxygen 1.4.7