[vtkusers] How to draw a checkered floor in VTK?
alican
alican1812 at hotmail.com
Thu Jun 1 09:53:29 EDT 2017
I have tried to do it with vtkQuad, based on this example
<http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Quad> , however
nothing is drawn.
// Add the points to a vtkPoints object
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> quads = vtkSmartPointer<vtkCellArray>::New();
for (int i = 0; i < 3; i++)
{
// Create four points (must be in counter clockwise order)
double p0[3] = { 0.0, 0.0, 0.0 };
double p1[3] = { 1.0*i, 0.0, 0.0 };
double p2[3] = { 1.0*i, 0.0, 1.0*i };
double p3[3] = { 0.0, 0.0, 1.0*i };
points->InsertNextPoint(p0);
points->InsertNextPoint(p1);
points->InsertNextPoint(p2);
points->InsertNextPoint(p3);
// Create a quad on the four points
vtkSmartPointer<vtkQuad> quad = vtkSmartPointer<vtkQuad>::New();
quad->GetPointIds()->SetId(0, 0);
quad->GetPointIds()->SetId(1, 1);
quad->GetPointIds()->SetId(2, 2);
quad->GetPointIds()->SetId(3, 3);
// Create a cell array to store the quad in
quads->InsertNextCell(quad);
}
// Create a polydata to store everything in
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
// Add the points and quads to the dataset
polydata->SetPoints(points);
polydata->SetPolys(quads);
// Setup colors
unsigned char red[3] = { 255, 0, 0 };
unsigned char green[3] = { 0, 255, 0 };
unsigned char blue[3] = { 0, 0, 255 };
vtkSmartPointer<vtkUnsignedCharArray> colors =
vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
colors->InsertNextTupleValue(red);
colors->InsertNextTupleValue(green);
colors->InsertNextTupleValue(blue);
polydata->GetPointData()->SetScalars(colors);
// Add the points and quads to the dataset
polydata->SetPoints(points);
polydata->SetPolys(quads);
// Setup actor and mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polydata);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Setup render window, renderer, and interactor
m_pRenderer->AddViewProp(actor);
--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-draw-a-checkered-floor-in-VTK-tp5743506.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list