align1.py 876 B

1234567891011121314151617181920212223
  1. """Align 2 shapes:
  2. the red line to the yellow surface"""
  3. from vedo import Mesh, dataurl, mag2, printc, show
  4. # Load two mesh objects, a limb and a rim, and color them gold and red
  5. limb = Mesh(dataurl + "270.vtk").c("gold")
  6. rim1 = Mesh(dataurl + "270_rim.vtk").c("red5").lw(4)
  7. # Make a clone copy of the rim and align it to the limb
  8. # Using rigid=True does not allow scaling
  9. rim2 = rim1.clone().align_to(limb, rigid=True).c("green5").lw(5)
  10. # Calculate the average squared distance between the aligned rim and the limb
  11. d = 0
  12. for p in rim2.coordinates:
  13. cpt = limb.closest_point(p)
  14. d += mag2(p - cpt) # square of residual distance
  15. average_squared_distance = d / rim2.npoints
  16. # Print the average squared distance between the aligned rim and the limb
  17. printc("Average squared distance =", average_squared_distance, c="g")
  18. show(limb, rim1, rim2, __doc__, axes=1).close()