Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
# SketchGetDP
Translates photographed hand-drawn shapes and/or SVG files to Gmsh geometries, ready to be used within a GetDP simulation.
**From Hand-Drawn Sketches to Electromagnetic Simulations**

SketchGetDP translates photographed hand-drawn shapes and SVG files into Gmsh geometries ready for GetDP simulation. It's designed for engineers, researchers, and students working with accelerator magnet cross-sections.

## 🎯 Overview

SketchGetDP provides two complementary tools that turn your drawings into simulation results:

- **Bitmap Tracer** – Converts photos of hand-drawn sketches (JPEG, PNG) into SVG vector graphics
- **SVG to GetDP** – Analyzes SVG sketches to create meshes and run electromagnetic simulations

> ⚠️ **Note**: The Bitmap Tracer and SVG to GetDP components are still being integrated. Currently, corner detection for freehand lines and color mapping between the two tools require further development.


## 📁 Project Structure

```
SketchGetDP/
├── sketchgetdp/ # Core Implementation
│ ├── bitmap_tracer/ # Converts Images to SVG
│ ├── svg_to_getdp/ # Converts SVG to simulations
│ └── rmvp_formulation.pro # GetDP configuration template
├── tests/ # Example inputs for testing
├── README.md # This documentation
├── getdp_path.txt # Path to your GetDP installation
└── requirements.txt # Python package dependencies
```

For detailed information, check the README files in each subdirectory.

## Getting started
Install the SketchGetDP module by running the command

`pip install -e .`
1. **Install the SketchGetDP module**
```bash
pip install -e .
```

2) **Install the SketchGetDP module**
```bash
pip install -r requirements.txt
```

