Skip to content

Commit 3e9c2f0

Browse files
uclaroswonder-sk
authored andcommitted
Search intersecting nodes in hierarchy instead of active nodes
1 parent ede8964 commit 3e9c2f0

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/app/3d/qgs3dmaptoolpointcloudchangeattribute.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,49 @@ SelectedPoints Qgs3DMapToolPointCloudChangeAttribute::searchPoints( QgsPointClou
202202
mapToPixel3D.origin = mCanvas->mapSettings()->origin();
203203
mapToPixel3D.canvasSize = mCanvas->size();
204204

205-
const QVector<const QgsChunkNode *> chunks = mCanvas->scene()->getLayerActiveChunkNodes( layer );
206-
for ( const QgsChunkNode *chunk : chunks )
205+
QgsCoordinateTransform ct( layer->crs(), mCanvas->mapSettings()->crs(), mCanvas->mapSettings()->transformContext() );
206+
ct.setBallparkTransformsAreAppropriate( true );
207+
const double zValueScale = layer->elevationProperties()->zScale();
208+
const double zValueOffset = layer->elevationProperties()->zOffset();
209+
210+
QgsPointCloudIndex index = layer->index();
211+
QVector<QgsPointCloudNodeId> nodes;
212+
QQueue<QgsPointCloudNodeId> queue;
213+
queue.append( index.root() );
214+
while ( !queue.empty() )
207215
{
208-
// check whether the hull intersects the search polygon
209-
const QgsGeometry hull = box3DToPolygonInScreenSpace( chunk->box3D(), mapToPixel3D );
210-
if ( !searchPolygon.intersects( hull.constGet() ) )
216+
const QgsPointCloudNode node = index.getNode( queue.constFirst() );
217+
queue.removeFirst();
218+
219+
const QgsBox3D bounds = node.bounds();
220+
QgsVector3D extentMin3D( bounds.xMinimum(), bounds.yMinimum(), bounds.zMinimum() * zValueScale + zValueOffset );
221+
QgsVector3D extentMax3D( bounds.xMaximum(), bounds.yMaximum(), bounds.zMaximum() * zValueScale + zValueOffset );
222+
try
223+
{
224+
extentMin3D = ct.transform( extentMin3D );
225+
extentMax3D = ct.transform( extentMax3D );
226+
}
227+
catch ( QgsCsException & )
228+
{
229+
QgsDebugError( QStringLiteral( "Error transforming node bounds coordinate" ) );
211230
continue;
231+
}
232+
233+
const QgsBox3D box( extentMin3D.x(), extentMin3D.y(), extentMin3D.z(), extentMax3D.x(), extentMax3D.y(), extentMax3D.z() );
234+
// check whether the hull intersects the search polygon
235+
const QgsGeometry hull = box3DToPolygonInScreenSpace( box, mapToPixel3D );
236+
if ( searchPolygon.intersects( hull.constGet() ) )
237+
{
238+
nodes.append( node.id() );
239+
for ( const QgsPointCloudNodeId &child : node.children() )
240+
{
241+
queue.append( child );
242+
}
243+
}
244+
}
212245

213-
const QgsPointCloudNodeId n( chunk->tileId().d, chunk->tileId().x, chunk->tileId().y, chunk->tileId().z );
246+
for ( const QgsPointCloudNodeId &n : nodes )
247+
{
214248
const QVector<int> pts = selectedPointsInNode( searchPolygon, n, mapToPixel3D, layer );
215249
if ( !pts.isEmpty() )
216250
{

0 commit comments

Comments
 (0)