def update_rt(self, all_rt):
        """
        Update position of the RotoTrans on the screen (but do not repaint)
        Parameters
        ----------
        all_rt : RotoTransCollection
            One frame of all RotoTrans to draw

        """
        if isinstance(all_rt, RotoTrans):
            rt_tp = RotoTransCollection()
            rt_tp.append(all_rt[:, :])
            all_rt = rt_tp

        if all_rt.get_num_rt() != self.n_rt:
            self.new_rt_set(all_rt)
            return  # Prevent calling update_rt recursively

        if not isinstance(all_rt, RotoTransCollection):
            raise TypeError("Please send a list of rt to new_rt_set")

        self.all_rt = all_rt

        for i, rt in enumerate(self.all_rt):
            if rt.get_num_frames() != 1:
                raise IndexError("RT should be from one frame only")

            # Update the end points of the axes and the origin
            pts = vtkPoints()
            pts.InsertNextPoint(rt.translation())
            pts.InsertNextPoint(rt.translation() +
                                rt[0:3, 0, :] * self.rt_length)
            pts.InsertNextPoint(rt.translation() +
                                rt[0:3, 1, :] * self.rt_length)
            pts.InsertNextPoint(rt.translation() +
                                rt[0:3, 2, :] * self.rt_length)

            # Update polydata in mapper
            lines_poly_data = self.rt_actors[i].GetMapper().GetInput()
            lines_poly_data.SetPoints(pts)
