Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes and tests #34

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions Tests/src/core/reos_hydraulic_structure_2D_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ email : vcloarec at gmail dot com
#include "reospolygonstructure.h"
#include "reosgisengine.h"
#include "reosmapextent.h"
#include "reostopographycollection.h"
#include "reos_testutils.h"

class ReoHydraulicStructure2DTest: public QObject
{
Expand All @@ -28,16 +30,20 @@ class ReoHydraulicStructure2DTest: public QObject
void init();
void createAndEditPolylineStructure();
void createAndEditPolygonStructure();

void createHydraulicStructure();
private:
ReosHydraulicNetwork *mNetwork = nullptr;
ReosModule *mRootModule = nullptr;
ReosGisEngine engine;
ReosGisEngine mGisEngine;

std::unique_ptr<ReosHydraulicStructure2D> mHydraulicStructure;
};

void ReoHydraulicStructure2DTest::init()
{
mRootModule = new ReosModule( this );
mNetwork = new ReosHydraulicNetwork( nullptr, nullptr, nullptr );
mNetwork = new ReosHydraulicNetwork( mRootModule, &mGisEngine, nullptr );
}

void ReoHydraulicStructure2DTest::createAndEditPolylineStructure()
Expand Down Expand Up @@ -379,5 +385,52 @@ void ReoHydraulicStructure2DTest::createAndEditPolygonStructure()

}

void ReoHydraulicStructure2DTest::createHydraulicStructure()
{
QPolygonF domain;
domain << QPointF( 0, 0 )
<< QPointF( 10, 0 )
<< QPointF( 10, 10 )
<< QPointF( 20, 10 )
<< QPointF( 20, 0 )
<< QPointF( 30, 0 )
<< QPointF( 30, 20 )
<< QPointF( 0, 20 );

mHydraulicStructure = std::make_unique<ReosHydraulicStructure2D>( domain, QString(), mNetwork->context() );
mHydraulicStructure->meshResolutionController()->defaultSize()->setValue( 1 );

std::unique_ptr<ReosMeshGeneratorProcess> meshGenerator( mHydraulicStructure->getGenerateMeshProcess() );
meshGenerator->start();
Q_ASSERT( meshGenerator->isSuccessful() );
QCOMPARE( mHydraulicStructure->mesh()->vertexCount(), 714 );

QPolygonF hole;
hole << QPointF( 2.5, 2.5 )
<< QPointF( 7.5, 2.5 )
<< QPointF( 7.5, 7.5 )
<< QPointF( 2.5, 7.5 )
<< QPointF( 2.5, 2.5 );
mHydraulicStructure->geometryStructure()->addPolylines( hole );
mHydraulicStructure->geometryStructure()->addHolePoint( QPointF( 5, 5 ) );

meshGenerator.reset( mHydraulicStructure->getGenerateMeshProcess() );
meshGenerator->start();
QVERIFY( meshGenerator->isSuccessful() );
QCOMPARE( mHydraulicStructure->mesh()->vertexCount(), 687 );

QString demId = mGisEngine.addRasterLayer( test_file( "dem_for_mesh.tif" ).c_str() );
mGisEngine.registerLayerAsDigitalElevationModel( demId );
mHydraulicStructure->topographyCollecion()->insertTopography( 0, demId );

ModuleProcessControler controler( mHydraulicStructure->mesh()->applyTopographyOnVertices( mHydraulicStructure->topographyCollecion() ) );
controler.waitForFinished();

QVERIFY( equal( mHydraulicStructure->terrainElevationAt( QPointF( 15.0, 15.0 ) ), 1, 0.01 ) );
QVERIFY( equal( mHydraulicStructure->terrainElevationAt( QPointF( 10.0, 15.0 ) ), 0.666, 0.01 ) );
QVERIFY( equal( mHydraulicStructure->terrainElevationAt( QPointF( 20.0, 15.0 ) ), 1.333, 0.01 ) );
QVERIFY( std::isnan( mHydraulicStructure->terrainElevationAt( QPointF( 5.0, 5.0 ) ) ) );
QVERIFY( std::isnan( mHydraulicStructure->terrainElevationAt( QPointF( 15.0, 5.0 ) ) ) );
}
QTEST_MAIN( ReoHydraulicStructure2DTest )
#include "reos_hydraulic_structure_2D_test.moc"
Binary file added Tests/testData/dem_for_mesh.tif
Binary file not shown.
26 changes: 16 additions & 10 deletions src/core/GIS/private/reosmesh_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "reosparameter.h"
#include "reosencodedelement.h"
#include "reosmapextent.h"
#include "reostopographycollection.h"

