コード例 #1
0
 def view_mesh_features(self, feature_idx=0):
     tmp_mesh = vtk_deep_copy(self.vtk_mesh)
     tmp_mesh.GetPointData().SetScalars(
         numpy_to_vtk(
             np.ascontiguousarray((self.node_features[feature_idx]))))
     plotter = Viewer(geometries=[tmp_mesh])
     return plotter
コード例 #2
0
 def view_aligned_smoothed_spectral_coords(self):
     plotter = Viewer(
         point_sets=[
             self.smoothed_target_coords, self.source_projected_on_target
         ],
         point_set_colors=[colors.to_rgb('C0'),
                           colors.to_rgb('C1')])
     return plotter
コード例 #3
0
    def show(self,
             ui_collapsed=True,
             rotate=False,
             show_bounds=False,
             **kwargs):
        """Show itkwidgets plotter in cell output.

        Parameters
        ----------
        ui_collapsed : bool, optional
            Plot with the user interface collapsed.  UI can be enabled
            when plotting.  Default ``False``.

        rotate : bool, optional
            Rotate the camera around the scene.  Default ``False``.
            Appears to be computationally intensive.

        show_bounds : bool, optional
            Show the bounding box.  Default False

        point_size : int, optional
            Size of the points displayed in the

        Returns
        --------
        viewer : itkwidgets.Viewer
            ``ITKwidgets`` viewer.
        """
        if self._background_color is not None:
            kwargs.setdefault('background', self._background_color)
        if self._camera_position is not None:
            kwargs.setdefault('camera', self._camera_position)

        from itkwidgets import Viewer
        viewer = Viewer(
            geometries=self._geometries,
            geometry_colors=self._geometry_colors,
            geometry_opacities=self._geometry_opacities,
            point_set_colors=self._point_set_colors,
            point_sets=self._point_sets,
            point_set_sizes=self._point_set_sizes,
            point_set_representations=self._point_set_representations,
            ui_collapsed=ui_collapsed,
            rotate=rotate,
            axes=show_bounds,
            **kwargs)

        # always show if iPython is installed
        try:
            from IPython import display
            display.display_html(viewer)
        except ImportError:
            pass

        return viewer
コード例 #4
0
 def show(self, ui_collapsed=False):
     """Show in cell output."""
     plotter = Viewer(geometries=self._geometries,
                      geometry_colors=self._geometry_colors,
                      geometry_opacities=self._geometry_opacities,
                      point_set_colors=self._point_set_colors,
                      point_sets=self._point_sets,
                      ui_collapsed=ui_collapsed,
                      actors=self._actors,
                      cmap=self._cmap)
     return plotter
コード例 #5
0
    def view_aligned_spectral_coords(self,
                                     starting_spectral_coord=0,
                                     point_set_representations=['spheres'],
                                     point_set_colors=None,
                                     include_target_coordinates=True,
                                     include_non_rigid_aligned=True,
                                     include_rigid_aligned=False,
                                     include_unaligned=False,
                                     upscale_factor=10.):

        point_sets = []

        if include_target_coordinates is True:
            point_sets.append(upscale_factor * np.ascontiguousarray(
                self.target_spectral_coords[:, starting_spectral_coord:
                                            starting_spectral_coord + 3]))

        if include_unaligned is True:
            point_sets.append(upscale_factor * np.ascontiguousarray(
                self.source_spectral_coords_b4_reg[:, starting_spectral_coord:
                                                   starting_spectral_coord +
                                                   3]))

        if include_rigid_aligned is True:
            point_sets.append(upscale_factor * np.ascontiguousarray(
                self.
                source_spectral_coords_after_rigid[:, starting_spectral_coord:
                                                   starting_spectral_coord +
                                                   3]))

        if include_non_rigid_aligned is True:
            point_sets.append(upscale_factor * np.ascontiguousarray(
                self.source_spectral_coords[:, starting_spectral_coord:
                                            starting_spectral_coord + 3]))

        # Make all the same shape, if only one specified and more than one point et included.
        if (len(point_set_representations) == 1) & (len(point_sets) > 1):
            point_set_representations = point_set_representations * len(
                point_sets)

        # Colours points sets sequentially using matplotlib V2 colours:
        if point_set_colors is None:
            point_set_colors = [
                colors.to_rgb('C{}'.format(x)) for x in range(len(point_sets))
            ]
        plotter = Viewer(point_sets=point_sets,
                         point_set_representations=point_set_representations,
                         point_set_colors=point_set_colors)

        return plotter
