Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mdal 0.9.0 (#45562)
mdal 0.9.0

Co-authored-by: Vincent Cloarec <vcloarec@gmail.com>
  • Loading branch information
PeterPetrik and vcloarec committed Oct 20, 2021
1 parent 24e2526 commit ffc4eac
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 56 deletions.
3 changes: 2 additions & 1 deletion external/mdal/3rdparty/libplyxx.h
Expand Up @@ -67,7 +67,8 @@ namespace libply
INT32,
UINT32,
FLOAT32,
FLOAT64
FLOAT64,
COORDINATE
};

class IProperty
Expand Down
7 changes: 7 additions & 0 deletions external/mdal/3rdparty/libplyxx/libplyxx.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 "";
}
Expand Down Expand Up @@ -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;
}
Expand Down
33 changes: 24 additions & 9 deletions external/mdal/3rdparty/libplyxx/libplyxx_internal.h
Expand Up @@ -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/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 )
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -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" ) )
{
Expand All @@ -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" ) )
{
Expand Down Expand Up @@ -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() )
{
Expand Down
6 changes: 3 additions & 3 deletions external/mdal/frmts/mdal_ascii_dat.cpp
Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions external/mdal/frmts/mdal_binary_dat.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions external/mdal/frmts/mdal_esri_tin.cpp
Expand Up @@ -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" );
}
Expand All @@ -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" );
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
22 changes: 11 additions & 11 deletions external/mdal/frmts/mdal_flo2d.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions external/mdal/frmts/mdal_ply.cpp
Expand Up @@ -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() );
Expand Down

0 comments on commit ffc4eac

Please sign in to comment.