Skip to content
Permalink
Browse files
mdal0.9.0
  • Loading branch information
PeterPetrik committed Oct 19, 2021
1 parent 37a37fe commit 98c90632ad6ca74fa62f16bc4f8136359578cb84
@@ -67,7 +67,8 @@ namespace libply
INT32,
UINT32,
FLOAT32,
FLOAT64
FLOAT64,
COORDINATE
};

class IProperty
@@ -461,6 +461,9 @@ namespace libply
case Type::FLOAT64:
prop = std::make_unique<ScalarProperty<double>>();
break;
case Type::COORDINATE:
prop = std::make_unique<ScalarProperty<double>>();
break;
}
return prop;
}
@@ -488,6 +491,7 @@ namespace libply
case Type::INT32: return "int";
case Type::FLOAT32: return "float";
case Type::FLOAT64: return "double";
case Type::COORDINATE: return "double";
}
return "";
}
@@ -701,6 +705,9 @@ namespace libply
case Type::FLOAT64:
prop = std::make_unique<ScalarProperty<double>>();
break;
case Type::COORDINATE:
prop = std::make_unique<ScalarProperty<double>>();
break;
}
return prop;
}
@@ -46,7 +46,11 @@ SOFTWARE.
#pragma once

#include "libplyxx.h"
#include "mdal_utils.hpp"

#include <sstream>
#include <iostream>


// a custom specialisation (and yes, you are allowed (and have to) put this in std)
// from http://www.cplusplus.com/forum/general/238538/
@@ -98,7 +102,8 @@ namespace libply
{ Type::INT32, 4},
{ Type::UINT32, 4},
{ Type::FLOAT32, 4},
{ Type::FLOAT64, 8}
{ Type::FLOAT64, 8},
{ Type::COORDINATE, 8}
};

/// Type conversion functions.
@@ -135,7 +140,8 @@ namespace libply
{ Type::INT32, convert_INT },
{ Type::UINT32, convert_UINT },
{ Type::FLOAT32, convert_FLOAT },
{ Type::FLOAT64, convert_DOUBLE }
{ Type::FLOAT64, convert_DOUBLE },
{ Type::COORDINATE, convert_DOUBLE }
};

/// Type casting functions.
@@ -192,30 +198,37 @@ namespace libply
{ Type::INT32, cast_INT32 },
{ Type::UINT32, cast_UINT32 },
{ Type::FLOAT32, cast_FLOAT },
{ Type::FLOAT64, cast_DOUBLE }
{ Type::FLOAT64, cast_DOUBLE },
{ Type::COORDINATE, cast_DOUBLE }
};

inline std::stringstream &write_convert_UINT( IProperty &property, std::stringstream &ss )
{
ss << static_cast<unsigned int>( property );
ss << std::to_string( static_cast<unsigned int>( property ) );
return ss;
}

inline std::stringstream &write_convert_INT( IProperty &property, std::stringstream &ss )
{
ss << static_cast<int>( property );
ss << std::to_string( static_cast<int>( property ) );
return ss;
}

inline std::stringstream &write_convert_FLOAT( IProperty &property, std::stringstream &ss )
{
ss << static_cast<float>( property );
ss << std::to_string( static_cast<float>( property ) );
return ss;
}

inline std::stringstream &write_convert_DOUBLE( IProperty &property, std::stringstream &ss )
{
ss << static_cast<double>( property );
ss << MDAL::doubleToString( static_cast<double>( property ) );
return ss;
}

inline std::stringstream &write_convert_COORDINATE( IProperty &property, std::stringstream &ss )
{
ss << MDAL::coordinateToString( static_cast<double>( property ) );
return ss;
}

@@ -231,7 +244,8 @@ namespace libply
{ Type::INT32, write_convert_INT },
{ Type::UINT32, write_convert_UINT },
{ Type::FLOAT32, write_convert_FLOAT },
{ Type::FLOAT64, write_convert_DOUBLE }
{ Type::FLOAT64, write_convert_DOUBLE },
{ Type::COORDINATE, write_convert_COORDINATE }
};

inline void write_cast_UINT( IProperty &property, char *buffer, size_t &size )
@@ -270,7 +284,8 @@ namespace libply
{ Type::INT32, write_cast_INT },
{ Type::UINT32, write_cast_UINT },
{ Type::FLOAT32, write_cast_FLOAT },
{ Type::FLOAT64, write_cast_DOUBLE }
{ Type::FLOAT64, write_cast_DOUBLE },
{ Type::COORDINATE, write_cast_DOUBLE }
};

