Skip to content

Commit 245d6e2

Browse files
PeterPetrikwonder-sk
authored andcommitted
update MDAL to 0.0.5
1 parent 64b18c6 commit 245d6e2

19 files changed

+470
-327
lines changed

external/mdal/api/mdal.h

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum MDAL_Status
5353
Err_IncompatibleMesh,
5454
Err_InvalidData,
5555
Err_IncompatibleDataset,
56+
Err_IncompatibleDatasetGroup,
5657
Err_MissingDriver,
5758
// Warnings
5859
Warn_UnsupportedElement,
@@ -64,80 +65,118 @@ enum MDAL_Status
6465

6566
//! Mesh
6667
typedef void *MeshH;
68+
typedef void *DatasetGroupH;
6769
typedef void *DatasetH;
6870

69-
//! Return MDAL version
71+
//! Returns MDAL version
7072
MDAL_EXPORT const char *MDAL_Version();
7173

72-
//! Return last status message
74+
//! Returns last status message
7375
MDAL_EXPORT MDAL_Status MDAL_LastStatus();
7476

75-
//! Load mesh file. On error see MDAL_LastStatus for error type This effectively loads whole mesh in-memory
77+
///////////////////////////////////////////////////////////////////////////////////////
78+
/// MESH
79+
///////////////////////////////////////////////////////////////////////////////////////
80+
81+
//! Loads mesh file. On error see MDAL_LastStatus for error type This effectively loads whole mesh in-memory
7682
MDAL_EXPORT MeshH MDAL_LoadMesh( const char *meshFile );
77-
//! Close mesh, free the memory
83+
//! Closes mesh, frees the memory
7884
MDAL_EXPORT void MDAL_CloseMesh( MeshH mesh );
79-
//! Return vertex count for the mesh
85+
86+
//! Returns vertex count for the mesh
8087
MDAL_EXPORT int MDAL_M_vertexCount( MeshH mesh );
81-
//! Return vertex X coord for the mesh
88+
//! Returns vertex X coord for the mesh
8289
MDAL_EXPORT double MDAL_M_vertexXCoordinatesAt( MeshH mesh, int index );
83-
//! Return vertex Y coord for the mesh
90+
//! Returns vertex Y coord for the mesh
8491
MDAL_EXPORT double MDAL_M_vertexYCoordinatesAt( MeshH mesh, int index );
85-
//! Return face count for the mesh
92+
//! Returns face count for the mesh
8693
MDAL_EXPORT int MDAL_M_faceCount( MeshH mesh );
87-
//! Return number of vertices face consist of, e.g. 3 for triangle
94+
//! Returns number of vertices face consist of, e.g. 3 for triangle
8895
MDAL_EXPORT int MDAL_M_faceVerticesCountAt( MeshH mesh, int index );
89-
//! Return vertex index for face
96+
//! Returns vertex index for face
9097
MDAL_EXPORT int MDAL_M_faceVerticesIndexAt( MeshH mesh, int face_index, int vertex_index );
9198

9299
/**
93-
* Load dataset file. On error see MDAL_LastStatus for error type.
100+
* Loads dataset file. On error see MDAL_LastStatus for error type.
94101
* This may effectively load whole dataset in-memory for some providers
95102
* Datasets will be closed automatically on mesh destruction or memory
96103
* can be freed manually with MDAL_CloseDataset if needed
97104
*/
98105
MDAL_EXPORT void MDAL_M_LoadDatasets( MeshH mesh, const char *datasetFile );
99106

100-
//! Free the memory used to get dataset values
101-
MDAL_EXPORT void MDAL_M_CloseDataset( DatasetH dataset );
107+
//! Returns dataset groups count
108+
MDAL_EXPORT int MDAL_M_datasetGroupCount( MeshH mesh );
109+
110+
//! Returns dataset group handle
111+
MDAL_EXPORT DatasetGroupH MDAL_M_datasetGroup( MeshH mesh, int index );
112+
113+
///////////////////////////////////////////////////////////////////////////////////////
114+
/// DATASET GROUPS
115+
///////////////////////////////////////////////////////////////////////////////////////
102116

103-
//! Return dataset count
104-
MDAL_EXPORT int MDAL_M_datasetCount( MeshH mesh );
117+
//! Returns dataset count in group
118+
MDAL_EXPORT int MDAL_G_datasetCount( DatasetGroupH group );
105119