コード例 #6
0
    def view_meshes(self,
                    include_target=True,
                    include_source=True,
                    include_transformed_target=False,
                    include_average=False,
                    shadow=True):
        geometries = []
        if include_target is True:
            geometries.append(self.graph_target.vtk_mesh)
        if include_source is True:
            geometries.append(self.graph_source.vtk_mesh)
        if include_transformed_target is True:
            if self.weighted_avg_transformed_mesh is not None:
                geometries.append(self.weighted_avg_transformed_mesh)
            elif self.nearest_neighbour_transformed_mesh is not None:
                geometries.append(self.nearest_neighbour_transformed_mesh)
            elif self.weighted_avg_transformed_points is not None:
                self.get_weighted_final_node_locations()
                self.get_source_mesh_transformed_weighted_avg()
                geometries.append(self.weighted_avg_transformed_mesh)
            elif self.nearest_neighbor_transformed_points is not None:
                self.get_nearest_neighbour_final_node_locations()
                self.get_source_mesh_transformed_nearest_neighbour()
                geometries.append(self.nearest_neighbour_transformed_mesh)
            else:
                raise Exception(
                    'No corresponding points or meshes calculated. Try running: \n'
                    'reg.get_weighted_final_node_locations()\n'
                    'reg.get_nearest_neighbour_final_node_locations()\n'
                    'or try re-running with the flags: \n'
                    'return_average_final_points=True & return_transformed_mesh=True'
                )
        if include_average is True:
            if self.average_mesh is None:
                if self.weighted_avg_transformed_points is not None:
                    self.get_average_shape()
                elif self.nearest_neighbor_transformed_points is not None:
                    self.get_average_shape(align_type='nearest')
                else:
                    raise Exception(
                        "No xyz correspondences calculated can't get average! Try:\n"
                        "`reg.get_weighted_final_node_locations` or `reg.get_nearest_neighbour_final_node_locations`"
                    )
            geometries.append(self.average_mesh)

        plotter = Viewer(geometries=geometries, shadow=shadow)
        return plotter
コード例 #7
0
    def view_meshes_colored_by_spectral_correspondences(
            self,
            x_translation=100,
            y_translation=0,
            z_translation=0,
            shadow=True):
        target_mesh = vtk_deep_copy(self.graph_target.vtk_mesh)
        target_mesh.GetPointData().SetScalars(
            numpy_to_vtk(np.arange(self.graph_target.n_points)))

        source_mesh = vtk_deep_copy(self.graph_source.vtk_mesh)
        source_mesh.GetPointData().SetScalars(
            numpy_to_vtk(self.corresponding_target_idx_for_each_source_pt))

        target_transform = vtk.vtkTransform()
        target_transform.Translate(x_translation, y_translation, z_translation)
        target_mesh = apply_transform(target_mesh, target_transform)

        plotter = Viewer(geometries=[source_mesh, target_mesh], shadow=shadow)
        return plotter
コード例 #8
0
    def show(self, ui_collapsed=False):
        """Show itkwidgets plotter in cell output.

        Parameters
        ----------
        ui_collapsed : bool, optional
            Plot with the user interface collapsed.  UI can be enabled
            when plotting.  Default False.

        Returns
        --------
        plotter : itkwidgets.Viewer
            ITKwidgets viewer.
        """
        plotter = Viewer(geometries=self._geometries,
                         geometry_colors=self._geometry_colors,
                         geometry_opacities=self._geometry_opacities,
                         point_set_colors=self._point_set_colors,
                         point_sets=self._point_sets,
                         ui_collapsed=ui_collapsed,
                         actors=self._actors)
        return plotter
コード例 #9
0
 def view_mesh_eig_vec(self, eig_vec=0):
     tmp_mesh = vtk_deep_copy(self.vtk_mesh)
     tmp_mesh.GetPointData().SetScalars(
         numpy_to_vtk(np.ascontiguousarray(self.eig_vecs[:, eig_vec])))
     plotter = Viewer(geometries=[tmp_mesh])
     return plotter
コード例 #10
0
 def view_mesh_existing_scalars(self):
     plotter = Viewer(geometries=[self.vtk_mesh])
     return plotter