25#include <QtConcurrentMap>
27using namespace Qt::StringLiterals;
37 , mAttribute( attribute )
40 QgsEventTracing::ScopedEvent _trace( u
"PointCloud"_s, u
"QgsPointCloudLayerUndoCommand constructor"_s );
42 QList<NodeProcessData> processData;
43 for (
auto it = mappedPoints.constBegin(); it != mappedPoints.constEnd(); ++it )
45 const int position = it.key();
50 index =
mLayer->subIndexes().at( position ).index();
51 const auto &nodes = it.value();
52 for (
auto nodeIt = nodes.constBegin(); nodeIt != nodes.constEnd(); ++nodeIt )
54 processData.append( { position, index, nodeIt.key(), nodeIt.value() } );
58 std::function mapFn = [attribute](
const NodeProcessData &data ) {
62 const QVector<int> &points = data.points;
64 PerNodeData perNodeData;
73 std::unique_ptr<QgsPointCloudBlock> block = index.
nodeData( n, req );
74 const char *ptr = block->data();
75 block->attributes().find( attribute.
name(), perNodeData.attributeOffset );
76 const int size = block->pointRecordSize();
77 for (
const int point : points )
79 const int offset = point * size + perNodeData.attributeOffset;
81 perNodeData.oldPointValues[point] = oldValue;
88 perNodeData.firstEdit =
true;
89 for (
const int point : points )
91 perNodeData.oldPointValues[point] = std::numeric_limits<double>::quiet_NaN();
95 return std::pair { data.position, std::pair { n, perNodeData } };
98 std::function reduceFn = []( QMap<int, QHash<QgsPointCloudNodeId, PerNodeData>> &res,
const std::pair<int, std::pair<QgsPointCloudNodeId, PerNodeData>> &pair ) {
99 res[pair.first][pair.second.first] = pair.second.second;
102 mPerNodeData = QtConcurrent::blockingMappedReduced<QMap<int, QHash<QgsPointCloudNodeId, PerNodeData>>>( processData, std::move( mapFn ), std::move( reduceFn ) );
107 undoRedoPrivate(
true );
112 undoRedoPrivate(
false );
115void QgsPointCloudLayerUndoCommandChangeAttribute::undoRedoPrivate(
bool isUndo )
117 QgsEventTracing::ScopedEvent _trace( u
"PointCloud"_s, u
"QgsPointCloudLayerUndoCommand::undoRedoPrivate"_s );
120 double newValue = mNewValue;
122 for (
auto it = mPerNodeData.begin(); it != mPerNodeData.end(); ++it )
124 const int position = it.key();
125 QHash<QgsPointCloudNodeId, PerNodeData> &nodesData = it.value();
133 QgsCopcPointCloudIndex *copcIndex =
dynamic_cast<QgsCopcPointCloudIndex *
>( editIndex->
backingIndex().get() );
135 QtConcurrent::blockingMap( nodesData.keyValueBegin(), nodesData.keyValueEnd(), [editIndex, copcIndex, isUndo, attribute, newValue]( std::pair<const QgsPointCloudNodeId &, PerNodeData &> pair ) {
136 QgsPointCloudNodeId node = pair.first;
137 PerNodeData &perNodeData = pair.second;
139 QByteArray chunkData = editIndex->rawEditedNodeData( node );
140 if ( chunkData.isEmpty() )
141 chunkData = copcIndex->rawNodeData( node );
144 if ( isUndo && perNodeData.firstEdit )
146 editIndex->resetNodeEdits( node );
160 for (
auto itNode = nodesData.constBegin(); itNode != nodesData.constEnd(); itNode++ )
162 emit
mLayer->chunkAttributeValuesChanged( itNode.key(), position );
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< int, QHash< QgsPointCloudNodeId, QVector< int > > > &mappedPoints, 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.
QVector< QgsPointCloudSubIndex > subIndexes() const
Returns point cloud indexes associated with the layer (only if the layer has a virtual point cloud da...
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.