Skip to content
Permalink
Browse files
update MDAL 0.8.90 (#43987)
  • Loading branch information
PeterPetrik committed Jun 30, 2021
1 parent 8835b2d commit 6e83672b06c9f8d7c429974608a2272505f73e0b
@@ -111,6 +111,18 @@ MDAL_EXPORT const char *MDAL_Version();
*/
MDAL_EXPORT MDAL_Status MDAL_LastStatus();

/**
* Resets the last status message
* \since MDAL 0.9.0
*/
MDAL_EXPORT void MDAL_ResetStatus();

/*
* Sets the last status message
* \since MDAL 0.9.0
*/
MDAL_EXPORT void MDAL_SetStatus( MDAL_LogLevel Level, MDAL_Status status, const char *message );

/**
* Sets custom callback for logging output
*
@@ -171,6 +183,14 @@ MDAL_EXPORT bool MDAL_DR_writeDatasetsCapability( MDAL_DriverH driver, MDAL_Data
*/
MDAL_EXPORT const char *MDAL_DR_writeDatasetsSuffix( MDAL_DriverH driver );

/**
* Returns the file suffix used to save mesh frame on file
* not thread-safe and valid only till next call
*
* \since MDAL 0.9.0
*/
MDAL_EXPORT const char *MDAL_DR_saveMeshSuffix( MDAL_DriverH driver );

/**
* Returns whether driver has capability to save mesh
*/
@@ -327,6 +327,9 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
//check that we have distinct nodes
}

if ( edges.empty() && faces.empty() )
maxVerticesPerFace = 4; //to allow empty mesh that can have a least 4 vertices per face when writing in.

std::unique_ptr< Mesh2dm > mesh(
new Mesh2dm(
maxVerticesPerFace,
@@ -447,3 +450,8 @@ void MDAL::Driver2dm::save( const std::string &uri, MDAL::Mesh *mesh )

file.close();
}

std::string MDAL::Driver2dm::saveMeshOnFileSuffix() const
{
return "2dm";
}
@@ -89,6 +89,8 @@ namespace MDAL
std::unique_ptr< Mesh > load( const std::string &meshFile, const std::string &meshName = "" ) override;
void save( const std::string &uri, Mesh *mesh ) override;

std::string saveMeshOnFileSuffix() const override;

private:
std::string mMeshFile;
};
@@ -38,7 +38,11 @@ std::string MDAL::Driver::filters() const

std::string MDAL::Driver::writeDatasetOnFileSuffix() const
{
return std::string();
}

std::string MDAL::Driver::saveMeshOnFileSuffix() const
{
return std::string();
}

@@ -43,6 +43,7 @@ namespace MDAL
bool hasWriteDatasetCapability( MDAL_DataLocation location ) const;

virtual std::string writeDatasetOnFileSuffix() const;
virtual std::string saveMeshOnFileSuffix() const;

virtual bool canReadMesh( const std::string &uri );
virtual bool canReadDatasets( const std::string &uri );
@@ -1023,17 +1023,20 @@ void MDAL::DriverSelafin::save( const std::string &uri, MDAL::Mesh *mesh )
std::unique_ptr<MeshFaceIterator> faceIter = mesh->readFaces();
size_t count = 0;
writeInt( file, MDAL::toInt( facesCount * verticesPerFace * 4 ) );
do
if ( facesCount > 0 )
{
std::vector<int> inkle( bufferSize * verticesPerFace );
count = faceIter->next( bufferSize, faceOffsetBuffer.data(), bufferSize * verticesPerFace, inkle.data() );
inkle.resize( count * verticesPerFace );
for ( size_t i = 0; i < inkle.size(); ++i )
inkle[i]++;
do
{
std::vector<int> inkle( bufferSize * verticesPerFace );
count = faceIter->next( bufferSize, faceOffsetBuffer.data(), bufferSize * verticesPerFace, inkle.data() );
inkle.resize( count * verticesPerFace );
for ( size_t i = 0; i < inkle.size(); ++i )
inkle[i]++;

writeValueArray( file, inkle );
writeValueArray( file, inkle );
}
while ( count != 0 );
}
while ( count != 0 );
writeInt( file, MDAL::toInt( facesCount * verticesPerFace * 4 ) );

// IPOBO filled with 0
@@ -1050,6 +1053,11 @@ std::string MDAL::DriverSelafin::writeDatasetOnFileSuffix() const
return "slf";
}

