Skip to content

liblaf.melon.ext.wrap ยค

Functions:

  • annotate_landmarks โ€“
  • fast_wrapping โ€“

annotate_landmarks ยค

annotate_landmarks(
    left: Any,
    right: Any,
    *,
    left_landmarks: Float[ArrayLike, "L 3"] | None = None,
    right_landmarks: Float[ArrayLike, "L 3"] | None = None,
) -> tuple[Float[ndarray, "L 3"], Float[ndarray, "L 3"]]
Source code in src/liblaf/melon/ext/wrap/_annotate_landmarks.py
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
def annotate_landmarks(
    left: Any,
    right: Any,
    *,
    left_landmarks: Float[ArrayLike, "L 3"] | None = None,
    right_landmarks: Float[ArrayLike, "L 3"] | None = None,
) -> tuple[Float[np.ndarray, "L 3"], Float[np.ndarray, "L 3"]]:
    if left_landmarks is None:
        left_landmarks = np.zeros((0, 3))
    if right_landmarks is None:
        right_landmarks = np.zeros((0, 3))
    with tempfile.TemporaryDirectory() as tmpdir_str:
        tmpdir: Path = Path(tmpdir_str).absolute()
        project_file: Path = tmpdir / "annotate-landmarks.wrap"
        left_file: Path = tmpdir / "left.obj"
        right_file: Path = tmpdir / "right.obj"
        left_landmarks_file: Path = tmpdir / "left.landmarks.json"
        right_landmarks_file: Path = tmpdir / "right.landmarks.json"
        io.save(left_file, left)
        io.save(right_file, right)
        io.save_landmarks(left_landmarks_file, left_landmarks)
        io.save_landmarks(right_landmarks_file, right_landmarks)
        template: jinja2.Template = environment.get_template("annotate-landmarks.wrap")
        project: str = template.render(
            {
                "left": left_file,
                "right": right_file,
                "left_landmarks": left_landmarks_file,
                "right_landmarks": right_landmarks_file,
            }
        )
        project_file.write_text(project)
        sp.run(["Wrap.sh", project_file], check=True)
        left_landmarks = io.load_landmarks(left_landmarks_file)
        right_landmarks = io.load_landmarks(right_landmarks_file)
    return left_landmarks, right_landmarks

fast_wrapping ยค

fast_wrapping(
    source: Any,
    target: Any,
    *,
    source_landmarks: Float[ArrayLike, "L 3"] | None = None,
    target_landmarks: Float[ArrayLike, "L 3"] | None = None,
    free_polygons_floating: Bool[ArrayLike, " full"]
    | Integer[ArrayLike, " free"]
    | None = None,
    verbose: bool = False,
) -> PolyData
Source code in src/liblaf/melon/ext/wrap/_fast_wrapping.py
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
def fast_wrapping(
    source: Any,
    target: Any,
    *,
    source_landmarks: Float[ArrayLike, "L 3"] | None = None,
    target_landmarks: Float[ArrayLike, "L 3"] | None = None,
    free_polygons_floating: Bool[ArrayLike, " full"]
    | Integer[ArrayLike, " free"]
    | None = None,
    verbose: bool = False,
) -> pv.PolyData:
    source_landmarks = (
        source_landmarks if source_landmarks is not None else np.empty((0, 3))
    )
    target_landmarks = (
        target_landmarks if target_landmarks is not None else np.empty((0, 3))
    )
    free_polygons_floating = (
        free_polygons_floating if free_polygons_floating is not None else np.empty((0,))
    )
    with tempfile.TemporaryDirectory() as tmpdir_str:
        tmpdir: Path = Path(tmpdir_str).absolute()
        project_file: Path = tmpdir / "fast-wrapping.wrap"
        source_file: Path = tmpdir / "source.obj"
        target_file: Path = tmpdir / "target.obj"
        output_file: Path = tmpdir / "output.obj"
        source_landmarks_file: Path = tmpdir / "source.landmarks.json"
        target_landmarks_file: Path = tmpdir / "target.landmarks.json"
        free_polygons_floating_file: Path = tmpdir / "free-polygons-floating.json"
        io.save(source_file, source)
        io.save(target_file, target)
        io.save_landmarks(source_landmarks_file, source_landmarks)
        io.save_landmarks(target_landmarks_file, target_landmarks)
        io.save_polygons(free_polygons_floating_file, free_polygons_floating)
        template: jinja2.Template = environment.get_template("fast-wrapping.wrap")
        project: str = template.render(
            {
                "source": str(source_file),
                "target": str(target_file),
                "output": str(output_file),
                "source_landmarks": str(source_landmarks_file),
                "target_landmarks": str(target_landmarks_file),
                "free_polygons_floating": str(free_polygons_floating_file),
            }
        )
        project_file.write_text(project)
        args: list[str | Path] = ["WrapCmd.sh", "compute", project_file]
        if verbose:
            args.append("--verbose")
        sp.run(args, check=True)
        result: pv.PolyData = io.load_polydata(output_file)
        result.copy_attributes(source)
        return result