| HEG BRep Component Identification — Distribution Bundle |
| ========================================================= |
|
|
| This folder is a self-contained Windows distribution. It runs without any |
| pre-installed Python or conda. Drop the whole folder next to your viewer's |
| installer; the viewer launches `heg_brep_service.bat` as a child process and |
| talks to it over localhost HTTP. |
|
|
|
|
| Contents |
| -------- |
| heg_brep_service.bat Launches the classification service. Prints |
| `READY port=<N>` to stdout once models are loaded. |
| Use `--device cpu` (default) or `--device cuda`. |
| heg_brep_batch.bat Optional batch CLI: STEP folder -> Excel report. |
| Useful for offline regression testing. |
| python\ Conda-packed Python 3.10 environment (~2 GB). |
| Includes pythonocc-core, occwl, torch (CPU), |
| torch_geometric, fastapi, uvicorn, numpy, MKL. |
| heg_brep\ The classification package (model, inference, |
| extraction, server, batch CLI). |
| BRepExtractor\ STEP -> NPZ feature extraction pipeline. |
| models\ Three checkpoints used by the two-pass classifier: |
| pass1.pt (parent), elbow.pt, tee.pt. |
| csharp_sample\ Reference C# integration: HegBrepClient.cs is a |
| drop-in async client; Program.cs is a smoke test |
| (build with `dotnet build`). |
|
|
|
|
| Quick smoke test |
| ---------------- |
| From this folder, in a regular cmd.exe: |
|
|
| heg_brep_batch.bat C:\path\to\step_folder C:\path\to\out.xlsx |
|
|
| Or run the service standalone and poke it with curl: |
|
|
| heg_brep_service.bat |
| (waits ~10-15s; prints `READY port=51571`) |
| curl http://127.0.0.1:51571/health |
| curl -X POST http://127.0.0.1:51571/classify ^ |
| -H "Content-Type: application/json" ^ |
| -d "{\"step_path\":\"C:\\path\\to\\part.step\"}" |
|
|
|
|
| Service HTTP API |
| ---------------- |
| GET /health |
| -> {"status":"ok","models_loaded":true,"device":"cpu","uptime_sec":...} |
|
|
| POST /classify Single STEP file -> classification result. |
| Body: {"step_path": "C:\\full\\path\\to\\part.step", |
| "npz_keep_dir": "optional\\persist\\dir"} |
| Resp: {"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, |
| "npz_path": "...", "step_path": "..."} |
|
|
| POST /classify_batch Multiple STEPs in one call. Same JSON schema, |
| but body is `{"step_paths": ["...", "..."]}`. |
|
|
| POST /shutdown Graceful exit. The host (your viewer) should call |
| this on exit so the python.exe child doesn't linger. |
|
|
|
|
| Performance budget (RTX 3050 laptop, --device cpu) |
| -------------------------------------------------- |
| Service startup: ~10-15s (OCC + torch + 3 models cold-load) |
| First /classify call: ~1.0s (single STEP extract + inference) |
| Warm /classify calls: ~0.8s (warm OCC stack, varies with STEP size) |
|
|
| Switch to `--device cuda` for ~5-10x faster inference if the target machine |
| has CUDA 12.x drivers + a supported GPU. With CPU torch (default), no NVIDIA |
| runtime is required. |
|
|
|
|
| Output label space |
| ------------------ |
| Pass-1 (parent classifier): elbow | tee | pipe | miscellaneous |
| Pass-2 elbow specialist: 1_elbow_wf | 2_elbow_pef | 3_elbow_sf | 8_elbow_misc |
| Pass-2 tee specialist: 4_tee_wf | 5_tee_pef | 6_tee_sf | 9_tee_misc |
|
|
| For pipe / miscellaneous routes the response has `final_label="random"` with |
| the pass-1 confidence (no specialist exists for those families). |
|
|
|
|
| C# integration |
| -------------- |
| See csharp_sample/HegBrepClient.cs for a drop-in async client. Typical usage: |
|
|
| var client = new HegBrepClient(); |
| await client.StartAsync(@"C:\Program Files\YourViewer\heg_brep\heg_brep_service.bat"); |
| // Later, when user clicks "Identify": |
| var r = await client.ClassifyAsync(@"C:\tmp\selection.step"); |
| label.Text = $"{r.FinalLabel} ({r.FinalConf:P1})"; |
| // On viewer exit: |
| await client.StopAsync(); |
|
|
| The client spawns the .bat as a child process, reads the `READY port=<N>` |
| line from its stdout, then POSTs to http://127.0.0.1:<N>/classify. Stderr is |
| forwarded to Debug.WriteLine for your logger to capture. |
|
|
|
|
| Troubleshooting |
| --------------- |
| * "DLL load failed" on first run. |
| The bat sets PATH to include python\Library\bin where MKL / OCC DLLs |
| live. If you launch python.exe directly without the bat, you'll hit this. |
|
|
| * Cold service start takes 30+ seconds. |
| The first run after extracting the zip is slow because Windows loads each |
| DLL from disk for the first time. Subsequent starts are ~5-10s once the |
| OS file cache is warm. |
|
|
| * "Bodies which are not closed are not supported". |
| Upstream extractor limitation. Some STEP files (typically Inventor |
| exports without explicit BREP closure) cannot be processed. The HTTP |
| response is {"status": "extraction_failed", "error": "..."}. |
|
|
| * `KMP_DUPLICATE_LIB_OK=TRUE` warning. |
| Set automatically. Coexists fine with both OpenMP runtimes; the warning |
| is overly conservative for inference. |
|
|