[vtkusers] vtkChartXY lines not visible when using logarithmic x axis

Hagen Mölle h.moelle at googlemail.com
Thu Jul 21 02:58:27 EDT 2016


Hi,

I want to report a bug for vtkChartXY. So I already send this Email two 
days ago to the vtkUsers mailing list without receiving any answer. The 
bug is not visible in the vtk bug tracker too. Thus I send the Email again.

Bug environment:
a) I am using VTK 6.2. I checked my test code on machines running 
Windows 7 (Visual Studio 2012/2015) and Ubuntu 15.10/Ubuntu 16.04 (gcc). 
On all these systems the bug is visible.
b) I can also reproduce the bug in VTK 7.0 (here I used an Ubuntu 16.04 
machine and compiled VTK 7.0 using OpenGL2 interface).

Bug description:

I am using vtkChartXY to display one line. I also enabled logarithmic x 
axis (chartXY->GetAxis(vtkAxis::BOTTOM)->SetLogScale(true);). Nothing 
more special. In the compiled application I start zooming into the chart 
using the mouse wheel, making sure I always have a line displayed in the 
view. At some zoom level this line just disappears. At the zoom level 
the line disappears I did the following:

1. Zooming more into the chart the line will not appear again.
2. Zooming out twice (with mouse wheel) the line will reappear.

How to reproduce the bug:

I basically used the LinePlot example for vtkChartXY (see 
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Plotting/LinePlot).

I added one line to the example code marked with *** (line was added 
after line 54 in example code).
I added the full code to the end of the Email.
---------------

// Add multiple line plots, setting the colors etc
    vtkSmartPointer<vtkChartXY >  chart= 
vtkSmartPointer<vtkChartXY >::New(); *** 
chart.Get()->GetAxis(vtkAxis::BOTTOM)->SetLogScale(true); 
view->GetScene()->AddItem(chart);

---------------

Compile and execute the program. See my bug description above to 
visualize the bug.


Please contact me if you need more information. I can also provide 
images of the bug if needed.
I hope the bug can be fixed.

Hagen.




#include <vtkVersion.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkChartXY.h>
#include <vtkAxis.h>
#include <vtkTable.h>
#include <vtkPlot.h>
#include <vtkFloatArray.h>
#include <vtkContextView.h>
#include <vtkContextScene.h>
#include <vtkPen.h>

int main(int, char *[])
{
    // Create a table with some points in it
    vtkSmartPointer<vtkTable> table =
      vtkSmartPointer<vtkTable>::New();

    vtkSmartPointer<vtkFloatArray> arrX =
      vtkSmartPointer<vtkFloatArray>::New();
    arrX->SetName("X Axis");
    table->AddColumn(arrX);

    vtkSmartPointer<vtkFloatArray> arrC =
      vtkSmartPointer<vtkFloatArray>::New();
    arrC->SetName("Cosine");
    table->AddColumn(arrC);

    vtkSmartPointer<vtkFloatArray> arrS =
      vtkSmartPointer<vtkFloatArray>::New();
    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));
    }

    // Set up the view
    vtkSmartPointer<vtkContextView> view =
      vtkSmartPointer<vtkContextView>::New();
    view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);

    // Add multiple line plots, setting the colors etc
    vtkSmartPointer<vtkChartXY> chart =
      vtkSmartPointer<vtkChartXY>::New();
    chart.Get()->GetAxis(vtkAxis::BOTTOM)->SetLogScale(true);
    view->GetScene()->AddItem(chart);
    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);

    // For dotted line, the line type can be from 2 to 5 for different 
dash/dot
    // patterns (see enum in vtkPen containing DASH_LINE, value 2):
#ifndef WIN32
    line->GetPen()->SetLineType(vtkPen::DASH_LINE);
#endif
    // (ifdef-ed out on Windows because DASH_LINE does not work on Windows
    //  machines with built-in Intel HD graphics card...)

    //view->GetRenderWindow()->SetMultiSamples(0);

    // Start interactor
    view->GetInteractor()->Initialize();
    view->GetInteractor()->Start();

    return EXIT_SUCCESS;
}


More information about the vtkusers mailing list