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 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, HuginBase::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     HuginBase::BaseSrcPanoImage::ResponseType responseType = m_pano->getImage(*m_images.begin()).getResponseType();
00109     bool identical=true;
00110 
00111     for (HuginBase::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     HuginBase::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(HuginBase::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<PanoCommand::PanoCommand*> commands;
00179     HuginBase::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(hugin_utils::str2double(s,val))
00187             {
00188                 if(strcmp(*varname, "v")==0)
00189                 {
00190                     switch(m_pano->getImage(*m_images.begin()).getProjection())
00191                     {
00192                         case HuginBase::SrcPanoImage::RECTILINEAR:
00193                             if(val>179)
00194                             {
00195                                 val=179;
00196                             };
00197                             break;
00198                         case HuginBase::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), HuginBase::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<HuginBase::SrcPanoImage> SrcImgs;
00231         for (HuginBase::UIntSet::const_iterator it=m_images.begin(); it!=m_images.end(); ++it)
00232         {
00233             HuginBase::SrcPanoImage img=m_pano->getSrcImage(*it);
00234             img.setResponseType((HuginBase::SrcPanoImage::ResponseType)sel);
00235             SrcImgs.push_back(img);
00236         }
00237         commands.push_back(new PanoCommand::UpdateSrcImagesCmd( *m_pano, m_images, SrcImgs ));
00238     }
00239     if(varMap.size()>0)
00240     {
00241         for(HuginBase::UIntSet::const_iterator it=m_images.begin();it!=m_images.end();++it)
00242         {
00243             commands.push_back(
00244                 new PanoCommand::UpdateImageVariablesCmd(*m_pano,*it,varMap)
00245                 );
00246         };
00247     };
00248     if(commands.size()>0)
00249     {
00250         PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::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 | wxFD_OVERWRITE_PROMPT, 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     // prevent copying of class
00455     Graph(const Graph&);
00456     Graph& operator=(const Graph&);
00457     //helper function to transform coordinates from real world to bitmap
00458     int TransformX(double x)
00459     {
00460         return hugin_utils::round((x-m_xmin)/(m_xmax-m_xmin)*(m_right-m_left)+m_left);
00461     };
00462     int TransformY(double y)
00463     {
00464         return hugin_utils::round(m_bottom - (y - m_ymin) / (m_ymax - m_ymin)*(m_bottom - m_top));
00465     };
00466     // area to be drawn
00467     double m_xmin, m_xmax, m_ymin, m_ymax;
00468     // size of canvas
00469     int m_width, m_height;
00470     // chart area
00471     int m_left, m_top, m_right, m_bottom;
00472     // bitmap
00473     wxBitmap* m_bitmap;
00474     wxMemoryDC m_dc;
00475 };
00476 
00477 void ImageVariableDialog::OnShowDistortionGraph(wxCommandEvent & e)
00478 {
00479     wxString stringa=GetImageVariableControl(this, "a")->GetValue();
00480     wxString stringb=GetImageVariableControl(this, "b")->GetValue();
00481     wxString stringc=GetImageVariableControl(this, "c")->GetValue();
00482     if(stringa.empty() || stringb.empty() || stringc.empty())
00483     {
00484         wxBell();
00485         return;
00486     };
00487     std::vector<double> radialDist(4 ,0);
00488     if(!hugin_utils::str2double(stringa, radialDist[0]) || !hugin_utils::str2double(stringb, radialDist[1]) || !hugin_utils::str2double(stringc, radialDist[2]))
00489     {
00490         wxBell();
00491         return;
00492     };
00493     radialDist[3] = 1 - radialDist[0] - radialDist[1] - radialDist[2];
00494 
00495     //create transformation
00496     HuginBase::SrcPanoImage srcImage;
00497 #define NRPOINTS 100
00498     srcImage.setSize(m_pano->getImage(*(m_images.begin())).getSize());
00499     // set projection to rectilinear, just in case, it should be the default value
00500     srcImage.setProjection(HuginBase::SrcPanoImage::RECTILINEAR);
00501     srcImage.setRadialDistortion(radialDist);
00502     HuginBase::PanoramaOptions opts;
00503     opts.setHFOV(srcImage.getHFOV());
00504     opts.setProjection(HuginBase::PanoramaOptions::RECTILINEAR);
00505     opts.setWidth(srcImage.getWidth());
00506     opts.setHeight(srcImage.getHeight());
00507     HuginBase::PTools::Transform transform;
00508     transform.createTransform(srcImage, opts);
00509 
00510     const double minLength = std::min<double>(srcImage.getWidth(), srcImage.getHeight()) / 2.0;
00511     const double maxR = std::sqrt(static_cast<double>(srcImage.getWidth()*srcImage.getWidth() + srcImage.getHeight()*srcImage.getHeight()) )/ (2.0*minLength);
00512     //draw graph
00513     delete m_popup;
00514     Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
00515     graph.SetChartArea(10, 10, 290, 190);
00516     graph.SetChartDisplay(0, -0.1, maxR, 0.1);
00517     graph.DrawGrid(6, 7);
00518     std::vector<hugin_utils::FDiff2D> points;
00519     // draw helper lines
00520     // help line at r=1
00521     points.push_back(hugin_utils::FDiff2D(1, -0.1));
00522     points.push_back(hugin_utils::FDiff2D(1, 0.1));
00523     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1);
00524     points.clear();
00525     // helper line at r=width/height (for landscape images), maximal radius in horizontal (or vertical) direction
00526     // chart goes to r for diagonal
00527     const double rMaxHorzVert = std::max<double>(srcImage.getWidth(), srcImage.getHeight()) / (2.0*minLength);
00528     points.push_back(hugin_utils::FDiff2D(rMaxHorzVert, -0.1));
00529     points.push_back(hugin_utils::FDiff2D(rMaxHorzVert, 0.1));
00530     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1);
00531     points.clear();
00532     // now draw distortion graph
00533     double r = 0;
00534     for(size_t i=0; i<NRPOINTS; i++)
00535     {
00536         double x,y;
00537         if (transform.transform(x, y, r*minLength, 0))
00538         {
00539             points.push_back(hugin_utils::FDiff2D(r, x/minLength - r));
00540         };
00541         r += maxR / (NRPOINTS-1);
00542     };
00543     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00544 
00545     //show popup
00546     m_popup = new GraphPopupWindow(this, graph.GetGraph());
00547     wxWindow *button = (wxWindow*) e.GetEventObject();
00548     wxPoint pos=button->ClientToScreen(wxPoint(0,0));
00549     m_popup->Position(pos, button->GetSize());
00550     m_popup->Popup();
00551 };
00552 
00553 void ImageVariableDialog::OnShowVignettingGraph(wxCommandEvent & e)
00554 {
00555     wxString stringVb=GetImageVariableControl(this, "Vb")->GetValue();
00556     wxString stringVc=GetImageVariableControl(this, "Vc")->GetValue();
00557     wxString stringVd=GetImageVariableControl(this, "Vd")->GetValue();
00558     if(stringVb.empty() || stringVc.empty() || stringVd.empty())
00559     {
00560         wxBell();
00561         return;
00562     };
00563     std::vector<double> vigCorr(4,0);
00564     vigCorr[0]=1.0;
00565     if(!hugin_utils::str2double(stringVb, vigCorr[1]) || !hugin_utils::str2double(stringVc, vigCorr[2]) || !hugin_utils::str2double(stringVd,  vigCorr[3]))
00566     {
00567         wxBell();
00568         return;
00569     };
00570     delete m_popup;
00571     Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
00572     graph.SetChartArea(10, 10, 290, 190);
00573     graph.SetChartDisplay(0, 0.8, 1, 1);
00574     graph.DrawGrid(6, 6);
00575 
00576     //create ResponseTransform with vignetting only
00577     HuginBase::SrcPanoImage srcImage;
00578     srcImage.setRadialVigCorrCoeff(vigCorr);
00579     srcImage.setSize(vigra::Size2D(2*NRPOINTS, 2*NRPOINTS));
00580     HuginBase::Photometric::ResponseTransform<double> transform(srcImage);
00581     transform.enforceMonotonicity();
00582 
00583     //now calc vignetting curve
00584     std::vector<hugin_utils::FDiff2D> points;
00585 #define NRPOINTS 100
00586     for(size_t i=0; i<=NRPOINTS; i++)
00587     {
00588         points.push_back(hugin_utils::FDiff2D(i/double(NRPOINTS),transform(1.0, hugin_utils::FDiff2D(NRPOINTS-i, NRPOINTS-i))));
00589     };
00590     graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00591 
00592     //display popup
00593     m_popup = new GraphPopupWindow(this, graph.GetGraph());
00594     wxWindow *button = (wxWindow*) e.GetEventObject();
00595     wxPoint pos=button->ClientToScreen(wxPoint(0,0));
00596     m_popup->Position(pos, button->GetSize());
00597     m_popup->Popup();
00598 };
00599 
00600 void ImageVariableDialog::OnShowResponseGraph(wxCommandEvent & e)
00601 {
00602     HuginBase::SrcPanoImage::ResponseType responseType=(HuginBase::SrcPanoImage::ResponseType)XRCCTRL(*this, "image_variable_responseType", wxChoice)->GetSelection();
00603     wxString stringRa=GetImageVariableControl(this, "Ra")->GetValue();
00604     wxString stringRb=GetImageVariableControl(this, "Rb")->GetValue();
00605     wxString stringRc=GetImageVariableControl(this, "Rc")->GetValue();
00606     wxString stringRd=GetImageVariableControl(this, "Rd")->GetValue();
00607     wxString stringRe=GetImageVariableControl(this, "Re")->GetValue();
00608     if(stringRa.empty() || stringRb.empty() || stringRc.empty() || stringRd.empty() || stringRe.empty())
00609     {
00610         wxBell();
00611         return;
00612     };
00613     double Ra, Rb, Rc, Rd, Re;
00614     if(!hugin_utils::str2double(stringRa, Ra) || !hugin_utils::str2double(stringRb, Rb) || !hugin_utils::str2double(stringRc, Rc) ||
00615         !hugin_utils::str2double(stringRd, Rd) || !hugin_utils::str2double(stringRe, Re))
00616     {
00617         wxBell();
00618         return;
00619     };
00620     delete m_popup;
00621     Graph graph(300, 200, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
00622     graph.SetChartArea(10, 10, 290, 190);
00623     graph.SetChartDisplay(0, 0, 1, 1);
00624     graph.DrawGrid(6, 6);
00625     switch(responseType)
00626     {
00627         case HuginBase::SrcPanoImage::RESPONSE_EMOR:
00628             {
00629                 //draw standard EMOR curve
00630                 std::vector<float> emor(5, 0.0);
00631                 std::vector<double> outLutStd;
00632                 vigra_ext::EMoR::createEMoRLUT(emor, outLutStd);
00633                 vigra_ext::enforceMonotonicity(outLutStd);
00634                 graph.SetChartDisplay(0, 0, outLutStd.size()-1.0, 1.0);
00635                 std::vector<hugin_utils::FDiff2D> points;
00636                 for(size_t i=0; i<outLutStd.size(); i++)
00637                 {
00638                     points.push_back(hugin_utils::FDiff2D(i, outLutStd[i]));
00639                 };
00640                 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 1);
00641                 outLutStd.clear();
00642                 points.clear();
00643                 // now draw our curve
00644                 emor[0]=Ra;
00645                 emor[1]=Rb;
00646                 emor[2]=Rc;
00647                 emor[3]=Rd;
00648                 emor[4]=Re;
00649                 std::vector<double> outLut;
00650                 vigra_ext::EMoR::createEMoRLUT(emor, outLut);
00651                 vigra_ext::enforceMonotonicity(outLut);
00652                 graph.SetChartDisplay(0, 0, outLut.size()-1.0, 1.0);
00653                 for(size_t i=0; i<outLut.size(); i++)
00654                 {
00655                     points.push_back(hugin_utils::FDiff2D(i, outLut[i]));
00656                 };
00657                 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00658             };
00659             break;
00660         case HuginBase::SrcPanoImage::RESPONSE_LINEAR:
00661         default:
00662             {
00663                 std::vector<hugin_utils::FDiff2D> points;
00664                 points.push_back(hugin_utils::FDiff2D(0, 0));
00665                 points.push_back(hugin_utils::FDiff2D(1, 1));
00666                 graph.DrawLine(points, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 2);
00667             };
00668             break;
00669     };
00670     //show popup
00671     m_popup = new GraphPopupWindow(this, graph.GetGraph());
00672     wxWindow *button = (wxWindow*) e.GetEventObject();
00673     wxPoint pos=button->ClientToScreen(wxPoint(0,0));
00674     m_popup->Position(pos, button->GetSize());
00675     m_popup->Popup();
00676 };

Generated on 28 Apr 2016 for Hugintrunk by  doxygen 1.4.7