106-
//! Return dataset handle
107-
MDAL_EXPORT DatasetH MDAL_M_dataset( MeshH mesh, int index );
120+
//! Returns dataset handle
121+
MDAL_EXPORT DatasetH MDAL_G_dataset( DatasetGroupH group, int index );
122+
123+
//! Returns dataset handle for Maximums. Could be null for some formats
124+
MDAL_EXPORT DatasetH MDAL_G_maxiumumsDataset( DatasetGroupH group );
125+
126+
//! Returns number of metadata values
127+
MDAL_EXPORT int MDAL_G_metadataCount( DatasetGroupH group );
128+
129+
/**
130+
* Returns dataset metadata key
131+
* not thread-safe and valid only till next call
132+
*/
133+
MDAL_EXPORT const char *MDAL_G_metadataKey( DatasetGroupH group, int index );
134+
135+
/**
136+
* Returns dataset metadata value
137+
* not thread-safe and valid only till next call
138+
*/
139+
MDAL_EXPORT const char *MDAL_G_metadataValue( DatasetGroupH group, int index );
140+
141+
/**
142+
* Returns dataset group name
143+
* not thread-safe and valid only till next call
144+
*/
145+
MDAL_EXPORT const char *MDAL_G_name( DatasetGroupH group );
108146

109147
//! Whether dataset has scalar data associated
110-
MDAL_EXPORT bool MDAL_D_hasScalarData( DatasetH dataset );
148+
MDAL_EXPORT bool MDAL_G_hasScalarData( DatasetGroupH group );
111149

112150
//! Whether dataset is on vertices
113-
MDAL_EXPORT bool MDAL_D_isOnVertices( DatasetH dataset );
151+
MDAL_EXPORT bool MDAL_G_isOnVertices( DatasetGroupH group );
114152

115-
//! Return number of metadata values
116-
MDAL_EXPORT int MDAL_D_metadataCount( DatasetH dataset );
153+
///////////////////////////////////////////////////////////////////////////////////////
154+
/// DATASETS
155+
///////////////////////////////////////////////////////////////////////////////////////
117156

118-
//! Return dataset metadata key
119-
MDAL_EXPORT const char *MDAL_D_metadataKey( DatasetH dataset, int index );
157+
//! Returns dataset parent group
158+
MDAL_EXPORT DatasetGroupH MDAL_D_group( DatasetH dataset );
120159

121-
//! Return dataset metadata value
122-
MDAL_EXPORT const char *MDAL_D_metadataValue( DatasetH dataset, int index );
160+
//! Returns dataset time
161+
MDAL_EXPORT double MDAL_D_time( DatasetH dataset );
123162

124-
//! Return number of values
163+
//! Returns number of values
125164
MDAL_EXPORT int MDAL_D_valueCount( DatasetH dataset );
126165

127166
/**
128-
* Return scalar value associated with the index from the dataset
167+
* Returns scalar value associated with the index from the dataset
129168
* for nodata return numeric_limits<double>:quiet_NaN
130169
*/
131170
MDAL_EXPORT double MDAL_D_value( DatasetH dataset, int valueIndex );
132171

133172
/**
134-
* Return X value associated with the index from the vector dataset
173+
* Returns X value associated with the index from the vector dataset
135174
* for nodata return numeric_limits<double>:quiet_NaN
136175
*/
137176
MDAL_EXPORT double MDAL_D_valueX( DatasetH dataset, int valueIndex );
138177

139178
/**
140-
* Return Y value associated with the index from the vector dataset
179+
* Returns Y value associated with the index from the vector dataset
141180
* for nodata return numeric_limits<double>:quiet_NaN
142181
*/
143182
MDAL_EXPORT double MDAL_D_valueY( DatasetH dataset, int valueIndex );
@@ -148,7 +187,7 @@ MDAL_EXPORT double MDAL_D_valueY( DatasetH dataset, int valueIndex );
148187
*/
149188
MDAL_EXPORT bool MDAL_D_active( DatasetH dataset, int faceIndex );
150189

151-
//! Return whether dataset is valid
190+
//! Returns whether dataset is valid
152191
MDAL_EXPORT bool MDAL_D_isValid( DatasetH dataset );
153192

154193
#ifdef __cplusplus

external/mdal/frmts/mdal_2dm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <string>
1010
#include <memory>
1111

12-
#include "mdal_defines.hpp"
12+
#include "mdal_data_model.hpp"
1313
#include "mdal.h"
1414