std::string MDAL::DriverSelafin::saveMeshOnFileSuffix() const
{
return "slf";
}

// return false if fails
static void streamToStream( std::ostream &destination,
std::ifstream &source,
@@ -328,6 +328,7 @@ namespace MDAL
void save( const std::string &uri, Mesh *mesh ) override;

std::string writeDatasetOnFileSuffix() const override;
std::string saveMeshOnFileSuffix() const override;

private:
bool saveDatasetGroupOnFile( DatasetGroup *datasetGroup );
@@ -12,6 +12,9 @@
#include <algorithm>
#include <cmath>

#define FILL_COORDINATES_VALUE -999.0
#define FILL_FACE2D_VALUE -999

MDAL::DriverUgrid::DriverUgrid()
: DriverCF(
"Ugrid",
@@ -286,6 +289,18 @@ void MDAL::DriverUgrid::populateVertices( MDAL::Vertices &vertices )
verticesZ = mNcFile->readDoubleArr( nodeZVariableName(), vertexCount );
}

if ( verticesX.size() == 1 &&
verticesY.size() == 1 &&
verticesZ.size() == 1 &&
verticesX.at( 0 ) == FILL_COORDINATES_VALUE &&
verticesY.at( 0 ) == FILL_COORDINATES_VALUE &&
verticesZ.at( 0 ) == FILL_COORDINATES_VALUE )
{
vertexCount = 0;
vertices.clear();
}


for ( size_t i = 0; i < vertexCount; ++i, ++vertexPtr )
{
vertexPtr->x = verticesX[i];
@@ -361,6 +376,9 @@ void MDAL::DriverUgrid::populateFaces( MDAL::Faces &faces )
}
faces[i] = idxs;
}

if ( faces.size() == 1 && faces.at( 0 ).size() == 0 )
faces.clear();
}

void MDAL::DriverUgrid::addBedElevation( MDAL::MemoryMesh *mesh )
@@ -681,15 +699,21 @@ void MDAL::DriverUgrid::save( const std::string &uri, MDAL::Mesh *mesh )
}
}

std::string MDAL::DriverUgrid::saveMeshOnFileSuffix() const
{
return "nc";
}

void MDAL::DriverUgrid::writeVariables( MDAL::Mesh *mesh )
{
// Global dimensions
int dimNodeCountId = mNcFile->defineDimension( "nmesh2d_node", mesh->verticesCount() );
int dimFaceCountId = mNcFile->defineDimension( "nmesh2d_face", mesh->facesCount() );
;
int dimNodeCountId = mNcFile->defineDimension( "nmesh2d_node", mesh->verticesCount() == 0 ? 1 : mesh->verticesCount() ); //if no vertices, set 1 since 0==NC_UNLIMITED
int dimFaceCountId = mNcFile->defineDimension( "nmesh2d_face", mesh->facesCount() == 0 ? 1 : mesh->facesCount() ); //if no vertices, set 1 since 0==NC_UNLIMITED
mNcFile->defineDimension( "nmesh2d_edge", 1 ); // no data on edges, cannot be 0, since 0==NC_UNLIMITED
int dimTimeId = mNcFile->defineDimension( "time", NC_UNLIMITED );
int dimMaxNodesPerFaceId = mNcFile->defineDimension( "max_nmesh2d_face_nodes",
mesh->faceVerticesMaximumCount() );
mesh->faceVerticesMaximumCount() == 0 ? 1 : mesh->faceVerticesMaximumCount() ); //if 0, set 1 since 0==NC_UNLIMITED

// Mesh 2D Definition
int mesh2dId = mNcFile->defineVar( "mesh2d", NC_INT, 0, nullptr );
@@ -725,8 +749,7 @@ void MDAL::DriverUgrid::writeVariables( MDAL::Mesh *mesh )
mNcFile->putAttrStr( mesh2dNodeZId, "standard_name", "altitude" );
mNcFile->putAttrStr( mesh2dNodeZId, "long_name", "z-coordinate of mesh nodes" );
mNcFile->putAttrStr( mesh2dNodeZId, "grid_mapping", "projected_coordinate_system" );
double fillNodeZCoodVal = -999.0;
mNcFile->putAttrDouble( mesh2dNodeZId, "_FillValue", fillNodeZCoodVal );
mNcFile->putAttrDouble( mesh2dNodeZId, "_FillValue", FILL_COORDINATES_VALUE );

