<div dir="ltr"><div>Hi  ! First, I would like to thanks people who works on VTK. This is a great piece of software, very fast, very efficient !<br><br>I'm currently working on a viewer that is supposed to display dynamically the polylines calculated by my algorithms. To do that, I relied on this post :<br><a href="http://public.kitware.com/pipermail/vtkusers/2010-July/061781.html">http://public.kitware.com/pipermail/vtkusers/2010-July/061781.html</a><br><br>This works fine to append points to the polyline, but due to my algorithms, I need also to prepend points at the beginning of the polyline. I can't figure out how to do that. Any help would be gracefully appreciated.<br><br></div>jMax<br><div><br>===<br>Here is my test code. The first loop works fine, but the second one is a mess.<br><br>package vtktest;<br><br>import java.awt.BorderLayout;<br><br>public class PolyLineTest extends JFrame {<br>    private static final long serialVersionUID = 1L;<br><br>    static {<br>        if (!vtkNativeLibrary.LoadAllNativeLibraries()) {<br>        }<br>        vtkNativeLibrary.DisableOutputWindow(null);<br>    }<br><br>    private Random random = new Random();<br>    private vtkRenderWindowPanel canvas;<br>    private vtkRenderer renderer;<br>    private vtkRenderWindowInteractor iren;<br>    private JPanel mainPanel;<br><br>    public static void main(String[] args) {<br>        new PolyLineTest();<br>    }<br><br>    public PolyLineTest() {<br>        this.canvas = new vtkRenderWindowPanel();<br>        this.renderer = canvas.GetRenderer();<br>        this.iren = canvas.getRenderWindowInteractor();<br>        this.setTitle("VTK Test");<br><br>        // First we'll create an initial point to build on<br>        vtkPoints points = new vtkPoints();<br>        points.InsertPoint(0, 0.0, 0.0, 0.0);<br><br>        // The cell array can be thought of as a connectivity list. Here we<br>        // specify the number of points followed by that number of point<br>        // ids. This can be repeated as many times as there are primitives in<br>        // the list.<br>        // This first one is just a point to connect to as we add more points<br>        vtkCellArray lines = new vtkCellArray();<br>        lines.InsertNextCell(1); // number of points<br>        lines.InsertCellPoint(0);<br><br>        vtkPolyData track = new vtkPolyData();<br>        track.SetPoints(points);<br>        track.SetLines(lines);<br><br>        vtkPolyDataMapper mapper = new vtkPolyDataMapper();<br>        mapper.SetInputData(track);<br><br>        vtkActor actor = new vtkActor();<br>        actor.SetMapper(mapper);<br>        actor.GetProperty().SetColor(0.3800, 0.7000, 0.1600);<br>        <br>        renderer.AddActor(actor);<br>        renderer.ResetCamera();<br>        <br>        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br>        <br>        mainPanel = new JPanel();<br>        mainPanel.setLayout(new BorderLayout());<br>        mainPanel.add(canvas, BorderLayout.CENTER);<br><br>        this.getContentPane().add(mainPanel);<br>        this.setSize(800, 800);<br>        this.setLocationRelativeTo(null); // Center on desktop<br>        <br>        this.setVisible(true);<br><br>        // Loop to add points to line<br>        System.out.println("Appending");<br>        for (int i = 1; i < 10; i++) {<br>            try {<br>                Thread.sleep(500);<br>            } catch (InterruptedException e) {<br>                e.printStackTrace();<br>            }<br>            double[] prev_pt = points.GetPoint(i - 1);<br>            double new_x = prev_pt[0] + (2.0 * random.nextDouble() - 1.0);<br>            double new_y = prev_pt[1] + (2.0 * random.nextDouble() - 1.0);<br>            double new_z = prev_pt[2] + (2.0 * random.nextDouble() - 1.0);<br><br>            // Insert the new point<br>            // then tell VTK that the data has been modified so the Render()<br>            // call will update the view with the new data<br>            points.InsertPoint(i, new_x, new_y, new_z);<br>            points.Modified();<br><br>            // To get lines we need a beginning and end point in the<br>            // connectivity list,<br>            // then again tell VTK that the data has been modified<br>            lines.InsertNextCell(2);<br>            lines.InsertCellPoint(i - 1);<br>            lines.InsertCellPoint(i);<br>            lines.Modified();<br>            canvas.repaint();<br>        }<br>        <br>        System.out.println("Prepending");<br>        for (int i = 1; i < 10; i++) {<br>            try {<br>                Thread.sleep(100);<br>            } catch (InterruptedException e) {<br>                e.printStackTrace();<br>            }<br>            double[] prev_pt = points.GetPoint(0);<br>            double new_x = prev_pt[0] + (2.0 * random.nextDouble() - 1.0);<br>            double new_y = prev_pt[1] + (2.0 * random.nextDouble() - 1.0);<br>            double new_z = prev_pt[2] + (2.0 * random.nextDouble() - 1.0);<br><br>            points.InsertPoint(0, new_x, new_y, new_z);<br>            points.Modified();<br><br>            lines.InsertNextCell(2);<br>            lines.UpdateCellCount (2);<br>            lines.InsertCellPoint(0);<br>            lines.InsertCellPoint(1);<br>            lines.Modified();<br>            canvas.repaint();<br>        }<br>    }<br>}<br></div></div>