diff --git a/FileIO/GMSInterface.cpp b/FileIO/GMSInterface.cpp index 25021b7fae20ffcdcc3dbf5cdf6934a9385ce24b..f190b8cc8e44d98d22056454574f15c328324e37 100644 --- a/FileIO/GMSInterface.cpp +++ b/FileIO/GMSInterface.cpp @@ -244,13 +244,15 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(std::string filename) return NULL; } - std::cout << "Read GMS-3DM data..."; + std::cout << "Read GMS-3DM mesh ... "; std::vector<MeshLib::Node*> nodes; std::vector<MeshLib::Element*> elements; + std::map<unsigned, unsigned> id_map; // elements are listed before nodes in 3dm-format, therefore // traverse file twice and read first nodes and then elements - std::string d1,d2; + std::string dummy; + unsigned id(0), count(0); double x[3]; // read nodes while ( getline(in, line) ) @@ -258,15 +260,18 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(std::string filename) if (line[0] == 'N') // "ND" for Node { std::stringstream str(line); - str >> d1 >> d2 >> x[0] >> x[1] >> x[2]; - MeshLib::Node* node = new MeshLib::Node(x); + str >> dummy >> id >> x[0] >> x[1] >> x[2]; + MeshLib::Node* node = new MeshLib::Node(x, id); + id_map.insert(std::pair<unsigned, unsigned>(id,count++)); nodes.push_back(node); } } + in.close(); // NOTE: Element types E8H (Hex), E4Q (Quad), E3T (Tri) are not implemented yet // read elements - in.seekg(0, std::ios::beg); + in.open(filename.c_str()); + getline(in, line); // "MESH3D" unsigned node_idx[6], mat_id; while ( getline(in, line) ) { @@ -276,23 +281,26 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(std::string filename) if (element_id.compare("E6W") == 0) // Prism { - str >> d1 >> d2 >> node_idx[0] >> node_idx[1] >> node_idx[2] >> node_idx[3] + str >> dummy >> id >> node_idx[0] >> node_idx[1] >> node_idx[2] >> node_idx[3] >> node_idx[4] >> node_idx[5] >> mat_id; - elem = new MeshLib::Prism(nodes[node_idx[0]-1], nodes[node_idx[1]-1], nodes[node_idx[2]-1], - nodes[node_idx[3]-1], nodes[node_idx[4]-1], nodes[node_idx[5]-1], mat_id); + elem = new MeshLib::Prism(nodes[id_map.find(node_idx[0])->second], nodes[id_map.find(node_idx[1])->second], + nodes[id_map.find(node_idx[2])->second], nodes[id_map.find(node_idx[3])->second], + nodes[id_map.find(node_idx[4])->second], nodes[id_map.find(node_idx[5])->second], mat_id); elements.push_back(elem); } else if (element_id.compare("E4T") == 0) // Tet { - str >> d1 >> d2 >> node_idx[0] >> node_idx[1] >> node_idx[2] >> node_idx[3] >> mat_id; - elem = new MeshLib::Tet(nodes[node_idx[0]-1], nodes[node_idx[1]-1], nodes[node_idx[2]-1], nodes[node_idx[3]-1], mat_id); + str >> dummy >> id >> node_idx[0] >> node_idx[1] >> node_idx[2] >> node_idx[3] >> mat_id; + elem = new MeshLib::Tet(nodes[id_map.find(node_idx[0])->second], nodes[id_map.find(node_idx[1])->second], + nodes[id_map.find(node_idx[2])->second], nodes[id_map.find(node_idx[3])->second], mat_id); elements.push_back(elem); } else if ((element_id.compare("E4P") == 0) || (element_id.compare("E5P") == 0)) // Pyramid (both do exist for some reason) { - str >> d1 >> d2 >> node_idx[0] >> node_idx[1] >> node_idx[2] >> node_idx[3] >> node_idx[4] >> mat_id; - elem = new MeshLib::Pyramid(nodes[node_idx[0]-1], nodes[node_idx[1]-1], nodes[node_idx[2]-1], - nodes[node_idx[3]-1], nodes[node_idx[4]-1], mat_id); + str >> dummy >> id >> node_idx[0] >> node_idx[1] >> node_idx[2] >> node_idx[3] >> node_idx[4] >> mat_id; + elem = new MeshLib::Pyramid(nodes[id_map.find(node_idx[0])->second], nodes[id_map.find(node_idx[1])->second], + nodes[id_map.find(node_idx[2])->second], nodes[id_map.find(node_idx[3])->second], + nodes[id_map.find(node_idx[4])->second], mat_id); elements.push_back(elem); } else if (element_id.compare("ND ") == 0) // Node @@ -301,7 +309,7 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(std::string filename) } else //default { - std::cout << "GMSInterface::readGMS3DMMesh() - Element type \"" << element_id << "\"not recognised ..." << std::endl; + std::cout << std::endl << "GMSInterface::readGMS3DMMesh() - Element type \"" << element_id << "\"not recognised ..." << std::endl; return NULL; } } diff --git a/FileIO/GMSInterface.h b/FileIO/GMSInterface.h index b449d5a9332d33efe0301e2df0dc9a23423a1116..785fb7a99007dce8177cfc0e7c98eaea4c94fdee 100644 --- a/FileIO/GMSInterface.h +++ b/FileIO/GMSInterface.h @@ -23,6 +23,13 @@ namespace MeshLib { /** * \brief Manages the import and export of Aquaveo GMS files into and out of GeoLib. + * + * This class currently supports reading and writing ASCII borehole files as well as + * (partially) reading mesh files. + * The 3dm-mesh-file-reader is based on example meshes and does currently only support + * the following element types: E4T (tetrahedra), E4P/E5P (pyramids) and E6W (wedges/prisms). + * Not supported are E8H (Hex), E4Q (Quad), E3T (Tri) as well as higher order elements. + * Please refer to the file format documentation of GMS for details. */ class GMSInterface { diff --git a/FileIO/Legacy/MeshIO.cpp b/FileIO/Legacy/MeshIO.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c047059cfee40f08c88b4c90f05e6b4039feca3 --- /dev/null +++ b/FileIO/Legacy/MeshIO.cpp @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.com) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.com/LICENSE.txt + * + * + * \file MeshIO.cpp + * + * Created on 2012-05-08 by Karsten Rink + */ + +#include "GEOObjects.h" +#include "MeshIO.h" +#include "Node.h" +#include "Elements/Edge.h" +#include "Elements/Tri.h" +#include "Elements/Quad.h" +#include "Elements/Tet.h" +#include "Elements/Hex.h" +#include "Elements/Pyramid.h" +#include "Elements/Prism.h" + +#include "StringTools.h" + +#include <iomanip> +#include <sstream> + +namespace FileIO +{ + +MeshIO::MeshIO() +: _mesh(NULL) +{ +} + +MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) +{ + std::cout << "Reading OGS legacy mesh ... "; + + std::ifstream in (file_name.c_str(),std::ios::in); + if (!in.is_open()) + { + std::cout << std::endl << "CFEMesh::FEMRead() - Could not open file...\n"; + return NULL; + } + + std::string line_string (""); + getline(in, line_string); + + std::vector<MeshLib::Node*> nodes; + std::vector<MeshLib::Element*> elements; + + if(line_string.find("#FEM_MSH") != std::string::npos) // OGS mesh file + { + double edge_length[2] = { std::numeric_limits<double>::max(), std::numeric_limits<double>::min() }; + while (!in.eof()) + { + getline(in, line_string); + + // check keywords + if (line_string.find("#STOP") != std::string::npos) + break; + else if (line_string.find("$NODES") != std::string::npos) + { + double x, y, z, double_dummy; + unsigned nNodes, idx; + in >> nNodes >> std::ws; + std::string s; + std::ios::pos_type position = in.tellg(); + for (unsigned i = 0; i < nNodes; i++) + { + in >> idx >> x >> y >> z; + MeshLib::Node* node(new MeshLib::Node(x, y, z, nodes.size())); + nodes.push_back(node); + position = in.tellg(); + in >> s; + if (s.find("$AREA") != std::string::npos) + in >> double_dummy; + else + in.seekg(position, std::ios::beg); + in >> std::ws; + } + } + else if (line_string.find("$ELEMENTS") != std::string::npos) + { + unsigned nElements; + in >> nElements >> std::ws; + for (unsigned i = 0; i < nElements; i++) + { + getline(in, line_string); + + size_t elem_idx (elements.size()); + elements.push_back(readElement(line_string, nodes)); + + double elem_min_length, elem_max_length; + elements[elem_idx]->computeSqrEdgeLengthRange(elem_min_length, elem_max_length); + edge_length[0] = (elem_min_length<edge_length[0]) ? elem_min_length : edge_length[0]; + edge_length[1] = (elem_max_length>edge_length[1]) ? elem_max_length : edge_length[1]; + } + } + } + + + MeshLib::Mesh* mesh (new MeshLib::Mesh(BaseLib::getFileNameFromPath(file_name), nodes, elements)); + mesh->setEdgeLengthRange(sqrt(edge_length[0]), sqrt(edge_length[1])); + + std::cout << "finished." << std::endl; + std::cout << "Nr. Nodes: " << nodes.size() << std::endl; + std::cout << "Nr. Elements: " << elements.size() << std::endl; + + in.close(); + return mesh; + } + else + { + in.close(); + return NULL; + } +} + +MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector<MeshLib::Node*> &nodes) +{ + std::stringstream ss (line); + std::string elem_type_str; + unsigned index, patch_index; + ss >> index >> patch_index >> elem_type_str; + + MshElemType::type elem_type (String2MshElemType(elem_type_str)); + unsigned* idx = new unsigned[8]; + + MeshLib::Element* elem; + + switch(elem_type) + { + case MshElemType::EDGE: + for (int i = 0; i < 2; i++) + ss >> idx[i]; + elem = new MeshLib::Edge(nodes[idx[1]], nodes[idx[0]], patch_index); + break; + case MshElemType::TRIANGLE: + for (int i = 0; i < 3; i++) + ss >> idx[i]; + elem = new MeshLib::Tri(nodes[idx[2]], nodes[idx[1]], nodes[idx[0]], patch_index); + break; + case MshElemType::QUAD: + for (int i = 0; i < 4; i++) + ss >> idx[i]; + elem = new MeshLib::Quad(nodes[idx[3]], nodes[idx[2]], nodes[idx[1]], nodes[idx[0]], patch_index); + break; + case MshElemType::TETRAHEDRON: + for (int i = 0; i < 4; i++) + ss >> idx[i]; + elem = new MeshLib::Tet(nodes[idx[3]], nodes[idx[2]], nodes[idx[1]], nodes[idx[0]], patch_index); + break; + case MshElemType::HEXAHEDRON: + for (int i = 0; i < 8; i++) + ss >> idx[i]; + elem = new MeshLib::Hex(nodes[idx[7]], nodes[idx[6]], nodes[idx[5]], nodes[idx[4]], nodes[idx[3]], nodes[idx[2]], nodes[idx[1]], nodes[idx[0]], patch_index); + break; + case MshElemType::PYRAMID: + for (int i = 0; i < 5; i++) + ss >> idx[i]; + elem = new MeshLib::Pyramid(nodes[idx[4]], nodes[idx[3]], nodes[idx[2]], nodes[idx[1]], nodes[idx[0]], patch_index); + break; + case MshElemType::PRISM: + for (int i = 0; i < 6; i++) + ss >> idx[i]; + elem = new MeshLib::Prism(nodes[idx[5]], nodes[idx[4]], nodes[idx[3]], nodes[idx[2]], nodes[idx[1]], nodes[idx[0]], patch_index); + break; + default: + elem = NULL; + } + + return elem; +} + +int MeshIO::write(std::ostream &out) +{ + if(!_mesh) { + std::cout << "OGSMeshIO cannot write: no mesh set!" << std::endl; + return 0; + } + + setPrecision(9); + + out << "#FEM_MSH" << std::endl; + + out << "$PCS_TYPE" << std::endl << " NO_PCS" << std::endl; + + out << "$NODES" << std::endl << " "; + const size_t n_nodes(_mesh->getNNodes()); + out << n_nodes << std::endl; + for (size_t i(0); i < n_nodes; i++) { + out << i << " " << *(_mesh->getNode(i)) << std::endl; + } + + out << "$ELEMENTS" << std::endl << " "; + writeElementsExceptLines(_mesh->getElements(), out); + + out << " $LAYER" << std::endl; + out << " 0" << std::endl; + out << "#STOP" << std::endl; + + return 1; +} + +void MeshIO::setMesh(const MeshLib::Mesh* mesh) +{ + _mesh = mesh; +} + +void MeshIO::writeElementsExceptLines(std::vector<MeshLib::Element*> const& ele_vec, std::ostream &out) +{ + const size_t ele_vector_size (ele_vec.size()); + const double epsilon (std::numeric_limits<double>::epsilon()); + std::vector<bool> non_line_element (ele_vector_size, true); + std::vector<bool> non_null_element (ele_vector_size, true); + size_t n_elements(0); + + for (size_t i(0); i < ele_vector_size; i++) { + if ((ele_vec[i])->getType() == MshElemType::EDGE) { + non_line_element[i] = false; + non_null_element[i] = false; + } else { + if (ele_vec[i]->getContent() < epsilon) { + non_null_element[i] = false; + } else { + n_elements++; + } + } + } + out << n_elements << std::endl; + for (size_t i(0), k(0); i < ele_vector_size; i++) + { + if (non_line_element[i] && non_null_element[i]) + { + out << k << " 0 " << MshElemType2String(ele_vec[i]->getType()) << " "; + const size_t nElemNodes (ele_vec[i]->getNNodes()-1); + for(size_t j = 0; j < nElemNodes; j++) + out << ele_vec[i]->getNode(nElemNodes-j-1)->getID() << " "; + out << ele_vec[i]->getNode(ele_vec[i]->getNNodes()-1)->getID() << std::endl; + k++; + } + } +} + + +} // end namespace FileIO diff --git a/FileIO/MeshIO.h b/FileIO/Legacy/MeshIO.h similarity index 93% rename from FileIO/MeshIO.h rename to FileIO/Legacy/MeshIO.h index ce4abd2533823067b1db37356802d6ba3ab644d1..d78462b0bd3f23cc9ee406f027f7cddd660291b2 100644 --- a/FileIO/MeshIO.h +++ b/FileIO/Legacy/MeshIO.h @@ -10,6 +10,9 @@ * Created on 2012-05-08 by Karsten Rink */ +/** + * This is currently just test functionality for testing ogs-6 mesh data structures! + */ #ifndef MESHIO_H_ #define MESHIO_H_ @@ -29,9 +32,6 @@ namespace MeshLib namespace FileIO { -/** - * Legacy support for mesh files for OGS Version 5 and below - */ class MeshIO : public Writer { public: diff --git a/FileIO/Legacy/OGSIOVer4.cpp b/FileIO/Legacy/OGSIOVer4.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e2f5674c87526c02fd53a3528a870898ead032c9 --- /dev/null +++ b/FileIO/Legacy/OGSIOVer4.cpp @@ -0,0 +1,781 @@ +/* + * OGSIOVer4.cpp + * + * Created on: Jan 14, 2010 + * Author: TF + */ + +#include <iomanip> +#include <sstream> + +//TODO6 #include "Configure.h" + +// FileIO +#include "MeshIO/GMSHInterface.h" +#include "OGSIOVer4.h" + +// Base +#include "StringTools.h" +#include "quicksort.h" + +// GEO +#include "GEOObjects.h" +#include "Point.h" +#include "Polygon.h" +#include "Polyline.h" +#include "SimplePolygonTree.h" +#include "Surface.h" +#include "Triangle.h" + +// for tests only +#include "PointVec.h" + +// MathLib +#include "AnalyticalGeometry.h" +#include "EarClippingTriangulation.h" + +using namespace GeoLib; + +namespace FileIO +{ +/************************************************************************** + GeoLib- Funktion: readPoints + Aufgabe: Lesen der GLI Points und schreiben in einen Vector + 08/2005 CC Implementation + 01/2010 TF big modifications +**************************************************************************/ +/** reads the points inclusive their names from input stream in + * using the OGS-4 file format */ +std::string readPoints(std::istream &in, std::vector<Point*>* pnt_vec, + bool &zero_based_indexing, std::map<std::string,size_t>* pnt_id_name_map) +{ + std::string line; + size_t cnt(0); + + getline(in, line); + // geometric key words start with the hash # + // while not found a new key word do ... + while (line.find("#") == std::string::npos && !in.eof() && !in.fail()) + { + // read id and point coordinates + std::stringstream inss(line); + size_t id; + double x, y, z; + inss >> id >> x >> y >> z; + if (!inss.fail ()) + { + if (cnt == 0) + { + if (id == 0) + zero_based_indexing = true; + else + zero_based_indexing = false; + } + pnt_vec->push_back(new Point(x, y, z)); + + // read mesh density + if (line.find("$MD") != std::string::npos) + { + double mesh_density; + size_t pos1(line.find_first_of("M")); + inss.str(line.substr(pos1 + 2, std::string::npos)); + inss >> mesh_density; + } + + // read name of point + size_t pos (line.find("$NAME")); + if (pos != std::string::npos) //OK + { + size_t end_pos ((line.substr (pos + 6)).find(" ")); + if (end_pos != std::string::npos) + (*pnt_id_name_map)[line.substr (pos + 6, end_pos)] = id; +// std::cout << "* name: " << line.substr (pos+6, end_pos) << ", id: " << id << std::endl; + else + (*pnt_id_name_map)[line.substr (pos + 6)] = id; +// std::cout << "name: " << line.substr (pos+6) << ", id: " << id << std::endl; + + } + + size_t id_pos (line.find("$ID")); + if (id_pos != std::string::npos) + std::cout << + "WARNING / ERROR: found tag $ID - please use tag $NAME for reading point names" + << cnt << std::endl; + cnt++; + } + getline(in, line); + } + + return line; +} + +/** reads points from a vector */ +void readPolylinePointVector(const std::string &fname, std::vector<Point*>& pnt_vec, + Polyline* ply, const std::string &path, std::vector<std::string> &errors) +{ + // open file + std::ifstream in((path + fname).c_str()); + if (!in) { + std::cerr << "error opening stream from " << fname << std::endl; + errors.push_back ("[readPolylinePointVector] error opening stream from " + fname); + return; + } + + double x, y, z; + while (in) + { + in >> x >> y >> z; + size_t pnt_id(pnt_vec.size()); + pnt_vec.push_back(new Point(x, y, z)); + ply->addPoint(pnt_id); + } +} + +/************************************************************************** + GeoLib-Method: Read + Task: Read polyline data from file + Programing: + 03/2004 CC Implementation + 09/2004 OK file path for PLY files + 07/2005 CC PLY id + 08/2005 CC parameter + 09/2005 CC itoa - convert integer to string + 01/2010 TF cleaned method from unused variables +**************************************************************************/ +/** read a single Polyline from stream in into the ply_vec-vector */ +std::string readPolyline(std::istream &in, + std::vector<Polyline*>* ply_vec, + std::map<std::string,size_t>& ply_vec_names, + std::vector<Point*>& pnt_vec, + bool zero_based_indexing, + const std::vector<size_t>& pnt_id_map, + const std::string &path, + std::vector<std::string> &errors) +{ + std::string line, name_of_ply; + Polyline* ply(new Polyline(pnt_vec)); + size_t type = 2; // need an initial value + + // Schleife ueber alle Phasen bzw. Komponenten + do { + in >> line; + if (line.find("$ID") != std::string::npos) // subkeyword found CC + in >> line; // read value + // id = strtol(line_string.data(), NULL, 0); + //.................................................................... + if (line.find("$NAME") != std::string::npos) // subkeyword found + { + in >> line; + name_of_ply = line.substr(0); // read value + } + //.................................................................... + if (line.find("$TYPE") != std::string::npos) // subkeyword found + { + in >> line; // read value + type = static_cast<size_t> (strtol(line.c_str(), NULL, 0)); + } + //.................................................................... + if (line.find("$EPSILON") != std::string::npos) // subkeyword found + in >> line; // read value + //.................................................................... + if (line.find("$MAT_GROUP") != std::string::npos) // subkeyword found + in >> line; // read value + //.................................................................... + if (line.find("$POINTS") != std::string::npos) // subkeyword found + { // read the point ids + in >> line; + if (type != 100) + while (!in.eof() && line.size() != 0 && (line.find("#") + == std::string::npos) && + (line.find("$") + == + std::string::npos)) + { + size_t pnt_id(str2number<size_t> (line)); + if (!zero_based_indexing) + pnt_id--; // one based indexing + size_t ply_size (ply->getNumberOfPoints()); + if (ply_size > 0) + { + if (ply->getPointID (ply_size - 1) != pnt_id_map[pnt_id]) + ply->addPoint(pnt_id_map[pnt_id]); + } + else + ply->addPoint(pnt_id_map[pnt_id]); + in >> line; + } + else { + std::cerr << "*** polyline is an arc *** reading not implemented" << std::endl; + errors.push_back ("[readPolyline] reading polyline as an arc is not implemented"); + } + // empty line or the keyword or subkeyword or end of file + } + //.................................................................... + if (line.find("$POINT_VECTOR") != std::string::npos) // subkeyword found + { + in >> line; // read file name + line = path + line; + readPolylinePointVector(line, pnt_vec, ply, path, errors); + } // subkeyword found + } while (line.find("#") == std::string::npos && line.size() != 0 && in); + + if (type != 100) + { + ply_vec_names.insert (std::pair<std::string,size_t>(name_of_ply, ply_vec->size())); + ply_vec->push_back(ply); + } + + return line; +} + +/************************************************************************** + GEOLib-Function: + Task: polyline read function + Programming: + 03/2004 CC Implementation + 05/2004 CC Modification + 04/2005 CC Modification calculate the minimal distance between points reference for + mesh density of line element calculation + 07/2005 CC read ID of polyline + 08/2005 CC parameter + 01/2010 TF changed signature of function +**************************************************************************/ +/** reads polylines */ +std::string readPolylines(std::istream &in, std::vector<Polyline*>* ply_vec, + std::map<std::string,size_t>& ply_vec_names, std::vector<Point*>& pnt_vec, + bool zero_based_indexing, const std::vector<size_t>& pnt_id_map, + const std::string &path, std::vector<std::string>& errors) +{ + if (!in) { + std::cerr << "*** readPolylines input stream error " << std::endl; + return std::string(""); + } + std::string tag("#POLYLINE"); + + while (!in.eof() && tag.find("#POLYLINE") != std::string::npos) + tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec, + zero_based_indexing, pnt_id_map, path, errors); + + return tag; +} + +void readTINFile(const std::string &fname, Surface* sfc, + std::vector<Point*> &pnt_vec, std::vector<std::string>& errors) +{ + // open file + std::ifstream in(fname.c_str()); + if (!in) { + std::cerr << "readTINFile error opening stream from " << fname + << std::endl; + errors.push_back ("readTINFile error opening stream from " + fname); + return; + } + + size_t id; + double x, y, z; + while (in) + { + // read id + in >> id; + // determine size + size_t pnt_pos(pnt_vec.size()); + // read first point + in >> x >> y >> z; + pnt_vec.push_back(new Point(x, y, z)); + // read second point + in >> x >> y >> z; + pnt_vec.push_back(new Point(x, y, z)); + // read third point + in >> x >> y >> z; + pnt_vec.push_back(new Point(x, y, z)); + // create new Triangle + sfc->addTriangle(pnt_pos, pnt_pos + 1, pnt_pos + 2); + } +} + +/************************************************************************** + GeoLib-Method: readSurface + Task: Read surface data from input stream + Programing: + 03/2004 OK Implementation + 05/2005 OK EPSILON + 09/2005 CC file_path_base + 01/2010 TF signatur modification, reimplementation +**************************************************************************/ +/** read a single Surface */ +std::string readSurface(std::istream &in, + std::vector<Polygon*> &polygon_vec, + std::vector<Surface*> &sfc_vec, + std::map<std::string,size_t>& sfc_names, + const std::vector<Polyline*> &ply_vec, + const std::map<std::string, size_t>& ply_vec_names, + std::vector<Point*> &pnt_vec, + std::string const& path, std::vector<std::string>& errors) +{ + std::string line; + Surface* sfc(NULL); + + int type (-1); + std::string name; + size_t ply_id (0); // std::numeric_limits<size_t>::max()); + + do { + in >> line; + if (line.find("$ID") != std::string::npos) // subkeyword found CC + in >> line; // read value + // id = strtol(line_string.data(), NULL, 0); + //.................................................................... + if (line.find("$NAME") != std::string::npos) // subkeyword found + { + in >> line; // read value + name = line.substr(0); + } + //.................................................................... + if (line.find("$TYPE") != std::string::npos) // subkeyword found + { + in >> line; // read value + type = strtol(line.c_str(), NULL, 0); + } + //.................................................................... + if (line.find("$EPSILON") != std::string::npos) // subkeyword found + in >> line; // read value + //.................................................................... + if (line.find("$TIN") != std::string::npos) // subkeyword found + { + in >> line; // read value (file name) + line = path + line; + sfc = new Surface(pnt_vec); + + readTINFile(line, sfc, pnt_vec, errors); + if (sfc->getNTriangles() == 0) { + delete sfc; + sfc = NULL; + } +// std::cout << "ok" << std::endl; + } + //.................................................................... + if (line.find("$MAT_GROUP") != std::string::npos) // subkeyword found + in >> line; // read value + //.................................................................... + if (line.find("$POLYLINES") != std::string::npos) // subkeyword found + { // read the name of the polyline(s) + in >> line; + while (!in.eof() && line.size() != 0 + && (line.find("#") == std::string::npos) + && (line.find("$") == std::string::npos)) + { + // we did read the name of a polyline -> search the id for polyline + std::map<std::string,size_t>::const_iterator it (ply_vec_names.find ( + line)); + if (it != ply_vec_names.end()) + ply_id = it->second; + else + ply_id = ply_vec.size(); + + if (ply_id == ply_vec.size()) { + std::cerr << "polyline for surface not found!" << std::endl; + errors.push_back("[readSurface] polyline for surface not found!"); + } else { + if (type == 3) { + std::cerr << "surface type 3: flat surface with any normal direction - - reading not implemented" + << std::endl; + errors.push_back("[readSurface] surface type 3: flat surface with any normal direction - - reading not implemented"); + } + if (type == 2) { + std::cerr << "vertical surface - reading not implemented" << std::endl; + errors.push_back("[readSurface] vertical surface - reading not implemented"); + } + } + in >> line; + } + // empty line or a keyword is found + } + } while (line.find("#") == std::string::npos && line.size() != 0 && in); + + if (!name.empty()) + sfc_names.insert(std::pair<std::string,size_t>(name,sfc_vec.size())); + + if (sfc) + // surface create by TIN + sfc_vec.push_back (sfc); + else + { + // surface created by polygon + if (ply_id != std::numeric_limits<size_t>::max() && ply_id != ply_vec.size()) + { + if (ply_vec[ply_id]->isClosed()) + { + polygon_vec.push_back (new Polygon (*(ply_vec[ply_id]), true)); + } + else + { + std::cerr << "\n\tcannot create surface " << name << " from polyline: " + << " polyline is not closed.\n"; + } + } + } + + return line; +} + +/************************************************************************** + GEOLib-Method: + Task: Surface read function + Programming: + 03/2004 OK Implementation + 05/2004 CC Modification + 01/2010 TF changed signature of function, big modifications +**************************************************************************/ +std::string readSurfaces(std::istream &in, + std::vector<Surface*> &sfc_vec, + std::map<std::string, size_t>& sfc_names, + const std::vector<Polyline*> &ply_vec, + const std::map<std::string,size_t>& ply_vec_names, + std::vector<Point*> &pnt_vec, + const std::string &path, std::vector<std::string>& errors) +{ + if (!in.good()) + { + std::cerr << "*** readSurfaces input stream error " << std::endl; + return std::string(""); + } + std::string tag("#SURFACE"); + + std::vector<Polygon*> polygon_vec; + + while (!in.eof() && tag.find("#SURFACE") != std::string::npos) + { + size_t n_polygons (polygon_vec.size()); + tag = readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec, ply_vec_names, pnt_vec, + path, errors); + if (n_polygons < polygon_vec.size()) { + // subdivide polygon in simple polygons + GeoLib::Surface * sfc(GeoLib::Surface::createSurface( + *(dynamic_cast<GeoLib::Polyline*> (polygon_vec[polygon_vec.size() - 1])))); + sfc_vec.push_back(sfc); + } + } + for (size_t k(0); k < polygon_vec.size(); k++) + delete polygon_vec[k]; +// std::cout << "readSurfaces: number of read polygons " << polygon_vec.size() << std::endl; + +// // subdivide all polygons in simple polygons +// for (std::vector<GeoLib::Polygon*>::iterator polygon_it (polygon_vec.begin()); +// polygon_it != polygon_vec.end(); polygon_it++) { +// // compute list of simple polygons +// (*polygon_it)->computeListOfSimplePolygons (); +// } + +// // forest consist of (hierarchy) trees +// std::list<SimplePolygonTree*> polygon_forest; +// // create polygon forest +// for (std::vector<GeoLib::Polygon*>::iterator polygon_it (polygon_vec.begin()); +// polygon_it != polygon_vec.end(); polygon_it++) { +// // get the list and insert the elements as SimplePolygonTree items into the forest +// const std::list<Polygon*> simple_polygon_list ((*polygon_it)->getListOfSimplePolygons()); +// for (std::list<Polygon*>::const_iterator simple_polygon_it (simple_polygon_list.begin()); +// simple_polygon_it != simple_polygon_list.end(); simple_polygon_it++) { +// SimplePolygonTree *spt (new SimplePolygonTree (*simple_polygon_it)); +// polygon_forest.push_back (spt); +// } +// } +// std::cout << "readSurfaces: \"Polygon forest\" consists of " << polygon_forest.size() << " trees" << std::endl; +// +// // create the hierarchy +// createPolygonTree (polygon_forest); +// std::cout << "readSurfaces: \"Polygon forest\" consists of " << polygon_forest.size() << " trees" << std::endl; +// +// std::string out_fname ("GMSHTest.geo"); +// std::cout << "writing input file for GMSH " << out_fname << " ... " << std::flush; +// GMSHInterface gmsh_io (out_fname); +// // writing points +// gmsh_io.writeGMSHPoints(pnt_vec); +// // writing simple polygon tree +// for (std::list<GeoLib::SimplePolygonTree*>::const_iterator polygon_tree_it (polygon_forest.begin()); +// polygon_tree_it != polygon_forest.end(); polygon_tree_it++) { +// (*polygon_tree_it)->visitAndProcessNodes (gmsh_io); +// } +// std::cout << "done" << std::endl; + + // create surfaces from simple polygons +// for (std::vector<GeoLib::Polygon*>::iterator polygon_it (polygon_vec.begin()); +// polygon_it != polygon_vec.end(); polygon_it++) { +// +// const std::list<GeoLib::Polygon*>& list_of_simple_polygons ((*polygon_it)->getListOfSimplePolygons()); +// +// for (std::list<GeoLib::Polygon*>::const_iterator simple_polygon_it (list_of_simple_polygons.begin()); +// simple_polygon_it != list_of_simple_polygons.end(); simple_polygon_it++) { +// +// std::list<GeoLib::Triangle> triangles; +// MathLib::earClippingTriangulationOfPolygon(*simple_polygon_it, triangles); +// std::cout << "done - " << triangles.size () << " triangles " << std::endl; +// +// Surface *sfc(new Surface(pnt_vec)); +// // add Triangles to Surface +// std::list<GeoLib::Triangle>::const_iterator it (triangles.begin()); +// while (it != triangles.end()) { +// sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]); +// it++; +// } +// sfc_vec.push_back (sfc); +// } +// } + + return tag; +} + +bool readGLIFileV4(const std::string& fname, GEOObjects* geo, std::string& unique_name, std::vector<std::string>& errors) +{ + std::cout << "GeoLib::readGLIFile open stream from file " << fname + << " ... " << std::flush; + std::ifstream in(fname.c_str()); + if (!in) { + std::cerr << "error opening stream from " << fname << std::endl; + errors.push_back("[readGLIFileV4] error opening stream from " + fname); + return false; + } + std::cout << "done" << std::endl; + + std::string tag; + while (tag.find("#POINTS") == std::string::npos && !in.eof()) + getline (in, tag); + + // read names of points into vector of strings + std::map<std::string,size_t>* pnt_id_names_map (new std::map<std::string,size_t>); + bool zero_based_idx(true); + std::vector<Point*>* pnt_vec(new std::vector<Point*>); + std::cout << "read points from stream ... " << std::flush; + tag = readPoints(in, pnt_vec, zero_based_idx, pnt_id_names_map); + std::cout << " ok, " << pnt_vec->size() << " points read" << std::endl; + + unique_name = BaseLib::getFileNameFromPath(fname, true); + if (!pnt_vec->empty()) + geo->addPointVec(pnt_vec, unique_name, pnt_id_names_map); // KR: insert into GEOObjects if not empty + + // extract path for reading external files + std::string path; + BaseLib::extractPath(fname, path); + + // read names of plys into temporary string-vec + std::map<std::string,size_t>* ply_names (new std::map<std::string,size_t>); + std::vector<Polyline*>* ply_vec(new std::vector<Polyline*>); + if (tag.find("#POLYLINE") != std::string::npos && in) + { + std::cout << "read polylines from stream ... " << std::flush; + tag = readPolylines(in, ply_vec, *ply_names, *pnt_vec, + zero_based_idx, geo->getPointVecObj( + unique_name)->getIDMap(), path, errors); + std::cout << " ok, " << ply_vec->size() << " polylines read" + << std::endl; + } + else + std::cerr + << "tag #POLYLINE not found or input stream error in GEOObjects" + << std::endl; + + std::vector<Surface*>* sfc_vec(new std::vector<Surface*>); + std::map<std::string,size_t>* sfc_names (new std::map<std::string,size_t>); + if (tag.find("#SURFACE") != std::string::npos && in) + { + std::cout << "read surfaces from stream ... " << std::flush; + tag = readSurfaces(in, *sfc_vec, *sfc_names, *ply_vec, *ply_names, *pnt_vec, path, errors); + std::cout << " ok, " << sfc_vec->size() << " surfaces read" + << std::endl; + } + else + std::cerr + << "tag #SURFACE not found or input stream error in GEOObjects" + << std::endl; + in.close(); + + if (!ply_vec->empty()) + geo->addPolylineVec(ply_vec, unique_name, ply_names); // KR: insert into GEOObjects if not empty + if (!sfc_vec->empty()) + geo->addSurfaceVec(sfc_vec, unique_name, sfc_names); // KR: insert into GEOObjects if not empty + + if (errors.empty()) + return true; + else + return false; +} + +void writeGLIFileV4 (const std::string& fname, + const std::string& geo_name, + const GeoLib::GEOObjects& geo) +{ + GeoLib::PointVec const*const pnt_vec(geo.getPointVecObj(geo_name)); + std::vector<GeoLib::Point*> const*const pnts (pnt_vec->getVector()); + std::ofstream os (fname.c_str()); + if (pnts) { + std::string pnt_name; + const size_t n_pnts(pnts->size()); + std::cout << "writing " << n_pnts << " points to file " << fname << + std::endl; + os << "#POINTS" << std::endl; + os.precision (20); + for (size_t k(0); k < n_pnts; k++) { + os << k << " " << *((*pnts)[k]) << std::flush; + if (pnt_vec->getNameOfElementByID(k, pnt_name)) { + os << " $NAME " << pnt_name << std::flush; + } + os << std::endl; + } + } + + std::cout << "writing " << std::flush; + const GeoLib::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_name)); + if (plys_vec) + { + const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); + std::cout << plys->size () << " polylines to file " << fname << std::endl; + for (size_t k(0); k < plys->size(); k++) + { + os << "#POLYLINE" << std::endl; + std::string polyline_name; + plys_vec->getNameOfElement((*plys)[k], polyline_name); + os << " $NAME " << std::endl << " " << polyline_name << std::endl; + os << " $POINTS" << std::endl; + for (size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++) + os << " " << ((*plys)[k])->getPointID(j) << std::endl; + } + } + + std::cout << "writing " << std::flush; + if (plys_vec) + { + const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); + std::cout << plys->size () << " closed polylines as surfaces to file " << fname << + std::endl; + for (size_t k(0); k < plys->size(); k++) + if ((*plys)[k]->isClosed()) + { + os << "#SURFACE" << std::endl; + os << " $NAME " << std::endl << " " << k << std::endl; //plys_vec->getNameOfElement ((*plys)[k]) << std::endl; + os << " $TYPE " << std::endl << " 0" << std::endl; + os << " $POLYLINES" << std::endl << " " << k << std::endl; //plys_vec->getNameOfElement ((*plys)[k]) << std::endl; + } + } + + os << "#STOP" << std::endl; + os.close (); +} + +void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects& geo) +{ + std::vector<std::string> geo_names; + geo.getGeometryNames (geo_names); + + // extract path for reading external files + std::string path; + BaseLib::extractPath(fname, path); + + std::ofstream os (fname.c_str()); + + size_t pnts_offset (0); + std::vector<size_t> pnts_id_offset; + pnts_id_offset.push_back (0); + + // writing all points + os << "#POINTS" << std::endl; + for (size_t j(0); j < geo_names.size(); j++) + { + os.precision (20); + GeoLib::PointVec const*const pnt_vec(geo.getPointVecObj(geo_names[j])); + std::vector<GeoLib::Point*> const*const pnts (pnt_vec->getVector()); + if (pnts) { + std::string pnt_name; + const size_t n_pnts(pnts->size()); + for (size_t k(0); k < n_pnts; k++) { + os << pnts_offset + k << " " << *((*pnts)[k]) << std::flush; + if (pnt_vec->getNameOfElementByID(k, pnt_name)) { + os << " $NAME " << pnt_name << std::flush; + } + os << std::endl; + } + pnts_offset += pnts->size(); + pnts_id_offset.push_back (pnts_offset); + } + } + + std::cout << "wrote " << pnts_offset << " points" << std::endl; + + // writing all stations + std::vector<std::string> stn_names; + geo.getStationVectorNames (stn_names); + for (size_t j(0); j < stn_names.size(); j++) + { + os.precision (20); + const std::vector<GeoLib::Point*>* pnts (geo.getStationVec(stn_names[j])); + if (pnts) + { + for (size_t k(0); k < pnts->size(); k++) + os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME " << + static_cast<GeoLib::Station*>((*pnts)[k])->getName() << + std::endl; + pnts_offset += pnts->size(); + pnts_id_offset.push_back (pnts_offset); + } + } + + size_t plys_cnt (0); + + // writing all polylines + for (size_t j(0); j < geo_names.size(); j++) + { + const GeoLib::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_names[j])); + if (plys_vec) { + const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); + for (size_t k(0); k < plys->size(); k++) { + os << "#POLYLINE" << std::endl; + std::string ply_name; + if (plys_vec->getNameOfElementByID (plys_cnt, ply_name)) + os << "\t$NAME " << std::endl << "\t\t" << ply_name << std::endl; + else + os << "\t$NAME " << std::endl << "\t\t" << geo_names[j] << "-" << plys_cnt << std::endl; + os << "\t$POINTS" << std::endl; + for (size_t l(0); l < (*plys)[k]->getNumberOfPoints(); l++) + os << "\t\t" << pnts_id_offset[j] + ((*plys)[k])->getPointID(l) << std::endl; + plys_cnt++; + } + } + } + + // writing surfaces as TIN files + size_t sfcs_cnt (0); + for (size_t j(0); j < geo_names.size(); j++) + { + const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_names[j])); + if (sfcs_vec) { + const std::vector<GeoLib::Surface*>* sfcs (sfcs_vec->getVector()); + for (size_t k(0); k < sfcs->size(); k++) + { + os << "#SURFACE" << std::endl; + std::string sfc_name(path); + if (sfcs_vec->getNameOfElementByID (sfcs_cnt, sfc_name)) { + os << "\t$NAME " << std::endl << "\t\t" << sfc_name << std::endl; + } else { + os << "\t$NAME " << std::endl << "\t\t" << sfcs_cnt << std::endl; + sfc_name += number2str (sfcs_cnt); + } + sfc_name += ".tin"; + os << "\t$TIN" << std::endl; + os << "\t\t" << sfc_name << std::endl; + // create tin file + std::ofstream tin_os (sfc_name.c_str()); + GeoLib::Surface const& sfc (*(*sfcs)[k]); + const size_t n_tris (sfc.getNTriangles()); + for (size_t l(0); l < n_tris; l++) { + GeoLib::Triangle const& tri (*(sfc[l])); + tin_os << l << " " << *(tri.getPoint(0)) << " " << *(tri.getPoint(1)) << " " << *(tri.getPoint(2)) << std::endl; + } + tin_os.close(); + + sfcs_cnt++; + } + } + } + + os << "#STOP" << std::endl; + os.close (); +} +} // end namespace diff --git a/FileIO/Legacy/OGSIOVer4.h b/FileIO/Legacy/OGSIOVer4.h new file mode 100644 index 0000000000000000000000000000000000000000..be7742540c74db7b3b75e465fd36a7292936a093 --- /dev/null +++ b/FileIO/Legacy/OGSIOVer4.h @@ -0,0 +1,42 @@ +/* + * OGSIOVer4.h + * + * Created on: Jan 14, 2010 + * Author: TF / KR + */ + +#ifndef OGSIOVER4_H_ +#define OGSIOVER4_H_ + +#include <fstream> +#include <sstream> +#include <string> +#include <vector> + +#include "Point.h" +#include "Polyline.h" +#include "StringTools.h" +#include "Surface.h" + +// forward declaration +namespace GeoLib +{ +class GEOObjects; +} + +namespace FileIO +{ +/** I/O - routines for the OGS-4 gli file format */ + +/** method reads geometric objects from file in gli format */ +bool readGLIFileV4 (const std::string& fname, GeoLib::GEOObjects* geo, std::string& unique_name, std::vector<std::string>& errors); + +void writeGLIFileV4 (const std::string& fname, + const std::string& proj_name, + const GeoLib::GEOObjects& geo); + +void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects& geo); + +} // end namespace + +#endif /* OGSIOVER4_H_ */ diff --git a/FileIO/NetCDFInterface.cpp b/FileIO/NetCDFInterface.cpp deleted file mode 100644 index b8c76a36cbd0f56f2b8017eceddab1afaa90f2ca..0000000000000000000000000000000000000000 --- a/FileIO/NetCDFInterface.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/** - * \file NetCDFInterface.cpp - * 29/07/2010 YW Initial implementations - */ -#include "NetCDFInterface.h" -#include <stdio.h> -#include <netcdf.h> - -#include "Mesh.h" -#include "Node.h" -#include "Elements/Quad.h" - -/* Names of variables. */ -#define DIM_RLAT "rlat" -#define DIM_RLON "rlon" -#define LAT_NAME "lat" -#define LON_NAME "lon" -/* Length of the original output NetCDF file. */ -#define LEN_ORIGINAL 18 - -/* Handle errors by printing an error message and exiting with a - * non-zero status. */ -#define HANDLE_ERROR(e) {printf("Error: %s\n", nc_strerror(e)); exit(-1); } - -namespace FileIO -{ -void NetCDFInterface::readNetCDFData(std::string &ifname, - std::vector<GeoLib::Point*>* points_vec, - GeoLib::GEOObjects* obj, - size_t &NRLAT, - size_t &NRLON) -{ - int ncid; - int rlat_dimid, rlon_dimid; - int lat_varid, lon_varid; - int choose_varid; - - /* The start and count arrays will tell the netCDF library where to read our data. */ - static size_t start2[2], count2[2]; - static size_t start3[3], count3[3]; - static size_t start4[4], count4[4]; - - /* Error handling. */ - int status; - - /* Open the file. */ - std::cout << "Open NetCDF file " << ifname << "\n" << std::flush; - status = nc_open(ifname.c_str(), NC_NOWRITE, &ncid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - /* Get the lengths of dimensions, such as "rlat" and "rlat". */ - status = nc_inq_dimid(ncid, DIM_RLAT, &rlat_dimid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - status = nc_inq_dimlen(ncid, rlat_dimid, &NRLAT); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - status = nc_inq_dimid(ncid, DIM_RLON, &rlon_dimid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - status = nc_inq_dimlen(ncid, rlon_dimid, &NRLON); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - /* Get the choosen variable name from the opened NetCDF file. */ - std::string nc_fname; - size_t indexChar; - indexChar = ifname.find_last_of('/'); - if(indexChar == std::string::npos) - nc_fname = ifname; - else - nc_fname = ifname.substr(indexChar + 1); - size_t len_varname = nc_fname.size() - LEN_ORIGINAL; - std::string var_name; - var_name = nc_fname.substr(0,len_varname); - - /* Get the varids of the netCDF variables, such as longitude, latitude, - * temperature or precipitation, and so on. */ - status = nc_inq_varid(ncid, LON_NAME, &lon_varid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - status = nc_inq_varid(ncid, LAT_NAME, &lat_varid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - status = nc_inq_varid(ncid, var_name.c_str(), &choose_varid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - /* Program variables to hold the data we will read. We will only - need enough space to hold one timestep of data; one record.*/ - size_t len_vals = NRLAT * NRLON; - float* lat_in = new float[len_vals]; - float* lon_in = new float[len_vals]; - float* var_in = new float[len_vals]; - - /* Read the data. Since we know the contents of the file we know - * that the data arrays in this program are the correct size to - * hold one timestep. */ - count2[0] = NRLAT; - count2[1] = NRLON; - count3[0] = 1; - count3[1] = NRLAT; - count3[2] = NRLON; - count4[0] = 1; - count4[1] = 1; - count4[2] = NRLAT; - count4[3] = NRLON; - - for (size_t i = 0; i < 2; i++) - start2[i] = 0; - for (size_t i = 0; i < 3; i++) - start3[i] = 0; - for (size_t i = 0; i < 4; i++) - start4[i] = 0; - - /* Read the above netCDF variables with their corresponding varids. */ - status = nc_get_vara_float(ncid, lon_varid, start2, count2, lon_in); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - status = nc_get_vara_float(ncid, lat_varid, start2, count2, lat_in); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - if (var_name.compare("T_2M") == 0) - { - status = nc_get_vara_float(ncid, choose_varid, start4, count4, var_in); - if (status != NC_NOERR) - HANDLE_ERROR(status); - } - else if (var_name.compare("TOT_PREC") == 0) - { - status = nc_get_vara_float(ncid, choose_varid, start3, count3, var_in); - if (status != NC_NOERR) - HANDLE_ERROR(status); - } - else if (var_name.compare("HSURF") == 0) - { - status = nc_get_vara_float(ncid, choose_varid, start3, count3, var_in); - if (status != NC_NOERR) - HANDLE_ERROR(status); - } - - /* Close the file. */ - status = nc_close(ncid); - if (status != NC_NOERR) - HANDLE_ERROR(status); - - printf("Reading netCDF file successfully!\n"); - - for (size_t i = 0; i < len_vals; i++) - points_vec->push_back(new GeoLib::Point( lon_in[i], lat_in[i], var_in[i] )); - - delete [] lat_in; - delete [] lon_in; - delete [] var_in; - - obj->addPointVec(points_vec, ifname); -} - -MeshLib::Mesh* NetCDFInterface::createMeshFromPoints(std::vector<GeoLib::Point*>* points_vec, - size_t &NRLAT, - size_t &NRLON) -{ - std::cout << "Converting points data to mesh with quad elements\n"; - - // setmesh nodes - size_t nNodes = points_vec->size(); - std::vector<MeshLib::Node*> nodes(nNodes); - for (size_t i = 0; i < nNodes; i++) - { - MeshLib::Node* node = new MeshLib::Node((*(*points_vec)[i])[0], (*(*points_vec)[i])[1], (*(*points_vec)[i])[2]); - nodes[i] = node; - } - - // set mesh elements - std::vector<MeshLib::Element*> elements; - for (size_t i = 0; i < NRLAT - 1; i++) - for (size_t j = 0; j < NRLON - 1; j++) - { - size_t n_Elems = i * NRLON + j; - MeshLib::Element* elem = new MeshLib::Quad(nodes[n_Elems], nodes[n_Elems+1], nodes[n_Elems+NRLON+1], nodes[n_Elems+NRLON], 0); - elements.push_back(elem); - } - - MeshLib::Mesh* mesh = new MeshLib::Mesh("NetCDF", nodes, elements); - std::cout << "Mesh is generated successfully!\n" << std::endl; - return mesh; -} -} // end namespace FileIO diff --git a/FileIO/NetCDFInterface.h b/FileIO/NetCDFInterface.h deleted file mode 100644 index 3f84c2579a94d78e2b3067a93be112e43143cd40..0000000000000000000000000000000000000000 --- a/FileIO/NetCDFInterface.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * \file NetCDFInterface.h - * 29/07/2010 YW Initial implementation - */ - -#ifndef NetCDFInterface_H -#define NetCDFInterface_H - -#include "GEOObjects.h" -#include <string> -#include <vector> - -namespace GeoLib -{ -class GEOObjects; -} - -namespace MeshLib -{ -class Mesh; -} - -namespace FileIO -{ -class NetCDFInterface -{ -public: - /// Import climate data from a NetCDF file. - static void readNetCDFData(std::string &fname, - std::vector<GeoLib::Point*>* points_vec, - GeoLib::GEOObjects* geo_obj, - size_t &NRLAT, - size_t &NRLON); - /// Convert imported point data to an CFEMesh. - static MeshLib::Mesh* createMeshFromPoints(std::vector<GeoLib::Point*>* points_vec, - size_t &NRLAT, - size_t &NRLON); - -private: -}; -} // end namespace - -#endif /* NetCDFInterface_H */ diff --git a/FileIO/readNonBlankLineFromInputStream.cpp b/FileIO/readNonBlankLineFromInputStream.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b15875afb7e6585ab2fd5c54507a26995729814 --- /dev/null +++ b/FileIO/readNonBlankLineFromInputStream.cpp @@ -0,0 +1,48 @@ +/* + * readNonBlankLineFromInputStream.cpp + * + * Created on: Apr 19, 2011 + * Author: TF + */ + +#include "readNonBlankLineFromInputStream.h" + +std::string readNonBlankLineFromInputStream(std::istream & in) +{ + std::string line; + + bool not_finished (true); + while (not_finished) + { + // read line + getline(in, line); + if (!in.fail()) + { + // skip initial space characters + std::string::size_type i (line.find_first_not_of(" ", 0)); + // search comment symbol ; + std::string::size_type j (line.find(";", i)); + if (j == i) // first non space character is equal to the comment symbol + not_finished = true; + else + { + if ((i != std::string::npos)) + // cut string from first non blank space character until the first comment character + line = line.substr(i, j - i); + + // remove last blank spaces + i = line.find_last_not_of(" "); + if (i != std::string::npos) + line = line.substr(0, i + 1); + + not_finished = false; + } + } + else + { + line = ""; + not_finished = false; + } + } + return line; +} diff --git a/FileIO/readNonBlankLineFromInputStream.h b/FileIO/readNonBlankLineFromInputStream.h new file mode 100644 index 0000000000000000000000000000000000000000..85a58b2775fc7e52efb5423f842b54b694fb0022 --- /dev/null +++ b/FileIO/readNonBlankLineFromInputStream.h @@ -0,0 +1,21 @@ +/* + * readNonBlankLineFromInputStream.h + * + * Created on: Apr 19, 2011 + * Author: TF + */ + +#ifndef READNONBLANKLINEFROMINPUTSTREAM_H_ +#define READNONBLANKLINEFROMINPUTSTREAM_H_ + +#include <istream> +#include <string> + +/** + * read a non blank line from given input stream + * @param in the input stream + * @return read line into a string + */ +std::string readNonBlankLineFromInputStream(std::istream & in); + +#endif /* READNONBLANKLINEFROMINPUTSTREAM_H_ */ diff --git a/GeoLib/PolylineWithSegmentMarker.cpp b/GeoLib/PolylineWithSegmentMarker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fda355893477abf1e4339e37255ec0a59c80abc1 --- /dev/null +++ b/GeoLib/PolylineWithSegmentMarker.cpp @@ -0,0 +1,47 @@ +/* + * PolylineWithSegmentMarker.cpp + * + * Created on: Apr 3, 2012 + * Author: fischeth + */ + +#include "PolylineWithSegmentMarker.h" + +namespace GeoLib { + +PolylineWithSegmentMarker::PolylineWithSegmentMarker(GeoLib::Polyline const& polyline) + : GeoLib::Polyline(polyline) +{ + const size_t n_pnts(getNumberOfPoints()); + _marker.resize(n_pnts); + for (size_t k(0); k<n_pnts; k++) { + _marker[k] = false; + } +} + +PolylineWithSegmentMarker::~PolylineWithSegmentMarker() +{} + + +void PolylineWithSegmentMarker::markSegment(size_t seg_num, bool mark_val) +{ + _marker[seg_num] = mark_val; +} +bool PolylineWithSegmentMarker::isSegmentMarked(size_t seg_num) const +{ + return _marker[seg_num]; +} + +void PolylineWithSegmentMarker::addPoint(size_t pnt_id) +{ + Polyline::addPoint(pnt_id); + _marker.push_back(false); +} + +void PolylineWithSegmentMarker::insertPoint(size_t pos, size_t pnt_id) +{ + Polyline::insertPoint(pos, pnt_id); + _marker.insert(_marker.begin()+pos, _marker[pos]); +} + +} // end GeoLib diff --git a/GeoLib/PolylineWithSegmentMarker.h b/GeoLib/PolylineWithSegmentMarker.h new file mode 100644 index 0000000000000000000000000000000000000000..4c6a156efd4150a639b81a4b745d730f303ae49e --- /dev/null +++ b/GeoLib/PolylineWithSegmentMarker.h @@ -0,0 +1,53 @@ +/* + * PolylineWithSegmentMarker.h + * + * Created on: Apr 3, 2012 + * Author: fischeth + */ + +#ifndef POLYLINEWITHSEGMENTMARKER_H_ +#define POLYLINEWITHSEGMENTMARKER_H_ + +#include "Polyline.h" + +namespace GeoLib { + +class PolylineWithSegmentMarker: public GeoLib::Polyline { +public: + PolylineWithSegmentMarker(GeoLib::Polyline const& polyline); + virtual ~PolylineWithSegmentMarker(); + /** + * Method marks the segment (default mark is true). + * @param seg_num the segment number that should be marked + * @param mark_val the value of the flag (true or false) + */ + void markSegment(size_t seg_num, bool mark_val = true); + /** + * Method returns the value of the mark for the given segment. + * @param seg_num segment number + * @return either true if the segment is marked or false else + */ + bool isSegmentMarked(size_t seg_num) const; + + /** + * Method calls @see Polyline::addPoint() and initializes the mark of the + * corresponding line segment. + * @param pnt_id @see Polyline::addPoint() + */ + virtual void addPoint(size_t pnt_id); + + /** + * Method calls the @see Polyline::insertPoint() and initializes the inserted line segment with the same + * value the previous line segment had. + * @param pos @see Polyline::insertPoint() + * @param pnt_id @see Polyline::insertPoint() + */ + virtual void insertPoint(size_t pos, size_t pnt_id); + +private: + std::vector<bool> _marker; +}; + +} + +#endif /* POLYLINEWITHSEGMENTMARKER_H_ */ diff --git a/Gui/DataView/DataView.cpp b/Gui/DataView/DataView.cpp index 25d7e2cbd61fbcfd149676dc0801f455ea7eab13..10143dec959d7862ca5e54d485b535071be34fac 100644 --- a/Gui/DataView/DataView.cpp +++ b/Gui/DataView/DataView.cpp @@ -21,7 +21,7 @@ #include <QObject> #include <QSettings> -#include "MeshIO.h" +#include "Legacy/MeshIO.h" #include "Writer.h" // necessary to avoid Linker Error in Windows DataView::DataView( QWidget* parent /*= 0*/ ) diff --git a/Gui/DataView/MshItem.cpp b/Gui/DataView/MshItem.cpp index 589dc9ca644a41e8a62bebefe0ea4fbface394ce..27982efca6fadace4dd88a64e6494850ea4cbc2b 100644 --- a/Gui/DataView/MshItem.cpp +++ b/Gui/DataView/MshItem.cpp @@ -12,11 +12,11 @@ * \param parent The parent item in the tree * \param grid The mesh associated with this item */ -MshItem::MshItem(const QList<QVariant> &data, TreeItem* parent, MeshLib::Mesh* grid) +MshItem::MshItem(const QList<QVariant> &data, TreeItem* parent, const MeshLib::Mesh* mesh) : TreeItem(data, parent) { _meshSource = VtkMeshSource::New(); - _meshSource->SetMesh(grid); + _meshSource->SetMesh(mesh); } MshItem::~MshItem() diff --git a/Gui/DataView/MshItem.h b/Gui/DataView/MshItem.h index 6cac3fef089c5e73cd3d7a35e312f7cb97655ee1..6341f190e34f6938609192ddc682f059ff7d8e8c 100644 --- a/Gui/DataView/MshItem.h +++ b/Gui/DataView/MshItem.h @@ -23,7 +23,7 @@ class MshItem : public TreeItem { public: /// Constructor, automatically generates VTK object of the given mesh. - MshItem(const QList<QVariant> &data, TreeItem* parent, MeshLib::Mesh* grid); + MshItem(const QList<QVariant> &data, TreeItem* parent, const MeshLib::Mesh* grid); ~MshItem(); /// Returns the mesh as a GridAdapter. diff --git a/Gui/DataView/MshModel.cpp b/Gui/DataView/MshModel.cpp index 89db5327b89d190930654716c4017cbfea7568cb..6b520d67ff8678481dd6e5e56667252acdbadebc 100644 --- a/Gui/DataView/MshModel.cpp +++ b/Gui/DataView/MshModel.cpp @@ -45,7 +45,7 @@ void MshModel::addMesh(MeshLib::Mesh* mesh) this->addMeshObject(mesh); } -void MshModel::addMeshObject(MeshLib::Mesh* mesh) +void MshModel::addMeshObject(const MeshLib::Mesh* mesh) { std::cout << "name: " << mesh->getName() << std::endl; QString display_name (QString::fromStdString(mesh->getName())); @@ -123,15 +123,9 @@ bool MshModel::removeMesh(const QModelIndex &idx) { MshItem* item = dynamic_cast<MshItem*>(this->getItem(idx)); if (item) - { - emit meshRemoved(this, idx); - _rootItem->removeChildren(item->row(),1); - reset(); - return true; - } + return this->removeMesh(item->getMesh()->getName()); return false; } - return false; } @@ -149,8 +143,7 @@ bool MshModel::removeMesh(const std::string &name) } } - std::cout << "MshModel::removeMesh() - No entry found with name \"" << name << "." << - std::endl; + std::cout << "MshModel::removeMesh() - No entry found with name \"" << name << "." << std::endl; return false; } diff --git a/Gui/DataView/MshModel.h b/Gui/DataView/MshModel.h index 9d7a586fc1b648fdb25e764650e3b6af50766589..c44442b0fbe317b2e37a0e25e59b3c8c39e7f106 100644 --- a/Gui/DataView/MshModel.h +++ b/Gui/DataView/MshModel.h @@ -51,7 +51,7 @@ public slots: private: /// Adds the mesh to the GUI-Mesh-Model und -View - void addMeshObject(MeshLib::Mesh* mesh); + void addMeshObject(const MeshLib::Mesh* mesh); /// Checks if the name of the mesh is already exists, if so it generates a unique name. //bool isUniqueMeshName(std::string &name); diff --git a/Gui/VtkVis/MeshFromRasterDialog.cpp b/Gui/VtkVis/MeshFromRasterDialog.cpp index 597a83ca1fbe6e61df516662bab42bf164c95866..e67ff6fe6671ad6f1ded4c8cfea6c0c4108a922f 100644 --- a/Gui/VtkVis/MeshFromRasterDialog.cpp +++ b/Gui/VtkVis/MeshFromRasterDialog.cpp @@ -13,7 +13,7 @@ MeshFromRasterDialog::MeshFromRasterDialog(QDialog* parent) this->elevationButton->setChecked(true); this->triButton->setChecked(true); - this->mshNameEdit->setText("NewMesh"); + this->mshNameEdit->setText("RasterDataMesh"); } diff --git a/Gui/VtkVis/VtkMeshConverter.cpp b/Gui/VtkVis/VtkMeshConverter.cpp index 32a961e62f9800a08d6e52b6896c9502dd98173b..d8575757060cb261e66ed813280da294ae0bf8a4 100644 --- a/Gui/VtkVis/VtkMeshConverter.cpp +++ b/Gui/VtkVis/VtkMeshConverter.cpp @@ -221,7 +221,7 @@ MeshLib::Mesh* VtkMeshConverter::constructMesh(const double* pixVal, } } - return new MeshLib::Mesh("vtkImageData-Mesh", nodes, elements); + return new MeshLib::Mesh("RasterDataMesh", nodes, elements); // the name is only a temp-name, the name given in the dialog is set later } MeshLib::Mesh* VtkMeshConverter::convertUnstructuredGrid(vtkUnstructuredGrid* grid) @@ -261,12 +261,19 @@ MeshLib::Mesh* VtkMeshConverter::convertUnstructuredGrid(vtkUnstructuredGrid* gr case VTK_QUAD: elem = new MeshLib::Quad(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], material); break; + case VTK_PIXEL: + elem = new MeshLib::Quad(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[3]], nodes[node_ids[2]], material); + break; case VTK_TETRA: - elem = new MeshLib::Quad(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], material); + elem = new MeshLib::Tet(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], material); break; case VTK_HEXAHEDRON: elem = new MeshLib::Hex(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], nodes[node_ids[3]], - nodes[node_ids[4]], nodes[node_ids[5]], nodes[node_ids[6]], nodes[node_ids[7]], material); + nodes[node_ids[4]], nodes[node_ids[5]], nodes[node_ids[6]], nodes[node_ids[7]], material); + break; + case VTK_VOXEL: + elem = new MeshLib::Hex(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[3]], nodes[node_ids[2]], + nodes[node_ids[4]], nodes[node_ids[5]], nodes[node_ids[7]], nodes[node_ids[6]], material); break; case VTK_PYRAMID: elem = new MeshLib::Pyramid(nodes[node_ids[0]], nodes[node_ids[1]], nodes[node_ids[2]], diff --git a/Gui/VtkVis/VtkMeshSource.cpp b/Gui/VtkVis/VtkMeshSource.cpp index 07a25601e3f410b7c7a70d1f13c2009c0a195f81..178d19492942e60001f807a4a270b38d794120da 100644 --- a/Gui/VtkVis/VtkMeshSource.cpp +++ b/Gui/VtkVis/VtkMeshSource.cpp @@ -49,7 +49,6 @@ VtkMeshSource::VtkMeshSource() : _matName("MaterialIDs") VtkMeshSource::~VtkMeshSource() { - delete _grid; } void VtkMeshSource::PrintSelf( ostream& os, vtkIndent indent ) @@ -134,7 +133,7 @@ int VtkMeshSource::RequestData( vtkInformation* request, type = 5; break; case MshElemType::QUAD: - type = 8; + type = 9; break; case MshElemType::HEXAHEDRON: type = 12; @@ -158,7 +157,7 @@ int VtkMeshSource::RequestData( vtkInformation* request, const size_t nElemNodes (elem->getNNodes()); for (size_t j = 0; j < nElemNodes; j++) - point_ids->InsertNextId(elem->getNode(nElemNodes-1-j)->getID()); + point_ids->InsertNextId(elem->getNode(j)->getID()); output->InsertNextCell(type, point_ids); } diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 4eea8b4add41adb10d1cc713e61d81f0e73af429..716c45f701324a509c7beb2a0a33c6ef5685fd80 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -56,7 +56,6 @@ #include "Legacy/OGSIOVer4.h" #include "MeshIO/GMSHInterface.h" // TODO6 #include "MeshIO/TetGenInterface.h" -#include "NetCDFInterface.h" #include "PetrelInterface.h" // TODO6 #include "StationIO.h" #include "XmlIO/XmlCndInterface.h" @@ -78,6 +77,7 @@ #include <QMessageBox> #include <QObject> #include <QSettings> +#include <QSignalMapper> // VTK includes #include <vtkOBJExporter.h> @@ -234,14 +234,14 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) SIGNAL(actorPicked(vtkProp3D*)), vtkVisTabWidget->vtkVisPipelineView, SLOT(selectItem(vtkProp3D*))); connect((QObject*) (visualizationWidget->interactorStyle()), - SIGNAL(elementPicked(const GridAdapter *, const size_t)), - this->_elementModel, SLOT(setElement(const GridAdapter *, const size_t))); + SIGNAL(elementPicked(const MeshLib::Mesh *, const size_t)), + this->_elementModel, SLOT(setElement(const MeshLib::Mesh *, const size_t))); connect((QObject*) (visualizationWidget->interactorStyle()), - SIGNAL(elementPicked(const GridAdapter *, const size_t)), + SIGNAL(elementPicked(const MeshLib::Mesh *, const size_t)), mshTabWidget->elementView, SLOT(updateView())); connect(vtkVisTabWidget->vtkVisPipelineView, SIGNAL(meshAdded(MeshLib::Mesh*)), - _meshModels, SLOT(addMesh(GridAdapter*))); + _meshModels, SLOT(addMesh(MeshLib::Mesh*))); // Stack the data dock widgets together tabifyDockWidget(geoDock, mshDock); @@ -322,35 +322,6 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) SLOT(showPropertiesDialog(std::string))); _visPrefsDialog = new VisPrefsDialog(_vtkVisPipeline, visualizationWidget); - - // std::cout << "size of Point: " << sizeof (GeoLib::Point) << std::endl; - // std::cout << "size of CGLPoint: " << sizeof (CGLPoint) << std::endl; - // - // std::cout << "size of Polyline: " << sizeof (GeoLib::Polyline) << std::endl; - // std::cout << "size of CGLPolyline: " << sizeof (CGLPolyline) << std::endl; - // - // std::cout << "size of GeoLib::Surface: " << sizeof (GeoLib::Surface) << std::endl; - // std::cout << "size of Surface: " << sizeof (Surface) << std::endl; - // - // std::cout << "size of CCore: " << sizeof (MeshLib::CCore) << std::endl; - // std::cout << "size of CNode: " << sizeof (MeshLib::CNode) << std::endl; - // std::cout << "size of CElement: " << sizeof (MeshLib::CNode) << std::endl; - // std::cout << "size of CEdge: " << sizeof (MeshLib::CEdge) << std::endl; - // std::cout << "size of CFEMesh: " << sizeof (MeshLib::CFEMesh) << std::endl; - // std::cout << "size of Matrix: " << sizeof (Math_Group::Matrix) << std::endl; - // - // std::cout << "size of vec<size_t>: " << sizeof (Math_Group::vec<size_t>) << std::endl; - // std::cout << "size of std::vector: " << sizeof (std::vector<size_t>) << std::endl; - - // std::cout << "size of CSourceTerm: " << sizeof (CSourceTerm) << std::endl; - // std::cout << "size of CBoundaryCondition: " << sizeof (CBoundaryCondition) << std::endl; - - // std::cout << "size of CElement: " << sizeof (FiniteElement::CElement) << std::endl; -// std::cout << "size of CMediumProperties: " << sizeof(CMediumProperties) << std::endl; -// std::cout << "size of CSolidProperties: " << sizeof(SolidProp::CSolidProperties) << std::endl; -// std::cout << "size of CFluidProperties: " << sizeof(CFluidProperties) << std::endl; - // std::cout << "size of CRFProcess: " << sizeof (CRFProcess) << std::endl; - // std::cout << "size of CFEMesh: " << sizeof (MeshLib::CFEMesh) << std::endl; } MainWindow::~MainWindow() @@ -359,8 +330,6 @@ MainWindow::~MainWindow() delete _vtkVisPipeline; delete _meshModels; delete _processModel; - //delete _visPrefsDialog; - //delete _geoModels; #ifdef OGS_USE_VRPN delete _trackingSettingsWidget; @@ -510,20 +479,6 @@ void MainWindow::loadFile(const QString &fileName) #ifndef NDEBUG std::cout << myTimer0.elapsed() << " ms" << std::endl; #endif - // - //#ifndef NDEBUG - // QTime myTimer; - // myTimer.start(); - // std::cout << "GeoLib_Read_GeoLib ... " << std::flush; - //#endif - // GeoLib_Read_GeoLib(base); //fileName.toStdString()); - // cout << "Nr. Points: " << gli_points_vector.size() << endl; - // cout << "Nr. Lines: " << polyline_vector.size() << endl; - // cout << "Nr. Surfaces: " << surface_vector.size() << endl; - //#ifndef NDEBUG - // std::cout << myTimer.elapsed() << " ms" << std::endl; - //#endif - // GEOCalcPointMinMaxCoordinates(); } else if (fi.suffix().toLower() == "gsp") { @@ -581,8 +536,7 @@ void MainWindow::loadFile(const QString &fileName) // GMS borehole files else if (fi.suffix().toLower() == "txt") { - std::vector<GeoLib::Point*>* boreholes = - new std::vector<GeoLib::Point*>(); + std::vector<GeoLib::Point*>* boreholes = new std::vector<GeoLib::Point*>(); std::string name = fi.baseName().toStdString(); if (GMSInterface::readBoreholesFromGMS(boreholes, fileName.toStdString())) @@ -707,36 +661,57 @@ void MainWindow::about() QMenu* MainWindow::createImportFilesMenu() { + _signal_mapper = new QSignalMapper(this); QMenu* importFiles = new QMenu("&Import Files"); /* TODO6 QAction* feflowFiles = importFiles->addAction("&FEFLOW Files..."); connect(feflowFiles, SIGNAL(triggered()), this, SLOT(importFeflow())); */ QAction* gmsFiles = importFiles->addAction("G&MS Files..."); - connect(gmsFiles, SIGNAL(triggered()), this, SLOT(importGMS())); + connect(gmsFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map())); + _signal_mapper->setMapping(gmsFiles, ImportFileType::GMS); + + QAction* gmshFiles = importFiles->addAction("&GMSH Files..."); + connect(gmshFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map())); + _signal_mapper->setMapping(gmshFiles, ImportFileType::GMSH); + QAction* netcdfFiles = importFiles->addAction("&NetCDF Files..."); - connect(netcdfFiles, SIGNAL(triggered()), this, SLOT(importNetcdf())); + connect(netcdfFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map())); + _signal_mapper->setMapping(netcdfFiles, ImportFileType::NETCDF); + QAction* petrelFiles = importFiles->addAction("&Petrel Files..."); - connect(petrelFiles, SIGNAL(triggered()), this, SLOT(importPetrel())); + connect(petrelFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map())); + _signal_mapper->setMapping(petrelFiles, ImportFileType::PETREL); + QAction* rasterFiles = importFiles->addAction("&Raster Files..."); - connect(rasterFiles, SIGNAL(triggered()), this, SLOT(importRaster())); + connect(rasterFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map())); + _signal_mapper->setMapping(rasterFiles, ImportFileType::RASTER); + #ifdef OGS_USE_OPENSG QAction* rasterPolyFiles = importFiles->addAction("R&aster Files as PolyData..."); connect(rasterPolyFiles, SIGNAL(triggered()), this, SLOT(importRasterAsPoly())); #endif + #ifdef Shapelib_FOUND QAction* shapeFiles = importFiles->addAction("&Shape Files..."); - connect(shapeFiles, SIGNAL(triggered()), this, SLOT(importShape())); + connect(shapeFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map())); + _signal_mapper->setMapping(shapeFiles, ImportFileType::SHAPE); #endif + QAction* tetgenFiles = importFiles->addAction("&TetGen Files..."); - connect( tetgenFiles, SIGNAL(triggered()), this, SLOT(importTetGen()) ); - QAction* vtkFiles = importFiles->addAction("&VTK Files..."); - connect( vtkFiles, SIGNAL(triggered()), this, SLOT(importVtk()) ); + connect( tetgenFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map()) ); + _signal_mapper->setMapping(tetgenFiles, ImportFileType::TETGEN); + QAction* vtkFiles = importFiles->addAction("&VTK Files..."); + connect( vtkFiles, SIGNAL(triggered()), _signal_mapper, SLOT(map()) ); + _signal_mapper->setMapping(vtkFiles, ImportFileType::VTK); + + connect(_signal_mapper, SIGNAL(mapped(int)), this, SLOT(openFile(int))); + return importFiles; } -void MainWindow::importGMS() +void MainWindow::openFile(int file_type) { QSettings settings("UFZ", "OpenGeoSys-5"); QString fileName = QFileDialog::getOpenFileName(this, @@ -751,6 +726,21 @@ void MainWindow::importGMS() } } +void MainWindow::importGMS() +{ + QSettings settings("UFZ", "OpenGeoSys-5"); + QString fileName = QFileDialog::getOpenFileName(this, + "Select GMSH file to import", settings.value( + "lastOpenedFileDirectory").toString(), + "GMSH meshes (*.msh)"); + if (!fileName.isEmpty()) + { + loadFile(fileName); + QDir dir = QDir(fileName); + settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); + } +} + void MainWindow::importRaster() { QSettings settings("UFZ", "OpenGeoSys-5"); diff --git a/Gui/mainwindow.h b/Gui/mainwindow.h index 2950b458a5084c0a26316b1069eb150ed5b7ee4a..442bf7fbd9b9f4e71215eb1fb03aa6fda1442b4d 100644 --- a/Gui/mainwindow.h +++ b/Gui/mainwindow.h @@ -9,6 +9,7 @@ #include "FileFinder.h" #include "ProjectData.h" +#include "ImportFileTypes.h" #include "ui_mainwindow.h" class GEOModels; @@ -19,6 +20,8 @@ class ProcessModel; class VtkVisPipeline; class VisPrefsDialog; +class QSignalMapper; + #ifdef OGS_USE_VRPN class TrackingSettingsWidget; #endif // OGS_USE_VRPN @@ -74,6 +77,7 @@ protected slots: // TODO6 void importFeflow(); void importTetGen(); void loadFEMConditions(std::string geoName); + void openFile(int file_type); void openRecentFile(); void about(); void showAddPipelineFilterItemDialog(QModelIndex parentIndex); @@ -133,6 +137,7 @@ private: QWidget* _vtkWidget; QByteArray _windowState; QMenu* _import_files_menu; + QSignalMapper* _signal_mapper; #ifdef OGS_USE_VRPN TrackingSettingsWidget* _trackingSettingsWidget; @@ -141,6 +146,7 @@ private: signals: void fileUsed( QString filename ); + void fileOpenRequested( int ); }; class StartQt4 diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index a8bdfd13f287e9b818d53cf02a1ae04cef9c8580..87f1466ebe650ca9048458ec222c658f5175030c 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -25,6 +25,7 @@ namespace MeshLib { Mesh::Mesh(const std::string &name, const std::vector<Node*> &nodes, const std::vector<Element*> &elements) : _name(name), _nodes(nodes), _elements(elements) { + this->resetNodeIDs(); // reset node ids so they match the node position in the vector _edge_length[0] = 0; _edge_length[1] = 0; this->makeNodesUnique(); @@ -83,6 +84,13 @@ void Mesh::addElement(Element* elem) elem->_nodes[i]->addElement(elem); } +void Mesh::resetNodeIDs() +{ + const size_t nNodes (this->_nodes.size()); + for (unsigned i=0; i<nNodes; i++) + _nodes[i]->setID(i); +} + void Mesh::setElementInformationForNodes() { const size_t nElements (_elements.size()); diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index a019665db98fe0142b891f73f7a8c6523cf0b53e..255ff38411e4784bc0cbbdff8ad3d42aca73b6c0 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -77,6 +77,9 @@ public: /// Get the element-vector for the mesh. const std::vector<Element*> getElements() const { return _elements; }; + /// Resets the IDs of all mesh-nodes to their position in the node vector + void resetNodeIDs(); + /** * Set the minimum and maximum length over the edges of the mesh. * This should have been previously calcumlated using the Element::computeSqrEdgeLengthRange(min, max) diff --git a/MeshLib/Node.h b/MeshLib/Node.h index 07362e911ba23fc7b3f19defe81b977ad32222c9..703afbb8d2c3ed2cc8ef9b9fb3e7ce712c3444f2 100644 --- a/MeshLib/Node.h +++ b/MeshLib/Node.h @@ -63,6 +63,9 @@ protected: */ void addElement(Element* elem) { _elements.push_back(elem); }; + /// Sets the ID of a node to the given value. + void setID(unsigned id) { this->_id = id; }; + std::vector<Element*> _elements; }; /* class */