Skip to content
Permalink
Browse files

update MDAL to 0.0.6

  • Loading branch information
PeterPetrik authored and nyalldawson committed Aug 29, 2018
1 parent f0ede77 commit 99a6f12ba3de7ff753179f708ac120bc70069cbd
@@ -89,6 +89,8 @@ MDAL_EXPORT int MDAL_M_vertexCount( MeshH mesh );
MDAL_EXPORT double MDAL_M_vertexXCoordinatesAt( MeshH mesh, int index );
//! Returns vertex Y coord for the mesh
MDAL_EXPORT double MDAL_M_vertexYCoordinatesAt( MeshH mesh, int index );
//! Returns vertex Z coord for the mesh
MDAL_EXPORT double MDAL_M_vertexZCoordinatesAt( MeshH mesh, int index );
//! Returns face count for the mesh
MDAL_EXPORT int MDAL_M_faceCount( MeshH mesh );
//! Returns number of vertices face consist of, e.g. 3 for triangle
@@ -120,9 +122,6 @@ MDAL_EXPORT int MDAL_G_datasetCount( DatasetGroupH group );
//! Returns dataset handle
MDAL_EXPORT DatasetH MDAL_G_dataset( DatasetGroupH group, int index );

//! Returns dataset handle for Maximums. Could be null for some formats
MDAL_EXPORT DatasetH MDAL_G_maxiumumsDataset( DatasetGroupH group );

//! Returns number of metadata values
MDAL_EXPORT int MDAL_G_metadataCount( DatasetGroupH group );

@@ -161,7 +161,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader2dm::load( MDAL_Status *status )
Vertex &vertex = vertices[vertexIndex];
vertex.x = toDouble( chunks[2] );
vertex.y = toDouble( chunks[3] );

vertex.z = toDouble( chunks[4] );
vertexIndex++;
}
}
@@ -196,6 +196,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader2dm::load( MDAL_Status *status )
mesh->vertices = vertices;
mesh->faceIDtoIndex = faceIDtoIndex;
mesh->vertexIDtoIndex = vertexIDtoIndex;
mesh->addBedElevationDataset();

return mesh;
}
@@ -129,6 +129,12 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
group->uri = mDatFile;
group->isOnVertices = true;

// in TUFLOW results there could be also a special timestep (99999) with maximums
// we will put it into a separate dataset
std::shared_ptr<DatasetGroup> groupMax( new DatasetGroup() );
groupMax->uri = mDatFile;
groupMax->isOnVertices = true;

while ( card != CT_ENDDS )
{
if ( read( in, reinterpret_cast< char * >( &card ), 4 ) )
@@ -161,10 +167,12 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )

case CT_BEGSCL:
group->isScalar = true;
groupMax->isScalar = true;
break;

case CT_BEGVEC:
group->isScalar = false;
groupMax->isScalar = false;
break;

case CT_VECTYPE:
@@ -202,6 +210,7 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
if ( name[39] != 0 )
name[39] = 0;
group->setName( trim( std::string( name ) ) );
groupMax->setName( group->name() + "/Maximums" );
break;

case CT_TS:
@@ -213,7 +222,7 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

double t = static_cast<double>( time );
if ( readVertexTimestep( mesh, group, t, istat, sflg, in ) )
if ( readVertexTimestep( mesh, group, groupMax, t, istat, sflg, in ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

break;
@@ -226,14 +235,17 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
mesh->datasetGroups.push_back( group );
}

bool MDAL::LoaderBinaryDat::readVertexTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
double time,
bool hasStatus,
int sflg,
std::ifstream &in )
bool MDAL::LoaderBinaryDat::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->vertices.size();
size_t faceCount = mesh->faces.size();

