예제 #1
0
def create_survey_movie(mabdi_simulate, survey_mesh=False, nsteps=None, fps=2):
    """
    Note: This method assumes the source is centered on the xz plane
    :param mabdi_simulate: Instance of MabdiSimulate
    :param survey_mesh: Show the global mesh or not.
    :param nsteps: Number of steps for the movie
    :param fps: Frames per second for the movie
    """

    sourceAo = mabdi.VTKPolyDataActorObjects(mabdi_simulate.source)
    sourceAo.actor.GetProperty().SetColor(slate_grey_light)
    sourceAo.actor.GetProperty().SetSpecularColor(1, 1, 1)
    sourceAo.actor.GetProperty().SetSpecular(0.3)
    sourceAo.actor.GetProperty().SetSpecularPower(20)
    sourceAo.actor.GetProperty().SetAmbient(0.2)
    sourceAo.actor.GetProperty().SetDiffuse(0.8)
    # sourceAo.actor.GetProperty().SetOpacity(0.2)

    meshAo = mabdi.VTKPolyDataActorObjects(mabdi_simulate.mesh)
    meshAo.actor.GetProperty().SetColor(salmon)
    meshAo.actor.GetProperty().SetColor(slate_grey_light)
    meshAo.actor.GetProperty().SetSpecularColor(1, 1, 1)
    meshAo.actor.GetProperty().SetSpecular(0.3)
    meshAo.actor.GetProperty().SetSpecularPower(20)
    meshAo.actor.GetProperty().SetAmbient(0.2)
    meshAo.actor.GetProperty().SetDiffuse(0.8)
    # meshAo.actor.GetProperty().SetOpacity(0.5)

    renWin = vtk.vtkRenderWindow()
    renWin.SetSize(640, 480)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    ren = vtk.vtkRenderer()
    ren.SetBackground(eggshell)

    ren.AddActor(sourceAo.actor)

    renWin.AddRenderer(ren)

    iren.Initialize()

    cam = ren.GetActiveCamera()

    position, lookat = \
        create_sensor_path(name=mabdi_simulate._output['path_flight'],
                           nsteps=nsteps)

    if survey_mesh:
        ren.AddActor(meshAo.actor)
        sourceAo.actor.GetProperty().SetOpacity(0.2)
        # sourceAo.actor.VisibilityOff()

    # iren.Start()
    movie = mabdi.RenderWindowToAvi(
        renWin,
        mabdi_simulate._file_prefix,
        fps=fps,
        savefig_at_frame=mabdi_simulate._output['movie_savefig_at_frame'])
    for i, (pos, lka) in enumerate(zip(position, lookat)):
        cam.SetPosition(pos)
        cam.SetFocalPoint(lka)
        iren.Render()

    movie.save_movie()

    iren.GetRenderWindow().Finalize()
    iren.TerminateApp()
    del iren, ren, renWin

    return
예제 #2
0
파일: Output.py 프로젝트: lucasplus/MABDI
def create_survey_movie(mabdi_simulate,
                        survey_mesh=False,
                        nsteps=None,
                        fps=2):
    """
    Note: This method assumes the source is centered on the xz plane
    :param mabdi_simulate: Instance of MabdiSimulate
    :param survey_mesh: Show the global mesh or not.
    :param nsteps: Number of steps for the movie
    :param fps: Frames per second for the movie
    """

    sourceAo = mabdi.VTKPolyDataActorObjects(mabdi_simulate.source)
    sourceAo.actor.GetProperty().SetColor(slate_grey_light)
    sourceAo.actor.GetProperty().SetSpecularColor(1, 1, 1)
    sourceAo.actor.GetProperty().SetSpecular(0.3)
    sourceAo.actor.GetProperty().SetSpecularPower(20)
    sourceAo.actor.GetProperty().SetAmbient(0.2)
    sourceAo.actor.GetProperty().SetDiffuse(0.8)
    # sourceAo.actor.GetProperty().SetOpacity(0.2)

    meshAo = mabdi.VTKPolyDataActorObjects(mabdi_simulate.mesh)
    meshAo.actor.GetProperty().SetColor(salmon)
    meshAo.actor.GetProperty().SetColor(slate_grey_light)
    meshAo.actor.GetProperty().SetSpecularColor(1, 1, 1)
    meshAo.actor.GetProperty().SetSpecular(0.3)
    meshAo.actor.GetProperty().SetSpecularPower(20)
    meshAo.actor.GetProperty().SetAmbient(0.2)
    meshAo.actor.GetProperty().SetDiffuse(0.8)
    # meshAo.actor.GetProperty().SetOpacity(0.5)

    renWin = vtk.vtkRenderWindow()
    renWin.SetSize(640, 480)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    ren = vtk.vtkRenderer()
    ren.SetBackground(eggshell)

    ren.AddActor(sourceAo.actor)

    renWin.AddRenderer(ren)

    iren.Initialize()

    cam = ren.GetActiveCamera()

    position, lookat = \
        create_sensor_path(name=mabdi_simulate._output['path_flight'],
                           nsteps=nsteps)

    if survey_mesh:
        ren.AddActor(meshAo.actor)
        sourceAo.actor.GetProperty().SetOpacity(0.2)
        # sourceAo.actor.VisibilityOff()

    # iren.Start()
    movie = mabdi.RenderWindowToAvi(renWin,
                                    mabdi_simulate._file_prefix,
                                    fps=fps,
                                    savefig_at_frame=mabdi_simulate._output['movie_savefig_at_frame'])
    for i, (pos, lka) in enumerate(zip(position, lookat)):
        cam.SetPosition(pos)
        cam.SetFocalPoint(lka)
        iren.Render()

    movie.save_movie()

    iren.GetRenderWindow().Finalize()
    iren.TerminateApp()
    del iren, ren, renWin

    return
