Skip to content

Commit

Permalink
update to MDAL 0.4.92, second beta release for QGIS 3.12. it speeds u…
Browse files Browse the repository at this point in the history
…p and optimize memory usage by allowing QGIS to check if driver/dataset uses active flag or not
  • Loading branch information
PeterPetrik committed Dec 12, 2019
1 parent a9826bb commit 4988468
Show file tree
Hide file tree
Showing 26 changed files with 721 additions and 320 deletions.
14 changes: 10 additions & 4 deletions external/mdal/api/mdal.h
Expand Up @@ -324,6 +324,9 @@ MDAL_EXPORT bool MDAL_G_hasScalarData( DatasetGroupH group );
//! Whether dataset is on vertices
MDAL_EXPORT MDAL_DataLocation MDAL_G_dataLocation( DatasetGroupH group );

//! Returns maximum number of vertical levels (for 3D meshes)
MDAL_EXPORT int MDAL_G_maximumVerticalLevelCount( DatasetGroupH group );

/**
* Returns the minimum and maximum values of the group
* Returns NaN on error
Expand All @@ -339,13 +342,15 @@ MDAL_EXPORT void MDAL_G_minimumMaximum( DatasetGroupH group, double *min, double
*
* Minimum and maximum dataset values are automatically calculated
*
* Only for 2D datasets
*
* \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.
* \param active if null pointer, MDAL_D_hasActiveFlagCapability returns false. 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,
Expand Down Expand Up @@ -399,18 +404,20 @@ MDAL_EXPORT int MDAL_D_valueCount( DatasetH dataset );
//! Returns whether dataset is valid
MDAL_EXPORT bool MDAL_D_isValid( DatasetH dataset );

//! Returns whether dataset supports active flag for dataset faces
MDAL_EXPORT bool MDAL_D_hasActiveFlagCapability( DatasetH dataset );

//! Data type to be returned by MDAL_D_data
enum MDAL_DataType
{
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)
ACTIVE_INTEGER, //!< Integer, active flag for dataset faces. Some formats support switching off the element for particular timestep (see MDAL_D_hasActiveFlagCapability)
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 @@ -431,7 +438,6 @@ enum MDAL_DataType
* 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
3 changes: 1 addition & 2 deletions external/mdal/frmts/mdal_3di.cpp
Expand Up @@ -140,10 +140,9 @@ void MDAL::Driver3Di::addBedElevation( MemoryMesh *mesh )

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 )
{
values[i] = MDAL::safeValue( coordZ[i], fillZ );
dataset->setScalarValue( i, MDAL::safeValue( coordZ[i], fillZ ) );
}
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
group->setStatistics( MDAL::calculateStatistics( group ) );
Expand Down
27 changes: 10 additions & 17 deletions external/mdal/frmts/mdal_ascii_dat.cpp
Expand Up @@ -338,26 +338,23 @@ void MDAL::DriverAsciiDat::readVertexTimestep(
size_t faceCount = mesh->facesCount();
size_t vertexCount = mesh->verticesCount();

std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MDAL::MemoryDataset2D >( group.get() );
std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MDAL::MemoryDataset2D >( group.get(), hasStatus );
dataset->setTime( t );

int *active = dataset->active();
// only for new format
for ( size_t i = 0; i < faceCount; ++i )
{
if ( hasStatus )
{
std::string line;
std::getline( stream, line );
active[i] = toBool( line );
dataset->setActive( i, toBool( line ) );
}
}

const Mesh2dm *m2dm = dynamic_cast<const Mesh2dm *>( mesh );
double *values = dataset->values();
size_t meshIdCount = maximumId( mesh ) + 1; // these are native format indexes (IDs). For formats without gaps it equals vertex array index


for ( size_t id = 0; id < meshIdCount; ++id )
{
std::string line;
Expand All @@ -376,8 +373,7 @@ void MDAL::DriverAsciiDat::readVertexTimestep(
{
if ( tsItems.size() >= 2 ) // BASEMENT files with vectors have 3 columns
{
values[2 * index] = toDouble( tsItems[0] );
values[2 * index + 1] = toDouble( tsItems[1] );
dataset->setVectorValue( index, toDouble( tsItems[0] ), toDouble( tsItems[1] ) );
}
else
{
Expand All @@ -387,7 +383,7 @@ void MDAL::DriverAsciiDat::readVertexTimestep(
else
{
if ( tsItems.size() >= 1 )
values[index] = toDouble( tsItems[0] );
dataset->setScalarValue( index, toDouble( tsItems[0] ) );
else
{
debug( "invalid timestep line" );
Expand All @@ -412,8 +408,6 @@ void MDAL::DriverAsciiDat::readFaceTimestep(

std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MDAL::MemoryDataset2D >( group.get() );
dataset->setTime( t );
double *values = dataset->values();
// TODO: hasStatus
for ( size_t index = 0; index < faceCount; ++index )
{
std::string line;
Expand All @@ -424,8 +418,7 @@ void MDAL::DriverAsciiDat::readFaceTimestep(
{
if ( tsItems.size() >= 2 ) // BASEMENT files with vectors have 3 columns
{
values[2 * index] = toDouble( tsItems[0] );
values[2 * index + 1] = toDouble( tsItems[1] );
dataset->setVectorValue( index, toDouble( tsItems[0] ), toDouble( tsItems[1] ) );
}
else
{
Expand All @@ -435,7 +428,7 @@ void MDAL::DriverAsciiDat::readFaceTimestep(
else
{
if ( tsItems.size() >= 1 )
values[index] = toDouble( tsItems[0] );
dataset->setScalarValue( index, toDouble( tsItems[0] ) ) ;
else
{
debug( "invalid timestep line" );
Expand Down Expand Up @@ -504,15 +497,15 @@ bool MDAL::DriverAsciiDat::persist( MDAL::DatasetGroup *group )
const std::shared_ptr<MDAL::MemoryDataset2D> dataset
= std::dynamic_pointer_cast<MDAL::MemoryDataset2D>( group->datasets[time_index] );

bool hasActiveStatus = isOnVertices && dataset->active();
bool hasActiveStatus = isOnVertices && dataset->supportsActiveFlag();
out << "TS " << hasActiveStatus << " " << std::to_string( dataset->time() ) << "\n";

if ( hasActiveStatus )
{
// Fill the active data
for ( size_t i = 0; i < elemCount; ++i )
{
int active = dataset->active()[i];
int active = dataset->active( i );
out << ( active == 1 ? true : false ) << "\n";
}
}
Expand All @@ -523,10 +516,10 @@ bool MDAL::DriverAsciiDat::persist( MDAL::DatasetGroup *group )
{
// Read values flags
if ( isScalar )
out << dataset->values()[i] << "\n";
out << dataset->scalarValue( i ) << "\n";
else
{
out << dataset->values()[2 * i] << " " << dataset->values()[2 * i + 1 ] << "\n";
out << dataset->valueX( i ) << " " << dataset->valueY( i ) << "\n";
}
}
}
Expand Down
34 changes: 16 additions & 18 deletions external/mdal/frmts/mdal_binary_dat.cpp
Expand Up @@ -311,23 +311,23 @@ void MDAL::DriverBinaryDat::load( const std::string &datFile, MDAL::Mesh *mesh,
}
}

bool MDAL::DriverBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
std::shared_ptr<DatasetGroup> groupMax,
double time,
bool hasStatus,
int sflg,
std::ifstream &in )
bool MDAL::DriverBinaryDat::readVertexTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
std::shared_ptr<DatasetGroup> groupMax,
double time,
bool hasStatus,
int sflg,
std::ifstream &in )
{
assert( group && groupMax && ( group->isScalar() == groupMax->isScalar() ) );
bool isScalar = group->isScalar();

size_t vertexCount = mesh->verticesCount();
size_t faceCount = mesh->facesCount();

std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MDAL::MemoryDataset2D >( group.get() );
std::shared_ptr<MDAL::MemoryDataset2D> dataset = std::make_shared< MDAL::MemoryDataset2D >( group.get(), hasStatus );

int *activeFlags = dataset->active();
bool active = true;
for ( size_t i = 0; i < faceCount; ++i )
{
Expand All @@ -337,10 +337,9 @@ bool MDAL::DriverBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh,
return true; //error

}
activeFlags[i] = active;
dataset->setActive( i, active );
}

double *values = dataset->values();
for ( size_t i = 0; i < vertexCount; ++i )
{
if ( !isScalar )
Expand All @@ -352,8 +351,7 @@ bool MDAL::DriverBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh,
if ( read( in, reinterpret_cast< char * >( &y ), 4 ) )
return true; //error

values[2 * i] = static_cast< double >( x );
values[2 * i + 1] = static_cast< double >( y );
dataset->setVectorValue( i, static_cast< double >( x ), static_cast< double >( y ) );
}
else
{
Expand All @@ -362,7 +360,7 @@ bool MDAL::DriverBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh,
if ( read( in, reinterpret_cast< char * >( &scalar ), 4 ) )
return true; //error

values[i] = static_cast< double >( scalar );
dataset->setScalarValue( i, static_cast< double >( scalar ) );
}
}

Expand Down Expand Up @@ -468,7 +466,7 @@ bool MDAL::DriverBinaryDat::persist( MDAL::DatasetGroup *group )
// Write status flags
for ( size_t i = 0; i < elemCount; i++ )
{
bool active = static_cast<bool>( dataset->active()[i] );
bool active = static_cast<bool>( dataset->active( i ) );
writeRawData( out, reinterpret_cast< const char * >( &active ), 1 );
}
}
Expand All @@ -478,14 +476,14 @@ bool MDAL::DriverBinaryDat::persist( MDAL::DatasetGroup *group )
// Read values flags
if ( !group->isScalar() )
{
float x = static_cast<float>( dataset->values()[2 * i] );
float y = static_cast<float>( dataset->values()[2 * i + 1 ] );
float x = static_cast<float>( dataset->valueX( i ) );
float y = static_cast<float>( dataset->valueY( i ) );
writeRawData( out, reinterpret_cast< const char * >( &x ), 4 );
writeRawData( out, reinterpret_cast< const char * >( &y ), 4 );
}
else
{
float val = static_cast<float>( dataset->values()[i] );
float val = static_cast<float>( dataset->scalarValue( i ) );
writeRawData( out, reinterpret_cast< const char * >( &val ), 4 );
}
}
Expand Down

0 comments on commit 4988468

Please sign in to comment.