File size: 8,402 Bytes
da6986a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 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? |