3) **Install GetDP**
- Download GetDP from [getdp.info](https://getdp.info/)
- Add the path to GetDP in `getdp_path.txt`

## 🛠️ Usage

### Bitmap Tracer

Convert a photo of a hand-drawn sketch to SVG by running the following from the sketchgetdp subdirectory:
```bash
python -m bitmap_tracer <path_to_image>
```

### SVG to GetDP

Three ways to use it from the sketchgetdp subdirectory:

in the SketchGetDP root directory. Use the command
```bash
# Mode 1: SVG to mesh only
python -m svg_to_getdp <path_to_svg> --config <path_to_config>

`pip install -r requirements.txt`
# Mode 2: Full pipeline (SVG → mesh → simulation)
python -m svg_to_getdp <path_to_svg> --run-simulation --config <path_to_config>

to install all further required packages to run SketchGetDP.
# Mode 3: Simulation only (existing mesh)
python -m svg_to_getdp --simulation-only <path_to_msh> --config <path_to_config>
```
74 changes: 19 additions & 55 deletions sketchgetdp/bitmap_tracer/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bitmap Tracer

A sophisticated image-to-SVG tracing application that converts bitmap images into clean, scalable vector graphics with intelligent color categorization and structure filtering.
A image-to-SVG tracing application that converts bitmap images into clean, scalable vector graphics with intelligent color categorization and structure filtering.

## 🎯 Overview

Expand All @@ -12,27 +12,6 @@ Bitmap Tracer is a Python-based tool that analyzes bitmap images and converts th
- **Point detection** for small, compact shapes
- **Automatic contour closure** ensuring all paths form complete loops

## 🏗️ Architecture

The project follows Clean Architecture principles with clear separation of concerns:

### Core Layers

- **`core/`** - Enterprise business rules
- `entities/` - Domain models (Point, Contour, Color)
- `use_cases/` - Application logic (Image Tracing, Structure Filtering)

- **`infrastructure/`** - Frameworks & drivers
- `image_processing/` - Contour detection, color analysis, closure services
- `svg_generation/` - SVG creation and shape processing
- `configuration/` - Config loading and management
- `point_detection/` - Point detection and curve fitting

- **`interfaces/`** - Interface adapters
- `controllers/` - Application flow control
- `presenters/` - Output formatting (SVG presentation)
- `gateways/` - External interfaces (image loading, config access)

## 🚀 Key Features

### Color Categorization
Expand All @@ -59,20 +38,23 @@ The project follows Clean Architecture principles with clear separation of conce

```
bitmap_tracer/
├── core/ # Business logic
│ ├── entities/ # Domain models
│ └── use_cases/ # Application services
├── infrastructure/ # External concerns
│ ├── image_processing/ # Computer vision
│ ├── svg_generation/ # Vector output
│ ├── configuration/ # Config management
│ └── point_detection/ # Point analysis
├── interfaces/ # Adapters
│ ├── controllers/ # Flow control
│ ├── presenters/ # Output formatting
│ └── gateways/ # External interfaces
├── __main__.py # Python module entry point
└── config.yaml # Configuration
├── core/ # Core logic
│ ├── entities/ # Point, Contour, Color models
│ └── use_cases/ # Tracing and filtering workflows
├── infrastructure/ # Technical Implementations
│ ├── image_processing/ # OpenCV contour detection
│ ├── svg_generation/ # Creates SVG output
│ ├── configuration/ # Loads config.yaml
│ └── point_detection/ # Identifies small shapes
├── interfaces/ # Connects components
│ ├── controllers/ # Orchestrates the workflow
│ ├── presenters/ # Formats output
│ └── gateways/ # Handles external input
├── tests/ # Pytests
├── __main__.py # Entry point
├── config.yaml # Your settings
├── pytest.ini # Pytest initialization
└── README.md # This documentation
```

## ⚙️ Configuration
Expand Down Expand Up @@ -104,20 +86,11 @@ min_value_black: 50 # Minimum value below which colors are consid

## 🛠️ Usage

The Bitmap Tracer can be run from the command line in two ways:

### From the sketchgetdp directory as a python module:
From the sketchgetdp directory:
```bash
python -m bitmap_tracer <path_to_image>
```

### From the bitmap_tracer directory:
```bash
python main.py <path_to_image>
```

Where `<path_to_image>` is the path to the bitmap image you want to convert to SVG.

The application will automatically:
- Load configuration from `config.yaml`
- Process the input image
Expand All @@ -138,12 +111,3 @@ The tracer generates SVG files with:
- NumPy - Numerical computations
- svgwrite - SVG generation
- PyYAML - Configuration parsing

## 🎨 Use Cases

- Converting hand-drawn sketches to vector graphics
- Processing technical diagrams and schematics
- Creating scalable versions of bitmap artwork
- Extracting structured information from images

The Bitmap Tracer excels at transforming complex bitmap images into clean, manageable vector representations while preserving the essential structure and color information.
126 changes: 63 additions & 63 deletions sketchgetdp/svg_to_getdp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,14 @@ A sophisticated electromagnetic simulation pipeline that converts SVG sketches i

## 🎯 Overview

SVG to GetDP is a Python-based electromagnetic simulation pipeline that processes SVG files containing electromagnetic structures and generates simulation results through a multi-stage workflow. It features:
SVG to GetDP is a Python-based electromagnetic simulation pipeline that processes non-freehand drawn SVG files containing electromagnetic structures and generates simulation results through a multi-stage workflow. It features:

- **Three operation modes**: SVG→Gmsh, SVG→Gmsh→GetDP, or Gmsh→GetDP
- **Configurable physical properties** via YAML configuration
- **Intelligent SVG parsing** with Bézier curve fitting and corner detection
- **Fixed color mapping** for physical group identification
- **Automatic wire grouping** and boundary curve meshing

## 🏗️ Architecture

The project follows Clean Architecture principles with clear separation of concerns:

### Core Layers

- **`core/`** - Enterprise business rules
- `entities/` - Domain models (Point, Color, BezierSegment, BoundaryCurve, PhysicalGroup)
- `use_cases/` - Application logic (SVG-to-Geometry conversion, Geometry-to-Gmsh conversion, GetDP simulation execution)

- **`infrastructure/`** - Frameworks & drivers
- `factories/` - Factory classes for dependency creation
- `svg_processing/` - SVG parsing and path extraction
- `corner_detection/` - Corner detection for curve segmentation
- `bezier_fitting/` - Bézier curve fitting
- `boundary_curve_grouper/` - Wire grouping logic
- `boundary_curve_mesher/` - Boundary curve meshing
- `wire_preprocessor/` - Wire preprocessing for meshing

- **`interfaces/`** - Interface adapters
- `controllers/` - Application flow control
- `arg_parser/` - Command line argument parsing
- `abstractions/` - Interfaces for dependency inversion
- `debug/` - Internal visualization and debug output

## 🚀 Key Features

### Three Operation Modes
Expand All @@ -59,32 +34,40 @@ The project follows Clean Architecture principles with clear separation of conce
- Visualization of internal geometry
- Debug output of intermediate processing steps via .txt files

## How It Works

1. **Parse SVG** – Reads paths and identifies colors (Blue = wires, Green = iron, Red = boundaries)
2. **Detect corners** – Breaks paths at sharp angles for better curve fitting
3. **Fit Bézier curves** – Creates smooth mathematical representations
4. **Preprocess wires and outlines** – Preprocesses wires and outlines for meshing with Gmsh
5. **Generate mesh** – Creates a Gmsh mesh with physical groups
6. **Run simulation** – Executes GetDP to solve the electromagnetic problem

## 📁 Project Structure
```
svg_to_getdp/
├── core/ # Business logic
│ ├── entities/ # Domain models
│ └── use_cases/ # Application services
├── infrastructure/ # External concerns
│ ├── factories/ # Factory pattern implementations
│ ├── svg_processing/ # SVG parsing
│ ├── corner_detection/ # Corner detection
│ ├── bezier_fitting/ # Bézier fitting
│ ├── boundary_curve_grouper.py # Wire grouping
│ ├── boundary_curve_mesher.py # Boundary meshing
│ └── wire_preprocessor # Wire preprocessing
├── interfaces/ # Adapters
│ ├── arg_parser.py # Command line interface
│ ├── abstractions/ # Dependency interfaces
│ ├── debug/ # Debug tools
│ ├── mesher/ # Meshing tools
│ └── solver/ # Solving tools
├── tests/ # pytests
│ ├── core/ # Core layer tests
│ └── infrastructure/ # Infrastructure tests
├── __main__.py # Package entry point
├── config.yaml # Configuration file
└── rmvp_formulation.pro # GetDP configuration file
├── core/ # Core logic
│ ├── entities/ # Point, color, outline, etc.
│ └── use_cases/ # Conversion workflows
├── infrastructure/ # Technical Implementations
│ ├── factories/ # Creates objects
│ ├── svg_processing/ # Parses SVG files
│ ├── corner_detection/ # Finds path corners
│ ├── bezier_fitting/ # Fits curves to paths
│ ├── outline_grouper.py # Groups outlines for preprocessing
│ ├── outline_preprocessor.py # Preprocesses outlines for Gmsh
│ ├── wire_preprocessor.py # Preprocesses wires for Gmsh
├── interfaces/ # Connectors
│ ├── arg_parser.py # Command-line interface
│ ├── abstractions/ # Dependency interfaces
│ ├── debug/ # Debugging tools
│ ├── mesher/ # Gmsh integration
│ └── solver/ # GetDP integration
├── tests/ # pytests
├── __main__.py # Entry point
├── config.yaml # Your settings
├── pytest.ini # Pytest initialization
└── README.md # This documentation
```

## ⚙️ Configuration
Expand Down Expand Up @@ -122,23 +105,23 @@ physical_values:
Convert an SVG file to a Gmsh mesh file:

```bash
python -m svg_to_getdp drawing.svg --config config.yaml
python -m svg_to_getdp <path_to_svg> --config <path_to_config>
```

### Mode 2: Full Pipeline (SVG to Simulation)

Convert SVG file to mesh file and run GetDP simulation:

```bash
python -m svg_to_getdp drawing.svg --run-simulation --config config.yaml
python -m svg_to_getdp <path_to_svg> --run-simulation --config <path_to_config>
```

### Mode 3: Simulation Only (Existing Mesh)

Run GetDP simulation on an existing mesh file:

```bash
python -m svg_to_getdp --simulation-only existing_mesh.msh --config config.yaml
python -m svg_to_getdp --simulation-only <path_to_msh> --config <path_to_config>
```

### Additional Options
Expand All @@ -149,13 +132,13 @@ python -m svg_to_getdp --simulation-only existing_mesh.msh --config config.yaml
### Examples
```bash
# Generate mesh with custom name and no GUI
python -m svg_to_getdp sketch.svg --mesh-name my_design --no-gui
python -m svg_to_getdp <path_to_svg> --mesh-name my_design --no-gui

# Full pipeline with custom config
python -m svg_to_getdp circuit.svg --config custom_config.yaml --run-simulation
python -m svg_to_getdp <path_to_svg> --config custom_config.yaml --run-simulation

# Get debug output
python -m svg_to_getdp layout.svg --debug
python -m svg_to_getdp <path_to_svg> --debug
```

## 📊 Output
Expand All @@ -164,33 +147,50 @@ The pipeline generates the following outputs depending on the mode:

### Mode 1 (SVG → Gmsh)

Inside the sketchgetdp directory inside SketchGetDP:

- **`.msh` file**: Gmsh mesh file with physical groups

### Mode 2 (SVG → Gmsh → GetDP)

Inside the sketchgetdp directory inside SketchGetDP:

- **`.msh` file**: Gmsh mesh file
- **`.pro` file**: GetDP problem definition
- **`results/` directory**: GetDP simulation results

### Mode 3 (Gmsh Mesh → GetDP)

Inside the sketchgetdp directory inside SketchGetDP:

- **`.pro` file**: GetDP problem definition
- **`results/` directory**: GetDP simulation results

### Debug Output

Inside the debug subdirectory of the sketchgetdp directory inside SketchGetDP:

- **`svg_parser_debug_[filename]_[timestamp].txt` file**: SVG Processing Debug output
- **`corner_detection_debug_[filename]_[timestamp].txt` file**: Corner Detection Debug output
- **`geometry_debug_[filename]_[timestamp].txt` file**: Internal Geometry Representation Debug output
- **`geometry_plot_[filename]_[timestamp].png` file**: Internal Geometry Representation Plot
- **`wire_preprocessor_debug_[filename]_[timestamp].txt` file**: Wire Preprocessing Debug output
- **`outline_grouping_debug_[filename]_[timestamp].txt` file**: Outline Grouping Debug output
- **`outline_preprocessing_debug_[filename]_[timestamp].txt` file**: Outline Preprocessing Debug output


## 🔧 Dependencies

- **NumPy** - Numerical computations
- **svgpathtools** - SVG parsing and path manipulation
- **PyYAML** - Configuration parsing
- **Gmsh** - Meshing engine (external dependency)
- **GetDP** - Finite element solver (external dependency)
- **matplotlib** - Visualization (optional)
- **NumPy** - Numerical calculations
- **svgpathtools** - SVG parsing
- **PyYAML** - Configuration
- **Gmsh** - Meshing engine (external)
- **GetDP** - Finite element solver (external)
- **matplotlib** - Visualization (optional, for debugging)

## 🎨 Use Cases

- **Rapid prototyping**: Get first estimates of electromagnetic poperties from SVG sketches
- **Educational Tool**: Visualize electromagnetic field distributions from simple drawings
- **Design validation**: Quickly test electromagnetic structures before detailed CAD modeling
- **Mesh generation**: Create quality meshes from vector graphics for various Finite Element Analysis applications

The SVG to GetDP pipeline excels at transforming intuitive SVG sketches into detailed electromagnetic simulations, bridging the gap between conceptual design and numerical analysis while maintaining configurability and reproducability.