/*========================================================================= Program: Visualization Toolkit Module: Cube.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // This example shows how to manually create vtkPolyData. // For a python version, please see: // [Cube](https://lorensen.github.io/VTKExamples/site/Python/DataManipulation/Cube/) #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main() { vtkNew colors; std::array, 8> pts = { { { { 0, 0, 0 } }, { { 1, 0, 0 } }, { { 1, 1, 0 } }, { { 0, 1, 0 } }, { { 0, 0, 1 } }, { { 1, 0, 1 } }, { { 1, 1, 1 } }, { { 0, 1, 1 } } } }; // The ordering of the corner points on each face. std::array, 6> ordering = { { { { 0, 1, 2, 3 } }, { { 4, 5, 6, 7 } }, { { 0, 1, 5, 4 } }, { { 1, 2, 6, 5 } }, { { 2, 3, 7, 6 } }, { { 3, 0, 4, 7 } } } }; // We'll create the building blocks of polydata including data attributes. vtkNew cube; vtkNew points; vtkNew polys; vtkNew scalars; // Load the point, cell, and data attributes. for (auto i = 0ul; i < pts.size(); ++i) { points->InsertPoint(i, pts[i].data()); scalars->InsertTuple1(i, i); } for (auto&& i : ordering) { polys->InsertNextCell(vtkIdType(i.size()), i.data()); } // We now assign the pieces to the vtkPolyData. cube->SetPoints(points); cube->SetPolys(polys); cube->GetPointData()->SetScalars(scalars); // Now we'll look at it. vtkNew cubeMapper; cubeMapper->SetInputData(cube); cubeMapper->SetScalarRange(cube->GetScalarRange()); vtkNew cubeActor; cubeActor->SetMapper(cubeMapper); // The usual rendering stuff. vtkNew camera; camera->SetPosition(1, 1, 1); camera->SetFocalPoint(0, 0, 0); vtkNew renderer; vtkNew renWin; renWin->AddRenderer(renderer); vtkNew iren; iren->SetRenderWindow(renWin); renderer->AddActor(cubeActor); renderer->SetActiveCamera(camera); renderer->ResetCamera(); renderer->SetBackground(colors->GetColor3d("Cornsilk").GetData()); renWin->SetSize(600, 600); // interact with data renWin->Render(); iren->Start(); return EXIT_SUCCESS; }