Skip to content

Commit eedea26

Browse files
committedNov 12, 2020
Quick hack and add combo box to select attribute for 2d point cloud rendering
For proof of concept testing only!
1 parent 3798f14 commit eedea26

File tree

5 files changed

+104
-37
lines changed

5 files changed

+104
-37
lines changed
 

‎src/app/pointcloud/qgspointcloudlayerproperties.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
5959
metadataFrame->setLayout( layout );
6060
mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
6161

62+
mAttributeComboBox->setFilters( QgsPointCloudAttributeProxyModel::Numeric );
63+
mAttributeComboBox->setLayer( mLayer );
64+
6265
// update based on lyr's current state
6366
syncToLayer();
6467

@@ -104,6 +107,7 @@ void QgsPointCloudLayerProperties::apply()
104107
mMetadataWidget->acceptMetadata();
105108

106109
// TODO -- move to proper widget classes!
110+
mLayer->setCustomProperty( QStringLiteral( "pcAttribute" ), mAttributeComboBox->currentAttribute() );
107111
mLayer->setCustomProperty( QStringLiteral( "pcMin" ), mMinZSpin->value() );
108112
mLayer->setCustomProperty( QStringLiteral( "pcMax" ), mMaxZSpin->value() );
109113
mLayer->setCustomProperty( QStringLiteral( "pcRamp" ), mBtnColorRamp->colorRampName().isEmpty() ? QStringLiteral( "Viridis" ) : mBtnColorRamp->colorRampName() );
@@ -138,6 +142,7 @@ void QgsPointCloudLayerProperties::syncToLayer()
138142
connect( mInformationTextBrowser, &QTextBrowser::anchorClicked, this, &QgsPointCloudLayerProperties::urlClicked );
139143

140144
// TODO -- move to proper widget classes!
145+
mAttributeComboBox->setAttribute( mLayer->customProperty( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ).toString() );
141146
mMinZSpin->setValue( mLayer->customProperty( QStringLiteral( "pcMin" ), 400 ).toInt() );
142147
mMaxZSpin->setValue( mLayer->customProperty( QStringLiteral( "pcMax" ), 600 ).toInt() );
143148
mBtnColorRamp->setColorRampFromName( mLayer->customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() );

‎src/core/pointcloud/qgspointcloudlayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMess
136136
setCustomProperty( QStringLiteral( "pcMin" ), elemRenderer.attribute( QStringLiteral( "pcMin" ), QStringLiteral( "400" ) ).toInt() );
137137
setCustomProperty( QStringLiteral( "pcMax" ), elemRenderer.attribute( QStringLiteral( "pcMax" ), QStringLiteral( "600" ) ).toInt() );
138138
setCustomProperty( QStringLiteral( "pcRamp" ), elemRenderer.attribute( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ) );
139+
setCustomProperty( QStringLiteral( "pcAttribute" ), elemRenderer.attribute( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ) );
139140
}
140141

141142
return true;
@@ -156,6 +157,7 @@ bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QStr
156157
elemRenderer.setAttribute( QStringLiteral( "pcMin" ), customProperty( QStringLiteral( "pcMin" ), 400 ).toInt() );
157158
elemRenderer.setAttribute( QStringLiteral( "pcMax" ), customProperty( QStringLiteral( "pcMax" ), 600 ).toInt() );
158159
elemRenderer.setAttribute( QStringLiteral( "pcRamp" ), customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() );
160+
elemRenderer.setAttribute( QStringLiteral( "pcAttribute" ), customProperty( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ).toString() );
159161
elem.appendChild( elemRenderer );
160162
}
161163

‎src/core/pointcloud/qgspointcloudrenderer.cpp

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ float QgsPointCloudRendererConfig::maximumScreenError() const
9292
return mMaximumScreenError;
9393
}
9494

95+
QString QgsPointCloudRendererConfig::attribute() const
96+
{
97+
return mAttribute;
98+
}
99+
100+
void QgsPointCloudRendererConfig::setAttribute( const QString &attribute )
101+
{
102+
mAttribute = attribute;
103+
}
104+
95105
///@endcond
96106

97107
QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *layer, QgsRenderContext &context )
@@ -104,11 +114,22 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye
104114
mConfig.setZMin( layer->customProperty( QStringLiteral( "pcMin" ), 400 ).toInt() );
105115
mConfig.setZMax( layer->customProperty( QStringLiteral( "pcMax" ), 600 ).toInt() );
106116
mConfig.setColorRamp( QgsStyle::defaultStyle()->colorRamp( layer->customProperty( QStringLiteral( "pcRamp" ), QStringLiteral( "Viridis" ) ).toString() ) );
117+
mConfig.setAttribute( layer->customProperty( QStringLiteral( "pcAttribute" ), QStringLiteral( "Z" ) ).toString() );
107118

