<div dir="ltr"><div><div><div><div><div>Hello,<br><br></div>You are right, vtkCellArray allows to append data but not insert in sense of shifting data.<br></div>Here you are building a set of segments so there is no need to shift anything (but you can do you manually by creating new arrays if you want).<br></div><div>Append your points and append your cells, the order does no matter, just remember what is first point (resp. last point to appending).<br> <br></div><div><span style="font-family:monospace,monospace"> int firstPointId = 0; // Initial start point<br></span></div><div><span style="font-family:monospace,monospace"> System.out.println("</span><wbr><span style="font-family:monospace,monospace">Prepending");</span></div><div><span style="font-family:monospace,monospace"> 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> int pid = points.InsertNextPoint(new_x, new_y, new_z);<br> points.Modified();<br><br> lines.InsertNextCell(2);<br> lines.InsertCellPoint(</span><span style="font-family:monospace,monospace"><span style="font-family:monospace,monospace">firstPointId</span>);<br> lines.InsertCellPoint(i);<br></span></div><div><span style="font-family:monospace,monospace"> firstPointId = i; // Newly insterted point is new line head point<br></span></div><div><span style="font-family:monospace,monospace"> lines.Modified();<br> canvas.repaint();<br> }</span><br></div><br></div>Hope it helps.<br><br></div>Best regards,<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><b>Joachim Pouderoux</b><font size="2">, <font size="1">PhD</font></font><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font size="1"><i>Technical Expert - Scientific Computing Team</i></font><br><b><font size="1"><a href="http://www.kitware.fr" target="_blank">Kitware SAS</a></font></b><br></blockquote>
</div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">2016-11-10 9:36 GMT-04:00 Jean-Max Redonnet <span dir="ltr"><<a href="mailto:jmax.red@gmail.com" target="_blank">jmax.red@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">http://public.kitware.com/<wbr>pipermail/vtkusers/2010-July/<wbr>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.<wbr>LoadAllNativeLibraries()) {<br> }<br> vtkNativeLibrary.<wbr>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.<wbr>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(<wbr>0.3800, 0.7000, 0.1600);<br> <br> renderer.AddActor(actor);<br> renderer.ResetCamera();<br> <br> this.setDefaultCloseOperation(<wbr>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(<wbr>mainPanel);<br> this.setSize(800, 800);<br> this.setLocationRelativeTo(<wbr>null); // Center on desktop<br> <br> this.setVisible(true);<br><br> // Loop to add points to line<br> System.out.println("Appending"<wbr>);<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("<wbr>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>
<br>______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>