Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update to MDAL 0.1.3 (mesh calculator API)
  • Loading branch information
PeterPetrik committed Jan 14, 2019
1 parent 3cb7e31 commit e163caf
Show file tree
Hide file tree
Showing 24 changed files with 666 additions and 75 deletions.
88 changes: 86 additions & 2 deletions external/mdal/api/mdal.h
Expand Up @@ -55,6 +55,7 @@ enum MDAL_Status
Err_IncompatibleDataset,
Err_IncompatibleDatasetGroup,
Err_MissingDriver,
Err_MissingDriverCapability,
// Warnings
Warn_UnsupportedElement,
Warn_InvalidElements,
Expand Down Expand Up @@ -101,6 +102,9 @@ 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 );

/**
* Returns name of MDAL driver
* not thread-safe and valid only till next call
Expand Down Expand Up @@ -163,6 +167,37 @@ MDAL_EXPORT int MDAL_M_datasetGroupCount( MeshH mesh );
//! Returns dataset group handle
MDAL_EXPORT DatasetGroupH MDAL_M_datasetGroup( MeshH mesh, int index );

/**
* Adds empty (new) dataset group to the mesh
* This increases dataset group count MDAL_M_datasetGroupCount() by 1
*
* The Dataset Group is opened in edit mode.
* To persist dataset group, call MDAL_G_closeEditMode();
*
* It is not possible to read and write to the same group
* at the same time. Finalize edits before reading.
*
* \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 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,
bool hasScalarData,
DriverH driver,
const char *datasetGroupFile );

/**
* Returns name of MDAL driver
* not thread-safe and valid only till next call
*/
MDAL_EXPORT const char *MDAL_M_driverName( MeshH mesh );

///////////////////////////////////////////////////////////////////////////////////////
/// MESH VERTICES
///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -247,24 +282,73 @@ MDAL_EXPORT const char *MDAL_G_metadataKey( DatasetGroupH group, int index );
*/
MDAL_EXPORT const char *MDAL_G_metadataValue( DatasetGroupH group, int index );

/**
* Adds new metadata to the group
* Group must be in edit mode MDAL_G_isInEditMode()
*/
MDAL_EXPORT void MDAL_G_setMetadata( DatasetGroupH group, const char *key, const char *val );

/**
* Returns dataset group name
* not thread-safe and valid only till next call
*/
MDAL_EXPORT const char *MDAL_G_name( DatasetGroupH group );

/**
* Returns name of MDAL driver
* not thread-safe and valid only till next call
*/
MDAL_EXPORT const char *MDAL_G_driverName( DatasetGroupH group );

//! Whether dataset has scalar data associated
MDAL_EXPORT bool MDAL_G_hasScalarData( DatasetGroupH group );

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

/**
* Returns the min and max values of the group
* Returns the minimum and maximum values of the group
* Returns NaN on error
*/
MDAL_EXPORT void MDAL_G_minimumMaximum( DatasetGroupH group, double *min, double *max );

/**
* Adds empty (new) dataset to the group
* This increases dataset group count MDAL_G_datasetCount() by 1
*
* The dataset is opened in edit mode.
* To persist dataset, call MDAL_G_closeEditMode() on parent group
*
* Minimum and maximum dataset values are automatically calculated
*
* \param group parent group handle
* \param time time for dataset
* \param values For scalar data on vertices, the size must be vertex count
* For scalar data on faces, the size must be faces count
* For vector data on vertices, the size must be vertex count * 2 (x1, y1, x2, y2, ..., xN, yN)
* For vector data on faces, the size must be faces count * 2 (x1, y1, x2, y2, ..., xN, yN)
* \param active if null pointer, all faces are active. Otherwise size must be equal to face count.
* \returns empty pointer if not possible to create dataset (e.g. group opened in read mode), otherwise handle to new dataset
*/
MDAL_EXPORT DatasetH MDAL_G_addDataset( DatasetGroupH group,
double time,
const double *values,
const int *active
);

//! Returns whether dataset group is in edit mode
MDAL_EXPORT bool MDAL_G_isInEditMode( DatasetGroupH group );

