예제 #1
0
    def __create_blocks(self,file_name):
        coil_points = read_and_transform.extract_coil_samples(self.normalized_points)
        #print "Tamano coil: %s" %len(coil_points)

        #Get file name
        temp = file_name.split('/')
        lastone = len(temp)
        newfile = temp[lastone-1]
        csvfile="calib_data/calib_points/"+newfile

        #Save file with calib coil_points
        with open(csvfile, "w") as output:
            writer = csv.writer(output, lineterminator='\n')
            writer.writerows([coil_points])

        #Generate new coil points
        self._create_csv(csvfile)
        coil_points=self._create_new_data(coil_points,csvfile)
        #print 'Nuevos datos coil'
        #print coil_points

        #Generate blocks to visualize
        blocks_indices = Blocks.get_blocks(coil_points, 7)

        # remove small blocks
        blocks_indices = filter(lambda x: len(x) > 5, blocks_indices)
        blocks = []
        for bi in blocks_indices:
            #print 'Creating blocks'
            points = [coil_points[i] for i in bi]
            b = TmsBlock(points)
            b.calculate_sphere_intersection(self.sphere_radius, self.sphere_center)
            b.find_hemisphere(self.calibration_points, self.sphere_center)
            blocks.append(b)
        self.blocks = blocks
예제 #2
0
def main():
    os.chdir(os.path.dirname(__file__))
    os.chdir("../data")


    test_file = "TMS-597.csv"
    test_file = "TMS-640.csv"
    points = read_and_transform.read_csv_file(test_file)
    points = read_and_transform.normalize_to_ref(points,points[0])
    calib = read_and_transform.extract_calibration_samples(points)

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

    colors = [(1,0,0),(0,1,0),(0,1,1),(1,0,1)]
    ot_points = [p.point_pos for p in calib.itervalues()]
    d = calib[1].date
    point_f = read_and_transform.get_pointer_transform_function(d)
    calib_ps = [point_f(p) for p in calib.itervalues()]

    for p1,p2,c in izip(ot_points,calib_ps,colors):
        ac = __add_sphere_to_ren(p1,0.01,ren)
        ac.GetProperty().SetColor(c)
        ac.GetProperty().SetOpacity(0.2)
        ac = __add_sphere_to_ren(p2,0.01,ren)
        ac.GetProperty().SetColor(c)
        ac = __add_line_to_ren(p1,p2,ren)
        ac.GetProperty().SetColor(c)
        #ac.GetProperty().SetRepresentationToWireframe()

    calib_ps2 = [calib_ps[i] for i in [0,2,3]]
    r,ctr = tms_geom.adjust_sphere(calib_ps2)
    print r
    print ctr
    __add_sphere_to_ren(ctr,r,ren)

    coil_fun = read_and_transform.get_coil_transform_function(d)
    coils = read_and_transform.extract_coil_samples(points)
    oops = 0
    for p in coils:
        c,t = coil_fun(p)
        __add_sphere_to_ren(c,0.01,ren)
        l=__add_line_to_ren(c,t,ren)
        l.GetProperty().SetLineWidth(2)
        x = tms_geom.intersect_point_with_sphere(c,t-c,r,ctr)
        if x is None:
            x = tms_geom.intersect_point_with_sphere(c,c-t,r,ctr)
            oops += 1
        if x is not None:
            l2 = __add_line_to_ren(c,x,ren)


    print oops
    iren.Initialize()
    iren.Start()





    iren.Initialize()
    iren.Start()
예제 #3
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()