// Faces 2D Variable
int mesh2FaceNodesId_dimIds [] { dimFaceCountId, dimMaxNodesPerFaceId };
@@ -736,8 +759,7 @@ void MDAL::DriverUgrid::writeVariables( MDAL::Mesh *mesh )
mNcFile->putAttrStr( mesh2FaceNodesId, "location", "face" );
mNcFile->putAttrStr( mesh2FaceNodesId, "long_name", "Mapping from every face to its corner nodes (counterclockwise)" );
mNcFile->putAttrInt( mesh2FaceNodesId, "start_index", 0 );
int fillFace2DVertexValue = -999;
mNcFile->putAttrInt( mesh2FaceNodesId, "_FillValue", fillFace2DVertexValue );
mNcFile->putAttrInt( mesh2FaceNodesId, "_FillValue", FILL_FACE2D_VALUE );

// Projected Coordinate System
int pcsId = mNcFile->defineVar( "projected_coordinate_system", NC_INT, 0, nullptr );
@@ -778,6 +800,14 @@ void MDAL::DriverUgrid::writeVariables( MDAL::Mesh *mesh )
std::vector<double> verticesCoordinates( verticesCoordCount );
std::unique_ptr<MDAL::MeshVertexIterator> vertexIterator = mesh->readVertices();

