A comprehensive collection of VTK (Visualization Toolkit) examples showcasing 3D graphics, scientific visualization, and computational fluid dynamics
π Documentation β’ π Quick Start β’ π‘ Examples β’ π€ Contributing
Experience the power of VTK through these interactive demonstrations. Click on any thumbnail to watch the video on YouTube:
- β¨ Why This Repository?
- π What is VTK?
- π Quick Start
- π Project Structure
- π‘ Examples Gallery
- π VTK.js Web Examples
- π Documentation
- π€ How to Contribute
- π References
- π License
| π Learn by Example | π οΈ Production Ready | π Comprehensive Coverage |
|---|---|---|
| 50+ working examples with clear explanations | Well-structured, reusable code patterns | From basics to advanced CFD simulations |
| π¬ Scientific Focus | π Web & Desktop | π Rich Documentation |
|---|---|---|
| Perfect for research and engineering | Python + VTK.js examples | In-depth notes and tutorials |
Whether you're a student learning visualization concepts, a researcher analyzing scientific data, or an engineer building professional applications, this repository provides the building blocks you need.
- Create stunning 3D visualizations from simple shapes to complex scientific data
- Master the VTK pipeline architecture for efficient rendering
- Handle various file formats (STL, OBJ, VTK, VTU, VTM, and more)
- Build interactive applications with widgets and UI integration
- Implement CFD simulations for heat transfer and fluid flow
- Deploy web visualizations using VTK.js
The Visualization Toolkit (VTK) is the gold standard for 3D computer graphics, image processing, and scientific visualization.
|
|
Understanding VTK's pipeline is essential for effective visualization:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VTK VISUALIZATION PIPELINE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β SOURCE βββββΆβ FILTER βββββΆβ MAPPER βββββΆβ ACTOR β β
β β β β β β β β β β
β β Generate β β Process β β Convert β β Render β β
β β Data β β Data β β to Geo β β Object β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββ¬ββββββ β
β β β
β βΌ β
β ββββββββββββββββ β
β β RENDERER β β
β β β β
β β Display β β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Get up and running in minutes with these simple steps:
- Python 3.8 or higher
- pip package manager
# 1. Clone the repository
git clone https://github.com/djeada/VTK-Examples.git
cd VTK-Examples
# 2. Create a virtual environment (recommended)
python -m venv venv
# 3. Activate the virtual environment
# On Linux/macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# 4. Install dependencies
pip install -r requirements.txt# Navigate to the examples directory and run a script
cd src/01_basic_shapes
python circle.pyπ Congratulations! You should see a window displaying circles rendered with VTK.
For an enhanced development experience with VS Code or PyCharm:
- Open the project folder in your IDE
- Configure the Python interpreter to use your virtual environment
- Run any script using the built-in run button or debugger
- Debug with breakpoints for step-through analysis
VTK-Examples/
βββ π src/ # Source code examples
β βββ π 01_basic_shapes/ # Fundamental geometric primitives
β βββ π 02_advanced_shapes/ # Complex geometries & techniques
β βββ π 03_structures_and_datasets/ # VTK data structures
β βββ π 04_input_output/ # File format handling
β βββ π 05_data_conversion/ # Format conversion utilities
β βββ π 06_visualization_pipeline/ # Rendering pipeline examples
β βββ π 07_interactive_widgets/ # UI widgets & interaction
β βββ π 08_integration_with_ui/ # Qt, Matplotlib integration
β βββ π 09_cfd/ # Computational Fluid Dynamics
β βββ π common/ # Shared utilities & helpers
β
βββ π notes/ # In-depth documentation & tutorials
βββ π vtk_js/ # VTK.js web visualization examples
βββ π data/ # Sample data files
β βββ π stls/ # STL mesh files
β βββ π objs/ # OBJ model files
β βββ π vtks/ # VTK data files
β βββ π ... # Other format samples
β
βββ π requirements.txt # Python dependencies
βββ π LICENSE # MIT License
βββ π README.md # This file
Start your VTK journey with fundamental geometric primitives. These examples demonstrate the core concepts of creating and rendering 3D objects.
| # | Example | Description | Link |
|---|---|---|---|
| 1 | Circle | Create perfectly round 2D circles with customizable radius and resolution | π Code |
| 2 | Cone | Generate 3D cones with adjustable height, radius, and resolution | π Code |
| 3 | Cube | Build solid cubes and boxes in 3D space | π Code |
| 4 | Cylinder | Create cylindrical shapes with height and radius parameters | π Code |
| 5 | Glyph | Introduction to glyph-based visualization for representing data points | π Code |
| 6 | Square | Render 2D squares and rectangles | π Code |
| 7 | Triangle | Create triangular primitives, the building blocks of 3D meshes | π Code |
Take your visualization skills to the next level with complex geometries, volume rendering, and multi-object scenes.
| # | Example | Description | Link |
|---|---|---|---|
| 1 | Enclosing Box | Create bounding boxes that enclose other objectsβuseful for spatial analysis | π Code |
| 2 | Isosurface | Extract surfaces of constant value from volumetric data | π Code |
| 3 | Multiple Dependent Objects | Build scenes with hierarchically linked objects | π Code |
| 4 | Multiple Independent Objects | Create complex scenes with multiple standalone objects | π Code |
| 5 | Streamlines | Visualize flow fields and vector data with streamline rendering | π Code |
| 6 | Triangulation | Apply triangulation techniques for mesh generation | π Code |
| 7 | Volume Rendering | Render volumetric data with customizable transfer functions | π Code |
| 8 | Visualization Comparison | Compare different visualization techniques side-by-side | π Code |
| 9 | Flow Simulation | Visualize computational fluid dynamics data | π Code |
Master VTK's data structuresβthe foundation of all visualization operations.
| # | Example | Description | Link |
|---|---|---|---|
| 1 | Points | Work with vtkPointsβthe fundamental spatial data structure | π Code |
| 2 | Cells | Understand cells and their role in defining mesh topology | π Code |
| 3 | Fields | Handle scalar, vector, and tensor field data | π Code |
| 4 | Multiblock Dataset | Organize complex data with hierarchical multiblock structures | π Code |
| 5 | PolyData | Work with polygonal surfacesβthe most common VTK data type | π Code |
| 6 | Structured Grid | Handle regularly spaced 3D grid data | π Code |
| 7 | Unstructured Grid | Work with arbitrary cell types and connectivity | π Code |
| 8 | Structured Mesh | Create and manipulate structured mesh geometries | π Code |
| 9 | Unstructured Mesh | Build and process unstructured mesh geometries | π Code |
Learn to read and write various 3D file formats commonly used in engineering and scientific applications.
| # | Format | Description | Link |
|---|---|---|---|
| 1 | OBJ | Wavefront OBJβwidely used 3D model format | π Code |
| 2 | STL | Stereolithography formatβstandard for 3D printing | π Code |
| 3 | VTK | Native VTK format for polygonal data | π Code |
| 4 | VTM | VTK multiblock format for composite datasets | π Code |
| 5 | VTU | VTK unstructured grid format | π Code |
| 6 | Exodus II | SANDIA National Labs format for FEM/CFD results | π Code |
| 7 | OpenFOAM | Read OpenFOAM CFD simulation results | π Code |
Convert between popular 3D file formats with ease.
| # | Conversion | Description | Link |
|---|---|---|---|
| 1 | Converter Interface | Base interface for building custom converters | π Code |
| 2 | STL β VTK | Convert between STL and VTK formats | π Code |
| 3 | VTK β OBJ | Convert between VTK and OBJ formats | π Code |
| 4 | STL β OBJ | Convert between STL and OBJ formats | π Code |
| 5 | VTK β VTM | Convert between VTK and VTM formats | π Code |
| 6 | VTK β VTU | Convert between VTK and VTU formats | π Code |
Understand and master the VTK rendering pipeline for professional-quality visualizations.
| # | Example | Description | Link |
|---|---|---|---|
| 1 | Actor-Mapper Setup | Handle multiple objects with proper actor-mapper relationships | π Code |
| 2 | Text Labels | Add informative text annotations to your visualizations | π Code |
| 3 | Scalar Color Mapping | Map data values to colors using customizable color maps | π Code |
| 4 | Camera Movement | Control camera position, orientation, and movement paths | π Code |
| 5 | Filters in Action | Apply VTK filters for data processing and transformation | π Code |
| 6 | Lighting & Shadows | Create realistic lighting effects and shadow rendering | π Code |
| 7 | Pipeline Animation | Animate your visualization pipeline over time | π Code |
Build interactive applications with VTK's powerful widget system.
| # | Widget | Description | Link |
|---|---|---|---|
| 1 | Orientation Marker | Add 3D axes indicator for spatial orientation | π Code |
| 2 | Slider | Create interactive sliders for parameter control | π Code |
| 3 | Button | Implement clickable buttons for user interaction | π Code |
| 4 | Planes Intersection | Interactively slice volumes with intersecting planes | π Code |
Combine VTK with popular frameworks for enhanced visualization capabilities.
| # | Integration | Description | Link |
|---|---|---|---|
| 1 | Qt Integration | Embed VTK visualizations in Qt desktop applications | π Code |
| 2 | Matplotlib Sphere | Combine VTK 3D rendering with Matplotlib | π Code |
| 3 | Matplotlib Surface | Create surface plots using VTK and Matplotlib together | π Code |
Simulate and visualize heat transfer and fluid flow phenomena with these physics-based examples.
| # | Simulation | Description | Link |
|---|---|---|---|
| 1 | 1D Heat Convection | Solve 1D heat convection problems with finite differences | π Code |
| 2 | 1D Fixed-End Heat Transfer | Heat transfer with fixed temperature boundary conditions | π Code |
| 3 | 1D Convective-End Heat Transfer | Heat transfer with convective boundary conditions | π Code |
| 4 | 1D Enhanced Heat Transfer | Advanced 1D heat transfer with enhanced accuracy | π Code |
| 5 | 2D Heat Conduction | Solve 2D steady-state heat conduction problems | π Code |
| 6 | 2D Enhanced Heat Transfer | Advanced 2D heat transfer solver | π Code |
| 7 | Fluid Flow Simulation | Simulate basic fluid flow patterns | π Code |
| 8 | Obstacle Flow | Simulate fluid flow around obstacles | π Code |
Take your visualizations to the web with VTK.jsβa JavaScript implementation of VTK for browser-based 3D rendering.
# Navigate to the VTK.js examples
cd vtk_js/basic
# Install dependencies
npm install
# Build the project
npm run build
# Start the development server
npm startThen open your browser to http://localhost:8080 to see VTK running in the web!
π Location: vtk_js/basic/
Deepen your understanding with our comprehensive documentation covering VTK concepts, techniques, and best practices.
| Topic | Description | Link |
|---|---|---|
| Data Types & Structures | vtkDataObject, points, cells, grids, and datasets | π Read |
| Filters & Algorithms | Data processing, transformation, and analysis filters | π Read |
| Input & Output | File format handling and data serialization | π Read |
| Visualization Techniques | Volume rendering, scalar mapping, vector visualization | π Read |
| Interactivity | User interaction, picking, and selection | π Read |
| Animations | Creating smooth animations and time-series visualizations | π Read |
| Performance Optimization | Parallelism, LOD, and rendering optimization | π Read |
| Tool Integration | Integrating VTK with Qt, Matplotlib, and other tools | π Read |
| Custom Filters | Building custom filters and algorithms | π Read |
We welcome contributions from the community! Whether you're fixing a bug, adding new examples, or improving documentation, your help is appreciated.
- π Report bugs β Found an issue? Open a bug report
- π‘ Suggest features β Have an idea? Share it with us
- π Improve documentation β Help make the docs even better
- π§ Submit code β Add new examples or enhance existing ones
# 1. Fork the repository on GitHub
# 2. Clone your fork
git clone https://github.com/YOUR_USERNAME/VTK-Examples.git
cd VTK-Examples
# 3. Create a feature branch
git checkout -b feature/AmazingFeature
# 4. Make your changes and commit
git add .
git commit -m "Add AmazingFeature: brief description"
# 5. Push to your fork
git push origin feature/AmazingFeature
# 6. Open a Pull Request on GitHub- Follow existing code style and patterns
- Add clear comments and docstrings
- Include example usage in new scripts
- Test your code before submitting
Expand your VTK knowledge with these excellent resources:
- π VTK Official Website β Documentation, downloads, and news
- π VTK User's Guide β Comprehensive official guide
- π VTK Examples β Official VTK examples collection
- π PyScience VTK Tutorials β Python-focused VTK tutorials
- π» Program Creek VTK Examples β Code snippets and examples
- π Visualization Course 2014 (Uppsala) β Academic visualization course
- π Data Visualization Course (SJTU) β University course materials
This project is licensed under the MIT License β see the LICENSE file for details.
MIT License - Copyright (c) 2021 Adam Djellouli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
If you find this repository helpful, please consider giving it a star! Your support helps others discover these resources.
Made with β€οΈ by Adam Djellouli and contributors

