[vtkusers] vtkCharts: No more Qt text rendering with vtk 5.10?

Arnaud BARRE arnaud.barre at gmail.com
Wed May 23 10:04:48 EDT 2012


Hi,

I am updating Mokka (http://b-tk.googlecode.com/svn/web/mokka/index.html -
a software used in Biomechanics) from VTK 5.6.1 to VTK 5.10 and everything
is fine except the text rendering in the charts.

As there is is lots of differences in the charts module between vtk 5.6.1
and vtk 5.10, I checked if the problem came from my code. For that, I
created a small executable based on the example "Line plot" but embedded in
a QVTKWidget.

The following link (http://derp.co.uk/c040e) gives you the result for VTK
5.6.1 and VTK 5.10. Both version were compiled with Qt 4.7.3 and with the
same options (VTK_USE_QT, VTK_USE_QVTK_QTOPENGL)

As you can see the text rendering is not the same and in the case of
vtk-5.10, the method vtkOpenGLContextDevice2D::SetStringRendererToQt()
returns false (and then "No Qt rendering"  is displayed in the title). I
tested under Windows 7 and MacOS X (Leopard - 10.5.8) and I have each time
the same problem.

Is there anything special to do in VTK 5.10 to have a Qt text rendering in
the charts? Should I use QVTKWidget2?

Regards,

Arnaud

The code is joined in the ZIP file, but if necessary, here is the source
code and the CMake project

*main.cpp*

#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkChartXY.h>
#include <vtkPlot.h>
#include <vtkPen.h>
#include <vtkTable.h>
#include <vtkFloatArray.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
#include <vtkContext2D.h>
#include <vtkOpenGLContextDevice2D.h>
#include <vtkVersion.h>

#include <QApplication>
#include <QVTKWidget.h>

#define VTK_CREATE(type, name) \
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()

int main(int argc, char *argv[])
{
  QApplication app(argc,argv);

  QVTKWidget widget;
  widget.resize(640,480);

  // Set up a 2D scene, add an XY chart to it
  VTK_CREATE(vtkContextView, view);
  VTK_CREATE(vtkChartXY, chart);
  view->GetScene()->AddItem(chart);

  // Link the view with the widget
  view->SetInteractor(widget.GetInteractor());
  widget.SetRenderWindow(view->GetRenderWindow());

  // Create a table with some points in it
  VTK_CREATE(vtkTable, table);

  VTK_CREATE(vtkFloatArray, arrX);
  arrX->SetName("X Axis");
  table->AddColumn(arrX);

  VTK_CREATE(vtkFloatArray, arrC);
  arrC->SetName("Cosine");
  table->AddColumn(arrC);

  VTK_CREATE(vtkFloatArray, arrS);
  arrS->SetName("Sine");
  table->AddColumn(arrS);

  // Fill in the table with some example values
  int numPoints = 69;
  float inc = 7.5 / (numPoints-1);
  table->SetNumberOfRows(numPoints);
  for (int i = 0; i < numPoints; ++i)
  {
    table->SetValue(i, 0, i * inc);
    table->SetValue(i, 1, cos(i * inc));
    table->SetValue(i, 2, sin(i * inc));
  }

  // Add multiple line plots, setting the colors etc
  vtkPlot *line = chart->AddPlot(vtkChart::LINE);
#if VTK_MAJOR_VERSION <= 5
  line->SetInput(table, 0, 1);
#else
  line->SetInputData(table, 0, 1);
#endif
  line->SetColor(0, 255, 0, 255);
  line->SetWidth(1.0);
  line = chart->AddPlot(vtkChart::LINE);
#if VTK_MAJOR_VERSION <= 5
  line->SetInput(table, 0, 2);
#else
  line->SetInputData(table, 0, 2);
#endif
  line->SetColor(255, 0, 0, 255);
  line->SetWidth(5.0);
  line->GetPen()->SetLineType(2);//For dotted line, can be from 2 to 5 for
different dot patterns

  std::string vtkVersion = vtkVersion::GetVTKVersion();
  std::string qtVersion = qVersion();
  std::string title = "VTK-" + vtkVersion + " & Qt-" + qtVersion + ": ";

  if
(!vtkOpenGLContextDevice2D::SafeDownCast(view->GetContext()->GetDevice())->SetStringRendererToQt())
    title += "No Qt Rendering";
  else
    title += "Qt Rendering";

  chart->SetTitle(title.c_str());

  widget.show();

  app.exec();

  return EXIT_SUCCESS;
}

*CMakeLists.txt*

cmake_minimum_required(VERSION 2.6)

PROJECT(vtkChartQtTextRendering)

FIND_PACKAGE(VTK)
INCLUDE(${VTK_USE_FILE})

SET(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
SET(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
SET(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")

FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})

# Use the include path and library for Qt that is used by VTK.
INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR}
                    ${QT_QTGUI_INCLUDE_DIR}
                    ${QT_QTCORE_INCLUDE_DIR})

ADD_EXECUTABLE(vtkChartQtTextRendering main.cpp)

TARGET_LINK_LIBRARIES(vtkChartQtTextRendering
  QVTK
  ${QT_LIBRARIES}
  vtkCharts
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120523/43bd9762/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkChartQtTexRendering.zip
Type: application/zip
Size: 1558 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120523/43bd9762/attachment.zip>


More information about the vtkusers mailing list