예제 #3
0
    def __init__(self, mabdi_param=None, sim_param=None, output=None):
        """
        Initialize all the vtkPythonAlgorithms that make up MABDI
        :param sim_param:
          * sim_param['shape'] - default='line' - 'line' 'circle'
          * sim_param['length'] - default=20 - length of sim_param
        :param output:
          * output['movie'] - default=False - Create a movie with
          the scenario view, and depth images after the simulation runs.
        """
        """ Configuration parameters """

        mabdi_param = {} if not mabdi_param else mabdi_param
        mabdi_param.setdefault('depth_image_size', (640, 480))
        mabdi_param.setdefault('farplane_threshold',
                               1.0)  # see FilterDepthImageToSurface
        mabdi_param.setdefault('convolution_threshold',
                               0.01)  # see FilterDepthImageToSurface
        mabdi_param.setdefault('classifier_threshold',
                               0.01)  # see FilterClassifier

        sim_param = {} if not sim_param else sim_param
        sim_param.setdefault('environment_name', 'table')
        sim_param.setdefault('stanford_bunny_nbunnies', 1)
        sim_param.setdefault('dynamic_environment', [
            (-1, -1)
        ])  # values that won't do anything, (frame_number, object_id)
        sim_param.setdefault('dynamic_environment_init_state', None)
        sim_param.setdefault('path_name', 'helix_table_ub')
        sim_param.setdefault('path_nsteps', 20)
        sim_param.setdefault(
            'noise', False
        )  # you can also specify a number instead of a bool, default is 0.002
        sim_param.setdefault('interactive', False)
        self._sim_param = sim_param

        output = {} if not output else output
        output.setdefault('folder_name', None)
        output.setdefault('movie', False)
        output.setdefault('movie_fps', 3)
        output.setdefault('movie_savefig_at_frame', ())
        output.setdefault('source_obs_position', None)
        output.setdefault('source_obs_lookat', None)
        output.setdefault('movie_preflight', False)
        output.setdefault('movie_postflight', False)
        output.setdefault('preflight_nsteps', 30)
        output.setdefault('postflight_nsteps', 30)
        output.setdefault('preflight_fps', 3)
        output.setdefault('postflight_fps', 3)
        output.setdefault('path_flight', 'helix_survey_ub')
        output.setdefault('save_global_mesh', False)
        self._output = output

        self._file_prefix = mabdi.get_file_prefix(output['folder_name'])
        """ Filters and sources (this block is basically the core of MABDI) """

        if sim_param['environment_name'] is 'table':
            self.source = mabdi.SourceEnvironmentTable()
        elif sim_param['environment_name'] is 'stanford_bunny':
            self.source = mabdi.SourceStandfordBunny(
                sim_param['stanford_bunny_nbunnies'])
        self.di = mabdi.FilterDepthImage(
            offscreen=True,
            name='sensor',
            noise=sim_param['noise'],
            depth_image_size=mabdi_param['depth_image_size'])
        self.sdi = mabdi.FilterDepthImage(
            offscreen=True,
            name='simulated sensor',
            depth_image_size=mabdi_param['depth_image_size'])
        self.classifier = mabdi.FilterClassifier()
        self.surf = mabdi.FilterDepthImageToSurface(
            param_farplane_threshold=mabdi_param['farplane_threshold'],
            param_convolution_threshold=mabdi_param['convolution_threshold'])
        self.mesh = mabdi.FilterWorldMesh(color=True)

        self.di.set_polydata(self.source)

        self.sdi.set_polydata_empty(
        )  # because the world mesh hasn't been initialized yet

        self.classifier.AddInputConnection(0, self.di.GetOutputPort())
        self.classifier.AddInputConnection(1, self.sdi.GetOutputPort())

        self.surf.SetInputConnection(self.classifier.GetOutputPort())

        self.mesh.SetInputConnection(self.surf.GetOutputPort())

        self.sdi.set_polydata(self.mesh)

        # get bounds of the source without the floor
        self.source.bounds, self.source.position, self.source.lookat = \
            find_bounds_and_observation_position_lookat(self.source)
        if output['source_obs_position']:
            self.source.position = output['source_obs_position']
        if output['source_obs_lookat']:
            self.source.lookat = output['source_obs_lookat']
        """ Sensor path """

        self.position, self.lookat = \
            create_sensor_path(name=sim_param['path_name'],
                               nsteps=sim_param['path_nsteps'],
                               bounds=self.source.bounds)
        """ Actor objects """

        sourceAo = mabdi.VTKPolyDataActorObjects(self.source)
        sourceAo.actor.GetProperty().SetColor(slate_grey_light)
        sourceAo.actor.GetProperty().SetOpacity(0.2)

        surfAo = mabdi.VTKPolyDataActorObjects(self.surf)
        surfAo.actor.GetProperty().SetColor(red)
        surfAo.actor.GetProperty().SetOpacity(1.0)

        meshAo = mabdi.VTKPolyDataActorObjects(self.mesh)
        meshAo.actor.GetProperty().SetColor(salmon)
        meshAo.actor.GetProperty().SetOpacity(0.5)
        """ Render objects """

        self.renWin = vtk.vtkRenderWindow()
        self.renWin.SetSize(640 * 2, 480 * 1)
        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.renWin)

        # scenario
        renScenario = vtk.vtkRenderer()
        renScenario.SetBackground(eggshell)
        renScenario.SetViewport(0.0 / 2.0, 0.0, 1.0 / 2.0, 1.0)
        add_sensor_visualization(self.di, self.position, renScenario)
        renScenario.AddActor(sourceAo.actor)
        renScenario.AddActor(surfAo.actor)
        renScenario.AddActor(meshAo.actor)
        renScenario.GetActiveCamera().SetPosition(self.source.position)
        renScenario.GetActiveCamera().SetFocalPoint(self.source.lookat)

        # surf
        renSurf = vtk.vtkRenderer()
        renSurf.SetBackground(eggshell)
        renSurf.SetViewport(1.0 / 2.0, 0.0, 2.0 / 2.0, 1.0)
        add_sensor_visualization(self.di, self.position, renSurf)
        renSurf.AddActor(sourceAo.actor)
        renSurf.AddActor(surfAo.actor)
        renSurf.GetActiveCamera().SetPosition(self.source.position)
        renSurf.GetActiveCamera().SetFocalPoint(self.source.lookat)

        self.renWin.AddRenderer(renScenario)
        self.renWin.AddRenderer(renSurf)

        self.iren.Initialize()

        return