ReosMeshFrame_p::ReosMeshFrame_p( const QString &crs, QObject *parent ): ReosMesh( parent )
{
Expand All @@ -36,11 +37,11 @@ ReosMeshFrame_p::ReosMeshFrame_p( const QString &crs, QObject *parent ): ReosMes
qgisCrs.createFromWkt( crs );
mMeshLayer->setCrs( qgisCrs );
meshProvider()->overrideCrs( qgisCrs );

mMeshLayer->updateTriangularMesh();
init();
}

ReosMeshFrame_p::ReosMeshFrame_p( const QString &dataPath )
ReosMeshFrame_p::ReosMeshFrame_p( const QString &dataPath, const QString &destinationCrs )
{
mMeshLayer.reset( new QgsMeshLayer( "path", "", QStringLiteral( "ReosMesh" ) ) );

Expand All @@ -50,7 +51,11 @@ ReosMeshFrame_p::ReosMeshFrame_p( const QString &dataPath )
meshProvider()->loadMeshFrame( dir.filePath( QStringLiteral( "meshFrame.nc" ) ), QStringLiteral( "Ugrid" ) );
mMeshLayer->setCrs( meshProvider()->crs() );
mMeshLayer->reload();
}
QgsCoordinateReferenceSystem qgisDestinationCrs;
qgisDestinationCrs.createFromWkt( destinationCrs );
QgsCoordinateTransform transform( meshProvider()->crs(), qgisDestinationCrs, QgsProject::instance() );
mMeshLayer->updateTriangularMesh( transform );
};

