[vtkusers] How to draw lines between two datasets using VTK
dev
work2compilation at gmail.com
Mon Nov 21 05:55:15 EST 2011
Hi David thank you for your answer.. I have done all what you said:
Put the points (source and target ) in a vtkObject ... and then trace the
lines between them. here is the code that I write:
vtkPolyData* mesh1 = LoadData(filename_source);
vtkPolyData* mesh2 = LoadData(filename_target);
int numb_lines=10;
//Get the points source and target
float* pointArray_src = (float*)mesh1->GetPoints()->GetVoidPointer(0);
float* pointArray_tgt = (float*)mesh2->GetPoints()->GetVoidPointer(0);
// Create a vtkPoints object and store the points in it: a list of
pointArray_src and pointArray_src
vtkSmartPointer<vtkPoints> pts =
vtkSmartPointer<vtkPoints>::New();
for ( int i=0 ; i<mesh1->GetNumberOfPoints() ; i++ )
pts->InsertNextPoint(pointArray_src[3*i],pointArray_src[3*i+1],pointArray_src[3*i+2]);
for ( int i=0 ; i<mesh2->GetNumberOfPoints() ; i++ )
pts->InsertNextPoint(pointArray_tgt[3*i],pointArray_tgt[3*i+1],pointArray_tgt[3*i+2]);
//
// Create the lines
vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
//for ( int i=0 ; i < numb_lines ; i++ )
//{
vtkSmartPointer<vtkLine> line =
vtkSmartPointer<vtkLine>::New();
line->GetPointIds()->SetId(0,1); //the second 0 is the index of the Origin
in the vtkPoints
line->GetPointIds()->SetId(1, 1 + mesh1->GetNumberOfPoints()); //the
second 1 is the index of P0 in the vtkPoints
lines->InsertNextCell(line);
//}
// Create a polydata to store everything in
vtkSmartPointer<vtkPolyData> linesPolyData =
vtkSmartPointer<vtkPolyData>::New();
// Add the points to the dataset
linesPolyData->SetPoints(pts);
// Add the lines to the dataset
linesPolyData->SetLines(lines);
std::cout << "There are " << linesPolyData->GetNumberOfLines() << "
lines." << std::endl;
*That works great, and I can visualize the lines, but how to display the
cloud points : pointArray_src and pointArray_tgt and lines in the same time
at the same windows to find a result like this (in the insterted image)??*
http://vtk.1045678.n5.nabble.com/file/n5010176/2011-11-21_115155.jpg
--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-draw-lines-between-two-datasets-using-VTK-tp5006807p5010176.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list