Skip to content
Permalink
Browse files

add test for ept hierarchy

  • Loading branch information
PeterPetrik committed Nov 11, 2020
1 parent ba74c4f commit 34e457fd5d616dd5a584b340bbebc1e24513c820
@@ -24,6 +24,7 @@
#include <QJsonObject>
#include <QTime>
#include <QtDebug>
#include <QQueue>

#include "qgseptdecoder.h"
#include "qgscoordinatereferencesystem.h"
@@ -175,27 +176,7 @@ bool QgsEptPointCloudIndex::load( const QString &fileName )
QgsDebugMsgLevel( QStringLiteral( "res at lvl2 %1 with node size %2" ).arg( dx / mSpan / 4 ).arg( dx / 4 ), 2 );

// load hierarchy

QFile fH( QStringLiteral( "%1/ept-hierarchy/0-0-0-0.json" ).arg( mDirectory ) );
if ( !fH.open( QIODevice::ReadOnly ) )
return false;

QByteArray dataJsonH = fH.readAll();
QJsonParseError errH;
QJsonDocument docH = QJsonDocument::fromJson( dataJsonH, &errH );
if ( errH.error != QJsonParseError::NoError )
return false;

QJsonObject rootHObj = docH.object();
for ( auto it = rootHObj.constBegin(); it != rootHObj.constEnd(); ++it )
{
QString nodeIdStr = it.key();
int nodePointCount = it.value().toInt();
IndexedPointCloudNode nodeId = IndexedPointCloudNode::fromString( nodeIdStr );
mHierarchy[nodeId] = nodePointCount;
}

return true;
return loadHierarchy();
}

QgsPointCloudBlock *QgsEptPointCloudIndex::nodeData( const IndexedPointCloudNode &n, const QgsPointCloudRequest &request )
@@ -229,4 +210,46 @@ QgsCoordinateReferenceSystem QgsEptPointCloudIndex::crs() const
return QgsCoordinateReferenceSystem::fromWkt( mWkt );
}

bool QgsEptPointCloudIndex::loadHierarchy()
{
QQueue<QString> queue;
queue.enqueue( QStringLiteral( "0-0-0-0" ) );
while ( !queue.isEmpty() )
{
const QString filename = QStringLiteral( "%1/ept-hierarchy/%2.json" ).arg( mDirectory ).arg( queue.dequeue() );
QFile fH( filename );
if ( !fH.open( QIODevice::ReadOnly ) )
{
QgsDebugMsgLevel( QStringLiteral( "unable to read hierarchy from file %1" ).arg( filename ), 2 );
return false;
}

QByteArray dataJsonH = fH.readAll();
QJsonParseError errH;
QJsonDocument docH = QJsonDocument::fromJson( dataJsonH, &errH );
if ( errH.error != QJsonParseError::NoError )
{
QgsDebugMsgLevel( QStringLiteral( "QJsonParseError when reading hierarchy from file %1" ).arg( filename ), 2 );
return false;
}

QJsonObject rootHObj = docH.object();
for ( auto it = rootHObj.constBegin(); it != rootHObj.constEnd(); ++it )
{
QString nodeIdStr = it.key();
int nodePointCount = it.value().toInt();
if ( nodePointCount < 0 )
{
queue.enqueue( nodeIdStr );
}
else
{
IndexedPointCloudNode nodeId = IndexedPointCloudNode::fromString( nodeIdStr );
mHierarchy[nodeId] = nodePointCount;
}
}
}
return true;
}

///@endcond
@@ -48,6 +48,8 @@ class QgsEptPointCloudIndex: public QgsPointCloudIndex

QgsCoordinateReferenceSystem crs() const;
private:
bool loadHierarchy();

QString mDataType;
QString mDirectory;
QString mWkt;
@@ -29,6 +29,7 @@
#include "qgsproviderregistry.h"
#include "qgseptprovider.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudindex.h"

/**
* \ingroup UnitTests
@@ -52,6 +53,7 @@ class TestQgsEptProvider : public QObject
void uriIsBlocklisted();
void brokenPath();
void validLayer();
void validLayerWithEptHierarchy();

private:
QString mTestDataDir;
@@ -166,6 +168,27 @@ void TestQgsEptProvider::validLayer()
QGSCOMPARENEAR( layer->extent().yMinimum(), 7050992.0, 0.1 );
QGSCOMPARENEAR( layer->extent().xMaximum(), 498068.0, 0.1 );
QGSCOMPARENEAR( layer->extent().yMaximum(), 7050998.0, 0.1 );

QVERIFY( layer->dataProvider()->index() );
// all hierarchy is stored in a single node
QVERIFY( layer->dataProvider()->index()->hasNode( IndexedPointCloudNode::fromString( "0-0-0-0" ) ) );
QVERIFY( !layer->dataProvider()->index()->hasNode( IndexedPointCloudNode::fromString( "1-0-0-0" ) ) );
}

void TestQgsEptProvider::validLayerWithEptHierarchy()
{
std::unique_ptr< QgsPointCloudLayer > layer = qgis::make_unique< QgsPointCloudLayer >( mTestDataDir + QStringLiteral( "point_clouds/ept/lone-star-laszip/ept.json" ), QStringLiteral( "layer" ), QStringLiteral( "ept" ) );
QVERIFY( layer->isValid() );

QGSCOMPARENEAR( layer->extent().xMinimum(), 515368.000000, 0.1 );
QGSCOMPARENEAR( layer->extent().yMinimum(), 4918340.000000, 0.1 );
QGSCOMPARENEAR( layer->extent().xMaximum(), 515402.000000, 0.1 );
QGSCOMPARENEAR( layer->extent().yMaximum(), 4918382.000000, 0.1 );

QVERIFY( layer->dataProvider()->index() );
// all hierarchy is stored in multiple nodes
QVERIFY( layer->dataProvider()->index()->hasNode( IndexedPointCloudNode::fromString( "1-1-1-1" ) ) );
QVERIFY( layer->dataProvider()->index()->hasNode( IndexedPointCloudNode::fromString( "2-3-3-1" ) ) );
}


0 comments on commit 34e457f

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