wxPanoCommand.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include <config.h>
00028 
00029 #include "panoinc_WX.h"
00030 #include "panoinc.h"
00031 #include "base_wx/wxPlatform.h"
00032 
00033 #include <base_wx/wxImageCache.h>
00034 #include <base_wx/platform.h>
00035 #include <hugin/wxPanoCommand.h>
00036 #include <hugin/MainFrame.h>
00037 #include <panodata/OptimizerSwitches.h>
00038 
00039 #include <vigra/cornerdetection.hxx>
00040 #include <vigra/localminmax.hxx>
00041 #include <panodata/StandardImageVariableGroups.h>
00042 
00043 #include <hugin_utils/alphanum.h>
00044 
00045 #ifdef HUGIN_HSI
00046 #include "hugin_script_interface/hpi.h"
00047 #endif
00048 
00049 using namespace std;
00050 using namespace vigra;
00051 using namespace hugin_utils;
00052 
00053 namespace PT {
00054 
00055 bool wxAddCtrlPointGridCmd::processPanorama(Panorama& pano)
00056 {
00057     // TODO: rewrite, and use same function for modular image creation.
00058 #if 1
00059     const SrcPanoImage & i1 = pano.getImage(img1);
00060     const SrcPanoImage & i2 = pano.getImage(img1);
00061 
00062     // run both images through the harris corner detector
00063     ImageCache::EntryPtr eptr = ImageCache::getInstance().getSmallImage(i1.getFilename());
00064 
00065     vigra::BImage leftImg(eptr->get8BitImage()->size());
00066 
00067     vigra::GreenAccessor<vigra::RGBValue<vigra::UInt8> > ga;
00068     vigra::copyImage(srcImageRange(*(eptr->get8BitImage()), ga ),
00069                      destImage(leftImg));
00070 
00071     double scale = i1.getSize().width() / (double) leftImg.width();
00072 
00073     //const vigra::BImage & leftImg = ImageCache::getInstance().getPyramidImage(
00074     //    i1.getFilename(),1);
00075 
00076     BImage leftCorners(leftImg.size());
00077     FImage leftCornerResponse(leftImg.size());
00078 
00079     // empty corner image
00080     leftCorners.init(0);
00081 
00082     DEBUG_DEBUG("running corner detector threshold: " << cornerThreshold << "  scale: " << scale );
00083 
00084     // find corner response at scale scale
00085     vigra::cornerResponseFunction(srcImageRange(leftImg),
00086         destImage(leftCornerResponse),
00087         scale);
00088 
00089     //    saveScaledImage(leftCornerResponse,"corner_response.png");
00090     DEBUG_DEBUG("finding local maxima");
00091     // find local maxima of corner response, mark with 1
00092     vigra::localMaxima(srcImageRange(leftCornerResponse), destImage(leftCorners), 255);
00093 
00094 //    exportImage(srcImageRange(leftCorners), vigra::ImageExportInfo("c:/corner_response_maxima.png"));
00095 
00096     DEBUG_DEBUG("thresholding corner response");
00097     // threshold corner response to keep only strong corners (above 400.0)
00098     transformImage(srcImageRange(leftCornerResponse), destImage(leftCornerResponse),
00099         vigra::Threshold<double, double>(
00100         cornerThreshold, DBL_MAX, 0.0, 1.0));
00101 
00102     vigra::combineTwoImages(srcImageRange(leftCorners), srcImage(leftCornerResponse),
00103         destImage(leftCorners), std::multiplies<float>());
00104 
00105 //    exportImage(srcImageRange(leftCorners), vigra::ImageExportInfo("c:/corner_response_threshold.png"));
00106 
00107     // create transform from img1 -> sphere
00108     PTools::Transform img1ToSphere;
00109     PTools::Transform sphereToImg2;
00110 
00111     PanoramaOptions opts;
00112     opts.setProjection(PanoramaOptions::EQUIRECTANGULAR);
00113     opts.setHFOV(360);
00114     opts.setWidth(360);
00115     opts.setVFOV(180);
00116 
00117     img1ToSphere.createInvTransform(pano, img1, opts);
00118     sphereToImg2.createTransform(pano, img2, opts);
00119 
00120 
00121     int border = 5;
00122     double sphx, sphy;
00123     double img2x, img2y;
00124     // need to scale the images.
00125     // sample grid on img1 and try to add ctrl points
00126     for (unsigned int x=0; x < (unsigned int)leftImg.width(); x++ ) {
00127         for (unsigned int y=0; y < (unsigned int)leftImg.height(); y++) {
00128             if (leftCorners(x,y) > 0) {
00129                 img1ToSphere.transformImgCoord(sphx, sphy, scale*x, scale*y);
00130                 sphereToImg2.transformImgCoord(img2x, img2y, sphx, sphy);
00131                 // check if it is inside..
00132                 if (   img2x > border && img2x < i2.getWidth() - border
00133                     && img2y > border && img2y < i2.getHeight() - border )
00134                 {
00135                     // add control point
00136                     ControlPoint p(img1, scale*x, scale*y, img2, img2x, img2y);
00137                     pano.addCtrlPoint(p);
00138                 }
00139             }
00140         }
00141     }
00142 #endif
00143     return true;
00144 }
00145 
00146 
00147 bool wxAddImagesCmd::processPanorama(Panorama& pano)
00148 {
00149     // check if the files should be sorted by date
00150     long sort = wxConfigBase::Get()->Read(wxT("General/SortNewImgOnAdd"), HUGIN_GUI_SORT_NEW_IMG_ON_ADD);
00151 
00152     switch (sort) {
00153         case 1:
00154                 // sort by filename
00155             std::sort(files.begin(), files.end(), doj::alphanum_less());
00156             break;
00157         case 2:
00158                 // sort by date
00159             std::sort(files.begin(), files.end(), FileIsNewer());
00160             break;
00161         default:
00162                 // no or unknown sort method
00163             break;
00164     }
00165 
00166     std::vector<std::string>::const_iterator it;
00167 
00168 
00169     double cropFactor = 0;
00170     double focalLength = 0;
00171 
00172     Lens lens;
00173     SrcPanoImage srcImg;
00174     HuginBase::StandardImageVariableGroups variable_groups(pano);
00175     HuginBase::ImageVariableGroup & lenses = variable_groups.getLenses();
00176 
00177     // load additional images...
00178     for (it = files.begin(); it != files.end(); ++it) {
00179         bool added = false;
00180         const std::string &filename = *it;
00181         wxString fname(filename.c_str(), HUGIN_CONV_FILENAME);
00182 
00183         int assumeSimilar = wxConfigBase::Get()->Read(wxT("/LensDefaults/AssumeSimilar"), HUGIN_LENS_ASSUME_SIMILAR);
00184         if (!assumeSimilar) {
00185             focalLength = 0;
00186             cropFactor = 0;
00187         }
00188 
00189         // try to read settings automatically.
00190         srcImg.setFilename(filename);
00191         srcImg.setWhiteBalanceRed(1);
00192         srcImg.setWhiteBalanceBlue(1);
00193         bool ok = srcImg.readEXIF(focalLength, cropFactor, true, true);
00194         if(cropFactor<=0)
00195         {
00196             srcImg.readCropfactorFromDB();
00197             ok=(srcImg.getExifFocalLength()>0 && srcImg.getExifCropFactor()>0);
00198         };
00199         if (srcImg.getSize().x == 0 || srcImg.getSize().y == 0) {
00200             wxMessageBox(wxString::Format(_("Could not decode image:\n%s\nAbort"), fname.c_str()), _("Unsupported image file format"));
00201             return false;
00202         }
00203         try
00204         {
00205             vigra::ImageImportInfo info(filename.c_str());
00206             std::string pixelType=info.getPixelType();
00207             if((pixelType=="UINT8") || (pixelType=="UINT16") || (pixelType=="INT16"))
00208                 srcImg.setResponseType(HuginBase::SrcPanoImage::RESPONSE_EMOR);
00209             else
00210                 srcImg.setResponseType(HuginBase::SrcPanoImage::RESPONSE_LINEAR);
00211         }
00212         catch(std::exception & e)
00213         {
00214             std::cerr << "ERROR: caught exception: " << e.what() << std::endl;
00215             std::cerr << "Could not get pixel type for file " << filename << std::endl;
00216         };
00217         if (! ok && assumeSimilar) {
00218                  // search for image with matching size and exif data
00219                  // and re-use it.
00220                 for (unsigned int i=0; i < pano.getNrOfImages(); i++) {
00221                     SrcPanoImage other = pano.getSrcImage(i);
00222                     double dummyfl=0;
00223                     double dummycrop = 0;
00224                     other.readEXIF(dummyfl, dummycrop, false, false);
00225                     if ( other.getSize() == srcImg.getSize()
00226                          &&
00227                          other.getExifModel() == srcImg.getExifModel() &&
00228                          other.getExifMake()  == srcImg.getExifMake() &&
00229                          other.getExifFocalLength() == srcImg.getExifFocalLength()
00230                        )
00231                     {
00232                         double ev = srcImg.getExposureValue();
00233                         srcImg = pano.getSrcImage(i);
00234                         srcImg.setFilename(filename);
00235                         srcImg.deleteAllMasks();
00236                         srcImg.readEXIF(focalLength, cropFactor, false, false);
00237                         // add image
00238                         int imgNr = pano.addImage(srcImg);
00239                         variable_groups.update();
00240                         lenses.switchParts(imgNr, lenses.getPartNumber(i));
00241                         lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_ExposureValue, i);
00242                         srcImg.setExposureValue(ev);
00243                         lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_WhiteBalanceRed, i);
00244                         lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_WhiteBalanceBlue, i);
00245                         srcImg.setWhiteBalanceRed(1);
00246                         srcImg.setWhiteBalanceBlue(1);
00247                         pano.setSrcImage(imgNr, srcImg);
00248                         added=true;
00249                         break;
00250                     }
00251                 }
00252                 if (added) continue;
00253         }
00254         int matchingLensNr=-1;
00255         // if no similar image found, ask user
00256         if (! ok) {
00257             srcImg.readProjectionFromDB();
00258             if (!getLensDataFromUser(MainFrame::Get(), srcImg, focalLength, cropFactor)) {
00259                 // assume a standart lens
00260                 srcImg.setHFOV(50);
00261                 srcImg.setExifCropFactor(1);
00262             }
00263         }
00264 
00265         // check the image hasn't disappeared on us since the HFOV dialog was
00266         // opened
00267         wxString fn(srcImg.getFilename().c_str(),HUGIN_CONV_FILENAME);
00268         if (!wxFileName::FileExists(fn)) {
00269             DEBUG_INFO("Image: " << fn.mb_str() << " has disappeared, skipping...");
00270             continue;
00271         }
00272 
00273         // FIXME: check if the exif information
00274         // indicates this image matches a already used lens
00275         variable_groups.update();
00276         double ev = 0;
00277         bool set_exposure = false;
00278         for (unsigned int i=0; i < pano.getNrOfImages(); i++) {
00279             SrcPanoImage other = pano.getSrcImage(i);
00280             // force reading of exif data, as it is currently not stored in the
00281             // Panorama data class
00282             if (other.readEXIF(focalLength, cropFactor, false, false)) {
00283                 if (other.getSize() == srcImg.getSize()
00284                     && other.getExifModel() == srcImg.getExifModel()
00285                     && other.getExifMake()  == srcImg.getExifMake()
00286                     && other.getExifFocalLength() == srcImg.getExifFocalLength()
00287                    )
00288                 {
00289                     matchingLensNr = lenses.getPartNumber(i);
00290                     // copy data from other image, just keep
00291                     // the file name and reload the exif data (for exposure)
00292                     ev = srcImg.getExposureValue();
00293                     set_exposure = true;
00294                     srcImg = pano.getSrcImage(i);
00295                     srcImg.setFilename(filename);
00296                     srcImg.deleteAllMasks();
00297                     srcImg.readEXIF(focalLength, cropFactor, false, false);
00298                     srcImg.setExposureValue(ev);
00299                     break;
00300                 }
00301             } else if (assumeSimilar) {
00302                 // no exiv information, just check image size.
00303                 if (other.getSize() == srcImg.getSize() ) {
00304                     matchingLensNr = lenses.getPartNumber(i);
00305                     // copy data from other image, just keep
00306                     // the file name
00307                     srcImg = pano.getSrcImage(i);
00308                     srcImg.setFilename(filename);
00309                     srcImg.deleteAllMasks();
00310                     srcImg.readEXIF(focalLength, cropFactor, false, false);
00311                     break;
00312                 }
00313             }
00314         }
00315 
00316         // If matchingLensNr == -1 still, we haven't found a good lens to use.
00317         // We shouldn't attach the image to a lens in this case, it will have
00318         // its own new lens.
00319         srcImg.readProjectionFromDB();
00320         int imgNr = pano.addImage(srcImg);
00321         variable_groups.update();
00322         if (matchingLensNr != -1)
00323         {
00324             lenses.switchParts(imgNr, matchingLensNr);
00325             // unlink and set exposure value, if wanted.
00326             if (set_exposure)
00327             {
00328                 lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_ExposureValue, imgNr);
00329                 lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_WhiteBalanceRed, imgNr);
00330                 lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_WhiteBalanceBlue, imgNr);
00331                 //don't link image size, this will foul the photometric optimizer
00332                 lenses.unlinkVariableImage(HuginBase::ImageVariableGroup::IVE_Size, imgNr);
00334                 SrcPanoImage t = pano.getSrcImage(imgNr);
00335                 t.setExposureValue(ev);
00336                 pano.setSrcImage(imgNr, t);
00337             }
00338         }
00339         if (imgNr == 0) {
00340             // get initial value for output exposure
00341             PanoramaOptions opts = pano.getOptions();
00342             opts.outputExposureValue = srcImg.getExposureValue();
00343             pano.setOptions(opts);
00344             // set the exposure, but there isn't anything to link to so don't try unlinking.
00345             // links are made by default when adding new images.
00346             if (set_exposure)
00347             {
00349                 SrcPanoImage t = pano.getSrcImage(imgNr);
00350                 t.setExposureValue(ev);
00351                 pano.setSrcImage(imgNr, t);
00352             }
00353         }
00354     }
00355     return true;
00356 }
00357 
00358 
00359 bool wxLoadPTProjectCmd::processPanorama(Panorama& pano)
00360 {
00361     PanoramaMemento newPano;
00362     int ptoVersion = 0;
00363     std::ifstream in(filename.c_str());
00364     if (newPano.loadPTScript(in, ptoVersion, prefix))
00365     {
00366         pano.setMemento(newPano);
00367         PanoramaOptions opts = pano.getOptions();
00368         // always reset to TIFF_m ...
00369         opts.outputFormat = PanoramaOptions::TIFF_m;
00370         // get enblend and enfuse options from preferences
00371         if (ptoVersion < 2)
00372         {
00373             // no options stored in file, use default arguments in config file
00374             opts.enblendOptions = wxConfigBase::Get()->Read(wxT("/Enblend/Args"), wxT(HUGIN_ENBLEND_ARGS)).mb_str(wxConvLocal);
00375             opts.enfuseOptions = wxConfigBase::Get()->Read(wxT("/Enfuse/Args"), wxT(HUGIN_ENFUSE_ARGS)).mb_str(wxConvLocal);
00376         }
00377         // Set the nona gpu flag base on what is in preferences as it is not
00378         // stored in the file.
00379         opts.remapUsingGPU = wxConfigBase::Get()->Read(wxT("/Nona/UseGPU"),HUGIN_NONA_USEGPU) == 1;
00380         pano.setOptions(opts);
00381 
00382         HuginBase::StandardImageVariableGroups variableGroups(pano);
00383         HuginBase::ImageVariableGroup & lenses = variableGroups.getLenses();
00384 
00385         unsigned int nImg = pano.getNrOfImages();
00386         wxString basedir;
00387         double focalLength=0;
00388         double cropFactor=0;
00389         bool autopanoSiftFile=false;
00390         SrcPanoImage autopanoSiftRefImg;
00391         for (unsigned int i = 0; i < nImg; i++) {
00392             wxFileName fname(wxString (pano.getImage(i).getFilename().c_str(), HUGIN_CONV_FILENAME));
00393             while (! fname.FileExists()){
00394                         // Is file in the new path
00395                 if (basedir != wxT("")) {
00396                     DEBUG_DEBUG("Old filename: " << pano.getImage(i).getFilename());
00397                     std::string fn = stripPath(pano.getImage(i).getFilename());
00398                     DEBUG_DEBUG("Old filename, without path): " << fn);
00399                     wxString newname(fn.c_str(), HUGIN_CONV_FILENAME);
00400                             // GetFullName does only work with local paths (not compatible across platforms)
00401 //                            wxString newname = fname.GetFullName();
00402                     fname.AssignDir(basedir);
00403                     fname.SetFullName(newname);
00404                     DEBUG_TRACE("filename with new path: " << fname.GetFullPath().mb_str(wxConvLocal));
00405                     if (fname.FileExists()) {
00406                         pano.setImageFilename(i, (const char *)fname.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
00407                         DEBUG_TRACE("New filename set: " << fname.GetFullPath().mb_str(wxConvLocal));
00408                                 // TODO - set pano dirty flag so that new paths are saved
00409                         continue;
00410                     }
00411                 }
00412 
00413                 wxMessageBox(wxString::Format(_("Image file not found:\n%s\nPlease select correct image"), fname.GetFullPath().c_str()), _("Image file not found"));
00414 
00415                 if (basedir == wxT("")) {
00416                     basedir = fname.GetPath();
00417                 }
00418 
00419                 // open file dialog
00420                 wxFileDialog dlg(MainFrame::Get(), _("Add images"),
00421                                  basedir, fname.GetFullName(),
00422                                  HUGIN_WX_FILE_IMG_FILTER, wxFD_OPEN, wxDefaultPosition);
00423                 dlg.SetDirectory(basedir);
00424                 if (dlg.ShowModal() == wxID_OK) {
00425                     pano.setImageFilename(i, (const char *)dlg.GetPath().mb_str(HUGIN_CONV_FILENAME));
00426                             // save used path
00427                     basedir = dlg.GetDirectory();
00428                     DEBUG_INFO("basedir is: " << basedir.mb_str(wxConvLocal));
00429                 } else {
00430                     PanoramaMemento emptyPano;
00431                     pano.setMemento(emptyPano);
00432                             // set an empty panorama
00433                     return true;
00434                 }
00435                 fname.Assign(dlg.GetPath());
00436             }
00437             // check if image size is correct
00438             SrcPanoImage srcImg = pano.getSrcImage(i);
00439             //
00440             vigra::ImageImportInfo imginfo(srcImg.getFilename().c_str());
00441             if (srcImg.getSize() != imginfo.size()) {
00442                 // adjust size properly.
00443                 srcImg.resize(imginfo.size());
00444             }
00445             // check if script contains invalid HFOV
00446             double hfov = pano.getImage(i).getHFOV();
00447             if (pano.getImage(i).getProjection() == HuginBase::SrcPanoImage::RECTILINEAR
00448                 && hfov >= 180 && autopanoSiftFile == false)
00449             {
00450                 autopanoSiftFile = true;
00451                 // something is wrong here, try to read from exif data (all images)
00452                 bool ok = initImageFromFile(srcImg, focalLength, cropFactor, false);
00453                 if (! ok) {
00454                     getLensDataFromUser(MainFrame::Get(), srcImg, focalLength, cropFactor);
00455                 }
00456                 autopanoSiftRefImg = srcImg;
00457             } else if (autopanoSiftFile) {
00458                 // need to copy the lens parameters from the first lens.
00459                 srcImg.setHFOV(autopanoSiftRefImg.getHFOV());
00460             } else {
00461                 // load exif data, but do not apply it
00462                 srcImg.readEXIF(focalLength, cropFactor, false, false);
00463             }
00464             pano.setSrcImage(i, srcImg);
00465         }
00466         // Link image projection across each lens, since it is not saved.
00467         for (unsigned int i = 0; i < lenses.getNumberOfParts(); i++)
00468         {
00469             // link the variables
00470             lenses.linkVariablePart(
00471                                 HuginBase::ImageVariableGroup::IVE_Projection,
00472                                 i
00473                                    );
00474         }
00475     } else {
00476         DEBUG_ERROR("could not load panotools script");
00477     }
00478     in.close();
00479 
00480     // Verify control points are valid
00481     // loop through entire list of points, confirming they are inside the
00482     // bounding box of their images
00483     const PT::CPVector & oldCPs = pano.getCtrlPoints();
00484     PT::CPVector goodCPs;
00485     int bad_cp_count = 0;
00486     for (PT::CPVector::const_iterator it = oldCPs.begin();
00487             it != oldCPs.end(); ++it)
00488     {
00489         PT::ControlPoint point = *it;
00490         const SrcPanoImage & img1 = pano.getImage(point.image1Nr);
00491         const SrcPanoImage & img2 = pano.getImage(point.image2Nr);
00492         if (0 > point.x1 || point.x1 > img1.getSize().x ||
00493             0 > point.y1 || point.y1 > img1.getSize().y ||
00494             0 > point.x2 || point.x2 > img2.getSize().x ||
00495             0 > point.y2 || point.y2 > img2.getSize().y)
00496         {
00497             bad_cp_count++;
00498         } else
00499         {
00500             goodCPs.push_back(point);
00501         }
00502     }
00503 
00504     if (bad_cp_count > 0)
00505     {
00506         wxString errMsg = wxString::Format(_("%d invalid control point(s) found.\n\nPress OK to remove."), bad_cp_count);
00507         wxMessageBox(errMsg, _("Error Detected"), wxICON_ERROR);
00508         pano.setCtrlPoints(goodCPs);
00509     }
00510 
00511     // Update control point error values
00512     HuginBase::PTools::calcCtrlPointErrors(pano);
00513     if(markAsOptimized)
00514     {
00515         pano.markAsOptimized();
00516     };
00517     return true;
00518 }
00519 
00520 bool wxNewProjectCmd::processPanorama(Panorama& pano)
00521 {
00522     pano.reset();
00523 
00524     // Setup pano with options from preferences
00525     PanoramaOptions opts = pano.getOptions();
00526     wxConfigBase* config = wxConfigBase::Get();
00527     opts.quality = config->Read(wxT("/output/jpeg_quality"),HUGIN_JPEG_QUALITY);
00528     switch(config->Read(wxT("/output/tiff_compression"), HUGIN_TIFF_COMPRESSION))
00529     {
00530         case 0:
00531         default:
00532             opts.outputImageTypeCompression = "NONE";
00533             opts.tiffCompression = "NONE";
00534             break;
00535         case 1:
00536             opts.outputImageTypeCompression = "PACKBITS";
00537             opts.tiffCompression = "PACKBITS";
00538             break;
00539         case 2:
00540             opts.outputImageTypeCompression = "LZW";
00541             opts.tiffCompression = "LZW";
00542             break;
00543         case 3:
00544             opts.outputImageTypeCompression = "DEFLATE";
00545             opts.tiffCompression = "DEFLATE";
00546             break;
00547     }
00548     switch (config->Read(wxT("/output/ldr_format"), HUGIN_LDR_OUTPUT_FORMAT)) {
00549     case 1:
00550         opts.outputImageType ="jpg";
00551         break;
00552     case 2:
00553         opts.outputImageType ="png";
00554         break;
00555     case 3:
00556         opts.outputImageType ="exr";
00557         break;
00558     default:
00559     case 0:
00560         opts.outputImageType ="tif";
00561         break;
00562     }
00563     // HDR disabled because there is no real choice at the moment:  HDR TIFF is broken and there is only EXR
00564     // opts.outputImageTypeHDR = config->Read(wxT("/output/hdr_format"), HUGIN_HDR_OUTPUT_FORMAT);
00565     opts.outputFormat = PanoramaOptions::TIFF_m;
00566     opts.blendMode = PanoramaOptions::ENBLEND_BLEND;
00567     opts.enblendOptions = config->Read(wxT("Enblend/Args"),wxT(HUGIN_ENBLEND_ARGS)).mb_str(wxConvLocal);
00568     opts.enfuseOptions = config->Read(wxT("Enfuse/Args"),wxT(HUGIN_ENFUSE_ARGS)).mb_str(wxConvLocal);
00569     opts.interpolator = (vigra_ext::Interpolator)config->Read(wxT("Nona/Interpolator"),HUGIN_NONA_INTERPOLATOR);
00570     opts.remapUsingGPU = config->Read(wxT("Nona/useGPU"),HUGIN_NONA_USEGPU)!=0;
00571     opts.tiff_saveROI = config->Read(wxT("Nona/CroppedImages"),HUGIN_NONA_CROPPEDIMAGES)!=0;
00572     opts.hdrMergeMode = PanoramaOptions::HDRMERGE_AVERAGE;
00573     opts.hdrmergeOptions = HUGIN_HDRMERGE_ARGS;
00574     pano.setOptions(opts);
00575 
00576     pano.setOptimizerSwitch(HuginBase::OPT_PAIR);
00577     pano.setPhotometricOptimizerSwitch(HuginBase::OPT_EXPOSURE | HuginBase::OPT_VIGNETTING | HuginBase::OPT_RESPONSE);
00578     return true;
00579 }
00580 
00581 
00582 bool wxApplyTemplateCmd::processPanorama(Panorama& pano)
00583 {
00584     wxConfigBase* config = wxConfigBase::Get();
00585 
00586     if (pano.getNrOfImages() == 0) {
00587         // TODO: prompt for images!
00588         wxString path = config->Read(wxT("actualPath"), wxT(""));
00589         wxFileDialog dlg(MainFrame::Get(), _("Add images"),
00590                 path, wxT(""),
00591                 HUGIN_WX_FILE_IMG_FILTER, wxFD_OPEN|wxFD_MULTIPLE , wxDefaultPosition);
00592         dlg.SetDirectory(path);
00593 
00594         // remember the image extension
00595         wxString img_ext;
00596         if (config->HasEntry(wxT("lastImageType"))){
00597             img_ext = config->Read(wxT("lastImageType")).c_str();
00598         }
00599         if (img_ext == wxT("all images"))
00600             dlg.SetFilterIndex(0);
00601         else if (img_ext == wxT("jpg"))
00602             dlg.SetFilterIndex(1);
00603         else if (img_ext == wxT("tiff"))
00604             dlg.SetFilterIndex(2);
00605         else if (img_ext == wxT("png"))
00606             dlg.SetFilterIndex(3);
00607         else if (img_ext == wxT("hdr"))
00608             dlg.SetFilterIndex(4);
00609         else if (img_ext == wxT("exr"))
00610             dlg.SetFilterIndex(5);
00611         else if (img_ext == wxT("all files"))
00612             dlg.SetFilterIndex(6);
00613         DEBUG_INFO ( "Image extention: " << img_ext.mb_str(wxConvLocal) );
00614 
00615         // call the file dialog
00616         if (dlg.ShowModal() == wxID_OK) {
00617             // get the selections
00618             wxArrayString Pathnames;
00619             dlg.GetPaths(Pathnames);
00620 
00621             // save the current path to config
00622 #ifdef __WXGTK__
00623             //workaround a bug in GTK, see https://bugzilla.redhat.com/show_bug.cgi?id=849692 and http://trac.wxwidgets.org/ticket/14525
00624             config->Write(wxT("/actualPath"), wxPathOnly(Pathnames[0]));
00625 #else
00626             config->Write(wxT("/actualPath"), dlg.GetDirectory());
00627 #endif
00628             DEBUG_INFO ( wxString::Format(wxT("img_ext: %d"), dlg.GetFilterIndex()).mb_str(wxConvLocal) );
00629             // save the image extension
00630             switch ( dlg.GetFilterIndex() ) {
00631                 case 0: config->Write(wxT("lastImageType"), wxT("all images")); break;
00632                 case 1: config->Write(wxT("lastImageType"), wxT("jpg")); break;
00633                 case 2: config->Write(wxT("lastImageType"), wxT("tiff")); break;
00634                 case 3: config->Write(wxT("lastImageType"), wxT("png")); break;
00635                 case 4: config->Write(wxT("lastImageType"), wxT("hdr")); break;
00636                 case 5: config->Write(wxT("lastImageType"), wxT("exr")); break;
00637                 case 6: config->Write(wxT("lastImageType"), wxT("all files")); break;
00638             }
00639 
00640             HuginBase::StandardImageVariableGroups variable_groups(pano);
00641             HuginBase::ImageVariableGroup & lenses = variable_groups.getLenses();
00642             // add images.
00643             for (unsigned int i=0; i< Pathnames.GetCount(); i++) {
00644                 std::string filename = (const char *)Pathnames[i].mb_str(HUGIN_CONV_FILENAME);
00645                 vigra::ImageImportInfo inf(filename.c_str());
00646                 SrcPanoImage img(filename);
00647                 img.setSize(inf.size());
00648                 int imgNr = pano.addImage(img);
00649                 lenses.updatePartNumbers();
00650                 if (i > 0) lenses.switchParts(imgNr, 0);
00651             }
00652 
00653         }
00654     }
00655 
00656     unsigned int nOldImg = pano.getNrOfImages();
00657     PanoramaMemento newPanoMem;
00658 
00659     int ptoVersion = 0;
00660     if (newPanoMem.loadPTScript(in, ptoVersion, "")) {
00661         Panorama newPano;
00662         newPano.setMemento(newPanoMem);
00663 
00664         unsigned int nNewImg = newPano.getNrOfImages();
00665         if (nOldImg != nNewImg) {
00666             wxString errMsg = wxString::Format(_("Error, template expects %d images,\ncurrent project contains %d images\n"), nNewImg, nOldImg);
00667             wxMessageBox(errMsg, _("Could not apply template"), wxICON_ERROR);
00668             return false;
00669         }
00670 
00671         // check image sizes, and correct parameters if required.
00672         for (unsigned int i = 0; i < nNewImg; i++) {
00673 
00674             // check if image size is correct
00675             const SrcPanoImage & oldSrcImg = pano.getImage(i);
00676             SrcPanoImage newSrcImg = newPano.getSrcImage(i);
00677 
00678             // just keep the file name
00679             DEBUG_DEBUG("apply template fn:" <<  newSrcImg.getFilename() << " real fn: " << oldSrcImg.getFilename());
00680             newSrcImg.setFilename(oldSrcImg.getFilename());
00681             if (oldSrcImg.getSize() != newSrcImg.getSize()) {
00682                 // adjust size properly.
00683                 newSrcImg.resize(oldSrcImg.getSize());
00684             }
00685             newPano.setSrcImage(i, newSrcImg);
00686         }
00687         // keep old control points.
00688         newPano.setCtrlPoints(pano.getCtrlPoints());
00689         newPanoMem = newPano.getMemento();
00690         pano.setMemento(newPanoMem);
00691     } else {
00692         wxMessageBox(_("Error loading project file"), _("Could not apply template"), wxICON_ERROR);
00693     }
00694     return true;
00695 }
00696 
00697 #ifdef HUGIN_HSI
00698 bool PythonScriptPanoCmd::processPanorama(Panorama& pano)
00699 {
00700     std::cout << "run python script: " << m_scriptFile.c_str() << std::endl;
00701 
00702     int success = hpi::callhpi ( m_scriptFile.c_str() , 1 ,
00703                    "HuginBase::Panorama*" , &pano ) ;
00704 
00705     if(success!=0)
00706         wxMessageBox(wxString::Format(wxT("Script returned %d"),success),_("Result"), wxICON_INFORMATION);
00707     std::cout << "Python interface returned " << success << endl ;
00708     // notify other of change in panorama
00709     if(pano.getNrOfImages()>0)
00710     {
00711         for(unsigned int i=0;i<pano.getNrOfImages();i++)
00712         {
00713             pano.imageChanged(i);
00714         };
00715     };
00716 
00717     return true;
00718 }
00719 #endif
00720 
00721 } // namespace
00722 

Generated on Wed Jul 16 01:25:36 2014 for Hugintrunk by  doxygen 1.3.9.1