예제 #1
0
    def __init__(self, X=sva.PTransformd.Identity(), length=0.1, text=''):
        """
    Create a 3D axis.
    """
        self._X = X
        self.axesActor = tvtk.AxesActor(total_length=(length, ) * 3,
                                        axis_labels=False)
        self.axesActor.user_transform = tvtk.Transform()

        textSource = tvtk.TextSource(text=text, backing=False)
        # textPdm = tvtk.PolyDataMapper(input=textSource.output)
        textPdm = tvtk.PolyDataMapper()

        # https://stackoverflow.com/questions/35089379/how-to-fix-traiterror-the-input-trait-of-a-instance-is-read-only
        # configure_input_data(textPdm, textSource.output_port)

        # https://github.com/enthought/mayavi/issues/521
        textPdm.input_connection = textSource.output_port

        #self.textActor = tvtk.Actor(mapper=textPdm)
        self.textActor = tvtk.Follower(mapper=textPdm)
        # take the maximum component of the bound and use it to scale it
        m = max(self.textActor.bounds)
        scale = length / m
        self.textActor.scale = (scale, ) * 3
        # TODO compute the origin well...
        self.textActor.origin = (
            -(self.textActor.bounds[0] + self.textActor.bounds[1]) / 2.,
            -(self.textActor.bounds[2] + self.textActor.bounds[3]) / 2.,
            -(self.textActor.bounds[4] + self.textActor.bounds[5]) / 2.,
        )
        ySize = self.textActor.bounds[3] * 1.2
        self.X_text = sva.PTransformd(e.Vector3d(0., -ySize, 0.))
        self._transform()
예제 #2
0
    def __init__(self, X=sva.PTransformd.Identity(), length=0.1, text=''):
        """
    Create a 3D axis.
    """
        self._X = X
        self.axesActor = tvtk.AxesActor(total_length=(length, ) * 3,
                                        axis_labels=False)
        self.axesActor.user_transform = tvtk.Transform()

        textSource = tvtk.TextSource(text=text, backing=False)
        textPdm = tvtk.PolyDataMapper(input=textSource.output)
        #self.textActor = tvtk.Actor(mapper=textPdm)
        self.textActor = tvtk.Follower(mapper=textPdm)
        # take the maximum component of the bound and use it to scale it
        m = max(self.textActor.bounds)
        scale = length / m
        self.textActor.scale = (scale, ) * 3
        # TODO compute the origin well...
        self.textActor.origin = (
            -(self.textActor.bounds[0] + self.textActor.bounds[1]) / 2.,
            -(self.textActor.bounds[2] + self.textActor.bounds[3]) / 2.,
            -(self.textActor.bounds[4] + self.textActor.bounds[5]) / 2.,
        )
        ySize = self.textActor.bounds[3] * 1.2
        self.X_text = sva.PTransformd(e.Vector3d(0., -ySize, 0.))
        self._transform()
예제 #3
0
    def setup_pipeline(self):
        """Override this method so that it *creates* the tvtk
        pipeline.

        This method is invoked when the object is initialized via
        `__init__`.  Note that at the time this method is called, the
        tvtk data pipeline will *not* yet be setup.  So upstream data
        will not be available.  The idea is that you simply create the
        basic objects and setup those parts of the pipeline not
        dependent on upstream sources and filters.  You should also
        set the `actors` attribute up at this point.
        """
        # Setup the default objects.
        self.axes = tvtk.AxesActor(normalized_tip_length=(0.4, 0.4, 0.4),
                                   normalized_shaft_length=(0.6, 0.6, 0.6),
                                   shaft_type='cylinder')
        self.text_property.set(color=(1,1,1), shadow=False, italic=False)

        self.marker = tvtk.OrientationMarkerWidget(key_press_activation=False)
예제 #4
0
def main():

    print ''
    print '1. Format of surface families should be [[a1, b1, c1], [a2, b2, c2],...,[an, bn, cn]], n >= 1.'
    print '2. Distance between the center of the polyhedron and the surface should be positive.'
    print '3. Color (r, g, b) is represented by the number from 0 to 1.'
    print ''
    hkl = surface_index()  # surface family
    print ''
    surf_dist = surface_distance(hkl)  # distance
    print ''
    surf_color = surface_color(hkl)  # surface color
    print 'surface_color', surf_color
    print ''
    planes, number_planes = crystal_plane(hkl)
    ps_setd_mingled(number_planes, planes, surf_dist)
    diameter = 20.0
    volume = 4.0 / 3.0 * np.pi * (diameter * 0.5)**3
    qfp = enclose_polyhedron(number_planes, planes, volume)
    p1 = tvtk.PolyData()
    n_planes = len(qfp[2])
    for i in np.arange(len(number_planes)):
        for surf_index in np.arange(sum(number_planes[0:i]),
                                    sum(number_planes[0:i + 1])):
            print 'surf_index', surf_index
            p1.points = qfp[2][
                surf_index]  # the coordinates of the intersection of each plane.
            faces = crystal_surface(qfp[2][surf_index])
            cells = tvtk.CellArray(
            )  # create a new CellArray object to assign the polys property.
            cells.set_cells(
                1, faces
            )  # the first parameter is the number of faces (here is 1),
            p1.polys = cells  # and the second parameter is an array describing the composition of each face.
            p1.point_data.scalars = np.linspace(0.0, 1.0, len(p1.points))
            mlab.figure(number_planes, fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
            mlab.pipeline.surface(p1,
                                  representation='surface',
                                  opacity=1.0,
                                  color=surf_color[i])
        axe = tvtk.AxesActor(total_length=(3, 3, 3))
    mlab.show()
예제 #5
0
def axes_actor(scale=0.05):
    axes_actor = tvtk.AxesActor(axis_labels=False)
    axes_actor.total_length = (scale, scale, scale)
    return axes_actor
        p1.points = qfp[2][
            i]  # the coordinates of the intersection of each plane.
        n_points = len(qfp[2][i])
        if n_points == 3:
            faces = [n_points, 0, 1, 2]
            plot3d_surfaces(f, val, hkl, faces, 1)
        if n_points == 4:
            faces = [n_points, 0, 1, 2, 3]
            plot3d_surfaces(f, val, hkl, faces, 1)
        if n_points == 5:
            faces = [n_points, 0, 1, 2, 3, 4]
            plot3d_surfaces(f, val, hkl, faces, 1)
        if n_points == 6:
            faces = [n_points, 0, 1, 2, 3, 4, 5]
            plot3d_surfaces(f, val, hkl, faces, 1)
        if n_points == 7:
            faces = [n_points, 0, 1, 2, 3, 4, 5, 6]
            plot3d_surfaces(f, val, hkl, faces, 1)
        if n_points == 8:
            faces = [n_points, 0, 1, 2, 3, 4, 5, 6, 7]
            plot3d_surfaces(f, val, hkl, faces, 1)
        if n_points == 12:
            faces = [n_points, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
            plot3d_surfaces(f, val, hkl, faces, 1)

        elif len(qfp[2][i]) > 12:
            print "The planes have more than 12 intersection points.", len(
                qfp[2][i])
        axe = tvtk.AxesActor(total_length=(3, 3, 3))
    mlab.show()