25#include <QtConcurrentMap>
27using namespace Qt::StringLiterals;
35 , mAttribute( attribute )
38 QgsEventTracing::ScopedEvent _trace( u
"PointCloud"_s, u
"QgsPointCloudLayerUndoCommand constructor"_s );
43 std::function mapFn = [editIndex, attribute, index = std::move( index )]( std::pair<const QgsPointCloudNodeId &, const QVector<int> &> pair )
46 auto &points = pair.second;
49 PerNodeData perNodeData;
58 std::unique_ptr<QgsPointCloudBlock> block = index2.
nodeData( n, req );
59 const char *ptr = block->data();
60 block->attributes().find( attribute.
name(), perNodeData.attributeOffset );
61 const int size = block->pointRecordSize();
62 for (
const int point : points )
64 const int offset = point * size + perNodeData.attributeOffset;
66 perNodeData.oldPointValues[point] = oldValue;
73 perNodeData.firstEdit =
true;
74 for (
const int point : points )
76 perNodeData.oldPointValues[point] = std::numeric_limits<double>::quiet_NaN();
80 return std::pair { n, perNodeData };
83 std::function reduceFn = []( QHash<QgsPointCloudNodeId, PerNodeData> &res,
const std::pair<QgsPointCloudNodeId, PerNodeData> &pair )
85 res[pair.first] = pair.second;
88 mPerNodeData = QtConcurrent::blockingMappedReduced<QHash<QgsPointCloudNodeId, PerNodeData>>(
89 nodesAndPoints.keyValueBegin(), nodesAndPoints.keyValueEnd(),
90 std::move( mapFn ), std::move( reduceFn )
96 undoRedoPrivate(
true );
101 undoRedoPrivate(
false );
104void QgsPointCloudLayerUndoCommandChangeAttribute::undoRedoPrivate(
bool isUndo )
106 QgsEventTracing::ScopedEvent _trace( u
"PointCloud"_s, u
"QgsPointCloudLayerUndoCommand::undoRedoPrivate"_s );
108 QgsCopcPointCloudIndex *copcIndex =
dynamic_cast<QgsCopcPointCloudIndex *
>( editIndex->
backingIndex().get() );
111 QtConcurrent::blockingMap(
112 mPerNodeData.keyValueBegin(),
113 mPerNodeData.keyValueEnd(),
114 [editIndex, copcIndex, isUndo, attribute = mAttribute, newValue = mNewValue](
115 std::pair<const QgsPointCloudNodeId &, PerNodeData &> pair
118 QgsPointCloudNodeId node = pair.first;
119 PerNodeData &perNodeData = pair.second;
121 QByteArray chunkData = editIndex->rawEditedNodeData( node );
122 if ( chunkData.isEmpty() )
123 chunkData = copcIndex->rawNodeData( node );
126 if ( isUndo && perNodeData.firstEdit )
128 editIndex->resetNodeEdits( node );
143 for (
auto it = mPerNodeData.constBegin(); it != mPerNodeData.constEnd(); it++ )
145 emit mLayer->chunkAttributeValuesChanged( it.key() );
A 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.
A QgsPointCloudIndex that is used as an editing buffer when editing point cloud data.
QgsPointCloudIndex backingIndex() const
Returns index for the underlying non-edited data.
bool isNodeModified(QgsPointCloudNodeId n) const
Returns true if this node was modified.
bool updateNodeData(const QHash< QgsPointCloudNodeId, QByteArray > &data) override
Tries to update the data for the specified nodes.
Smart pointer for QgsAbstractPointCloudIndex.
std::unique_ptr< QgsPointCloudBlock > nodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)
Returns node data block.
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(QgsPointCloudLayer *layer, const QHash< QgsPointCloudNodeId, QVector< int > > &nodesAndPoints, const QgsPointCloudAttribute &attribute, double value)
Constructor for QgsPointCloudLayerUndoCommandChangeAttribute.
QgsPointCloudLayerUndoCommand(QgsPointCloudLayer *layer)
Ctor.
QgsPointCloudLayer * mLayer
Represents a map layer supporting display of point clouds.
QgsPointCloudIndex index() const
Returns the point cloud index associated with the layer.
Represents an indexed point cloud node's position in octree.
Point cloud data request.
void setIgnoreIndexFilterEnabled(bool enable)
When enable is true, the request will ignore the point cloud index's filter expression and use an emp...
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.