[vtkusers] Trouble with vtkLinearExtrusionFilter and Coloring and vtkSplineFilter

Christopher Bruns cmbruns at stanford.edu
Wed Jun 14 19:12:42 EDT 2006

Please help.  I am having some trouble creating a graphics object in vtk 
the way I want to. 

For molecular visualization I create a thick ribbon that follows a path 
through space.  I am trying to compose a pipeline as follows:


Unfortunately, this only works if I exclude the vtkSplineFilter and also 
exclude the color scalars.

Without color and without spline smoothing I can create a nice 
monochromatic thick ribbon.

If I stop at the vtkRibbonFilter, I can get a nice colored 
zero-thickness smooth splined ribbon.  But I want it thick.

When vtkLinearExtrusionFilter is combined with either vtkSplineFilter or 
color scalars, my (Java) program crashes with a reference to one of the 
vtk native libraries.

I can work around the first problem (vtkSplineFilter vs. 
vtkLinearExtrusionFilter) by using vtkCardinalSpline to compute my own 
interpolated positions and normals.  This way I can get a nice thick and 
smooth ribbon, but which still has no internal coloring.

I experience this same situation with vtk versions 4.4 and 5.0.  I have 
not tried other versions.

What can I do to get internally colored extruded ribbons?

--Chris Bruns

What follows is a test program to help clarify my summary:

 * Created on Jun 14, 2006
 * Original author: Christopher Bruns
package org.simtk.moleculargraphics.cartoon;

import vtk.*;

import org.simtk.moleculargraphics.VTKLibraries;
import javax.swing.JFrame;

  * @author Christopher Bruns
  * Test program to demonstrate problem coloring extruded ribbon with 
public class TestColoredRibbon {
    public static void main(String[] args) {
        VTKLibraries.load(); // (my custom native library loader)

        // Program crashes or hangs with the extruded object when either 
colors are enabled,
        // or the spline smoothing filter is used.

//        boolean extrudeShape = true;  // if true, color and smooth 
must be false
//        boolean smoothPath = false; // if true, extrudeShape must be 
false, or else hang
//        boolean colorShape = false; // if true, extrudeShape must be 
false, or else crash
        boolean extrudeShape = false;  // if true, color and smooth must 
be false
        boolean smoothPath = true; // if true, extrudeShape must be 
false, or else hang
        boolean colorShape = true; // if true, extrudeShape must be 
false, or else crash

        // Color lookup table
        vtkLookupTable lut = new vtkLookupTable();
        int numberOfColors = 3;
        int redColor = 0;
        int whiteColor = 1;
        int blueColor = 2;
        lut.SetTableValue(redColor, 1.0, 0.0, 0.0, 1.0); // red
        lut.SetTableValue(whiteColor, 1.0, 1.0, 1.0, 1.0); // white
        lut.SetTableValue(blueColor, 0.0, 0.0, 1.0, 1.0); // blue

        // Data structures for points, normals, and colors
        vtkPoints linePoints = new vtkPoints();
        vtkFloatArray lineNormals = new vtkFloatArray();
        vtkFloatArray lineColors = new vtkFloatArray();
        // Create a line with three points and a slight kink
        // Point 1
        linePoints.InsertNextPoint(0, 0, 0);
        lineNormals.InsertNextTuple3(-0.44, 0.90, 0);
        // Point 2
        linePoints.InsertNextPoint(1, 0.1, 0);
        lineNormals.InsertNextTuple3(0, 1, 0);
        // Point 3
        linePoints.InsertNextPoint(2, 0, 0);
        lineNormals.InsertNextTuple3(0.44, 0.90, 0.0);
        // Connect points into a line
        int numberOfPoints = linePoints.GetNumberOfPoints();
        vtkCellArray lineCells = new vtkCellArray();
        for (int i = 0; i < numberOfPoints; i ++)
        // Create a proper vtkPolyData object from the line
        vtkPolyData lineData = new vtkPolyData();
        // Coloring by adding scalars causes crash with extruded shape
        if (colorShape) lineData.GetPointData().SetScalars(lineColors);

        // Smooth the line with a spline function
        vtkSplineFilter splineFilter = new vtkSplineFilter();
        // Widen the line into a ribbon
        vtkRibbonFilter ribbonFilter = new vtkRibbonFilter();
        ribbonFilter.SetAngle(0); // Perpendicular to normals
        if (smoothPath)
            ribbonFilter.SetInput(splineFilter.GetOutput()); // use spline
            ribbonFilter.SetInput(lineData); // skip spline

        vtkLinearExtrusionFilter ribbonThicknessFilter = new 

        // The stupid mapper needs to be explicitly told the range of 
the color lookup table
        vtkPolyDataMapper mapper = new vtkPolyDataMapper();       
        mapper.SetScalarRange(0.0, lut.GetNumberOfTableValues() - 
        // Rendering before extrusion works, after extrusion does not
        // (unless coloring and smoothing are not attempted)
        // mapper.SetInput(lineData); // simple line -- works
        // mapper.SetInput(splineFilter.GetOutput()); // smoothed line 
-- works
        // mapper.SetInput(cleanFilter.GetOutput()); // cleaned line -- 
        if (extrudeShape) {
            // thick ribbon
            //  -- crashes if scalars are present
            //  -- hangs if spline filter is included
        else {
            mapper.SetInput(ribbonFilter.GetOutput()); // ribbon -- works

        vtkActor actor = new vtkActor();

        // VTK rendering window
        vtkPanel panel = new vtkPanel();
        panel.GetRenderer().SetBackground(1,1,1); // white backgrounds rule
        // Java swing window to hold the rendering window
        JFrame frame = new JFrame("Test extruded strip color");
        frame.setSize(500, 500);

More information about the vtkusers mailing list