From c785b17ca7fb10b702db4238914557e8a1bf0c01 Mon Sep 17 00:00:00 2001 From: Lars Bilke <lars.bilke@ufz.de> Date: Wed, 15 Aug 2012 14:19:09 +0200 Subject: [PATCH] Work in progress: removing GridAdapter. --- Gui/DataView/CondFromRasterDialog.cpp | 13 +- Gui/DataView/CondFromRasterDialog.h | 11 +- Gui/DataView/DataView.cpp | 26 +- Gui/DataView/DirectConditionGenerator.cpp | 9 +- Gui/DataView/DirectConditionGenerator.h | 10 +- Gui/DataView/ElementTreeModel.cpp | 8 +- Gui/DataView/ElementTreeModel.h | 7 +- Gui/DataView/MshEditDialog.cpp | 6 +- Gui/DataView/MshEditDialog.h | 8 +- Gui/DataView/MshItem.h | 7 +- Gui/DataView/MshModel.h | 13 +- Gui/VtkAct/VtkCustomInteractorStyle.h | 7 +- Gui/VtkVis/VtkMeshSource.cpp | 7 +- Gui/VtkVis/VtkMeshSource.h | 11 +- MeshLib/GridAdapter.cpp | 311 ---------------------- MeshLib/GridAdapter.h | 99 ------- MeshLib/MshEditor.cpp | 177 ++++++++++++ MeshLib/MshEditor.h | 42 +++ scripts/cmake/CompilerSetup.cmake | 2 +- 19 files changed, 306 insertions(+), 468 deletions(-) delete mode 100644 MeshLib/GridAdapter.cpp delete mode 100644 MeshLib/GridAdapter.h create mode 100644 MeshLib/MshEditor.cpp create mode 100644 MeshLib/MshEditor.h diff --git a/Gui/DataView/CondFromRasterDialog.cpp b/Gui/DataView/CondFromRasterDialog.cpp index babf1d87f42..cf2cf0c2cab 100644 --- a/Gui/DataView/CondFromRasterDialog.cpp +++ b/Gui/DataView/CondFromRasterDialog.cpp @@ -4,6 +4,7 @@ */ #include "CondFromRasterDialog.h" +#include "Mesh.h" #include <QFileDialog> #include <QSettings> @@ -12,7 +13,7 @@ #include "OGSError.h" #include "StrictDoubleValidator.h" -CondFromRasterDialog::CondFromRasterDialog(const std::map<std::string, MeshLib::CFEMesh*> &msh_map, QDialog* parent) +CondFromRasterDialog::CondFromRasterDialog(const std::map<std::string, MeshLib::Mesh*> &msh_map, QDialog* parent) : QDialog(parent), _msh_map(msh_map) { setupUi(this); @@ -22,8 +23,8 @@ CondFromRasterDialog::CondFromRasterDialog(const std::map<std::string, MeshLib:: this->scalingEdit->setText("1.0"); this->scalingEdit->setValidator (_scale_validator); - for (std::map<std::string, MeshLib::CFEMesh*>::const_iterator it = _msh_map.begin(); - it != _msh_map.end(); ++it) + for (std::map<std::string, MeshLib::Mesh*>::const_iterator it = _msh_map.begin(); + it != _msh_map.end(); ++it) this->meshBox->addItem(QString::fromStdString(it->first)); this->directButton->setChecked(true); @@ -73,8 +74,8 @@ void CondFromRasterDialog::accept() OGSError::box("No raster selected."); return; } - - const MeshLib::CFEMesh* mesh = (_msh_map.find(mesh_name))->second; + + const MeshLib::Mesh* mesh = (_msh_map.find(mesh_name))->second; //std::string direct_node_name(raster_name + ".txt"); if (this->directButton->isChecked()) @@ -90,7 +91,7 @@ void CondFromRasterDialog::accept() OGSError::box("No valid scaling factor given."); return; } - MeshLib::CFEMesh* new_mesh = const_cast<MeshLib::CFEMesh*>(mesh); + MeshLib::Mesh* new_mesh = const_cast<MeshLib::Mesh*>(mesh); DirectConditionGenerator dcg; direct_values = dcg.directWithSurfaceIntegration(*new_mesh, raster_name, scaling_factor); //dcg.writeToFile(direct_node_name); diff --git a/Gui/DataView/CondFromRasterDialog.h b/Gui/DataView/CondFromRasterDialog.h index 0537113915d..571670ed0cf 100644 --- a/Gui/DataView/CondFromRasterDialog.h +++ b/Gui/DataView/CondFromRasterDialog.h @@ -10,7 +10,10 @@ #include <QDialog> #include "ProjectData.h" -#include "GridAdapter.h" + +namespace { + class Mesh; +} class StrictDoubleValidator; @@ -22,11 +25,11 @@ class CondFromRasterDialog : public QDialog, private Ui_CondFromRaster Q_OBJECT public: - CondFromRasterDialog(const std::map<std::string, MeshLib::CFEMesh*> &msh_map, QDialog* parent = 0); + CondFromRasterDialog(const std::map<std::string, MeshLib::Mesh*> &msh_map, QDialog* parent = 0); ~CondFromRasterDialog(void); private: - const std::map<std::string, MeshLib::CFEMesh*> _msh_map; + const std::map<std::string, MeshLib::Mesh*> _msh_map; StrictDoubleValidator* _scale_validator; private slots: @@ -38,7 +41,7 @@ private slots: /// Instructions if the Cancel-Button has been pressed. void reject(); - + signals: void directNodesWritten(std::string); void transmitDisValues(std::vector< std::pair<size_t,double> >); diff --git a/Gui/DataView/DataView.cpp b/Gui/DataView/DataView.cpp index d6352b9bc65..8be904389fb 100644 --- a/Gui/DataView/DataView.cpp +++ b/Gui/DataView/DataView.cpp @@ -6,7 +6,7 @@ */ #include "DataView.h" -#include "GridAdapter.h" +#include "Mesh.h" #include "MshEditDialog.h" #include "MshItem.h" #include "MshModel.h" @@ -21,7 +21,7 @@ #include <QObject> #include <QSettings> -#include "MeshIO/OGSMeshIO.h" +#include "MeshIO.h" #include "Writer.h" // necessary to avoid Linker Error in Windows DataView::DataView( QWidget* parent /*= 0*/ ) @@ -50,8 +50,8 @@ void DataView::addMeshAction() if (!fileName.isEmpty()) { std::string name = fileName.toStdString(); - FileIO::OGSMeshIO meshIO; - MeshLib::CFEMesh* msh = meshIO.loadMeshFromFile(name); + FileIO::MeshIO meshIO; + MeshLib::Mesh* msh = meshIO.loadMeshFromFile(name); if (msh) static_cast<MshModel*>(this->model())->addMesh(msh, name); } @@ -102,8 +102,8 @@ void DataView::openMshEditDialog() { MshModel* model = static_cast<MshModel*>(this->model()); QModelIndex index = this->selectionModel()->currentIndex(); - const MeshLib::CFEMesh* mesh = - static_cast<MshModel*>(this->model())->getMesh(index)->getCFEMesh(); + const MeshLib::Mesh* mesh = + static_cast<MshModel*>(this->model())->getMesh(index); MshEditDialog meshEdit(mesh); connect(&meshEdit, SIGNAL(mshEditFinished(MeshLib::CFEMesh*, std::string &)), @@ -114,8 +114,8 @@ void DataView::openMshEditDialog() int DataView::writeMeshToFile() const { QModelIndex index = this->selectionModel()->currentIndex(); - const MeshLib::CFEMesh* mesh = - static_cast<MshModel*>(this->model())->getMesh(index)->getCFEMesh(); + const MeshLib::Mesh* mesh = + static_cast<MshModel*>(this->model())->getMesh(index); if (mesh) { @@ -128,7 +128,7 @@ int DataView::writeMeshToFile() const if (!fileName.isEmpty()) { - FileIO::OGSMeshIO meshIO; + FileIO::MeshIO meshIO; meshIO.setMesh(mesh); meshIO.writeToFile(fileName.toStdString().c_str()); QDir dir = QDir(fileName); @@ -144,7 +144,7 @@ int DataView::writeMeshToFile() const void DataView::addDIRECTSourceTerms() { QModelIndex index = this->selectionModel()->currentIndex(); - const GridAdapter* grid = static_cast<MshModel*>(this->model())->getMesh(index); + const MeshLib::Mesh* grid = static_cast<MshModel*>(this->model())->getMesh(index); emit requestCondSetupDialog(grid->getName(), GeoLib::INVALID, 0, false); } @@ -152,9 +152,9 @@ void DataView::addDIRECTSourceTerms() void DataView::loadDIRECTSourceTerms() { QModelIndex index = this->selectionModel()->currentIndex(); - const GridAdapter* grid = static_cast<MshModel*>(this->model())->getMesh(index); - const std::vector<GeoLib::Point*>* points = grid->getNodes(); - emit requestDIRECTSourceTerms(grid->getName(), points); + const MeshLib::Mesh* grid = static_cast<MshModel*>(this->model())->getMesh(index); + // TODO6 const std::vector<MeshLib::Node*>* nodes = grid->getNodes(); + // TODO6 emit requestDIRECTSourceTerms(grid->getName(), nodes); } void DataView::checkMeshQuality () diff --git a/Gui/DataView/DirectConditionGenerator.cpp b/Gui/DataView/DirectConditionGenerator.cpp index 6e92cfd98c2..d52e906d0ff 100644 --- a/Gui/DataView/DirectConditionGenerator.cpp +++ b/Gui/DataView/DirectConditionGenerator.cpp @@ -9,10 +9,11 @@ #include "VtkRaster.h" #include "MshEditor.h" #include "PointWithID.h" +#include "Mesh.h" -#include "fem_ele.h" +#include <cmath> -const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directToSurfaceNodes(const MeshLib::CFEMesh &mesh, const std::string &filename) +const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directToSurfaceNodes(const MeshLib::Mesh &mesh, const std::string &filename) { if (_direct_values.empty()) { @@ -32,7 +33,7 @@ const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directT _direct_values.reserve(nNodes); for (size_t i=0; i<nNodes; i++) { - const double* coords (surface_nodes[i]->getData()); + const double* coords (surface_nodes[i]->getCoords()); if (coords[0]>=origin_x && coords[0]<(origin_x+(delta*imgwidth)) && coords[1]>=origin_y && coords[1]<(origin_y+(delta*imgheight))) { @@ -59,7 +60,7 @@ const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directT } -const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directWithSurfaceIntegration(MeshLib::CFEMesh &mesh, const std::string &filename, double scaling) +const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directWithSurfaceIntegration(MeshLib::Mesh &mesh, const std::string &filename, double scaling) { double no_data_value (-9999); // TODO: get this from asc-reader! diff --git a/Gui/DataView/DirectConditionGenerator.h b/Gui/DataView/DirectConditionGenerator.h index e1839d73b32..c347af18440 100644 --- a/Gui/DataView/DirectConditionGenerator.h +++ b/Gui/DataView/DirectConditionGenerator.h @@ -7,7 +7,11 @@ #ifndef DIRECTCONDITIONGENERATOR_H #define DIRECTCONDITIONGENERATOR_H -#include "msh_mesh.h" +#include <vector> + +namespace MeshLib { + class Mesh; +} class DirectConditionGenerator { @@ -15,9 +19,9 @@ public: DirectConditionGenerator() {}; ~DirectConditionGenerator() {}; - const std::vector< std::pair<size_t,double> >& directToSurfaceNodes(const MeshLib::CFEMesh &mesh, const std::string &filename); + const std::vector< std::pair<size_t,double> >& directToSurfaceNodes(const MeshLib::Mesh &mesh, const std::string &filename); - const std::vector< std::pair<size_t,double> >& directWithSurfaceIntegration(MeshLib::CFEMesh &mesh, const std::string &filename, double scaling); + const std::vector< std::pair<size_t,double> >& directWithSurfaceIntegration(MeshLib::Mesh &mesh, const std::string &filename, double scaling); int writeToFile(const std::string &name) const; diff --git a/Gui/DataView/ElementTreeModel.cpp b/Gui/DataView/ElementTreeModel.cpp index 13fd9fe8572..deb225910ab 100644 --- a/Gui/DataView/ElementTreeModel.cpp +++ b/Gui/DataView/ElementTreeModel.cpp @@ -6,6 +6,8 @@ #include "ElementTreeModel.h" #include "OGSError.h" #include "TreeItem.h" +#include "Mesh.h" +#include "Elements/Element.h" /** * Constructor. @@ -23,10 +25,10 @@ ElementTreeModel::~ElementTreeModel() { } -void ElementTreeModel::setElement(const GridAdapter* grid, const size_t elem_index) +void ElementTreeModel::setElement(const MeshLib::Mesh* grid, const size_t elem_index) { this->clearView(); - GridAdapter::Element* elem = (*(grid->getElements()))[elem_index]; + const MeshLib::Element* elem = grid->getElement(elem_index); QList<QVariant> elemData; elemData << "Element " + QString::number(elem_index) << "" << "" << ""; @@ -34,7 +36,7 @@ void ElementTreeModel::setElement(const GridAdapter* grid, const size_t elem_ind _rootItem->appendChild(elemItem); QList<QVariant> typeData; - typeData << "Element Type: " << QString::fromStdString(MshElemType2String(elem->type)); + typeData << "Element Type: " << QString::fromStdString(MshElemType2String(elem->getType())); TreeItem* typeItem = new TreeItem(typeData, elemItem); elemItem->appendChild(typeItem); diff --git a/Gui/DataView/ElementTreeModel.h b/Gui/DataView/ElementTreeModel.h index 5c75e467fbd..09a081d7e7f 100644 --- a/Gui/DataView/ElementTreeModel.h +++ b/Gui/DataView/ElementTreeModel.h @@ -6,9 +6,12 @@ #ifndef ELEMENTTREEMODEL_H #define ELEMENTTREEMODEL_H -#include "GridAdapter.h" #include "TreeModel.h" +namespace MeshLib { + class Mesh; +} + /** * \brief A model for the display of information concerning element information implemented as a TreeModel. * \sa TreeModel, ElementTreeView, TreeItem @@ -26,7 +29,7 @@ public slots: void clearView(); /// Extracts information of the element with the given index from the given grid. - void setElement(const GridAdapter* grid, const size_t elem_index); + void setElement(const MeshLib::Mesh* grid, const size_t elem_index); private: }; diff --git a/Gui/DataView/MshEditDialog.cpp b/Gui/DataView/MshEditDialog.cpp index 1337841ef93..3bcb46d9ebb 100644 --- a/Gui/DataView/MshEditDialog.cpp +++ b/Gui/DataView/MshEditDialog.cpp @@ -6,14 +6,14 @@ #include "MshEditDialog.h" #include "OGSError.h" #include "StringTools.h" -#include "msh_mesh.h" +#include "Mesh.h" #include <QCheckBox> #include <QFileDialog> #include <QPushButton> #include <QSettings> -MshEditDialog::MshEditDialog(const MeshLib::CFEMesh* mesh, QDialog* parent) +MshEditDialog::MshEditDialog(const MeshLib::Mesh* mesh, QDialog* parent) : QDialog(parent), _msh(mesh), _noDataDeleteBox(NULL) { setupUi(this); @@ -110,7 +110,7 @@ void MshEditDialog::accept() } } } - if (nLayers>0 && this->_edits[0]->text().length()>0) + if (nLayers>0 && this->_edits[0]->text().length()>0) { MeshLib::CFEMesh* final_mesh = MshLayerMapper::blendLayersWithSurface(new_mesh, nLayers, this->_edits[0]->text().toStdString()); delete new_mesh; diff --git a/Gui/DataView/MshEditDialog.h b/Gui/DataView/MshEditDialog.h index 214c04dabdf..0dce75a4e72 100644 --- a/Gui/DataView/MshEditDialog.h +++ b/Gui/DataView/MshEditDialog.h @@ -16,7 +16,7 @@ class QCheckBox; namespace MeshLib { -class CFEMesh; +class Mesh; } /** @@ -27,11 +27,11 @@ class MshEditDialog : public QDialog, private Ui_MshEdit Q_OBJECT public: - MshEditDialog(const MeshLib::CFEMesh* mesh, QDialog* parent = 0); + MshEditDialog(const MeshLib::Mesh* mesh, QDialog* parent = 0); ~MshEditDialog(void); private: - const MeshLib::CFEMesh* _msh; + const MeshLib::Mesh* _msh; QVector<QLabel*> _labels; QMap<QPushButton*, QLineEdit*> _fileButtonMap; QVector<QLineEdit*> _edits; @@ -48,7 +48,7 @@ private slots: void reject(); signals: - void mshEditFinished(MeshLib::CFEMesh*, std::string&); + void mshEditFinished(MeshLib::Mesh*, std::string&); }; #endif //MSHEDITDIALOG_H diff --git a/Gui/DataView/MshItem.h b/Gui/DataView/MshItem.h index 548ee347b47..0d98b5b792d 100644 --- a/Gui/DataView/MshItem.h +++ b/Gui/DataView/MshItem.h @@ -9,9 +9,12 @@ #include "TreeItem.h" #include "VtkMeshSource.h" -class GridAdapter; class VtkMeshSource; +namespace MeshLib { + class Mesh; +} + /** * \brief A TreeItem containing a mesh and the associated vtk object used in the Mesh Model. * \sa TreeItem @@ -24,7 +27,7 @@ public: ~MshItem(); /// Returns the mesh as a GridAdapter. - const GridAdapter* getGrid() const { return this->_meshSource->GetGrid(); } + const MeshLib::Mesh* getGrid() const { return this->_meshSource->GetGrid(); } /// Returns the VTK object. VtkMeshSource* vtkSource() const { return _meshSource; } diff --git a/Gui/DataView/MshModel.h b/Gui/DataView/MshModel.h index c64edaa90c4..d61a15cfc8e 100644 --- a/Gui/DataView/MshModel.h +++ b/Gui/DataView/MshModel.h @@ -9,10 +9,13 @@ #define MSHMODEL_H // ** INCLUDES ** -#include "GridAdapter.h" #include "ProjectData.h" #include "TreeModel.h" +namespace MeshLib { + class Mesh; +} + class VtkMeshSource; /** @@ -32,11 +35,11 @@ public slots: /// Adds a new mesh void addMesh(GridAdapter* mesh); /// Adds a new mesh - void addMesh(MeshLib::CFEMesh* mesh, std::string &name); // needs only to be a slot for MshLayerMapper. Otherwise normal function would be okay. + void addMesh(MeshLib::Mesh* mesh, std::string &name); // needs only to be a slot for MshLayerMapper. Otherwise normal function would be okay. /// Returns the mesh with the given index. - const GridAdapter* getMesh(const QModelIndex &idx) const; + const MeshLib::Mesh* getMesh(const QModelIndex &idx) const; /// Returns the mesh with the given name. - const GridAdapter* getMesh(const std::string &name) const; + const MeshLib::Mesh* getMesh(const std::string &name) const; /// Removes the mesh with the given index. bool removeMesh(const QModelIndex &idx); /// Removes the mesh with the given name. @@ -50,7 +53,7 @@ public slots: private: /// Adds the mesh to the GUI-Mesh-Model und -View - void addMeshObject(GridAdapter* mesh); + void addMeshObject(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/VtkAct/VtkCustomInteractorStyle.h b/Gui/VtkAct/VtkCustomInteractorStyle.h index b4fa3d033d7..aebe33f8749 100644 --- a/Gui/VtkAct/VtkCustomInteractorStyle.h +++ b/Gui/VtkAct/VtkCustomInteractorStyle.h @@ -15,7 +15,10 @@ class vtkDataObject; class vtkDataSetMapper; class vtkActor; -class GridAdapter; + +namespace MeshLib { + class Mesh; +} /** * VtkCustomInteractorStyle implements highlighting of an active actor and @@ -80,7 +83,7 @@ signals: void cursorChanged(Qt::CursorShape); /// @brief Emitted when a mesh element has been picked - void elementPicked(const GridAdapter*, const size_t); + void elementPicked(const MeshLib::Mesh*, const size_t); }; #endif // VTKINTERACTORSTYLE_H diff --git a/Gui/VtkVis/VtkMeshSource.cpp b/Gui/VtkVis/VtkMeshSource.cpp index aaa710298cc..c6574d4a0fe 100644 --- a/Gui/VtkVis/VtkMeshSource.cpp +++ b/Gui/VtkVis/VtkMeshSource.cpp @@ -6,6 +6,9 @@ #include "VtkColorLookupTable.h" #include "VtkMeshSource.h" +#include "Mesh.h" +#include "Node.h" +#include "Element.h" // ** VTK INCLUDES ** #include "vtkObjectFactory.h" @@ -53,8 +56,8 @@ void VtkMeshSource::PrintSelf( ostream& os, vtkIndent indent ) if (_grid == NULL) return; - const std::vector<GeoLib::Point*>* nodes = _grid->getNodes(); - const std::vector<GridAdapter::Element*>* elems = _grid->getElements(); + const std::vector<GeoLib::Node*>* nodes = _grid->getNodes(); + const std::vector<MeshLib::Element*>* elems = _grid->getElements(); if (nodes->empty() || elems->empty() ) return; diff --git a/Gui/VtkVis/VtkMeshSource.h b/Gui/VtkVis/VtkMeshSource.h index c85e1ccc31a..e45a9332166 100644 --- a/Gui/VtkVis/VtkMeshSource.h +++ b/Gui/VtkVis/VtkMeshSource.h @@ -10,12 +10,15 @@ // ** INCLUDES ** #include <map> -#include "GridAdapter.h" #include "VtkAlgorithmProperties.h" #include <vtkUnstructuredGridAlgorithm.h> class VtkColorLookupTable; +namespace MeshLib { + class Mesh; +} + /** * \brief VTK source object for the visualisation of unstructured grids */ @@ -30,10 +33,10 @@ public: const char* GetMaterialArrayName() const { return _matName; } /// Returns the base object of this grid - const GridAdapter* GetGrid() { return this->_grid; } + const MeshLib::Mesh* GetGrid() { return this->_grid; } /// Sets the grid object that should be visualized - void SetGrid(const GridAdapter* grid) { _grid = grid; } + void SetGrid(const MeshLib::Mesh* grid) { _grid = grid; } /// Prints the mesh data to an output stream. void PrintSelf(ostream& os, vtkIndent indent); @@ -56,7 +59,7 @@ protected: vtkInformationVector** inputVector, vtkInformationVector* outputVector); - const GridAdapter* _grid; + const MeshLib::Mesh* _grid; private: const char* _matName; diff --git a/MeshLib/GridAdapter.cpp b/MeshLib/GridAdapter.cpp deleted file mode 100644 index 40a085e2b9d..00000000000 --- a/MeshLib/GridAdapter.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/** - * \file GridAdapter.cpp - * 24/03/2010 KR Initial implementation - * - */ - -#include "GridAdapter.h" - -#include "StringTools.h" -#include <cstdlib> -#include <iostream> -#include <list> - -GridAdapter::GridAdapter(const MeshLib::CFEMesh* mesh) : - _name(""), _nodes(new std::vector<GEOLIB::Point*>), _elems(new std::vector<Element*>), - _mesh(mesh) -{ - if (mesh) - this->convertCFEMesh(mesh); -} - -GridAdapter::GridAdapter(const std::string &filename) : - _name(""), _nodes(new std::vector<GEOLIB::Point*>), _elems(new std::vector<Element*>), - _mesh(NULL) -{ - readMeshFromFile(filename); -} - -GridAdapter::GridAdapter(const GridAdapter* grid) : - _name(""), _nodes(new std::vector<GEOLIB::Point*>), _elems(new std::vector<Element*>), - _mesh(NULL) -{ - if (grid) - { - this->_name = grid->getName(); - - const std::vector<GEOLIB::Point*> *nodes = grid->getNodes(); - const size_t nNodes(nodes->size()); - for (size_t i=0; i<nNodes; i++) - { - GEOLIB::Point* pnt (new GEOLIB::Point((*nodes)[i]->getData())); - this->addNode(pnt); - } - - const std::vector<GridAdapter::Element*> *elements = grid->getElements(); - const size_t nElems(elements->size()); - for (size_t i=0; i<nElems; i++) - { - GridAdapter::Element* elem = new GridAdapter::Element; - elem->material = (*elements)[i]->material; - const size_t nElemNodes ((*elements)[i]->nodes.size()); - for (size_t j=0; j<nElemNodes; j++) - elem->nodes.push_back((*elements)[i]->nodes[j]); - elem->type = (*elements)[i]->type; - this->addElement(elem); - } - } -} - -GridAdapter::~GridAdapter() -{ - size_t nNodes = _nodes->size(); - size_t nElems = _elems->size(); - - for (size_t i = 0; i < nNodes; i++) - delete (*_nodes)[i]; - for (size_t i = 0; i < nElems; i++) - delete (*_elems)[i]; - - delete this->_nodes; - delete this->_elems; -} - -int GridAdapter::convertCFEMesh(const MeshLib::CFEMesh* mesh) -{ - if (!mesh) - return 0; - - size_t nNodes = mesh->nod_vector.size(); - for (size_t i = 0; i < nNodes; i++) - _nodes->push_back(new GEOLIB::Point(mesh->nod_vector[i]->getData())); - - size_t nElems = mesh->ele_vector.size(); - size_t nElemNodes = 0; - - for (size_t i = 0; i < nElems; i++) - { - Element* newElem = new Element(); - newElem->type = mesh->ele_vector[i]->GetElementType(); - newElem->material = mesh->ele_vector[i]->GetPatchIndex(); - - if (newElem->type != MshElemType::INVALID) - { - std::vector<long> elemNodes; - nElemNodes = mesh->ele_vector[i]->getNodeIndices().Size(); - for (size_t j = 0; j < nElemNodes; j++) - newElem->nodes.push_back(mesh->ele_vector[i]->GetNodeIndex(j)); - - _elems->push_back(newElem); - } - else - std::cout << "GridAdapter::convertCFEMesh() - Error recognising element type..." << std::endl; - } - - return 1; -} - -const MeshLib::CFEMesh* GridAdapter::getCFEMesh() const -{ - if (_mesh) - return _mesh; - return toCFEMesh(); -} - -const MeshLib::CFEMesh* GridAdapter::toCFEMesh() const -{ - MeshLib::CFEMesh* mesh (new MeshLib::CFEMesh()); - std::cout << "Converting mesh object ... "; - - // set mesh nodes - size_t nNodes = _nodes->size(); - for (size_t i = 0; i < nNodes; i++) - mesh->nod_vector.push_back(new MeshLib::CNode(i, (*(*_nodes)[i])[0], (*(*_nodes)[i])[1], (*(*_nodes)[i])[2])); - - // set mesh elements - size_t nElems = _elems->size(); - for (size_t i = 0; i < nElems; i++) - { - MeshLib::CElem* elem(new MeshLib::CElem()); - elem->setElementProperties((*_elems)[i]->type); - elem->SetPatchIndex((*_elems)[i]->material); - - size_t nElemNodes = ((*_elems)[i]->nodes).size(); - for (size_t j = 0; j < nElemNodes; j++) - elem->SetNodeIndex(j, (*_elems)[i]->nodes[j]); - - mesh->ele_vector.push_back(elem); - } - - mesh->ConstructGrid(); - std::cout << "done." << std::endl; - - return mesh; -} - -int GridAdapter::readMeshFromFile(const std::string &filename) -{ - std::string line; - std::list<std::string>::const_iterator it; - - std::ifstream in( filename.c_str() ); - - if (!in.is_open()) - { - std::cout << "GridAdapter::readMeshFromFile() - Could not open file..." << - std::endl; - return 0; - } - - // try to find the start of the nodes list - while ( getline(in, line) ) - { - trim(line); - if (line.compare("$NODES") == 0) - break; - } - - // read number of nodes - getline(in, line); - trim(line); - - // read all nodes - while ( getline(in, line) ) - { - trim(line); - if (line.compare("$ELEMENTS") == 0) - break; - - std::list<std::string> fields = splitString(line, ' '); - - if (fields.size() >= 4) - { - it = fields.begin(); - - if (atoi(it->c_str()) == (int)_nodes->size()) - { - GEOLIB::Point* pnt = new GEOLIB::Point(); - - (*pnt)[0] = strtod((++it)->c_str(), 0); - (*pnt)[1] = strtod((++it)->c_str(), 0); - (*pnt)[2] = strtod((++it)->c_str(), 0); - - _nodes->push_back(pnt); - } - else - std::cout << - "GridAdapter::readMeshFromFile() - Index error while reading nodes..." - << std::endl; - } - else - std::cout << - "GridAdapter::readMeshFromFile() - Error reading node format..." << - std::endl; - } - - if (line.compare("$ELEMENTS") == 0) - { - Element* newElem; - - // read number of elements - getline(in, line); - trim(line); - - // read all elements - while ( getline(in, line) ) - { - trim(line); - if (line.compare("$LAYER") == 0) - break; - - std::list<std::string> fields = splitString(line, ' '); - - if (fields.size() >= 5) - { - it = fields.begin(); - if (atoi(it->c_str()) == (int)_elems->size()) - { - newElem = new Element(); - - if ((++it)->empty()) - it++; - newElem->material = atoi(it->c_str()); // material group - if ((++it)->empty()) - it++; - newElem->type = getElementType(*it); // element type - - if (newElem->type != MshElemType::INVALID) - { - while ((++it) != fields.end()) - { - if (it->empty()) - continue; - newElem->nodes.push_back(atoi(it->c_str())); // next node id - } - - _elems->push_back(newElem); - } - else - std::cout << - "GridAdapter::readMeshFromFile() - Error recognising element type..." - << std::endl; - } - else - std::cout << - "GridAdapter::readMeshFromFile() - Index error while reading element " << *it << "... " - << std::endl; - } - else - std::cout << - "GridAdapter::readMeshFromFile() - Error reading element format..." - << std::endl; - } - } - else - std::cout << - "GridAdapter::readMeshFromFile() - Index error after reading nodes..." << std::endl; - - in.close(); - - return 1; -} - -MshElemType::type GridAdapter::getElementType(const std::string &t) const -{ - if (t.compare("tri") == 0) - return MshElemType::TRIANGLE; - if (t.compare("line") == 0) - return MshElemType::LINE; - if (t.compare("quad") == 0) - return MshElemType::QUAD; - if (t.compare("tet") == 0) - return MshElemType::TETRAHEDRON; - if (t.compare("hex") == 0) - return MshElemType::HEXAHEDRON; - if ((t.compare("pri") == 0) || (t.compare("pris") == 0)) - return MshElemType::PRISM; - else - return MshElemType::INVALID; -} - -size_t GridAdapter::getNumberOfMaterials() const -{ - size_t nElems = _elems->size(); - size_t maxMaterialID = 0; - - for (size_t i = 0; i < nElems; i++) - if ((*_elems)[i]->material > maxMaterialID) - maxMaterialID = (*_elems)[i]->material; - return maxMaterialID; -} - -const std::vector<GridAdapter::Element*>* GridAdapter::getElements(size_t matID) const -{ - std::vector<GridAdapter::Element*>* matElems = new std::vector<GridAdapter::Element*>; - size_t nElements = _elems->size(); - for (size_t i = 0; i < nElements; i++) - if ((*_elems)[i]->material == matID) - matElems->push_back((*_elems)[i]); - - return matElems; -} diff --git a/MeshLib/GridAdapter.h b/MeshLib/GridAdapter.h deleted file mode 100644 index 43cb4fac87a..00000000000 --- a/MeshLib/GridAdapter.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * \file GridAdapter.h - * 24/03/2010 KR Initial implementation - * - */ - -#ifndef GRIDADAPTER_H -#define GRIDADAPTER_H - -// ** INCLUDES ** -#include "msh_mesh.h" - -class vtkImageData; // For conversion from Image to QuadMesh -class vtkUnstructuredGrid; // For conversion vom vtk to ogs mesh - -namespace MeshLib -{ -class CFEMesh; -class CNode; -} - -/** - * \brief Adapter class to convert FEM Mesh to a representation more suited for visualisation purposes - */ -class GridAdapter -{ -public: - /// An element structure consisting of a number of nodes and a MshElemType - typedef struct - { - MshElemType::type type; - size_t material; - std::vector<size_t> nodes; - } Element; - - /// Constructor using a FEM-Mesh Object as source - GridAdapter(const MeshLib::CFEMesh* mesh); - - /// Constructor using a MSH-file as source - GridAdapter(const std::string &filename); - - /// Copy Constructor - GridAdapter(const GridAdapter* grid = NULL); - - ~GridAdapter(); - - /// Adds a node to the grid - void addNode(GEOLIB::Point* node) { _nodes->push_back(node); }; - - /// Adds an element to the grid - void addElement(Element* element) { _elems->push_back(element); }; - - /// Returns the total number of unique material IDs. - size_t getNumberOfMaterials() const; - - /// Returns the vector of nodes. - const std::vector<GEOLIB::Point*>* getNodes() const { return _nodes; } - - /// Returns the vector of elements. - const std::vector<Element*>* getElements() const { return _elems; } - - /// Return a vector of elements for one material group only. - const std::vector<Element*>* getElements(size_t matID) const; - - /// Returns the grid as a CFEMesh for use in OGS-FEM - const MeshLib::CFEMesh* getCFEMesh() const; - - /// Returns the name of the mesh. - std::string getName() const { return _name; } - - /// Sets the element vector of the grid - void setElements(std::vector<Element*> *elements) { _elems=elements; }; - - /// Sets the name for the mesh. - void setName(const std::string &name) { _name = name; } - - /// Sets the node vector of the grid - void setNodeVector(std::vector<GEOLIB::Point*> *nodes) { _nodes=nodes; }; - -private: - /// Converts an FEM Mesh to a list of nodes and elements. - int convertCFEMesh(const MeshLib::CFEMesh* mesh); - - /// Reads a MSH file into a list of nodes and elements. - int readMeshFromFile(const std::string &filename); - - /// Converts a string to a MshElemType - MshElemType::type getElementType(const std::string &t) const; - - /// Converts a GridAdapter into an CFEMesh. - const MeshLib::CFEMesh* toCFEMesh() const; - - std::string _name; - std::vector<GEOLIB::Point*>* _nodes; - std::vector<Element*>* _elems; - const MeshLib::CFEMesh* _mesh; -}; - -#endif // GRIDADAPTER_H diff --git a/MeshLib/MshEditor.cpp b/MeshLib/MshEditor.cpp new file mode 100644 index 00000000000..9656946c84a --- /dev/null +++ b/MeshLib/MshEditor.cpp @@ -0,0 +1,177 @@ +/** + * \file MshEditor.cpp + * 2011/06/15 KR Initial implementation + */ + +#include "MshEditor.h" +#include "PointWithID.h" +#include "Mesh.h" + + +MeshLib::Mesh* MshEditor::removeMeshNodes(MeshLib::Mesh* mesh, + const std::vector<size_t> &nodes) +{ + MeshLib::Mesh* new_mesh (new MeshLib::Mesh(*mesh)); + + /* TODO6 + // delete nodes and their connected elements and replace them with null pointers + size_t delNodes = nodes.size(); + for (size_t i = 0; i < delNodes; i++) + { + const MeshLib::Node* node = new_mesh->getNode(i); + std::vector<size_t> conn_elems = node->getConnectedElementIDs(); + for (size_t j = 0; j < conn_elems.size(); j++) + { + delete new_mesh->ele_vector[conn_elems[j]]; + new_mesh->ele_vector[conn_elems[j]] = NULL; + } + delete new_mesh->nod_vector[nodes[i]]; + new_mesh->nod_vector[nodes[i]] = NULL; + } + + // create map to adjust node indices in element vector + size_t nNodes = new_mesh->nod_vector.size(); + std::vector<int> id_map; + size_t count = 0; + for (size_t i = 0; i < nNodes; i++) + { + if (new_mesh->nod_vector[i]) + { + new_mesh->nod_vector[i]->SetIndex(count); + id_map.push_back(count); + count++; + } + else + id_map.push_back(-1); + } + + // erase null pointers from node- and element vectors + for (std::vector<MeshLib::CElem*>::iterator it = new_mesh->ele_vector.begin(); + it != new_mesh->ele_vector.end(); ) + { + if (*it) + ++it; + else + it = new_mesh->ele_vector.erase(it); + } + + for (std::vector<MeshLib::CNode*>::iterator it = new_mesh->nod_vector.begin(); + it != new_mesh->nod_vector.end(); ) + { + if (*it) + ++it; + else + it = new_mesh->nod_vector.erase(it); + } + + // re-adjust node indices + size_t nElems = new_mesh->ele_vector.size(); + for (size_t i = 0; i < nElems; i++) + { + MeshLib::CElem* elem = new_mesh->ele_vector[i]; + size_t nElemNodes = elem->GetNodesNumber(false); + for (size_t j = 0; j < nElemNodes; j++) + elem->SetNodeIndex(j, id_map[elem->GetNodeIndex(j)]); + } + */ + return new_mesh; +} + +std::vector<GeoLib::PointWithID*> MshEditor::getSurfaceNodes(const MeshLib::Mesh &mesh) +{ + /* TODO6 + std::cout << "Extracting surface nodes..." << std::endl; + // Sort points lexicographically + size_t nNodes (mesh.nod_vector.size()); + std::vector<GeoLib::PointWithID*> nodes; + std::vector<size_t> perm; + for (size_t j(0); j<nNodes; j++) + { + nodes.push_back(new GeoLib::PointWithID(mesh.nod_vector[j]->getData(), j)); + perm.push_back(j); + } + Quicksort<GeoLib::PointWithID*> (nodes, 0, nodes.size(), perm); + + // Extract surface points + double eps (std::numeric_limits<double>::epsilon()); + */ + std::vector<GeoLib::PointWithID*> surface_pnts; + /* TODO6 + for (size_t k(1); k < nNodes; k++) + { + const GeoLib::PointWithID& p0 (*(nodes[k - 1])); + const GeoLib::PointWithID& p1 (*(nodes[k])); + if (fabs (p0[0] - p1[0]) > eps || fabs (p0[1] - p1[1]) > eps) + surface_pnts.push_back (nodes[k - 1]); + } + // Add last point + surface_pnts.push_back (nodes[nNodes - 1]); + + */ + return surface_pnts; +} + +MeshLib::Mesh* MshEditor::getMeshSurface(const MeshLib::Mesh &mesh) +{ + /* TODO6 + std::cout << "Extracting mesh surface..." << std::endl; + GridAdapter surface; + const std::vector<GeoLib::PointWithID*> sfc_points = MshEditor::getSurfaceNodes(mesh); + const size_t nSurfacePoints (sfc_points.size()); + + std::vector<GridAdapter::Element*> *elements = new std::vector<GridAdapter::Element*>; + + const size_t nElements = mesh.ele_vector.size(); + for (size_t j=0; j<nElements; j++) + { + MeshLib::CElem* elem (mesh.ele_vector[j]); + std::vector<size_t> elem_nodes; + bool is_surface (true); + for (size_t i=0; i<4; i++) + { + size_t node_index = elem->GetNodeIndex(i); + bool node_found(false), one_node(true); + for (size_t k=0; k<nSurfacePoints; k++) + { + if (sfc_points[k]->getID() == node_index) + { + node_found=true; + elem_nodes.push_back(k); + break; + } + } + if (!node_found) + { + if (one_node == true) + one_node = false; + else + { + is_surface = false; + break; + } + } + } + if (is_surface) + { + GridAdapter::Element* element = new GridAdapter::Element; + element->material = 0; + element->type = MshElemType::TRIANGLE; + element->nodes = elem_nodes; + elements->push_back(element); + } + } + + std::vector<GeoLib::Point*> *nodes = new std::vector<GeoLib::Point*>(nSurfacePoints); + for (size_t j=0; j<nSurfacePoints; j++) + //(*nodes)[sfc_points[j]->getID()]=sfc_points[j]; + (*nodes)[j] = sfc_points[j]; + + surface.setNodeVector(nodes); + surface.setElements(elements); + + MeshLib::Mesh* sfc_mesh = new MeshLib::Mesh(*surface.getMesh()); + return sfc_mesh; + */ + return new MeshLib::Mesh(mesh); +} + diff --git a/MeshLib/MshEditor.h b/MeshLib/MshEditor.h new file mode 100644 index 00000000000..09ea3dc2a6f --- /dev/null +++ b/MeshLib/MshEditor.h @@ -0,0 +1,42 @@ +/** + * \file MshEditor.h + * 2011/06/15 KR Initial implementation + */ + +#ifndef MSHEDITOR_H +#define MSHEDITOR_H + +#include <cstddef> +#include <vector> + +namespace GeoLib { + class PointWithID; +} + +namespace MeshLib +{ +class Mesh; +} + +class GridAdapter; + +/** + * \brief A set of tools for manipulating existing meshes + */ +class MshEditor +{ +public: + MshEditor() {} + ~MshEditor() {} + + static MeshLib::Mesh* removeMeshNodes(MeshLib::Mesh* mesh, + const std::vector<size_t> &nodes); + + static std::vector<GeoLib::PointWithID*> getSurfaceNodes(const MeshLib::Mesh &mesh); + + static MeshLib::Mesh* getMeshSurface(const MeshLib::Mesh &mesh); + +private: +}; + +#endif //MSHEDITOR_H diff --git a/scripts/cmake/CompilerSetup.cmake b/scripts/cmake/CompilerSetup.cmake index 15cbb475bf4..4ade37904ed 100644 --- a/scripts/cmake/CompilerSetup.cmake +++ b/scripts/cmake/CompilerSetup.cmake @@ -30,7 +30,7 @@ IF(COMPILER_IS_GCC) ENDIF() # -g SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wall -Wextra -fno-nonansi-builtins") - ADD_DEFINITIONS( -DGCC ) + ADD_DEFINITIONS( -DGCC -Wfatal-errors) ENDIF() # COMPILER_IS_GCC ### Intel compiler -- GitLab