예제 #4
0
    def __init__(self,
                 mabdi_param=None,
                 sim_param=None,
                 output=None):
        """
        Initialize all the vtkPythonAlgorithms that make up MABDI
        :param sim_param:
          * sim_param['shape'] - default='line' - 'line' 'circle'
          * sim_param['length'] - default=20 - length of sim_param
        :param output:
          * output['movie'] - default=False - Create a movie with
          the scenario view, and depth images after the simulation runs.
        """

        """ Configuration parameters """

        mabdi_param = {} if not mabdi_param else mabdi_param
        mabdi_param.setdefault('depth_image_size', (640, 480))
        mabdi_param.setdefault('farplane_threshold', 1.0)  # see FilterDepthImageToSurface
        mabdi_param.setdefault('convolution_threshold', 0.01)  # see FilterDepthImageToSurface
        mabdi_param.setdefault('classifier_threshold', 0.01)  # see FilterClassifier

        sim_param = {} if not sim_param else sim_param
        sim_param.setdefault('environment_name', 'table')
        sim_param.setdefault('stanford_bunny_nbunnies', 1)
        sim_param.setdefault('dynamic_environment', [(-1, -1)])  # values that won't do anything, (frame_number, object_id)
        sim_param.setdefault('dynamic_environment_init_state', None)
        sim_param.setdefault('path_name', 'helix_table_ub')
        sim_param.setdefault('path_nsteps', 20)
        sim_param.setdefault('noise', False)  # you can also specify a number instead of a bool, default is 0.002
        sim_param.setdefault('interactive', False)
        self._sim_param = sim_param

        output = {} if not output else output
        output.setdefault('folder_name', None)
        output.setdefault('movie', False)
        output.setdefault('movie_fps', 3)
        output.setdefault('movie_savefig_at_frame', ())
        output.setdefault('source_obs_position', None)
        output.setdefault('source_obs_lookat', None)
        output.setdefault('movie_preflight', False)
        output.setdefault('movie_postflight', False)
        output.setdefault('preflight_nsteps', 30)
        output.setdefault('postflight_nsteps', 30)
        output.setdefault('preflight_fps', 3)
        output.setdefault('postflight_fps', 3)
        output.setdefault('path_flight', 'helix_survey_ub')
        output.setdefault('save_global_mesh', False)
        self._output = output

        self._file_prefix = mabdi.get_file_prefix(output['folder_name'])

        """ Filters and sources (this block is basically the core of MABDI) """

        if sim_param['environment_name'] is 'table':
            self.source = mabdi.SourceEnvironmentTable()
        elif sim_param['environment_name'] is 'stanford_bunny':
            self.source = mabdi.SourceStandfordBunny(sim_param['stanford_bunny_nbunnies'])
        self.di = mabdi.FilterDepthImage(offscreen=True,
                                         name='sensor',
                                         noise=sim_param['noise'],
                                         depth_image_size=mabdi_param['depth_image_size'])
        self.sdi = mabdi.FilterDepthImage(offscreen=True,
                                          name='simulated sensor',
                                          depth_image_size=mabdi_param['depth_image_size'])
        self.classifier = mabdi.FilterClassifier()
        self.surf = mabdi.FilterDepthImageToSurface(
            param_farplane_threshold=mabdi_param['farplane_threshold'],
            param_convolution_threshold=mabdi_param['convolution_threshold'])
        self.mesh = mabdi.FilterWorldMesh(color=True)

        self.di.set_polydata(self.source)

        self.sdi.set_polydata_empty()  # because the world mesh hasn't been initialized yet

        self.classifier.AddInputConnection(0, self.di.GetOutputPort())
        self.classifier.AddInputConnection(1, self.sdi.GetOutputPort())

        self.surf.SetInputConnection(self.classifier.GetOutputPort())

        self.mesh.SetInputConnection(self.surf.GetOutputPort())

        self.sdi.set_polydata(self.mesh)

        # get bounds of the source without the floor
        self.source.bounds, self.source.position, self.source.lookat = \
            find_bounds_and_observation_position_lookat(self.source)
        if output['source_obs_position']:
            self.source.position = output['source_obs_position']
        if output['source_obs_lookat']:
            self.source.lookat = output['source_obs_lookat']

        """ Sensor path """

        self.position, self.lookat = \
            create_sensor_path(name=sim_param['path_name'],
                               nsteps=sim_param['path_nsteps'],
                               bounds=self.source.bounds)

        """ Actor objects """

        sourceAo = mabdi.VTKPolyDataActorObjects(self.source)
        sourceAo.actor.GetProperty().SetColor(slate_grey_light)
        sourceAo.actor.GetProperty().SetOpacity(0.2)

        surfAo = mabdi.VTKPolyDataActorObjects(self.surf)
        surfAo.actor.GetProperty().SetColor(red)
        surfAo.actor.GetProperty().SetOpacity(1.0)

        meshAo = mabdi.VTKPolyDataActorObjects(self.mesh)
        meshAo.actor.GetProperty().SetColor(salmon)
        meshAo.actor.GetProperty().SetOpacity(0.5)

        """ Render objects """

        self.renWin = vtk.vtkRenderWindow()
        self.renWin.SetSize(640 * 2, 480 * 1)
        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.renWin)

        # scenario
        renScenario = vtk.vtkRenderer()
        renScenario.SetBackground(eggshell)
        renScenario.SetViewport(0.0 / 2.0, 0.0, 1.0 / 2.0, 1.0)
        add_sensor_visualization(self.di, self.position, renScenario)
        renScenario.AddActor(sourceAo.actor)
        renScenario.AddActor(surfAo.actor)
        renScenario.AddActor(meshAo.actor)
        renScenario.GetActiveCamera().SetPosition(self.source.position)
        renScenario.GetActiveCamera().SetFocalPoint(self.source.lookat)

        # surf
        renSurf = vtk.vtkRenderer()
        renSurf.SetBackground(eggshell)
        renSurf.SetViewport(1.0 / 2.0, 0.0, 2.0 / 2.0, 1.0)
        add_sensor_visualization(self.di, self.position, renSurf)
        renSurf.AddActor(sourceAo.actor)
        renSurf.AddActor(surfAo.actor)
        renSurf.GetActiveCamera().SetPosition(self.source.position)
        renSurf.GetActiveCamera().SetFocalPoint(self.source.lookat)

        self.renWin.AddRenderer(renScenario)
        self.renWin.AddRenderer(renSurf)

        self.iren.Initialize()

        return