45#include <ACG/GL/GLState.hh>
50#include "FileOpenVolumeMesh.hh"
56FileOpenVolumeMeshPlugin::FileOpenVolumeMeshPlugin() :
68void FileOpenVolumeMeshPlugin::initializePlugin() {
70 if (!OpenFlipper::Options::nogui())
72 loadOptions_ =
new QWidget();
74 QVBoxLayout* llayout =
new QVBoxLayout();
75 llayout->setAlignment(Qt::AlignTop);
77 typeCheck_ =
new QComboBox();
78 typeCheck_->addItem(
"Autodetect");
79 typeCheck_->addItem(
"Polyhedral Mesh");
80 typeCheck_->addItem(
"Hexahedral Mesh");
81#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
82 typeCheck_->addItem(
"Tetrahedral Mesh");
84 typeCheck_->setCurrentIndex(0);
85 loadCompMode_ =
new QCheckBox(
"Load PolyVolMesh format");
86 loadTopCheck_ =
new QCheckBox(
"Perform topology checks");
87 llayout->addWidget(typeCheck_);
88 llayout->addWidget(loadCompMode_);
89 llayout->addWidget(loadTopCheck_);
91 loadOptions_->setLayout(llayout);
93 saveOptions_ =
new QWidget();
95 QVBoxLayout* slayout =
new QVBoxLayout();
96 slayout->setAlignment(Qt::AlignTop);
98 saveCompMode_ =
new QCheckBox(
"Save in PolyVolMesh format");
99 slayout->addWidget(saveCompMode_);
101 saveOptions_->setLayout(slayout);
109 return QString(tr(
"Polyhedral Volume Mesh files ( *.ovm *.polyvolmesh *.tetmesh )"));
117 return QString(tr(
"Polyhedral Volume Mesh files ( *.ovm )"));
127#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
136int FileOpenVolumeMeshPlugin::loadObject(QString _filename) {
138 bool compatibility_mode =
false;
139 if(!OpenFlipper::Options::nogui()) {
140 compatibility_mode = loadCompMode_->isChecked();
143 bool topology_checks =
true;
144 if(!OpenFlipper::Options::nogui()) {
145 topology_checks = loadTopCheck_->isChecked();
149 bool hexMesh =
false;
151 if(!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 0) {
153 }
else if (!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 2) {
157#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
158 bool tetMesh =
false;
159 if(!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 0) {
161 }
else if (!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 3) {
176 if(compatibility_mode) {
178 loadMesh((
const char*) _filename.toLatin1(), *(obj->mesh()), compatibility_mode,
182 if(!fileManager_.
readFile(_filename.toStdString(), *(obj->mesh()),
183 topology_checks,
true)) {
184 emit log(
LOGERR, QString(
"Could not open file %1!").arg(_filename));
189 obj->meshNode()->set_scaling(0.8);
194#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
203 if(compatibility_mode) {
205 loadMesh((
const char*) _filename.toLatin1(), *(obj->mesh()), compatibility_mode,
209 if(!fileManager_.
readFile(_filename.toStdString(), *(obj->mesh()),
210 topology_checks,
true)) {
211 emit log(
LOGERR, QString(
"Could not open file %1!").arg(_filename));
216 obj->meshNode()->set_scaling(0.8);
230 if(compatibility_mode) {
232 loadMesh((
const char*) _filename.toLatin1(), *(obj->mesh()), compatibility_mode,
236 if(!fileManager_.
readFile(_filename.toStdString(), *(obj->mesh()),
237 topology_checks,
true)) {
238 emit log(
LOGERR, QString(
"Could not open file %1!").arg(_filename));
242 if (!OpenFlipper::Options::nogui())
245 obj->meshNode()->set_scaling(0.8);
262 emit openedFile(baseObj->
id());
271bool FileOpenVolumeMeshPlugin::saveObject(
int _id, QString _filename) {
278#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
283 obj->setFromFileName(_filename);
284 obj->setName(obj->filename());
285 if(!fileManager_.
writeFile(_filename.toStdString(), *(mesh_obj->
mesh()))) {
286 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
290 else if (hex_mesh_obj) {
292 obj->setFromFileName(_filename);
293 obj->setName(obj->filename());
294 if (!fileManager_.
writeFile(_filename.toStdString(), *(hex_mesh_obj->
mesh()))) {
295 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
299#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
300 else if (tet_mesh_obj) {
302 obj->setFromFileName(_filename);
303 obj->setName(obj->filename());
304 if (!fileManager_.
writeFile(_filename.toStdString(), *(tet_mesh_obj->
mesh()))) {
305 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
314 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
324void FileOpenVolumeMeshPlugin::loadIniFileLast(
INIFile& _ini,
int _id) {
328 emit log(
LOGERR, tr(
"Cannot find object for id %1 in saveFile!").arg(_id));
338 object->materialNode()->set_base_color(col);
345void FileOpenVolumeMeshPlugin::saveIniFile(
INIFile& _ini,
int _id) {
349 emit log(
LOGERR, tr(
"Cannot find object for id %1 in saveFile!").arg(_id));
#define DATA_HEXAHEDRAL_MESH
#define DATA_POLYHEDRAL_MESH
#define DATA_TETRAHEDRAL_MESH
const Vec4f & base_color() const
get the base color ( same as emission() )
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
MaterialNode * materialNode()
get a pointer to the materialnode
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
QString filename() const
return the filename of the object
void setFromFileName(const QString &_filename)
QWidget * loadOptionsWidget(QString _currentFilter)
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
QWidget * saveOptionsWidget(QString _currentFilter)
Class for the handling of simple configuration files.
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
bool readFile(const std::string &_filename, MeshT &_mesh, bool _topologyCheck=true, bool _computeBottomUpIncidences=true) const
Read a mesh from a file.
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.
bool isTetrahedralMesh(const std::string &_filename) const
Test whether given file contains a tetrahedral mesh.
bool isHexahedralMesh(const std::string &_filename) const
Test whether given file contains a hexahedral mesh.
MeshT * mesh()
return a pointer to the mesh
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
HexahedralMeshObject * hexahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an HexahedralMeshObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TetrahedralMeshObject * tetrahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an TetrahedralMeshObject if possible.