MLRenderingData included in openProject

This commit is contained in:
alemuntoni 2021-06-04 17:39:25 +02:00
parent cb00f22d20
commit b01ac1ff2f
9 changed files with 97 additions and 124 deletions

View File

@ -31,6 +31,8 @@
#include "../../utilities/file_format.h"
#include "../../ml_document/raster_model.h"
class MLRenderingData;
/**
* @brief The IOPlugin is the base class for meshes, images and projects loading
* and saving.
@ -341,17 +343,22 @@ public:
* @param fileName: the name of the file from which load the project (including its path)
* @param md: MeshDocument on which store the content of the loaded project
* note: the document could not be empty!
* @param rendOpt: rendering options that may be loaded from the project file,
* if it supports them. They are not required. If you can support
* rendering options, the rendOpt vector must have the same size of
* the MeshModel vector returned by the openProject function.
* @param cb: standard callback for reporting progresso in the loading
* @return the list of MeshModel that have been loaded from the given project
*/
virtual std::list<MeshModel*> openProject(
virtual std::vector<MeshModel*> openProject(
const QString& format,
const QStringList& /*filenames*/,
MeshDocument& /*md*/,
std::vector<MLRenderingData>& /*rendOpt*/,
vcg::CallBackPos* /*cb*/ = nullptr)
{
wrongOpenFormat(format);
return std::list<MeshModel*>();
return std::vector<MeshModel*>();
}
/**************************

View File

@ -336,10 +336,11 @@ void loadRaster(const QString& filename, RasterModel& rm, GLLogStream* log, vcg:
// End of EXIF reading
}
std::list<MeshModel*> loadProject(
std::vector<MeshModel*> loadProject(
const QStringList& filenames,
IOPlugin* ioPlugin,
MeshDocument& md,
std::vector<MLRenderingData>& rendOpt,
GLLogStream* log,
vcg::CallBackPos* cb)
{
@ -347,10 +348,10 @@ std::list<MeshModel*> loadProject(
QString extension = fi.suffix();
ioPlugin->setLog(log);
return ioPlugin->openProject(extension, filenames, md, cb);
return ioPlugin->openProject(extension, filenames, md, rendOpt, cb);
}
std::list<MeshModel*> loadProject(
std::vector<MeshModel*> loadProject(
const QStringList& filenames,
MeshDocument& md,
GLLogStream* log,
@ -375,11 +376,11 @@ std::list<MeshModel*> loadProject(
") is different from the expected one (" +
QString::number(additionalFiles.size() +1));
}
return loadProject(filenames, ioPlugin, md, log, cb);
std::vector<MLRenderingData> rendOpt;
return loadProject(filenames, ioPlugin, md, rendOpt, log, cb);
}
std::list<MeshModel*> loadProject(
std::vector<MeshModel*> loadProject(
const QString& filename,
MeshDocument& md,
GLLogStream* log,

View File

@ -72,20 +72,21 @@ void loadRaster(
GLLogStream* log = nullptr,
vcg::CallBackPos *cb = nullptr);
std::list<MeshModel*> loadProject(
std::vector<MeshModel*> loadProject(
const QStringList& filenames,
IOPlugin* ioPlugin,
MeshDocument& md,
std::vector<MLRenderingData>& rendOpt,
GLLogStream* log = nullptr,
vcg::CallBackPos *cb = nullptr);
std::list<MeshModel*> loadProject(
std::vector<MeshModel*> loadProject(
const QStringList& filenames,
MeshDocument& md,
GLLogStream* log = nullptr,
vcg::CallBackPos *cb = nullptr);
std::list<MeshModel*> loadProject(
std::vector<MeshModel*> loadProject(
const QString& filename,
MeshDocument& md,
GLLogStream* log = nullptr,

View File

@ -125,7 +125,6 @@ public slots:
bool importMeshWithLayerManagement(QString fileName=QString());
bool importRaster(const QString& fileImg = QString());
bool openProject(QString fileName=QString(), bool append = false);
void loadMLPRenderingOptions(QString fileName, const std::list<MeshModel*>& meshLsit);
bool appendProject(QString fileName=QString());
void updateCustomSettings();
void updateLayerDialog();

View File

@ -1753,9 +1753,10 @@ bool MainWindow::openProject(QString fileName, bool append)
QDir::setCurrent(fi.absoluteDir().absolutePath());
qb->show();
std::list<MeshModel*> meshList;
std::vector<MeshModel*> meshList;
std::vector<MLRenderingData> rendOptions;
try {
meshList = meshlab::loadProject(filenames, ioPlugin, *meshDoc(), &meshDoc()->Log, QCallBack);
meshList = meshlab::loadProject(filenames, ioPlugin, *meshDoc(), rendOptions, &meshDoc()->Log, QCallBack);
}
catch (const MLException& e) {
QMessageBox::critical(this, tr("Meshlab Opening Error"), e.what());
@ -1766,16 +1767,13 @@ bool MainWindow::openProject(QString fileName, bool append)
QMessageBox::warning(this, "Warning", warningString);
}
for (MeshModel* mm : meshList){
computeRenderingDataOnLoading(mm, false, nullptr);
if (!(mm->cm.textures.empty()))
updateTexture(mm->id());
}
if (QString(fi.suffix()).toLower() == "mlp" || QString(fi.suffix()).toLower() == "mlb")
{
loadMLPRenderingOptions(fileName, meshList);
GLA()->updateMeshSetVisibilities();
for (unsigned int i = 0; i < meshList.size(); i++){
MLRenderingData* ptr = nullptr;
if (rendOptions.size() == meshList.size())
ptr = &rendOptions[i];
computeRenderingDataOnLoading(meshList[i], false, ptr);
if (!(meshList[i]->cm.textures.empty()))
updateTexture(meshList[i]->id());
}
meshDoc()->setBusy(false);
@ -1797,83 +1795,6 @@ bool MainWindow::openProject(QString fileName, bool append)
return true;
}
void MainWindow::loadMLPRenderingOptions(QString fileName, const std::list<MeshModel*>& meshLsit)
{
std::map<int, MLRenderingData> rendOpt;
QFile qf(fileName);
QFileInfo qfInfo(fileName);
QDir tmpDir = QDir::current();
QDir::setCurrent(qfInfo.absoluteDir().absolutePath());
if (!qf.open(QIODevice::ReadOnly))
return;
QString project_path = qfInfo.absoluteFilePath();
QDomDocument doc("MeshLabDocument"); //It represents the XML document
if (!doc.setContent(&qf))
return;
QDomElement root = doc.documentElement();
QDomNode node;
node = root.firstChild();
//Devices
while (!node.isNull()) {
if (QString::compare(node.nodeName(), "MeshGroup") == 0)
{
QDomNode mesh;
mesh = node.firstChild();
auto it = meshLsit.begin();
while (!mesh.isNull()) {
QDomNode renderingOpt = mesh.firstChildElement("RenderingOption");
if (!renderingOpt.isNull())
{
QString value = renderingOpt.firstChild().nodeValue();
MLRenderingData::GLOptionsType opt;
if (renderingOpt.attributes().contains("pointSize"))
opt._perpoint_pointsize = renderingOpt.attributes().namedItem("pointSize").nodeValue().toFloat();
if (renderingOpt.attributes().contains("wireWidth"))
opt._perwire_wirewidth = renderingOpt.attributes().namedItem("wireWidth").nodeValue().toFloat();
if (renderingOpt.attributes().contains("boxColor"))
{
QStringList values = renderingOpt.attributes().namedItem("boxColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perbbox_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("pointColor"))
{
QStringList values = renderingOpt.attributes().namedItem("pointColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perpoint_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("wireColor"))
{
QStringList values = renderingOpt.attributes().namedItem("wireColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perwire_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("solidColor"))
{
QStringList values = renderingOpt.attributes().namedItem("solidColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._persolid_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
MLRenderingData data;
data.set(opt);
if (data.deserialize(value.toStdString()))
rendOpt.insert(std::pair<int, MLRenderingData>((*it)->id(), data));
}
mesh = mesh.nextSibling();
++it;
}
}
node = node.nextSibling();
}
for (MeshModel* mm : meshDoc()->meshIterator())
{
MLRenderingData* ptr = nullptr;
if (rendOpt.find(mm->id()) != rendOpt.end())
ptr = &rendOpt[mm->id()];
computeRenderingDataOnLoading(mm, false, ptr);
}
}
bool MainWindow::appendProject(QString fileName)
{
QStringList fileNameList;

View File

@ -563,13 +563,15 @@ void BaseMeshIOPlugin::saveImage(
}
}
std::list<MeshModel*> BaseMeshIOPlugin::openProject(
std::vector<MeshModel*> BaseMeshIOPlugin::openProject(
const QString& format,
const QStringList& filenames,
MeshDocument& md,
std::vector<MLRenderingData>& rendOpt,
CallBackPos* cb)
{
std::list<MeshModel*> meshList;
std::vector<MeshModel*> meshList;
rendOpt.clear();
if (format.toUpper() == "ALN") {
meshList = loadALN(filenames.first(), md, cb);
}
@ -583,7 +585,7 @@ std::list<MeshModel*> BaseMeshIOPlugin::openProject(
meshList = loadNVM(filenames.first(), md, unloadedImgs, cb);
}
else if (format.toUpper() =="MLP" || format.toUpper() == "MLB") {
meshList = loadMLP(filenames.first(), md, unloadedImgs, cb);
meshList = loadMLP(filenames.first(), md, rendOpt, unloadedImgs, cb);
}
if (unloadedImgs.size() > 0){
QString msg = "Unable to load the following " +

View File

@ -78,15 +78,18 @@ public:
int quality,
vcg::CallBackPos* cb);
std::list<MeshModel*> openProject(
std::vector<MeshModel*> openProject(
const QString& format,
const QStringList& filenames,
MeshDocument& md,
std::vector<MLRenderingData>& rendOpt,
vcg::CallBackPos* cb);
std::list<FileFormat> projectFileRequiresAdditionalFiles(
const QString& format,
const QString& filename);
const QString& format,
const QString& filename);
void initPreOpenParameter(const QString &formatName, RichParameterList &parlst);
void initSaveParameter(const QString &format, const MeshModel &/*m*/, RichParameterList & par);

