2018-04-06 16:11:50 +02:00
|
|
|
/*
|
|
|
|
MDAL - Mesh Data Abstraction Library (MIT License)
|
|
|
|
Copyright (C) 2018 Peter Petrik (zilolv at gmail dot com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MDAL_2DM_HPP
|
|
|
|
#define MDAL_2DM_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2018-05-16 11:20:25 +02:00
|
|
|
#include <memory>
|
2018-04-06 16:11:50 +02:00
|
|
|
|
2018-07-18 09:00:34 +02:00
|
|
|
#include "mdal_data_model.hpp"
|
2018-12-04 17:28:05 +01:00
|
|
|
#include "mdal_memory_data_model.hpp"
|
2018-04-06 16:11:50 +02:00
|
|
|
#include "mdal.h"
|
2018-12-14 14:59:53 +01:00
|
|
|
#include "mdal_driver.hpp"
|
2018-04-06 16:11:50 +02:00
|
|
|
|
|
|
|
namespace MDAL
|
|
|
|
{
|
2018-12-04 17:28:05 +01:00
|
|
|
class Mesh2dm: public MemoryMesh
|
|
|
|
{
|
|
|
|
public:
|
2020-07-01 04:18:27 -04:00
|
|
|
Mesh2dm( size_t faceVerticesMaximumCount,
|
2018-12-04 17:28:05 +01:00
|
|
|
const std::string &uri,
|
|
|
|
const std::map<size_t, size_t> vertexIDtoIndex
|
|
|
|
);
|
|
|
|
~Mesh2dm() override;
|
|
|
|
|
|
|
|
|
2019-04-17 11:22:45 +02:00
|
|
|
//! HYDRO_AS-2D supports gaps in the vertex indexing,
|
|
|
|
//! but we use continuos array of vertices in MDAL
|
2018-12-04 17:28:05 +01:00
|
|
|
//! \param vertexID internal index/ID of the vertex that native format uses
|
2019-04-17 11:22:45 +02:00
|
|
|
//! \returns index of the vertex in the continuous array of vertices we returned by readVertices().
|
|
|
|
//! For invalid vertexID it is returned index that is out of vertices array bounds.
|
2018-12-04 17:28:05 +01:00
|
|
|
virtual size_t vertexIndex( size_t vertexID ) const;
|
|
|
|
|
2019-04-17 11:22:45 +02:00
|
|
|
//! Returns maximum vertex ID.
|
|
|
|
//! For meshes without gaps in vertex indexing, it is vertex count - 1
|
|
|
|
virtual size_t maximumVertexId() const;
|
|
|
|
|
2018-12-04 17:28:05 +01:00
|
|
|
private:
|
2019-04-17 11:22:45 +02:00
|
|
|
//! 2dm supports "gaps" in the mesh indexing
|
|
|
|
//! Store only the indices that have different index and ID
|
|
|
|
//! https://github.com/lutraconsulting/MDAL/issues/51
|
2018-12-04 17:28:05 +01:00
|
|
|
std::map<size_t, size_t> mVertexIDtoIndex;
|
|
|
|
};
|
2018-04-06 16:11:50 +02:00
|
|
|
|
2019-03-18 14:05:41 +01:00
|
|
|
/**
|
2019-04-17 11:22:45 +02:00
|
|
|
* 2DM format specification used in TUFLOW, HYDRO_AS-2D and BASEMENET solvers
|
2019-03-18 14:05:41 +01:00
|
|
|
* Text file format representing mesh vertices (ND) and faces (E**)
|
|
|
|
* ND id x y z
|
2020-03-09 05:59:51 +01:00
|
|
|
* The format supports lines, triangles and quads, where the elememts could be
|
|
|
|
* stored with some intermediate points (e.g. triangle defined by 6 vertices, vertices
|
|
|
|
* and the middle of the edges) We do support only simple definition, so E6T, E8Q and E9Q
|
|
|
|
* are not supported.
|
2019-03-18 14:05:41 +01:00
|
|
|
* E3T id 1 2 3 mat_id -> face type, id, vertex indices ..., material index
|
|
|
|
*
|
|
|
|
* full specification here: https://www.xmswiki.com/wiki/SMS:2D_Mesh_Files_*.2dm
|
|
|
|
*
|
2020-07-01 04:18:27 -04:00
|
|
|
* This will process as many material IDs as promised by the NUM_MATERIALS_PER_ELEM tag and add them as face
|
|
|
|
* dataset groups. The naming for these groups is "Material ID" for the first, "Bed Elevation (Face)" for the
|
|
|
|
* second, and finally "Auxiliary Material ID <X>" for any subsequent materials, X being a counter to ensure
|
|
|
|
* unique group names:
|
|
|
|
* E** id 1 2 3 [Material ID] [Bed Elevation (Face)] [Auxiliary Material ID 1] [Auxiliary Material ID 2] ...
|
|
|
|
* If the NUM_MATERIALS_PER_ELEM tag is not provided, a fallback mode is used that will only check for the
|
|
|
|
* second MATID column and add it under the name "Bed Elevation (Face)" if found.
|
|
|
|
* Noe that this is purely a compatibility mode for BASEMENT 3.x releases; NUM_MATERIALS_... is a required
|
|
|
|
* tag according to the 2DM specification.
|
2019-03-18 14:05:41 +01:00
|
|
|
*
|
|
|
|
* Note that some 2dm formats do have some extra columns after mat_id column with
|
|
|
|
* data with unknown origin/name (e.g. tests/data/2dm/regular_grid.2dm)
|
2019-04-17 11:22:45 +02:00
|
|
|
*
|
|
|
|
* HYDRO_AS-2D also allows gaps in vertex indexing. In this case we support only files
|
|
|
|
* where the vertices are sorted by ID in the source file (limitation of the implementation)
|
|
|
|
*
|
|
|
|
* Vertex/Face IDs should be indexed from 1. We support indexing from 0 for datasets in xmdf format,
|
|
|
|
* but not for ascii dat format (since the loop is from 0 to maximumVertexId() which is in this case
|
|
|
|
* numberical_limits<size_t>::max(); (limitation of the implementation)
|
2019-03-18 14:05:41 +01:00
|
|
|
*/
|
2018-12-14 14:59:53 +01:00
|
|
|
class Driver2dm: public Driver
|
2018-04-06 16:11:50 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-12-14 14:59:53 +01:00
|
|
|
Driver2dm();
|
|
|
|
~Driver2dm() override;
|
|
|
|
Driver2dm *create() override;
|
|
|
|
|
2020-12-17 09:03:08 +01:00
|
|
|
int faceVerticesMaximumCount() const override {return 6;}
|
2019-10-14 09:19:14 +02:00
|
|
|
|
2019-11-29 15:15:01 +01:00
|
|
|
bool canReadMesh( const std::string &uri ) override;
|
2020-04-14 02:17:15 -04:00
|
|
|
std::unique_ptr< Mesh > load( const std::string &meshFile, const std::string &meshName = "" ) override;
|
2021-08-18 10:49:05 +02:00
|
|
|
void save( const std::string &fileName, const std::string &, Mesh *mesh ) override;
|
2018-04-06 16:11:50 +02:00
|
|
|
|
2021-06-30 13:45:22 +02:00
|
|
|
std::string saveMeshOnFileSuffix() const override;
|
|
|
|
|
2018-04-06 16:11:50 +02:00
|
|
|
private:
|
|
|
|
std::string mMeshFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MDAL
|
|
|
|
#endif //MDAL_2DM_HPP
|