27using namespace Qt::StringLiterals;
39 auto res = std::make_unique< QgsPointCloudRgbRenderer >();
40 res->mRedAttribute = mRedAttribute;
41 res->mGreenAttribute = mGreenAttribute;
42 res->mBlueAttribute = mBlueAttribute;
44 if ( mRedContrastEnhancement )
48 if ( mGreenContrastEnhancement )
52 if ( mBlueContrastEnhancement )
69 visibleExtent.
grow( std::max( visibleExtent.
width(), visibleExtent.
height() ) * 0.05 );
72 const char *ptr = block->
data();
84 attribute = request.
find( mGreenAttribute, greenOffset );
90 attribute = request.
find( mBlueAttribute, blueOffset );
101 const bool considerZ = !zRange.
isInfinite() || renderElevation;
108 const bool reproject = ct.
isValid();
111 for (
int i = 0; i < count; ++i )
121 z =
pointZ( context, ptr, i );
126 pointXY( context, ptr, i, x, y );
127 if ( visibleExtent.
contains( x, y ) )
142 context.
getAttribute( ptr, i * recordSize + redOffset, redType, red );
144 context.
getAttribute( ptr, i * recordSize + greenOffset, greenType, green );
146 context.
getAttribute( ptr, i * recordSize + blueOffset, blueType, blue );
149 if ( ( useRedContrastEnhancement && !mRedContrastEnhancement->isValueInDisplayableRange( red ) )
150 || ( useGreenContrastEnhancement && !mGreenContrastEnhancement->isValueInDisplayableRange( green ) )
151 || ( useBlueContrastEnhancement && !mBlueContrastEnhancement->isValueInDisplayableRange( blue ) ) )
157 if ( useRedContrastEnhancement )
159 red = mRedContrastEnhancement->enhanceContrast( red );
161 if ( useGreenContrastEnhancement )
163 green = mGreenContrastEnhancement->enhanceContrast( green );
165 if ( useBlueContrastEnhancement )
167 blue = mBlueContrastEnhancement->enhanceContrast( blue );
170 red = std::max( 0, std::min( 255, red ) );
171 green = std::max( 0, std::min( 255, green ) );
172 blue = std::max( 0, std::min( 255, blue ) );
174 QColor color( red, green, blue );
175 if ( dataDefinedPropertiesActive )
188 if ( renderElevation )
200 auto r = std::make_unique< QgsPointCloudRgbRenderer >();
202 r->setRedAttribute( element.attribute( u
"red"_s, u
"Red"_s ) );
203 r->setGreenAttribute( element.attribute( u
"green"_s, u
"Green"_s ) );
204 r->setBlueAttribute( element.attribute( u
"blue"_s, u
"Blue"_s ) );
206 r->restoreCommonProperties( element, context );
210 const QDomElement redContrastElem = element.firstChildElement( u
"redContrastEnhancement"_s );
211 if ( !redContrastElem.isNull() )
219 const QDomElement greenContrastElem = element.firstChildElement( u
"greenContrastEnhancement"_s );
220 if ( !greenContrastElem.isNull() )
228 const QDomElement blueContrastElem = element.firstChildElement( u
"blueContrastEnhancement"_s );
229 if ( !blueContrastElem.isNull() )
241 QDomElement rendererElem = doc.createElement( u
"renderer"_s );
243 rendererElem.setAttribute( u
"type"_s, u
"rgb"_s );
245 rendererElem.setAttribute( u
"red"_s, mRedAttribute );
246 rendererElem.setAttribute( u
"green"_s, mGreenAttribute );
247 rendererElem.setAttribute( u
"blue"_s, mBlueAttribute );
252 if ( mRedContrastEnhancement )
254 QDomElement redContrastElem = doc.createElement( u
"redContrastEnhancement"_s );
255 mRedContrastEnhancement->writeXml( doc, redContrastElem );
256 rendererElem.appendChild( redContrastElem );
258 if ( mGreenContrastEnhancement )
260 QDomElement greenContrastElem = doc.createElement( u
"greenContrastEnhancement"_s );
261 mGreenContrastEnhancement->writeXml( doc, greenContrastElem );
262 rendererElem.appendChild( greenContrastElem );
264 if ( mBlueContrastEnhancement )
266 QDomElement blueContrastElem = doc.createElement( u
"blueContrastEnhancement"_s );
267 mBlueContrastEnhancement->writeXml( doc, blueContrastElem );
268 rendererElem.appendChild( blueContrastElem );
277 res << mRedAttribute << mGreenAttribute << mBlueAttribute;
283 auto data = std::make_unique< QgsPointCloudRgbRendererPreparedData >();
284 data->redAttribute = mRedAttribute;
285 if ( mRedContrastEnhancement )
286 data->redContrastEnhancement = std::make_unique<QgsContrastEnhancement>( *mRedContrastEnhancement );
287 data->greenAttribute = mGreenAttribute;
288 if ( mGreenContrastEnhancement )
289 data->greenContrastEnhancement = std::make_unique<QgsContrastEnhancement>( *mGreenContrastEnhancement );
290 data->blueAttribute = mBlueAttribute;
291 if ( mBlueContrastEnhancement )
292 data->blueContrastEnhancement = std::make_unique<QgsContrastEnhancement>( *mBlueContrastEnhancement );
331 const char *ptr = block->
data();
363 red = std::max( 0, std::min( 255, red ) );
364 green = std::max( 0, std::min( 255, green ) );
365 blue = std::max( 0, std::min( 255, blue ) );
367 return QColor( red, green, blue );
372 return mRedAttribute;
382 return mGreenAttribute;
392 return mBlueAttribute;
402 return mRedContrastEnhancement.get();
407 mRedContrastEnhancement.reset( enhancement );
412 return mGreenContrastEnhancement.get();
417 mGreenContrastEnhancement.reset( enhancement );
422 return mBlueContrastEnhancement.get();
427 mBlueContrastEnhancement.reset( enhancement );
@ UnknownDataType
Unknown or unspecified type.
Handles contrast enhancement and clipping.
@ NoEnhancement
Default color scaling algorithm, no scaling is applied.
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.
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.
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...
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.
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.
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.
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.
bool useRedContrastEnhancement
std::unique_ptr< QgsContrastEnhancement > redContrastEnhancement
QSet< QString > usedAttributes() const override
Returns the set of attributes used by the prepared point cloud renderer.
std::unique_ptr< QgsContrastEnhancement > greenContrastEnhancement
bool prepareBlock(const QgsPointCloudBlock *block) override
Prepares the renderer for using the specified block.
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.
bool useGreenContrastEnhancement
std::unique_ptr< QgsContrastEnhancement > blueContrastEnhancement
QgsPointCloudAttribute::DataType blueType
bool useBlueContrastEnhancement
QgsPointCloudAttribute::DataType redType
QgsPointCloudAttribute::DataType greenType
std::unique_ptr< QgsPreparedPointCloudRendererData > prepare() override
Returns prepared data container for bulk point color retrieval.
void setRedContrastEnhancement(QgsContrastEnhancement *enhancement)
Sets the contrast enhancement to use for the red channel.
QString redAttribute() const
Returns the attribute to use for the red channel.
static QgsPointCloudRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates an RGB renderer from an XML element.
QString greenAttribute() const
Returns the attribute to use for the green channel.
QString type() const override
Returns the identifier of the renderer type.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Saves the renderer configuration to an XML element.
void setBlueContrastEnhancement(QgsContrastEnhancement *enhancement)
Sets the contrast enhancement to use for the blue channel.
void renderBlock(const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context) override
Renders a block of point cloud data using the specified render context.
const QgsContrastEnhancement * greenContrastEnhancement() const
Returns the contrast enhancement to use for the green channel.
QString blueAttribute() const
Returns the attribute to use for the blue channel.
QgsPointCloudRgbRenderer()
Constructor for QgsPointCloudRgbRenderer.
void setGreenContrastEnhancement(QgsContrastEnhancement *enhancement)
Sets the contrast enhancement to use for the green channel.
void setBlueAttribute(const QString &attribute)
Sets the attribute to use for the blue channel.
const QgsContrastEnhancement * blueContrastEnhancement() const
Returns the contrast enhancement to use for the blue channel.
void setGreenAttribute(const QString &attribute)
Sets the attribute to use for the green channel.
void setRedAttribute(const QString &attribute)
Sets the attribute to use for the red channel.
QgsPointCloudRenderer * clone() const override
Create a deep copy of this renderer.
const QgsContrastEnhancement * redContrastEnhancement() const
Returns the contrast enhancement to use for the red channel.
QSet< QString > usedAttributes(const QgsPointCloudRenderContext &context) const override
Returns a list of attributes required by this renderer.
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.
A container for the context for various read/write operations on objects.
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.
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.