Ejemplo n.º 1
0
 def _slab_default(self):
     top = tvtk.ClipPolyData(
         clip_function=self.planes[0],
         inside_out=1,
         input=self.parent.surf.parent.parent.filter.output)
     bot = tvtk.ClipPolyData(clip_function=self.planes[1],
                             inside_out=1,
                             input=top.output)
     bot.update()
     return bot
Ejemplo n.º 2
0
def voxelize(pts, polys, shape=(256, 256, 256), center=(128, 128, 128), mp=True):
    from tvtk.api import tvtk
    
    pd = tvtk.PolyData(points=pts + center + (0, 0, 0), polys=polys)
    plane = tvtk.Planes(normals=[(0,0,1)], points=[(0,0,0)])
    clip = tvtk.ClipPolyData(clip_function=plane, input=pd)
    feats = tvtk.FeatureEdges(
        manifold_edges=False, 
        non_manifold_edges=False, 
        feature_edges=False,
        boundary_edges=True,
        input=clip.output)

    def func(i):
        plane.points = [(0,0,i)]
        feats.update()
        vox = np.zeros(shape[:2][::-1], np.uint8)
        if feats.output.number_of_lines > 0:
            epts = feats.output.points.to_array()
            edges = feats.output.lines.to_array().reshape(-1, 3)[:,1:]
            for poly in trace_poly(edges):
                vox += rasterize(epts[poly][:,:2]+[.5, .5], shape=shape[:2][::-1])
        return vox % 2

    if mp:
        from . import mp
        layers = mp.map(func, range(shape[2]))
    else:
        #layers = map(func, range(shape[2]))
        layers = [func(x) for x in range(shape[2])] # python3 compatible

    return np.array(layers).T
Ejemplo n.º 3
0
    def _pipeline_default(self):
        sqrt2 = numpy.sqrt(2)
        x = -sqrt2 * numpy.cos(numpy.pi * 2. / 3)
        y = sqrt2 * numpy.sin(numpy.pi * 2. / 3)
        p1 = tvtk.PlaneSource(origin=(0,0,0), \
                              point1=(-sqrt2,0,1), point2=(x,y,1))
        p2 = tvtk.PlaneSource(origin=(0,0,0), \
                               point1=(x,y,1), point2=(x,-y,1))
        p3 = tvtk.PlaneSource(origin=(0,0,0), \
                               point1=(x,-y,1), point2=(-sqrt2,0,1))
        for p in (p1, p2, p3):
            p.set_resolution(32, 32)
        append = tvtk.AppendPolyData()
        append.add_input_connection(p1.output_port)
        append.add_input_connection(p2.output_port)
        append.add_input_connection(p3.output_port)

        scale_f = tvtk.TransformFilter(input_connection=append.output_port,
                                       transform=self.scale)

        trans = tvtk.Transform()
        trans.rotate_x(90.0)
        self.imp_cyl.transform = trans

        clip = tvtk.ClipPolyData(input_connection=scale_f.output_port,
                                 clip_function=self.imp_cyl,
                                 inside_out=True)

        transF2 = tvtk.TransformFilter(input_connection=clip.output_port,
                                       transform=self.transform)
        self.config_pipeline()
        return transF2
Ejemplo n.º 4
0
def visvtk(vtkfile, clip_bounds=None, color_by_normals=False,
           renderer=renderer):
    """
    visualizes the vtkfile with cells colored by normals. Also, right click
    saves "screnshot.png" in the current directory.
    """
    polydata = readpolydata(vtkfile)

    if clip_bounds is not None:
        box = tvtk.Box()
        #box.set_bounds(-5, 5, -5, 2.5, -5, 5)
        box.set_bounds(*clip_bounds)
        clipper = tvtk.ClipPolyData(input=polydata)
        clipper.inside_out = True
        clipper.clip_function = box
        clipper.generate_clip_scalars = True

        polydata = clipper.output
    return visualise(polydata, color_by_normals=color_by_normals, renderer=renderer)