ShotNoise
VTKExamples/Cxx/ImageProcessing/ShotNoise
Other Languages
See (Java)
Code¶
ShotNoise.cxx
#include <vtkSmartPointer.h> #include <vtkImageCanvasSource2D.h> #include <vtkPNGWriter.h> int main (int argc, char *argv[]) { vtkSmartPointer<vtkImageCanvasSource2D> imageCanvas = vtkSmartPointer<vtkImageCanvasSource2D>::New(); imageCanvas->SetScalarTypeToUnsignedChar(); imageCanvas->SetExtent(1, 256, 1, 256, 0, 0); imageCanvas->SetDrawColor(0.0); imageCanvas->FillBox(1, 256, 1, 256); imageCanvas->SetDrawColor(255.0); imageCanvas->FillBox(30, 225, 30, 225); imageCanvas->SetDrawColor(0.0); imageCanvas->FillBox(60, 195, 60, 195); imageCanvas->SetDrawColor(255.0); imageCanvas->FillTube(100, 100, 154, 154, 40.0); imageCanvas->SetDrawColor(0.0); imageCanvas->DrawSegment(45, 45, 45, 210); imageCanvas->DrawSegment(45, 210, 210, 210); imageCanvas->DrawSegment(210, 210, 210, 45); imageCanvas->DrawSegment(210, 45, 45, 45); imageCanvas->DrawSegment(100, 150, 150, 100); imageCanvas->DrawSegment(110, 160, 160, 110); imageCanvas->DrawSegment(90, 140, 140, 90); imageCanvas->DrawSegment(120, 170, 170, 120); imageCanvas->DrawSegment(80, 130, 130, 80); imageCanvas->Update(); vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New(); writer->SetInputConnection(imageCanvas->GetOutputPort()); writer->SetFileName(argv[1]); writer->Write(); return EXIT_SUCCESS; }
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(ShotNoise) find_package(VTK COMPONENTS vtkCommonCore vtkIOImage vtkImagingSources QUIET) if (NOT VTK_FOUND) message("Skipping ShotNoise: ${VTK_NOT_FOUND_MESSAGE}") return () endif() message (STATUS "VTK_VERSION: ${VTK_VERSION}") if (VTK_VERSION VERSION_LESS "8.90.0") # old system include(${VTK_USE_FILE}) add_executable(ShotNoise MACOSX_BUNDLE ShotNoise.cxx ) target_link_libraries(ShotNoise PRIVATE ${VTK_LIBRARIES}) else () # include all components add_executable(ShotNoise MACOSX_BUNDLE ShotNoise.cxx ) target_link_libraries(ShotNoise PRIVATE ${VTK_LIBRARIES}) # vtk_module_autoinit is needed vtk_module_autoinit( TARGETS ShotNoise MODULES ${VTK_LIBRARIES} ) endif ()
Download and Build ShotNoise¶
Click here to download ShotNoise and its CMakeLists.txt file. Once the tarball ShotNoise.tar has been downloaded and extracted,
cd ShotNoise/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:
./ShotNoise
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.