if ( mesh->verticesCount() == 0 )
{
// if there is no vertices fill the first fake vertex, see global dimension
mNcFile->putDataDouble( mesh2dNodeXId, 0, FILL_COORDINATES_VALUE );
mNcFile->putDataDouble( mesh2dNodeYId, 0, FILL_COORDINATES_VALUE );
mNcFile->putDataDouble( mesh2dNodeZId, 0, FILL_COORDINATES_VALUE );
}
else
{
size_t vertexIndex = 0;
size_t vertexFileIndex = 0;
@@ -792,7 +822,7 @@ void MDAL::DriverUgrid::writeVariables( MDAL::Mesh *mesh )
mNcFile->putDataDouble( mesh2dNodeXId, vertexFileIndex, verticesCoordinates[3 * i] );
mNcFile->putDataDouble( mesh2dNodeYId, vertexFileIndex, verticesCoordinates[3 * i + 1] );
if ( std::isnan( verticesCoordinates[3 * i + 2] ) )
mNcFile->putDataDouble( mesh2dNodeZId, vertexFileIndex, fillNodeZCoodVal );
mNcFile->putDataDouble( mesh2dNodeZId, vertexFileIndex, FILL_COORDINATES_VALUE );
else
mNcFile->putDataDouble( mesh2dNodeZId, vertexFileIndex, verticesCoordinates[3 * i + 2] );
vertexFileIndex++;
@@ -812,33 +842,43 @@ void MDAL::DriverUgrid::writeVariables( MDAL::Mesh *mesh )
std::vector<int> vertexIndicesBuffer( vertexIndicesBufferLen );

size_t faceIndex = 0;
while ( faceIndex < facesCount )
{
size_t facesRead = faceIterator->next(
faceOffsetsBufferLen,
faceOffsetsBuffer.data(),
vertexIndicesBufferLen,
vertexIndicesBuffer.data() );
if ( facesRead == 0 )
break;

for ( size_t i = 0; i < facesRead; i++ )
if ( facesCount == 0 )
{
// if there is no vertices fill the first fake vertex, see global dimension
int fillValue = FILL_FACE2D_VALUE;
mNcFile->putDataArrayInt( 0, 0, 1, &fillValue );
}
else
{
while ( faceIndex < facesCount )
{
std::vector<int> verticesFaceData( faceVerticesMax, fillFace2DVertexValue );
int startIndex = 0;
if ( i > 0 )
startIndex = faceOffsetsBuffer[ i - 1 ];
int endIndex = faceOffsetsBuffer[ i ];

size_t k = 0;
for ( int j = startIndex; j < endIndex; ++j )
size_t facesRead = faceIterator->next(
faceOffsetsBufferLen,
faceOffsetsBuffer.data(),
vertexIndicesBufferLen,
vertexIndicesBuffer.data() );
if ( facesRead == 0 )
break;

for ( size_t i = 0; i < facesRead; i++ )
{
int vertexIndex = vertexIndicesBuffer[ static_cast<size_t>( j ) ];
verticesFaceData[k++] = vertexIndex;
std::vector<int> verticesFaceData( faceVerticesMax, FILL_FACE2D_VALUE );
int startIndex = 0;
if ( i > 0 )
startIndex = faceOffsetsBuffer[ i - 1 ];
int endIndex = faceOffsetsBuffer[ i ];

size_t k = 0;
for ( int j = startIndex; j < endIndex; ++j )
{
int vertexIndex = vertexIndicesBuffer[ static_cast<size_t>( j ) ];
verticesFaceData[k++] = vertexIndex;
}
mNcFile->putDataArrayInt( mesh2FaceNodesId, faceIndex + i, faceVerticesMax, verticesFaceData.data() );
}
mNcFile->putDataArrayInt( mesh2FaceNodesId, faceIndex + i, faceVerticesMax, verticesFaceData.data() );
faceIndex += facesRead;
}
faceIndex += facesRead;
}

// Time values (not implemented)
@@ -27,6 +27,7 @@ namespace MDAL
~DriverUgrid() override = default;
DriverUgrid *create() override;
void save( const std::string &uri, Mesh *mesh ) override;
std::string saveMeshOnFileSuffix() const override;

private:
std::string buildUri( const std::string &meshFile ) override;
@@ -21,14 +21,35 @@ static const char *EMPTY_STR = "";

const char *MDAL_Version()
{
return "0.8.1";
return "0.8.90";
}

MDAL_Status MDAL_LastStatus()
{
return MDAL::Log::getLastStatus();
}

MDAL_EXPORT void MDAL_ResetStatus()
{
return MDAL::Log::resetLastStatus();
}

MDAL_EXPORT void MDAL_SetStatus( MDAL_LogLevel level, MDAL_Status status, const char *message )
{
MDAL::Log::resetLastStatus();
switch ( level )
{
case MDAL_LogLevel::Error:
return MDAL::Log::error( status, message );
case MDAL_LogLevel::Warn:
return MDAL::Log::warning( status, message );
case MDAL_LogLevel::Info:
return MDAL::Log::info( message );
case MDAL_LogLevel::Debug:
return MDAL::Log::debug( message );
}
}

void MDAL_SetLoggerCallback( MDAL_LoggerCallback callback )
{
MDAL::Log::setLoggerCallback( callback );
@@ -194,6 +215,7 @@ const char *MDAL_MeshNames( const char *uri )

void MDAL_SaveMesh( MDAL_MeshH mesh, const char *meshFile, const char *driver )
{
MDAL::Log::resetLastStatus();
if ( !meshFile )
{
MDAL::Log::error( MDAL_Status::Err_FileNotFound, "Mesh file is not valid (null)" );
@@ -1215,6 +1237,18 @@ const char *MDAL_DR_writeDatasetsSuffix( MDAL_DriverH driver )
return _return_str( d->writeDatasetOnFileSuffix() );
}

const char *MDAL_DR_saveMeshSuffix( MDAL_DriverH driver )
{
if ( !driver )
{
MDAL::Log::error( MDAL_Status::Err_MissingDriver, "Driver is not valid (null)" );
return EMPTY_STR;
}

MDAL::Driver *d = static_cast< MDAL::Driver * >( driver );
return _return_str( d->saveMeshOnFileSuffix() );
}

MDAL_MeshH MDAL_CreateMesh( MDAL_DriverH driver )
{
if ( !driver )
@@ -1285,3 +1319,4 @@ void MDAL_M_setProjection( MDAL_MeshH mesh, const char *projection )

static_cast<MDAL::Mesh *>( mesh )->setSourceCrsFromWKT( std::string( projection ) );
}

@@ -196,7 +196,7 @@ namespace MDAL
Mesh *mParent = nullptr;
bool mIsScalar = true;
bool mIsPolar = false;
std::pair<double, double> mReferenceAngles = {-360, 0}; //default full rotation is negative to be consistent with usual geographical clockwise
std::pair<double, double> mReferenceAngles = { -360, 0}; //default full rotation is negative to be consistent with usual geographical clockwise
MDAL_DataLocation mDataLocation = MDAL_DataLocation::DataOnVertices;
std::string mUri; // file/uri from where it came
Statistics mStatistics;

0 comments on commit 6e83672

Please sign in to comment.