init();
}
Expand Down Expand Up @@ -297,7 +302,7 @@ QPointF ReosMeshFrame_p::vertexPosition( int vertexIndex, const QString &destina
return mMeshLayer->nativeMesh()->vertices.at( vertexIndex ).toQPointF();

QgsCoordinateReferenceSystem crs;
crs.fromWkt( destinationCrs );
crs.createFromWkt( destinationCrs );
QgsCoordinateTransform transform( mMeshLayer->crs(), crs, QgsProject::instance() );
QgsPointXY vert = mMeshLayer->nativeMesh()->vertices.at( vertexIndex );
if ( transform.isValid() )
Expand Down Expand Up @@ -358,7 +363,7 @@ void ReosMeshFrame_p::updateWireFrameSettings()
QPointF ReosMeshFrame_p::tolayerCoordinates( const ReosSpatialPosition &position ) const
{
QgsCoordinateReferenceSystem sourceCrs;
sourceCrs.fromWkt( position.crs() );
sourceCrs.createFromWkt( position.crs() );

const QgsCoordinateTransform transform( sourceCrs, mMeshLayer->crs(), QgsProject::instance() );
QgsPointXY ret;
Expand Down Expand Up @@ -859,12 +864,13 @@ class ApplyTopopraphyProcess : public ReosProcess
ApplyTopopraphyProcess( ReosTopographyCollection *topographyCollection, ReosMeshDataProvider_p *meshProvider )
: mTopographyCollection( topographyCollection )
, mProvider( meshProvider )
{
{}


}
void start()
{
mProvider->applyTopographyOnVertices( mTopographyCollection, this );
mIsSuccessful = true;
}

private:
Expand All @@ -877,13 +883,13 @@ ReosProcess *ReosMeshFrame_p::applyTopographyOnVertices( ReosTopographyCollectio
if ( mMeshLayer->isEditable() )
stopFrameEditing( true );


std::unique_ptr<ReosProcess> process( new ApplyTopopraphyProcess( topographyCollection, meshProvider() ) );

connect( process.get(), &ReosProcess::finished, this, [this]
connect( process.get(), &ReosProcess::finished, this, [this, topographyCollection]
{
mMeshLayer->reload();

QgsCoordinateTransform tranform( mMeshLayer->crs(), QgsCoordinateReferenceSystem::fromWkt( topographyCollection->gisEngine()->crs() ), QgsProject::instance()->transformContext() );
mMeshLayer->updateTriangularMesh( tranform );
if ( mZVerticesDatasetGroup )
mZVerticesDatasetGroup->setStatisticObsolete();

Expand Down
4 changes: 2 additions & 2 deletions src/core/GIS/private/reosmesh_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ReosMeshFrame_p : public ReosMesh
{
public:
ReosMeshFrame_p( const QString &crs, QObject *parent );
ReosMeshFrame_p( const QString &dataPath );
ReosMeshFrame_p( const QString &dataPath, const QString &destinationCrs );

bool isValid() const override;
int vertexCount() const override;
Expand All @@ -56,7 +56,7 @@ class ReosMeshFrame_p : public ReosMesh
void generateMesh( const ReosMeshFrameData &data ) override;
QString crs() const override;
QObject *data() const override;
ReosProcess *applyTopographyOnVertices( ReosTopographyCollection *topographyCollection ) override;
ReosProcess *applyTopographyOnVertices(ReosTopographyCollection *topographyCollection ) override;
double datasetScalarValueAt( const QString &datasetId, const QPointF &pos ) const override;
void datasetGroupMinimumMaximum( const QString &datasetId, double &min, double &max ) const override;
void save( const QString &dataPath ) override;
Expand Down
8 changes: 4 additions & 4 deletions src/core/GIS/private/reospolylinesstructure_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ReosGeometryStructure_p::ReosGeometryStructure_p( const QString &type, const QS
QgsPointXY ReosGeometryStructure_p::toLayerCoordinates( const ReosSpatialPosition &position ) const
{
QgsCoordinateReferenceSystem crs;
crs.fromWkt( position.crs() );
crs.createFromWkt( position.crs() );

QgsCoordinateTransform transform( crs, mVectorLayer->crs(), QgsProject::instance() );

Expand All @@ -57,15 +57,15 @@ QgsPointXY ReosGeometryStructure_p::transformCoordinates( const QPointF &positio
const QgsCoordinateTransform ReosGeometryStructure_p::toLayerTransform( const QString &crs ) const
{
QgsCoordinateReferenceSystem qgsCrs;
qgsCrs.fromWkt( crs );
qgsCrs.createFromWkt( crs );

return QgsCoordinateTransform( qgsCrs, mVectorLayer->crs(), QgsProject::instance() );
}

const QgsCoordinateTransform ReosGeometryStructure_p::toDestinationTransform( const QString &destinationCrs ) const
{
QgsCoordinateReferenceSystem qgsCrs;
qgsCrs.fromWkt( destinationCrs );
qgsCrs.createFromWkt( destinationCrs );

return QgsCoordinateTransform( mVectorLayer->crs(), qgsCrs, QgsProject::instance() );
}
Expand Down Expand Up @@ -1936,7 +1936,7 @@ bool ReosPolylineStructureVectorLayer::isOnBoundary( ReosGeometryStructureVertex
double ReosPolylineStructureVectorLayer::tolerance( const QString &wktCrs ) const
{
QgsCoordinateReferenceSystem destCrs;
destCrs.fromWkt( wktCrs );
destCrs.createFromWkt( wktCrs );

QgsUnitTypes::DistanceUnit destUnit = destCrs.mapUnits();
QgsUnitTypes::DistanceUnit layerUnit = mVectorLayer->crs().mapUnits();
Expand Down
4 changes: 2 additions & 2 deletions src/core/GIS/reosmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ ReosMesh *ReosMesh::createMeshFrame( const QString &crs, QObject *parent )
return new ReosMeshFrame_p( crs, parent );
}

ReosMesh *ReosMesh::createMeshFrameFromFile( const QString &dataPath )
ReosMesh *ReosMesh::createMeshFrameFromFile( const QString &dataPath, const QString &destinationCrs )
{
return new ReosMeshFrame_p( dataPath );
return new ReosMeshFrame_p( dataPath, destinationCrs );
}


Expand Down
5 changes: 3 additions & 2 deletions src/core/GIS/reosmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#include <QSet>

#include "reoscore.h"
#include "reosgisengine.h"
#include "reosrenderedobject.h"
#include "reosencodedelement.h"

class ReosMeshGenerator;
class ReosMeshFrameData;
class ReosDigitalElevationModel;
class ReosMap;
class ReosTopographyCollection;
class ReosParameterDouble;
class ReosParameterInteger;
Expand All @@ -37,6 +37,7 @@ class ReosParameterArea;
class ReosHydraulicSimulationResults;
class ReosSpatialPosition;
class ReosMeshDatasetSource;
class ReosGisEngine;


class ReosMeshQualityChecker : public ReosProcess
Expand Down Expand Up @@ -110,7 +111,7 @@ class REOSCORE_EXPORT ReosMesh: public ReosRenderedObject
//! Creates a new void mesh in memory
static ReosMesh *createMeshFrame( const QString &crs = QString(), QObject *parent = nullptr );

static ReosMesh *createMeshFrameFromFile( const QString &dataPath );
static ReosMesh *createMeshFrameFromFile( const QString &dataPath, const QString &destinationCrs );

//! Returns whether the mesh is valid
virtual bool isValid() const = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/core/GIS/reostopographycollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ ReosTopographyCollection::ReosTopographyCollection( const ReosEncodedElement &el
}
}

ReosGisEngine *ReosTopographyCollection::gisEngine() const
{
return mGisEngine;
}

ReosParameterBoolean *ReosTopographyCollection::autoApply() const
{
return mAutoApply;
Expand Down
4 changes: 3 additions & 1 deletion src/core/GIS/reostopographycollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class REOSCORE_EXPORT ReosTopographyCollection : public ReosDataObject

ReosParameterBoolean *autoApply() const;

protected:
ReosGisEngine *gisEngine() const;

protected:
explicit ReosTopographyCollection( ReosGisEngine *gisEngine, QObject *parent = nullptr );
explicit ReosTopographyCollection( const ReosEncodedElement &element, ReosGisEngine *gisEngine, QObject *parent = nullptr );

Expand Down
2 changes: 1 addition & 1 deletion src/core/data/reosdataobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class REOSCORE_EXPORT ReosDataObject: public QObject
void deregisterUpstreamData( ReosDataObject *data );
void setActualized() const;

//! Return true whether the data need to be calculated ot updated
//! Return true whether the data need to be calculated or updated
bool isObsolete() const;

protected slots:
Expand Down
29 changes: 21 additions & 8 deletions src/core/hydraulicNetwork/reoshydraulicnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

ReosHydraulicNetworkElement::ReosHydraulicNetworkElement( ReosHydraulicNetwork *parent ):
ReosDataObject( parent )
, mNetWork( parent )
, mNetwork( parent )
, mNameParameter( new ReosParameterString( tr( "Name" ), false, this ) )
{
mConstantTimeStepInTable = new ReosParameterDuration( tr( "Constant time step" ) );
Expand All @@ -36,7 +36,7 @@ ReosHydraulicNetworkElement::ReosHydraulicNetworkElement( ReosHydraulicNetwork *

ReosHydraulicNetworkElement::ReosHydraulicNetworkElement( const ReosEncodedElement &encodedElement, ReosHydraulicNetwork *parent )
: ReosDataObject( parent )
, mNetWork( parent )
, mNetwork( parent )
, mNameParameter( ReosParameterString::decode( encodedElement.getEncodedData( QStringLiteral( "name-parameter" ) ), false, tr( "Name" ), this ) )
{
ReosDataObject::decode( encodedElement );
Expand Down Expand Up @@ -73,15 +73,15 @@ ReosHydraulicNetworkElement::~ReosHydraulicNetworkElement()

void ReosHydraulicNetworkElement::destroy()
{
if ( !mNetWork.isNull() )
mNetWork->mElements.remove( id() );
if ( !mNetwork.isNull() )
mNetwork->mElements.remove( id() );
deleteLater();
}

void ReosHydraulicNetworkElement::positionChanged()
{
if ( mNetWork )
mNetWork->elemPositionChangedPrivate( this );
if ( mNetwork )
mNetwork->elemPositionChangedPrivate( this );
}

ReosParameterString *ReosHydraulicNetworkElement::elementName() const
Expand Down Expand Up @@ -120,8 +120,8 @@ void ReosHydraulicNetworkElement::notify( const ReosModule::Message &messageObje
{
ReosModule::Message sendedMessage = messageObject;
sendedMessage.prefixMessage( tr( "Routing %1: " ).arg( elementName()->value() ) );
if ( mNetWork )
mNetWork->message( sendedMessage );
if ( mNetwork )
mNetwork->message( sendedMessage );
}
}

Expand All @@ -139,6 +139,11 @@ ReosDuration ReosHydraulicNetworkElement::currentElementTimeStep() const
return ReosDuration( qint64( 0 ) );
}

ReosHydraulicNetwork *ReosHydraulicNetworkElement::network() const
{
return mNetwork;
}

ReosHydraulicNetwork::ReosHydraulicNetwork( ReosModule *parent, ReosGisEngine *gisEngine, ReosWatershedModule *watershedModule )
: ReosModule( parent )
, mGisEngine( gisEngine )
Expand Down Expand Up @@ -482,6 +487,14 @@ ReosHydraulicNetwork *ReosHydraulicNetworkContext::network() const
return mNetwork;
}

QString ReosHydraulicNetworkContext::crs() const
{
if ( mNetwork->gisEngine() )
return mNetwork->gisEngine()->crs();

return QString();
}

QString ReosHydraulicNetworkContext::projectPath() const
{
return mProjectPath;
Expand Down
Loading