[vtkusers] Rendering huge amount of polyData with 1 actor and vtkMultiBlockDataSet/vtkCompositePolyDataMapper2

finfanillo esteban.vidal at huawei.com
Thu Aug 29 04:41:03 EDT 2013


Hi all,

I have a huge amount of polydata (octagons) created from a point cloud, so I
want to render them with 1 actor, in order to save memory. I need to keep
track of color information, which is different for every point. My code is
something like:

////////////

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
vtkSmartPointer<vtkPolygon> octagon = vtkSmartPointer<vtkPolygon>::New();
vtkSmartPointer<vtkCellArray> Octagons =
vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
vtkMultiBlockDataSet* Blocks = vtkMultiBlockDataSet::New();


for(size_t i=0;i<point_cloud_size;++i)
{
   // Create and octagon for every point, using them at a central points and
getting 8 vertices

   points->InsertNextPoint(vertex_1_x[i], vertex_1_y[i], vertex_1_z[i]);
   ...
   points->InsertNextPoint(vertex_8_x[i], vertex_8_y[i], vertex_8_z[i]);

   // Add color information to every vertex

   colors->SetNumberOfComponents(3);
   colors->SetName("Colors");
   colors->InsertNextTupleValue(point_color[i]);
   ...
   colors->InsertNextTupleValue(point_color[i]); // 8 times, 1 for every
vertex

  // Create every octagon

  octagon->GetPointIds()->SetNumberOfIds(8);
  octagon->GetPointIds()->SetId(0, 0);
  octagon->GetPointIds()->SetId(1, 1);
  ...
  octagon->GetPointIds()->SetId(7, 7);

  Octagons->InsertNextCell(octagon);

  // Create the polydatas and put it into a MultiBlockDataSet

  polyData ->SetPoints(points);
  polyData ->SetPolys(Octagons);
  polyData ->GetPointData()->SetScalars(colors);

  Blocks ->SetBlock(i+1,polyData);
  Blocks ->Modified();

  // Initialize

  points->Initialize();
  colors->Initialize();
  octagon->Initialize();
  Octagons->Initialize();
  polyData->Initialize();
}

// Rendering. I guess the problem is here, but I don't know where exactly

vtkSmartPointer<vtkCompositeDataGeometryFilter> geom =
vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();

geom->SetInput(Blocks);
geom->Update();

vtkCompositePolyDataMapper2* mapper = vtkCompositePolyDataMapper2::New();
mapper->SetInputConnection(0,geom->GetOutputPort(0));

vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
 
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();

////////////////

The result is that only the last polygon is rendered. Can anybody help me
please? Thank you!





--
View this message in context: http://vtk.1045678.n5.nabble.com/Rendering-huge-amount-of-polyData-with-1-actor-and-vtkMultiBlockDataSet-vtkCompositePolyDataMapper2-tp5723120.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list