Skip to content

Commit

Permalink
update MDAL to 0.4.91 (alpha release of 0.5.0 for QGIS 3.12) - stacke…
Browse files Browse the repository at this point in the history
…d meshes 3d
  • Loading branch information
PeterPetrik committed Dec 5, 2019
1 parent a30bda6 commit 8aa0c28
Show file tree
Hide file tree
Showing 46 changed files with 2,613 additions and 656 deletions.
63 changes: 48 additions & 15 deletions external/mdal/api/mdal.h
Expand Up @@ -6,12 +6,6 @@
#ifndef MDAL_H
#define MDAL_H

/**********************************************************************/
/**********************************************************************/
/* API is considered EXPERIMENTAL and can be changed without a notice */
/**********************************************************************/
/**********************************************************************/

#ifdef MDAL_STATIC
# define MDAL_EXPORT
#else
Expand Down Expand Up @@ -65,12 +59,28 @@ enum MDAL_Status
Warn_NodeNotUnique
};

/**
* Specifies where the data is defined
*/
enum MDAL_DataLocation
{
//! Unknown/Invalid location
DataInvalidLocation = 0,
//! Data is defined on vertices of 2D mesh
DataOnVertices2D,
//! Data is defined on face centres of 2D mesh
DataOnFaces2D,
//! Data is defined on volume centres of 3D mesh
DataOnVolumes3D
};

typedef void *MeshH;
typedef void *MeshVertexIteratorH;
typedef void *MeshFaceIteratorH;
typedef void *DatasetGroupH;
typedef void *DatasetH;
typedef void *DriverH;
typedef void *AveragingMethodH;

//! Returns MDAL version
MDAL_EXPORT const char *MDAL_Version();
Expand Down Expand Up @@ -104,10 +114,10 @@ MDAL_EXPORT DriverH MDAL_driverFromName( const char *name );
MDAL_EXPORT bool MDAL_DR_meshLoadCapability( DriverH driver );

//! Returns whether driver has capability to write/edit dataset (groups)
MDAL_EXPORT bool MDAL_DR_writeDatasetsCapability( DriverH driver );
MDAL_EXPORT bool MDAL_DR_writeDatasetsCapability( DriverH driver, MDAL_DataLocation location );

//! Returns whether driver has capability to save mesh
MDAL_EXPORT bool MDAL_DR_SaveMeshCapability( DriverH driver );
MDAL_EXPORT bool MDAL_DR_saveMeshCapability( DriverH driver );

/**
* Returns name of MDAL driver
Expand Down Expand Up @@ -188,14 +198,14 @@ MDAL_EXPORT DatasetGroupH MDAL_M_datasetGroup( MeshH mesh, int index );
* \param mesh mesh handle
* \param driver the driver to use for storing the data
* \param name dataset group name
* \param isOnVertices whether data is defined on vertices
* \param dataLocation location of data (face, vertex, volume)
* \param hasScalarData whether data is scalar (false = vector data)
* \param datasetGroupFile file to store the new dataset group
* \returns empty pointer if not possible to create group, otherwise handle to new group
*/
MDAL_EXPORT DatasetGroupH MDAL_M_addDatasetGroup( MeshH mesh,
const char *name,
bool isOnVertices,
MDAL_DataLocation dataLocation,
bool hasScalarData,
DriverH driver,
const char *datasetGroupFile );
Expand Down Expand Up @@ -312,7 +322,7 @@ MDAL_EXPORT const char *MDAL_G_driverName( DatasetGroupH group );
MDAL_EXPORT bool MDAL_G_hasScalarData( DatasetGroupH group );

//! Whether dataset is on vertices
MDAL_EXPORT bool MDAL_G_isOnVertices( DatasetGroupH group );
MDAL_EXPORT MDAL_DataLocation MDAL_G_dataLocation( DatasetGroupH group );

/**
* Returns the minimum and maximum values of the group
Expand Down Expand Up @@ -372,7 +382,18 @@ MDAL_EXPORT DatasetGroupH MDAL_D_group( DatasetH dataset );
//! Returns dataset time
MDAL_EXPORT double MDAL_D_time( DatasetH dataset );

//! Returns number of values
//! Returns volumes count for the mesh (for 3D meshes)
MDAL_EXPORT int MDAL_D_volumesCount( DatasetH dataset );

//! Returns maximum number of vertical levels (for 3D meshes)
MDAL_EXPORT int MDAL_D_maximumVerticalLevelCount( DatasetH dataset );

/**
* Returns number of values
* For dataset with data location DataOnVertices2D returns vertex count
* For dataset with data location DataOnFaces2D returns face count
* For dataset with data location DataOnVolumes3D returns volumes count
*/
MDAL_EXPORT int MDAL_D_valueCount( DatasetH dataset );

