File: align1.py

package info (click to toggle)
vedo 2025.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,404 kB
  • sloc: python: 64,792; javascript: 1,932; xml: 437; sh: 139; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 844 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Align 2 shapes:
the red line to the yellow surface"""
from vedo import *

# Load two mesh objects, a limb and a rim, and color them gold and red
limb = Mesh(dataurl + "270.vtk").c("gold")
rim1 = Mesh(dataurl + "270_rim.vtk").c("red5").lw(4)

# Make a clone copy of the rim and align it to the limb
# Using rigid=True does not allow scaling
rim2 = rim1.clone().align_to(limb, rigid=True).c("green5").lw(5)

# Calculate the average squared distance between the aligned rim and the limb
d = 0
for p in rim2.coordinates:
    cpt = limb.closest_point(p)
    d += mag2(p - cpt)  # square of residual distance
average_squared_distance = d / rim2.npoints

# Print the average squared distance between the aligned rim and the limb
printc("Average squared distance =", average_squared_distance, c="g")

show(limb, rim1, rim2, __doc__, axes=1).close()