I need to render a huge number of instance(each one have different color / scale / orientation / type), I want to use vtkGlyph3D to do this. The following is my code (it does not work)
void Test2()
{
vtkNew<vtkNamedColors> nc;
// Create points
vtkNew<vtkPoints> points;
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(5, 0, 0);
points->InsertNextPoint(10, 0, 0);
vtkNew<vtkUnsignedCharArray> colors;
colors->SetName("colors");
colors->SetNumberOfComponents(3);
unsigned char r[3] = {255, 0, 0};
unsigned char g[3] = {0, 255, 0};
unsigned char b[3] = {0, 0, 255};
colors->InsertNextTuple3(r[0], g[0], b[0]);
colors->InsertNextTuple3(r[1], g[1], b[1]);
colors->InsertNextTuple3(r[2], g[2], b[2]);
vtkNew<vtkFloatArray> scales;
scales->SetNumberOfComponents(3);
scales->InsertNextTuple3(4.0, 2.0, 1.0);
scales->InsertNextTuple3(2.0, 2.0, 1.0);
scales->InsertNextTuple3(8.0, 2.0, 1.0);
scales->SetName("Scale");
vtkNew<vtkFloatArray> orientation;
orientation->SetNumberOfComponents(3);
orientation->InsertNextTuple3(0, 0.0, 0.0);
orientation->InsertNextTuple3(45.0, 45.0, 45.0);
orientation->InsertNextTuple3(45.0, 0.0, 0.0);
orientation->SetName("directions");
vtkNew<vtkIntArray> index;
index->SetName("types");
index->SetNumberOfComponents(1);
index->InsertNextTuple1(0);
index->InsertNextTuple1(1);
index->InsertNextTuple1(0);
vtkNew<vtkPolyData> polydata;
polydata->SetPoints(points);
polydata->GetPointData()->SetScalars(index);
polydata->GetPointData()->AddArray(colors);
polydata->GetPointData()->AddArray(orientation);
polydata->GetPointData()->AddArray(scales);
// Create anything you want here, we will use a cube and a arrow for the demo.
vtkNew<vtkCubeSource> cubeSource;
vtkNew<vtkArrowSource> arrowSource;
// I don't know how to write
vtkNew<vtkGlyph3D> glyph3D;
glyph3D->SetInputData(polydata);
glyph3D->SetSourceConnection(0, cubeSource->GetOutputPort());
glyph3D->SetSourceConnection(1, arrowSource->GetOutputPort());
glyph3D->SetIndexModeToScalar();
glyph3D->SetRange(0, 1);
glyph3D->SetInputArrayToProcess(0, 0, 0, 0, "types");
glyph3D->SetColorModeToColorByScalar();
glyph3D->SetInputArrayToProcess(3, 0, 0, 0, "colors");
glyph3D->OrientOn();
glyph3D->SetInputArrayToProcess(1, 0, 0, 0, "directions");
glyph3D->Update();
// Create a mapper and actor
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(glyph3D->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
// Visualize
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("ColorGlyphs");
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(nc->GetColor3d("Black").GetData());
vtkNew<vtkInteractorStyleTrackballCamera> style;
style->SetDefaultRenderer(renderer);
renderWindowInteractor->SetInteractorStyle(style);
renderer->GetActiveCamera()->ParallelProjectionOn();
renderer->ResetCamera();
renderWindow->SetMultiSamples(8);
renderWindow->Render();
renderWindowInteractor->Start();
}