[vtkusers] Draw line between Points

Bill Lorensen bill.lorensen at gmail.com
Wed Nov 26 07:39:09 EST 2014


There should be 1 less line than there are points. The loop
for(i = 0; i < number_of_points; i++)
  {
      vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
      line->GetPointIds()->SetId(0,i);
      line->GetPointIds()->SetId(1,i+1);
      lines->InsertNextCell(line);
    }
  }
should go to number_of_points - 1.

On Wed, Nov 26, 2014 at 5:22 AM, Michael Franzburg
<michael.franzburg at gmx.de> wrote:
> Hi vtkusers,
> I just started using VTK and i'm currently having some problems with simply
> drawing lines between different points.
> What i basically want to do is to read a file of coordinates (which works)
> and then connect these points whith lines. I basically adapted the code from
> this wiki example:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/LongLine
> As i understand this example my code should now connect the 1st point with
> the 2nd and so on. However for some reason this doesnt happen. When i define
> my points as:
> 1.0 1.0 0.0
> 2.0 1.0 0.0
> 1.0 2.0 0.0
> 2.0 2.0 0.0
> They get connected with eachother however they get connected with the origin
> aswell.
> If somebody could explain to me why this happens i would be grateful.
> Regards,
> Michael
>
> **************************************
> float coord[number_of_points][3];
> for (i = 0; i < number_of_points; i++)
>   {
>     fin >> coord[i][0] >> coord[i][1] >> coord[i][2];
>   }
>
> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
>   for (i = 0; i < number_of_points; i++)
>   {
>     points->InsertNextPoint(coord[i]);
>   }
>
> vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
>
> for(i = 0; i < number_of_points; i++)
>   {
>       vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
>       line->GetPointIds()->SetId(0,i);
>       line->GetPointIds()->SetId(1,i+1);
>       lines->InsertNextCell(line);
>     }
>   }
>
>   // Create a polydata to store everything in
>    vtkSmartPointer<vtkPolyData> linesPolyData =
>     vtkSmartPointer<vtkPolyData>::New();
>
>   // Add the points to the dataset
>   linesPolyData->SetPoints(points);
>
>   // Add the lines to the dataset
>   linesPolyData->SetLines(lines);
>
>   // Setup actor and mapper
>   vtkSmartPointer<vtkPolyDataMapper> mapper =
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>   mapper->SetInputData(linesPolyData);
>
>   vtkSmartPointer<vtkActor> actor =
>     vtkSmartPointer<vtkActor>::New();
>   actor->SetMapper(mapper);
>
>   // Setup render window, renderer, and interactor
>   vtkSmartPointer<vtkRenderer> renderer =
>     vtkSmartPointer<vtkRenderer>::New();
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>     vtkSmartPointer<vtkRenderWindow>::New();
>   renderWindow->AddRenderer(renderer);
>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>       vtkSmartPointer<vtkRenderWindowInteractor>::New();
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>   renderer->AddActor(actor);
>
>   renderWindow->Render();
>   renderWindowInteractor->Start();
> *********************************************
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list