//! Returns whether dataset is valid
Expand All @@ -381,9 +402,15 @@ MDAL_EXPORT bool MDAL_D_isValid( DatasetH dataset );
//! Data type to be returned by MDAL_D_data
enum MDAL_DataType
{
SCALAR_DOUBLE, //!< Double value for scalar datasets
VECTOR_2D_DOUBLE, //!< Double, double value for vector datasets
ACTIVE_INTEGER //!< Integer, active flag for dataset faces. Some formats support switching off the element for particular timestep.
SCALAR_DOUBLE = 0, //!< Double value for scalar datasets (DataOnVertices2D or DataOnFaces2D)
VECTOR_2D_DOUBLE, //!< Double, double value for vector datasets (DataOnVertices2D or DataOnFaces2D)
ACTIVE_INTEGER, //!< Integer, active flag for dataset faces. Some formats support switching off the element for particular timestep (DataOnVertices2D or DataOnFaces2D)
VERTICAL_LEVEL_COUNT_INTEGER, //!< Number of vertical level for particular mesh's face in 3D Stacked Meshes (DataOnVolumes3D)
VERTICAL_LEVEL_DOUBLE, //!< Vertical level extrusion for particular mesh's face in 3D Stacked Meshes (DataOnVolumes3D)
FACE_INDEX_TO_VOLUME_INDEX_INTEGER, //!< The first index of 3D volume for particular mesh's face in 3D Stacked Meshes (DataOnVolumes3D)
SCALAR_VOLUMES_DOUBLE, //!< Double scalar values for volumes in 3D Stacked Meshes (DataOnVolumes3D)
VECTOR_2D_VOLUMES_DOUBLE, //!< Double, double value for volumes in 3D Stacked Meshes (DataOnVolumes3D)
ACTIVE_VOLUMES_INTEGER //!< Integer, active flag for dataset volumes. Some formats support switching off the element for particular timestep (DataOnVolumes3D)
};

/**
Expand All @@ -399,6 +426,12 @@ enum MDAL_DataType
* For VECTOR_2D_DOUBLE, the minimum size must be valuesCount * 2 * size_of(double).
* Values are returned as x1, y1, x2, y2, ..., xN, yN
* For ACTIVE_INTEGER, the minimum size must be valuesCount * size_of(int)
* For VERTICAL_LEVEL_COUNT_INTEGER, the minimum size must be faceCount * size_of(int)
* For VERTICAL_LEVEL_DOUBLE, the minimum size must be (faceCount + volumesCount) * size_of(double)
* For FACE_INDEX_TO_VOLUME_INDEX_INTEGER, the minimum size must be faceCount * size_of(int)
* For SCALAR_VOLUMES_DOUBLE, the minimum size must be volumesCount * size_of(double)
* For VECTOR_2D_VOLUMES_DOUBLE, the minimum size must be 2 * volumesCount * size_of(double)
* For ACTIVE_VOLUMES_INTEGER, , the minimum size must be volumesCount * size_of(int)
* \returns number of values written to buffer. If return value != count requested, see MDAL_LastStatus() for error type
*/
MDAL_EXPORT int MDAL_D_data( DatasetH dataset, int indexStart, int count, MDAL_DataType dataType, void *buffer );
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -94,7 +94,7 @@ MDAL::Driver2dm *MDAL::Driver2dm::create()

MDAL::Driver2dm::~Driver2dm() = default;

bool MDAL::Driver2dm::canRead( const std::string &uri )
bool MDAL::Driver2dm::canReadMesh( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::string line;
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_2dm.hpp
Expand Up @@ -86,7 +86,7 @@ namespace MDAL
int faceVerticesMaximumCount() const override
{return MAX_VERTICES_PER_FACE_2DM;}

bool canRead( const std::string &uri ) override;
bool canReadMesh( const std::string &uri ) override;
std::unique_ptr< Mesh > load( const std::string &meshFile, MDAL_Status *status ) override;
void save( const std::string &uri, Mesh *mesh, MDAL_Status *status ) override;

Expand Down
40 changes: 23 additions & 17 deletions external/mdal/frmts/mdal_3di.cpp
Expand Up @@ -11,7 +11,8 @@ MDAL::Driver3Di::Driver3Di()
: DriverCF(
"3Di",
"3Di Results",
"results_3di.nc" )
"results_3di.nc",
Capability::ReadMesh )
{
}

Expand All @@ -27,17 +28,17 @@ MDAL::CFDimensions MDAL::Driver3Di::populateDimensions( )
int ncid;

// 2D Mesh
mNcFile.getDimension( "nMesh2D_nodes", &count, &ncid );
mNcFile->getDimension( "nMesh2D_nodes", &count, &ncid );
dims.setDimension( CFDimensions::Face2D, count, ncid );

mNcFile.getDimension( "nCorner_Nodes", &count, &ncid );
mNcFile->getDimension( "nCorner_Nodes", &count, &ncid );
dims.setDimension( CFDimensions::MaxVerticesInFace, count, ncid );