View File

@ -10,12 +10,12 @@
#include <common/ml_document/mesh_document.h>
#include <common/utilities/load_save.h>
std::list<MeshModel*> loadALN(
std::vector<MeshModel*> loadALN(
const QString& filename,
MeshDocument& md,
vcg::CallBackPos* cb)
{
std::list<MeshModel*> meshList;
std::vector<MeshModel*> meshList;
std::vector<RangeMap> rmv;
int retVal = ALNParser::ParseALN(rmv, qUtf8Printable(filename));
if(retVal != ALNParser::NoError) {
@ -40,14 +40,14 @@ std::list<MeshModel*> loadALN(
return meshList;
}
std::list<MeshModel*> loadOUT(
std::vector<MeshModel*> loadOUT(
const QString& filename,
const QString& imageListFile,
MeshDocument& md,
std::vector<std::string>& unloadedImgList,
vcg::CallBackPos*)
{
std::list<MeshModel*> meshList;
std::vector<MeshModel*> meshList;
unloadedImgList.clear();
QFileInfo fi(filename);
@ -105,13 +105,13 @@ std::list<MeshModel*> loadOUT(
return meshList;
}
std::list<MeshModel*> loadNVM(
std::vector<MeshModel*> loadNVM(
const QString& filename,
MeshDocument& md,
std::vector<std::string>& unloadedImgList,
vcg::CallBackPos*)
{
std::list<MeshModel*> meshList;
std::vector<MeshModel*> meshList;
unloadedImgList.clear();
QFileInfo fi(filename);
@ -153,13 +153,14 @@ std::list<MeshModel*> loadNVM(
return meshList;
}
std::list<MeshModel*> loadMLP(
std::vector<MeshModel*> loadMLP(
const QString& filename,
MeshDocument& md,
std::vector<MLRenderingData>& rendOpt,
std::vector<std::string>& unloadedImgList,
vcg::CallBackPos* cb)
vcg::CallBackPos*)
{
std::list<MeshModel*> meshList;
std::vector<MeshModel*> meshList;
unloadedImgList.clear();
QFile qf(filename);
@ -171,8 +172,6 @@ std::list<MeshModel*> loadMLP(
if (!qf.open(QIODevice::ReadOnly))
throw MLException("File not found.");
QString project_path = qfInfo.absoluteFilePath();
QDomDocument doc("MeshLabDocument"); //It represents the XML document
if (!doc.setContent(&qf))
@ -187,7 +186,8 @@ std::list<MeshModel*> loadMLP(
//Devices
while (!node.isNull()) {
if (QString::compare(node.nodeName(), "MeshGroup") == 0) {
QDomNode mesh; QString filen, label;
QDomNode mesh;
QString filen, label;
mesh = node.firstChild();
while (!mesh.isNull()) {
//return true;
@ -252,6 +252,41 @@ std::list<MeshModel*> loadMLP(
}
}
QDomNode renderingOpt = mesh.firstChildElement("RenderingOption");
if (!renderingOpt.isNull())
{
QString value = renderingOpt.firstChild().nodeValue();
MLRenderingData::GLOptionsType opt;
if (renderingOpt.attributes().contains("pointSize"))
opt._perpoint_pointsize = renderingOpt.attributes().namedItem("pointSize").nodeValue().toFloat();
if (renderingOpt.attributes().contains("wireWidth"))
opt._perwire_wirewidth = renderingOpt.attributes().namedItem("wireWidth").nodeValue().toFloat();
if (renderingOpt.attributes().contains("boxColor"))
{
QStringList values = renderingOpt.attributes().namedItem("boxColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perbbox_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("pointColor"))
{
QStringList values = renderingOpt.attributes().namedItem("pointColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perpoint_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("wireColor"))
{
QStringList values = renderingOpt.attributes().namedItem("wireColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._perwire_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
if (renderingOpt.attributes().contains("solidColor"))
{
QStringList values = renderingOpt.attributes().namedItem("solidColor").nodeValue().split(" ", QString::SkipEmptyParts);
opt._persolid_fixed_color = vcg::Color4b(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3].toInt());
}
MLRenderingData data;
data.set(opt);
if (data.deserialize(value.toStdString()))
rendOpt.push_back(data);
}
mesh = mesh.nextSibling();
}
}
@ -294,5 +329,9 @@ std::list<MeshModel*> loadMLP(
QDir::setCurrent(tmpDir.absolutePath());
qf.close();
if (rendOpt.size() != meshList.size()){
std::cerr << "cannot load rend options\n";
}
return meshList;
}

View File

@ -3,26 +3,26 @@
#include <common/ml_document/mesh_model.h>
std::list<MeshModel*> loadALN(
std::vector<MeshModel*> loadALN(
const QString& filename,
MeshDocument& md,
vcg::CallBackPos* cb);
std::list<MeshModel*> loadOUT(const QString& filename,
std::vector<MeshModel*> loadOUT(const QString& filename,
const QString& imageListFile,
MeshDocument& md,
std::vector<std::string>& unloadedImgList,
vcg::CallBackPos* cb);
std::list<MeshModel*> loadNVM(
std::vector<MeshModel*> loadNVM(
const QString& filename,
MeshDocument& md,
std::vector<std::string>& unloadedImgList,
vcg::CallBackPos* cb);
std::list<MeshModel*> loadMLP(
const QString& filename,
std::vector<MeshModel*> loadMLP(const QString& filename,
MeshDocument& md,
std::vector<MLRenderingData>& rendOpt,
std::vector<std::string>& unloadedImgList,
vcg::CallBackPos* cb);