Skip to content
Snippets Groups Projects
Commit 2bbfc352 authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

add convertSurfaceToMesh()

parent 0447d56e
No related branches found
No related tags found
No related merge requests found
......@@ -17,15 +17,13 @@
#include "logog/include/logog.hpp"
#include "GeoLib/GEOObjects.h"
namespace GeoLib
{
class Surface;
}
#include "GeoLib/Surface.h"
#include "Mesh.h"
#include "Elements/Tri.h"
#include "Elements/Quad.h"
#include "MeshInformation.h"
#include "MeshEditing/MeshRevision.h"
namespace MeshLib {
......@@ -81,6 +79,28 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects
return true;
}
MeshLib::Mesh* convertSurfaceToMesh(const GeoLib::Surface &sfc, const std::string &mesh_name, double eps)
{
// convert to a mesh including duplicated nodes
std::vector<MeshLib::Node*> nodes;
std::vector<MeshLib::Element*> elements;
std::size_t nodeId = 0;
for (std::size_t i=0; i<sfc.getNTriangles(); i++)
{
auto* tri = sfc[i];
MeshLib::Node** tri_nodes = new MeshLib::Node*[3];
for (unsigned j=0; j<3; j++)
tri_nodes[j] = new MeshLib::Node(tri->getPoint(j)->getCoords(), nodeId++);
elements.push_back(new MeshLib::Tri(tri_nodes, 0, i));
for (unsigned j=0; j<3; j++)
nodes.push_back(tri_nodes[j]);
}
MeshLib::Mesh mesh_with_duplicated_nodes(mesh_name, nodes, elements);
// remove duplicated nodes
MeshLib::MeshRevision rev(mesh_with_duplicated_nodes);
return rev.simplifyMesh(mesh_with_duplicated_nodes.getName(), eps);
}
}
......@@ -16,10 +16,12 @@
#define CONVERTMESHTOGEO_H_
#include <limits>
#include <string>
namespace GeoLib
{
class GEOObjects;
class Surface;
}
namespace MeshLib
......@@ -36,6 +38,15 @@ namespace MeshLib
*/
bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects, double eps = std::numeric_limits<double>::epsilon());
/**
* Converts a surface into a triangular mesh
* @param sfc Surface object
* @param mesh_name New mesh name
* @param eps Minimum distance for nodes not to be collapsed
* @return a pointer to a converted mesh object. nullptr is returned if the conversion fails.
*/
MeshLib::Mesh* convertSurfaceToMesh(const GeoLib::Surface &sfc, const std::string &mesh_name, double eps = std::numeric_limits<double>::epsilon());
} // namespace
#endif /* CONVERTMESHTOGEO_H_ */
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