PDA

View Full Version : Q3DSurface and contouring



baray98
27th January 2021, 23:37
Hello,

I am Q3DSurface to display my 3D data in my desktop app. I want to add more into the 3D plot like the following

Contour lines given contour levels
multiple markers placed in an XYZ location

Can someone give me some hints or share some experience about these items?
Any idea will be appreciated,
baray98

Added after 10 minutes:


Hello,

I am Q3DSurface to display my 3D data in my desktop app. I want to add more into the 3D plot like the following

Contour lines given contour levels
multiple markers placed in an XYZ location

Can someone give me some hints or share some experience about these items?
Any idea will be appreciated,
baray98

P.S. I can even abandon Qt 3D Visualization if I can find a good 3D plot library that can suffice my reqs

d_stranz
28th January 2021, 03:52
I can even abandon Qt 3D Visualization if I can find a good 3D plot library that can suffice my reqs

If you find one, post the link. I've been looking for years with no luck. The Qt folks really screwed up with the Qt Charts and Qt Data Visualization frameworks by making it impossible to extend them in any way. Not a virtual method to be found anywhere. You get what they give you and that's it.

Other frameworks like VTK are as huge as Qt.

baray98
29th January 2021, 18:07
Trying VTK and update this thread soon

d_stranz
29th January 2021, 18:33
Trying VTK and update this thread soon

I've done a few small things with VTK, but the learning curve is really tough, and aside from being able to host a VTK window in a QWidget, there isn't much integration with other Qt data structures. Good luck.

baray98
10th February 2021, 19:55
Took me 2 days to figure out how to host vtkContextView in QVTKOpenGLStereoWidge. I have a surface plot on it but it looks primitive. Not a whole lot of tutorial out there. Are there any good looking ones like (Q3DSurface ) out there that I could try? Suggestions are welcome.

baray98
11th February 2021, 23:35
I actually managed to do contouring with Q3dSurface by combining QwtPlotSpectrogram;

see piture13593

IDEA:


Initialize Q3DSurfaceSeries with QwtRaster from QwtPlotSpectogram to get Z values;
Get QwtPlotSpectogram draw the image into QImage QwtPlotSpectogram ::draw();
Use image as texture of Q3dSurfaceSeries Q3dSurfaceSeries::setTexture(QImage);
So contouring is just a matter of setting spectogram to turn it on or off;
That should do it .. play with resolution along x and y for satisfaction.




void RasterSurfaceSeries::refresh(const Comn::Range<double>& range)
{

auto pixelHint = p_data->m_spectro->pixelHint(QRectF(0,0,range.end - range.start,
p_data->m_yRange.end - p_data->m_yRange.start));
double dx = 0.001;
double dy = 0.001;
if (pixelHint.isValid())
{
dx = pixelHint.width();
dy = pixelHint.height();
}
double xPan = range.end - range.start;
double yPan = p_data->m_yRange.end - p_data->m_yRange.start;

int height = yPan / dy ;
int width = xPan / dx ;
QSize plotSize (width,height);

auto rasterData = p_data->m_spectro->data();

QSurfaceDataArray *dataArray = new QSurfaceDataArray;
dataArray->reserve(height);
for (int i = 0; i < height; i++) {
QSurfaceDataRow *newRow = new QSurfaceDataRow(width);
for (int j = 0; j < width; j++) {
float x = float(j) * dx + range.start;
float y = float(i) * dy + p_data->m_yRange.start;
float z = rasterData->value(x,y) + p_data->m_zOffset;
(*newRow)[j].setPosition(QVector3D(x, z,y));
}
*dataArray << newRow;
}

dataProxy()->resetArray(dataArray);


QImage plotImage = QImage(plotSize,QImage::Format::Format_RGB32);
plotImage.fill(QColor(Qt::white));
QPainter painter(&plotImage);


QwtScaleMap xMap;
xMap.setPaintInterval(0, plotSize.width());
xMap.setScaleInterval(range.start,range.end);

QwtScaleMap yMap;
yMap.setPaintInterval(plotSize.height(), 0); // inverted !!!
yMap.setScaleInterval(p_data->m_yRange.start,p_data->m_yRange.end);

p_data->m_spectro->draw(&painter, xMap, yMap, QRect(QPoint(0, 0), plotSize));
setTexture(plotImage);
}