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

Marcus D. Hanwell marcus.hanwell at kitware.com
Thu May 24 10:20:08 EDT 2012


I am responsible for a large portion of the chart development work. It
is preferable to upload commits without compression so that they can
be viewed inline, or using Gerrit for code review. Did you confirm
your changes still work as expected with the FreeType rendering?

I would like to facilitate the use of either rendering method, and in
modular (current master) putting this in an ifdef is not an acceptable
solution. I will try to find some time to take a look and see what we
can put together for the next release/master. It is also great to see
application areas the charts (and other VTK work) is being used in -
we should try to collect some of these examples.

Marcus

On Thu, May 24, 2012 at 5:09 AM, Arnaud BARRE <arnaud.barre at gmail.com> wrote:
> I found somes issues in VTK 5.10 to render text with Qt in the charts,
> and I filled a bug report with a patch to fix them
> (http://www.vtk.org/Bug/view.php?id=13199).
>
> Now everything is fine: http://dug.im/cbfbe
>
> Arnaud
>
> On Wed, May 23, 2012 at 4:04 PM, Arnaud BARRE <arnaud.barre at gmail.com> wrote:
>> 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
>> )
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list