diff --git a/src/Cxx/GeometricObjects/LinearCellDemo.cxx b/src/Cxx/GeometricObjects/LinearCellDemo.cxx index 512f797b005fb9ad2a93be41c4efac156db2817b..7179a1f6646238046f324055f33afd109284bc31 100644 --- a/src/Cxx/GeometricObjects/LinearCellDemo.cxx +++ b/src/Cxx/GeometricObjects/LinearCellDemo.cxx @@ -52,15 +52,18 @@ using cellPair = std::pair<vtkSmartPointer<vtkUnstructuredGrid>, std::array<double, 3>>; using cellMap = std::map<std::string, cellPair>; -// These functions return an vtkUnstructured grid corresponding to the object. namespace { /** - * @brief GetNameCellOrientation - * @return A map of cell names, cells and their initial orientations. + * Make a map consisting of the unstructured grid name, + * the unstructured grid and it's orientation as + * Azimuth, Elevation and Zoom in degrees. + * + * @return The map. */ -cellMap GetNameCellOrientation(); +cellMap GetUnstructuredGrids(); +// These functions return an vtkUnstructured grid corresponding to the object. vtkNew<vtkUnstructuredGrid> MakeVertex(); vtkNew<vtkUnstructuredGrid> MakePolyVertex(); vtkNew<vtkUnstructuredGrid> MakeLine(); @@ -89,13 +92,14 @@ vtkNew<vtkUnstructuredGrid> MakeHexagonalPrism(); * @param thicknessRatio - the thickness ratio in the Y direction, >= 0. * @return An actor corresponding to the tile. */ -vtkNew<vtkActor> MakeTile(double *const &bounds, - double const &expansionFactor = 0.1, - double const &thicknessRatio = 0.05); +vtkNew<vtkActor> MakeTile(double* const& bounds, + double const& expansionFactor = 0.1, + double const& thicknessRatio = 0.05); } // namespace -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) +{ CLI::App app{ "Demonstrate the linear cell types found in VTK. " "The numbers define the ordering of the points making the cell."}; @@ -107,20 +111,26 @@ int main(int argc, char *argv[]) { auto backfaceOn{false}; app.add_flag("-b, --backface", backfaceOn, "Display the back face in a different colour."); + auto plinthOff{false}; + app.add_flag("-n, --noPlinth", plinthOff, "Remove the plinth."); CLI11_PARSE(app, argc, argv); - if (wireframeOn && backfaceOn) { + if (wireframeOn && backfaceOn) + { std::cerr << "error: argument -b/--backface: not allowed with argument " "-w/--wireframe" << std::endl; return EXIT_FAILURE; } - std::vector<std::string> needsTile = { - "VTK_VOXEL (=11)", - "VTK_HEXAHEDRON (=12)", - "VTK_PENTAGONAL_PRISM (=15)", - "VTK_HEXAGONAL_PRISM (=16)", - }; + vtkNew<vtkNamedColors> colors; + + // Create one sphere for all. + vtkNew<vtkSphereSource> sphere; + sphere->SetPhiResolution(21); + sphere->SetThetaResolution(21); + sphere->SetRadius(0.04); + + auto cells = GetUnstructuredGrids(); // clang-format off std::array<std::string, 16> keys = { @@ -134,7 +144,13 @@ int main(int argc, char *argv[]) { "VTK_PENTAGONAL_PRISM (=15)", "VTK_HEXAGONAL_PRISM (=16)"}; // clang-format on - auto cells = GetNameCellOrientation(); + std::vector<std::string> addPlinth = { + "VTK_TETRA (=10)", "VTK_VOXEL (=11)", + "VTK_HEXAHEDRON (=12)", "VTK_WEDGE (=13)", + "VTK_PYRAMID (=14)", "VTK_PENTAGONAL_PRISM (=15)", + "VTK_HEXAGONAL_PRISM (=16)", + }; + std::vector<std::string> lines{"VTK_LINE (=3)", "VTK_POLY_LINE (=4)"}; // Set up the viewports. auto gridRowDimensions = 4; @@ -147,8 +163,10 @@ int main(int argc, char *argv[]) { std::vector<std::string> blankViewports; std::map<std::string, std::array<double, 4>> viewports; - for (int row = 0; row < gridRowDimensions; row++) { - for (int col = 0; col < gridColumnDimensions; col++) { + for (int row = 0; row < gridRowDimensions; row++) + { + for (int col = 0; col < gridColumnDimensions; col++) + { int index = row * gridColumnDimensions + col; // Set the renderer's viewport dimensions (xmin, ymin, xmax, ymax) @@ -163,9 +181,12 @@ int main(int argc, char *argv[]) { static_cast<double>(gridRowDimensions - row) / gridRowDimensions}; // std::cout << viewport[0] << " " << viewport[1] // << " " << viewport[2] << " "<< viewport[3] << std::endl; - if (index < blank) { + if (index < blank) + { viewports[keys[index]] = viewport; - } else { + } + else + { auto s = fmt::format("vp_{:d}_{:d}", col, row); viewports[s] = viewport; blankViewports.push_back(s); @@ -173,14 +194,6 @@ int main(int argc, char *argv[]) { } } - vtkNew<vtkNamedColors> colors; - - // Create one sphere for all. - vtkNew<vtkSphereSource> sphere; - sphere->SetPhiResolution(21); - sphere->SetThetaResolution(21); - sphere->SetRadius(0.04); - // Create one text property for all. vtkNew<vtkTextProperty> textProperty; textProperty->SetFontSize(int(rendererSize / 18)); @@ -191,11 +204,12 @@ int main(int argc, char *argv[]) { vtkNew<vtkTextProperty> labelProperty; labelProperty->SetFontSize(int(rendererSize / 12)); labelProperty->BoldOn(); + labelProperty->ShadowOn(); labelProperty->SetJustificationToCentered(); - labelProperty->SetColor(colors->GetColor3d("FireBrick").GetData()); + labelProperty->SetColor(colors->GetColor3d("DeepPink").GetData()); vtkNew<vtkProperty> backProperty; - backProperty->SetColor(colors->GetColor3d("Coral").GetData()); + backProperty->SetColor(colors->GetColor3d("DodgerBlue").GetData()); std::map<std::string, vtkSmartPointer<vtkRenderer>> renderers; @@ -207,93 +221,103 @@ int main(int argc, char *argv[]) { iRen->SetRenderWindow(renWin); // Create and link the mappers, actors and renderers together. - for (const auto &name : keys) { - std::cout << "Creating: " << name << std::endl; + for (const auto& key : keys) + { + std::cout << "Creating: " << key << std::endl; vtkNew<vtkTextMapper> textMapper; textMapper->SetTextProperty(textProperty); - textMapper->SetInput(name.c_str()); + textMapper->SetInput(key.c_str()); vtkNew<vtkActor2D> textActor; textActor->SetMapper(textMapper); textActor->SetPosition(rendererSize / 2.0, 8); vtkNew<vtkDataSetMapper> mapper; - mapper->SetInputData(cells[name].first); + mapper->SetInputData(cells[key].first); vtkNew<vtkActor> actor; actor->SetMapper(mapper); - if (wireframeOn) { + if (wireframeOn || + std::find(lines.cbegin(), lines.cend(), key) != lines.cend()) + { + std::cout << "wireframe on" << std::endl; actor->GetProperty()->SetRepresentationToWireframe(); actor->GetProperty()->SetLineWidth(2); actor->GetProperty()->SetOpacity(1); actor->GetProperty()->SetColor(colors->GetColor3d("Black").GetData()); - } else { + } + else + { actor->GetProperty()->EdgeVisibilityOn(); actor->GetProperty()->SetLineWidth(3); actor->GetProperty()->SetColor(colors->GetColor3d("Snow").GetData()); - if (backfaceOn) { + if (backfaceOn) + { actor->GetProperty()->SetOpacity(0.4); actor->SetBackfaceProperty(backProperty); backProperty->SetOpacity(0.6); - } else { + } + else + { actor->GetProperty()->SetOpacity(0.8); } } // Label the points. vtkNew<vtkLabeledDataMapper> labelMapper; - labelMapper->SetInputData(cells[name].first); + labelMapper->SetInputData(cells[key].first); labelMapper->SetLabelTextProperty(labelProperty); vtkNew<vtkActor2D> labelActor; labelActor->SetMapper(labelMapper); // Glyph the points. vtkNew<vtkGlyph3DMapper> pointMapper; - pointMapper->SetInputData(cells[name].first); + pointMapper->SetInputData(cells[key].first); pointMapper->SetSourceConnection(sphere->GetOutputPort()); pointMapper->ScalingOff(); pointMapper->ScalarVisibilityOff(); vtkNew<vtkActor> pointActor; pointActor->SetMapper(pointMapper); - pointActor->GetProperty()->SetColor(colors->GetColor3d("Yellow").GetData()); - pointActor->GetProperty()->SetSpecular(1.0); - pointActor->GetProperty()->SetSpecularColor( - colors->GetColor3d("White").GetData()); - pointActor->GetProperty()->SetSpecularPower(100); + pointActor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData()); vtkNew<vtkRenderer> renderer; - renderer->SetBackground(colors->GetColor3d("CornflowerBlue").GetData()); - renderer->SetViewport(viewports[name].data()); + renderer->SetBackground(colors->GetColor3d("LightSteelBlue").GetData()); + renderer->SetViewport(viewports[key].data()); + renderer->AddViewProp(textActor); renderer->AddViewProp(actor); renderer->AddViewProp(labelActor); renderer->AddViewProp(pointActor); - if (std::find(needsTile.cbegin(), needsTile.cend(), name) != - needsTile.cend()) { - auto tileActor = MakeTile(cells[name].first->GetBounds(), 0.1, 0.05); - tileActor->GetProperty()->SetColor( - colors->GetColor3d("SpringGreen").GetData()); - tileActor->GetProperty()->SetOpacity(0.3); - renderer->AddViewProp(tileActor); + if (!plinthOff) + { + if (std::find(addPlinth.cbegin(), addPlinth.cend(), key) != + addPlinth.cend()) + { + auto tileActor = MakeTile(cells[key].first->GetBounds(), 0.5, 0.05); + tileActor->GetProperty()->SetColor( + colors->GetColor3d("Lavender").GetData()); + tileActor->GetProperty()->SetOpacity(0.3); + renderer->AddViewProp(tileActor); + } } - // renderer->Render(); renderer->ResetCamera(); - renderer->GetActiveCamera()->Azimuth(cells[name].second[0]); - renderer->GetActiveCamera()->Elevation(cells[name].second[1]); - renderer->GetActiveCamera()->Dolly(cells[name].second[2]); + renderer->GetActiveCamera()->Azimuth(cells[key].second[0]); + renderer->GetActiveCamera()->Elevation(cells[key].second[1]); + renderer->GetActiveCamera()->Dolly(cells[key].second[2]); renderer->ResetCameraClippingRange(); renWin->AddRenderer(renderer); - renderers[name] = renderer; + renderers[key] = renderer; } - for (const auto &name : blankViewports) { + for (const auto& key : blankViewports) + { vtkNew<vtkRenderer> renderer; - renderer->SetBackground(colors->GetColor3d("CornflowerBlue").GetData()); - renderer->SetViewport(viewports[name].data()); + renderer->SetBackground(colors->GetColor3d("LightSteelBlue").GetData()); + renderer->SetViewport(viewports[key].data()); renWin->AddRenderer(renderer); - renderers[name] = renderer; + renderers[key] = renderer; } iRen->Initialize(); @@ -305,7 +329,8 @@ int main(int argc, char *argv[]) { namespace { -cellMap GetNameCellOrientation() { +cellMap GetUnstructuredGrids() +{ cellMap cells; cells["VTK_VERTEX (=1)"] = cellPair(MakeVertex(), {30, -30, 0.1}); @@ -317,31 +342,31 @@ cellMap GetNameCellOrientation() { cellPair(MakeTriangleStrip(), {30, -30, 1.1}); cells["VTK_POLYGON (=7)"] = cellPair(MakePolygon(), {0, -45, 1.0}); cells["VTK_PIXEL (=8)"] = cellPair(MakePixel(), {0, -45, 1.0}); - cells["VTK_QUAD (=9)"] = cellPair(MakeQuad(), {0, -45, 0}); - cells["VTK_TETRA (=10)"] = cellPair(MakeTetra(), {0, -45, 0.95}); + cells["VTK_QUAD (=9)"] = cellPair(MakeQuad(), {0, -45, 1.0}); + cells["VTK_TETRA (=10)"] = cellPair(MakeTetra(), {20, 20, 1.0}); cells["VTK_VOXEL (=11)"] = cellPair(MakeVoxel(), {-22.5, 15, 0.95}); cells["VTK_HEXAHEDRON (=12)"] = cellPair(MakeHexahedron(), {-22.5, 15, 0.95}); - cells["VTK_WEDGE (=13)"] = cellPair(MakeWedge(), {-45, 15, 1.0}); - cells["VTK_PYRAMID (=14)"] = cellPair(MakePyramid(), {0, -30, 1.0}); - // cells["VTK_PENTAGONAL_PRISM (=15)"]=cellPair(MakePentagonalPrism(), {-22.5, - // 15, 0.95}); + cells["VTK_WEDGE (=13)"] = cellPair(MakeWedge(), {-30, 15, 1.0}); + cells["VTK_PYRAMID (=14)"] = cellPair(MakePyramid(), {-60, 15, 1.0}); cells["VTK_PENTAGONAL_PRISM (=15)"] = - cellPair(MakePentagonalPrism(), {-30, 15, 0.95}); + cellPair(MakePentagonalPrism(), {-60, 10, 1.0}); cells["VTK_HEXAGONAL_PRISM (=16)"] = - cellPair(MakeHexagonalPrism(), {-30, 15, 0.95}); + cellPair(MakeHexagonalPrism(), {-60, 15, 1.0}); return cells; } -vtkNew<vtkUnstructuredGrid> MakeVertex() { - // A vertex is a cell that represents a 3D point - int numberOfVertices = 1; +vtkNew<vtkUnstructuredGrid> MakeVertex() +{ + // A vertex is a cell that represents a 3D point. + auto numberOfVertices = 1; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); vtkNew<vtkVertex> vertex; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { vertex->GetPointIds()->SetId(i, i); } vtkNew<vtkUnstructuredGrid> ug; @@ -351,9 +376,10 @@ vtkNew<vtkUnstructuredGrid> MakeVertex() { return ug; } -vtkNew<vtkUnstructuredGrid> MakePolyVertex() { - // A polyvertex is a cell represents a set of 0D vertices - int numberOfVertices = 6; +vtkNew<vtkUnstructuredGrid> MakePolyVertex() +{ + // A polyvertex is a cell that represents a set of 0D vertices. + auto numberOfVertices = 6; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); @@ -366,7 +392,8 @@ vtkNew<vtkUnstructuredGrid> MakePolyVertex() { vtkNew<vtkPolyVertex> polyVertex; polyVertex->GetPointIds()->SetNumberOfIds(numberOfVertices); - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { polyVertex->GetPointIds()->SetId(i, i); } @@ -377,16 +404,18 @@ vtkNew<vtkUnstructuredGrid> MakePolyVertex() { return ug; } -vtkNew<vtkUnstructuredGrid> MakeLine() { - // A line is a cell that represents a 1D point - int numberOfVertices = 2; +vtkNew<vtkUnstructuredGrid> MakeLine() +{ + // A line is a cell that represents a 1D point. + auto numberOfVertices = 2; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); points->InsertNextPoint(0.5, 0.5, 0); vtkNew<vtkLine> line; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { line->GetPointIds()->SetId(i, i); } @@ -397,9 +426,10 @@ vtkNew<vtkUnstructuredGrid> MakeLine() { return ug; } -vtkNew<vtkUnstructuredGrid> MakePolyLine() { - // A polyline is a cell that represents a set of 1D lines - int numberOfVertices = 5; +vtkNew<vtkUnstructuredGrid> MakePolyLine() +{ + // A polyline is a cell that represents a set of 1D lines. + auto numberOfVertices = 5; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0.5, 0); @@ -411,7 +441,8 @@ vtkNew<vtkUnstructuredGrid> MakePolyLine() { vtkNew<vtkPolyLine> polyline; polyline->GetPointIds()->SetNumberOfIds(numberOfVertices); - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { polyline->GetPointIds()->SetId(i, i); } @@ -422,9 +453,10 @@ vtkNew<vtkUnstructuredGrid> MakePolyLine() { return ug; } -vtkNew<vtkUnstructuredGrid> MakeTriangle() { - // A triangle is a cell that represents a 1D point - int numberOfVertices = 3; +vtkNew<vtkUnstructuredGrid> MakeTriangle() +{ + // A triangle is a cell that represents a triangle. + auto numberOfVertices = 3; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); @@ -432,7 +464,8 @@ vtkNew<vtkUnstructuredGrid> MakeTriangle() { points->InsertNextPoint(0.2, 1, 0); vtkNew<vtkTriangle> triangle; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { triangle->GetPointIds()->SetId(i, i); } @@ -443,9 +476,10 @@ vtkNew<vtkUnstructuredGrid> MakeTriangle() { return ug; } -vtkNew<vtkUnstructuredGrid> MakeTriangleStrip() { - // A triangle is a cell that represents a triangle strip - int numberOfVertices = 10; +vtkNew<vtkUnstructuredGrid> MakeTriangleStrip() +{ + // A triangle is a cell that represents a triangle strip. + auto numberOfVertices = 10; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); @@ -461,7 +495,8 @@ vtkNew<vtkUnstructuredGrid> MakeTriangleStrip() { vtkNew<vtkTriangleStrip> trianglestrip; trianglestrip->GetPointIds()->SetNumberOfIds(numberOfVertices); - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { trianglestrip->GetPointIds()->SetId(i, i); } @@ -473,9 +508,10 @@ vtkNew<vtkUnstructuredGrid> MakeTriangleStrip() { return ug; } -vtkNew<vtkUnstructuredGrid> MakePolygon() { - // A polygon is a cell that represents a polygon - int numberOfVertices = 6; +vtkNew<vtkUnstructuredGrid> MakePolygon() +{ + // A polygon is a cell that represents a polygon. + auto numberOfVertices = 6; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); @@ -487,7 +523,8 @@ vtkNew<vtkUnstructuredGrid> MakePolygon() { vtkNew<vtkPolygon> polygon; polygon->GetPointIds()->SetNumberOfIds(numberOfVertices); - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { polygon->GetPointIds()->SetId(i, i); } @@ -501,17 +538,19 @@ vtkNew<vtkUnstructuredGrid> MakePolygon() { vtkNew<vtkUnstructuredGrid> MakePixel() { - // A pixel is a cell that represents a pixel + // A pixel is a cell that represents a pixel. + auto numberOfVertices = 4; + vtkNew<vtkPixel> pixel; pixel->GetPoints()->SetPoint(0, 0, 0, 0); pixel->GetPoints()->SetPoint(1, 1, 0, 0); pixel->GetPoints()->SetPoint(2, 0, 1, 0); pixel->GetPoints()->SetPoint(3, 1, 1, 0); - pixel->GetPointIds()->SetId(0, 0); - pixel->GetPointIds()->SetId(1, 1); - pixel->GetPointIds()->SetId(2, 2); - pixel->GetPointIds()->SetId(3, 3); + for (auto i = 0; i < numberOfVertices; ++i) + { + pixel->GetPointIds()->SetId(i, i); + } vtkNew<vtkUnstructuredGrid> ug; ug->SetPoints(pixel->GetPoints()); @@ -523,17 +562,19 @@ vtkNew<vtkUnstructuredGrid> MakePixel() vtkNew<vtkUnstructuredGrid> MakeQuad() { - // A quad is a cell that represents a quad + // A quad is a cell that represents a quad. + auto numberOfVertices = 4; + vtkNew<vtkQuad> quad; quad->GetPoints()->SetPoint(0, 0, 0, 0); quad->GetPoints()->SetPoint(1, 1, 0, 0); quad->GetPoints()->SetPoint(2, 1, 1, 0); quad->GetPoints()->SetPoint(3, 0, 1, 0); - quad->GetPointIds()->SetId(0, 0); - quad->GetPointIds()->SetId(1, 1); - quad->GetPointIds()->SetId(2, 2); - quad->GetPointIds()->SetId(3, 3); + for (auto i = 0; i < numberOfVertices; ++i) + { + quad->GetPointIds()->SetId(i, i); + } vtkNew<vtkUnstructuredGrid> ug; ug->SetPoints(quad->GetPoints()); @@ -542,18 +583,27 @@ vtkNew<vtkUnstructuredGrid> MakeQuad() return ug; } -vtkNew<vtkUnstructuredGrid> MakeTetra() { +vtkNew<vtkUnstructuredGrid> MakeTetra() +{ // Make a tetrahedron. - int numberOfVertices = 4; + auto numberOfVertices = 4; + + // vtkNew<vtkPoints> points; + // points->InsertNextPoint(0, 0, 0); + // points->InsertNextPoint(1, 0, 0); + // points->InsertNextPoint(1, 1, 0); + // points->InsertNextPoint(0, 1, 1); + // Rotate the above points -90° about the X-axis. vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); points->InsertNextPoint(1, 0, 0); - points->InsertNextPoint(1, 1, 0); - points->InsertNextPoint(0, 1, 1); + points->InsertNextPoint(1, 0, -1); + points->InsertNextPoint(0, 1, -1); vtkNew<vtkTetra> tetra; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { tetra->GetPointIds()->SetId(i, i); } @@ -567,9 +617,10 @@ vtkNew<vtkUnstructuredGrid> MakeTetra() { return unstructuredGrid; } -vtkNew<vtkUnstructuredGrid> MakeVoxel() { +vtkNew<vtkUnstructuredGrid> MakeVoxel() +{ // A voxel is a representation of a regular grid in 3-D space. - int numberOfVertices = 8; + auto numberOfVertices = 8; vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); @@ -582,7 +633,8 @@ vtkNew<vtkUnstructuredGrid> MakeVoxel() { points->InsertNextPoint(1, 1, 1); vtkNew<vtkVoxel> voxel; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { voxel->GetPointIds()->SetId(i, i); } @@ -593,7 +645,8 @@ vtkNew<vtkUnstructuredGrid> MakeVoxel() { return ug; } -vtkNew<vtkUnstructuredGrid> MakeHexahedron() { +vtkNew<vtkUnstructuredGrid> MakeHexahedron() +{ // A regular hexagon (cube) with all faces square and three squares around // each vertex is created below. @@ -601,7 +654,7 @@ vtkNew<vtkUnstructuredGrid> MakeHexahedron() { // (the two faces must be in counter-clockwise // order as viewed from the outside). - int numberOfVertices = 8; + auto numberOfVertices = 8; // Create the points vtkNew<vtkPoints> points; @@ -616,7 +669,8 @@ vtkNew<vtkUnstructuredGrid> MakeHexahedron() { // Create a hexahedron from the points vtkNew<vtkHexahedron> hex; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { hex->GetPointIds()->SetId(i, i); } @@ -628,23 +682,34 @@ vtkNew<vtkUnstructuredGrid> MakeHexahedron() { return uGrid; } -vtkNew<vtkUnstructuredGrid> MakeWedge() { +vtkNew<vtkUnstructuredGrid> MakeWedge() +{ // A wedge consists of two triangular ends and three rectangular faces. - int numberOfVertices = 6; + auto numberOfVertices = 6; - vtkNew<vtkPoints> points; + // vtkNew<vtkPoints> points; + // points->InsertNextPoint(0, 1, 0); + // points->InsertNextPoint(0, 0, 0); + // points->InsertNextPoint(0, 0.5, 0.5); + // points->InsertNextPoint(1, 1, 0); + // points->InsertNextPoint(1, 0.0, 0.0); + // points->InsertNextPoint(1, 0.5, 0.5); - points->InsertNextPoint(0, 1, 0); + // Rotate the above points -90° about the X-axis + // and translate -1 along the Y-axis. + vtkNew<vtkPoints> points; points->InsertNextPoint(0, 0, 0); + points->InsertNextPoint(0, 0, 1); points->InsertNextPoint(0, 0.5, 0.5); - points->InsertNextPoint(1, 1, 0); - points->InsertNextPoint(1, 0.0, 0.0); + points->InsertNextPoint(1, 0, 0); + points->InsertNextPoint(1, 0, 1); points->InsertNextPoint(1, 0.5, 0.5); vtkNew<vtkWedge> wedge; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { wedge->GetPointIds()->SetId(i, i); } @@ -655,17 +720,25 @@ vtkNew<vtkUnstructuredGrid> MakeWedge() { return ug; } -vtkNew<vtkUnstructuredGrid> MakePyramid() { +vtkNew<vtkUnstructuredGrid> MakePyramid() +{ // Make a regular square pyramid. - int numberOfVertices = 5; + auto numberOfVertices = 5; vtkNew<vtkPoints> points; - float p0[3] = {1.0, 1.0, 0.0}; - float p1[3] = {-1.0, 1.0, 0.0}; - float p2[3] = {-1.0, -1.0, 0.0}; - float p3[3] = {1.0, -1.0, 0.0}; - float p4[3] = {0.0, 0.0, 1.0}; + // float p0[3] = {1.0, 1.0, 0.0}; + // float p1[3] = {-1.0, 1.0, 0.0}; + // float p2[3] = {-1.0, -1.0, 0.0}; + // float p3[3] = {1.0, -1.0, 0.0}; + // float p4[3] = {0.0, 0.0, 1.0}; + + // Rotate the above points -90° about the X-axis. + float p0[3] = {1.0, 0.0, -1.0}; + float p1[3] = {-1.0, 0.0, -1.0}; + float p2[3] = {-1.0, 0.0, 1.0}; + float p3[3] = {1.0, 0.0, 1.0}; + float p4[3] = {0.0, 2.0, 0.0}; points->InsertNextPoint(p0); points->InsertNextPoint(p1); @@ -674,7 +747,8 @@ vtkNew<vtkUnstructuredGrid> MakePyramid() { points->InsertNextPoint(p4); vtkNew<vtkPyramid> pyramid; - for (int i = 0; i < numberOfVertices; ++i) { + for (auto i = 0; i < numberOfVertices; ++i) + { pyramid->GetPointIds()->SetId(i, i); } @@ -684,19 +758,11 @@ vtkNew<vtkUnstructuredGrid> MakePyramid() { return ug; } -vtkNew<vtkUnstructuredGrid> MakePentagonalPrism() { - vtkNew<vtkPentagonalPrism> pentagonalPrism; +vtkNew<vtkUnstructuredGrid> MakePentagonalPrism() +{ + auto numberOfVertices = 10; - pentagonalPrism->GetPointIds()->SetId(0, 0); - pentagonalPrism->GetPointIds()->SetId(1, 1); - pentagonalPrism->GetPointIds()->SetId(2, 2); - pentagonalPrism->GetPointIds()->SetId(3, 3); - pentagonalPrism->GetPointIds()->SetId(4, 4); - pentagonalPrism->GetPointIds()->SetId(5, 5); - pentagonalPrism->GetPointIds()->SetId(6, 6); - pentagonalPrism->GetPointIds()->SetId(7, 7); - pentagonalPrism->GetPointIds()->SetId(8, 8); - pentagonalPrism->GetPointIds()->SetId(9, 9); + vtkNew<vtkPentagonalPrism> pentagonalPrism; double scale = 2.0; pentagonalPrism->GetPoints()->SetPoint(0, 11 / scale, 10 / scale, 10 / scale); @@ -710,6 +776,11 @@ vtkNew<vtkUnstructuredGrid> MakePentagonalPrism() { pentagonalPrism->GetPoints()->SetPoint(8, 12 / scale, 14 / scale, 14 / scale); pentagonalPrism->GetPoints()->SetPoint(9, 10 / scale, 12 / scale, 14 / scale); + for (auto i = 0; i < numberOfVertices; ++i) + { + pentagonalPrism->GetPointIds()->SetId(i, i); + } + vtkNew<vtkUnstructuredGrid> ug; ug->SetPoints(pentagonalPrism->GetPoints()); ug->InsertNextCell(pentagonalPrism->GetCellType(), @@ -718,20 +789,11 @@ vtkNew<vtkUnstructuredGrid> MakePentagonalPrism() { return ug; } -vtkNew<vtkUnstructuredGrid> MakeHexagonalPrism() { +vtkNew<vtkUnstructuredGrid> MakeHexagonalPrism() +{ + auto numberOfVertices = 12; + vtkNew<vtkHexagonalPrism> hexagonalPrism; - hexagonalPrism->GetPointIds()->SetId(0, 0); - hexagonalPrism->GetPointIds()->SetId(1, 1); - hexagonalPrism->GetPointIds()->SetId(2, 2); - hexagonalPrism->GetPointIds()->SetId(3, 3); - hexagonalPrism->GetPointIds()->SetId(4, 4); - hexagonalPrism->GetPointIds()->SetId(5, 5); - hexagonalPrism->GetPointIds()->SetId(6, 6); - hexagonalPrism->GetPointIds()->SetId(7, 7); - hexagonalPrism->GetPointIds()->SetId(8, 8); - hexagonalPrism->GetPointIds()->SetId(9, 9); - hexagonalPrism->GetPointIds()->SetId(10, 10); - hexagonalPrism->GetPointIds()->SetId(11, 11); double scale = 2.0; hexagonalPrism->GetPoints()->SetPoint(0, 11 / scale, 10 / scale, 10 / scale); @@ -747,6 +809,11 @@ vtkNew<vtkUnstructuredGrid> MakeHexagonalPrism() { hexagonalPrism->GetPoints()->SetPoint(10, 11 / scale, 14 / scale, 14 / scale); hexagonalPrism->GetPoints()->SetPoint(11, 10 / scale, 12 / scale, 14 / scale); + for (auto i = 0; i < numberOfVertices; ++i) + { + hexagonalPrism->GetPointIds()->SetId(i, i); + } + vtkNew<vtkUnstructuredGrid> ug; ug->SetPoints(hexagonalPrism->GetPoints()); ug->InsertNextCell(hexagonalPrism->GetCellType(), @@ -766,8 +833,9 @@ vtkNew<vtkUnstructuredGrid> MakeHexagonalPrism() { * @param thicknessRatio - the thickness ratio in the Y direction, >= 0. * @return An actor corresponding to the tile. */ -vtkNew<vtkActor> MakeTile(double *const &bounds, double const &expansionFactor, - double const &thicknessRatio) { +vtkNew<vtkActor> MakeTile(double* const& bounds, double const& expansionFactor, + double const& thicknessRatio) +{ std::vector<double> d_xyz = {bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4]}; auto thickness = d_xyz[2] * std::abs(thicknessRatio); diff --git a/src/Cxx/GeometricObjects/LinearCellDemo.md b/src/Cxx/GeometricObjects/LinearCellDemo.md index 4d2dadaacf29e83a45df1b76cbe857b75ba76998..b0b8d3215785d7a64be96e5d19b1665199f71f97 100644 --- a/src/Cxx/GeometricObjects/LinearCellDemo.md +++ b/src/Cxx/GeometricObjects/LinearCellDemo.md @@ -2,8 +2,8 @@ Linear cell types found in VTK. -The numbers define ordering of the defining points. As a general guide, for non-planar three-dimensional objects, the back face indices in the views are numbered 0, 1, 2, however, for the VTK_WEDGE, the back face is 0, 4, 3. Of course, if you change the orientation, you will get different numbering for the back face. +The numbers define the ordering of the defining points. -Options are provided to show a wire frame (`-w`) or to add a back face color (`-b`). +Options are provided to show a wire frame (`-w`) or to add a back face color (`-b`). You can also remove the plinth with the (`-n`) option. With the back face option selected, the back face color will be visible as the objects are semitransparent. diff --git a/src/Python/GeometricObjects/LinearCellDemo.md b/src/Python/GeometricObjects/LinearCellDemo.md index 4d2dadaacf29e83a45df1b76cbe857b75ba76998..b0b8d3215785d7a64be96e5d19b1665199f71f97 100644 --- a/src/Python/GeometricObjects/LinearCellDemo.md +++ b/src/Python/GeometricObjects/LinearCellDemo.md @@ -2,8 +2,8 @@ Linear cell types found in VTK. -The numbers define ordering of the defining points. As a general guide, for non-planar three-dimensional objects, the back face indices in the views are numbered 0, 1, 2, however, for the VTK_WEDGE, the back face is 0, 4, 3. Of course, if you change the orientation, you will get different numbering for the back face. +The numbers define the ordering of the defining points. -Options are provided to show a wire frame (`-w`) or to add a back face color (`-b`). +Options are provided to show a wire frame (`-w`) or to add a back face color (`-b`). You can also remove the plinth with the (`-n`) option. With the back face option selected, the back face color will be visible as the objects are semitransparent. diff --git a/src/Python/GeometricObjects/LinearCellDemo.py b/src/Python/GeometricObjects/LinearCellDemo.py index e3195b29722ff290507d9534e8fe1d326abc347d..a433184e89d2d2d7076e9cfd27ff0437ba0a21ed 100755 --- a/src/Python/GeometricObjects/LinearCellDemo.py +++ b/src/Python/GeometricObjects/LinearCellDemo.py @@ -60,12 +60,15 @@ def get_program_parameters(): help='Render a wireframe.') group1.add_argument('-b', '--backface', action='store_true', help='Display the back face in a different colour.') + + parser.add_argument('-n', '--no_plinth', action='store_true', + help='Remove the plinth.') args = parser.parse_args() - return args.wireframe, args.backface + return args.wireframe, args.backface, args.no_plinth def main(): - wireframe_on, backface_on = get_program_parameters() + wireframe_on, backface_on, plinth_off = get_program_parameters() colors = vtkNamedColors() @@ -75,32 +78,18 @@ def main(): sphere.SetThetaResolution(21) sphere.SetRadius(0.04) - renderer_size = 300 - - # Create one text property for all. - text_property = vtkTextProperty() - text_property.SetFontSize(int(renderer_size / 18)) - text_property.BoldOn() - text_property.SetJustificationToCentered() - text_property.SetColor(colors.GetColor3d('Black')) - - label_property = vtkTextProperty() - label_property.SetFontSize(int(renderer_size / 12)) - label_property.BoldOn() - label_property.SetJustificationToCentered() - label_property.SetColor(colors.GetColor3d('FireBrick')) - - back_property = vtkProperty() - back_property.SetColor(colors.GetColor3d('Coral')) - - renderers = dict() + cells = get_unstructured_grids() + keys = list(cells.keys()) - cells = get_cells() - needs_a_tile = ('VTK_VOXEL (=11)', - 'VTK_HEXAHEDRON (=12)', - 'VTK_PENTAGONAL_PRISM (=15)', - 'VTK_HEXAGONAL_PRISM (=16)', - ) + add_plinth = ('VTK_TETRA (=10)', + 'VTK_VOXEL (=11)', + 'VTK_HEXAHEDRON (=12)', + 'VTK_WEDGE (=13)', + 'VTK_PYRAMID (=14)', + 'VTK_PENTAGONAL_PRISM (=15)', + 'VTK_HEXAGONAL_PRISM (=16)', + ) + lines = ('VTK_LINE (=3)', 'VTK_POLY_LINE (=4)') # Set up the viewports. grid_column_dimensions = 4 @@ -108,8 +97,6 @@ def main(): renderer_size = 300 window_size = (grid_column_dimensions * renderer_size, grid_row_dimensions * renderer_size) - keys = list(cells.keys()) - viewports = dict() blank = len(cells) blank_viewports = list() @@ -136,6 +123,23 @@ def main(): viewports[s] = viewport blank_viewports.append(s) + # Create one text property for all. + text_property = vtkTextProperty() + text_property.SetFontSize(int(renderer_size / 18)) + text_property.BoldOn() + text_property.SetJustificationToCentered() + text_property.SetColor(colors.GetColor3d('Black')) + + label_property = vtkTextProperty() + label_property.SetFontSize(int(renderer_size / 12)) + label_property.BoldOn() + label_property.ShadowOn() + label_property.SetJustificationToCentered() + label_property.SetColor(colors.GetColor3d('DeepPink')) + + back_property = vtkProperty() + back_property.SetColor(colors.GetColor3d('DodgerBlue')) + ren_win = vtkRenderWindow() ren_win.SetSize(window_size) ren_win.SetWindowName('LinearCellDemo') @@ -143,6 +147,8 @@ def main(): iren = vtkRenderWindowInteractor() iren.SetRenderWindow(ren_win) + renderers = dict() + # Create and link the mappers, actors and renderers together. keys = cells.keys() for key in keys: @@ -159,7 +165,7 @@ def main(): mapper.SetInputData(cells[key][0]) actor = vtkActor() actor.SetMapper(mapper) - if wireframe_on: + if wireframe_on or key in lines: actor.GetProperty().SetRepresentationToWireframe() actor.GetProperty().SetLineWidth(2) actor.GetProperty().SetOpacity(1) @@ -191,23 +197,23 @@ def main(): point_actor = vtkActor() point_actor.SetMapper(point_mapper) - point_actor.GetProperty().SetColor(colors.GetColor3d('Yellow')) - point_actor.GetProperty().SetSpecular(1.0) - point_actor.GetProperty().SetSpecularColor(colors.GetColor3d('White')) - point_actor.GetProperty().SetSpecularPower(100) + point_actor.GetProperty().SetColor(colors.GetColor3d('Gold')) - renderer = vtkRenderer(background=colors.GetColor3d('CornflowerBlue'), viewport=viewports[key]) + renderer = vtkRenderer() + renderer.SetBackground(colors.GetColor3d('LightSteelBlue')) + renderer.SetViewport(viewports[key]) renderer.AddActor(text_actor) renderer.AddActor(actor) renderer.AddActor(label_actor) renderer.AddActor(point_actor) - # Add a plane. - if key in needs_a_tile: - tile_actor = make_tile(cells[key][0].GetBounds(), expansion_factor=0.1, thickness_ratio=0.05) - tile_actor.GetProperty().SetColor(colors.GetColor3d('SpringGreen')) - tile_actor.GetProperty().SetOpacity(0.3) - renderer.AddActor(tile_actor) + if not plinth_off: + # Add a plinth. + if key in add_plinth: + tile_actor = make_tile(cells[key][0].GetBounds(), expansion_factor=0.5, thickness_ratio=0.05) + tile_actor.GetProperty().SetColor(colors.GetColor3d('Lavender')) + tile_actor.GetProperty().SetOpacity(0.3) + renderer.AddActor(tile_actor) renderer.ResetCamera() renderer.GetActiveCamera().Azimuth(cells[key][1]) @@ -221,7 +227,9 @@ def main(): for name in blank_viewports: viewport = viewports[name] - renderer = vtkRenderer(background=colors.GetColor3d('CornflowerBlue'), viewport=viewport) + renderer = vtkRenderer() + renderer.SetBackground = colors.GetColor3d('LightSteelBlue') + renderer.SetViewport(viewport) ren_win.AddRenderer(renderer) ren_win.Render() @@ -229,13 +237,14 @@ def main(): iren.Start() -def get_cells(): +def get_unstructured_grids(): """ - get the cells along with their orientation. - :return: A dictionary of cells. + Get the unstructured grids along with their orientation. + + :return: A dictionary of unstructured grids. """ cells = dict() - # name, unsigned grid source, dolly, azimuth, elevation. + # name, unstructured grid source, azimuth, elevation and dolly. cells['VTK_VERTEX (=1)'] = (make_vertex(), 30, -30, 0.1) cells['VTK_POLY_VERTEX (=2)'] = (make_poly_vertex(), 30, -30, 0.8) cells['VTK_LINE (=3)'] = (make_line(), 30, -30, 0.4) @@ -245,14 +254,13 @@ def get_cells(): cells['VTK_POLYGON (=7)'] = (make_polygon(), 0, -45, 1.0) cells['VTK_PIXEL (=8)'] = (make_pixel(), 0, -45, 1.0) cells['VTK_QUAD (=9)'] = (make_quad(), 0, -45, 1.0) - cells['VTK_TETRA (=10)'] = (make_tetra(), 0, -45, 0.95) + cells['VTK_TETRA (=10)'] = (make_tetra(), 20, 20, 1.0) cells['VTK_VOXEL (=11)'] = (make_voxel(), -22.5, 15, 0.95) cells['VTK_HEXAHEDRON (=12)'] = (make_hexahedron(), -22.5, 15, 0.95) - cells['VTK_WEDGE (=13)'] = (make_wedge(), -45, 15, 0.9) - cells['VTK_PYRAMID (=14)'] = (make_pyramid(), 0, -30, 1.0) - # cells['VTK_PENTAGONAL_PRISM (=15)'] = (make_pentagonal_prism(), -22.5, 15, 0.95) - cells['VTK_PENTAGONAL_PRISM (=15)'] = (make_pentagonal_prism(), -30, 15, 0.95) - cells['VTK_HEXAGONAL_PRISM (=16)'] = (make_hexagonal_prism(), -30, 15, 0.95) + cells['VTK_WEDGE (=13)'] = (make_wedge(), -30, 15, 1.0) + cells['VTK_PYRAMID (=14)'] = (make_pyramid(), -60, 15, 1.0) + cells['VTK_PENTAGONAL_PRISM (=15)'] = (make_pentagonal_prism(), -60, 10, 1.0) + cells['VTK_HEXAGONAL_PRISM (=16)'] = (make_hexagonal_prism(), -60, 15, 1.0) return cells @@ -260,7 +268,7 @@ def get_cells(): # These functions return an vtkUnstructured grid corresponding to the object. def make_vertex(): - # A vertex is a cell that represents a 3D point + # A vertex is a cell that represents a 3D point. number_of_vertices = 1 points = vtkPoints() @@ -278,7 +286,7 @@ def make_vertex(): def make_poly_vertex(): - # A polyvertex is a cell represents a set of 0D vertices + # A polyvertex is a cell that represents a set of 0D vertices. number_of_vertices = 6 points = vtkPoints() @@ -303,7 +311,7 @@ def make_poly_vertex(): def make_line(): - # A line is a cell that represents a 1D point + # A line is a cell that represents a 1D point. number_of_vertices = 2 points = vtkPoints() @@ -322,7 +330,7 @@ def make_line(): def make_polyline(): - # A polyline is a cell that represents a set of 1D lines + # A polyline is a cell that represents a set of 1D lines. number_of_vertices = 5 points = vtkPoints() @@ -346,7 +354,7 @@ def make_polyline(): def make_triangle(): - # A triangle is a cell that represents a 1D point + # A triangle is a cell that represents a triangle. number_of_vertices = 3 points = vtkPoints() @@ -366,7 +374,7 @@ def make_triangle(): def make_triangle_strip(): - # A triangle is a cell that represents a triangle strip + # A triangle strip is a cell that represents a triangle strip. number_of_vertices = 10 points = vtkPoints() @@ -381,20 +389,20 @@ def make_triangle_strip(): points.InsertNextPoint(3.5, 0.8, 0) points.InsertNextPoint(4.5, 1.1, 0) - trianglestrip = vtkTriangleStrip() - trianglestrip.GetPointIds().SetNumberOfIds(number_of_vertices) + triangle_strip = vtkTriangleStrip() + triangle_strip.GetPointIds().SetNumberOfIds(number_of_vertices) for i in range(0, number_of_vertices): - trianglestrip.GetPointIds().SetId(i, i) + triangle_strip.GetPointIds().SetId(i, i) ug = vtkUnstructuredGrid() ug.SetPoints(points) - ug.InsertNextCell(trianglestrip.GetCellType(), trianglestrip.GetPointIds()) + ug.InsertNextCell(triangle_strip.GetCellType(), triangle_strip.GetPointIds()) return ug def make_polygon(): - # A polygon is a cell that represents a polygon + # A polygon is a cell that represents a polygon. number_of_vertices = 6 points = vtkPoints() @@ -419,16 +427,16 @@ def make_polygon(): def make_pixel(): # A pixel is a cell that represents a pixel + number_of_vertices = 4 + pixel = vtkPixel() pixel.GetPoints().SetPoint(0, 0, 0, 0) pixel.GetPoints().SetPoint(1, 1, 0, 0) pixel.GetPoints().SetPoint(2, 0, 1, 0) pixel.GetPoints().SetPoint(3, 1, 1, 0) - pixel.GetPointIds().SetId(0, 0) - pixel.GetPointIds().SetId(1, 1) - pixel.GetPointIds().SetId(2, 2) - pixel.GetPointIds().SetId(3, 3) + for i in range(0, number_of_vertices): + pixel.GetPointIds().SetId(i, i) ug = vtkUnstructuredGrid() ug.SetPoints(pixel.GetPoints()) @@ -439,16 +447,16 @@ def make_pixel(): def make_quad(): # A quad is a cell that represents a quad + number_of_vertices = 4 + quad = vtkQuad() quad.GetPoints().SetPoint(0, 0, 0, 0) quad.GetPoints().SetPoint(1, 1, 0, 0) quad.GetPoints().SetPoint(2, 1, 1, 0) quad.GetPoints().SetPoint(3, 0, 1, 0) - quad.GetPointIds().SetId(0, 0) - quad.GetPointIds().SetId(1, 1) - quad.GetPointIds().SetId(2, 2) - quad.GetPointIds().SetId(3, 3) + for i in range(0, number_of_vertices): + quad.point_ids.SetId(i, i) ug = vtkUnstructuredGrid() ug.SetPoints(quad.GetPoints()) @@ -462,10 +470,16 @@ def make_tetra(): number_of_vertices = 4 points = vtkPoints() - points.InsertNextPoint(0, 0, 0) - points.InsertNextPoint(1, 0, 0) - points.InsertNextPoint(1, 1, 0) - points.InsertNextPoint(0, 1, 1) + # points.InsertNextPoint(0, 0, 0) + # points.InsertNextPoint(1, 0, 0) + # points.InsertNextPoint(1, 1, 0) + # points.InsertNextPoint(0, 1, 1) + + # Rotate the above points -90° about the X-axis. + points.InsertNextPoint((0.0, 0.0, 0.0)) + points.InsertNextPoint((1.0, 0.0, 0.0)) + points.InsertNextPoint((1.0, 0.0, -1.0)) + points.InsertNextPoint((0.0, 1.0, -1.0)) tetra = vtkTetra() for i in range(0, number_of_vertices): @@ -507,16 +521,19 @@ def make_voxel(): def make_hexahedron(): - # A regular hexagon (cube) with all faces square and three squares around - # each vertex is created below. + """ + A regular hexagon (cube) with all faces square and three squares + around each vertex is created below. - # Set up the coordinates of eight points - # (the two faces must be in counter-clockwise - # order as viewed from the outside). + Set up the coordinates of eight points, (the two faces must be + in counter-clockwise order as viewed from the outside). + + :return: + """ number_of_vertices = 8 - # Create the points + # Create the points. points = vtkPoints() points.InsertNextPoint(0, 0, 0) points.InsertNextPoint(1, 0, 0) @@ -527,15 +544,15 @@ def make_hexahedron(): points.InsertNextPoint(1, 1, 1) points.InsertNextPoint(0, 1, 1) - # Create a hexahedron from the points - hexhedr = vtkHexahedron() + # Create a hexahedron from the points. + hexahedron = vtkHexahedron() for i in range(0, number_of_vertices): - hexhedr.GetPointIds().SetId(i, i) + hexahedron.GetPointIds().SetId(i, i) # Add the points and hexahedron to an unstructured grid ug = vtkUnstructuredGrid() ug.SetPoints(points) - ug.InsertNextCell(hexhedr.GetCellType(), hexhedr.GetPointIds()) + ug.InsertNextCell(hexahedron.GetCellType(), hexahedron.GetPointIds()) return ug @@ -547,12 +564,21 @@ def make_wedge(): points = vtkPoints() - points.InsertNextPoint(0, 1, 0) - points.InsertNextPoint(0, 0, 0) - points.InsertNextPoint(0, 0.5, 0.5) - points.InsertNextPoint(1, 1, 0) - points.InsertNextPoint(1, 0.0, 0.0) - points.InsertNextPoint(1, 0.5, 0.5) + # points.InsertNextPoint(0, 1, 0) + # points.InsertNextPoint(0, 0, 0) + # points.InsertNextPoint(0, 0.5, 0.5) + # points.InsertNextPoint(1, 1, 0) + # points.InsertNextPoint(1, 0.0, 0.0) + # points.InsertNextPoint(1, 0.5, 0.5) + + # Rotate the above points -90° about the X-axis + # and translate -1 along the Y-axis. + points.InsertNextPoint(0.0, 0.0, 0.0) + points.InsertNextPoint(0.0, 0, 1.0) + points.InsertNextPoint(0.0, 0.5, 0.5) + points.InsertNextPoint(1.0, 0.0, 0.0) + points.InsertNextPoint(1.0, 0, 1.0) + points.InsertNextPoint(1.0, 0.5, 0.5) wedge = vtkWedge() for i in range(0, number_of_vertices): @@ -571,11 +597,18 @@ def make_pyramid(): points = vtkPoints() - p0 = [1.0, 1.0, 0.0] - p1 = [-1.0, 1.0, 0.0] - p2 = [-1.0, -1.0, 0.0] - p3 = [1.0, -1.0, 0.0] - p4 = [0.0, 0.0, 1.0] + # p0 = [1.0, 1.0, 0.0] + # p1 = [-1.0, 1.0, 0.0] + # p2 = [-1.0, -1.0, 0.0] + # p3 = [1.0, -1.0, 0.0] + # p4 = [0.0, 0.0, 1.0] + + # Rotate the above points -90° about the X-axis. + p0 = (1.0, 0, -1.0) + p1 = (-1.0, 0, -1.0) + p2 = (-1.0, 0, 1.0) + p3 = (1.0, 0, 1.0) + p4 = (0.0, 2.0, 0) points.InsertNextPoint(p0) points.InsertNextPoint(p1) @@ -595,18 +628,9 @@ def make_pyramid(): def make_pentagonal_prism(): - pentagonal_prism = vtkPentagonalPrism() + number_of_vertices = 10 - pentagonal_prism.GetPointIds().SetId(0, 0) - pentagonal_prism.GetPointIds().SetId(1, 1) - pentagonal_prism.GetPointIds().SetId(2, 2) - pentagonal_prism.GetPointIds().SetId(3, 3) - pentagonal_prism.GetPointIds().SetId(4, 4) - pentagonal_prism.GetPointIds().SetId(5, 5) - pentagonal_prism.GetPointIds().SetId(6, 6) - pentagonal_prism.GetPointIds().SetId(7, 7) - pentagonal_prism.GetPointIds().SetId(8, 8) - pentagonal_prism.GetPointIds().SetId(9, 9) + pentagonal_prism = vtkPentagonalPrism() scale = 2.0 pentagonal_prism.GetPoints().SetPoint(0, 11 / scale, 10 / scale, 10 / scale) @@ -620,6 +644,9 @@ def make_pentagonal_prism(): pentagonal_prism.GetPoints().SetPoint(8, 12 / scale, 14 / scale, 14 / scale) pentagonal_prism.GetPoints().SetPoint(9, 10 / scale, 12 / scale, 14 / scale) + for i in range(0, number_of_vertices): + pentagonal_prism.point_ids.SetId(i, i) + ug = vtkUnstructuredGrid() ug.SetPoints(pentagonal_prism.GetPoints()) ug.InsertNextCell(pentagonal_prism.GetCellType(), pentagonal_prism.GetPointIds()) @@ -628,19 +655,9 @@ def make_pentagonal_prism(): def make_hexagonal_prism(): + number_of_vertices = 12 + hexagonal_prism = vtkHexagonalPrism() - hexagonal_prism.GetPointIds().SetId(0, 0) - hexagonal_prism.GetPointIds().SetId(1, 1) - hexagonal_prism.GetPointIds().SetId(2, 2) - hexagonal_prism.GetPointIds().SetId(3, 3) - hexagonal_prism.GetPointIds().SetId(4, 4) - hexagonal_prism.GetPointIds().SetId(5, 5) - hexagonal_prism.GetPointIds().SetId(6, 6) - hexagonal_prism.GetPointIds().SetId(7, 7) - hexagonal_prism.GetPointIds().SetId(8, 8) - hexagonal_prism.GetPointIds().SetId(9, 9) - hexagonal_prism.GetPointIds().SetId(10, 10) - hexagonal_prism.GetPointIds().SetId(11, 11) scale = 2.0 hexagonal_prism.GetPoints().SetPoint(0, 11 / scale, 10 / scale, 10 / scale) @@ -656,6 +673,9 @@ def make_hexagonal_prism(): hexagonal_prism.GetPoints().SetPoint(10, 11 / scale, 14 / scale, 14 / scale) hexagonal_prism.GetPoints().SetPoint(11, 10 / scale, 12 / scale, 14 / scale) + for i in range(0, number_of_vertices): + hexagonal_prism.point_ids.SetId(i, i) + ug = vtkUnstructuredGrid() ug.SetPoints(hexagonal_prism.GetPoints()) ug.InsertNextCell(hexagonal_prism.GetCellType(), hexagonal_prism.GetPointIds()) diff --git a/src/PythonicAPI/GeometricObjects/LinearCellDemo.md b/src/PythonicAPI/GeometricObjects/LinearCellDemo.md index 4d2dadaacf29e83a45df1b76cbe857b75ba76998..b0b8d3215785d7a64be96e5d19b1665199f71f97 100644 --- a/src/PythonicAPI/GeometricObjects/LinearCellDemo.md +++ b/src/PythonicAPI/GeometricObjects/LinearCellDemo.md @@ -2,8 +2,8 @@ Linear cell types found in VTK. -The numbers define ordering of the defining points. As a general guide, for non-planar three-dimensional objects, the back face indices in the views are numbered 0, 1, 2, however, for the VTK_WEDGE, the back face is 0, 4, 3. Of course, if you change the orientation, you will get different numbering for the back face. +The numbers define the ordering of the defining points. -Options are provided to show a wire frame (`-w`) or to add a back face color (`-b`). +Options are provided to show a wire frame (`-w`) or to add a back face color (`-b`). You can also remove the plinth with the (`-n`) option. With the back face option selected, the back face color will be visible as the objects are semitransparent. diff --git a/src/PythonicAPI/GeometricObjects/LinearCellDemo.py b/src/PythonicAPI/GeometricObjects/LinearCellDemo.py index 9d5999a0f51459b938a6e7d876fc6d61503d89cb..54aa9d080fc8a97afbec188949a290b8988986ec 100755 --- a/src/PythonicAPI/GeometricObjects/LinearCellDemo.py +++ b/src/PythonicAPI/GeometricObjects/LinearCellDemo.py @@ -31,7 +31,11 @@ from vtkmodules.vtkCommonDataModel import ( vtkVoxel, vtkWedge ) +# noinspection PyUnresolvedReferences +from vtkmodules.vtkCommonTransforms import vtkTransform from vtkmodules.vtkFiltersCore import vtkAppendPolyData +# noinspection PyUnresolvedReferences +from vtkmodules.vtkFiltersGeneral import vtkTransformFilter from vtkmodules.vtkFiltersSources import ( vtkCubeSource, vtkSphereSource @@ -71,24 +75,33 @@ def get_program_parameters(): help='Render a wireframe.') group1.add_argument('-b', '--backface', action='store_true', help='Display the back face in a different colour.') + + parser.add_argument('-n', '--no_plinth', action='store_true', + help='Remove the plinth.') args = parser.parse_args() - return args.wireframe, args.backface + return args.wireframe, args.backface, args.no_plinth def main(): - wireframe_on, backface_on = get_program_parameters() + wireframe_on, backface_on, plinth_off = get_program_parameters() colors = vtkNamedColors() # Create one sphere for all. sphere = vtkSphereSource(phi_resolution=21, theta_resolution=21, radius=0.04) - cells = get_cell_orientation() - needs_a_tile = ('VTK_VOXEL (=11)', - 'VTK_HEXAHEDRON (=12)', - 'VTK_PENTAGONAL_PRISM (=15)', - 'VTK_HEXAGONAL_PRISM (=16)', - ) + cells = get_unstructured_grids() + keys = list(cells.keys()) + + add_plinth = ('VTK_TETRA (=10)', + 'VTK_VOXEL (=11)', + 'VTK_HEXAHEDRON (=12)', + 'VTK_WEDGE (=13)', + 'VTK_PYRAMID (=14)', + 'VTK_PENTAGONAL_PRISM (=15)', + 'VTK_HEXAGONAL_PRISM (=16)', + ) + lines = ('VTK_LINE (=3)', 'VTK_POLY_LINE (=4)') # Set up the viewports. grid_column_dimensions = 4 @@ -96,8 +109,6 @@ def main(): renderer_size = 300 window_size = (grid_column_dimensions * renderer_size, grid_row_dimensions * renderer_size) - keys = list(cells.keys()) - viewports = dict() VP_Params = namedtuple('VP_Params', ['viewport', 'border']) last_col = False @@ -146,13 +157,13 @@ def main(): font_size=int(renderer_size / 18), justification=TextProperty.Justification.VTK_TEXT_CENTERED) - label_property = vtkTextProperty(color=colors.GetColor3d('FireBrick'), - bold=True, italic=False, shadow=False, + label_property = vtkTextProperty(color=colors.GetColor3d('DeepPink'), + bold=True, italic=False, shadow=True, font_family_as_string='Courier', font_size=int(renderer_size / 12), justification=TextProperty.Justification.VTK_TEXT_CENTERED) - back_property = vtkProperty(color=colors.GetColor3d('Coral')) + back_property = vtkProperty(color=colors.GetColor3d('DodgerBlue')) # Position text according to its length and centered in the viewport. text_positions = get_text_positions(keys, @@ -178,7 +189,7 @@ def main(): mapper = vtkDataSetMapper() cells[key][0] >> mapper actor = vtkActor(mapper=mapper) - if wireframe_on: + if wireframe_on or key in lines: actor.property.representation = Property.Representation.VTK_WIREFRAME actor.property.line_width = 2 actor.property.opacity = 1 @@ -205,25 +216,23 @@ def main(): source_connection=sphere.output_port) cells[key][0] >> point_mapper point_actor = vtkActor(mapper=point_mapper) - point_actor.property.color = colors.GetColor3d('Yellow') - point_actor.property.specular = 1.0 - point_actor.property.specular_color = colors.GetColor3d('White') - point_actor.property.specular_power = 100 + point_actor.property.color = colors.GetColor3d('Gold') viewport = viewports[key].viewport border = viewports[key].border - renderer = vtkRenderer(background=colors.GetColor3d('CornflowerBlue'), viewport=viewport) - draw_viewport_border(renderer, border=border, color=colors.GetColor3d('Yellow'), line_width=4) + renderer = vtkRenderer(background=colors.GetColor3d('LightSteelBlue'), viewport=viewport) + draw_viewport_border(renderer, border=border, color=colors.GetColor3d('MidnightBlue'), line_width=4) renderer.AddActor(actor) renderer.AddActor(label_actor) renderer.AddActor(point_actor) - # Add a plane. - if key in needs_a_tile: - tile_actor = make_tile(cells[key][0].GetBounds(), expansion_factor=0.1, thickness_ratio=0.05) - tile_actor.GetProperty().SetColor(colors.GetColor3d('SpringGreen')) - tile_actor.GetProperty().SetOpacity(0.3) - renderer.AddActor(tile_actor) + if not plinth_off: + # Add a plinth. + if key in add_plinth: + tile_actor = make_tile(cells[key][0].GetBounds(), expansion_factor=0.5, thickness_ratio=0.05) + tile_actor.GetProperty().SetColor(colors.GetColor3d('Lavender')) + tile_actor.GetProperty().SetOpacity(0.3) + renderer.AddActor(tile_actor) # Create the text actor and representation. text_actor = vtkTextActor(input=key, @@ -256,8 +265,8 @@ def main(): for name in blank_viewports: viewport = viewports[name].viewport border = viewports[name].border - renderer = vtkRenderer(background=colors.GetColor3d('CornflowerBlue'), viewport=viewport) - draw_viewport_border(renderer, border=border, color=colors.GetColor3d('Yellow'), line_width=4) + renderer = vtkRenderer(background=colors.GetColor3d('LightSteelBlue'), viewport=viewport) + draw_viewport_border(renderer, border=border, color=colors.GetColor3d('MidnightBlue'), line_width=4) ren_win.AddRenderer(renderer) for i in range(0, len(text_widgets)): @@ -268,11 +277,11 @@ def main(): iren.Start() -def get_cell_orientation(): +def get_unstructured_grids(): """ - Get the linear cell names, the cells and initial orientations. + Get the unstructured grid names, the unstructured grid and initial orientations. - :return: The linear cell names, the cells and initial orientations. + :return: A dictionary of unstructured grids. """ def make_orientation(azimuth: float = 0, elevation: float = 0, zoom: float = 1.0): @@ -288,14 +297,13 @@ def get_cell_orientation(): 'VTK_POLYGON (=7)': (make_polygon(), make_orientation(0, -45, 1.0)), 'VTK_PIXEL (=8)': (make_pixel(), make_orientation(0, -45, 1.0)), 'VTK_QUAD (=9)': (make_quad(), make_orientation(0, -45, 0)), - 'VTK_TETRA (=10)': (make_tetra(), make_orientation(0, -45, 0.95)), + 'VTK_TETRA (=10)': (make_tetra(), make_orientation(20, 20, 1.0)), 'VTK_VOXEL (=11)': (make_voxel(), make_orientation(-22.5, 15, 0.95)), 'VTK_HEXAHEDRON (=12)': (make_hexahedron(), make_orientation(-22.5, 15, 0.95)), - 'VTK_WEDGE (=13)': (make_wedge(), make_orientation(-45, 15, 1.0)), - 'VTK_PYRAMID (=14)': (make_pyramid(), make_orientation(0, -30, 1.0)), - # 'VTK_PENTAGONAL_PRISM (=15)': (make_pentagonal_prism(), make_orientation(-22.5, 15, 0.95)), - 'VTK_PENTAGONAL_PRISM (=15)': (make_pentagonal_prism(), make_orientation(-30, 15, 0.95)), - 'VTK_HEXAGONAL_PRISM (=16)': (make_hexagonal_prism(), make_orientation(-30, 15, 0.95)), + 'VTK_WEDGE (=13)': (make_wedge(), make_orientation(-30, 15, 1.0)), + 'VTK_PYRAMID (=14)': (make_pyramid(), make_orientation(-60, 15, 1.0)), + 'VTK_PENTAGONAL_PRISM (=15)': (make_pentagonal_prism(), make_orientation(-60, 10, 1.0)), + 'VTK_HEXAGONAL_PRISM (=16)': (make_hexagonal_prism(), make_orientation(-60, 15, 1.0)), } @@ -350,7 +358,7 @@ def make_poly_vertex(): def make_line(): - # A line is a cell that represents a 1D point + # A line is a cell that represents a 1D point. number_of_vertices = 2 points = vtkPoints() @@ -368,7 +376,7 @@ def make_line(): def make_polyline(): - # A polyline is a cell that represents a set of 1D lines + # A polyline is a cell that represents a set of 1D lines. number_of_vertices = 5 points = vtkPoints() @@ -391,7 +399,7 @@ def make_polyline(): def make_triangle(): - # A triangle is a cell that represents a 1D point + # A triangle is a cell that represents a triangle. number_of_vertices = 3 points = vtkPoints() @@ -410,7 +418,7 @@ def make_triangle(): def make_triangle_strip(): - # A triangle is a cell that represents a triangle strip + # A triangle is a cell that represents a triangle strip. number_of_vertices = 10 points = vtkPoints() @@ -425,19 +433,19 @@ def make_triangle_strip(): points.InsertNextPoint(3.5, 0.8, 0) points.InsertNextPoint(4.5, 1.1, 0) - trianglestrip = vtkTriangleStrip() - trianglestrip.point_ids.SetNumberOfIds(number_of_vertices) + triangle_strip = vtkTriangleStrip() + triangle_strip.point_ids.SetNumberOfIds(number_of_vertices) for i in range(0, number_of_vertices): - trianglestrip.point_ids.SetId(i, i) + triangle_strip.point_ids.SetId(i, i) ug = vtkUnstructuredGrid(points=points) - ug.InsertNextCell(trianglestrip.GetCellType(), trianglestrip.GetPointIds()) + ug.InsertNextCell(triangle_strip.GetCellType(), triangle_strip.GetPointIds()) return ug def make_polygon(): - # A polygon is a cell that represents a polygon + # A polygon is a cell that represents a polygon. number_of_vertices = 6 points = vtkPoints() @@ -460,17 +468,17 @@ def make_polygon(): def make_pixel(): - # A pixel is a cell that represents a pixel + # A pixel is a cell that represents a pixel. + number_of_vertices = 4 + pixel = vtkPixel() pixel.points.SetPoint(0, 0, 0, 0) pixel.points.SetPoint(1, 1, 0, 0) pixel.points.SetPoint(2, 0, 1, 0) pixel.points.SetPoint(3, 1, 1, 0) - pixel.point_ids.SetId(0, 0) - pixel.point_ids.SetId(1, 1) - pixel.point_ids.SetId(2, 2) - pixel.point_ids.SetId(3, 3) + for i in range(0, number_of_vertices): + pixel.point_ids.SetId(i, i) ug = vtkUnstructuredGrid(points=pixel.points) ug.InsertNextCell(pixel.GetCellType(), pixel.GetPointIds()) @@ -479,17 +487,17 @@ def make_pixel(): def make_quad(): - # A quad is a cell that represents a quad + # A quad is a cell that represents a quad. + number_of_vertices = 4 + quad = vtkQuad() quad.points.SetPoint(0, 0, 0, 0) quad.points.SetPoint(1, 1, 0, 0) quad.points.SetPoint(2, 1, 1, 0) quad.points.SetPoint(3, 0, 1, 0) - quad.point_ids.SetId(0, 0) - quad.point_ids.SetId(1, 1) - quad.point_ids.SetId(2, 2) - quad.point_ids.SetId(3, 3) + for i in range(0, number_of_vertices): + quad.point_ids.SetId(i, i) ug = vtkUnstructuredGrid(points=quad.points) ug.InsertNextCell(quad.cell_type, quad.point_ids) @@ -498,14 +506,20 @@ def make_quad(): def make_tetra(): - # Make a tetrahedron. number_of_vertices = 4 + # Make a tetrahedron. points = vtkPoints() - points.InsertNextPoint(0, 0, 0) - points.InsertNextPoint(1, 0, 0) - points.InsertNextPoint(1, 1, 0) - points.InsertNextPoint(0, 1, 1) + # points.InsertNextPoint(0, 0, 0) + # points.InsertNextPoint(1, 0, 0) + # points.InsertNextPoint(1, 1, 0) + # points.InsertNextPoint(0, 1, 1) + + # Rotate the above points -90° about the X-axis. + points.InsertNextPoint((0.0, 0.0, 0.0)) + points.InsertNextPoint((1.0, 0.0, 0.0)) + points.InsertNextPoint((1.0, 0.0, -1.0)) + points.InsertNextPoint((0.0, 1.0, -1.0)) tetra = vtkTetra() for i in range(0, number_of_vertices): @@ -517,6 +531,16 @@ def make_tetra(): ug = vtkUnstructuredGrid(points=points) ug.SetCells(VTK_TETRA, cell_array) + # pd = vtkPolyData(points=points) + # t = vtkTransform() + # t.RotateX(-90) + # t.Translate(0, 0, 0) + # tf = vtkTransformFilter(transform=t) + # (pd >> tf).update() + # pts = tf.output.GetPoints() + # for i in range(0, pts.number_of_points): + # print(f'points.InsertNextPoint({pts.GetPoint(i)})') + return ug @@ -545,16 +569,19 @@ def make_voxel(): def make_hexahedron(): - # A regular hexagon (cube) with all faces square and three squares around - # each vertex is created below. + """ + A regular hexagon (cube) with all faces square and three squares + around each vertex is created below. + + Set up the coordinates of eight points, (the two faces must be + in counter-clockwise order as viewed from the outside). - # Set up the coordinates of eight points - # (the two faces must be in counter-clockwise - # order as viewed from the outside). + :return: + """ number_of_vertices = 8 - # Create the points + # Create the points. points = vtkPoints() points.InsertNextPoint(0, 0, 0) points.InsertNextPoint(1, 0, 0) @@ -565,7 +592,7 @@ def make_hexahedron(): points.InsertNextPoint(1, 1, 1) points.InsertNextPoint(0, 1, 1) - # Create a hexahedron from the points + # Create a hexahedron from the points. hexhedr = vtkHexahedron() for i in range(0, number_of_vertices): hexhedr.point_ids.SetId(i, i) @@ -578,27 +605,27 @@ def make_hexahedron(): def make_wedge(): - # A wedge consists of two triangular ends and three rectangular faces. - number_of_vertices = 6 + # A wedge consists of two triangular ends and three rectangular faces. points = vtkPoints() # Original Points. - points.InsertNextPoint(0, 1, 0) - points.InsertNextPoint(0, 0, 0) - points.InsertNextPoint(0, 0.5, 0.5) - points.InsertNextPoint(1, 1, 0) - points.InsertNextPoint(1, 0.0, 0.0) - points.InsertNextPoint(1, 0.5, 0.5) - - # RotateX(-90), Translate(0,-1,0). - # points.InsertNextPoint(0.0, 0.0, 0.0) - # points.InsertNextPoint(0.0,0 , 1.0) - # points.InsertNextPoint(0.0, 0.5, 0.5) - # points.InsertNextPoint(1.0, 0.0, 0.0) - # points.InsertNextPoint(1.0, 0, 1.0) - # points.InsertNextPoint(1.0, 0.5, 0.5) + # points.InsertNextPoint(0, 1, 0) + # points.InsertNextPoint(0, 0, 0) + # points.InsertNextPoint(0, 0.5, 0.5) + # points.InsertNextPoint(1, 1, 0) + # points.InsertNextPoint(1, 0.0, 0.0) + # points.InsertNextPoint(1, 0.5, 0.5) + + # Rotate the above points -90° about the X-axis + # and translate -1 along the Y-axis. + points.InsertNextPoint(0.0, 0.0, 0.0) + points.InsertNextPoint(0.0, 0, 1.0) + points.InsertNextPoint(0.0, 0.5, 0.5) + points.InsertNextPoint(1.0, 0.0, 0.0) + points.InsertNextPoint(1.0, 0, 1.0) + points.InsertNextPoint(1.0, 0.5, 0.5) wedge = vtkWedge() for i in range(0, number_of_vertices): @@ -609,7 +636,6 @@ def make_wedge(): # pd = vtkPolyData(points=points) # t = vtkTransform() - # # t.Translate(1,1,1) # t.RotateX(-90) # t.Translate(0,-1,0) # tf = vtkTransformFilter(transform=t) @@ -628,18 +654,18 @@ def make_pyramid(): points = vtkPoints() # Original points. - p0 = [1.0, 1.0, 0.0] - p1 = [-1.0, 1.0, 0.0] - p2 = [-1.0, -1.0, 0.0] - p3 = [1.0, -1.0, 0.0] - p4 = [0.0, 0.0, 1.0] - - # # RotateX(-90) - # p0 = (1.0, 0, -1.0) - # p1 = (-1.0, 0, -1.0) - # p2 = (-1.0, 0, 1.0) - # p3 = (1.0, 0, 1.0) - # p4 = (0.0, 2.0, 0) + # p0 = [1.0, 1.0, 0.0] + # p1 = [-1.0, 1.0, 0.0] + # p2 = [-1.0, -1.0, 0.0] + # p3 = [1.0, -1.0, 0.0] + # p4 = [0.0, 0.0, 1.0] + + # Rotate the above points -90° about the X-axis. + p0 = (1.0, 0, -1.0) + p1 = (-1.0, 0, -1.0) + p2 = (-1.0, 0, 1.0) + p3 = (1.0, 0, 1.0) + p4 = (0.0, 2.0, 0) points.InsertNextPoint(p0) points.InsertNextPoint(p1) @@ -668,18 +694,9 @@ def make_pyramid(): def make_pentagonal_prism(): - pentagonal_prism = vtkPentagonalPrism() + number_of_vertices = 10 - pentagonal_prism.point_ids.SetId(0, 0) - pentagonal_prism.point_ids.SetId(1, 1) - pentagonal_prism.point_ids.SetId(2, 2) - pentagonal_prism.point_ids.SetId(3, 3) - pentagonal_prism.point_ids.SetId(4, 4) - pentagonal_prism.point_ids.SetId(5, 5) - pentagonal_prism.point_ids.SetId(6, 6) - pentagonal_prism.point_ids.SetId(7, 7) - pentagonal_prism.point_ids.SetId(8, 8) - pentagonal_prism.point_ids.SetId(9, 9) + pentagonal_prism = vtkPentagonalPrism() scale = 2.0 pentagonal_prism.points.SetPoint(0, 11 / scale, 10 / scale, 10 / scale) @@ -693,6 +710,9 @@ def make_pentagonal_prism(): pentagonal_prism.points.SetPoint(8, 12 / scale, 14 / scale, 14 / scale) pentagonal_prism.points.SetPoint(9, 10 / scale, 12 / scale, 14 / scale) + for i in range(0, number_of_vertices): + pentagonal_prism.point_ids.SetId(i, i) + ug = vtkUnstructuredGrid(points=pentagonal_prism.points) ug.InsertNextCell(pentagonal_prism.cell_type, pentagonal_prism.point_ids) @@ -700,19 +720,9 @@ def make_pentagonal_prism(): def make_hexagonal_prism(): + number_of_vertices = 12 + hexagonal_prism = vtkHexagonalPrism() - hexagonal_prism.point_ids.SetId(0, 0) - hexagonal_prism.point_ids.SetId(1, 1) - hexagonal_prism.point_ids.SetId(2, 2) - hexagonal_prism.point_ids.SetId(3, 3) - hexagonal_prism.point_ids.SetId(4, 4) - hexagonal_prism.point_ids.SetId(5, 5) - hexagonal_prism.point_ids.SetId(6, 6) - hexagonal_prism.point_ids.SetId(7, 7) - hexagonal_prism.point_ids.SetId(8, 8) - hexagonal_prism.point_ids.SetId(9, 9) - hexagonal_prism.point_ids.SetId(10, 10) - hexagonal_prism.point_ids.SetId(11, 11) scale = 2.0 hexagonal_prism.points.SetPoint(0, 11 / scale, 10 / scale, 10 / scale) @@ -728,6 +738,9 @@ def make_hexagonal_prism(): hexagonal_prism.points.SetPoint(10, 11 / scale, 14 / scale, 14 / scale) hexagonal_prism.points.SetPoint(11, 10 / scale, 12 / scale, 14 / scale) + for i in range(0, number_of_vertices): + hexagonal_prism.point_ids.SetId(i, i) + ug = vtkUnstructuredGrid(points=hexagonal_prism.points) ug.InsertNextCell(hexagonal_prism.cell_type, hexagonal_prism.point_ids) diff --git a/src/Testing/Baseline/Cxx/GeometricObjects/TestLinearCellDemo.png b/src/Testing/Baseline/Cxx/GeometricObjects/TestLinearCellDemo.png index a65770014d8c5662e45a2519a61283383fc88b7d..e2e41cfbae1e74ffcbb7c635eb21feb39404c0ba 100644 --- a/src/Testing/Baseline/Cxx/GeometricObjects/TestLinearCellDemo.png +++ b/src/Testing/Baseline/Cxx/GeometricObjects/TestLinearCellDemo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:81f9fb07ef33340fa2eebe4a8b10bb58221c32d97b86b21bce9b53c694ed2043 -size 155322 +oid sha256:cb95d176629dfaed4bc3de03f740ff0654e9edc5860cd3da8736b8726075ba0e +size 146252 diff --git a/src/Testing/Baseline/Python/GeometricObjects/TestLinearCellDemo.png b/src/Testing/Baseline/Python/GeometricObjects/TestLinearCellDemo.png index a65770014d8c5662e45a2519a61283383fc88b7d..e2e41cfbae1e74ffcbb7c635eb21feb39404c0ba 100644 --- a/src/Testing/Baseline/Python/GeometricObjects/TestLinearCellDemo.png +++ b/src/Testing/Baseline/Python/GeometricObjects/TestLinearCellDemo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:81f9fb07ef33340fa2eebe4a8b10bb58221c32d97b86b21bce9b53c694ed2043 -size 155322 +oid sha256:cb95d176629dfaed4bc3de03f740ff0654e9edc5860cd3da8736b8726075ba0e +size 146252 diff --git a/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestLinearCellDemo.png b/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestLinearCellDemo.png index 368c3936d6c8cec479f8464ece0a2ae9a667e6b5..8bead6417cf0c67df3e41513f082d29ba7d2f6de 100644 --- a/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestLinearCellDemo.png +++ b/src/Testing/Baseline/PythonicAPI/GeometricObjects/TestLinearCellDemo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f902b343e3bd091ce62226f4fa7241e20407c8ab8c304981b6ef58df0c13f526 -size 149987 +oid sha256:680f677f35ca43528e5acb7b4bfd5881fe5e8a1b875c2999d523cef2e6da8637 +size 149320