12
12
#include < vector>
13
13
#include < map>
14
14
#include < cassert>
15
+ #include < limits>
15
16
16
17
#include " mdal_2dm.hpp"
17
18
#include " mdal.h"
@@ -63,7 +64,6 @@ size_t MDAL::Mesh2dm::vertexIndex( size_t vertexID ) const
63
64
return vertexID;
64
65
}
65
66
66
-
67
67
MDAL::Driver2dm::Driver2dm ():
68
68
Driver( DRIVER_NAME,
69
69
" 2DM Mesh File" ,
@@ -135,6 +135,9 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
135
135
std::vector<Vertex> vertices ( vertexCount );
136
136
std::vector<Face> faces ( faceCount );
137
137
138
+ // Basement 3.x supports definition of elevation for cell centers
139
+ std::vector<double > elementCenteredElevation;
140
+
138
141
in.clear ();
139
142
in.seekg ( 0 , std::ios::beg );
140
143
@@ -146,30 +149,40 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
146
149
147
150
while ( std::getline ( in, line ) )
148
151
{
149
- if ( startsWith ( line, " E4Q" ) )
152
+ if ( startsWith ( line, " E4Q" ) ||
153
+ startsWith ( line, " E3T" )
154
+ )
150
155
{
151
156
chunks = split ( line, ' ' );
152
157
assert ( faceIndex < faceCount );
153
158
159
+ const size_t faceVertexCount = MDAL::toSizeT ( line[1 ] );
160
+ assert ( ( faceVertexCount == 3 ) || ( faceVertexCount == 4 ) );
161
+
154
162
Face &face = faces[faceIndex];
155
- face.resize ( 4 );
163
+ face.resize ( faceVertexCount );
164
+
165
+ // chunks format here
166
+ // E** id vertex_id1, vertex_id2, ... material_id (elevation - optional)
167
+ // vertex ids are numbered from 1
156
168
// Right now we just store node IDs here - we will convert them to node indices afterwards
157
- for ( size_t i = 0 ; i < 4 ; ++i )
158
- face[i] = toSizeT ( chunks[i + 2 ] ) - 1 ; // 2dm is numbered from 1
169
+ assert ( chunks.size () > faceVertexCount + 1 );
159
170
160
- faceIndex++;
161
- }
162
- else if ( startsWith ( line, " E3T" ) )
163
- {
164
- chunks = split ( line, ' ' );
165
- assert ( faceIndex < faceCount );
171
+ for ( size_t i = 0 ; i < faceVertexCount; ++i )
172
+ face[i] = MDAL::toSizeT ( chunks[i + 2 ] ) - 1 ; // 2dm is numbered from 1
166
173
167
- Face &face = faces[faceIndex];
168
- face.resize ( 3 );
169
- // Right now we just store node IDs here - we will convert them to node indices afterwards
170
- for ( size_t i = 0 ; i < 3 ; ++i )
174
+ // OK, now find out if there is optional cell elevation (BASEMENT 3.x)
175
+ if ( chunks.size () == faceVertexCount + 4 )
171
176
{
172
- face[i] = toSizeT ( chunks[i + 2 ] ) - 1 ; // 2dm is numbered from 1
177
+
178
+ // initialize dataset if it is still empty
179
+ if ( elementCenteredElevation.empty () )
180
+ {
181
+ elementCenteredElevation = std::vector<double >( faceCount, std::numeric_limits<double >::quiet_NaN () );
182
+ }
183
+
184
+ // add Bed Elevation (Face) value
185
+ elementCenteredElevation[faceIndex] = MDAL::toDouble ( chunks[ faceVertexCount + 3 ] );
173
186
}
174
187
175
188
faceIndex++;
@@ -236,6 +249,10 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
236
249
);
237
250
mesh->faces = faces;
238
251
mesh->vertices = vertices;
252
+
253
+ // Add Bed Elevations
254
+ MDAL::addFaceScalarDatasetGroup ( mesh.get (), elementCenteredElevation, " Bed Elevation (Face)" );
239
255
MDAL::addBedElevationDatasetGroup ( mesh.get (), vertices );
256
+
240
257
return std::unique_ptr<Mesh>( mesh.release () );
241
258
}
0 commit comments