1515
namespace MDAL

external/mdal/frmts/mdal_ascii_dat.cpp

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,38 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
5252
return;
5353
}
5454
line = trim( line );
55-
std::string basename = baseName( mDatFile );
5655

5756
// http://www.xmswiki.com/xms/SMS:ASCII_Dataset_Files_*.dat
5857
// Apart from the format specified above, there is an older supported format used in BASEMENT (and SMS?)
5958
// which is simpler (has only one dataset in one file, no status flags etc)
6059
bool oldFormat;
6160
bool isVector = false;
62-
bool readingDataset = false; // whether we are in process of reading the dataset
6361

64-
std::string baseDatasetName( basename );
65-
std::vector<std::shared_ptr<Dataset>> datOutputs; // DAT outputs data
62+
std::shared_ptr<DatasetGroup> group; // DAT outputs data
63+
std::string name( MDAL::baseName( mDatFile ) );
6664

6765
if ( line == "DATASET" )
6866
oldFormat = false;
6967
else if ( line == "SCALAR" || line == "VECTOR" )
7068
{
7169
oldFormat = true;
7270
isVector = ( line == "VECTOR" );
73-
baseDatasetName = basename;
74-
readingDataset = true;
71+
72+
group.reset( new DatasetGroup() );
73+
group->uri = mDatFile;
74+
group->setName( name );
75+
group->isScalar = !isVector;
7576
}
7677
else
7778
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
7879

79-
// see if it contains element-centered results - supported by BASEMENT
80-
bool elementCentered = false;
81-
if ( !oldFormat && contains( basename, "_els_" ) )
82-
elementCentered = true;
80+
// see if it contains face-centered results - supported by BASEMENT
81+
bool faceCentered = false;
82+
if ( !oldFormat && contains( name, "_els_" ) )
83+
faceCentered = true;
84+
85+
if ( group )
86+
group->isOnVertices = !faceCentered;
8387

