<div dir="ltr"><div><div><div><div><div>Hello,<br><br></div>Thanks for your response.<br></div><div><br></div>I just replaced i by pid in lines<br><div><span style="font-family:monospace,monospace"> lines.InsertCellPoint(i);<br></span></div><div><span style="font-family:monospace,monospace"> firstPointId = i; // Newly insterted point is new line head point</span></div>to make it work.<br><br></div>Thanks again. You help me a lot.<br><br></div>Regards<br><br></div>jMax<br><br><div><div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-11-22 14:54 GMT+01:00 Joachim Pouderoux <span dir="ltr"><<a href="mailto:joachim.pouderoux@kitware.com" target="_blank">joachim.pouderoux@kitware.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><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><span style="font-family:monospace,monospace">Prepending<wbr>");</span></div><div><span style="font-family:monospace,monospace"><span class=""> 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></span> 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">firstPoi<wbr>ntId</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="m_8156554955513741221gmail_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"><div><div class="h5">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></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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/pipe<wbr>rmail/vtkusers/2010-July/06178<wbr>1.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.LoadAllNati<wbr>veLibraries()) {<br> }<br> vtkNativeLibrary.DisableOutput<wbr>Window(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.getRenderWindowInteract<wbr>or();<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<wbr>.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(main<wbr>Panel);<br> this.setSize(800, 800);<br> this.setLocationRelativeTo(nul<wbr>l); // 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("Prepending<wbr>");<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></div></div>______________________________<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/opensou<wbr>rce/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_FA<wbr>Q</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/mail<wbr>man/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>