QGIS API Documentation 3.41.0-Master (f75d66fa9f9)
Loading...
Searching...
No Matches
qgspointcloudlayerundocommand.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudlayerundocommand.cpp
3 ---------------------
4 begin : January 2025
5 copyright : (C) 2025 by Stefanos Natsis
6 email : uclaros at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
20
21
25
28 , mNode( n )
29 , mAttribute( attribute )
30 , mNewValue( value )
31{
34 req.setAttributes( allAttributes );
35 std::unique_ptr<QgsPointCloudBlock> block = mIndex.nodeData( n, req );
36 const char *ptr = block->data();
37 block->attributes().find( attribute.name(), mAttributeOffset );
38 const int size = block->pointRecordSize();
39 for ( const int point : points )
40 {
41 const int offset = point * size + mAttributeOffset;
42 const double oldValue = attribute.convertValueToDouble( ptr + offset );
43 mPointValues[point] = oldValue;
44 }
45}
46
48{
49 undoRedoPrivate( true );
50}
51
53{
54 undoRedoPrivate( false );
55}
56
57void QgsPointCloudLayerUndoCommandChangeAttribute::undoRedoPrivate( bool isUndo )
58{
59 QgsPointCloudEditingIndex *editIndex = static_cast<QgsPointCloudEditingIndex *>( mIndex.get() );
60 QgsCopcPointCloudIndex *copcIndex = static_cast<QgsCopcPointCloudIndex *>( editIndex->mIndex.get() );
61
62 QByteArray chunkData;
63 if ( editIndex->mEditedNodeData.contains( mNode ) )
64 {
65 chunkData = editIndex->mEditedNodeData[mNode];
66 }
67 else
68 {
69 QPair<uint64_t, int32_t> offsetSizePair = copcIndex->mHierarchyNodePos[mNode];
70 chunkData = copcIndex->readRange( offsetSizePair.first, offsetSizePair.second );
71 }
72
73 QByteArray data;
74 if ( isUndo )
75 {
76 data = QgsPointCloudLayerEditUtils::updateChunkValues( copcIndex, chunkData, mAttribute, mNode, mPointValues );
77 }
78 else
79 {
80 data = QgsPointCloudLayerEditUtils::updateChunkValues( copcIndex, chunkData, mAttribute, mNode, mPointValues, mNewValue );
81 }
82
83 mIndex.updateNodeData( {{mNode, data}} );
84}
Collection of point cloud attributes.
Attribute for point cloud data pair of name and size in bytes.
QString name() const
Returns name of the attribute.
double convertValueToDouble(const char *ptr) const
Returns the attribute's value as a double for data pointed to by ptr.
The QgsPointCloudEditingIndex class is a QgsPointCloudIndex that is used as an editing buffer when ed...
Smart pointer for QgsAbstractPointCloudIndex.
std::unique_ptr< QgsPointCloudBlock > nodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)
Returns node data block.
bool updateNodeData(const QHash< QgsPointCloudNodeId, QByteArray > &data)
Tries to update the data for the specified nodes.
QgsAbstractPointCloudIndex * get()
Returns pointer to the implementation class.
QgsPointCloudAttributeCollection attributes() const
Returns all attributes that are stored in the file.
static QByteArray updateChunkValues(QgsCopcPointCloudIndex *copcIndex, const QByteArray &chunkData, const QgsPointCloudAttribute &attribute, const QgsPointCloudNodeId &n, const QHash< int, double > &pointValues, std::optional< double > newValue=std::nullopt)
Sets new classification value for the given points in voxel and return updated chunk data.
QgsPointCloudLayerUndoCommandChangeAttribute(QgsPointCloudIndex index, const QgsPointCloudNodeId &n, const QVector< int > &points, const QgsPointCloudAttribute &attribute, double value)
Constructor for QgsPointCloudLayerUndoCommandChangeAttribute.
Base class for undo/redo command for point cloud editing.
QgsPointCloudLayerUndoCommand(QgsPointCloudIndex index)
Ctor.
Represents a indexed point cloud node's position in octree.
Point cloud data request.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.