@@ -256,7 +268,7 @@ bool MDAL::LoaderBinaryDat::readVertexTimestep(

for ( size_t i = 0; i < vertexCount; ++i )
{
if ( !group->isScalar )
if ( !isScalar )
{
float x, y;

@@ -282,11 +294,11 @@ bool MDAL::LoaderBinaryDat::readVertexTimestep(
if ( MDAL::equals( time, 99999.0 ) ) // Special TUFLOW dataset with maximus
{
dataset->time = time;
group->maximumDataset = dataset;
groupMax->datasets.push_back( dataset );
}
else
{
dataset->time = time / 3600.0; // TODO read TIMEUNITS
dataset->time = time; // TODO read TIMEUNITS
group->datasets.push_back( dataset );
}
return false; //OK
@@ -28,6 +28,7 @@ namespace MDAL
private:
bool readVertexTimestep( const Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
std::shared_ptr<DatasetGroup> groupMax,
double time,
bool hasStatus,
int sflg,
@@ -83,6 +83,7 @@ bool MDAL::LoaderGdal::initVertices( Vertices &vertices )
// VertexsPtr->setId(x + mXSize*y);
VertexsPtr->x = mGT[0] + ( x + 0.5 ) * mGT[1] + ( y + 0.5 ) * mGT[2];
VertexsPtr->y = mGT[3] + ( x + 0.5 ) * mGT[4] + ( y + 0.5 ) * mGT[5];
VertexsPtr->z = 0.0;
}
}

@@ -69,23 +69,7 @@ void MDAL::LoaderXmdf::load( MDAL::Mesh *mesh, MDAL_Status *status )
if ( maxGroup->datasets.size() != 1 )
MDAL::debug( "Maximum dataset should have just one timestep!" );
else
{
bool found = false;
for ( const std::shared_ptr<MDAL::DatasetGroup> grp : groups )
{
if ( grp->name() == name )
{
grp->maximumDataset = maxGroup->datasets.at( 0 );
found = true;
break;
}
}

if ( !found )
{
MDAL::debug( "Unable to find base dataset for maximum dataset" );
}
}
groups.push_back( maxGroup );
}
}

@@ -168,7 +152,7 @@ std::shared_ptr<MDAL::DatasetGroup> MDAL::LoaderXmdf::readXmdfGroupAsDatasetGrou
dataset->values.resize( vertexCount );
dataset->active.resize( faceCount );
dataset->parent = group.get();
dataset->time = double( times[i] ) / 3600.0;
dataset->time = double( times[i] );

if ( isVector )
{
@@ -18,7 +18,7 @@ static MDAL_Status sLastStatus;

const char *MDAL_Version()
{
return "0.0.5";
return "0.0.6";
}

MDAL_Status MDAL_LastStatus()
@@ -119,6 +119,28 @@ double MDAL_M_vertexYCoordinatesAt( MeshH mesh, int index )
return m->vertices[i].y;
}

double MDAL_M_vertexZCoordinatesAt( MeshH mesh, int index )
{
if ( !mesh )
{
sLastStatus = MDAL_Status::Err_IncompatibleMesh;
return NODATA;
}
MDAL::Mesh *m = static_cast< MDAL::Mesh * >( mesh );
if ( index < 0 )
{
sLastStatus = MDAL_Status::Err_IncompatibleMesh;
return NODATA;
}
size_t i = static_cast<size_t>( index );
if ( m->vertices.size() <= i )
{
sLastStatus = MDAL_Status::Err_IncompatibleMesh;
return NODATA;
}
return m->vertices[i].z;
}

int MDAL_M_faceCount( MeshH mesh )
{
if ( !mesh )
@@ -227,6 +249,13 @@ DatasetGroupH MDAL_M_datasetGroup( MeshH mesh, int index )
sLastStatus = MDAL_Status::Err_IncompatibleMesh;
return nullptr;
}

if ( index < 0 )
{
sLastStatus = MDAL_Status::Err_IncompatibleMesh;
return nullptr;
}

MDAL::Mesh *m = static_cast< MDAL::Mesh * >( mesh );
int len = static_cast<int>( m->datasetGroups.size() );
if ( len <= index )
@@ -262,26 +291,22 @@ DatasetH MDAL_G_dataset( DatasetGroupH group, int index )
sLastStatus = MDAL_Status::Err_IncompatibleDatasetGroup;
return nullptr;
}
MDAL::DatasetGroup *g = static_cast< MDAL::DatasetGroup * >( group );
int len = static_cast<int>( g->datasets.size() );
if ( len <= index )

if ( index < 0 )
{
sLastStatus = MDAL_Status::Err_IncompatibleDatasetGroup;
return nullptr;
}
size_t i = static_cast<size_t>( index );
return static_cast< DatasetH >( g->datasets[i].get() );
}

DatasetH MDAL_G_maxiumumsDataset( DatasetGroupH group )
{
if ( !group )
MDAL::DatasetGroup *g = static_cast< MDAL::DatasetGroup * >( group );
int len = static_cast<int>( g->datasets.size() );
if ( len <= index )
{
sLastStatus = MDAL_Status::Err_IncompatibleDatasetGroup;
return nullptr;
}
MDAL::DatasetGroup *g = static_cast< MDAL::DatasetGroup * >( group );
return static_cast< DatasetH >( g->maximumDataset.get() );
size_t i = static_cast<size_t>( index );
return static_cast< DatasetH >( g->datasets[i].get() );
}

int MDAL_G_metadataCount( DatasetGroupH group )
@@ -5,6 +5,7 @@

#include "mdal_data_model.hpp"
#include <assert.h>
#include <algorithm>

bool MDAL::Dataset::isActive( size_t faceIndex )
{
@@ -58,3 +59,27 @@ void MDAL::DatasetGroup::setName( const std::string &name )
{
setMetadata( "name", name );
}

void MDAL::Mesh::addBedElevationDataset()
{
if ( faces.empty() )
return;

std::shared_ptr<DatasetGroup> group( new DatasetGroup );
group->isOnVertices = true;
group->isScalar = true;
group->setName( "Bed Elevation" );
group->uri = uri;
std::shared_ptr<MDAL::Dataset> dataset( new Dataset );
dataset->time = 0.0;
dataset->values.resize( vertices.size() );
dataset->active.resize( faces.size() );
dataset->parent = group.get();
std::fill( dataset->active.begin(), dataset->active.end(), 1 );
for ( size_t i = 0; i < vertices.size(); ++i )
{
dataset->values[i].x = vertices[i].z;
}
group->datasets.push_back( dataset );
datasetGroups.push_back( group );
}
@@ -10,10 +10,6 @@
#include <vector>
#include <memory>
#include <map>
#include <string>

// avoid unused variable warnings
#define MDAL_UNUSED(x) (void)x;

namespace MDAL
{
@@ -35,6 +31,7 @@ namespace MDAL
{
double x;
double y;
double z; // Bed elevation
} Vertex;

typedef std::vector<size_t> Face;
@@ -87,8 +84,6 @@ namespace MDAL
bool isScalar = true;
bool isOnVertices = true;
Datasets datasets;
std::shared_ptr<Dataset> maximumDataset;

std::string uri; // file/uri from where it came
};

@@ -109,6 +104,8 @@ namespace MDAL

void setSourceCrs( const std::string &str ) {crs = str;} //TODO
void setSourceCrsFromWKT( const std::string &str ) {crs = str;} //TODO

void addBedElevationDataset();
};

} // namespace MDAL

0 comments on commit 99a6f12

Please sign in to comment.
You can’t perform that action at this time.