Skip to content
Snippets Groups Projects
Commit 24b967eb authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge pull request #115 from rinkk/MaterialGroupModding

Material group modding
parents 898ae2ce aa8ec98e
No related branches found
No related tags found
No related merge requests found
Showing
with 716 additions and 98 deletions
......@@ -17,6 +17,7 @@ set( SOURCES
LinearEditDialog.cpp
LineEditDialog.cpp
ListPropertiesDialog.cpp
MeshValueEditDialog.cpp
ModellingTabWidget.cpp
ModelTreeItem.cpp
MshEditDialog.cpp
......@@ -54,6 +55,7 @@ set( MOC_HEADERS
LinearEditDialog.h
LineEditDialog.h
ListPropertiesDialog.h
MeshValueEditDialog.h
ModellingTabWidget.h
MshEditDialog.h
MshModel.h
......@@ -96,6 +98,7 @@ set( UIS
License.ui
LinearEdit.ui
LineEdit.ui
MeshValueEdit.ui
ModellingTabWidgetBase.ui
MshEdit.ui
MshQualitySelection.ui
......
......@@ -20,7 +20,7 @@
#include "DirectConditionGenerator.h"
#include "Raster.h"
#include "MshEditor.h"
#include "MeshSurfaceExtraction.h"
#include "PointWithID.h"
#include "Mesh.h"
......@@ -45,7 +45,7 @@ const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directT
double const*const img(raster->begin());
const double dir[3] = {0,0,1};
const std::vector<GeoLib::PointWithID*> surface_nodes(MeshLib::MshEditor::getSurfaceNodes(mesh, dir) );
const std::vector<GeoLib::PointWithID*> surface_nodes(MeshLib::MeshSurfaceExtraction::getSurfaceNodes(mesh, dir) );
//std::vector<MeshLib::CNode*> nodes = mesh.nod_vector;
const size_t nNodes(surface_nodes.size());
_direct_values.reserve(nNodes);
......@@ -90,9 +90,9 @@ const std::vector< std::pair<size_t,double> >& DirectConditionGenerator::directW
//mesh.MarkInterface_mHM_Hydro_3D(); // mark element faces on the surface
//----
const double dir[3] = {0,0,1};
MeshLib::Mesh* sfc_mesh (MeshLib::MshEditor::getMeshSurface(mesh, dir));
MeshLib::Mesh* sfc_mesh (MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, dir));
std::vector<double> node_area_vec (sfc_mesh->getNNodes());
MeshLib::MshEditor::getSurfaceAreaForNodes(sfc_mesh, node_area_vec);
MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(sfc_mesh, node_area_vec);
//----
double origin_x(0), origin_y(0), delta(0);
size_t imgwidth(0), imgheight(0);
......
......@@ -19,7 +19,7 @@
#include "Mesh.h"
#include "Node.h"
#include "MshEditor.h"
#include "MeshSurfaceExtraction.h"
#include "PointWithID.h"
#include "Raster.h"
#include "readMeshFromFile.h"
......@@ -145,7 +145,7 @@ GeoLib::Grid<GeoLib::PointWithID>* GeoMapper::getFlatGrid(MeshLib::Mesh const*co
else
{
double dir[3] = {0,0,1};
sfc_pnts = MeshLib::MshEditor::getSurfaceNodes(*mesh, dir);
sfc_pnts = MeshLib::MeshSurfaceExtraction::getSurfaceNodes(*mesh, dir);
}
size_t nPoints (sfc_pnts.size());
for (unsigned i=0; i<nPoints; ++i)
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MeshValueEdit</class>
<widget class="QDialog" name="MeshValueEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>206</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="condenseButton">
<property name="text">
<string>Condense material groups to smallest possible range</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QLabel" name="label_example">
<property name="text">
<string>(e.g. [0,2,27] will become [0,1,2]; [3,4,6,7,9] will become [0,1,2,3,4])</string>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="replaceButton">
<property name="text">
<string>Replace material group value:</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QLineEdit" name="edit_new_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_new_value">
<property name="text">
<string>New value:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="edit_old_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_old_value">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Current value:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QCheckBox" name="replaceCheckBox">
<property name="text">
<string>Do not replace if material group already exists</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MeshValueEdit</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MeshValueEdit</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/**
* \file
* \author Karsten Rink
* \date 2013-03-27
* \brief Implementation of the MeshValueEditDialog class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "MeshValueEditDialog.h"
#include "MeshEditing/ElementValueModification.h"
#include "OGSError.h"
MeshValueEditDialog::MeshValueEditDialog(MeshLib::Mesh* mesh, QDialog* parent)
: QDialog(parent), _mesh(mesh)
{
setupUi(this);
this->edit_old_value->setEnabled(false);
this->edit_new_value->setEnabled(false);
this->replaceCheckBox->setEnabled(false);
}
MeshValueEditDialog::~MeshValueEditDialog(void)
{
}
void MeshValueEditDialog::accept()
{
if (this->condenseButton->isChecked())
MeshLib::ElementValueModification::condense(*_mesh);
else
{
if (this->edit_old_value->text().isEmpty())
{
OGSError::box("Please input which material you want to replace.");
return;
}
unsigned old_value = static_cast<unsigned>(atoi(this->edit_old_value->text().toStdString().c_str()));
if (this->edit_new_value->text().isEmpty())
{
OGSError::box("Please input the new material to replace group " + this->edit_old_value->text() + ".");
return;
}
unsigned new_value = static_cast<unsigned>(atoi(this->edit_new_value->text().toStdString().c_str()));
bool do_not_replace = this->replaceCheckBox->isChecked();
bool result = MeshLib::ElementValueModification::replace(*_mesh, old_value, new_value, !do_not_replace);
if (!result && do_not_replace)
{
OGSError::box("The new material group already exists.");
return;
}
}
emit valueEditFinished(_mesh);
this->done(QDialog::Accepted);
}
void MeshValueEditDialog::reject()
{
this->done(QDialog::Rejected);
}
void MeshValueEditDialog::on_replaceButton_toggled(bool isSelected)
{
this->edit_old_value->setEnabled(isSelected);
this->edit_new_value->setEnabled(isSelected);
this->replaceCheckBox->setEnabled(isSelected);
}
/**
* \file
* \author Karsten Rink
* \date 2013-03-27
* \brief Definition of the MeshValueEditDialog class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef MESHVALUEEDITDIALOG_H
#define MESHVALUEEDITDIALOG_H
#include "ui_MeshValueEdit.h"
#include "FEMCondition.h"
#include <QDialog>
namespace MeshLib {
class Mesh;
}
/**
* \brief A dialog window for changing the MaterialID for mesh elements
*/
class MeshValueEditDialog : public QDialog, private Ui_MeshValueEdit
{
Q_OBJECT
public:
/// Constructor for creating a new FEM condition.
MeshValueEditDialog(MeshLib::Mesh* mesh, QDialog* parent = 0);
~MeshValueEditDialog(void);
private:
MeshLib::Mesh* _mesh;
private slots:
/// Instructions if the OK-Button has been pressed.
void accept();
/// Instructions if the Cancel-Button has been pressed.
void reject();
void on_replaceButton_toggled(bool isSelected);
signals:
void valueEditFinished(MeshLib::Mesh*);
};
#endif //MESHVALUEEDITDIALOG_H
......@@ -26,7 +26,7 @@
#include "Elements/Hex.h"
#include "Elements/Pyramid.h"
#include "Elements/Prism.h"
#include "MshEditor.h"
#include "MeshSurfaceExtraction.h"
#include "MathTools.h"
#include <QImage>
......@@ -213,7 +213,7 @@ int MshLayerMapper::LayerMapping(MeshLib::Mesh* new_mesh, const std::string &ras
{
std::cout << "Warning: Removing " << noData_nodes.size()
<< " mesh nodes at NoData values ... " << std::endl;
MeshLib::Mesh* red_mesh = MeshLib::MshEditor::removeMeshNodes(new_mesh, noData_nodes);
MeshLib::Mesh* red_mesh = MeshLib::removeMeshNodes(new_mesh, noData_nodes);
if (new_mesh->getNElements() == 0)
{
delete new_mesh;
......@@ -279,7 +279,7 @@ MeshLib::Mesh* MshLayerMapper::blendLayersWithSurface(MeshLib::Mesh* mesh, const
{
// construct surface mesh from DEM
const double dir[3] = {0,0,1};
MeshLib::Mesh* dem = MeshLib::MshEditor::getMeshSurface(*mesh, dir);
MeshLib::Mesh* dem = MeshLib::MeshSurfaceExtraction::getMeshSurface(*mesh, dir);
MshLayerMapper::LayerMapping(dem, dem_raster, 0, 0);
const std::vector<MeshLib::Node*> dem_nodes (dem->getNodes());
......
......@@ -153,6 +153,19 @@ bool MshModel::removeMesh(const std::string &name)
return false;
}
void MshModel::updateMesh(MeshLib::Mesh* mesh)
{
for (int i = 0; i < _rootItem->childCount(); i++)
{
if (dynamic_cast<MshItem*>(this->_rootItem->child(i))->getMesh() == mesh)
{
emit meshRemoved(this, this->index(i, 0, QModelIndex()));
_rootItem->removeChildren(i,1);
}
}
this->addMeshObject(mesh);
}
void MshModel::updateModel()
{
const std::vector<MeshLib::Mesh*> msh_vec = _project.getMeshObjects();
......
......@@ -49,6 +49,8 @@ public slots:
bool removeMesh(const QModelIndex &idx);
/// Removes the mesh with the given name.
bool removeMesh(const std::string &name);
/// Updates the model/view for a mesh.
void updateMesh(MeshLib::Mesh*);
/// Updates the model based on the ProjectData-object
void updateModel();
/// Returns the VTK source item for the mesh with the given index.
......
......@@ -15,10 +15,11 @@
#include "MshView.h"
#include "Mesh.h"
#include "MshEditDialog.h"
#include "MeshValueEditDialog.h"
#include "MshItem.h"
#include "MshModel.h"
#include "OGSError.h"
#include "MshEditor.h"
#include "MeshSurfaceExtraction.h"
#include "ImportFileTypes.h"
#include <QHeaderView>
......@@ -107,6 +108,7 @@ void MshView::contextMenuEvent( QContextMenuEvent* event )
{
QMenu menu;
QAction* editMeshAction = menu.addAction("Edit mesh...");
QAction* editValuesAction = menu.addAction("Edit material groups...");
QAction* checkMeshAction = menu.addAction("Check mesh quality...");
QAction* surfaceMeshAction (NULL);
if (is_3D_mesh)
......@@ -119,6 +121,7 @@ void MshView::contextMenuEvent( QContextMenuEvent* event )
QAction* loadDirectAction = direct_cond_menu.addAction("Load...");
//menu.addSeparator();
connect(editMeshAction, SIGNAL(triggered()), this, SLOT(openMshEditDialog()));
connect(editValuesAction, SIGNAL(triggered()), this, SLOT(openValuesEditDialog()));
connect(checkMeshAction, SIGNAL(triggered()), this, SLOT(checkMeshQuality()));
if (is_3D_mesh)
connect(surfaceMeshAction, SIGNAL(triggered()), this, SLOT(extractSurfaceMesh()));
......@@ -141,6 +144,18 @@ void MshView::openMshEditDialog()
meshEdit.exec();
}
void MshView::openValuesEditDialog()
{
MshModel* model = static_cast<MshModel*>(this->model());
QModelIndex index = this->selectionModel()->currentIndex();
MeshLib::Mesh* mesh = const_cast<MeshLib::Mesh*>(static_cast<MshModel*>(this->model())->getMesh(index));
MeshValueEditDialog valueEdit(mesh);
connect(&valueEdit, SIGNAL(valueEditFinished(MeshLib::Mesh*)),
model, SLOT(updateMesh(MeshLib::Mesh*)));
valueEdit.exec();
}
void MshView::extractSurfaceMesh()
{
QModelIndex index = this->selectionModel()->currentIndex();
......@@ -149,7 +164,7 @@ void MshView::extractSurfaceMesh()
const MeshLib::Mesh* mesh = static_cast<MshModel*>(this->model())->getMesh(index);
const double dir[3] = {0, 0, 1};
static_cast<MshModel*>(this->model())->addMesh( MeshLib::MshEditor::getMeshSurface(*mesh, dir) );
static_cast<MshModel*>(this->model())->addMesh( MeshLib::MeshSurfaceExtraction::getMeshSurface(*mesh, dir) );
}
int MshView::writeToFile() const
......
......@@ -59,9 +59,12 @@ private:
void contextMenuEvent( QContextMenuEvent* event );
private slots:
/// Open a dialog for editing meshes.
/// Opens a dialog for editing meshes.
void openMshEditDialog();
/// Opens a dialog for editing material groups.
void openValuesEditDialog();
/// Adds a new mesh.
void addMesh();
......
......@@ -81,7 +81,7 @@
#include "Mesh.h"
#include "Node.h"
#include "Elements/Element.h"
#include "MshEditor.h"
#include "MeshSurfaceExtraction.h"
#include "readMeshFromFile.h"
#include "Mesh2MeshPropertyInterpolation.h"
......@@ -1153,7 +1153,7 @@ void MainWindow::FEMTestStart()
/*
const double dir[3] = {0, 0, 1};
const MeshLib::Mesh* mesh = this->_project.getMesh("ketzin_2012_11_11_tets");
_meshModels->addMesh( MeshLib::MshEditor::getMeshSurface(*mesh, dir) );
_meshModels->addMesh( MeshLib::MeshSurfaceExtraction::getMeshSurface(*mesh, dir) );
*/
/*
const std::vector<GeoLib::Polyline*> *lines = this->_geoModels->getPolylineVec("WESS Rivers"); MeshLib::CFEMesh* mesh = const_cast<MeshLib::CFEMesh*>(_project.getMesh("Ammer-Homogen100m-Final"));
......
# Source files
GET_SOURCE_FILES(SOURCES_MESHLIB)
GET_SOURCE_FILES(SOURCES_ELEMENTS Elements)
GET_SOURCE_FILES(SOURCES_EDITING MeshEditing)
GET_SOURCE_FILES(SOURCES_QUALITY MeshQuality)
SET ( SOURCES ${SOURCES_MESHLIB} ${SOURCES_ELEMENTS} ${SOURCES_QUALITY})
SET ( SOURCES ${SOURCES_MESHLIB} ${SOURCES_ELEMENTS} ${SOURCES_EDITING} ${SOURCES_QUALITY})
# Create the library
ADD_LIBRARY(MeshLib STATIC ${SOURCES})
......
/**
* \file
* \author Karsten Rink
* \date 2013-04-04
* \brief Implementation of the ElementValueModification class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include <algorithm>
#include "ElementValueModification.h"
#include "Mesh.h"
#include "Elements/Element.h"
#include "logog/include/logog.hpp"
namespace MeshLib {
std::vector<unsigned> ElementValueModification::getMeshValues(const MeshLib::Mesh &mesh)
{
const std::size_t nElements (mesh.getNElements());
std::vector<unsigned> value_mapping;
for (unsigned i=0; i<nElements; ++i)
{
bool exists(false);
unsigned value (mesh.getElement(i)->getValue());
const unsigned nValues (value_mapping.size());
for (unsigned j=0; j<nValues; ++j)
{
if (value == value_mapping[j])
{
exists = true;
break;
}
}
if (!exists)
value_mapping.push_back(value);
}
std::sort(value_mapping.begin(), value_mapping.end());
return value_mapping;
}
bool ElementValueModification::replace(MeshLib::Mesh &mesh, unsigned old_value, unsigned new_value, bool replace_if_exists)
{
std::vector<unsigned> value_mapping (ElementValueModification::getMeshValues(mesh));
if (!replace_if_exists)
{
const unsigned nValues (value_mapping.size());
for (unsigned j=0; j<nValues; ++j)
{
if (new_value == value_mapping[j])
{
ERR ("Error in ElementValueModification::replaceElementValue() - Replacement value is already taken.");
return false;
}
}
}
const std::size_t nElements (mesh.getNElements());
std::vector<MeshLib::Element*> elements (mesh.getElements());
for (unsigned i=0; i<nElements; ++i)
{
if (elements[i]->getValue() == old_value)
elements[i]->setValue(new_value);
}
return true;
}
unsigned ElementValueModification::condense(MeshLib::Mesh &mesh)
{
std::vector<unsigned> value_mapping (ElementValueModification::getMeshValues(mesh));
std::vector<unsigned> reverse_mapping(value_mapping.back()+1, 0);
const unsigned nValues (value_mapping.size());
for (unsigned i=0; i<nValues; ++i)
reverse_mapping[value_mapping[i]] = i;
const std::size_t nElements (mesh.getNElements());
std::vector<MeshLib::Element*> elements (mesh.getElements());
for (unsigned i=0; i<nElements; ++i)
elements[i]->setValue(reverse_mapping[elements[i]->getValue()]);
return nValues;
}
} // end namespace MeshLib
/**
* \file
* \author Karsten Rink
* \date 2013-04-04
* \brief Definition of the ElementValueModification class
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef MESHVALUEMODIFICATION_H
#define MESHVALUEMODIFICATION_H
#include <vector>
namespace MeshLib {
// forward declarations
class Mesh;
/**
* \brief A set of methods for manipulating mesh element values
*/
class ElementValueModification
{
public:
/// Reduces the values assigned the elements of mesh to the smallest possible range.
/// Returns the number of different values.
static unsigned condense(MeshLib::Mesh &mesh);
/// Replaces for all elements of mesh with the value old_value with new_value if possible.
/// Returns true if successful or false if the value is already taken.
static bool replace(MeshLib::Mesh &mesh, unsigned old_value, unsigned new_value, bool replace_if_exists = false);
private:
/// Returns the values of elements within the mesh
static std::vector<unsigned> getMeshValues(const MeshLib::Mesh &mesh);
};
} // end namespace MeshLib
#endif //MESHVALUEMODIFICATION_H
/**
* \file
* \author Karsten Rink
* \date 2013-04-04
* \brief Implementation of removeMeshNodes.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "removeMeshNodes.h"
#include "Mesh.h"
#include "Node.h"
#include "Elements/Element.h"
namespace MeshLib {
MeshLib::Mesh* removeMeshNodes(MeshLib::Mesh* mesh, const std::vector<size_t> &nodes)
{
MeshLib::Mesh* new_mesh (new MeshLib::Mesh(*mesh));
// delete nodes and their connected elements and replace them with null pointers
const size_t delNodes = nodes.size();
std::vector<MeshLib::Node*> mesh_nodes = new_mesh->getNodes();
for (size_t i = 0; i < delNodes; ++i)
{
const MeshLib::Node* node = new_mesh->getNode(i);
std::vector<MeshLib::Element*> conn_elems = node->getElements();
for (size_t j = 0; j < conn_elems.size(); ++j)
{
delete conn_elems[j];
conn_elems[j] = NULL;
}
delete mesh_nodes[i];
mesh_nodes[i] = NULL;
}
// create map to adjust node indices in element vector
const size_t nNodes = new_mesh->getNNodes();
std::vector<int> id_map(nNodes, -1);
size_t count(0);
for (size_t i = 0; i < nNodes; ++i)
{
if (mesh_nodes[i])
{
mesh_nodes[i]->setID(count);
id_map.push_back(count++);
}
}
// erase null pointers from node- and element vectors
std::vector<MeshLib::Element*> elements = new_mesh->getElements();
for (std::vector<MeshLib::Element*>::iterator it = elements.begin(); it != elements.end(); )
{
if (*it)
++it;
else
it = elements.erase(it);
}
for (std::vector<MeshLib::Node*>::iterator it = mesh_nodes.begin(); it != mesh_nodes.end(); )
{
if (*it)
++it;
else
it = mesh_nodes.erase(it);
}
return new_mesh;
}
} // end namespace MeshLib
/**
* \file
* \author Karsten Rink
* \date 2013-04-04
* \brief Definition of the removeMeshNodes
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef REMOVEMESHNODES_H
#define REMOVEMESHNODES_H
#include <vector>
namespace MeshLib {
// forward declarations
class Mesh;
/// Removes the mesh nodes (and connected elements) given in the nodes-list from the mesh.
MeshLib::Mesh* removeMeshNodes(MeshLib::Mesh* mesh, const std::vector<std::size_t> &nodes);
} // end namespace MeshLib
#endif //REMOVEMESHNODES_H
/**
* \file
* \author Karsten Rink
* \date 2011-06-15
* \brief Implementation of the MshEditor class.
* \date 2013-04-04
* \brief Implementation of the MeshSurfaceExtraction class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
......@@ -12,23 +12,20 @@
*
*/
#include "MshEditor.h"
#include "MeshSurfaceExtraction.h"
#include "PointWithID.h"
#include "Mesh.h"
#include "Node.h"
#include "Elements/Element.h"
#include "Elements/Face.h"
#include "Elements/Cell.h"
#include "Elements/Tri.h"
#include "Elements/Quad.h"
#include "MathTools.h"
#include "logog/include/logog.hpp"
namespace MeshLib {
void MshEditor::getSurfaceAreaForNodes(const MeshLib::Mesh* mesh, std::vector<double> &node_area_vec)
void MeshSurfaceExtraction::getSurfaceAreaForNodes(const MeshLib::Mesh* mesh, std::vector<double> &node_area_vec)
{
if (mesh->getDimension() == 2)
{
......@@ -59,66 +56,10 @@ void MshEditor::getSurfaceAreaForNodes(const MeshLib::Mesh* mesh, std::vector<do
INFO ("Total surface Area: %f", total_area);
}
else
ERR ("Error in MshEditor::getSurfaceAreaForNodes() - Given mesh is no surface mesh (dimension != 2).");
ERR ("Error in MeshSurfaceExtraction::getSurfaceAreaForNodes() - Given mesh is no surface mesh (dimension != 2).");
}
MeshLib::Mesh* MshEditor::removeMeshNodes(MeshLib::Mesh* mesh,
const std::vector<size_t> &nodes)
{
MeshLib::Mesh* new_mesh (new MeshLib::Mesh(*mesh));
// delete nodes and their connected elements and replace them with null pointers
const size_t delNodes = nodes.size();
std::vector<MeshLib::Node*> mesh_nodes = new_mesh->getNodes();
for (size_t i = 0; i < delNodes; ++i)
{
const MeshLib::Node* node = new_mesh->getNode(i);
std::vector<MeshLib::Element*> conn_elems = node->getElements();
for (size_t j = 0; j < conn_elems.size(); ++j)
{
delete conn_elems[j];
conn_elems[j] = NULL;
}
delete mesh_nodes[i];
mesh_nodes[i] = NULL;
}
// create map to adjust node indices in element vector
const size_t nNodes = new_mesh->getNNodes();
std::vector<int> id_map(nNodes, -1);
size_t count(0);
for (size_t i = 0; i < nNodes; ++i)
{
if (mesh_nodes[i])
{
mesh_nodes[i]->setID(count);
id_map.push_back(count++);
}
}
// erase null pointers from node- and element vectors
std::vector<MeshLib::Element*> elements = new_mesh->getElements();
for (std::vector<MeshLib::Element*>::iterator it = elements.begin(); it != elements.end(); )
{
if (*it)
++it;
else
it = elements.erase(it);
}
for (std::vector<MeshLib::Node*>::iterator it = mesh_nodes.begin(); it != mesh_nodes.end(); )
{
if (*it)
++it;
else
it = mesh_nodes.erase(it);
}
return new_mesh;
}
MeshLib::Mesh* MshEditor::getMeshSurface(const MeshLib::Mesh &mesh, const double* dir)
MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface(const MeshLib::Mesh &mesh, const double* dir)
{
INFO ("Extracting mesh surface...");
const std::vector<MeshLib::Element*> all_elements (mesh.getElements());
......@@ -158,7 +99,7 @@ MeshLib::Mesh* MshEditor::getMeshSurface(const MeshLib::Mesh &mesh, const double
return NULL;
}
void MshEditor::get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_elements, std::vector<MeshLib::Element*> &sfc_elements, const double* dir, unsigned mesh_dimension)
void MeshSurfaceExtraction::get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_elements, std::vector<MeshLib::Element*> &sfc_elements, const double* dir, unsigned mesh_dimension)
{
bool complete_surface (true);
if (dir)
......@@ -219,7 +160,7 @@ void MshEditor::get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_e
ERR("Cannot handle meshes of dimension %i", mesh_dimension);
}
void MshEditor::get2DSurfaceNodes(const std::vector<MeshLib::Node*> &all_nodes, std::vector<MeshLib::Node*> &sfc_nodes, const std::vector<MeshLib::Element*> &sfc_elements, std::vector<unsigned> &node_id_map)
void MeshSurfaceExtraction::get2DSurfaceNodes(const std::vector<MeshLib::Node*> &all_nodes, std::vector<MeshLib::Node*> &sfc_nodes, const std::vector<MeshLib::Element*> &sfc_elements, std::vector<unsigned> &node_id_map)
{
const size_t nNewElements (sfc_elements.size());
std::vector<const MeshLib::Node*> tmp_nodes(all_nodes.size(), NULL);
......@@ -243,7 +184,7 @@ void MshEditor::get2DSurfaceNodes(const std::vector<MeshLib::Node*> &all_nodes,
}
}
std::vector<GeoLib::PointWithID*> MshEditor::getSurfaceNodes(const MeshLib::Mesh &mesh, const double *dir)
std::vector<GeoLib::PointWithID*> MeshSurfaceExtraction::getSurfaceNodes(const MeshLib::Mesh &mesh, const double *dir)
{
INFO ("Extracting surface nodes...");
const std::vector<MeshLib::Element*> all_elements (mesh.getElements());
......@@ -270,5 +211,4 @@ std::vector<GeoLib::PointWithID*> MshEditor::getSurfaceNodes(const MeshLib::Mesh
return surface_pnts;
}
} // end namespace MeshLib
/**
* \file
* \author Karsten Rink
* \date 2011-06-15
* \brief Definition of the MshEditor class
* \date 2013-04-04
* \brief Definition of the MeshSurfaceExtraction class
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
......@@ -12,14 +12,12 @@
*
*/
#ifndef MSHEDITOR_H
#define MSHEDITOR_H
#ifndef MESHSURFACEEXTRACTION_H
#define MESHSURFACEEXTRACTION_H
#include <cstddef>
#include <vector>
#include "Point.h"
namespace GeoLib {
class PointWithID;
}
......@@ -31,17 +29,14 @@ class Element;
class Node;
/**
* \brief A set of tools for manipulating existing meshes
* \brief A set of tools concerned with extracting nodes and elements from a mesh surface
*/
class MshEditor
class MeshSurfaceExtraction
{
public:
/// Returns the area assigned to each node on a surface mesh.
static void getSurfaceAreaForNodes(const MeshLib::Mesh* mesh, std::vector<double> &node_area_vec);
/// Removes the mesh nodes (and connected elements) given in the nodes-list from the mesh.
static MeshLib::Mesh* removeMeshNodes(MeshLib::Mesh* mesh, const std::vector<std::size_t> &nodes);
/// Returns the surface nodes of a layered mesh.
static std::vector<GeoLib::PointWithID*> getSurfaceNodes(const MeshLib::Mesh &mesh, const double* dir = NULL);
......@@ -58,4 +53,4 @@ private:
} // end namespace MeshLib
#endif //MSHEDITOR_H
#endif //MESHSURFACEEXTRACTION_H
......@@ -22,7 +22,8 @@
#include "PointWithID.h"
#include "Mesh.h"
#include "MshEditor.h"
#include "MeshEditing/removeMeshNodes.h"
#include "MeshSurfaceExtraction.h"
#ifdef OGS_BUILD_GUI
#include "../Gui/DataView/MshLayerMapper.h"
#endif
......@@ -37,7 +38,7 @@ class Element;
class Node : public GeoLib::PointWithID
{
/* friend functions: */
friend MeshLib::Mesh* MshEditor::removeMeshNodes(MeshLib::Mesh* mesh, const std::vector<std::size_t> &nodes);
friend MeshLib::Mesh* removeMeshNodes(MeshLib::Mesh* mesh, const std::vector<std::size_t> &nodes);
#ifdef OGS_BUILD_GUI
friend int MshLayerMapper::LayerMapping(MeshLib::Mesh* msh, const std::string &rasterfile, const unsigned nLayers,
const unsigned layer_id, bool removeNoDataValues);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment