Skip to content

Commit 1df077a

Browse files
authoredMay 27, 2020
MDAL update 0.6.0 (#36703)
MDAL update 0.6.0
1 parent 0ea7187 commit 1df077a

17 files changed

+412
-32
lines changed
 

‎external/mdal/cmake_templates/mdal_config.hpp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#cmakedefine HAVE_XML
1313

14+
#cmakedefine HAVE_SQLITE3
15+
1416
#endif // MDAL_CONFIG_HPP
1517

1618

‎external/mdal/frmts/mdal_3di.cpp

Lines changed: 197 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
*/
55

66
#include "mdal_3di.hpp"
7+
#include "mdal_logger.hpp"
8+
#include <cmath>
79
#include <netcdf.h>
810
#include <assert.h>
11+
#include "mdal_sqlite3.hpp"
12+
913

1014
MDAL::Driver3Di::Driver3Di()
1115
: DriverCF(
@@ -21,9 +25,49 @@ MDAL::Driver3Di *MDAL::Driver3Di::create()
2125
return new Driver3Di();
2226
}
2327

24-
MDAL::CFDimensions MDAL::Driver3Di::populateDimensions( )
28+
std::string MDAL::Driver3Di::buildUri( const std::string &meshFile )
2529
{
30+
mNcFile.reset( new NetCDFFile );
31+
32+
try
33+
{
34+
mNcFile->openFile( meshFile );
35+
}
36+
catch ( MDAL::Error &err )
37+
{
38+
err.setDriver( name() );
39+
MDAL::Log::error( err );
40+
return std::string();
41+
}
42+
43+
std::vector<std::string> meshNames;
44+
2645
CFDimensions dims;
46+
bool sqliteFileExist = check1DConnection( meshFile );
47+
if ( sqliteFileExist )
48+
{
49+
populate1DMeshDimensions( dims );
50+
if ( dims.size( CFDimensions::Vertex ) > 0 && dims.size( CFDimensions::Edge ) > 0 )
51+
{
52+
meshNames.push_back( "Mesh1D" );
53+
}
54+
}
55+
56+
populate2DMeshDimensions( dims );
57+
if ( dims.size( CFDimensions::Face ) > 0 )
58+
meshNames.push_back( "Mesh2D" );
59+
60+
if ( !meshNames.size() )
61+
{
62+
MDAL::Log::error( MDAL_Status::Err_UnknownFormat, name(), "No meshes found in file" + meshFile );
63+
return std::string( "" );
64+
}
65+
66+
return MDAL::buildAndMergeMeshUris( meshFile, meshNames, name() );
67+
}
68+
69+
void MDAL::Driver3Di::populate2DMeshDimensions( MDAL::CFDimensions &dims )
70+
{
2771
size_t count;
2872
int ncid;
2973

@@ -36,6 +80,23 @@ MDAL::CFDimensions MDAL::Driver3Di::populateDimensions( )
3680

3781
// Vertices count is populated later in populateElements
3882
// it is not known from the array dimensions
83+
}
84+
85+
MDAL::CFDimensions MDAL::Driver3Di::populateDimensions( )
86+
{
87+
CFDimensions dims;
88+
size_t count;
89+
int ncid;
90+
91+
if ( mRequestedMeshName == "Mesh1D" )
92+
{
93+
populate1DMeshDimensions( dims );
94+
}
95+
else
96+
{
97+
// Default loaded mesh is the 2D mesh
98+
populate2DMeshDimensions( dims );
99+
}
39100

40101
// Time
41102
mNcFile->getDimension( "time", &count, &ncid );
@@ -44,7 +105,15 @@ MDAL::CFDimensions MDAL::Driver3Di::populateDimensions( )
44105
return dims;
45106
}
46107

47-
void MDAL::Driver3Di::populateElements( Vertices &vertices, Edges &, Faces &faces )
108+
void MDAL::Driver3Di::populateElements( Vertices &vertices, Edges &edges, Faces &faces )
109+
{
110+
if ( mRequestedMeshName == "Mesh1D" )
111+
populateMesh1DElements( vertices, edges );
112+
else
113+
populateMesh2DElements( vertices, faces );
114+
}
115+
116+
void MDAL::Driver3Di::populateMesh2DElements( MDAL::Vertices &vertices, MDAL::Faces &faces )
48117
{
49118
assert( vertices.empty() );
50119
size_t faceCount = mDimensions.size( CFDimensions::Face );
@@ -259,3 +328,129 @@ std::vector<std::pair<double, double>> MDAL::Driver3Di::parseClassification( int
259328
MDAL_UNUSED( varid );
260329
return std::vector<std::pair<double, double>>();
261330
}
331+
332+
void MDAL::Driver3Di::populate1DMeshDimensions( MDAL::CFDimensions &dims )
333+
{
334+
size_t count;
335+
int ncid;
336+
337+
mNcFile->getDimension( "nMesh1D_nodes", &count, &ncid );
338+
dims.setDimension( CFDimensions::Vertex, count, ncid );
339+
340+
mNcFile->getDimension( "nMesh1D_lines", &count, &ncid );
341+
dims.setDimension( CFDimensions::Edge, count, ncid );
342+
}
343+
344+
void MDAL::Driver3Di::populateMesh1DElements( MDAL::Vertices &vertices, MDAL::Edges &edges )
345+
{
346+
assert( vertices.empty() && edges.empty() );
347+
size_t vertexCount = mDimensions.size( CFDimensions::Vertex );
348+
size_t edgesCount = mDimensions.size( CFDimensions::Edge );
349+
vertices.resize( vertexCount );
350+
edges.resize( edgesCount );
351+
352+
// X coordinate
353+
int ncidX = mNcFile->getVarId( "Mesh1DNode_xcc" );
354+
double fillX = mNcFile->getFillValue( ncidX );
355+
std::vector<double> verticesX( vertexCount );
356+
if ( nc_get_var_double( mNcFile->handle(), ncidX, verticesX.data() ) ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unknown format" );
357+
358+
// Y coordinate
359+
int ncidY = mNcFile->getVarId( "Mesh1DNode_ycc" );
360+
double fillY = mNcFile->getFillValue( ncidY );
361+
std::vector<double> verticesY( vertexCount );
362+
if ( nc_get_var_double( mNcFile->handle(), ncidY, verticesY.data() ) ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unknown format" );
363+
364+
// Z coordinate
365+
int ncidZ = mNcFile->getVarId( "Mesh1DNode_zcc" );
366+
double fillZ = mNcFile->getFillValue( ncidZ );
367+
std::vector<double> verticesZ( vertexCount );
368+
if ( nc_get_var_double( mNcFile->handle(), ncidZ, verticesZ.data() ) ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unknown format" );
369+
370+
// Node Id
371+
int ncidNodeId = mNcFile->getVarId( "Mesh1DNode_id" );
372+
std::vector<int> verticesId( vertexCount );
373+
if ( nc_get_var_int( mNcFile->handle(), ncidNodeId, verticesId.data() ) ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unknown format" );
374+
375+
// Edge Id
376+
int ncidEgeId = mNcFile->getVarId( "Mesh1DLine_id" );
377+
std::vector<int> edgesId( edgesCount );
378+
if ( nc_get_var_int( mNcFile->handle(), ncidEgeId, edgesId.data() ) ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unknown format" );
379+
380+
for ( size_t i = 0; i < vertexCount; ++i )
381+
{
382+
Vertex vertex;
383+
vertex.x = verticesX[i];
384+
if ( vertex.x == fillX )
385+
vertex.x = std::numeric_limits<double>::quiet_NaN();
386+
vertex.y = verticesY[i];
387+
if ( vertex.y == fillY )
388+
vertex.y = std::numeric_limits<double>::quiet_NaN();
389+
vertex.z = verticesZ[i];
390+
if ( vertex.z == fillZ )
391+
vertex.z = std::numeric_limits<double>::quiet_NaN();
392+
vertices[i] = vertex;
393+
}
394+
395+
parse1DConnection( verticesId, edgesId, edges );
396+
}
397+
398+
399+
bool MDAL::Driver3Di::check1DConnection( std::string fileName )
400+
{
401+
std::string sqliteFile = dirName( fileName ) + "/gridadmin.sqlite";
402+
403+
if ( !fileExists( sqliteFile ) )
404+
return false;
405+
406+
Sqlite3Db sqliteDb;
407+
return sqliteDb.open( sqliteFile );
408+
409+
}
410+
411+
void MDAL::Driver3Di::parse1DConnection( const std::vector<int> &nodesId,
412+
const std::vector<int> &edgesId,
413+
Edges &edges )
414+
{
415+
std::string sqliteFileName = dirName( mNcFile->getFileName() ) + "/gridadmin.sqlite";
416+
417+
//construct id map
418+
std::map<int, size_t> edgeMap;
419+
std::map<int, size_t> nodeMap;
420+
for ( size_t edgeIndex = 0; edgeIndex < edges.size(); ++edgeIndex )
421+
edgeMap[edgesId.at( edgeIndex )] = edgeIndex;
422+
423+
for ( size_t nodeIndex = 0; nodeIndex < nodesId.size(); ++nodeIndex )
424+
nodeMap[nodesId.at( nodeIndex )] = nodeIndex;
425+
426+
427+
Sqlite3Db db;
428+
if ( !db.open( sqliteFileName ) || !( db.get() ) )
429+
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unable to open sqlite database" );
430+
431+
Sqlite3Statement stmt;
432+
433+
if ( ! stmt.prepare( &db, "SELECT id, start_node_idx, end_node_idx FROM flowlines" ) )
434+
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unable to read edges connectivity from sqlite database" );
435+
436+
if ( stmt.columnCount() < 0 || stmt.columnCount() != 3 )
437+
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Invalid edges connectivity schema in sqlite database" );
438+
439+
while ( stmt.next() )
440+
{
441+
int idEdge, idStartNode, idEndNode;
442+
idEdge = stmt.getInt( 0 );
443+
idStartNode = stmt.getInt( 1 );
444+
idEndNode = stmt.getInt( 2 );
445+
446+
auto itEdge = edgeMap.find( idEdge );
447+
auto itStart = nodeMap.find( idStartNode );
448+
auto itEnd = nodeMap.find( idEndNode );
449+
450+
if ( itEdge != edgeMap.end() && itStart != nodeMap.end() && itEnd != nodeMap.end() )
451+
{
452+
edges[itEdge->second].startVertex = itStart->second;
453+
edges[itEdge->second].endVertex = itEnd->second;
454+
}
455+
}
456+
}

‎external/mdal/frmts/mdal_3di.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string>
1111
#include <stddef.h>
1212

13+
#include "mdal_config.hpp"
1314
#include "mdal_cf.hpp"
1415
#include "mdal_driver.hpp"
1516

@@ -42,10 +43,12 @@ namespace MDAL
4243
Driver3Di();
4344
~Driver3Di() override = default;
4445
Driver3Di *create() override;
45-
46+
std::string buildUri( const std::string &meshFile ) override;
4647
private:
4748
CFDimensions populateDimensions( ) override;
49+
void populate2DMeshDimensions( MDAL::CFDimensions &dims );
4850
void populateElements( Vertices &vertices, Edges &edges, Faces &faces ) override;
51+
void populateMesh2DElements( Vertices &vertices, Faces &faces );
4952
void addBedElevation( MemoryMesh *mesh ) override;
5053
std::string getCoordinateSystemVariableName() override;
5154
std::string getTimeVariableName() const override;
@@ -62,6 +65,11 @@ namespace MDAL
6265
size_t parse2DMesh();
6366

6467
void addBedElevationDatasetOnFaces();
68+
69+
void populate1DMeshDimensions( MDAL::CFDimensions &dims );
70+
void populateMesh1DElements( Vertices &vertices, Edges &edges );
71+
bool check1DConnection( std::string fileName );
72+
void parse1DConnection( const std::vector<int> &nodesId, const std::vector<int> &edgesId, Edges &edges );
6573
};
6674

6775
} // namespace MDAL

‎external/mdal/frmts/mdal_cf.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ MDAL::cfdataset_info_map MDAL::DriverCF::parseDatasetGroupInfo()
147147

148148
//construct classification metadata
149149
if ( isClassified && !is_vector )
150-
{
151-
152150
meta.push_back( metadataFromClassification( classes ) );
153-
}
151+
154152

155153
// Add dsinfo to the map
156154
auto it = dsinfo_map.find( vectorName );

‎external/mdal/frmts/mdal_hdf5.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ std::string HdfAttribute::readString() const
127127
return res;
128128
}
129129

130+
double HdfAttribute::readDouble() const
131+
{
132+
HdfDataType datatype( H5Aget_type( id() ) );
133+
double value;
134+
herr_t status = H5Aread( d->id, H5T_NATIVE_DOUBLE, &value );
135+
if ( status < 0 )
136+
{
137+
return std::numeric_limits<double>::quiet_NaN();
138+
}
139+
return value;
140+
}
141+
130142
void HdfAttribute::write( const std::string &value )
131143
{
132144
if ( !isValid() || !mType.isValid() )

‎external/mdal/frmts/mdal_hdf5.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class HdfAttribute
151151
hid_t id() const;
152152

153153
std::string readString() const;
154+
double readDouble() const;
154155

155156
void write( const std::string &value );
156157
void write( int value );

‎external/mdal/frmts/mdal_netcdf.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void NetCDFFile::openFile( const std::string &fileName )
3737
{
3838
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not open file " + fileName );
3939
}
40+
mFileName = fileName;
4041
}
4142

4243
std::vector<int> NetCDFFile::readIntArr( const std::string &name, size_t dim ) const
@@ -446,3 +447,8 @@ void NetCDFFile::putDataArrayInt( int varId, size_t line, size_t faceVerticesMax
446447
throw MDAL::Error( MDAL_Status::Err_FailToWriteToDisk, nc_strerror( res ) );
447448
}
448449
}
450+
451+
std::string NetCDFFile::getFileName() const
452+
{
453+
return mFileName;
454+
}

‎external/mdal/frmts/mdal_netcdf.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ class NetCDFFile
8686
void putDataDouble( int varId, const size_t index, const double value );
8787
void putDataArrayInt( int varId, size_t line, size_t faceVerticesMax, int *values );
8888

89+
std::string getFileName() const;
90+
8991
private:
9092
int mNcid; // C handle to the file
93+
std::string mFileName;
9194
};
9295

9396
#endif // MDAL_NETCDF_HPP

‎external/mdal/frmts/mdal_sqlite3.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
MDAL - Mesh Data Abstraction Library (MIT License)
3+
Copyright (C) 2020 Lutra Consulting Limited
4+
*/
5+
6+
#include "mdal_sqlite3.hpp"
7+
#include <sqlite3.h>
8+
9+
10+
Sqlite3Db::Sqlite3Db() = default;
11+
12+
Sqlite3Db::~Sqlite3Db()
13+
{
14+
close();
15+
}
16+
17+
bool Sqlite3Db::open( const std::string &fileName )
18+
{
19+
close();
20+
int rc = sqlite3_open( fileName.c_str(), &mDb );
21+
if ( rc )
22+
return false;
23+
else
24+
return true;
25+
}
26+
27+
void Sqlite3Db::close()
28+
{
29+
if ( mDb )
30+
{
31+
sqlite3_close( mDb );
32+
mDb = nullptr;
33+
}
34+
}
35+
36+
sqlite3 *Sqlite3Db::get()
37+
{
38+
return mDb;
39+
}
40+
41+
Sqlite3Statement::Sqlite3Statement() = default;
42+
43+
Sqlite3Statement::~Sqlite3Statement()
44+
{
45+
close();
46+
}
47+
48+
bool Sqlite3Statement::prepare( Sqlite3Db *db, const std::string &statementString )
49+
{
50+
return sqlite3_prepare_v2( db->get(), statementString.c_str(), -1, &mStatement, nullptr ) == SQLITE_OK;
51+
52+
}
53+
54+
void Sqlite3Statement::close()
55+
{
56+
if ( mStatement )
57+
{
58+
sqlite3_finalize( mStatement );
59+
mStatement = nullptr;
60+
}
61+
}
62+
63+
bool Sqlite3Statement::next()
64+
{
65+
return SQLITE_ROW == sqlite3_step( mStatement );
66+
}
67+
68+
int Sqlite3Statement::getInt( int column ) const
69+
{
70+
if ( mStatement )
71+
return sqlite3_column_int( mStatement, column );
72+
else
73+
return std::numeric_limits<int>::quiet_NaN();
74+
}
75+
76+
int Sqlite3Statement::columnCount() const
77+
{
78+
if ( mStatement )
79+
return sqlite3_column_count( mStatement );
80+
else
81+
return -1;
82+
}

‎external/mdal/frmts/mdal_sqlite3.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
MDAL - Mesh Data Abstraction Library (MIT License)
3+
Copyright (C) 2020 Lutra Consulting Limited
4+
*/
5+
6+
#ifndef MDAL_SQLITE3_HPP
7+
#define MDAL_SQLITE3_HPP
8+
9+
#include <string>
10+
/** A simple C++ wrapper around SQLITE3 library API */
11+
12+
#include <sqlite3.h>
13+
14+
#include "mdal_logger.hpp"
15+
16+
class Sqlite3Db
17+
{
18+
public:
19+
Sqlite3Db();
20+
~Sqlite3Db();
21+
22+
bool open( const std::string &fileName );
23+
void close();
24+
25+
sqlite3 *get();
26+
27+
private:
28+
sqlite3 *mDb = nullptr;
29+
};
30+
31+
class Sqlite3Statement
32+
{
33+
public:
34+
Sqlite3Statement();
35+
~Sqlite3Statement();
36+
37+
bool prepare( Sqlite3Db *db, const std::string &statementString );
38+
void close();
39+
40+
int columnCount() const;
41+
42+
bool next();
43+
44+
int getInt( int column ) const;
45+
46+
private:
47+
sqlite3_stmt *mStatement = nullptr;
48+
};
49+
50+
#endif // MDAL_SQLITE3_HPP

‎external/mdal/frmts/mdal_xmdf.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,29 +245,35 @@ std::shared_ptr<MDAL::DatasetGroup> MDAL::DriverXmdf::readXmdfGroupAsDatasetGrou
245245
return group;
246246
}
247247

248-
bool isVector = dimValues.size() == 3;
249-
250-
std::vector<double> times = dsTimes.readArrayDouble();
251-
std::string timeUnitString = rootGroup.attribute( "TimeUnits" ).readString();
252-
MDAL::RelativeTimestamp::Unit timeUnit = parseDurationTimeUnit( timeUnitString );
253-
HdfAttribute refTime = rootGroup.attribute( "Reftime" );
254-
if ( refTime.isValid() )
255-
{
256-
std::string referenceTimeJulianDay = rootGroup.attribute( "Reftime" ).readString();
257-
group->setReferenceTime( DateTime( MDAL::toDouble( referenceTimeJulianDay ), DateTime::JulianDay ) );
258-
}
259-
260248
// all fine, set group and return
261249
group = std::make_shared<MDAL::DatasetGroup>(
262250
name(),
263251
mMesh,
264252
mDatFile,
265253
groupName
266254
);
255+
bool isVector = dimValues.size() == 3;
267256
group->setIsScalar( !isVector );
268257
group->setDataLocation( MDAL_DataLocation::DataOnVertices );
258+
std::vector<double> times = dsTimes.readArrayDouble();
259+
std::string timeUnitString = rootGroup.attribute( "TimeUnits" ).readString();
260+
MDAL::RelativeTimestamp::Unit timeUnit = parseDurationTimeUnit( timeUnitString );
261+
HdfAttribute refTime = rootGroup.attribute( "Reftime" );
269262
group->setMetadata( "TIMEUNITS", timeUnitString );
270263

264+
if ( refTime.isValid() )
265+
{
266+
std::string referenceTimeJulianDay = rootGroup.attribute( "Reftime" ).readString();
267+
double refTime;
268+
if ( referenceTimeJulianDay.empty() )
269+
refTime = rootGroup.attribute( "Reftime" ).readDouble();
270+
else
271+
refTime = MDAL::toDouble( referenceTimeJulianDay );
272+
273+
if ( ! std::isnan( refTime ) )
274+
group->setReferenceTime( DateTime( refTime, DateTime::JulianDay ) );
275+
}
276+
271277
// lazy loading of min and max of the dataset group
272278
std::vector<float> mins = dsMins.readArray();
273279
std::vector<float> maxs = dsMaxs.readArray();

‎external/mdal/mdal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static const char *EMPTY_STR = "";
2121

2222
const char *MDAL_Version()
2323
{
24-
return "0.5.92";
24+
return "0.6.0";
2525
}
2626

2727
MDAL_Status MDAL_LastStatus()

‎external/mdal/mdal_driver_manager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#ifdef HAVE_NETCDF
2727
#include "frmts/mdal_ugrid.hpp"
28-
#include "frmts/mdal_3di.hpp"
2928
#include "frmts/mdal_sww.hpp"
3029
#include "frmts/mdal_tuflowfv.hpp"
3130
#endif
@@ -38,6 +37,10 @@
3837
#include "frmts/mdal_xdmf.hpp"
3938
#endif
4039

40+
#if defined HAVE_SQLITE3 && defined HAVE_NETCDF
41+
#include "frmts/mdal_3di.hpp"
42+
#endif
43+
4144
std::string MDAL::DriverManager::getUris( const std::string &file, const std::string &driverName ) const
4245
{
4346
if ( !MDAL::fileExists( file ) )
@@ -209,11 +212,14 @@ MDAL::DriverManager::DriverManager()
209212

210213
#ifdef HAVE_NETCDF
211214
mDrivers.push_back( std::make_shared<MDAL::DriverTuflowFV>() );
212-
mDrivers.push_back( std::make_shared<MDAL::Driver3Di>() );
213215
mDrivers.push_back( std::make_shared<MDAL::DriverSWW>() );
214216
mDrivers.push_back( std::make_shared<MDAL::DriverUgrid>() );
215217
#endif
216218

219+
#if defined HAVE_SQLITE3 && defined HAVE_NETCDF
220+
mDrivers.push_back( std::make_shared<MDAL::Driver3Di>() );
221+
#endif
222+
217223
#if defined HAVE_GDAL && defined HAVE_NETCDF
218224
mDrivers.push_back( std::make_shared<MDAL::DriverGdalNetCDF>() );
219225
#endif

‎external/mdal/mdal_memory_data_model.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ void MDAL::MemoryDataset2D::activateFaces( MDAL::MemoryMesh *mesh )
5252

5353
for ( unsigned int idx = 0; idx < nFaces; ++idx )
5454
{
55-
Face elem = mesh->faces.at( idx );
56-
for ( size_t i = 0; i < elem.size(); ++i )
55+
const Face &elem = mesh->faces.at( idx );
56+
const std::size_t elemSize = elem.size();
57+
for ( size_t i = 0; i < elemSize; ++i )
5758
{
5859
const size_t vertexIndex = elem[i];
5960
if ( isScalar )
@@ -267,8 +268,9 @@ size_t MDAL::MemoryMeshFaceIterator::next(
267268
if ( mLastFaceIndex + faceIndex >= maxFaces )
268269
break;
269270

270-
const Face f = mMemoryMesh->faces[mLastFaceIndex + faceIndex];
271-
for ( size_t faceVertexIndex = 0; faceVertexIndex < f.size(); ++faceVertexIndex )
271+
const Face &f = mMemoryMesh->faces[mLastFaceIndex + faceIndex];
272+
const std::size_t faceSize = f.size();
273+
for ( size_t faceVertexIndex = 0; faceVertexIndex < faceSize; ++faceVertexIndex )
272274
{
273275
assert( vertexIndex < vertexIndicesBufferLen );
274276
vertexIndicesBuffer[vertexIndex] = static_cast<int>( f[faceVertexIndex] );

‎external/mdal/mdal_utils.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <sstream>
1212
#include <math.h>
1313
#include <assert.h>
14-
#include <cmath>
1514
#include <string.h>
1615
#include <stdio.h>
1716
#include <ctime>
@@ -357,11 +356,6 @@ MDAL::BBox MDAL::computeExtent( const MDAL::Vertices &vertices )
357356
return b;
358357
}
359358

360-
bool MDAL::equals( double val1, double val2, double eps )
361-
{
362-
return fabs( val1 - val2 ) < eps;
363-
}
364-
365359
double MDAL::safeValue( double val, double nodata, double eps )
366360
{
367361
if ( std::isnan( val ) )

‎external/mdal/mdal_utils.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <limits>
1313
#include <sstream>
1414
#include <fstream>
15+
#include <cmath>
1516

1617
#include <algorithm>
1718

@@ -33,7 +34,10 @@ namespace MDAL
3334
bool isNativeLittleEndian();
3435

3536
// numbers
36-
bool equals( double val1, double val2, double eps = std::numeric_limits<double>::epsilon() );
37+
inline bool equals( double val1, double val2, double eps = std::numeric_limits<double>::epsilon() )
38+
{
39+
return fabs( val1 - val2 ) < eps;
40+
}
3741

3842
//! returns quiet_NaN if value equals nodata value, otherwise returns val itself
3943
double safeValue( double val, double nodata, double eps = std::numeric_limits<double>::epsilon() );

‎src/providers/mdal/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ IF (WITH_INTERNAL_MDAL)
7777
SET (HAVE_HDF5 TRUE)
7878
ENDIF(HDF5_FOUND)
7979

80+
IF(SQLITE3_FOUND AND NETCDF_FOUND)
81+
SET(MDAL_LIB_SRCS ${MDAL_LIB_SRCS}
82+
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_sqlite3.cpp
83+
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_3di.cpp
84+
)
85+
SET(MDAL_LIB_HDRS ${MDAL_LIB_HDRS}
86+
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_sqlite3.hpp
87+
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_3di.hpp
88+
)
89+
ENDIF(SQLITE3_FOUND AND NETCDF_FOUND)
90+
8091
IF(GDAL_FOUND)
8192
SET(MDAL_LIB_SRCS ${MDAL_LIB_SRCS}
8293
${CMAKE_SOURCE_DIR}/external/mdal/frmts/mdal_gdal.cpp

0 commit comments

Comments
 (0)
Please sign in to comment.