react-native-mask-segment-c.../docs/docs/api/ref-methods.md
a1518 3a3f07628d
Some checks failed
Deploy Docs to GitHub Pages / deploy (push) Has been cancelled
Publish to npm / publish (push) Has been cancelled
feat: add manual lasso wall splitting with magnetic edge-snapping and active contour refinement
- New magneticLasso module: Sobel energy map + Dijkstra shortest-path + Douglas-Peucker
- New activeContour module: greedy snake + balloon force for polygon-to-edge refinement
- wallTextureSplit: edge barrier mask, morphological mask hole closing, Moore boundary tracing, simplified polygon contours, manual pick map patching, gap absorption
- MaskSegmentCanvas: full lasso gesture pipeline (tap vertices, drag, magnetic paths, close polygon, endLasso/cancelLasso/deleteLasso)
- New maskConfig options: splitWallsEdgeBarrierThreshold, splitWallsCloseMaskRadius, manualSplitWalls, manualSplitWallsMaxCount, manualSplitWallsGapAbsorbDilatePx, magneticLasso, activeContourRefine
- New ref methods: startLasso, endLasso, cancelLasso, getManualRegions, deleteLasso
- New exported types: LassoPolygon, ManualWallPartition
- RegionMaskData carries indexToName and wallSemanticIdx through downsample
- Simplify README to point to documentation site
- Update documentation site (EN + ZH-CN) with all new APIs and interaction guide
- Example app: lasso mode toggles and operation buttons

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 20:23:57 -07:00

3.3 KiB

id title
ref-methods Ref Methods

🔧 Ref Methods

Accessed via ref (type MaskSegmentCanvasRef):

Method Signature Description
reset () => void Undo last paint step (by paintHistory)
swap (showOrigin?: boolean) => void Toggle origin image comparison; omit arg to toggle, true/false to force
save (options?) => Promise<SavePaintResult> Composite and save PNG; options.destDir optional output directory
session () => MaskSegmentSession Export JSON-serializable session (for MMKV storage)
loadSession (session) => void Restore paint state (also available via initialSession)
setPaintColor (color, configJson?) => void Set current brush color; clears bottom color bar selection
setMaskConfig (config) => void Update mask config at runtime and re-segment
clearAllPaint () => void Clear all paint records
resegment () => Promise<void> Clear PNG cache and re-segment
getRegions () => SegmentRegion[] Snapshot of current region list
getPaintedRegions () => PaintedRegionRecord[] Snapshot of current paint records
getLastExport () => SavePaintResult | null Returns the most recent auto-export or save() result, if any
startLasso () => void Enter lasso mode — user can tap wall mask area to place polygon vertices
endLasso () => ManualWallPartition[] Exit lasso mode, convert all closed lasso polygons into wall-X sub-regions for painting
cancelLasso () => void Exit the current lasso editing session without saving regions
getManualRegions () => ManualWallPartition[] Get the current manual wall partitions (only valid after endLasso)
deleteLasso (id: string) => void Delete a lasso polygon by its id. Committed partitions also drop paint on that region

SavePaintResult

{ filePath, width, height, paintedCount, previewPath? }

ManualWallPartition

{ id, regionId, regionName, vertices, bbox, area }

Returned by endLasso() and getManualRegions(). Each partition maps a lasso polygon to a wall-N sub-region.

Code Examples

const ref = useRef<MaskSegmentCanvasRef>(null);

// Paint operations
ref.current?.reset();
ref.current?.swap();           // toggle
ref.current?.swap(true);       // force show origin

const result = await ref.current?.save({ destDir: '/path/to/dir' });

const session = ref.current?.session();
ref.current?.loadSession(session);

ref.current?.setPaintColor({ b: 100, g: 120, r: 140 }, { sku: 'paint-001' });
ref.current?.setMaskConfig({ semanticColors: customColors });

ref.current?.clearAllPaint();
await ref.current?.resegment();

const regions = ref.current?.getRegions();
const painted = ref.current?.getPaintedRegions();

// Lasso operations
ref.current?.startLasso();                // enter lasso mode
// ... user taps wall areas to place vertices ...
const partitions = ref.current?.endLasso();  // convert polygons to wall-N regions
ref.current?.cancelLasso();               // discard in-progress lasso

const manualRegions = ref.current?.getManualRegions();
ref.current?.deleteLasso('lasso_1');      // remove a specific polygon

save depends on the working buffer and pickMap being ready (typically after interactive); throws 'Image not ready, cannot save' if not ready.