Exemple #2
0
    def __init__(self, parent,
                 markers_size=5, markers_color=(1, 1, 1), markers_opacity=1.0,
                 rt_size=25):
        """
        Creates a model that will holds things to plot
        Parameters
        ----------
        parent
            Parent of the Model window
        markers_size : float
            Size the markers should be drawn
        markers_color : Tuple(int)
            Color the markers should be drawn (1 is max brightness)
        markers_opacity : float
            Opacity of the markers (0.0 is completely transparent, 1.0 completely opaque)
        rt_size : int
            Length of the axes of the system of axes
        """
        QtWidgets.QWidget.__init__(self, parent)
        self.parent_window = parent

        palette = QPalette()
        palette.setColor(self.backgroundRole(), QColor(255, 255, 255))
        self.setAutoFillBackground(True)
        self.setPalette(palette)

        self.markers = Markers3d()
        self.markers_size = markers_size
        self.markers_color = markers_color
        self.markers_opacity = markers_opacity
        self.markers_actors = list()

        self.all_rt = RotoTransCollection()
        self.n_rt = 0
        self.rt_size = rt_size
        self.rt_actors = list()
        self.parent_window.should_reset_camera = True

        self.all_meshes = MeshCollection()
        self.mesh_actors = list()
    def new_rt_set(self, all_rt):
        """
        Define a new rt set. This function must be called each time the number of rt change
        Parameters
        ----------
        all_rt : RotoTransCollection
            One frame of all RotoTrans to draw

        """
        if isinstance(all_rt, RotoTrans):
            rt_tp = RotoTransCollection()
            rt_tp.append(all_rt[:, :])
            all_rt = rt_tp

        if not isinstance(all_rt, RotoTransCollection):
            raise TypeError("Please send a list of rt to new_rt_set")

        # Remove previous actors from the scene
        for actor in self.rt_actors:
            self.parent_window.ren.RemoveActor(actor)
        self.rt_actors = list()

        for i, rt in enumerate(all_rt):
            if rt.get_num_frames() != 1:
                raise IndexError("RT should be from one frame only")

            # Create the polyline which will hold the actors
            lines_poly_data = vtkPolyData()

            # Create four points of a generic system of axes
            pts = vtkPoints()
            pts.InsertNextPoint([0, 0, 0])
            pts.InsertNextPoint([1, 0, 0])
            pts.InsertNextPoint([0, 1, 0])
            pts.InsertNextPoint([0, 0, 1])
            lines_poly_data.SetPoints(pts)

            # Create the first line(between Origin and P0)
            line0 = vtkLine()
            line0.GetPointIds().SetId(0, 0)
            line0.GetPointIds().SetId(1, 1)

            # Create the second line(between Origin and P1)
            line1 = vtkLine()
            line1.GetPointIds().SetId(0, 0)
            line1.GetPointIds().SetId(1, 2)

            # Create the second line(between Origin and P1)
            line2 = vtkLine()
            line2.GetPointIds().SetId(0, 0)
            line2.GetPointIds().SetId(1, 3)

            # Create a vtkCellArray container and store the lines in it
            lines = vtkCellArray()
            lines.InsertNextCell(line0)
            lines.InsertNextCell(line1)
            lines.InsertNextCell(line2)

            # Add the lines to the polydata container
            lines_poly_data.SetLines(lines)

            # Create a vtkUnsignedCharArray container and store the colors in it
            colors = vtkUnsignedCharArray()
            colors.SetNumberOfComponents(3)
            colors.InsertNextTuple([255, 0, 0])
            colors.InsertNextTuple([0, 255, 0])
            colors.InsertNextTuple([0, 0, 255])
            lines_poly_data.GetCellData().SetScalars(colors)

            # Create a mapper
            mapper = vtkPolyDataMapper()
            mapper.SetInputData(lines_poly_data)

            # Create an actor
            self.rt_actors.append(vtkActor())
            self.rt_actors[i].SetMapper(mapper)
            self.rt_actors[i].GetProperty().SetLineWidth(self.rt_width)

            self.parent_window.ren.AddActor(self.rt_actors[i])
            self.parent_window.ren.ResetCamera()

        # Set rt orientations
        self.n_rt = all_rt.get_num_rt()
        self.update_rt(all_rt)
    def __init__(self,
                 parent,
                 markers_size=0.010,
                 markers_color=(1, 1, 1),
                 markers_opacity=1.0,
                 global_ref_frame_length=0.15,
                 global_ref_frame_width=5,
                 global_center_of_mass_size=0.0075,
                 global_center_of_mass_color=(0, 0, 0),
                 global_center_of_mass_opacity=1.0,
                 segments_center_of_mass_size=0.005,
                 segments_center_of_mass_color=(0, 0, 0),
                 segments_center_of_mass_opacity=1.0,
                 mesh_color=(0, 0, 0),
                 mesh_opacity=1.0,
                 muscle_color=(150 / 255, 15 / 255, 15 / 255),
                 muscle_opacity=1.0,
                 rt_length=0.1,
                 rt_width=2):
        """
        Creates a model that will holds things to plot
        Parameters
        ----------
        parent
            Parent of the Model window
        markers_size : float
            Size the markers should be drawn
        markers_color : Tuple(int)
            Color the markers should be drawn (1 is max brightness)
        markers_opacity : float
            Opacity of the markers (0.0 is completely transparent, 1.0 completely opaque)
        rt_length : int
            Length of the axes of the system of axes
        """
        QtWidgets.QWidget.__init__(self, parent)
        self.parent_window = parent

        palette = QPalette()
        palette.setColor(self.backgroundRole(), QColor(255, 255, 255))
        self.setAutoFillBackground(True)
        self.setPalette(palette)

        self.markers = Markers3d()
        self.markers_size = markers_size
        self.markers_color = markers_color
        self.markers_opacity = markers_opacity
        self.markers_actors = list()

        self.has_global_ref_frame = False
        self.global_ref_frame_length = global_ref_frame_length
        self.global_ref_frame_width = global_ref_frame_width

        self.global_center_of_mass = Markers3d()
        self.global_center_of_mass_size = global_center_of_mass_size
        self.global_center_of_mass_color = global_center_of_mass_color
        self.global_center_of_mass_opacity = global_center_of_mass_opacity
        self.global_center_of_mass_actors = list()

        self.segments_center_of_mass = Markers3d()
        self.segments_center_of_mass_size = segments_center_of_mass_size
        self.segments_center_of_mass_color = segments_center_of_mass_color
        self.segments_center_of_mass_opacity = segments_center_of_mass_opacity
        self.segments_center_of_mass_actors = list()

        self.all_rt = RotoTransCollection()
        self.n_rt = 0
        self.rt_length = rt_length
        self.rt_width = rt_width
        self.rt_actors = list()
        self.parent_window.should_reset_camera = True

        self.all_meshes = MeshCollection()
        self.mesh_color = mesh_color
        self.mesh_opacity = mesh_opacity
        self.mesh_actors = list()

        self.all_muscles = MeshCollection()
        self.muscle_color = muscle_color
        self.muscle_opacity = muscle_opacity
        self.muscle_actors = list()
