[vtkusers] How to draw a checkered floor in VTK?

kenichiro yoshimi rccm.kyoshimi at gmail.com
Fri Jun 2 02:02:10 EDT 2017


Hi alican,

I changed your code to show a checkered floor and attached it. But
there may be more skillful ways.

Thanks,

2017-06-01 22:53 GMT+09:00 alican <alican1812 at hotmail.com>:
> 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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Checkerboard.tar.gz
Type: application/x-gzip
Size: 1348 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170602/c2539394/attachment.bin>


More information about the vtkusers mailing list