struct PropertyDefinition
@@ -106,7 +106,7 @@ MDAL::Driver2dm::~Driver2dm() = default;

bool MDAL::Driver2dm::canReadMesh( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::ifstream in = MDAL::openInputFile( uri );
std::string line;
if ( !MDAL::getHeaderLine( in, line ) || !startsWith( line, "MESH2D" ) )
{
@@ -121,7 +121,8 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,

MDAL::Log::resetLastStatus();

std::ifstream in( mMeshFile, std::ifstream::in );
std::ifstream in = MDAL::openInputFile( meshFile );

std::string line;
if ( !std::getline( in, line ) || !startsWith( line, "MESH2D" ) )
{
@@ -380,7 +381,7 @@ void MDAL::Driver2dm::save( const std::string &fileName, const std::string &, MD
{
MDAL::Log::resetLastStatus();

std::ofstream file( fileName, std::ofstream::out );
std::ofstream file = MDAL::openOutputFile( fileName, std::ofstream::out );

if ( !file.is_open() )
{
@@ -44,7 +44,7 @@ MDAL::DriverAsciiDat::~DriverAsciiDat( ) = default;

bool MDAL::DriverAsciiDat::canReadDatasets( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::ifstream in = MDAL::openInputFile( uri );
std::string line;
if ( !MDAL::getHeaderLine( in, line ) )
{
@@ -335,7 +335,7 @@ void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh )
return;
}

std::ifstream in( mDatFile, std::ifstream::in );
std::ifstream in = MDAL::openInputFile( mDatFile );
std::string line;
if ( !std::getline( in, line ) )
{
@@ -496,7 +496,7 @@ bool MDAL::DriverAsciiDat::persist( MDAL::DatasetGroup *group )
return true;
}

std::ofstream out( uri, std::ofstream::out );
std::ofstream out = MDAL::openOutputFile( uri, std::ofstream::out );

// implementation based on information from:
// https://www.xmswiki.com/wiki/SMS:ASCII_Dataset_Files_*.dat
@@ -94,7 +94,7 @@ MDAL::DriverBinaryDat::~DriverBinaryDat() = default;

bool MDAL::DriverBinaryDat::canReadDatasets( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in | std::ifstream::binary );
std::ifstream in = MDAL::openInputFile( uri, std::ifstream::in | std::ifstream::binary );
int version;

if ( read( in, reinterpret_cast< char * >( &version ), 4 ) )
@@ -127,7 +127,7 @@ void MDAL::DriverBinaryDat::load( const std::string &datFile, MDAL::Mesh *mesh )
return;
}

std::ifstream in( mDatFile, std::ifstream::in | std::ifstream::binary );
std::ifstream in = MDAL::openInputFile( mDatFile, std::ifstream::in | std::ifstream::binary );

// implementation based on information from:
// http://www.xmswiki.com/wiki/SMS:Binary_Dataset_Files_*.dat
@@ -393,7 +393,7 @@ bool MDAL::DriverBinaryDat::persist( MDAL::DatasetGroup *group )
{
assert( group->dataLocation() == MDAL_DataLocation::DataOnVertices );

std::ofstream out( group->uri(), std::ofstream::out | std::ofstream::binary );
std::ofstream out = MDAL::openOutputFile( group->uri(), std::ofstream::out | std::ofstream::binary );

// implementation based on information from:
// http://www.xmswiki.com/wiki/SMS:Binary_Dataset_Files_*.dat
@@ -29,10 +29,12 @@ std::unique_ptr<MDAL::Mesh> MDAL::DriverEsriTin::load( const std::string &uri, c

//read the total number of vertices (including superpoints and isolated vertices)
int32_t totalIndexesCount32;
std::ifstream inDenv( denvFile( uri ), std::ifstream::in | std::ifstream::binary );

std::ifstream inDenv = MDAL::openInputFile( denvFile( uri ), std::ios_base::in | std::ios_base::binary );

if ( !inDenv.is_open() )
{
inDenv.open( denv9File( uri ), std::ifstream::in | std::ifstream::binary );
inDenv = MDAL::openInputFile( denv9File( uri ), std::ifstream::in | std::ifstream::binary );
if ( !inDenv.is_open() )
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not open file " + uri + " as denv file" );
}
@@ -46,9 +48,9 @@ std::unique_ptr<MDAL::Mesh> MDAL::DriverEsriTin::load( const std::string &uri, c
* Unwanted vertices are associated with the totalIndexesCount value
*/
std::vector<size_t> rawAndCorrectedIndexesMap( totalIndexesCount, totalIndexesCount );
std::ifstream inFaces( faceFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inMsk( mskFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inMsx( msxFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inFaces = MDAL::openInputFile( faceFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inMsk = MDAL::openInputFile( mskFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inMsx = MDAL::openInputFile( msxFile( uri ), std::ifstream::in | std::ifstream::binary );

if ( ! inFaces.is_open() )
throw MDAL::Error( MDAL_Status::Err_FileNotFound, "Could not open file " + uri + " as faces file" );
@@ -132,8 +134,8 @@ std::unique_ptr<MDAL::Mesh> MDAL::DriverEsriTin::load( const std::string &uri, c

//Round 3: populate vertices
Vertices vertices( correctedIndexCount );
std::ifstream inXY( xyFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inZ( zFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inXY = MDAL::openInputFile( xyFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream inZ = MDAL::openInputFile( zFile( uri ), std::ifstream::in | std::ifstream::binary );

if ( ! inXY.is_open() )
throw MDAL::Error( MDAL_Status::Err_FileNotFound, "Could not open file " + uri + " as xyFile type" );
@@ -213,19 +215,19 @@ bool MDAL::DriverEsriTin::canReadMesh( const std::string &uri )
std::string zFileName = zFile( uri );
std::string faceFileName = faceFile( uri );

std::ifstream xyIn( xyFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream xyIn = MDAL::openInputFile( xyFile( uri ), std::ifstream::in | std::ifstream::binary );
if ( ! xyIn.is_open() )
return false;

std::ifstream zIn( zFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream zIn = MDAL::openInputFile( zFile( uri ), std::ifstream::in | std::ifstream::binary );
if ( ! zIn.is_open() )
return false;

std::ifstream faceIn( faceFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream faceIn = MDAL::openInputFile( faceFile( uri ), std::ifstream::in | std::ifstream::binary );
if ( ! faceIn.is_open() )
return false;

std::ifstream hullIn( hullFile( uri ), std::ifstream::in | std::ifstream::binary );
std::ifstream hullIn = MDAL::openInputFile( hullFile( uri ), std::ifstream::in | std::ifstream::binary );
if ( ! hullIn.is_open() )
return false;

@@ -313,7 +315,7 @@ std::string MDAL::DriverEsriTin::getTinName( const std::string &uri ) const

std::string MDAL::DriverEsriTin::getCrsWkt( const std::string &uri ) const
{
std::ifstream inCRS( crsFile( uri ), std::ifstream::in );
std::ifstream inCRS = MDAL::openInputFile( crsFile( uri ) );
if ( ! inCRS.is_open() )
return std::string();

@@ -94,7 +94,7 @@ void MDAL::DriverFlo2D::parseCADPTSFile( const std::string &datFileName, std::ve
throw MDAL::Error( MDAL_Status::Err_FileNotFound, "Could not find file " + cadptsFile );
}

std::ifstream cadptsStream( cadptsFile, std::ifstream::in );
std::ifstream cadptsStream = MDAL::openInputFile( cadptsFile, std::ifstream::in );
std::string line;
// CADPTS.DAT - COORDINATES OF CELL CENTERS (ELEM NUM, X, Y)
while ( std::getline( cadptsStream, line ) )
@@ -132,7 +132,7 @@ void MDAL::DriverFlo2D::parseCHANBANKFile( const std::string &datFileName,
{
throw MDAL::Error( MDAL_Status::Err_FileNotFound, "Could not find file " + chanBankFile );
}
std::ifstream chanBankStream( chanBankFile, std::ifstream::in );
std::ifstream chanBankStream = MDAL::openInputFile( chanBankFile, std::ifstream::in );
std::string line;
// CHANBANK.DAT - Cell id of each bank (Left Bank id , Right Bank id), if right bank id is 0, channel is only on left cell
size_t vertexIndex = 0;
@@ -176,7 +176,7 @@ void MDAL::DriverFlo2D::parseCHANFile( const std::string &datFileName, const std
{
throw MDAL::Error( MDAL_Status::Err_FileNotFound, "Could not find file " + chanFile );
}
std::ifstream chanStream( chanFile, std::ifstream::in );
std::ifstream chanStream = MDAL::openInputFile( chanFile, std::ifstream::in );
std::string line;
// CHAN.DAT - each reachs are represented by following line beginning by R, V,T or N
// Confluences are represented by line beginning by C
@@ -293,7 +293,7 @@ void MDAL::DriverFlo2D::parseHYCHANFile( const std::string &datFileName, const s
{
return;
}
std::ifstream hyChanStream( hyChanFile, std::ifstream::in );
std::ifstream hyChanStream = MDAL::openInputFile( hyChanFile, std::ifstream::in );
std::string line;

std::vector<std::string> variablesName;
@@ -487,7 +487,7 @@ void MDAL::DriverFlo2D::parseFPLAINFile( std::vector<double> &elevations,
throw MDAL::Error( MDAL_Status::Err_FileNotFound, "Could not find file " + fplainFile );
}

std::ifstream fplainStream( fplainFile, std::ifstream::in );
std::ifstream fplainStream = MDAL::openInputFile( fplainFile, std::ifstream::in );
std::string line;

bool cellSizeCalculated = false;
@@ -550,7 +550,7 @@ void MDAL::DriverFlo2D::parseTIMDEPFile( const std::string &datFileName, const s
return;
}

std::ifstream inStream( inFile, std::ifstream::in );
std::ifstream inStream = MDAL::openInputFile( inFile, std::ifstream::in );
std::string line;

size_t nVertexs = mMesh->verticesCount();
@@ -661,7 +661,7 @@ void MDAL::DriverFlo2D::parseDEPTHFile( const std::string &datFileName, const st
return; //optional file
}

std::ifstream depthStream( depthFile, std::ifstream::in );
std::ifstream depthStream = MDAL::openInputFile( depthFile, std::ifstream::in );
std::string line;

size_t nFaces = mMesh->facesCount();
@@ -711,7 +711,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName )
return; //optional file
}

std::ifstream velocityStream( velocityFile, std::ifstream::in );
std::ifstream velocityStream = MDAL::openInputFile( velocityFile, std::ifstream::in );
std::string line;

size_t vertex_idx = 0;
@@ -742,7 +742,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName )
return; //optional file
}

std::ifstream velocityStream( velocityFile, std::ifstream::in );
std::ifstream velocityStream = MDAL::openInputFile( velocityFile, std::ifstream::in );
std::string line;

size_t vertex_idx = 0;
@@ -818,8 +818,8 @@ void MDAL::DriverFlo2D::createMesh2d( const std::vector<CellCenter> &cells, cons
cellCenterExtent.minY - half_cell_size,
cellCenterExtent.maxY + half_cell_size );

size_t width = MDAL::toSizeT( ( vertexExtent.maxX - vertexExtent.minX ) / cell_size + 1 );
size_t heigh = MDAL::toSizeT( ( vertexExtent.maxY - vertexExtent.minY ) / cell_size + 1 );
size_t width = MDAL::toSizeT( ( vertexExtent.maxX - vertexExtent.minX ) / cell_size + 1.5 );
size_t heigh = MDAL::toSizeT( ( vertexExtent.maxY - vertexExtent.minY ) / cell_size + 1.5 );
std::vector<std::vector<size_t>> vertexGrid( width, std::vector<size_t>( heigh, INVALID_INDEX ) );

Vertices vertices;
@@ -583,9 +583,9 @@ void MDAL::DriverPly::save( const std::string &fileName, const std::string &mesh

libply::ElementsDefinition definitions;
std::vector<libply::Property> vproperties;
vproperties.emplace_back( "X", libply::Type::FLOAT64, false );
vproperties.emplace_back( "Y", libply::Type::FLOAT64, false );
vproperties.emplace_back( "Z", libply::Type::FLOAT64, false );
vproperties.emplace_back( "X", libply::Type::COORDINATE, false );
vproperties.emplace_back( "Y", libply::Type::COORDINATE, false );
vproperties.emplace_back( "Z", libply::Type::COORDINATE, false );
for ( std::shared_ptr<DatasetGroup> group : vgroups )
{
vproperties.emplace_back( group->name(), libply::Type::FLOAT64, ! group->isScalar() );

0 comments on commit 98c9063

Please sign in to comment.