Skip to content

djeada/Vtk-Examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎨 VTK Examples - Master 3D Visualization with Python

A comprehensive collection of VTK (Visualization Toolkit) examples showcasing 3D graphics, scientific visualization, and computational fluid dynamics

License: MIT Python 3.8+ VTK 9.4 Contributions Welcome

πŸ“– Documentation β€’ πŸš€ Quick Start β€’ πŸ’‘ Examples β€’ 🀝 Contributing


VTK Visualization Demo

🎬 See VTK in Action

Experience the power of VTK through these interactive demonstrations. Click on any thumbnail to watch the video on YouTube:

Visualization Demo Animation Showcase
Watch Demo 1 Watch Demo 2
3D Rendering & Interaction Dynamic Visualization

πŸ“‹ Table of Contents


✨ Why This Repository?

πŸŽ“ 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.

🎯 What You'll Learn

  • 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

πŸ” What is VTK?

The Visualization Toolkit (VTK) is the gold standard for 3D computer graphics, image processing, and scientific visualization.

πŸ† Features

  • Extensive Algorithm Library β€” Hundreds of visualization algorithms for any use case
  • Cross-Platform β€” Windows, Linux, macOS support
  • Multi-Language β€” C++, Python, Java, Tcl bindings
  • Open Source β€” BSD license, free for commercial use
  • Active Community β€” 30+ years of development by Kitware

πŸ”§ Core Capabilities

  • 3D surface and volume rendering
  • Scalar, vector, and tensor visualization
  • Image processing and analysis
  • Mesh generation and manipulation
  • Scientific data formats I/O
  • Interactive 3D widgets

πŸ“Š VTK Pipeline Architecture

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    β”‚          β”‚
β”‚                                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Get up and running in minutes with these simple steps:

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

# 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

Run Your First Example

# 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.

πŸ’» IDE Setup (Optional)

For an enhanced development experience with VS Code or PyCharm:

  1. Open the project folder in your IDE
  2. Configure the Python interpreter to use your virtual environment
  3. Run any script using the built-in run button or debugger
  4. Debug with breakpoints for step-through analysis

πŸ“ Project Structure

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

πŸ’‘ Examples Gallery

πŸ”· Basic Shapes

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

πŸ”Ά Advanced Shapes

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

πŸ“Š Structures and Datasets

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

πŸ“₯ Input and Output

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

πŸ”„ Data Conversion

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

🎯 Visualization Pipeline

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

πŸŽ›οΈ Interactive Widgets

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

πŸ”— Integrations with External Tools

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

🌊 Computational Fluid Dynamics (CFD)

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

🌐 VTK.js Web Examples

Take your visualizations to the web with VTK.jsβ€”a JavaScript implementation of VTK for browser-based 3D rendering.

Quick Start with VTK.js

# 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 start

Then open your browser to http://localhost:8080 to see VTK running in the web!

πŸ“‚ Location: vtk_js/basic/


πŸ“– Documentation

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

🀝 How to Contribute

We welcome contributions from the community! Whether you're fixing a bug, adding new examples, or improving documentation, your help is appreciated.

Ways to Contribute

  • πŸ› 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

Contribution Workflow

# 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

Code Guidelines

  • Follow existing code style and patterns
  • Add clear comments and docstrings
  • Include example usage in new scripts
  • Test your code before submitting

πŸ“š References

Expand your VTK knowledge with these excellent resources:

Official Resources

Community Resources


πŸ“„ License

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.

⭐ Star History

If you find this repository helpful, please consider giving it a star! Your support helps others discover these resources.

Star History Chart


Made with ❀️ by Adam Djellouli and contributors

⬆ Back to Top

About

Explore the world of 3D graphics and visualization with VTK examples in Python.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages