IronIsoSurface
vtk-examples/Cxx/VisualizationAlgorithms/IronIsoSurface
Description¶
This example generates an isosurface of electron potential of an iron protein molecule.
Info
See Figure 6-11d in Chapter 6 the VTK Textbook.
Other languages
See (Python)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
IronIsoSurface.cxx
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkContourFilter.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOutlineFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkStructuredPointsReader.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " ironProt.vtk" << std::endl;
return EXIT_SUCCESS;
}
vtkNew<vtkNamedColors> colors;
// Create the RenderWindow, Renderer and both Actors
//
vtkNew<vtkRenderer> ren1;
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(ren1);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
// create pipeline
//
vtkNew<vtkStructuredPointsReader> reader;
reader->SetFileName(argv[1]);
vtkNew<vtkContourFilter> iso;
iso->SetInputConnection(reader->GetOutputPort());
iso->SetValue(0, 128);
vtkNew<vtkPolyDataMapper> isoMapper;
isoMapper->SetInputConnection(iso->GetOutputPort());
isoMapper->ScalarVisibilityOff();
vtkNew<vtkActor> isoActor;
isoActor->SetMapper(isoMapper);
isoActor->GetProperty()->SetColor(colors->GetColor3d("Banana").GetData());
vtkNew<vtkOutlineFilter> outline;
outline->SetInputConnection(reader->GetOutputPort());
vtkNew<vtkPolyDataMapper> outlineMapper;
outlineMapper->SetInputConnection(outline->GetOutputPort());
vtkNew<vtkActor> outlineActor;
outlineActor->SetMapper(outlineMapper);
// Add the actors to the renderer, set the background and size
//
ren1->AddActor(outlineActor);
ren1->AddActor(isoActor);
ren1->SetBackground(colors->GetColor3d("SlateGray").GetData());
renWin->SetSize(640, 640);
renWin->SetWindowName("IronIsoSurface");
// render the image
//
ren1->ResetCamera();
ren1->GetActiveCamera()->Azimuth(30);
ren1->GetActiveCamera()->Elevation(30);
renWin->Render();
iren->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(IronIsoSurface)
find_package(VTK COMPONENTS
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "IronIsoSurface: 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(IronIsoSurface MACOSX_BUNDLE IronIsoSurface.cxx )
target_link_libraries(IronIsoSurface PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS IronIsoSurface
MODULES ${VTK_LIBRARIES}
)
Download and Build IronIsoSurface¶
Click here to download IronIsoSurface and its CMakeLists.txt file. Once the tarball IronIsoSurface.tar has been downloaded and extracted,
cd IronIsoSurface/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:
./IronIsoSurface
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.