Skip to content

Commit

Permalink
Move some code to reusable methods in QgsPointCloudRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 2, 2020
1 parent ef8bd49 commit 8ba9866
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 82 deletions.
Expand Up @@ -111,6 +111,7 @@ Returns the offset for the y value in a point record.
.. seealso:: :py:func:`yOffset`
%End


private:
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh );
};
Expand Down Expand Up @@ -335,6 +336,11 @@ Sets the ``unit`` for the maximum screen error allowed when rendering the point
static void pointXY( QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y );
%Docstring
Retrieves the x and y coordinate for the point at index ``i``.
%End

static double pointZ( QgsPointCloudRenderContext &context, const char *ptr, int i );
%Docstring
Retrieves the z value for the point at index ``i``.
%End

void copyCommonProperties( QgsPointCloudRenderer *destination ) const;
Expand Down
52 changes: 49 additions & 3 deletions src/core/pointcloud/qgspointcloudrenderer.h
Expand Up @@ -131,6 +131,44 @@ class CORE_EXPORT QgsPointCloudRenderContext
*/
int zOffset() const { return mZOffset; }

#ifndef SIP_RUN

/**
* Retrieves the attribute \a value from \a data at the specified \a offset, where
* \a type indicates the original data type for the attribute.
*/
template <typename T>
void getAttribute( const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value ) const
{
switch ( type )
{
case QgsPointCloudAttribute::Char:
value = *( data + offset );
return;

case QgsPointCloudAttribute::Int32:
value = *reinterpret_cast< const qint32 * >( data + offset );
return;

case QgsPointCloudAttribute::Short:
value = *reinterpret_cast< const short * >( data + offset );
return;

case QgsPointCloudAttribute::UShort:
value = *reinterpret_cast< const unsigned short * >( data + offset );
return;

case QgsPointCloudAttribute::Float:
value = *reinterpret_cast< const float * >( data + offset );
return;

case QgsPointCloudAttribute::Double:
value = *reinterpret_cast< const double * >( data + offset );
return;
}
}
#endif

private:
#ifdef SIP_RUN
QgsPointCloudRenderContext( const QgsPointCloudRenderContext &rh );
Expand Down Expand Up @@ -348,13 +386,21 @@ class CORE_EXPORT QgsPointCloudRenderer
*/
static void pointXY( QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y )
{
qint32 ix = *( qint32 * )( ptr + i * context.pointRecordSize() + context.xOffset() );
qint32 iy = *( qint32 * )( ptr + i * context.pointRecordSize() + context.yOffset() );

const qint32 ix = *reinterpret_cast< const qint32 * >( ptr + i * context.pointRecordSize() + context.xOffset() );
const qint32 iy = *reinterpret_cast< const qint32 * >( ptr + i * context.pointRecordSize() + context.yOffset() );
x = context.offset().x() + context.scale().x() * ix;
y = context.offset().y() + context.scale().y() * iy;
}

/**
* Retrieves the z value for the point at index \a i.
*/
static double pointZ( QgsPointCloudRenderContext &context, const char *ptr, int i )
{
const qint32 iz = *reinterpret_cast<const qint32 * >( ptr + i * context.pointRecordSize() + context.zOffset() );
return context.offset().z() + context.scale().z() * iz;
}

/**
* Copies common point cloud properties (such as point size and screen error) to the \a destination renderer.
*/
Expand Down
83 changes: 4 additions & 79 deletions src/core/pointcloud/qgspointcloudrgbrenderer.cpp
Expand Up @@ -106,8 +106,7 @@ void QgsPointCloudRgbRenderer::renderBlock( const QgsPointCloudBlock *block, Qgs
if ( considerZ )
{
// z value filtering is cheapest, if we're doing it...
qint32 iz = *( qint32 * )( ptr + i * context.pointRecordSize() + context.zOffset() );
z = context.offset().z() + context.scale().z() * iz;
z = pointZ( context, ptr, i );
if ( !zRange.contains( z ) )
continue;
}
Expand All @@ -128,85 +127,11 @@ void QgsPointCloudRgbRenderer::renderBlock( const QgsPointCloudBlock *block, Qgs
}

int red = 0;
switch ( redType )
{
case QgsPointCloudAttribute::Char:
continue;

case QgsPointCloudAttribute::Int32:
red = *( qint32 * )( ptr + i * recordSize + redOffset );
break;

case QgsPointCloudAttribute::Short:
red = *( short * )( ptr + i * recordSize + redOffset );
break;

case QgsPointCloudAttribute::UShort:
red = *( unsigned short * )( ptr + i * recordSize + redOffset );
break;

case QgsPointCloudAttribute::Float:
red = *( float * )( ptr + i * recordSize + redOffset );
break;

case QgsPointCloudAttribute::Double:
red = *( double * )( ptr + i * recordSize + redOffset );
break;
}

context.getAttribute( ptr, i * recordSize + redOffset, redType, red );
int green = 0;
switch ( greenType )
{
case QgsPointCloudAttribute::Char:
continue;

case QgsPointCloudAttribute::Int32:
green = *( qint32 * )( ptr + i * recordSize + greenOffset );
break;

case QgsPointCloudAttribute::Short:
green = *( short * )( ptr + i * recordSize + greenOffset );
break;

case QgsPointCloudAttribute::UShort:
green = *( unsigned short * )( ptr + i * recordSize + greenOffset );
break;

case QgsPointCloudAttribute::Float:
green = *( float * )( ptr + i * recordSize + greenOffset );
break;

case QgsPointCloudAttribute::Double:
green = *( double * )( ptr + i * recordSize + greenOffset );
break;
}

context.getAttribute( ptr, i * recordSize + greenOffset, greenType, green );
int blue = 0;
switch ( blueType )
{
case QgsPointCloudAttribute::Char:
continue;

case QgsPointCloudAttribute::Int32:
blue = *( qint32 * )( ptr + i * recordSize + blueOffset );
break;

case QgsPointCloudAttribute::Short:
blue = *( short * )( ptr + i * recordSize + blueOffset );
break;

case QgsPointCloudAttribute::UShort:
blue = *( unsigned short * )( ptr + i * recordSize + blueOffset );
break;

case QgsPointCloudAttribute::Float:
blue = *( float * )( ptr + i * recordSize + blueOffset );
break;

case QgsPointCloudAttribute::Double:
blue = *( double * )( ptr + i * recordSize + blueOffset );
break;
}
context.getAttribute( ptr, i * recordSize + blueOffset, blueType, blue );

//skip if red, green or blue not in displayable range
if ( ( useRedContrastEnhancement && !mRedContrastEnhancement->isValueInDisplayableRange( red ) )
Expand Down

0 comments on commit 8ba9866

Please sign in to comment.