Commit 05379787 authored by Mike Kremer's avatar Mike Kremer
Browse files

Added file plugin for OVM files. Adapted rendering node for volume meshes.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13867 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9add6c4a
......@@ -101,7 +101,7 @@ public:
};
/// Constructor
VolumeMeshNodeT(VolumeMesh& _mesh,
VolumeMeshNodeT(const VolumeMesh& _mesh,
OpenVolumeMesh::StatusAttrib& _statusAttrib,
OpenVolumeMesh::ColorAttrib<Vec4f>& _colorAttrib,
OpenVolumeMesh::NormalAttrib<VolumeMesh>& _normalAttrib,
......@@ -242,7 +242,7 @@ private:
private:
VolumeMesh& mesh_;
const VolumeMesh& mesh_;
std::vector<Plane> cut_planes_;
......
......@@ -57,7 +57,7 @@ namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
template<class VolumeMeshT>
VolumeMeshNodeT<VolumeMeshT>::VolumeMeshNodeT(VolumeMesh& _mesh,
VolumeMeshNodeT<VolumeMeshT>::VolumeMeshNodeT(const VolumeMesh& _mesh,
OpenVolumeMesh::StatusAttrib& _statusAttrib,
OpenVolumeMesh::ColorAttrib<Vec4f>& _colorAttrib,
OpenVolumeMesh::NormalAttrib<VolumeMesh>& _normalAttrib,
......
......@@ -44,6 +44,8 @@
#define VOLUME_MESH_OBJECT_HH
// Includes
#include <memory>
#include <ACG/Math/VectorT.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
#include <ACG/Scenegraph/StatusNodesT.hh>
......@@ -83,7 +85,7 @@ public:
protected:
/// Initialise current object, including all related nodes.
virtual void init(MeshT* _mesh = 0);
virtual void init();
//===========================================================================
/** @name Name and Path handling
......@@ -139,7 +141,7 @@ public:
NormalAttrib& normals() { return normalAttrib_; }
private:
MeshT* mesh_;
std::auto_ptr<MeshT> mesh_;
StatusAttrib statusAttrib_;
......
......@@ -61,7 +61,7 @@
template<class MeshT>
VolumeMeshObject<MeshT>::VolumeMeshObject(const VolumeMeshObject& _object) :
BaseObjectData(_object), mesh_(_object.mesh_),
BaseObjectData(_object), mesh_(_object.mesh_.get()),
statusAttrib_(*mesh_),
colorAttrib_(*mesh_),
normalAttrib_(*mesh_),
......@@ -70,7 +70,7 @@ VolumeMeshObject<MeshT>::VolumeMeshObject(const VolumeMeshObject& _object) :
new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_,
normalAttrib_, NULL, "NEW VolumeMeshNode"))) {
init(_object.mesh_);
init();
setName(name());
}
......@@ -100,14 +100,6 @@ VolumeMeshObject<MeshT>::~VolumeMeshObject() {
// perObjectData.
deleteData();
// Delete the mesh only, if this object contains a mesh
if(mesh_ != NULL) {
delete mesh_;
mesh_ = NULL;
} else {
std::cerr << "Destructor error: Mesh already deleted." << std::endl;
}
// No need to delete the scenegraph nodes as this will be managed by baseplugin
meshNode_ = 0;
}
......@@ -118,14 +110,6 @@ VolumeMeshObject<MeshT>::~VolumeMeshObject() {
template<class MeshT>
void VolumeMeshObject<MeshT>::cleanup() {
// Delete the mesh only, if this object contains a mesh
if(mesh_ != NULL) {
delete mesh_;
mesh_ = NULL;
} else {
std::cerr << "Cleanup error: Triangle Mesh already deleted." << std::endl;
}
BaseObjectData::cleanup();
meshNode_ = 0;
......@@ -137,7 +121,7 @@ void VolumeMeshObject<MeshT>::cleanup() {
* the mesh and requests all required properties for the mesh.
*/
template<class MeshT>
void VolumeMeshObject<MeshT>::init(MeshT* _mesh) {
void VolumeMeshObject<MeshT>::init() {
// Only initialize scenegraph nodes when we initialized a gui!!
if(OpenFlipper::Options::nogui())
......@@ -183,7 +167,7 @@ void VolumeMeshObject<MeshT>::setName(QString _name) {
*/
template<class MeshT>
MeshT* VolumeMeshObject<MeshT>::mesh() {
return mesh_;
return mesh_.get();
}
/** Updates the visualization of the object. Calls VolumeMeshObject::updateGeometry,
......
include (plugin)
openflipper_plugin (OpenVolumeMesh)
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 13576 $ *
* $LastChangedBy: kremer $ *
* $Date: 2012-01-30 11:22:27 +0100 (Mo, 30 Jan 2012) $ *
* *
\*===========================================================================*/
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <QtGui>
#include <QFileInfo>
#include <ACG/GL/GLState.hh>
#include <OpenMesh/Core/IO/IOManager.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
#include "FileOpenVolumeMesh.hh"
FileOpenVolumeMeshPlugin::FileOpenVolumeMeshPlugin() :
loadOptions_(0),
saveOptions_(0),
typeCheck_(0),
loadCompMode_(0),
loadCorrectOrder_(0),
loadTopCheck_(0),
saveCompMode_(0) {
}
//----------------------------------------------------------------------------
void FileOpenVolumeMeshPlugin::initializePlugin() {
loadOptions_ = new QWidget();
QVBoxLayout* llayout = new QVBoxLayout();
llayout->setAlignment(Qt::AlignTop);
typeCheck_ = new QComboBox();
typeCheck_->addItem("Autodetect");
typeCheck_->addItem("Polyhedral Mesh");
typeCheck_->addItem("Hexahedral Mesh");
typeCheck_->setCurrentIndex(0);
loadCompMode_ = new QCheckBox("Load PolyVolMesh format");
loadCorrectOrder_= new QCheckBox("Correct face ordering");
loadTopCheck_ = new QCheckBox("Perform topology checks");
llayout->addWidget(typeCheck_);
llayout->addWidget(loadCompMode_);
llayout->addWidget(loadCorrectOrder_);
llayout->addWidget(loadTopCheck_);
loadOptions_->setLayout(llayout);
saveOptions_ = new QWidget();
QVBoxLayout* slayout = new QVBoxLayout();
slayout->setAlignment(Qt::AlignTop);
saveCompMode_ = new QCheckBox("Save in PolyVolMesh format");
slayout->addWidget(saveCompMode_);
saveOptions_->setLayout(slayout);
}
//----------------------------------------------------------------------------
QString FileOpenVolumeMeshPlugin::getLoadFilters() {
return QString(tr("Polyhedral Volume Mesh files ( *.ovm *.polyvolmesh *.tetmesh )"));
}
;
//----------------------------------------------------------------------------
QString FileOpenVolumeMeshPlugin::getSaveFilters() {
return QString(tr("Polyhedral Volume Mesh files ( *.ovm )"));
}
;
//----------------------------------------------------------------------------
DataType FileOpenVolumeMeshPlugin::supportedType() {
DataType type = DATA_POLYHEDRAL_MESH;// | DATA_HEXAHEDRAL_MESH;
return type;
}
//----------------------------------------------------------------------------
int FileOpenVolumeMeshPlugin::loadObject(QString _filename) {
bool compatibility_mode = false;
if(!OpenFlipper::Options::nogui()) {
compatibility_mode = loadCompMode_->isChecked();
}
bool correct_face_order = false;
if(!OpenFlipper::Options::nogui()) {
correct_face_order = loadCorrectOrder_->isChecked();
}
bool topology_checks = true;
if(!OpenFlipper::Options::nogui()) {
topology_checks = loadTopCheck_->isChecked();
}
int id = -1;
bool hexMesh = false;
if(!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 0) {
hexMesh = fileManager_.isHexahedralMesh(_filename.toStdString());
} else if (!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 2) {
hexMesh = true;
}
if(hexMesh) {
emit addEmptyObject(DATA_HEXAHEDRAL_MESH, id);
HexahedralMeshObject* obj(0);
if (PluginFunctions::getObject(id, obj)) {
if(compatibility_mode) {
loadMesh((const char*) _filename.toAscii(), *(obj->mesh()), compatibility_mode,
topology_checks, correct_face_order);
} else {
if(!fileManager_.readFile(_filename.toStdString(), *(obj->mesh()),
topology_checks,true)) {
emit log(LOGERR, QString("Could not open file %1!").arg(_filename));
}
}
obj->setFromFileName(_filename);
// Compute top-down-adjacencies
obj->mesh()->update_adjacencies();
// Compute face normals
emit updatedObject(obj->id(), UPDATE_ALL);
}
emit openedFile(obj->id());
// Go into solid flat shaded mode
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED, PluginFunctions::activeExaminer());
// Scale polyhedra a bit
obj->meshNode()->set_scaling(0.8);
} else {
emit addEmptyObject(DATA_POLYHEDRAL_MESH, id);
PolyhedralMeshObject* obj(0);
if (PluginFunctions::getObject(id, obj)) {
if(compatibility_mode) {
loadMesh((const char*) _filename.toAscii(), *(obj->mesh()), compatibility_mode,
topology_checks, correct_face_order);
} else {
if(!fileManager_.readFile(_filename.toStdString(), *(obj->mesh()),
topology_checks,true)) {
emit log(LOGERR, QString("Could not open file %1!").arg(_filename));
}
}
obj->setFromFileName(_filename);
// Compute top-down-adjacencies
obj->mesh()->update_adjacencies();
// Compute face normals
emit updatedObject(obj->id(), UPDATE_ALL);
}
emit openedFile(obj->id());
// Go into solid flat shaded mode
PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED, PluginFunctions::activeExaminer());
// Scale polyhedra a bit
obj->meshNode()->set_scaling(0.8);
}
PluginFunctions::viewAll();
return id;
}
//----------------------------------------------------------------------------
bool FileOpenVolumeMeshPlugin::saveObject(int _id, QString _filename) {
BaseObjectData* obj(0);
if (PluginFunctions::getObject(_id, obj)) {
PolyhedralMeshObject* mesh_obj = PluginFunctions::polyhedralMeshObject(obj);
HexahedralMeshObject* hex_mesh_obj = PluginFunctions::hexahedralMeshObject(obj);
if (mesh_obj) {
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(), -1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2));
fileManager_.writeFile(_filename.toStdString(), *(mesh_obj->mesh()));
}
else if (hex_mesh_obj) {
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(), -1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2));
fileManager_.writeFile(_filename.toStdString(), *(hex_mesh_obj->mesh()));
}
}
return true;
}
//----------------------------------------------------------------------------
void FileOpenVolumeMeshPlugin::loadIniFileLast(INIFile& _ini, int _id) {
BaseObjectData* baseObject;
if (!PluginFunctions::getObject(_id, baseObject)) {
emit log(LOGERR, tr("Cannot find object for id %1 in saveFile!").arg(_id));
return;
}
PolyhedralMeshObject* object = PluginFunctions::polyhedralMeshObject(baseObject);
if (object) {
ACG::Vec4f col(0.0, 0.0, 0.0, 0.0);
if (_ini.get_entryVecf(col, object->name(), "BaseColor"))
object->materialNode()->set_base_color(col);
}
}
//----------------------------------------------------------------------------
void FileOpenVolumeMeshPlugin::saveIniFile(INIFile& _ini, int _id) {
BaseObjectData* baseObject;
if (!PluginFunctions::getObject(_id, baseObject)) {
emit log(LOGERR, tr("Cannot find object for id %1 in saveFile!").arg(_id));
return;
}
PolyhedralMeshObject* object = PluginFunctions::polyhedralMeshObject(baseObject);
if (object) {
_ini.add_entryVec(object->name(), "BaseColor", object->materialNode()->base_color());
}
}
//----------------------------------------------------------------------------
QWidget* FileOpenVolumeMeshPlugin::saveOptionsWidget(QString _currentFilter) {
return saveOptions_;
}
//----------------------------------------------------------------------------
QWidget* FileOpenVolumeMeshPlugin::loadOptionsWidget(QString _currentFilter) {
return loadOptions_;
}
Q_EXPORT_PLUGIN2(fileopenvolumemeshplugin, FileOpenVolumeMeshPlugin)
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 13548 $ *
* $LastChangedBy: kremer $ *
* $Date: 2012-01-27 11:58:19 +0100 (Fr, 27 Jan 2012) $ *
* *
\*===========================================================================*/
#ifndef FILEOPENVOLUMEMESH_HH
#define FILEOPENVOLUMEMESH_HH
#include <QObject>
#include <QMenuBar>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/FileInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
#include <ObjectTypes/Plane/Plane.hh>
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#ifndef FILEOPENVOLUMEMESHT_CC
#include <OpenVolumeMesh/FileManager/FileManager.hh>
#endif
class FileOpenVolumeMeshPlugin: public QObject,
BaseInterface,
FileInterface,
LoadSaveInterface,
LoggingInterface,
ScriptInterface,
INIInterface {
Q_OBJECT
Q_INTERFACES(FileInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(INIInterface)
public:
// Default constructor
FileOpenVolumeMeshPlugin();
signals:
void openedFile(int _id);
void addEmptyObject(DataType _type, int& _id);
void load(QString _filename, DataType _type, int& _id);
void save(int _id, QString _filename);
void log(Logtype _type, QString _message);
void log(QString _message);
void emptyObjectAdded(int _id);
void updateView();
void updatedObject(int _id, const UpdateType& _type);
void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
private slots:
void fileOpened(int /*_id*/) {}
void loadIniFileLast(INIFile& _ini, int _id);
void saveIniFile(INIFile& _ini, int _id);
void initializePlugin();
public:
~FileOpenVolumeMeshPlugin() {}
QString name() {
return (QString("FileOpenVolumeMesh"));
}
QString description() {
return (QString(tr("Load/Save OpenVolumeMeshes")));
}
DataType supportedType();
QString getSaveFilters();
QString getLoadFilters();
QWidget* saveOptionsWidget(QString _currentFilter);
QWidget* loadOptionsWidget(QString _currentFilter);
public slots:
int loadObject(QString _filename);
bool saveObject(int _id, QString _filename);
QString version() {
return QString("1.0");
}
private:
template <typename MeshT>
void loadMesh(const char* _filename, MeshT& _mesh, bool _comp, bool _topCheck, bool _correctOrder);
template <typename MeshT>
void saveMesh(const char* _filename, MeshT& _mesh, bool _comp);
private:
QWidget* loadOptions_;
QWidget* saveOptions_;
QComboBox* typeCheck_;
QCheckBox* loadCompMode_;
QCheckBox* loadCorrectOrder_;
QCheckBox* loadTopCheck_;
QCheckBox* saveCompMode_;
OpenVolumeMesh::IO::FileManager fileManager_;
};
#if defined(INCLUDE_TEMPLATES) && !defined(FILEOPENVOLUMEMESHT_CC)
#include "FileOpenVolumeMeshT.cc"
#endif
#endif //FILEOPENVOLUMEMESH_HH
/*===========================================================================*\
* *
* OpenFlipper *