// Vertices count is populated later in populateFacesAndVertices
// it is not known from the array dimensions

// Time
mNcFile.getDimension( "time", &count, &ncid );
mNcFile->getDimension( "time", &count, &ncid );
dims.setDimension( CFDimensions::Time, count, ncid );

return dims;
Expand All @@ -53,16 +54,16 @@ void MDAL::Driver3Di::populateFacesAndVertices( Vertices &vertices, Faces &faces
std::map<std::string, size_t> xyToVertex2DId;

// X coordinate
int ncidX = mNcFile.getVarId( "Mesh2DContour_x" );
double fillX = mNcFile.getFillValue( ncidX );
int ncidX = mNcFile->getVarId( "Mesh2DContour_x" );
double fillX = mNcFile->getFillValue( ncidX );
std::vector<double> faceVerticesX( arrsize );
if ( nc_get_var_double( mNcFile.handle(), ncidX, faceVerticesX.data() ) ) throw MDAL_Status::Err_UnknownFormat;
if ( nc_get_var_double( mNcFile->handle(), ncidX, faceVerticesX.data() ) ) throw MDAL_Status::Err_UnknownFormat;

// Y coordinate
int ncidY = mNcFile.getVarId( "Mesh2DContour_y" );
double fillY = mNcFile.getFillValue( ncidY );
int ncidY = mNcFile->getVarId( "Mesh2DContour_y" );
double fillY = mNcFile->getFillValue( ncidY );
std::vector<double> faceVerticesY( arrsize );
if ( nc_get_var_double( mNcFile.handle(), ncidY, faceVerticesY.data() ) ) throw MDAL_Status::Err_UnknownFormat;
if ( nc_get_var_double( mNcFile->handle(), ncidY, faceVerticesY.data() ) ) throw MDAL_Status::Err_UnknownFormat;

// now populate create faces and backtrack which vertices
// are used in multiple faces
Expand Down Expand Up @@ -120,10 +121,10 @@ void MDAL::Driver3Di::addBedElevation( MemoryMesh *mesh )
size_t faceCount = mesh->facesCount();

// read Z coordinate of 3di computation nodes centers
int ncidZ = mNcFile.getVarId( "Mesh2DFace_zcc" );
double fillZ = mNcFile.getFillValue( ncidZ );
int ncidZ = mNcFile->getVarId( "Mesh2DFace_zcc" );
double fillZ = mNcFile->getFillValue( ncidZ );
std::vector<double> coordZ( faceCount );
if ( nc_get_var_double( mNcFile.handle(), ncidZ, coordZ.data() ) )
if ( nc_get_var_double( mNcFile->handle(), ncidZ, coordZ.data() ) )
return; //error reading the array


Expand All @@ -134,10 +135,10 @@ void MDAL::Driver3Di::addBedElevation( MemoryMesh *mesh )
"Bed Elevation"
);

group->setIsOnVertices( false );
group->setDataLocation( MDAL_DataLocation::DataOnFaces2D );
group->setIsScalar( true );

std::shared_ptr<MDAL::MemoryDataset> dataset = std::make_shared< MemoryDataset >( group.get() );
std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MemoryDataset2D >( group.get() );
dataset->setTime( 0.0 );
double *values = dataset->values();
for ( size_t i = 0; i < faceCount; ++i )
Expand All @@ -155,6 +156,11 @@ std::string MDAL::Driver3Di::getCoordinateSystemVariableName()
return "projected_coordinate_system";
}

std::string MDAL::Driver3Di::getTimeVariableName() const
{
return "time";
}

std::set<std::string> MDAL::Driver3Di::ignoreNetCDFVariables()
{
std::set<std::string> ignore_variables;
Expand Down Expand Up @@ -194,10 +200,10 @@ void MDAL::Driver3Di::parseNetCDFVariableMetadata( int varid, const std::string
*is_vector = false;
*is_x = true;

std::string long_name = mNcFile.getAttrStr( "long_name", varid );
std::string long_name = mNcFile->getAttrStr( "long_name", varid );
if ( long_name.empty() )
{
std::string standard_name = mNcFile.getAttrStr( "standard_name", varid );
std::string standard_name = mNcFile->getAttrStr( "standard_name", varid );
if ( standard_name.empty() )
{
name = variableName;
Expand Down
1 change: 1 addition & 0 deletions external/mdal/frmts/mdal_3di.hpp
Expand Up @@ -48,6 +48,7 @@ namespace MDAL
void populateFacesAndVertices( Vertices &vertices, Faces &faces ) override;
void addBedElevation( MemoryMesh *mesh ) override;
std::string getCoordinateSystemVariableName() override;
std::string getTimeVariableName() const override;
std::set<std::string> ignoreNetCDFVariables() override;
void parseNetCDFVariableMetadata( int varid, const std::string &variableName,
std::string &name, bool *is_vector, bool *is_x ) override;
Expand Down

0 comments on commit 8aa0c28

Please sign in to comment.