28using namespace Qt::StringLiterals;
48 : mAttribute( attributeName )
54 return u
"classified"_s;
59 auto res = std::make_unique< QgsPointCloudClassifiedRenderer >();
60 res->mAttribute = mAttribute;
61 res->mCategories = mCategories;
75 visibleExtent.
grow( std::max( visibleExtent.
width(), visibleExtent.
height() ) * 0.05 );
78 const char *ptr = block->
data();
83 int attributeOffset = 0;
98 const bool reproject = ct.
isValid();
100 QHash< int, QColor > colors;
101 QHash< int, int > pointSizes;
106 if ( !category.renderState() )
109 colors.insert( category.value(), category.color() );
111 const double size = category.pointSize() > 0 ? category.pointSize() :
pointSize();
115 for (
int i = 0; i < count; ++i )
125 z =
pointZ( context, ptr, i );
130 int attributeValue = 0;
131 context.
getAttribute( ptr, i * recordSize + attributeOffset, attributeType, attributeValue );
132 QColor color = colors.value( attributeValue );
133 if ( !color.isValid() )
136 if ( dataDefinedPropertiesActive )
139 pointXY( context, ptr, i, x, y );
140 if ( visibleExtent.
contains( x, y ) )
166 const double size = pointSizes.value( attributeValue );
168 if ( renderElevation )
179 if ( !pointAttributes.contains( mAttribute ) )
181 bool parsedCorrectly;
182 int attributeInt = pointAttributes[mAttribute].toInt( &parsedCorrectly );
183 if ( !parsedCorrectly )
187 if ( category.value() == attributeInt )
188 return category.renderState();
195 auto r = std::make_unique< QgsPointCloudClassifiedRenderer >();
197 r->setAttribute( element.attribute( u
"attribute"_s, u
"Classification"_s ) );
200 const QDomElement catsElem = element.firstChildElement( u
"categories"_s );
201 if ( !catsElem.isNull() )
203 QDomElement catElem = catsElem.firstChildElement();
204 while ( !catElem.isNull() )
206 if ( catElem.tagName() ==
"category"_L1 )
208 const int value = catElem.attribute( u
"value"_s ).toInt();
209 const double size = catElem.attribute( u
"pointSize"_s, u
"0"_s ).toDouble();
211 QgsDebugMsgLevel(
"context" + u
"project:layers:%1:legendsymbollabels"_s.arg( context.
currentLayerId() ) +
" source " + catElem.attribute( u
"label"_s ), 3 );
213 const bool render = catElem.attribute( u
"render"_s ) !=
"false"_L1;
217 catElem = catElem.nextSiblingElement();
222 r->restoreCommonProperties( element, context );
253 QDomElement rendererElem = doc.createElement( u
"renderer"_s );
255 rendererElem.setAttribute( u
"type"_s, u
"classified"_s );
256 rendererElem.setAttribute( u
"attribute"_s, mAttribute );
259 QDomElement catsElem = doc.createElement( u
"categories"_s );
262 QDomElement catElem = doc.createElement( u
"category"_s );
263 catElem.setAttribute( u
"value"_s, QString::number( category.value() ) );
264 catElem.setAttribute( u
"pointSize"_s, QString::number( category.pointSize() ) );
265 catElem.setAttribute( u
"label"_s, category.label() );
267 catElem.setAttribute( u
"render"_s, category.renderState() ?
"true" :
"false" );
268 catsElem.appendChild( catElem );
270 rendererElem.appendChild( catsElem );
286 QList<QgsLayerTreeModelLegendNode *> nodes;
290 nodes <<
new QgsRasterSymbolLegendNode( nodeLayer, category.color(), category.label(),
nullptr,
true, QString::number( category.value() ) );
301 res << QString::number( category.value() );
309 const int value = key.toInt( &ok );
315 if ( category.value() == value )
316 return category.renderState();
324 const int value = key.toInt( &ok );
328 for (
auto it = mCategories.begin(); it != mCategories.end(); ++it )
330 if ( it->value() == value )
332 it->setRenderState( state );
360 mCategories.append( category );
365 auto data = std::make_unique< QgsPointCloudClassifiedRendererPreparedData >();
366 data->attributeName = mAttribute;
370 if ( !category.renderState() )
373 data->colors.insert( category.value(), category.color() );
397 int attributeValue = 0;
399 return colors.value( attributeValue );
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Custom exception class for Coordinate Reference System related exceptions.
QgsRange which stores a range of double values.
bool isInfinite() const
Returns true if the range consists of all possible values.
Layer tree node points to a map layer.
A collection of point cloud attributes.
int pointRecordSize() const
Returns total size of record.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
Attribute for point cloud data pair of name and size in bytes.
DataType
Systems of unit measurement.
DataType type() const
Returns the data type.
Base class for storing raw data from point cloud nodes.
const char * data() const
Returns raw pointer to data.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes that are stored in the data block, along with their size.
int pointCount() const
Returns number of points that are stored in the block.
int pointRecordSize() const
Returns the total size of each individual point record.
Represents an individual category (class) from a QgsPointCloudClassifiedRenderer.
QgsPointCloudCategory()=default
int value() const
Returns the value corresponding to this category.
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
QColor color() const
Returns the color which will be used to render this category.
double pointSize() const
Returns the point size for this category.
bool operator==(const QgsPointCloudCategory &other) const
Equality operator.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
QgsPointCloudAttribute::DataType attributeType
QColor pointColor(const QgsPointCloudBlock *block, int i, double z) override
An optimised method of retrieving the color of a point from a point cloud block.
QSet< QString > usedAttributes() const override
Returns the set of attributes used by the prepared point cloud renderer.
bool prepareBlock(const QgsPointCloudBlock *block) override
Prepares the renderer for using the specified block.
QHash< int, QColor > colors
void addCategory(const QgsPointCloudCategory &category)
Adds a category to the renderer.
QString attribute() const
Returns the attribute to use for the renderer.
QgsPointCloudClassifiedRenderer(const QString &attributeName=QString(), const QgsPointCloudCategoryList &categories=QgsPointCloudCategoryList())
Constructor for QgsPointCloudClassifiedRenderer.
bool willRenderPoint(const QVariantMap &pointAttributes) override
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Saves the renderer configuration to an XML element.
void checkLegendItem(const QString &key, bool state=true) override
Called when the check state of the legend item with the specified key is changed.
QSet< QString > usedAttributes(const QgsPointCloudRenderContext &context) const override
Returns a list of attributes required by this renderer.
static QgsPointCloudRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates an RGB renderer from an XML element.
QgsPointCloudCategoryList categories() const
Returns the classification categories used for rendering.
static QgsPointCloudCategoryList defaultCategories()
Returns the default list of categories.
bool legendItemChecked(const QString &key) override
Returns true if the legend item with the specified key is checked.
QgsPointCloudRenderer * clone() const override
Create a deep copy of this renderer.
void setCategories(const QgsPointCloudCategoryList &categories)
Sets the classification categories used for rendering.
QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Creates a set of legend nodes representing the renderer.
void renderBlock(const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context) override
Renders a block of point cloud data using the specified render context.
std::unique_ptr< QgsPreparedPointCloudRendererData > prepare() override
Returns prepared data container for bulk point color retrieval.
QStringList legendRuleKeys() const override
Returns a list of all rule keys for legend nodes created by the renderer.
void setAttribute(const QString &attribute)
Sets the attribute to use for the renderer.
QString type() const override
Returns the identifier of the renderer type.
static QMap< int, QString > translatedLasClassificationCodes()
Returns the map of LAS classification code to translated string value, corresponding to the ASPRS Sta...
Encapsulates the render context for a 2D point cloud rendering operation.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
void incrementPointsRendered(long count)
Increments the count of points rendered by the specified amount.
static void getAttribute(const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value)
Retrieves the attribute value from data at the specified offset, where type indicates the original da...
QgsDoubleRange mapCrsZFilter() const
Returns the allowable range of z values in the map (destination) CRS.
bool renderAsTriangles() const
Returns whether points are triangulated to render solid surface.
void drawPointToElevationMap(double x, double y, double z, QgsPointCloudRenderContext &context) const
Draws a point at the elevation z using at the specified x and y (in map coordinates) on the elevation...
void saveCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Saves common renderer properties (such as point size and screen error) to the specified DOM element.
const QgsMapUnitScale & pointSizeMapUnitScale() const
Returns the map unit scale used for the point size.
QColor colorFromExpression(const QgsPointCloudBlock *block, int pointIndex, const QColor &rendererColor, QgsPointCloudRenderContext &context)
Computes color from the expression set, uses expression referenced variables and renderer base color.
virtual QSet< QString > usedAttributes(const QgsPointCloudRenderContext &context) const
Returns a list of attributes required by this renderer.
void addPointToTriangulation(double x, double y, double z, const QColor &color, QgsPointCloudRenderContext &context)
Adds a point to the list of points to be triangulated (only used when renderAsTriangles() is enabled)...
void copyCommonProperties(QgsPointCloudRenderer *destination) const
Copies common point cloud properties (such as point size and screen error) to the destination rendere...
void drawPoint(double x, double y, const QColor &color, QgsPointCloudRenderContext &context) const
Draws a point using a color at the specified x and y (in map coordinates).
const QgsPropertyCollection & dataDefinedProperties() const
Returns the renderer's property collection, used for data defined overrides.
Qgis::RenderUnit pointSizeUnit() const
Returns the units used for the point size.
double pointSize() const
Returns the point size.
static double pointZ(QgsPointCloudRenderContext &context, const char *ptr, int i)
Retrieves the z value for the point at index i.
static void pointXY(QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y)
Retrieves the x and y coordinate for the point at index i.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
bool contains(const QgsRange< T > &other) const
Returns true if this range contains another range.
Implementation of legend node interface for displaying raster legend entries.
A container for the context for various read/write operations on objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
const QString currentLayerId() const
Returns the currently used layer id as string.
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void grow(double delta)
Grows the rectangle in place by the specified amount.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QgsElevationMap * elevationMap() const
Returns the destination elevation map for the render operation.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QPainter * previewRenderPainter()
Returns the const destination QPainter for temporary in-progress preview renders.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
#define QgsDebugMsgLevel(str, level)
QList< QgsPointCloudCategory > QgsPointCloudCategoryList