コード例 #1
0
 def calculate_sphere_intersection(self, sphere_r, sphere_center):
     ctr, top = self.coil_center, self.coil_top
     self.sphere_intersection = tms_geom.intersect_point_with_sphere(ctr, top - ctr, sphere_r, sphere_center)
コード例 #2
0
def __test_one():
    import os
    import vtk
    from itertools import izip

    test_dir = os.path.join(os.path.dirname(__file__), "data")
    test_file = os.path.join(test_dir, "TMS-441.csv")
    test_file = os.path.join(test_dir, "TMS-758.csv")
    #test_file = os.path.join(test_dir, "TMS-310.csv")

    points = tms_rt.read_csv_file(test_file)
    calibs = tms_rt.extract_calibration_samples(points)
    assert set(calibs.keys()) == {1, 2, 3, 4}
    ref = calibs[3]
    calibs_norm = dict(((k, tms_rt.normalize_point_to_ref(v, ref) ) for k, v in calibs.iteritems() ))

    ren_win = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(ren_win)
    ren = vtk.vtkRenderer()
    ren_win.AddRenderer(ren)

    date = ref.date

    pointer_fun = tms_rt.get_pointer_transform_function(date)
    calib_points = [pointer_fun(p) for p in calibs_norm.itervalues()]

    r,ctr = tms_geom.adjust_sphere(calib_points)

    for p in calib_points:
        __add_sphere_to_ren(p,r/20,ren)

    ac = __add_sphere_to_ren(ctr,r,ren)
    ac.GetProperty().SetColor(1,0,0)
    #fit sphere to calibration

    coil_samples = tms_rt.extract_coil_samples(points)[:50]
    coil_samples_norm = tms_rt.normalize_to_ref(coil_samples, ref)
    coil_function = tms_rt.get_coil_transform_function(date)
    coil_pairs = [coil_function(p) for p in coil_samples_norm]
    cc = (0, 1, 0)
    cc2 = (0.2,0.7,0.2)
    for (c, t),p in izip(coil_pairs,coil_samples_norm):
        ac = __add_sphere_to_ren(c, 0.002, ren)
        ac.GetProperty().SetColor(cc)
        ac = __add_line_to_ren(c, np.subtract(t, c), ren)
        ac.GetProperty().SetColor(cc)

    #draw intersection with sphere
    intersects = [tms_geom.intersect_point_with_sphere(c,np.subtract(t,c),r,ctr) for c,t in coil_pairs]
    for p in intersects:
        ac = __add_sphere_to_ren(p, 0.001, ren)
        ac.GetProperty().SetColor(cc2)
        ac.GetProperty().SetOpacity(0.5)

    #find plane
    vec,  circle_radius = tms_geom.circle_from_points_in_sphere(intersects,r,ctr)
    __add_plane_to_ren(ctr+vec,vec,r,ren)

    iren.Initialize()
    iren.Start()