vflow2 Documentation

IFC Analysis Tools ← Back to App

Connection Graph System

Purpose

The connection graph assigns connection points (nodes) to every IFC building element and creates edges between points that are physically connected. This provides the topological foundation for all pathfinding, routing, and mathematical analysis.

Files

File Role
tools/_connection_graph.py Core engine: element extraction, point generators, graph building
tools/connection_graph.py Tool wrapper: runs from the analysis page, saves JSON
app.py route /connection_graph/<filename> API endpoint: serves cached graph JSON to the viewer

Calculation Steps

Step 1: Element Extraction (extract_all_elements)

Opens the IFC model and extracts geometry for all relevant elements:

Each element gets: {id, type, name, bbox_min, bbox_max, corners[8], ...type-specific fields}

Step 2: Point Generation (Registry Pattern)

Each element type has a registered point generator function:

@register_point_generator("IfcWall")
def _generate_wall_points(elem_data, all_elements):
    # Returns (nodes, internal_edges)

Adding a new element type requires only writing one new @register_point_generator function. No other files need modification.

IfcWall Points

IfcDoor Points

IfcWindow Points

IfcSlab Points

IfcSpace Points

Step 3: External Edge Detection

After all point generators have run, a spatial query finds co-located nodes from different elements:

  1. Build a scipy.spatial.KDTree from all node positions
  2. Query all pairs within 0.05m radius
  3. Pairs from different elements → "external" edge (distance ≈ 0.0)

This handles all cross-element connections uniformly: wall↔wall, wall↔door, wall↔slab, wall↔space, slab↔space

Step 4: Serialization

The graph is saved as uploads/<stem>.connection_graph.json:

{
  "version": 1,
  "ifc_file": "test-1.ifc",
  "generated_at": "2026-03-28T14:30:00Z",
  "nodes": [
    {"id": "wall_291_corner_0", "pos": [0.3, 5.1, 0.0],
     "element_id": 291, "element_type": "IfcWall", "point_type": "corner"}
  ],
  "edges": [
    {"source": "wall_291_corner_0", "target": "wall_291_corner_1",
     "type": "internal", "distance": 2.8}
  ],
  "stats": {"node_count": 114, "edge_count": 174,
            "internal_edges": 136, "external_edges": 44}
}

Node IDs are deterministic: <type>_<elementId>_<pointType>_<index>

Viewer Visualization

Connection graph overlay

Example Output (test-1.ifc)