Example #1
0
    def create_coordinate_system(self,
                                 coord_id: int,
                                 dim_max: float,
                                 label: str = '',
                                 origin=None,
                                 matrix_3x3=None,
                                 coord_type: str = 'xyz'):
        """
        Creates a coordinate system

        Parameters
        ----------
        coord_id : int
            the coordinate system id
        dim_max : float
            the max model dimension; 10% of the max will be used for the coord length
        label : str
            the coord id or other unique label (default is empty to indicate the global frame)
        origin : (3, ) ndarray/list/tuple
            the origin
        matrix_3x3 : (3, 3) ndarray
            a standard Nastran-style coordinate system
        coord_type : str
            a string of 'xyz', 'Rtz', 'Rtp' (xyz, cylindrical, spherical)
            that changes the axis names

        .. todo::  coord_type is not supported ('xyz' ONLY)
        .. todo::  Can only set one coordinate system

        .. seealso::
            http://en.wikipedia.org/wiki/Homogeneous_coordinates
            http://www3.cs.stonybrook.edu/~qin/courses/graphics/camera-coordinate-system.pdf
            http://www.vtk.org/doc/nightly/html/classvtkTransform.html#ad58b847446d791391e32441b98eff151

        """
        self.settings.dim_max = dim_max
        scale = self.settings.coord_scale * dim_max

        transform = make_vtk_transform(origin, matrix_3x3)

        create_actor = True
        if coord_id in self.gui.axes:
            axes = self.gui.axes[coord_id]
            create_actor = False
        else:
            axes = vtk.vtkAxesActor()
            axes.DragableOff()
            axes.PickableOff()

        #axes.GetLength() # pi
        #axes.GetNormalizedShaftLength() # (0.8, 0.8, 0.8)
        #axes.GetNormalizedTipLength() # (0.2, 0.2, 0.2)
        #axes.GetOrigin() # (0., 0., 0.)
        #axes.GetScale() # (1., 1., 1.)
        #axes.GetShaftType() # 1
        #axes.GetTotalLength() # (1., 1., 1.)

        axes.SetUserTransform(transform)
        axes.SetTotalLength(scale, scale, scale)
        if coord_type == 'xyz':
            if label:
                xlabel = u'x%s' % label
                ylabel = u'y%s' % label
                zlabel = u'z%s' % label
                axes.SetXAxisLabelText(xlabel)
                axes.SetYAxisLabelText(ylabel)
                axes.SetZAxisLabelText(zlabel)
        else:
            if coord_type == 'Rtz':  # cylindrical
                y = u'θ'
                x = 'R'
                z = 'z'
                if font_file:
                    #xprop = axes.GetXAxisCaptionActor2D().GetCaptionTextProperty()
                    yprop = axes.GetYAxisCaptionActor2D(
                    ).GetCaptionTextProperty()
                    #zprop = axes.GetZAxisCaptionActor2D().GetCaptionTextProperty()
                    set_vtk_property_to_unicode(yprop, font_file)
                else:
                    y = 't'

            elif coord_type == 'Rtp':  # spherical
                x = 'R'
                y = u'θ'
                z = u'Φ'
                if font_file:
                    #xprop = axes.GetXAxisCaptionActor2D().GetCaptionTextProperty()
                    yprop = axes.GetYAxisCaptionActor2D(
                    ).GetCaptionTextProperty()
                    zprop = axes.GetZAxisCaptionActor2D(
                    ).GetCaptionTextProperty()
                    set_vtk_property_to_unicode(yprop, font_file)
                    set_vtk_property_to_unicode(zprop, font_file)
                else:
                    y = 't'
                    z = 'p'
            else:  # pragma: no cover
                raise RuntimeError('invalid axis type; coord_type=%r' %
                                   coord_type)

            xlabel = '%s%s' % (x, label)
            ylabel = '%s%s' % (y, label)
            zlabel = '%s%s' % (z, label)
            axes.SetXAxisLabelText(xlabel)
            axes.SetYAxisLabelText(ylabel)
            axes.SetZAxisLabelText(zlabel)

        self.gui.transform[coord_id] = transform
        self.gui.axes[coord_id] = axes

        is_visible = False
        if label == '':
            label = 'Global XYZ'
            is_visible = True
        else:
            label = 'Coord %s' % label
        self.gui.geometry_properties[label] = CoordProperties(
            label, coord_type, is_visible, scale)
        self.gui.geometry_actors[label] = axes
        if create_actor:
            self.rend.AddActor(axes)
Example #2
0
    def create_coordinate_system(self,
                                 coord_id: int,
                                 dim_max: float,
                                 label: str = '',
                                 origin=None,
                                 matrix_3x3=None,
                                 coord_type: str = 'xyz') -> None:
        """
        Creates a coordinate system

        Parameters
        ----------
        coord_id : int
            the coordinate system id
        dim_max : float
            the max model dimension; 10% of the max will be used for the coord length
        label : str
            the coord id or other unique label (default is empty to indicate the global frame)
        origin : (3, ) ndarray/list/tuple
            the origin
        matrix_3x3 : (3, 3) ndarray
            a standard Nastran-style coordinate system
        coord_type : str
            a string of 'xyz', 'Rtz', 'Rtp' (xyz, cylindrical, spherical)
            that changes the axis names

        .. todo::  coord_type is not supported ('xyz' ONLY)
        .. todo::  Can only set one coordinate system

        .. seealso::
            http://en.wikipedia.org/wiki/Homogeneous_coordinates
            http://www3.cs.stonybrook.edu/~qin/courses/graphics/camera-coordinate-system.pdf
            http://www.vtk.org/doc/nightly/html/classvtkTransform.html#ad58b847446d791391e32441b98eff151

        """
        self.settings.dim_max = dim_max
        coord_scale = self.settings.coord_scale * dim_max
        coord_text_scale = self.settings.coord_text_scale
        linewidth = self.settings.coord_linewidth

        create_actor = True
        if coord_id in self.gui.axes:
            axes = self.gui.axes[coord_id]
            create_actor = False
        else:
            axes = vtk.vtkAxesActor()
            axes.DragableOff()
            axes.PickableOff()

        transform = make_vtk_transform(origin, matrix_3x3)
        _set_base_axes(axes, transform, coord_type, label, coord_scale,
                       coord_text_scale, linewidth)

        self.gui.transform[coord_id] = transform
        self.gui.axes[coord_id] = axes

        is_visible = False
        if label == '':
            label = 'Global XYZ'
            is_visible = True
        else:
            label = 'Coord %s' % label
        self.gui.geometry_properties[label] = CoordProperties(
            label, coord_type, is_visible, coord_scale)
        self.gui.geometry_actors[label] = axes
        if create_actor:
            self.rend.AddActor(axes)