[vtkusers] Draw thousands of different size and color 3D rectangles several times per second

Mwoua david.levy at leddartech.com
Wed Mar 1 15:06:47 EST 2017


I have built my polydata and glyph3D, but I can't find a way to give them the
color I want. The color is also using the size scaling.

How can I specify the size and color of each glyph independantly? (ergo how
can I use my array of colors for each point)

You can find my current code below if it can helps.

Thanks,
David


vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();

vtkSmartPointer<vtkCubeSource> cubeSource =
vtkSmartPointer<vtkCubeSource>::New();
cubeSource->SetXLength(x);
cubeSource->SetYLength(y);
cubeSource->SetZLength(z);

// Setup scale for size
vtkSmartPointer<vtkFloatArray> dscale =
vtkSmartPointer<vtkFloatArray>::New();
dscale->SetName("dscale");

//and color
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);

//build points and scales
for(...){
    points->InsertNextPoint(lPoint1.x,lPoint1.y,lPoint1.z);
    dscale->InsertNextValue(lDistance);
    unsigned char lCol[3] = { lColor.red(), lColor.green(), lColor.blue() };
    colors->InsertNextTypedTuple(lCol);
}

// Combine into a polydata
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->GetPointData()->SetScalars(dscale);

vtkSmartPointer<vtkGlyph3D> glyph3D = vtkSmartPointer<vtkGlyph3D>::New();
glyph3D->SetScaleModeToScaleByScalar();
glyph3D->SetSourceConnection(cubeSource->GetOutputPort());
glyph3D->SetInputData(polydata);
glyph3D->Update();

// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(glyph3D->GetOutputPort());
        vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

// Add the actor to the scene
  renderer->AddActor(actor);



--
View this message in context: http://vtk.1045678.n5.nabble.com/Draw-thousands-of-different-size-and-color-3D-rectangles-several-times-per-second-tp5742310p5742331.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list