[vtkusers] Problem with vtkPiecewiseFunction (0x1c4d430): Index out of range! (test case included)

Elvis Stansvik elvis.stansvik at orexplore.com
Wed Jun 22 09:57:32 EDT 2016


2016-06-22 15:54 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:

> Hi all,
>
> I'd like to use a vtkCompositeTransferFunctionItem +
> vtkCompositeControlPointsItem combo inside a vtkChartXY, for editing a
> color transfer function (and visualizing the opacity transfer function at
> the same time).
>
> I want to use
> SetPointsFunction(vtkCompositeControlPointsItem.ColorPointsFunction) on the
> vtkCompositeControlPointsItem, to enable editing only of the color transfer
> function (while still showing the opacity transfer function). But if I do
> so, I get a
>
> ERROR: In
> /build/vtk7-0qbNHX/vtk7-7.0.0/Common/DataModel/vtkPiecewiseFunction.cxx,
> line 349
> vtkPiecewiseFunction (0x277bc50): Index out of range!
>
> when I double a certain point in the plot to edit it.
>
> Here's a minimal test case:
>
> from vtk import vtkRenderWindow
> from vtk import vtkRenderWindowInteractor
> from vtk import vtkColorTransferFunction
> from vtk import vtkPiecewiseFunction
> from vtk import vtkContextView
> from vtk import vtkChartXY
> from vtk import vtkAxis
> from vtk import vtkCompositeTransferFunctionItem
> from vtk import vtkCompositeControlPointsItem
> from vtk import vtkControlPointsItem
>
> # Create a render window and interactor
> renderWindow = vtkRenderWindow()
> interactor = vtkRenderWindowInteractor()
>
> # Create a color transfer function
> colorFunction = vtkColorTransferFunction()
> colorFunction.AddHSVSegment(0., 0., 1., 1., 1./3, 1./3, 1., 1.)
> colorFunction.AddHSVSegment(1./3, 1./3, 1., 1., 2./3, 2./3, 1., 1.)
> colorFunction.AddHSVSegment(2./3, 2./3, 1., 1., 1., 0., 1., 1.)
>
> # Create an opacity transfer function
> opacityFunction = vtkPiecewiseFunction()
> opacityFunction.AddPoint(0.2, 0.)
> opacityFunction.AddPoint(0.5, 0.5)
> opacityFunction.AddPoint(1., 1.)
>
> # Create an item for showing the transfer functions
> functionsItem = vtkCompositeTransferFunctionItem()
> functionsItem.SetColorTransferFunction(colorFunction)
> functionsItem.SetOpacityFunction(opacityFunction)
> functionsItem.SetMaskAboveCurve(True)
>
> # Create an item for showing/controlling the color
> # transfer function points
> pointsItem = vtkCompositeControlPointsItem()
> pointsItem.SetPointsFunction(
>     vtkCompositeControlPointsItem.ColorPointsFunction)
> pointsItem.SetColorTransferFunction(colorFunction)
> pointsItem.SetOpacityFunction(opacityFunction)
> pointsItem.SetUseOpacityPointHandles(True)
> pointsItem.SetEndPointsXMovable(False)
> pointsItem.SetEndPointsRemovable(False)
> pointsItem.SetShowLabels(True)
> pointsItem.SetLabelFormat("%.3f : %.3f")
>
> def editPoint(sender, event):
>     print('TODO: edit point')
>
> pointsItem.AddObserver(
>     vtkControlPointsItem.CurrentPointEditEvent, editPoint)
>
> # Create an XY chart to hold the items
> chart = vtkChartXY()
> chart.AddPlot(functionsItem)
> chart.AddPlot(pointsItem)
>
> # Create a context view to show the chart
> view = vtkContextView()
> view.GetScene().AddItem(chart)
> view.SetRenderWindow(renderWindow)
> view.SetInteractor(interactor)
>
> interactor.Start()
>
> Launch the program and then double click the third point. You will get
>
> TODO: edit point
> ERROR: In
> /build/vtk7-0qbNHX/vtk7-7.0.0/Common/DataModel/vtkPiecewiseFunction.cxx,
> line 349
> vtkPiecewiseFunction (0x1c4d430): Index out of range!
>
> printed. The first printout ("TODO: edit point") is from my editPoint(...)
> function, while the ERROR message comes from inside VTK. After having made
> the first double click these error messages keeps spewing on the console as
> soon as you move the mouse over the chart. This only happens when
> doubleclicking the third point (at index 2), not when doubleclicking point
> 0, 1 or 3.
>
> Anyone know what is going on? I also noticed that if I remove the line
>
> pointsItem.SetPointsFunction(
>     vtkCompositeControlPointsItem.ColorPointsFunction)
>
> The problem disappears. But this will not give me the kind of editor I
> want.
>

To clarify which point I mean, and to show the behavior I'm seeing, I'm
attaching a screenshot. I took this after doubleclicking the selected point
and moving the mouse outside the window.

Elvis


>
> Elvis
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160622/d5c6900c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chart_ctf.png
Type: image/png
Size: 59084 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160622/d5c6900c/attachment.png>


More information about the vtkusers mailing list