QuadraticTetra
Repository source: QuadraticTetra
Description¶
The quadratic tetrahedron is a primary three-dimensional cell. It is defined by ten points. The first four points are located at the vertices of the tetrahedron; the next six are located in the middle of each of the six edges.
Other languages
See (Python)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
QuadraticTetra.cxx
#include <vtkActor.h>
#include <vtkDataSetMapper.h>
#include <vtkGlyph3D.h>
#include <vtkMinimalStandardRandomSequence.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkQuadraticTetra.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkTessellatorFilter.h>
#include <vtkUnstructuredGrid.h>
namespace {
vtkSmartPointer<vtkUnstructuredGrid> MakeQuadraticTetra();
}
int main(int, char*[])
{
vtkNew<vtkNamedColors> namedColors;
auto uGrid = MakeQuadraticTetra();
vtkNew<vtkTessellatorFilter> tessellate;
tessellate->SetInputData(uGrid);
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputConnection(tessellate->GetOutputPort());
mapper->ScalarVisibilityOff();
// Create an actor for the grid
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetDiffuseColor(
namedColors->GetColor3d("Tomato").GetData());
actor->GetProperty()->SetEdgeColor(
namedColors->GetColor3d("IvoryBlack").GetData());
actor->GetProperty()->EdgeVisibilityOn();
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetRadius(0.02);
vtkNew<vtkGlyph3D> glyph3D;
glyph3D->SetInputData(uGrid);
glyph3D->SetSourceConnection(sphereSource->GetOutputPort());
glyph3D->ScalingOff();
glyph3D->Update();
vtkNew<vtkDataSetMapper> glyph3DMapper;
glyph3DMapper->SetInputConnection(glyph3D->GetOutputPort());
glyph3DMapper->ScalarVisibilityOff();
vtkNew<vtkActor> glyph3DActor;
glyph3DActor->SetMapper(glyph3DMapper);
glyph3DActor->GetProperty()->SetColor(
namedColors->GetColor3d("Banana").GetData());
// Visualize
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetWindowName("QuadraticTetra");
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->AddActor(glyph3DActor);
renderer->SetBackground(namedColors->GetColor3d("SlateGray").GetData());
renderWindow->Render();
interactor->Start();
return EXIT_SUCCESS;
}
namespace {
vtkSmartPointer<vtkUnstructuredGrid> MakeQuadraticTetra()
{
vtkNew<vtkQuadraticTetra> aTetra;
vtkNew<vtkPoints> points;
double* pcoords = aTetra->GetParametricCoords();
vtkNew<vtkMinimalStandardRandomSequence> rng;
points->SetNumberOfPoints(aTetra->GetNumberOfPoints());
rng->SetSeed(5070); // for testing
for (auto i = 0; i < aTetra->GetNumberOfPoints(); ++i)
{
double perturbation[3];
for (auto j = 0; j < 3; ++j)
{
rng->Next();
perturbation[j] = rng->GetRangeValue(-0.1, 0.1);
}
aTetra->GetPointIds()->SetId(i, i);
points->SetPoint(i, *(pcoords + 3 * i) + perturbation[0],
*(pcoords + 3 * i + 1) + perturbation[1],
*(pcoords + 3 * i + 2) + perturbation[2]);
}
// Add the points and tetra to an unstructured grid
vtkSmartPointer<vtkUnstructuredGrid> uGrid =
vtkSmartPointer<vtkUnstructuredGrid>::New();
uGrid->SetPoints(points);
uGrid->InsertNextCell(aTetra->GetCellType(), aTetra->GetPointIds());
return uGrid;
}
} // namespace
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(QuadraticTetra)
find_package(VTK COMPONENTS
CommonColor
CommonCore
CommonDataModel
FiltersCore
FiltersGeneral
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "QuadraticTetra: Unable to find the VTK build folder.")
endif()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(QuadraticTetra MACOSX_BUNDLE QuadraticTetra.cxx )
target_link_libraries(QuadraticTetra PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS QuadraticTetra
MODULES ${VTK_LIBRARIES}
)
Download and Build QuadraticTetra¶
Click here to download QuadraticTetra and its CMakeLists.txt file. Once the tarball QuadraticTetra.tar has been downloaded and extracted,
cd QuadraticTetra/build
If VTK is installed:
cmake ..
If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..
Build the project:
make
and run it:
./QuadraticTetra
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.