diff --git a/Applications/CLI/CMakeLists.txt b/Applications/CLI/CMakeLists.txt index edb87aa77c7ff8a7b3c1afdfeda1f8c8193aeccc..40cd7e7fc084cb3824065427865db2e3866871ed 100644 --- a/Applications/CLI/CMakeLists.txt +++ b/Applications/CLI/CMakeLists.txt @@ -8,6 +8,8 @@ TARGET_LINK_LIBRARIES(ogs BaseLib FileIO MeshLib + InSituLib + ${CATALYST_LIBRARIES} ${Boost_LIBRARIES} ) diff --git a/Applications/DataExplorer/DataExplorer.cmake b/Applications/DataExplorer/DataExplorer.cmake index 815b4acc2b0af1b0bfc723ef470a350123316c70..a3b1bfbdebec6af6cae82a4dc669fc47473c592b 100644 --- a/Applications/DataExplorer/DataExplorer.cmake +++ b/Applications/DataExplorer/DataExplorer.cmake @@ -80,6 +80,7 @@ TARGET_LINK_LIBRARIES( DataExplorer BaseLib GeoLib FileIO + InSituLib MeshLib #MSHGEOTOOLS QtBase diff --git a/Applications/DataExplorer/DataView/MshView.cpp b/Applications/DataExplorer/DataView/MshView.cpp index 232f5a99b165910094ddf9e0b300bf76be6ed877..4597811071da2bfae9478f901c840b8cd1d11314 100644 --- a/Applications/DataExplorer/DataView/MshView.cpp +++ b/Applications/DataExplorer/DataView/MshView.cpp @@ -37,7 +37,7 @@ #include "Legacy/MeshIO.h" //#include "RapidXmlIO/RapidVtuInterface.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" #include "Writer.h" // necessary to avoid Linker Error in Windows #include "SHPInterface.h" #include "TetGenInterface.h" @@ -269,7 +269,7 @@ int MshView::writeToFile() const QFileInfo fi(fileName); if (fi.suffix().toLower() == "vtu") { - FileIO::BoostVtuInterface vtkIO; + FileIO::VtuInterface vtkIO; vtkIO.setMesh(mesh); vtkIO.writeToFile(fileName.toStdString().c_str()); } diff --git a/Applications/Utils/FileConverter/CMakeLists.txt b/Applications/Utils/FileConverter/CMakeLists.txt index 3f9894899d2452c5352d41c5fcd12e37b2fe47ad..9dd4c33035ec247b28ea4ec656e15ff0eb4e9d33 100644 --- a/Applications/Utils/FileConverter/CMakeLists.txt +++ b/Applications/Utils/FileConverter/CMakeLists.txt @@ -48,6 +48,8 @@ IF (QT4_FOUND) GeoLib MeshLib FileIO + InSituLib + ${CATALYST_LIBRARIES} ${QT_LIBRARIES} ) ENDIF () # QT4_FOUND @@ -58,7 +60,8 @@ IF (Boost_FOUND) FileIO MeshLib logog - ${Boost_LIBRARIES} + InSituLib + ${CATALYST_LIBRARIES} ) SET_TARGET_PROPERTIES(generateMatPropsFromMatID PROPERTIES FOLDER Utilities) @@ -69,6 +72,8 @@ SET_TARGET_PROPERTIES(GMSH2OGS PROPERTIES FOLDER Utilities) TARGET_LINK_LIBRARIES (GMSH2OGS MeshLib FileIO + InSituLib + ${CATALYST_LIBRARIES} ) IF(MSVC) TARGET_LINK_LIBRARIES (GMSH2OGS winmm) @@ -80,6 +85,8 @@ TARGET_LINK_LIBRARIES (OGS2VTK MeshLib FileIO zlib + InSituLib + ${CATALYST_LIBRARIES} ) ADD_EXECUTABLE (VTK2OGS VTK2OGS.cpp) @@ -88,6 +95,8 @@ TARGET_LINK_LIBRARIES (VTK2OGS MeshLib FileIO zlib + InSituLib + ${CATALYST_LIBRARIES} ) ADD_EXECUTABLE (VTK2TIN VTK2TIN.cpp) diff --git a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp index 9e795298e48a1371b1c800992eef0633af85e516..67f47efc52bb412098e83be81e98870037ea1701 100644 --- a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp +++ b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp @@ -27,7 +27,7 @@ // FileIO #include "Legacy/MeshIO.h" #include "FEFLOWInterface.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" // MeshLib #include "Mesh.h" @@ -97,7 +97,7 @@ int main (int argc, char* argv[]) ogs_mesh_fname += ".vtu"; } INFO("Writing %s.", ogs_mesh_fname.c_str()); - FileIO::BoostVtuInterface mesh_io; + FileIO::VtuInterface mesh_io; mesh_io.setMesh(mesh); mesh_io.writeToFile(ogs_mesh_fname); } diff --git a/Applications/Utils/FileConverter/GMSH2OGS.cpp b/Applications/Utils/FileConverter/GMSH2OGS.cpp index 5c8d280aa45c8228b7a2016a2fce9cd31cb1ced9..7db6b3c853a8b3856aa846aa6e716931a9d964f3 100644 --- a/Applications/Utils/FileConverter/GMSH2OGS.cpp +++ b/Applications/Utils/FileConverter/GMSH2OGS.cpp @@ -32,7 +32,7 @@ // FileIO #include "Legacy/MeshIO.h" #include "GMSHInterface.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" // MeshLib #include "Mesh.h" @@ -101,7 +101,7 @@ int main (int argc, char* argv[]) ogs_mesh_fname += ".vtu"; } INFO("Writing %s.", ogs_mesh_fname.c_str()); - FileIO::BoostVtuInterface mesh_io; + FileIO::VtuInterface mesh_io; mesh_io.setMesh(mesh); mesh_io.writeToFile(ogs_mesh_fname); } diff --git a/Applications/Utils/FileConverter/OGS2VTK.cpp b/Applications/Utils/FileConverter/OGS2VTK.cpp index c3a3fd0de521561a0e0390bf3bad81d6fa2c7a57..b994ea62b6fd6694fcf753d613d7aba1ca5d6566 100644 --- a/Applications/Utils/FileConverter/OGS2VTK.cpp +++ b/Applications/Utils/FileConverter/OGS2VTK.cpp @@ -24,7 +24,7 @@ #include "LogogSimpleFormatter.h" // FileIO -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" #include "readMeshFromFile.h" // MeshLib @@ -51,7 +51,7 @@ int main (int argc, char* argv[]) MeshLib::Mesh* mesh (FileIO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); - FileIO::BoostVtuInterface vtu; + FileIO::VtuInterface vtu; vtu.setMesh(mesh); vtu.writeToFile(mesh_out.getValue()); diff --git a/Applications/Utils/FileConverter/VTK2OGS.cpp b/Applications/Utils/FileConverter/VTK2OGS.cpp index a53e96f6fa7d816f78b65a0199994a92a2c556e5..d1b414478443f0dc3fe5df7a291f3c6e48a20943 100644 --- a/Applications/Utils/FileConverter/VTK2OGS.cpp +++ b/Applications/Utils/FileConverter/VTK2OGS.cpp @@ -24,7 +24,7 @@ #include "LogogSimpleFormatter.h" // FileIO -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" #include "Legacy/MeshIO.h" // MeshLib @@ -48,7 +48,7 @@ int main (int argc, char* argv[]) cmd.add(mesh_out); cmd.parse(argc, argv); - MeshLib::Mesh* mesh (FileIO::BoostVtuInterface::readVTUFile(mesh_in.getValue())); + MeshLib::Mesh* mesh (FileIO::VtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); FileIO::Legacy::MeshIO meshIO; diff --git a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp index c5ec2c4f590e414d5c469cf75722fe8ed46e22ad..5b1f6a9f8cf0c31e1a968af87ab6444d2fa02568 100644 --- a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp +++ b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp @@ -22,7 +22,7 @@ // FileIO #include "readMeshFromFile.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" // MeshLib #include "Mesh.h" @@ -78,7 +78,7 @@ int main (int argc, char* argv[]) std::string new_mshname(name + "_new.vtu"); INFO("Writing mesh to file \"%s\".", new_mshname.c_str()); - FileIO::BoostVtuInterface mesh_io; + FileIO::VtuInterface mesh_io; mesh_io.setMesh(mesh); mesh_io.writeToFile (new_mshname); diff --git a/Applications/Utils/MeshEdit/CMakeLists.txt b/Applications/Utils/MeshEdit/CMakeLists.txt index dec1139cc270d30ef2f90cbd541eb0a0de069d00..671e3f55f3329d43a1fc7bdce4013d28463a8b30 100644 --- a/Applications/Utils/MeshEdit/CMakeLists.txt +++ b/Applications/Utils/MeshEdit/CMakeLists.txt @@ -18,6 +18,8 @@ IF(QT4_FOUND) FileIO MathLib MeshLib + InSituLib + ${CATALYST_LIBRARIES} ${QT_LIBRARIES} ) @@ -32,6 +34,8 @@ TARGET_LINK_LIBRARIES( removeMeshElements FileIO MathLib MeshLib + InSituLib + ${CATALYST_LIBRARIES} ) SET_TARGET_PROPERTIES(removeMeshElements PROPERTIES FOLDER Utilities) @@ -39,6 +43,8 @@ ADD_EXECUTABLE( DataExplorer5NodeReordering DataExplorer5NodeReordering.cpp ) TARGET_LINK_LIBRARIES( DataExplorer5NodeReordering FileIO MeshLib + InSituLib + ${CATALYST_LIBRARIES} ) SET_TARGET_PROPERTIES(DataExplorer5NodeReordering PROPERTIES FOLDER Utilities) @@ -46,6 +52,8 @@ ADD_EXECUTABLE( MoveMesh MoveMesh.cpp ) TARGET_LINK_LIBRARIES( MoveMesh FileIO MeshLib + InSituLib + ${CATALYST_LIBRARIES} ) SET_TARGET_PROPERTIES(MoveMesh PROPERTIES FOLDER Utilities) @@ -56,6 +64,8 @@ TARGET_LINK_LIBRARIES( appendLinesAlongPolyline MathLib MeshLib MeshGeoToolsLib + InSituLib + ${CATALYST_LIBRARIES} ) SET_TARGET_PROPERTIES(appendLinesAlongPolyline @@ -67,6 +77,8 @@ TARGET_LINK_LIBRARIES( editMaterialID FileIO MathLib MeshLib + InSituLib + ${CATALYST_LIBRARIES} ) SET_TARGET_PROPERTIES(editMaterialID diff --git a/Applications/Utils/MeshEdit/DataExplorer5NodeReordering.cpp b/Applications/Utils/MeshEdit/DataExplorer5NodeReordering.cpp index 0d135670ac279ecb6070393cb8100c01285e3eba..4a4bcc0a37ac2d65f2d56ef631b16f19f4098bf3 100644 --- a/Applications/Utils/MeshEdit/DataExplorer5NodeReordering.cpp +++ b/Applications/Utils/MeshEdit/DataExplorer5NodeReordering.cpp @@ -21,7 +21,7 @@ // FileIO #include "readMeshFromFile.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" // MeshLib #include "Mesh.h" @@ -30,7 +30,7 @@ void reorderNodes(std::vector<MeshLib::Element*> &elements) { std::size_t nElements (elements.size()); - for (std::size_t i=0; i<nElements; ++i) + for (std::size_t i=0; i<nElements; ++i) { const unsigned nElemNodes (elements[i]->getNBaseNodes()); std::vector<MeshLib::Node*> nodes(elements[i]->getNodes(), elements[i]->getNodes() + nElemNodes); @@ -93,12 +93,12 @@ int main (int argc, char* argv[]) INFO("Reordering nodes... "); reorderNodes(const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements())); - - FileIO::BoostVtuInterface writer; + + FileIO::VtuInterface writer; writer.setMesh(mesh); writer.writeToFile(output_mesh_arg.getValue().c_str()); - INFO("VTU file written."); + INFO("VTU file written."); delete formatter; delete logogCout; diff --git a/Applications/Utils/MeshEdit/MoveMesh.cpp b/Applications/Utils/MeshEdit/MoveMesh.cpp index cda6fa193eb75f225327f64d7e322f0f8d17fa10..011c84888cd6bdd4babc5f400b4fb17162babeb3 100644 --- a/Applications/Utils/MeshEdit/MoveMesh.cpp +++ b/Applications/Utils/MeshEdit/MoveMesh.cpp @@ -23,7 +23,7 @@ // FileIO #include "readMeshFromFile.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" // GeoLib #include "AABB.h" @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) out_fname += "_displaced.vtu"; } - FileIO::BoostVtuInterface mesh_io; + FileIO::VtuInterface mesh_io; mesh_io.setMesh(mesh); mesh_io.writeToFile(out_fname); diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp index 5cc53bd35fa2b84fee368621befe2ec1e2b3dbcf..f33e8c1c94f160e6f6ac297808ae251aed1f7c66 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp @@ -32,7 +32,7 @@ // mesh #include "Legacy/MeshIO.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" OGSFileConverter::OGSFileConverter(QWidget* parent) : QDialog(parent) @@ -124,7 +124,7 @@ void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &o if (fileExists(output_str)) continue; - FileIO::BoostVtuInterface vtu; + FileIO::VtuInterface vtu; MeshLib::Mesh const*const mesh (vtu.readVTUFile(it->toStdString().c_str())); if (mesh == nullptr) { @@ -159,11 +159,11 @@ void OGSFileConverter::convertMSH2VTU(const QStringList &input, const QString &o OGSError::box("Error reading mesh " + fi.fileName()); continue; } - FileIO::BoostVtuInterface vtu; + FileIO::VtuInterface vtu; vtu.setMesh(mesh); vtu.writeToFile(output_str); delete mesh; - } + } OGSError::box("File conversion finished"); } diff --git a/FileIO/VtkIO/VtuInterface.cpp b/FileIO/VtkIO/VtuInterface.cpp index 964e19867e4cb8d2cd989098980f74568fe782fa..8f9f8c2047b3a64b25a2987ae8be5105de96cb24 100644 --- a/FileIO/VtkIO/VtuInterface.cpp +++ b/FileIO/VtkIO/VtuInterface.cpp @@ -2,7 +2,7 @@ * \file * \author Lars Bilke * \date 2014-09-25 - * \brief Implementation of the BoostVtuInterface class. + * \brief Implementation of the VtuInterface class. * * \copyright * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) diff --git a/FileIO/VtkIO/VtuInterface.h b/FileIO/VtkIO/VtuInterface.h index c93d4fea454379fcc369daf68cacc97c063d0fff..4be1b61e762bd9d24e327d682766a7ceadb9deab 100644 --- a/FileIO/VtkIO/VtuInterface.h +++ b/FileIO/VtkIO/VtuInterface.h @@ -46,7 +46,7 @@ public: /// Sets the mesh to write. void setMesh(const MeshLib::Mesh* mesh); - int writeToFile(std::string const &filen_name); + int writeToFile(std::string const &file_name); private: diff --git a/FileIO/XmlIO/Boost/BoostVtuInterface.cpp b/FileIO/XmlIO/Boost/BoostVtuInterface.cpp deleted file mode 100644 index ba2c27de1321a80727b6ac775ee351fd5ef6abca..0000000000000000000000000000000000000000 --- a/FileIO/XmlIO/Boost/BoostVtuInterface.cpp +++ /dev/null @@ -1,604 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2012-12-05 - * \brief Implementation of the BoostVtuInterface class. - * - * \copyright - * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - * \file BoostVtuInterface.cpp - * @date 2012-12-05 - * @author Karsten Rink - * @brief Read VTU files employing boost. - */ - -#include "BoostVtuInterface.h" -#include "zLibDataCompressor.h" -#include <fstream> - -#include <boost/version.hpp> -#include <boost/foreach.hpp> -#include <boost/property_tree/xml_parser.hpp> - -// ThirdParty/logog -#include "logog/include/logog.hpp" - -#include "FileTools.h" - -// MSH -#include "Elements/Line.h" -#include "Elements/Hex.h" -#include "Elements/Prism.h" -#include "Elements/Pyramid.h" -#include "Elements/Quad.h" -#include "Elements/Tet.h" -#include "Elements/Tri.h" -#include "Mesh.h" -#include "MeshLib/Node.h" - -namespace FileIO -{ -using namespace boost; - -BoostVtuInterface::BoostVtuInterface() : - _mesh(nullptr), _use_compressor(false), _doc() -{ -} - -BoostVtuInterface::~BoostVtuInterface() -{} - -MeshLib::Mesh* BoostVtuInterface::readVTUFile(const std::string &file_name) -{ - std::ifstream in(file_name.c_str()); - if (in.fail()) - { - ERR("BoostVtuInterface::readVTUFile(): Can't open xml-file %s.", file_name.c_str()); - return nullptr; - } - - // build DOM tree - using boost::property_tree::ptree; - ptree doc; - read_xml(in, doc); - - if (isVTKUnstructuredGrid(doc)) - { - ptree const& root_node = doc.get_child("VTKFile"); - optional<std::string> const& compressor (getXmlAttribute("compressor", root_node)); - bool is_compressed = static_cast<bool>(compressor); - if (is_compressed) - { - if (*compressor != "vtkZLibDataCompressor") - { - ERR("BoostVtuInterface::readVTUFile(): Unknown compression method."); - return nullptr; - } - - // TODO: remove this once compressed data can be handled!! - INFO("Handling of compressed meshes not yet implemented."); - return nullptr; - } - - //skip to <Piece>-tag and start parsing content - OptionalPtree const& piece_node = root_node.get_child_optional( - "UnstructuredGrid.Piece"); - if (piece_node) - { - const unsigned nNodes = - static_cast<unsigned>(piece_node->get("<xmlattr>.NumberOfPoints", 0)); - const unsigned nElems = - static_cast<unsigned>(piece_node->get("<xmlattr>.NumberOfCells", 0)); - - if ((nNodes == 0) || (nElems == 0)) - { - ERR("BoostVtuInterface::readVTUFile() - Number of nodes is %d, number of elements is %d.", - nNodes, nElems); - return nullptr; - } - - std::vector<MeshLib::Node*> nodes(nNodes); - std::vector<MeshLib::Element*> elements(nElems); - std::vector<unsigned> mat_ids(nElems, 0); - std::vector<unsigned> cell_types(nElems); - - BOOST_FOREACH( ptree::value_type const & grid_piece, *piece_node ) - { - if (grid_piece.first == "CellData") - { - const OptionalPtree& cell_data_node = findDataArray( - "MaterialIDs", - grid_piece.second); - if (cell_data_node) - { - optional<std::string> const& format = - getXmlAttribute("format", *cell_data_node); - std::stringstream iss (cell_data_node->data()); //v.second.get<std::string>("DataArray")); - if (format) - { - if (*format == "ascii") - for(unsigned i = 0; i < nElems; i++) - iss >> mat_ids[i]; - else if (*format == "appended") - { - //uncompress - } - } - } - else - WARN("BoostVtuInterface::readVTUFile(): MaterialIDs not found, setting every cell to 0."); - } - - if (grid_piece.first == "Points") - { - // This node may or may not have an attribute "Name" with the value "Points". - // However, there shouldn't be any other DataArray nodes so most likely not checking the name isn't a problem. - ptree const& data_array_node = grid_piece.second.get_child( - "DataArray"); - optional<std::string> const& format = getXmlAttribute( - "format", - data_array_node); - - if (format) - { - if (*format == "ascii") - { - std::stringstream iss (data_array_node.data()); - double x,y,z; - for(unsigned i = 0; i < nNodes; i++) - { - iss >> x >> y >> z; - nodes[i] = new MeshLib::Node(x, y, z, i); - } - } - else if (*format == "appended") - { - //uncompress - } - } - } - - if (grid_piece.first == "Cells") - { - ptree const& cells = grid_piece.second; - - // cell types - OptionalPtree const& types = findDataArray("types", cells); - if (!types) - ERR("BoostVtuInterface::readVTUFile(): Cannot find \"types\" data array."); - - std::stringstream iss (types->data()); - optional<std::string> const& format = getXmlAttribute("format", *types); - if (*format == "ascii") - { - for(unsigned i = 0; i < nElems; i++) - iss >> cell_types[i]; - } - else if (*format == "appended") - { - //uncompress - } - - // connectivity / element nodes - OptionalPtree const& connectivity = findDataArray("connectivity", cells); - if (!connectivity) - ERR("BoostVtuInterface::readVTUFile(): Cannot find \"connectivity\" data array."); - - std::string conn_string = connectivity->data(); - - if (!conn_string.empty()) - { - optional<std::string> const& format = - getXmlAttribute("format", *connectivity); - if (*format == "appended") - { - //uncompress - } - - std::stringstream iss (conn_string); - for(unsigned i = 0; i < nElems; i++) - elements[i] = readElement(iss, nodes, mat_ids[i],cell_types[i]); - } - } - } - - INFO("Reading VTU mesh finished."); - INFO("Name: %s", BaseLib::extractBaseNameWithoutExtension(file_name).c_str()); - INFO("Nr. Nodes: %d", nodes.size()); - INFO("Nr. Elements: %d", elements.size()); - return new MeshLib::Mesh(BaseLib::extractBaseNameWithoutExtension(file_name), nodes, - elements); - - } // piece - } // unstructured grid - - return nullptr; -} - -MeshLib::Element* BoostVtuInterface::readElement(std::stringstream &iss, - const std::vector<MeshLib::Node*> &nodes, - unsigned material, unsigned type) -{ - unsigned node_ids[8]; - switch (type) - { - case 3: { //line - for (unsigned i(0); i < 2; i++) - iss >> node_ids[i]; - MeshLib::Node** edge_nodes = new MeshLib::Node*[2]; - edge_nodes[0] = nodes[node_ids[0]]; - edge_nodes[1] = nodes[node_ids[1]]; - return new MeshLib::Line(edge_nodes, material); - break; - } - case 5: { //triangle - for (unsigned i(0); i < 3; i++) - iss >> node_ids[i]; - MeshLib::Node** tri_nodes = new MeshLib::Node*[3]; - tri_nodes[0] = nodes[node_ids[0]]; - tri_nodes[1] = nodes[node_ids[1]]; - tri_nodes[2] = nodes[node_ids[2]]; - return new MeshLib::Tri(tri_nodes, material); - break; - } - case 9: { //quad - for (unsigned i(0); i < 4; i++) - iss >> node_ids[i]; - MeshLib::Node** quad_nodes = new MeshLib::Node*[4]; - for (unsigned k(0); k < 4; k++) - quad_nodes[k] = nodes[node_ids[k]]; - return new MeshLib::Quad(quad_nodes, material); - break; - } - case 8: { //pixel - for (unsigned i(0); i < 4; i++) - iss >> node_ids[i]; - MeshLib::Node** quad_nodes = new MeshLib::Node*[4]; - quad_nodes[0] = nodes[node_ids[0]]; - quad_nodes[1] = nodes[node_ids[1]]; - quad_nodes[2] = nodes[node_ids[3]]; - quad_nodes[3] = nodes[node_ids[2]]; - return new MeshLib::Quad(quad_nodes, material); - break; - } - case 10: { - for (unsigned i(0); i < 4; i++) - iss >> node_ids[i]; - MeshLib::Node** tet_nodes = new MeshLib::Node*[4]; - for (unsigned k(0); k < 4; k++) - tet_nodes[k] = nodes[node_ids[k]]; - return new MeshLib::Tet(tet_nodes, material); - break; - } - case 12: { //hexahedron - for (unsigned i(0); i < 8; i++) - iss >> node_ids[i]; - MeshLib::Node** hex_nodes = new MeshLib::Node*[8]; - for (unsigned k(0); k < 8; k++) - hex_nodes[k] = nodes[node_ids[k]]; - return new MeshLib::Hex(hex_nodes, material); - break; - } - case 11: { //voxel - for (unsigned i(0); i < 8; i++) - iss >> node_ids[i]; - MeshLib::Node** voxel_nodes = new MeshLib::Node*[8]; - voxel_nodes[0] = nodes[node_ids[0]]; - voxel_nodes[1] = nodes[node_ids[1]]; - voxel_nodes[2] = nodes[node_ids[3]]; - voxel_nodes[3] = nodes[node_ids[2]]; - voxel_nodes[4] = nodes[node_ids[4]]; - voxel_nodes[5] = nodes[node_ids[5]]; - voxel_nodes[6] = nodes[node_ids[7]]; - voxel_nodes[7] = nodes[node_ids[6]]; - return new MeshLib::Hex(voxel_nodes, material); - break; - } - case 14: { //pyramid - for (unsigned i(0); i < 5; i++) - iss >> node_ids[i]; - MeshLib::Node** pyramid_nodes = new MeshLib::Node*[5]; - for (unsigned k(0); k < 5; k++) - pyramid_nodes[k] = nodes[node_ids[k]]; - return new MeshLib::Pyramid(pyramid_nodes, material); - break; - } - case 13: { //wedge - for (unsigned i(0); i < 6; i++) - iss >> node_ids[i]; - MeshLib::Node** prism_nodes = new MeshLib::Node*[6]; - for (unsigned k(0); k < 6; k++) - prism_nodes[k] = nodes[node_ids[k]]; - return new MeshLib::Prism(prism_nodes, material); - break; - } - default: - ERR("BoostVtuInterface::readElement(): Unknown mesh element type \"%d\".", type); - return nullptr; - } -} - -bool BoostVtuInterface::isVTKFile(const property_tree::ptree &vtk_root) -{ - if (!vtk_root.get_child_optional("VTKFile")) - { - ERR("BoostVtuInterface::isVTKFile(): Not a VTK file."); - return false; - } - optional<std::string> const& att_version (getXmlAttribute("version", vtk_root)); - if (att_version && *att_version == "0.1") - { - ERR("BoostVtuInterface::isVTKFile(): Unsupported file format version."); - return false; - } - optional<std::string> const& att_order (getXmlAttribute("byte_order", vtk_root)); - if (att_order && *att_order == "LittleEndian") - { - ERR("BoostVtuInterface::isVTKFile(): Only little endian files are supported."); - return false; - } - return true; -} - -bool BoostVtuInterface::isVTKUnstructuredGrid(const property_tree::ptree &vtk_root) -{ - if (isVTKFile(vtk_root)) - { - const OptionalPtree &u_grid_node = vtk_root.get_child_optional( - "VTKFile.UnstructuredGrid"); - if (u_grid_node) - return true; - ERR("Error in BoostVtuInterface::isVTKUnstructuredGrid(): Not an unstructured grid."); - } - return false; -} - -unsigned char* BoostVtuInterface::uncompressData(property_tree::ptree const& compressed_data_node) -{ - const unsigned char* compressed_data = reinterpret_cast<const unsigned char*>(compressed_data_node.data().c_str()); - unsigned long compressed_size = strlen(compressed_data_node.data().c_str()); - unsigned char* uncompressed_data = NULL; - unsigned long uncompressed_size = 0; - // unsigned long result = - zLibDataCompressor::UncompressBuffer(compressed_data, compressed_size, uncompressed_data, uncompressed_size); - return uncompressed_data; -} - -const optional<std::string> BoostVtuInterface::getXmlAttribute(std::string const& key, - property_tree::ptree const& tree) -{ - for (property_tree::ptree::const_iterator it = tree.begin(); it != tree.end(); ++it) - { - if (it->first != "<xmlattr>") - continue; - if (it->second.get_child_optional(key)) - return it->second.get_child(key).data(); - } - - return optional<std::string>(); -} - -const OptionalPtree BoostVtuInterface::findDataArray(std::string const& array_name, - property_tree::ptree const& tree) -{ - // Loop over all "DataArray" children. - for (property_tree::ptree::const_iterator it = tree.begin(); it != tree.end(); ++it) - if (it->first == "DataArray") - { - optional<std::string> const& value = getXmlAttribute("Name", it->second); - if (value && *value == array_name) - return it->second; - } - - return OptionalPtree(); -} - -void BoostVtuInterface::setMesh(const MeshLib::Mesh* mesh) -{ - if (!mesh) - { - ERR("BoostVtuInterface::write(): No mesh specified."); - return; - } - this->_mesh = const_cast<MeshLib::Mesh*>(mesh); - buildPropertyTree(); -}; - -void BoostVtuInterface::addScalarPointProperty(std::string const& name, - std::vector<double> const& prop_vals) -{ - if (_doc.empty()) { - WARN("BoostVtuInterface::addPointProperty(): propertry tree empty (no mesh set)"); - return; - } - - if (_mesh->getNNodes() != prop_vals.size()) { - WARN("BoostVtuInterface::addPointProperty(): number of values for propertry %s (%d) does not match the number of nodes (%d)", name.c_str(), prop_vals.size(), _mesh->getNNodes()); - return; - } - -#if BOOST_VERSION <= 105500 - const std::string data_array_close("\t\t\t\t"); - const std::string data_array_indent("\t\t\t\t "); -#endif - - // go to the node where data should be inserted - using boost::property_tree::ptree; - ptree &root_node = _doc.get_child("VTKFile"); - ptree &piece_node = root_node.get_child("UnstructuredGrid.Piece"); - ptree &pointdata_node = piece_node.get_child("PointData"); - - // prepare the data - std::stringstream oss(std::stringstream::out); - oss.precision(_out.precision()); -#if BOOST_VERSION <= 105500 - oss << "\n" << data_array_indent; - std::copy(prop_vals.cbegin(), prop_vals.cend(), std::ostream_iterator<double>(oss, " ")); - oss << "\n" << data_array_close; -#else - std::copy(prop_vals.cbegin(), prop_vals.cend(), std::ostream_iterator<double>(oss, " ")); -#endif - this->addDataArray(pointdata_node, name, "Float64", oss.str()); - oss.str(std::string()); -} - -void BoostVtuInterface::buildPropertyTree() -{ - _doc.clear(); - const std::size_t nNodes (_mesh->getNNodes()); - const std::size_t nElems (_mesh->getNElements()); - const std::vector<MeshLib::Node*> &nodes (_mesh->getNodes()); - const std::vector<MeshLib::Element*> &elements (_mesh->getElements()); - -#if BOOST_VERSION <= 105500 - const std::string data_array_close("\t\t\t\t"); - const std::string data_array_indent("\t\t\t\t "); -#endif - - using boost::property_tree::ptree; - - ptree &root_node = _doc.put("VTKFile", ""); - root_node.put("<xmlattr>.type", "UnstructuredGrid"); - root_node.put("<xmlattr>.version", "0.1"); - root_node.put("<xmlattr>.byte_order", "LittleEndian"); - - if (_use_compressor) - root_node.put("<xmlattr>.compressor", "vtkZLibDataCompressor"); - - ptree &piece_node = root_node.put("UnstructuredGrid.Piece", ""); - const std::string str_nNodes (std::to_string(nNodes)); - const std::string str_nElems (std::to_string(nElems)); - piece_node.put("<xmlattr>.NumberOfPoints", str_nNodes.c_str()); - piece_node.put("<xmlattr>.NumberOfCells", str_nElems.c_str()); - - // scalar arrays for point- and cell-data - piece_node.add("PointData", ""); - // add node_area array here if necessary! - ptree &celldata_node = piece_node.add("CellData", ""); - celldata_node.put("<xmlattr>.Scalars", "MaterialIDs"); - - std::stringstream oss(std::stringstream::out); - oss.precision(_out.precision()); -#if BOOST_VERSION <= 105500 - oss << std::endl << data_array_indent; - for (unsigned i = 0; i < nElems; i++) - oss << elements[i]->getValue() << " "; - oss << std::endl << data_array_close; -#else - for (unsigned i = 0; i < nElems; i++) - oss << elements[i]->getValue() << " "; -#endif - this->addDataArray(celldata_node, "MaterialIDs", "Int32", oss.str()); - oss.str(std::string()); - oss.clear(); - - // point coordinates - ptree &points_node = piece_node.add("Points", ""); -#if BOOST_VERSION <= 105500 - oss << std::endl; - for (unsigned i = 0; i < nNodes; i++) - oss << data_array_indent << (*nodes[i])[0] << " " << (*nodes[i])[1] << " " << - (*nodes[i])[2] << std::endl; - oss << data_array_close; -#else - for (unsigned i = 0; i < nNodes; i++) - oss << (*nodes[i])[0] << " " << (*nodes[i])[1] << " " << (*nodes[i])[2] << " "; -#endif - this->addDataArray(points_node, "Points", "Float64", oss.str(), 3); - oss.str(std::string()); - oss.clear(); - - // cells with node ids - ptree &cells_node = piece_node.add("Cells", ""); - std::stringstream offstream(std::stringstream::out); - std::stringstream typestream(std::stringstream::out); -#if BOOST_VERSION <= 105500 - oss << std::endl; - offstream << std::endl << data_array_indent; - typestream << std::endl << data_array_indent; -#endif - unsigned offset_count(0); - for (unsigned i = 0; i < nElems; i++) - { - MeshLib::Element* element (elements[i]); - const unsigned nElemNodes (element->getNBaseNodes()); -#if BOOST_VERSION <= 105500 - oss << data_array_indent; -#endif - for (unsigned j = 0; j < nElemNodes; j++) - oss << element->getNode(j)->getID() << " "; -#if BOOST_VERSION <= 105500 - oss << std::endl; -#endif - offset_count += nElemNodes; - offstream << offset_count << " "; - typestream << this->getVTKElementID(element->getGeomType()) << " "; - } -#if BOOST_VERSION <= 105500 - oss << data_array_close; - offstream << std::endl << data_array_close; - typestream << std::endl << data_array_close; -#endif - - // connectivity attributes - this->addDataArray(cells_node, "connectivity", "Int32", oss.str()); - this->addDataArray(cells_node, "offsets", "Int32", offstream.str()); - this->addDataArray(cells_node, "types", "UInt8", typestream.str()); -} - -bool BoostVtuInterface::write() -{ - if (_doc.empty()) { - ERR("BoostVtuInterface::write(): No mesh specified."); - return false; - } -#if BOOST_VERSION <= 105500 - property_tree::xml_writer_settings<char> settings('\t', 1); -#else - property_tree::xml_writer_settings<std::string> settings('\t', 1); -#endif // BOOST_VERSION - write_xml(_out, _doc, settings); - return true; -} - -unsigned BoostVtuInterface::getVTKElementID(MeshElemType type) const -{ - switch (type) - { - case MeshElemType::LINE: - return 3; - case MeshElemType::TRIANGLE: - return 5; - case MeshElemType::QUAD: - return 9; - case MeshElemType::TETRAHEDRON: - return 10; - case MeshElemType::HEXAHEDRON: - return 12; - case MeshElemType::PYRAMID: - return 14; - case MeshElemType::PRISM: - return 13; - default: - return std::numeric_limits<unsigned>::max(); - } -} - -void BoostVtuInterface::addDataArray(property_tree::ptree &parent_node, const std::string &name, - const std::string &data_type, const std::string &data, - unsigned nComponents) -{ - property_tree::ptree &dataarray_node = parent_node.add("DataArray", data.c_str()); - dataarray_node.put("<xmlattr>.type", data_type.c_str()); - dataarray_node.put("<xmlattr>.Name", name.c_str()); - if (nComponents > 1) - dataarray_node.put("<xmlattr>.NumberOfComponents", std::to_string(nComponents).c_str()); - std::string comp_type = (_use_compressor) ? "appended" : "ascii"; - dataarray_node.put("<xmlattr>.format", comp_type.c_str()); - // ---- offset attribute for compressed data! ---- -} -} // end namespace FileIO diff --git a/FileIO/XmlIO/Boost/BoostVtuInterface.h b/FileIO/XmlIO/Boost/BoostVtuInterface.h deleted file mode 100644 index 57d28ddad450de1b02971eda3add233656dd8c23..0000000000000000000000000000000000000000 --- a/FileIO/XmlIO/Boost/BoostVtuInterface.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2012-12-05 - * \brief Implementation of the BoostVtuInterface class. - * - * \copyright - * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#ifndef BOOSTVTUINTERFACE_H_ -#define BOOSTVTUINTERFACE_H_ - -#include "FileIO/Writer.h" - -#include <string> -#include <vector> - -#include <boost/property_tree/ptree.hpp> -#include <boost/optional.hpp> - -#include "MeshLib/MeshEnums.h" - -typedef boost::optional<const boost::property_tree::ptree&> OptionalPtree; - -namespace MeshLib { - class Mesh; - class Node; - class Element; -} - -namespace FileIO -{ - -/** - * \brief Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures. - * - * XML parsing is performed using boost::property_tree::ptree. - */ -class BoostVtuInterface : public Writer -{ -public: - BoostVtuInterface(); - ~BoostVtuInterface(); - - /// Read an unstructured grid from a VTU file - static MeshLib::Mesh* readVTUFile(const std::string &file_name); - - /// Decide if the mesh data should be written compressed (default is false). - void setCompressData(bool flag=true) { _use_compressor = flag; }; - - /// Set mesh for writing. - void setMesh(const MeshLib::Mesh* mesh); - - void addScalarPointProperty(std::string const& name, std::vector<double> const& prop_vals); - -private: - /** Method builds a tree structure storing the mesh data. This method is called from - * setMesh(). - */ - void buildPropertyTree(); - - /// Adds a VTK-DataArray of the given name and datatype to the DOM tree and inserts the data-string at that node - void addDataArray(boost::property_tree::ptree &parent_node, const std::string &name, const std::string &data_type, const std::string &data, unsigned nComponents = 1); - - bool write(); - - /// Returns the ID used by VTK for a given cell type (e.g. "5" for a triangle, etc.) - unsigned getVTKElementID(MeshElemType type) const; - - /// Check if the root node really specifies an XML file - static bool isVTKFile(const boost::property_tree::ptree &vtk_root); - - /// Check if the file really specifies a VTK Unstructured Grid - static bool isVTKUnstructuredGrid(const boost::property_tree::ptree &vtk_root); - - /// Construct an Element-object from the data given to the method and the data at the current stream position. - static MeshLib::Element* readElement(std::stringstream &iss, const std::vector<MeshLib::Node*> &nodes, unsigned material, unsigned type); - - static unsigned char* uncompressData(boost::property_tree::ptree const& compressed_data_node); - - /// Get an XML attribute value corresponding to given string from a property tree. - static const boost::optional<std::string> getXmlAttribute(std::string const& key, boost::property_tree::ptree const& tree); - - /// Find first child of a tree, which is a DataArray and has requested name. - static const OptionalPtree findDataArray(std::string const& array_name, boost::property_tree::ptree const& tree); - - MeshLib::Mesh* _mesh; - bool _use_compressor; - boost::property_tree::ptree _doc; -}; - -} - -#endif /* BOOSTVTUINTERFACE_H_ */ diff --git a/FileIO/readMeshFromFile.cpp b/FileIO/readMeshFromFile.cpp index d26add422201cdbe44b269a8be14146f72471555..b83bf396cad7e8513bb0776f8da8911259581ce2 100644 --- a/FileIO/readMeshFromFile.cpp +++ b/FileIO/readMeshFromFile.cpp @@ -27,7 +27,7 @@ // FileIO #include "Legacy/MeshIO.h" -#include "XmlIO/Boost/BoostVtuInterface.h" +#include "FileIO/VtkIO/VtuInterface.h" #include "readMeshFromFile.h" namespace FileIO @@ -41,7 +41,7 @@ MeshLib::Mesh* readMeshFromFile(const std::string &file_name) } if (BaseLib::hasFileExtension("vtu", file_name)) - return BoostVtuInterface::readVTUFile(file_name); + return VtuInterface::readVTUFile(file_name); ERR("readMeshFromFile(): Unknown mesh file format in file %s.", file_name.c_str()); return nullptr;