108119
// TODO: we must not keep pointer to mLayer (it's dangerous) - we must copy anything we need for rendering
109120
// or use some locking to prevent read/write from multiple threads
110121
if ( !mLayer || !mLayer->dataProvider() || !mLayer->dataProvider()->index() )
111122
return;
123+
124+
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
125+
mAttributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) );
126+
127+
int offset;
128+
const QgsPointCloudAttribute *renderAttribute = mLayer->attributes().find( mConfig.attribute(), offset );
129+
if ( !renderAttribute )
130+
return;
131+
132+
mAttributes.push_back( *renderAttribute );
112133
}
113134

114135
bool QgsPointCloudLayerRenderer::render()
@@ -151,13 +172,8 @@ bool QgsPointCloudLayerRenderer::render()
151172
qDebug() << "canceled";
152173
break;
153174
}
154-
QgsPointCloudAttributeCollection attributes;
155-
attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
156-
attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Y" ), QgsPointCloudAttribute::Int32 ) );
157-
attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Z" ), QgsPointCloudAttribute::Int32 ) );
158-
attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "Classification" ), QgsPointCloudAttribute::Char ) );
159175
QgsPointCloudRequest request;
160-
request.setAttributes( attributes );
176+
request.setAttributes( mAttributes );
161177
std::unique_ptr<QgsPointCloudBlock> block( pc->nodeData( n, request ) );
162178
drawData( painter, block.get(), mConfig );
163179
}
@@ -229,21 +245,43 @@ void QgsPointCloudLayerRenderer::drawData( QPainter *painter, const QgsPointClou
229245

230246
for ( int i = 0; i < count; ++i )
231247
{
232-
// TODO generic based on reques
248+
// TODO clean up!
233249
qint32 ix = *( qint32 * )( ptr + i * recordSize + 0 );
234250
qint32 iy = *( qint32 * )( ptr + i * recordSize + 4 );
235-
qint32 iz = *( qint32 * )( ptr + i * recordSize + 8 );
236-
char cls = *( char * )( ptr + i * recordSize + 12 );
237-
Q_UNUSED( cls );
238251

239252
double x = offset.x() + scale.x() * ix;
240253
double y = offset.y() + scale.y() * iy;
241254
if ( mapExtent.contains( QgsPointXY( x, y ) ) )
242255
{
243-
double z = offset.z() + scale.z() * iz;
256+
double atr = 0;
257+
switch ( mAttributes.at( 2 ).type() )
258+
{
259+
case QgsPointCloudAttribute::Char:
260+
continue;
261+
262+
case QgsPointCloudAttribute::Int32:
263+
atr = *( qint32 * )( ptr + i * recordSize + 8 );
264+
break;
265+
266+
case QgsPointCloudAttribute::Short:
267+
atr = *( short * )( ptr + i * recordSize + 8 );
268+
break;
269+
270+
case QgsPointCloudAttribute::Float:
271+
atr = *( float * )( ptr + i * recordSize + 8 );
272+
break;
273+
274+
case QgsPointCloudAttribute::Double:
275+
atr = *( double * )( ptr + i * recordSize + 8 );
276+
break;
277+
}
278+
279+
if ( mAttributes.at( 2 ).name() == QLatin1String( "Z" ) )
280+
atr = offset.z() + scale.z() * atr;
281+
244282
mapToPixel.transformInPlace( x, y );
245283

246-
pen.setColor( config.colorRamp()->color( ( z - config.zMin() ) / ( config.zMax() - config.zMin() ) ) );
284+
pen.setColor( config.colorRamp()->color( ( atr - config.zMin() ) / ( config.zMax() - config.zMin() ) ) );
247285
painter->setPen( pen );
248286
painter->drawPoint( QPointF( x, y ) );
249287
}

‎src/core/pointcloud/qgspointcloudrenderer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ class CORE_EXPORT QgsPointCloudRendererConfig
7474
//! Returns maximum allowed screen error in pixels
7575
float maximumScreenError() const;
7676

77+
QString attribute() const;
78+
void setAttribute( const QString &attribute );
79+
7780
private:
7881
double mZMin = 0, mZMax = 0;
82+
QString mAttribute;
7983
int mPenWidth = 1;
8084
std::unique_ptr<QgsColorRamp> mColorRamp;
8185
float mMaximumScreenError = 5;
@@ -112,6 +116,8 @@ class CORE_EXPORT QgsPointCloudLayerRenderer: public QgsMapLayerRenderer
112116

113117
QgsPointCloudRendererConfig mConfig;
114118

119+
QgsPointCloudAttributeCollection mAttributes;
120+
115121
// int imgW, imgH; // DO WE NEED AT ALL?
116122
// QgsPointCloudDataBounds mBounds; // DO WE NEED AT ALL?
117123

@@ -120,6 +126,7 @@ class CORE_EXPORT QgsPointCloudLayerRenderer: public QgsMapLayerRenderer
120126
int pointsDrawn = 0;
121127

122128
void drawData( QPainter *painter, const QgsPointCloudBlock *data, const QgsPointCloudRendererConfig &config );
129+
123130
};
124131
#endif
125132

‎src/ui/qgspointcloudlayerpropertiesbase.ui

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,21 @@
199199
</widget>
200200
<widget class="QWidget" name="page">
201201
<layout class="QGridLayout" name="gridLayout_2">
202-
<item row="2" column="0">
202+
<item row="3" column="0">
203203
<widget class="QLabel" name="label_3">
204204
<property name="text">
205205
<string>Ramp</string>
206206
</property>
207207
</widget>
208208
</item>
209-
<item row="0" column="0">
210-
<widget class="QLabel" name="label">
211-
<property name="text">
212-
<string>Min z</string>
213-
</property>
214-
</widget>
215-
</item>
216-
<item row="1" column="0">
209+
<item row="2" column="0">
217210
<widget class="QLabel" name="label_2">
218211
<property name="text">
219-
<string>Max z</string>
212+
<string>Max</string>
220213
</property>
221214
</widget>
222215
</item>
223-
<item row="2" column="1">
216+
<item row="3" column="1">
224217
<widget class="QgsColorRampButton" name="mBtnColorRamp">
225218
<property name="sizePolicy">
226219
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -242,7 +235,7 @@
242235
</property>
243236
</widget>
244237
</item>
245-
<item row="3" column="1">
238+
<item row="4" column="1">
246239
<spacer name="verticalSpacer">
247240
<property name="orientation">
248241
<enum>Qt::Vertical</enum>
@@ -255,7 +248,7 @@
255248
</property>
256249
</spacer>
257250
</item>
258-
<item row="1" column="2">
251+
<item row="2" column="2">
259252
<spacer name="horizontalSpacer">
260253
<property name="orientation">
261254
<enum>Qt::Horizontal</enum>
@@ -268,23 +261,40 @@
268261
</property>
269262
</spacer>
270263
</item>
264+
<item row="1" column="0">
265+
<widget class="QLabel" name="label">
266+
<property name="text">
267+
<string>Min</string>
268+
</property>
269+
</widget>
270+
</item>
271271
<item row="0" column="1">
272-
<widget class="QgsSpinBox" name="mMinZSpin">
273-
<property name="minimum">
274-
<number>-999999999</number>
272+
<widget class="QgsPointCloudAttributeComboBox" name="mAttributeComboBox"/>
273+
</item>
274+
<item row="0" column="0">
275+
<widget class="QLabel" name="label_4">
276+
<property name="text">
277+
<string>Attribute</string>
278+
</property>
279+
</widget>
280+
</item>
281+
<item row="1" column="1">
282+
<widget class="QgsDoubleSpinBox" name="mMinZSpin">
283+
<property name="decimals">
284+
<number>5</number>
275285
</property>
276286
<property name="maximum">
277-
<number>999999999</number>
287+
<double>999999.000000000000000</double>
278288
</property>
279289
</widget>
280290
</item>
281-
<item row="1" column="1">
282-
<widget class="QgsSpinBox" name="mMaxZSpin">
283-
<property name="minimum">
284-
<number>-999999999</number>
291+
<item row="2" column="1">
292+
<widget class="QgsDoubleSpinBox" name="mMaxZSpin">
293+
<property name="decimals">
294+
<number>5</number>
285295
</property>
286296
<property name="maximum">
287-
<number>999999999</number>
297+
<double>999999.000000000000000</double>
288298
</property>
289299
</widget>
290300
</item>
@@ -377,9 +387,14 @@
377387
<container>1</container>
378388
</customwidget>
379389
<customwidget>
380-
<class>QgsSpinBox</class>
381-
<extends>QSpinBox</extends>
382-
<header>qgsspinbox.h</header>
390+
<class>QgsPointCloudAttributeComboBox</class>
391+
<extends>QComboBox</extends>
392+
<header>qgspointcloudattributecombobox.h</header>
393+
</customwidget>
394+
<customwidget>
395+
<class>QgsDoubleSpinBox</class>
396+
<extends>QDoubleSpinBox</extends>
397+
<header>qgsdoublespinbox.h</header>
383398
</customwidget>
384399
</customwidgets>
385400
<tabstops>

0 commit comments

Comments
 (0)
Please sign in to comment.