/**
* Close edit mode for group and all its datasets.
* This may effectively write the data to the files and/or
* reopen the file in read-only mode
*
* When closed, minimum and maximum dataset group values are automatically calculated
*/
MDAL_EXPORT void MDAL_G_closeEditMode( DatasetGroupH group );


///////////////////////////////////////////////////////////////////////////////////////
/// DATASETS
///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -307,7 +391,7 @@ enum MDAL_DataType
MDAL_EXPORT int MDAL_D_data( DatasetH dataset, int indexStart, int count, MDAL_DataType dataType, void *buffer );

/**
* Returns the min and max values of the dataset
* Returns the minimum and maximum values of the dataset
* Returns NaN on error
*/
MDAL_EXPORT void MDAL_D_minimumMaximum( DatasetH dataset, double *min, double *max );
Expand Down
13 changes: 10 additions & 3 deletions external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -17,13 +17,20 @@
#include "mdal.h"
#include "mdal_utils.hpp"

#define DRIVER_NAME "2DM"

MDAL::Mesh2dm::Mesh2dm( size_t verticesCount,
size_t facesCount,
size_t faceVerticesMaximumCount,
MDAL::BBox extent,
const std::string &uri,
const std::map<size_t, size_t> vertexIDtoIndex )
: MemoryMesh( verticesCount, facesCount, faceVerticesMaximumCount, extent, uri )
: MemoryMesh( DRIVER_NAME,
verticesCount,
facesCount,
faceVerticesMaximumCount,
extent,
uri )
, mVertexIDtoIndex( vertexIDtoIndex )
{
}
Expand Down Expand Up @@ -58,10 +65,10 @@ size_t MDAL::Mesh2dm::vertexIndex( size_t vertexID ) const


MDAL::Driver2dm::Driver2dm():
Driver( "2DM",
Driver( DRIVER_NAME,
"2DM Mesh File",
"*.2dm",
DriverType::CanReadMeshAndDatasets
Capability::ReadMesh
)
{
}
Expand Down
1 change: 1 addition & 0 deletions external/mdal/frmts/mdal_3di.cpp
Expand Up @@ -126,6 +126,7 @@ void MDAL::Driver3Di::addBedElevation( MDAL::Mesh *mesh )


std::shared_ptr<DatasetGroup> group = std::make_shared< DatasetGroup >(
name(),
mesh,
mesh->uri(),
"Bed Elevation"
Expand Down
12 changes: 7 additions & 5 deletions external/mdal/frmts/mdal_ascii_dat.cpp
Expand Up @@ -27,7 +27,7 @@ MDAL::DriverAsciiDat::DriverAsciiDat( ):
Driver( "ASCII_DAT",
"DAT",
"*.dat",
DriverType::CanReadOnlyDatasets
Capability::ReadDatasets
)
{
}
Expand Down Expand Up @@ -93,7 +93,7 @@ void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh, M
bool isVector = false;

std::shared_ptr<DatasetGroup> group; // DAT outputs data
std::string name( MDAL::baseName( mDatFile ) );
std::string groupName( MDAL::baseName( mDatFile ) );

if ( line == "DATASET" )
oldFormat = false;
Expand All @@ -103,9 +103,10 @@ void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh, M
isVector = ( line == "VECTOR" );

group = std::make_shared< DatasetGroup >(
name(),
mesh,
mDatFile,
name
groupName
);
group->setIsScalar( !isVector );
}
Expand All @@ -114,7 +115,7 @@ void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh, M

// see if it contains face-centered results - supported by BASEMENT
bool faceCentered = false;
if ( !oldFormat && contains( name, "_els_" ) )
if ( !oldFormat && contains( groupName, "_els_" ) )
faceCentered = true;

if ( group )
Expand Down Expand Up @@ -158,9 +159,10 @@ void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh, M
isVector = cardType == "BEGVEC";

group = std::make_shared< DatasetGroup >(
name(),
mesh,
mDatFile,
name
groupName
);
group->setIsScalar( !isVector );
group->setIsOnVertices( !faceCentered );
Expand Down

0 comments on commit e163caf

Please sign in to comment.