コード例 #1
0
ファイル: test_tubetk.py プロジェクト: xetrocoen/TubeTK
def VesselTubeToNumPyTest(tubes, baseline_array):
    import numpy as np
    from tubetk.numpy import tubes_from_file

    array = tubes_from_file(tubes)
    print(array.dtype)
    print(array)

    baseline = np.load(baseline_array)

    all_fields_close = True
    for field in baseline.dtype.fields.iterkeys():
        if not np.allclose(array[field], baseline[field]):
            all_fields_close = False
            print('The array field: ' + field + ' does not match!')

    return all_fields_close
コード例 #2
0
ファイル: test_tubetk.py プロジェクト: AorticaCorp/TubeTK
def VesselTubeToNumPyTest(tubes, baseline_array):
    import numpy as np
    from tubetk.numpy import tubes_from_file

    array = tubes_from_file(tubes)
    print(array.dtype)
    print(array)

    baseline = np.load(baseline_array)

    all_fields_close = True
    for field in baseline.dtype.fields.iterkeys():
        if not np.allclose(array[field], baseline[field]):
            all_fields_close = False
            print('The array field: ' + field + ' does not match!')

    return all_fields_close
コード例 #3
0
def VesselTubeToNumPyTest(tubes, baseline_array):
    import numpy as np
    from tubetk.numpy import tubes_from_file

    print('Reading file: ' + tubes)
    array = tubes_from_file(tubes)
    print(array.dtype)
    print(array)

    baseline = np.load(baseline_array)

    all_fields_close = True
    for field in baseline.dtype.fields.keys():
        print("Testing field = " + field)
        if not np.allclose(array[field], baseline[field]):
            all_fields_close = False
            print('The array field: ' + field + ' does not match!')
            print('array = ' + str(array[field]))
            print('baseline = ' + str(baseline[field]))

    return all_fields_close
コード例 #4
0
ファイル: test_tubetk.py プロジェクト: xetrocoen/TubeTK
def PyQtGraphTubesAsCirclesTest(tube_file, screenshot):
    import pyqtgraph as pg
    import pyqtgraph.opengl as gl
    from tubetk.numpy import tubes_from_file
    from tubetk.pyqtgraph import tubes_as_circles

    tubes = tubes_from_file(tube_file)
    subsample = 30
    tubes = tubes[::subsample]

    # Setup QApplication
    qapp = pg.mkQApp()

    view = gl.GLViewWidget()
    view.setCameraPosition(distance=200)
    view.orbit(0., 20.)
    view.setWindowTitle('PyQtGraphTubePointsTest')
    view.show()

    x_grid = gl.GLGridItem()
    grid_scale = 20
    x_grid.rotate(90, 0, 1, 0)
    x_grid.translate(-10 * grid_scale, 0, 0)
    y_grid = gl.GLGridItem()
    y_grid.rotate(90, 1, 0, 0)
    y_grid.translate(0, -10 * grid_scale, 0)
    z_grid = gl.GLGridItem()
    z_grid.translate(0, 0, -10 * grid_scale)
    for grid in x_grid, y_grid, z_grid:
        grid.scale(grid_scale, grid_scale, grid_scale)
        view.addItem(grid)

    circles = tubes_as_circles(tubes)
    circles_mesh = gl.GLMeshItem(meshdata=circles, smooth=False)
    view.addItem(circles_mesh)

    #return qapp.exec_()
    view.paintGL()
    framebuffer = view.grabFrameBuffer()
    return framebuffer.save(screenshot)
