Esempio n. 1
0
def cylinder(pos=[0, 0, 0],
             r=1,
             height=1,
             axis=[0, 0, 1],
             c='teal',
             wire=0,
             alpha=1,
             legend=None,
             texture=None,
             res=24):
    '''
    Build a cylinder of specified height and radius r, centered at pos.

    If pos is a list of 2 points, e.g. pos=[v1,v2], build a cylinder with base
    centered at v1 and top at v2.

    [**Example1**](https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced/gyroscope1.py)    
    [**Example2**](https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced/turing.py)    
    '''

    if utils.isSequence(pos[0]):  # assume user is passing pos=[base, top]
        base = np.array(pos[0])
        top = np.array(pos[1])
        pos = (base + top) / 2
        height = np.linalg.norm(top - base)
        axis = top - base
        axis = utils.norm(axis)
    else:
        axis = utils.norm(axis)
        base = pos - axis * height / 2
        top = pos + axis * height / 2

    cyl = vtk.vtkCylinderSource()
    cyl.SetResolution(res)
    cyl.SetRadius(r)
    cyl.SetHeight(height)
    cyl.Update()

    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateX(90)  # put it along Z
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(cyl.GetOutput())
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()

    actor = Actor(pd, c, alpha, wire, legend=legend, texture=texture)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    actor.base = base
    actor.top = top
    return actor
Esempio n. 2
0
def Cylinder(
        pos=(0, 0, 0), r=1, height=1, axis=(0, 0, 1), c="teal", alpha=1,
        res=24):
    """
    Build a cylinder of specified height and radius `r`, centered at `pos`.

    If `pos` is a list of 2 Points, e.g. `pos=[v1,v2]`, build a cylinder with base
    centered at `v1` and top at `v2`.
    
    |Cylinder|
    """

    if utils.isSequence(pos[0]):  # assume user is passing pos=[base, top]
        base = np.array(pos[0])
        top = np.array(pos[1])
        pos = (base + top) / 2
        height = np.linalg.norm(top - base)
        axis = top - base
        axis = utils.norm(axis)
    else:
        axis = utils.norm(axis)
        base = pos - axis * height / 2
        top = pos + axis * height / 2

    cyl = vtk.vtkCylinderSource()
    cyl.SetResolution(res)
    cyl.SetRadius(r)
    cyl.SetHeight(height)
    cyl.Update()

    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateX(90)  # put it along Z
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(cyl.GetOutput())
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()

    actor = Actor(pd, c, alpha)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    actor.base = base + pos
    actor.top = top + pos
    return actor
def cone(pos=[0, 0, 0],
         r=1,
         height=1,
         axis=[0, 0, 1],
         c='dg',
         alpha=1,
         legend=None,
         texture=None,
         res=48):
    '''
    Build a cone of specified radius r and height, centered at pos.
    '''
    con = vtk.vtkConeSource()
    con.SetResolution(res)
    con.SetRadius(r)
    con.SetHeight(height)
    con.SetDirection(axis)
    con.Update()
    actor = vu.makeActor(con.GetOutput(),
                         c,
                         alpha,
                         legend=legend,
                         texture=texture)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    v = vu.norm(axis) * height / 2
    setattr(actor, 'base', pos - v)
    setattr(actor, 'top', pos + v)
    return actor
Esempio n. 4
0
def cone(pos=[0, 0, 0],
         r=1,
         height=1,
         axis=[0, 0, 1],
         c='dg',
         alpha=1,
         legend=None,
         texture=None,
         res=48):
    '''
    Build a cone of specified radius `r` and `height`, centered at `pos`.
    '''
    con = vtk.vtkConeSource()
    con.SetResolution(res)
    con.SetRadius(r)
    con.SetHeight(height)
    con.SetDirection(axis)
    con.Update()
    actor = Actor(con.GetOutput(), c, alpha, legend=legend, texture=texture)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    v = utils.norm(axis) * height / 2
    actor.base = pos - v
    actor.top = pos + v
    return actor
Esempio n. 5
0
def Cone(pos=(0, 0, 0), r=1, height=3, axis=(0, 0, 1), c="dg", alpha=1,
         res=48):
    """
    Build a cone of specified radius `r` and `height`, centered at `pos`.
    
    |Cone|
    """
    con = vtk.vtkConeSource()
    con.SetResolution(res)
    con.SetRadius(r)
    con.SetHeight(height)
    con.SetDirection(axis)
    con.Update()
    actor = Actor(con.GetOutput(), c, alpha)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    v = utils.norm(axis) * height / 2
    actor.base = pos - v
    actor.top = pos + v
    return actor
def cylinder(pos=[0, 0, 0],
             r=1,
             height=1,
             axis=[0, 0, 1],
             c='teal',
             wire=0,
             alpha=1,
             edges=False,
             legend=None,
             texture=None,
             res=24):
    '''
    Build a cylinder of specified height and radius r, centered at pos.
    
    If pos is a list of 2 points, e.g. pos=[v1,v2], build a cylinder with base
    centered at v1 and top at v2.
    '''

    if vu.isSequence(pos[0]):  # assume user is passing pos=[base, top]
        base = np.array(pos[0])
        top = np.array(pos[1])
        pos = (base + top) / 2
        height = np.linalg.norm(top - base)
        axis = top - base
        axis = vu.norm(axis)
    else:
        axis = vu.norm(axis)
        base = pos - axis * height / 2
        top = pos + axis * height / 2

    cyl = vtk.vtkCylinderSource()
    cyl.SetResolution(res)
    cyl.SetRadius(r)
    cyl.SetHeight(height)
    cyl.Update()

    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateX(90)  #put it along Z
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    vu.setInput(tf, cyl.GetOutput())
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()

    actor = vu.makeActor(pd,
                         c,
                         alpha,
                         wire,
                         edges=edges,
                         legend=legend,
                         texture=texture)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    setattr(actor, 'base', base)
    setattr(actor, 'top', top)
    return actor