[vtkusers] Digital Graticule

Jothybasu K Selvaraj jothybasu at gmail.com
Sun Apr 18 13:08:44 EDT 2010


Hi again,

I have modified the code a bit. Used Assembly to add lines and cursoe, so
that we can rotate the entire cursor easily.

Here is the modified code

*import vtk
import numpy as np
color=[1,1,0]
Bounds=[-110,110,-110,110,0,0]
Cursor=vtk.vtkCursor2D()
Cursor.SetModelBounds(Bounds)
Cursor.SetFocalPoint(0,0,0)
Cursor.AllOn()
Cursor.AxesOn()
Cursor.OutlineOff()
Cursor.SetRadius(1)
mapper=vtk.vtkPolyDataMapper()
mapper.SetInputConnection(Cursor.GetOutputPort())
actor=vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(color)


def CreateTicks(Cursorolor,CursorursorBounds,TickInterval):
    XTicks=list()
    YTicks=list()
    XBoundsRight=CursorursorBounds[0]
    XBoundsLeft=CursorursorBounds[1]
    YBoundsRight=CursorursorBounds[2]
    YBoundsLeft=CursorursorBounds[3]

    for x in range(XBoundsRight+TickInterval,XBoundsLeft,TickInterval):
        print x
        XTick=vtk.vtkLineSource()
        XTick.SetPoint1(x,5,0)
        XTick.SetPoint2(x,-5,0)
        XTick.Update()
        XTickMapper=vtk.vtkPolyDataMapper()
        XTickMapper.SetInputConnection(XTick.GetOutputPort())
        XTickActor=vtk.vtkActor()
        XTickActor.SetMapper(XTickMapper)
        XTickActor.GetProperty().SetColor(color)
        XTicks.append(XTickActor)

    for y in range(YBoundsRight+TickInterval,YBoundsLeft,TickInterval):
        #print y
        YTick=vtk.vtkLineSource()
        YTick.SetPoint1(5,y,0)
        YTick.SetPoint2(-5,y,0)
        YTick.Update()
        YTickMapper=vtk.vtkPolyDataMapper()
        YTickMapper.SetInputConnection(YTick.GetOutputPort())
        YTickActor=vtk.vtkActor()
        YTickActor.SetMapper(YTickMapper)
        YTickActor.GetProperty().SetColor(color)
        YTicks.append(YTickActor)
    return XTicks,YTicks


XTicks,YTicks=CreateTicks((1,1,0),Bounds,10)
NumOfXTicks= np.size(XTicks)
NumOfYTicks= np.size(YTicks)


Ren=vtk.vtkRenderer()
Assembly=vtk.vtkAssembly()
Assembly.AddPart(actor)
for x in range(0,NumOfXTicks,1):
    Assembly.AddPart(XTicks[x])

for y in range(0,NumOfYTicks,1):
    Assembly.AddPart(YTicks[y])
Assembly.RotateZ(45)
Ren.AddActor(Assembly)
RenWin=vtk.vtkRenderWindow()
RenWin.AddRenderer(Ren)
RenWin.Render()*


Thanks,

Jothy

On Sun, Apr 18, 2010 at 5:54 PM, Jothybasu K Selvaraj
<jothybasu at gmail.com>wrote:

> Hi Guys,
>
> I have managed to create a digital graticule, but the distance of the ticks
> doesn't match properly.Basically its stitching together a cursor2D & small
> line from vtkLineSource.
>
> If anyone can figure it out, I request them to create a c++ class and
> sub,it that to the developer list as a convenience class.
>
> Thanks,
>
> Jothy
>
>
>
>
>
> import vtk
> import numpy as np
> color=[1,1,0]
> Bounds=[-110,110,-110,110,0,0]
> Cursor=vtk.vtkCursor2D()
> Cursor.SetModelBounds(Bounds)
> Cursor.SetFocalPoint(0,0,0)
> Cursor.AllOn()
> Cursor.AxesOn()
> Cursor.OutlineOff()
> Cursor.SetRadius(1)
> mapper=vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(Cursor.GetOutputPort())
> actor=vtk.vtkActor()
> actor.SetMapper(mapper)
> actor.GetProperty().SetColor(color)
>
>
> def CreateTicks(Cursorolor,CursorursorBounds,TickInterval):
>     XTicks=list()
>     YTicks=list()
>     XBoundsRight=CursorursorBounds[0]
>     XBoundsLeft=CursorursorBounds[1]
>     YBoundsRight=CursorursorBounds[2]
>     YBoundsLeft=CursorursorBounds[3]
>
>     for x in range(XBoundsRight+TickInterval,XBoundsLeft,TickInterval):
>         print x
>         XTick=vtk.vtkLineSource()
>         XTick.SetPoint1(x,5,0)
>         XTick.SetPoint2(x,-5,0)
>         XTick.Update()
>         XTickMapper=vtk.vtkPolyDataMapper()
>         XTickMapper.SetInputConnection(XTick.GetOutputPort())
>         XTickActor=vtk.vtkActor()
>         XTickActor.SetMapper(XTickMapper)
>         XTickActor.GetProperty().SetColor(color)
>         XTicks.append(XTickActor)
>
>     for y in range(YBoundsRight+TickInterval,YBoundsLeft,TickInterval):
>         #print y
>         YTick=vtk.vtkLineSource()
>         YTick.SetPoint1(5,y,0)
>         YTick.SetPoint2(-5,y,0)
>         YTick.Update()
>         YTickMapper=vtk.vtkPolyDataMapper()
>         YTickMapper.SetInputConnection(YTick.GetOutputPort())
>         YTickActor=vtk.vtkActor()
>         YTickActor.SetMapper(YTickMapper)
>         YTickActor.GetProperty().SetColor(color)
>         YTicks.append(YTickActor)
>     return XTicks,YTicks
>
>
> XTicks,YTicks=CreateTicks((1,1,0),Bounds,10)
> NumOfXTicks= np.size(XTicks)
> NumOfYTicks= np.size(YTicks)
>
>
> Ren=vtk.vtkRenderer()
> Ren.AddActor(actor)
> for x in range(0,NumOfXTicks,1):
>     Ren.AddActor(XTicks[x])
>
> for y in range(0,NumOfYTicks,1):
>     Ren.AddActor(YTicks[y])
>
>
> RenWin=vtk.vtkRenderWindow()
> RenWin.AddRenderer(Ren)
> RenWin.Render()
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100418/4c5b8ede/attachment.htm>


More information about the vtkusers mailing list