コード例 #5
0
ファイル: test_tubetk.py プロジェクト: AorticaCorp/TubeTK
def PyQtGraphTubesAsCirclesTest(tube_file, screenshot):
    import pyqtgraph as pg
    import pyqtgraph.opengl as gl
    from tubetk.numpy import tubes_from_file
    from tubetk.pyqtgraph import tubes_as_circles

    tubes = tubes_from_file(tube_file)
    subsample = 30
    tubes = tubes[::subsample]

    # Setup QApplication
    qapp = pg.mkQApp()

    view = gl.GLViewWidget()
    view.setCameraPosition(distance=200)
    view.orbit(0., 20.)
    view.setWindowTitle('PyQtGraphTubePointsTest')
    view.show()

    x_grid = gl.GLGridItem()
    grid_scale = 20
    x_grid.rotate(90, 0, 1, 0)
    x_grid.translate(-10 * grid_scale, 0, 0)
    y_grid = gl.GLGridItem()
    y_grid.rotate(90, 1, 0, 0)
    y_grid.translate(0, -10 * grid_scale, 0)
    z_grid = gl.GLGridItem()
    z_grid.translate(0, 0, -10 * grid_scale)
    for grid in x_grid, y_grid, z_grid:
        grid.scale(grid_scale, grid_scale, grid_scale)
        view.addItem(grid)

    circles = tubes_as_circles(tubes)
    circles_mesh = gl.GLMeshItem(meshdata=circles, smooth=False)
    view.addItem(circles_mesh)

    #return qapp.exec_()
    view.paintGL()
    framebuffer = view.grabFrameBuffer()
    return framebuffer.save(screenshot)
    def add_tubes(self):
        """Add the transformed tubes for the visualization."""
        memory = 4
        target_iterations = tuple(range(self.logic.iteration,
                                  self.logic.iteration - memory,
                                  -1))

        for it in target_iterations:
            if it >= 0 and it <= self.logic.number_of_iterations:
                alpha = np.exp(0.8*(it - self.logic.iteration))
                center_color = (0.8, 0.1, 0.25, alpha)
                center = self.logic.tubes_center
                if self.logic.progression != None:
                    parameters = self.logic.progression[it]['Parameters']
                else:
                    parameters = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
                tubes = tubes_from_file(self.logic.subsampled_tubes)
                #tubes_color = (0.2, 0.25, 0.75, alpha)
                if 'TubePointWeightsFile' in self.config and \
                        os.path.exists(self.config['TubePointWeightsFile']):
                    with open(self.config['TubePointWeightsFile'], 'r') as fp:
                        tube_weights = json.load(fp)['TubePointWeights']
                        tube_weights = np.array(tube_weights)
                else:
                    tube_weights = 2./(1. + np.exp(-2 * tubes['Radius']))
                tube_weights = tube_weights - tube_weights.min()
                tube_weights = tube_weights / tube_weights.max()
                tubes_colors = matplotlib.cm.PuBuGn(tube_weights)
                tubes_colors[:, 3] = tube_weights**0.5 * alpha
                circles = tubes_as_circles(tubes, point_colors=tubes_colors)
                circles_mesh = gl.GLMeshItem(meshdata=circles,
                                             glOptions='translucent',
                                             smooth=False)
                if self.logic.progression != None:
                    # TODO: need to verify that this is correct
                    circles_mesh.translate(-center[0],
                                           -center[1],
                                           -center[2])
                    r2d = 180. / np.pi
                    circles_mesh.rotate(parameters[0] * r2d, 1, 0, 0,
                                        local=False)
                    circles_mesh.rotate(parameters[1] * r2d, 0, 1, 0,
                                        local=False)
                    circles_mesh.rotate(parameters[2] * r2d, 0, 0, 1,
                                        local=False)
                    circles_mesh.translate(center[0] + parameters[3],
                                           center[1] + parameters[4],
                                           center[2] + parameters[5])
                if it in self.tubes_circles:
                    self.removeItem(self.tubes_circles[it][1])
                self.addItem(circles_mesh)

                sphere = gl.MeshData.sphere(rows=10,
                                            cols=20,
                                            radius=1.0)
                center_mesh = gl.GLMeshItem(meshdata=sphere,
                                            smooth=False,
                                            color=center_color,
                                            glOptions='translucent')
                center_mesh.translate(center[0] + parameters[3],
                                      center[1] + parameters[4],
                                      center[2] + parameters[5])
                if it in self.tubes_circles:
                    self.removeItem(self.tubes_circles[it][2])
                self.addItem(center_mesh)

                self.tubes_circles[it] = [circles,
                                          circles_mesh,
                                          center_mesh]

        for it, circs in self.tubes_circles.items():
            if not it in target_iterations:
                self.removeItem(circs[1])
                self.removeItem(circs[2])
                self.tubes_circles.pop(it)