Exemple #5
0
# mean of first 3 markers in c3d file
d5 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0], [1], [2]], prefix=':')

# Create a windows with a nice gray background
vtkWindow = VtkWindow(background_color=(.5, .5, .5))

# Add marker holders to the window
vtkModelReal = VtkModel(vtkWindow, markers_color=(1, 0, 0), markers_size=10.0, markers_opacity=1)
vtkModelPred = VtkModel(vtkWindow, markers_color=(0, 0, 0), markers_size=10.0, markers_opacity=.5)
vtkModelMid = VtkModel(vtkWindow, markers_color=(0, 0, 1), markers_size=10.0, markers_opacity=.5)
vtkModelByNames = VtkModel(vtkWindow, markers_color=(0, 1, 1), markers_size=10.0, markers_opacity=.5)
vtkModelFromC3d = VtkModel(vtkWindow, markers_color=(0, 1, 0), markers_size=10.0, markers_opacity=.5)

# Create some RotoTrans attached to the first model
all_rt_real = RotoTransCollection()
all_rt_real.append(RotoTrans(angles=[0, 0, 0], angle_sequence="yxz", translations=d[:, 0, 0]))
all_rt_real.append(RotoTrans(angles=[0, 0, 0], angle_sequence="yxz", translations=d[:, 0, 0]))

# Create some RotoTrans attached to the second model
one_rt = RotoTrans.define_axes(d, [3, 5], [[4, 3], [4, 5]], "zx", "z", [3, 4, 5])

# Create some mesh (could be from any mesh source)
meshes = MeshCollection()
meshes.append(Mesh(vertex=d, triangles=[[0, 1, 5], [0, 1, 6]]))

# Animate all this
i = 0
while vtkWindow.is_active:
    # Update markers
    if i < 100:
Exemple #6
0
                        markers_opacity=.5)
vtkModelMid = VtkModel(vtkWindow,
                       markers_color=(0, 0, 1),
                       markers_size=10.0,
                       markers_opacity=.5)
vtkModelByNames = VtkModel(vtkWindow,
                           markers_color=(0, 1, 1),
                           markers_size=10.0,
                           markers_opacity=.5)
vtkModelFromC3d = VtkModel(vtkWindow,
                           markers_color=(0, 1, 0),
                           markers_size=10.0,
                           markers_opacity=.5)

# Create some RotoTrans attached to the first model
all_rt_real = RotoTransCollection()
all_rt_real.append(
    RotoTrans(angles=FrameDependentNpArray(np.zeros((3, 1, 1))),
              angle_sequence="yxz",
              translations=d[:, 0, 0:1]))
all_rt_real.append(
    RotoTrans(angles=FrameDependentNpArray(np.zeros((3, 1, 1))),
              angle_sequence="yxz",
              translations=d[:, 0, 0:1]))

# Create some RotoTrans attached to the second model
one_rt = RotoTrans.define_axes(d, [3, 5], [[4, 3], [4, 5]], "zx", "z",
                               [3, 4, 5])

# Create some mesh (could be from any mesh source)
meshes = MeshCollection()