HEG BRep Component Identifier — integration brief What it is A self-contained Windows folder (~2.1 GB unpacked) that runs an ML classifier for STEP-format CAD parts. Given a STEP file path, it returns a component label (elbow, tee, pipe, miscellaneous, plus a subtype for elbows/tees). It is not a DLL. It's a local HTTP service that runs as a child process of our viewer. The classifier is a PyTorch model behind a FastAPI server. The whole Python stack — interpreter, OCC kernel, torch, model weights — is bundled inside the folder. No Python install required on the user's machine. Architecture ┌──────────────────────────┐ ┌──────────────────────────────┐ │ Our C# 3D Viewer │ spawn child + stdout │ heg_brep_service.bat │ │ (parent process) │ ───────────────────────► │ (our launcher) │ │ │ │ └─► python.exe │ │ On viewer startup: │ read line: │ └─► FastAPI server │ │ - Process.Start(bat) │ ◄───────────────────────│ on 127.0.0.1 │ │ - read "READY port=N" │ "READY port=51571" │ :random_port │ │ │ │ │ │ On user click: │ POST /classify │ Loads models once at │ │ - HttpClient.PostAsync │ ───────────────────────► │ startup. Per-request: │ │ - JSON body │ ◄─────────────────────── │ STEP → OCC features → │ │ {step_path: "..."} │ JSON response │ GNN classifier → JSON │ │ │ │ │ │ On viewer exit: │ POST /shutdown │ │ │ - StopAsync() │ ───────────────────────► │ Graceful exit │ └──────────────────────────┘ └──────────────────────────────┘ Two key properties: One process per viewer instance. Service lifetime == viewer lifetime. Loopback only. Binds to 127.0.0.1, never exposed to the network. No firewall prompts. The API contract Endpoint Method Body Returns /health GET — {"status":"ok","models_loaded":true,"device":"cpu","uptime_sec":...} /classify POST {"step_path":"C:\\full\\path.step"} classification JSON (below) /classify_batch POST {"step_paths":["...","..."]} {"results":[...]} /shutdown POST — {"status":"shutting_down"} (service exits ~200ms later) Successful /classify response: { "status": "ok", "final_label": "4_tee_wf", "final_conf": 0.9997, "route": "tee", "pass1_argmax": "tee", "pass1_conf": 1.0, "pass2_argmax": "4_tee_wf", "pass2_predicted": "4_tee_wf", "pass2_conf": 0.9997, "step_path": "C:\\...\\part.step", "npz_path": "C:\\Users\\...\\AppData\\Local\\Temp\\heg_brep_npz_xxx\\part.npz" } Error responses (HTTP 200 with an error status field, not HTTP 4xx — so the C# code branches on status): {"step_path": "...", "status": "extraction_failed", "error": "Bodies which are not closed are not supported"} {"step_path": "...", "status": "inference_failed", "error": "..."} {"step_path": "...", "status": "error", "error": "step_path not found"} Label space Pass-1 (parent classifier): elbow / tee / pipe / miscellaneous Pass-2 elbow subtypes: 1_elbow_wf / 2_elbow_pef / 3_elbow_sf / 8_elbow_misc Pass-2 tee subtypes: 4_tee_wf / 5_tee_pef / 6_tee_sf / 9_tee_misc Pipe / miscellaneous: final_label is random (no specialist for these families). Use pass1_argmax if you need the parent label. *_wf = welded fitting, *_pef / *_sf = other manufacturing subtypes, *_misc = within-family unclassified. What you need to implement in C# There's a working reference client in dist/heg_brep_dist/csharp_sample/ (~150 lines). It targets .NET 6 but works on .NET Framework 4.7.2+ with no changes. Usage: var client = new HegBrepClient(); // At viewer startup (or lazily on first identify request — your call): await client.StartAsync(@"C:\Program Files\OurViewer\heg_brep\heg_brep_service.bat"); // When the user clicks "Identify component": var stepPath = await ExportCurrentSelectionToTempStep(); // your existing OCC export var result = await client.ClassifyAsync(stepPath); labelControl.Text = $"{result.FinalLabel} ({result.FinalConf:P1})"; // On viewer shutdown: await client.StopAsync(); The client class handles: spawning the bat, reading the READY port=N line from stdout, posting JSON, parsing responses, graceful shutdown with a Kill fallback. Performance budget Measured on a developer laptop (RTX 3050, but service runs on CPU): Event Cost Service startup 10–15 s (paid once per viewer launch) First /classify after startup ~1.0 s Subsequent /classify calls ~0.8 s (dominated by OCC feature extraction; inference itself is ~50 ms) For UX, recommend you start the service eagerly at viewer launch (hide behind splash) or lazily on first Identify click (show a "warming up..." spinner for ~10 s). Failure modes you must handle Service won't start (heg_brep_service.bat exits before READY line) → log stderr (the client forwards it to Debug.WriteLine), surface error to user, do not retry in a tight loop. STEP fails extraction ("Bodies which are not closed are not supported" is the most common one — Inventor exports sometimes hit this). Branch on status != "ok". Service hangs / takes too long — HegBrepClient has a 60-second timeout. If ClassifyAsync throws TaskCanceledException, the service is wedged. Call StopAsync() and restart. Service crashes mid-session — process exits, next ClassifyAsync will throw a connection error. Recovery: catch, call StartAsync() again, retry once. A small supervisor that restarts the service on crash (max 3 retries per session) is a reasonable addition. What's in the bundle heg_brep_dist/ ├── heg_brep_service.bat ← what you Process.Start ├── heg_brep_batch.bat ← offline regression-test tool, irrelevant for the viewer ├── README.txt ← detailed docs ├── python/ ← bundled Python 3.10 env (do not modify) ├── heg_brep/ ← our Python code ├── BRepExtractor/ ← STEP→features pipeline ├── models/ ← 3 model files (~94 MB total) └── csharp_sample/ ← HegBrepClient.cs + Program.cs (copy into your project) Installer should drop this whole folder somewhere under the viewer's install dir (e.g. Program Files\OurViewer\heg_brep\) and never modify it. Updates ship as a new folder replacement; viewer code doesn't change. Constraints / non-goals Windows x64 only. Linux / macOS / 32-bit not supported. CPU inference by default. A CUDA variant exists (separate ~2 GB bundle) if customers have NVIDIA GPUs — currently not packaged. STEP input only. Other CAD formats (IGES, JT, native Inventor/SolidWorks) would need a converter layer first. Single-threaded service. Don't fire concurrent /classify calls from multiple viewer threads — they'll serialize anyway. If you need parallelism, queue requests in C#. Questions to send back If anything in the contract is unclear, the things most worth raising before coding starts: Where in the installer layout should heg_brep_dist/ live? That determines the path you pass to StartAsync. Eager vs. lazy service startup — affects splash-screen design. How does the viewer currently export a selected solid to a STEP file? (We need a file path, not in-memory geometry, in v1.) Logging — should service stderr go to the viewer's existing log file, or to its own file alongside the bundle?