From: Pablo d'A. <da...@us...> - 2006-12-30 17:47:08
|
Update of /cvsroot/hugin/hugin/src/hugin In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv32514/src/hugin Modified Files: wxPanoCommand.cpp Log Message: fixed possible crash when loading autopano-SIFT project files Index: wxPanoCommand.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/hugin/wxPanoCommand.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- wxPanoCommand.cpp 9 Mar 2006 07:47:55 -0000 1.2 +++ wxPanoCommand.cpp 30 Dec 2006 17:46:59 -0000 1.3 @@ -121,10 +121,210 @@ } } } + pano.changeFinished(); +} + + +void wxAddImagesCmd::execute() +{ + PanoCommand::execute(); + + // check if the files should be sorted by date + long sort = wxConfigBase::Get()->Read(wxT("General/SortNewImgOnAdd"), HUGIN_GUI_SORT_NEW_IMG_ON_ADD); + + switch (sort) { + case 1: + // sort by filename + std::sort(files.begin(), files.end()); + break; + case 2: + // sort by date + std::sort(files.begin(), files.end(), FileIsNewer()); + break; + default: + // no or unknown sort method + break; + } + + std::vector<std::string>::const_iterator it; + + + double cropFactor = 0; + double focalLength = 0; + + Lens lens; + VariableMap vars; + fillVariableMap(vars); + ImageOptions imgopts; + SrcPanoImage srcImg; + + // load additional images... + for (it = files.begin(); it != files.end(); ++it) { + const std::string &filename = *it; + + // try to read settings automatically. + srcImg.setFilename(filename); + int assumeSimilar = wxConfigBase::Get()->Read(wxT("/LensDefaults/AssumeSimilar"), HUGIN_LENS_ASSUME_SIMILAR); + if (!assumeSimilar) { + focalLength = 0; + cropFactor = 0; + } + bool ok = initImageFromFile(srcImg, focalLength, cropFactor); +#if 0 + if (! ok) { + // search for image with matching size and exif data + for (unsigned int i=0; i < pano.getNrOfImages(); i++) { + SrcPanoImage other = pano.getSrcImage(i); + if ( other.getSize() == srcImg.getSize() ) + /* this exif data is currently not saved in the Panorama object and the .pto files. + do not check it. + && + other.getExifModel() == srcImg.getExifModel() && + other.getExifMake() == srcImg.getExifMake() && + other.getExifFocalLength() == srcImg.getExifFocalLength() && + other.getExifCropFactor() == srcImg.getExifCropFactor() + ) + */ + { + srcImg = pano.getSrcImage(i); + srcImg.setFilename(filename); + ok = true; + break; + } + } + } + } +#endif + // if no similar image found, ask user + if (! ok) { + getLensDataFromUser(srcImg, focalLength, cropFactor); + } + + if( srcImg.getSize().x == 0) { + // if image size is invalid, do not add image. + pano.changeFinished(); + wxLogError(_("Could not read image size")); + return; + } + + int matchingLensNr=-1; + // FIXME: check if the exif information + // indicates other camera parameters + for (unsigned int i=0; i < pano.getNrOfImages(); i++) { + SrcPanoImage other = pano.getSrcImage(i); + if (abs(other.getHFOV () - srcImg.getHFOV()) < 1 + && other.getSize() == srcImg.getSize() + /* + && other.getExifModel() == srcImg.getExifModel() + && other.getExifMake() == srcImg.getExifMake() */ + ) + { + matchingLensNr = pano.getImage(i).getLensNr(); + break; + } + } + + if (matchingLensNr == -1) { + // create and add new lens + Lens lens; + matchingLensNr = pano.addLens(lens); + } + PanoImage img(filename, srcImg.getSize().x, srcImg.getSize().y, (unsigned int) matchingLensNr); + int i = pano.addImage(img, vars); + pano.setSrcImage(i, srcImg); + } + pano.changeFinished(); +} + + +void wxLoadPTProjectCmd::execute() +{ + PanoCommand::execute(); + PanoramaMemento newPano; + if (newPano.loadPTScript(in,prefix)) { + pano.setMemento(newPano); + unsigned int nImg = pano.getNrOfImages(); + wxString basedir; + double focalLength=0; + double cropFactor=0; + for (unsigned int i = 0; i < nImg; i++) { + wxFileName fname(wxString (pano.getImage(i).getFilename().c_str(), *wxConvCurrent)); + while (! fname.FileExists()){ + // Is file in the new path + if (basedir != wxT("")) { + DEBUG_DEBUG("Old filename: " << pano.getImage(i).getFilename()); + std::string fn = utils::stripPath(pano.getImage(i).getFilename()); + DEBUG_DEBUG("Old filename, without path): " << fn); + wxString newname(fn.c_str(), *wxConvCurrent); + // GetFullName does only work with local paths (not compatible across platforms) +// wxString newname = fname.GetFullName(); + fname.AssignDir(basedir); + fname.SetFullName(newname); + DEBUG_TRACE("filename with new path: " << fname.GetFullPath().mb_str()); + if (fname.FileExists()) { + pano.setImageFilename(i, (const char *)fname.GetFullPath().mb_str()); + DEBUG_TRACE("New filename set: " << fname.GetFullPath().mb_str()); + // TODO - set pano dirty flag so that new paths are saved + continue; + } + } + wxMessageBox(wxString::Format(_("Image file not found:\n%s\nPlease select correct image"), fname.GetFullPath().c_str()), _("Image file not found")); + if (basedir == wxT("")) { + basedir = fname.GetPath(); + } + // open file dialog + wxString wildcard (_("All Image files|*.jpg;*.JPG;*.tif;*.TIF;*.tiff;*.TIFF;*.png;*.PNG;*.bmp;*.BMP;*.gif;*.GIF;*.pnm;*.PNM;*.sun;*.viff;*.hdr|JPEG files (*.jpg)|*.jpg;*.JPG|All files (*)|*")); + wxFileDialog dlg(MainFrame::Get(), _("Add images"), + basedir, fname.GetFullName(), + wildcard, wxOPEN, wxDefaultPosition); + if (dlg.ShowModal() == wxID_OK) { + pano.setImageFilename(i, (const char *)dlg.GetPath().mb_str()); + // save used path + basedir = dlg.GetDirectory(); + DEBUG_INFO("basedir is: " << basedir.mb_str()); + } else { + PanoramaMemento emptyPano; + pano.setMemento(emptyPano); + // set an empty panorama + pano.changeFinished(); + return; + } + fname.Assign(dlg.GetPath()); + } + // check if image size is correct + SrcPanoImage srcImg = pano.getSrcImage(i); + // + vigra::ImageImportInfo imginfo(srcImg.getFilename().c_str()); + if (srcImg.getSize() != imginfo.size()) { + // adjust size properly. + srcImg.resize(imginfo.size()); + pano.setSrcImage(i, srcImg); + } + // check if script contains invalid HFOV + unsigned lNr = pano.getImage(i).getLensNr(); + Lens cLens = pano.getLens(lNr); + double hfov = const_map_get(pano.getVariables()[i], "v").getValue(); + if (cLens.getProjection() == Lens::RECTILINEAR + && hfov >= 180) + { + // something is wrong here, try to read from exif data + bool ok = initImageFromFile(srcImg, focalLength, cropFactor); + if (! ok) { + getLensDataFromUser(srcImg, focalLength, cropFactor); + } + pano.setSrcImage(i, srcImg); + } + } + } else { + DEBUG_ERROR("could not load panotools script"); + } pano.changeFinished(); } + + + } // namespace |