8488
while ( std::getline( in, line ) )
8589
{
@@ -107,28 +111,32 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
107111
}
108112
else if ( !oldFormat && ( cardType == "BEGSCL" || cardType == "BEGVEC" ) )
109113
{
110-
if ( readingDataset )
114+
if ( group )
111115
{
112116
debug( "New dataset while previous one is still active!" );
113117
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
114118
}
115119
isVector = cardType == "BEGVEC";
116-
baseDatasetName = basename;
117-
readingDataset = true;
120+
121+
group.reset( new DatasetGroup() );
122+
group->uri = mDatFile;
123+
group->setName( name );
124+
group->isScalar = !isVector;
125+
group->isOnVertices = !faceCentered;
118126
}
119127
else if ( !oldFormat && cardType == "ENDDS" )
120128
{
121-
if ( !readingDataset )
129+
if ( !group )
122130
{
123131
debug( "ENDDS card for no active dataset!" );
124132
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
125133
}
126-
127-
addDatasets( mesh, baseDatasetName, datOutputs );
134+
mesh->datasetGroups.push_back( group );
135+
group.reset();
128136
}
129137
else if ( !oldFormat && cardType == "NAME" && items.size() >= 2 )
130138
{
131-
if ( !readingDataset )
139+
if ( !group )
132140
{
133141
debug( "NAME card for no active dataset!" );
134142
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
@@ -137,7 +145,7 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
137145
size_t quoteIdx1 = line.find( '\"' );
138146
size_t quoteIdx2 = line.find( '\"', quoteIdx1 + 1 );
139147
if ( quoteIdx1 != std::string::npos && quoteIdx2 != std::string::npos )
140-
baseDatasetName = line.substr( quoteIdx1 + 1, quoteIdx2 - quoteIdx1 - 1 );
148+
group->setName( line.substr( quoteIdx1 + 1, quoteIdx2 - quoteIdx1 - 1 ) );
141149
}
142150
else if ( oldFormat && ( cardType == "SCALAR" || cardType == "VECTOR" ) )
143151
{
@@ -147,14 +155,14 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
147155
{
148156
double t = toDouble( items[oldFormat ? 1 : 2] );
149157

150-
if ( elementCentered )
158+
if ( faceCentered )
151159
{
152-
readFaceTimestep( mesh, datOutputs, t, isVector, in );
160+
readFaceTimestep( mesh, group, t, isVector, in );
153161
}
154162
else
155163
{
156164
bool hasStatus = ( oldFormat ? false : toBool( items[1] ) );
157-
readVertexTimestep( mesh, datOutputs, t, isVector, hasStatus, in );
165+
readVertexTimestep( mesh, group, t, isVector, hasStatus, in );
158166
}
159167

160168
}
@@ -168,45 +176,32 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
168176

169177
if ( oldFormat )
170178
{
171-
if ( datOutputs.size() == 0 )
179+
if ( !group || group->datasets.size() == 0 )
172180
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
173181

174-
addDatasets( mesh, baseDatasetName, datOutputs );
182+
mesh->datasetGroups.push_back( group );
183+
group.reset();
175184
}
176185
}
177186

178-
void MDAL::LoaderAsciiDat::addDatasets( MDAL::Mesh *mesh,
179-
const std::string &name,
180-
const Datasets &datOutputs ) const
187+
void MDAL::LoaderAsciiDat::readVertexTimestep(
188+
const MDAL::Mesh *mesh,
189+
std::shared_ptr<DatasetGroup> group,
190+
double t,
191+
bool isVector,
192+
bool hasStatus,
193+
std::ifstream &stream )
181194
{
182-
for ( const std::shared_ptr<Dataset> &ds : datOutputs )
183-
{
184-
ds->uri = mDatFile;
185-
ds->setName( name );
186-
ds->isValid = true;
187-
}
188-
189-
//https://stackoverflow.com/a/2551785/2838364
190-
mesh->datasets.insert(
191-
mesh->datasets.end(),
192-
datOutputs.begin(),
193-
datOutputs.end()
194-
);
195-
}
195+
assert( group );
196196

197-
void MDAL::LoaderAsciiDat::readVertexTimestep( const MDAL::Mesh *mesh, Datasets &datOutputs,
198-
double t, bool isVector,
199-
bool hasStatus, std::ifstream &stream )
200-
{
201197
size_t vertexCount = mesh->vertices.size();
202198
size_t faceCount = mesh->faces.size();
203199

204200
std::shared_ptr<MDAL::Dataset> dataset( new MDAL::Dataset );
205-
dataset->isScalar = !isVector; //everything else to be set in addDatasets
206-
dataset->setMetadata( "time", std::to_string( t / 3600. ) );
201+
dataset->time = t / 3600.; // TODO read TIMEUNITS
207202
dataset->values.resize( vertexCount );
208203
dataset->active.resize( faceCount );
209-
dataset->isOnVertices = true;
204+
dataset->parent = group.get();
210205

211206
// only for new format
212207
for ( size_t i = 0; i < faceCount; ++i )
@@ -258,18 +253,24 @@ void MDAL::LoaderAsciiDat::readVertexTimestep( const MDAL::Mesh *mesh, Datasets
258253
}
259254
}
260255

261-
datOutputs.push_back( std::move( dataset ) );
256+
group->datasets.push_back( dataset );
262257
}
263258

264-
void MDAL::LoaderAsciiDat::readFaceTimestep( const MDAL::Mesh *mesh, Datasets &datOutputs, double t, bool isVector, std::ifstream &stream )
259+
void MDAL::LoaderAsciiDat::readFaceTimestep(
260+
const MDAL::Mesh *mesh,
261+
std::shared_ptr<DatasetGroup> group,
262+
double t,
263+
bool isVector,
264+
std::ifstream &stream )
265265
{
266+
assert( group );
267+
266268
size_t faceCount = mesh->faces.size();
267269

268270
std::shared_ptr<MDAL::Dataset> dataset( new MDAL::Dataset );
269-
dataset->isScalar = !isVector; //everything else to be set in addDatasets
270-
dataset->setMetadata( "time", std::to_string( t / 3600. ) );
271+
dataset->time = t / 3600.;
271272
dataset->values.resize( faceCount );
272-
dataset->isOnVertices = false;
273+
dataset->parent = group.get();
273274

274275
// TODO: hasStatus
275276
for ( size_t index = 0; index < faceCount; ++index )
@@ -303,5 +304,5 @@ void MDAL::LoaderAsciiDat::readFaceTimestep( const MDAL::Mesh *mesh, Datasets &d
303304
}
304305
}
305306

306-
datOutputs.push_back( std::move( dataset ) );
307+
group->datasets.push_back( dataset );
307308
}

0 commit comments

Comments
 (0)