From 0e996ee1db5958731cb895bc4dba51f22d84645f Mon Sep 17 00:00:00 2001 From: Guido Ranzuglia granzuglia Date: Fri, 2 Jul 2010 10:21:34 +0000 Subject: [PATCH] removed crash on loading picked points from a file. --- .../edit_pickpoints/pickPointsTemplate.cpp | 194 +++++++++--------- .../edit_pickpoints/pickpointsDialog.cpp | 3 + 2 files changed, 100 insertions(+), 97 deletions(-) diff --git a/src/meshlabplugins/edit_pickpoints/pickPointsTemplate.cpp b/src/meshlabplugins/edit_pickpoints/pickPointsTemplate.cpp index 89e720149..f8bb16dde 100644 --- a/src/meshlabplugins/edit_pickpoints/pickPointsTemplate.cpp +++ b/src/meshlabplugins/edit_pickpoints/pickPointsTemplate.cpp @@ -19,100 +19,100 @@ * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * -****************************************************************************/ - -/* A class representing a set of point names that is used - * as a template a user can fill out to create a PickedPoints - * - * - * @author Oscar Barney - */ - - -#include "pickPointsTemplate.h" - -#include -//xml stuff -#include -#include -#include - - -//Define Constants -const QString PickPointsTemplate::fileExtension = ".pptpl"; -const QString PickPointsTemplate::rootName = "PickPointsTemplate"; -const QString PickPointsTemplate::pointElementName = "point"; -const QString PickPointsTemplate::pointName = "name"; - - -bool PickPointsTemplate::save(QString filename, - std::vector *pointNameVector){ - QDomDocument doc(rootName); - QDomElement root = doc.createElement(rootName); - doc.appendChild(root); - - //create an element for each point - for (int i = 0; i < pointNameVector->size(); ++i) { - QString name = pointNameVector->at(i); - - QDomElement tag = doc.createElement(pointElementName); - tag.setAttribute(pointName, name); - - //append the element to the root - root.appendChild(tag); - } - - //create a file and write the data - QFile file(filename); - file.open(QIODevice::WriteOnly); - QTextStream qstream(&file); - doc.save(qstream,1); - file.close(); - return true; -} - -bool PickPointsTemplate::load(QString filename, - std::vector *pointNameVector){ - - QDomDocument doc; - pointNameVector->clear(); - - QFile file(filename); - - QString errorMessage; - if (file.open(QIODevice::ReadOnly) && doc.setContent(&file, &errorMessage)) - { - file.close(); - QDomElement root = doc.documentElement(); - if (root.nodeName() == rootName) - { - qDebug() << "About to read a " << rootName << " xml document"; - - for(QDomElement element = root.firstChildElement(pointElementName); - !element.isNull(); - element = element.nextSiblingElement(pointElementName)) - { - QString name = element.attribute(pointName); - qDebug() << "Reading point with name " << name; - - pointNameVector->push_back(name); - - } - } else { - //file is of unknown type - qDebug() << "Failed, tried to read a " << rootName << " xml document"; - return false; - } - - } else { - // problem opening the file - qDebug() << "problem reading from the file, setContent error: " << errorMessage; - return false; - } - return true; -} - -QString PickPointsTemplate::getDefaultTemplateFileName() -{ - return QDir::homePath() + "/.pickPointsTemplate" + fileExtension; -} +****************************************************************************/ + +/* A class representing a set of point names that is used + * as a template a user can fill out to create a PickedPoints + * + * + * @author Oscar Barney + */ + + +#include "pickPointsTemplate.h" + +#include +//xml stuff +#include +#include +#include + + +//Define Constants +const QString PickPointsTemplate::fileExtension = ".pptpl"; +const QString PickPointsTemplate::rootName = "PickPointsTemplate"; +const QString PickPointsTemplate::pointElementName = "point"; +const QString PickPointsTemplate::pointName = "name"; + + +bool PickPointsTemplate::save(QString filename, + std::vector *pointNameVector){ + QDomDocument doc(rootName); + QDomElement root = doc.createElement(rootName); + doc.appendChild(root); + + //create an element for each point + for (int i = 0; i < pointNameVector->size(); ++i) { + QString name = pointNameVector->at(i); + + QDomElement tag = doc.createElement(pointElementName); + tag.setAttribute(pointName, name); + + //append the element to the root + root.appendChild(tag); + } + + //create a file and write the data + QFile file(filename); + file.open(QIODevice::WriteOnly); + QTextStream qstream(&file); + doc.save(qstream,1); + file.close(); + return true; +} + +bool PickPointsTemplate::load(QString filename, + std::vector *pointNameVector){ + + QDomDocument doc; + pointNameVector->clear(); + + QFile file(filename); + + QString errorMessage; + if (file.open(QIODevice::ReadOnly) && doc.setContent(&file, &errorMessage)) + { + file.close(); + QDomElement root = doc.documentElement(); + if (root.nodeName() == rootName) + { + qDebug() << "About to read a " << rootName << " xml document"; + + for(QDomElement element = root.firstChildElement(pointElementName); + !element.isNull(); + element = element.nextSiblingElement(pointElementName)) + { + QString name = element.attribute(pointName); + qDebug() << "Reading point with name " << name; + + pointNameVector->push_back(name); + + } + } else { + //file is of unknown type + qDebug() << "Failed, tried to read a " << rootName << " xml document"; + return false; + } + + } else { + // problem opening the file + qDebug() << "problem reading from the file, setContent error: " << errorMessage; + return false; + } + return true; +} + +QString PickPointsTemplate::getDefaultTemplateFileName() +{ + return QDir::homePath() + "/.pickPointsTemplate" + fileExtension; +} diff --git a/src/meshlabplugins/edit_pickpoints/pickpointsDialog.cpp b/src/meshlabplugins/edit_pickpoints/pickpointsDialog.cpp index 3d876e0f7..c7550811a 100644 --- a/src/meshlabplugins/edit_pickpoints/pickpointsDialog.cpp +++ b/src/meshlabplugins/edit_pickpoints/pickpointsDialog.cpp @@ -380,6 +380,8 @@ bool PickPointsDialog::drawNormalAsPin() void PickPointsDialog::addPoint(vcg::Point3f &point, QString &name, bool present) { + //bool result = GLPickTri::PickNearestFace(currentMousePosition.x(),gla->height()-currentMousePosition.y(), + // mm.cm, face); CMeshO::FaceType *face = 0; //qDebug() << "present: " << present; @@ -736,6 +738,7 @@ PickedPoints * PickPointsDialog::getPickedPoints() } void PickPointsDialog::loadPoints(QString filename){ + vcg::tri::UpdateFlags::FaceProjection(meshModel->cm); //clear the points tree and template in case it was loaded clearTemplate();