예제 #1
0
def project(pts,projection,wc,geo=None):
  xm,xM,ym,yM= wc
  if isinstance(projection,(str,unicode)):
    projection = vcs.elements["projection"][projection]
  if projection.type=="linear":
    return None,pts
  if geo is None:
    geo = vtk.vtkGeoTransform()
    ps = vtk.vtkGeoProjection()
    pd = vtk.vtkGeoProjection()
    names = ["linear","utm","state","aea","lcc","merc","stere","poly","eqdc","tmerc","stere","lcca","azi","gnom","ortho","vertnearper","sinu","eqc","mill","vandg","omerc","robin","somerc","alsk","goode","moll","imoll","hammer","wag4","wag7","oea"]
    proj_dic = {"polar stereographic":"stere",
        -3:"aeqd",
        }
    for i in range(len(names)):
      proj_dic[i]=names[i]

    pname = proj_dic.get(projection._type,projection.type)
    projName = pname
    pd.SetName(projName)
    if projection.type == "polar (non gctp)":
      if ym<yM:
        pd.SetOptionalParameter("lat_0","-90.")
        pd.SetCentralMeridian(xm)
      else:
        pd.SetOptionalParameter("lat_0","90.")
        pd.SetCentralMeridian(xm+180.)
    else:
      setProjectionParameters(pd,projection)
    geo.SetSourceProjection(ps)
    geo.SetDestinationProjection(pd)
  geopts = vtk.vtkPoints()
  geo.TransformPoints(pts,geopts)
  return geo,geopts
예제 #2
0
def project(pts,projName='wintri',meridian=None):
  geo = vtk.vtkGeoTransform()
  ps = vtk.vtkGeoProjection()
  pd = vtk.vtkGeoProjection()
  pd.SetName(projName)
  if meridian is not None:
    pd.SetCentralMeridian(180)
  geo.SetSourceProjection(ps)
  geo.SetDestinationProjection(pd)
  geopts = vtk.vtkPoints()
  geo.TransformPoints(pts,geopts)
  return geopts
예제 #3
0
def project(pts,projection):
  if projection.type=="linear":
    return pts
  geo = vtk.vtkGeoTransform()
  ps = vtk.vtkGeoProjection()
  pd = vtk.vtkGeoProjection()
  projName = projection.type
  pd.SetName(projName)
  geo.SetSourceProjection(ps)
  geo.SetDestinationProjection(pd)
  geopts = vtk.vtkPoints()
  geo.TransformPoints(pts,geopts)
  return geopts
예제 #4
0
def project(pts, projection, wc):
    xm, xM, ym, yM = wc
    if isinstance(projection, (str, unicode)):
        projection = vcs.elements["projection"][projection]
    if projection.type == "linear":
        return None, pts
    geo = vtk.vtkGeoTransform()
    ps = vtk.vtkGeoProjection()
    #for i in range(ps.GetNumberOfProjections()):
    #  print i, ps.GetProjectionName(i)
    pd = vtk.vtkGeoProjection()
    names = [
        "linear", "utm", "state", "aea", "lcc", "merc", "stere", "poly",
        "eqdc", "tmerc", "stere", "lcca", "azi", "gnom", "ortho",
        "vertnearper", "sinu", "eqc", "mill", "vandg", "omerc", "robin",
        "somerc", "alsk", "goode", "moll", "imoll", "hammer", "wag4", "wag7",
        "oea"
    ]
    proj_dic = {
        "polar stereographic": "stere",
        -3: "aeqd",
    }
    for i in range(len(names)):
        proj_dic[i] = names[i]

    pname = proj_dic.get(projection._type, projection.type)
    projName = pname
    #for i in range(0,184,2):
    #  pd.SetName(pd.GetProjectionName(i))
    #  print i,":",pd.GetProjectionName(i),"(",pd.GetNumberOfOptionalParameters(),") --"
    #  pd.SetName(pd.GetProjectionName(i+1))
    #  print i+1,":",pd.GetProjectionName(i+1),"(",pd.GetNumberOfOptionalParameters(),")"

    pd.SetName(projName)
    if projection.type == "polar (non gctp)":
        if ym < yM:
            pd.SetOptionalParameter("lat_0", "-90.")
            pd.SetCentralMeridian(xm)
        else:
            pd.SetOptionalParameter("lat_0", "90.")
            pd.SetCentralMeridian(xm + 180.)
    else:
        setProjectionParameters(pd, projection)
    geo.SetSourceProjection(ps)
    geo.SetDestinationProjection(pd)
    geopts = vtk.vtkPoints()
    geo.TransformPoints(pts, geopts)
    return geo, geopts
예제 #5
0
    def __init__(self, proj_name='moll'):
        # Set up source and target projection
        sourceProjection = vtk.vtkGeoProjection()
        destinationProjection = vtk.vtkGeoProjection()
        destinationProjection.SetName(proj_name)

        # Set up transform between source and target.
        transformProjection = vtk.vtkGeoTransform()
        transformProjection.SetSourceProjection(sourceProjection)
        transformProjection.SetDestinationProjection(destinationProjection)

        # Set up transform filter
        transform_filter = vtk.vtkTransformPolyDataFilter()
        transform_filter.SetTransform(transformProjection)

        self.transform_filter = transform_filter
예제 #6
0
def main():
    colors = vtk.vtkNamedColors()
    geoGraticle = vtk.vtkGeoGraticule()
    transformProjection = vtk.vtkGeoTransform()
    destinationProjection = vtk.vtkGeoProjection()
    sourceProjection = vtk.vtkGeoProjection()
    transformGraticle = vtk.vtkTransformFilter()
    
    reader = vtk.vtkXMLPolyDataReader()
    transformReader = vtk.vtkTransformFilter()
    graticleMapper = vtk.vtkPolyDataMapper()
    readerMapper = vtk.vtkPolyDataMapper()
    graticleActor = vtk.vtkActor()
    readerActor = vtk.vtkActor()

    geoGraticle.SetGeometryType( geoGraticle.POLYLINES )
    geoGraticle.SetLatitudeLevel( 2 )
    geoGraticle.SetLongitudeLevel( 2 )
    geoGraticle.SetLongitudeBounds( -180, 180 )
    geoGraticle.SetLatitudeBounds( -90, 90 )
    
    # destinationProjection defaults to latlong.
    destinationProjection.SetName( "rouss" )
    destinationProjection.SetCentralMeridian( 0. )
    transformProjection.SetSourceProjection( sourceProjection )
    transformProjection.SetDestinationProjection( destinationProjection )
    transformGraticle.SetInputConnection( geoGraticle.GetOutputPort() )
    transformGraticle.SetTransform( transformProjection )
    graticleMapper.SetInputConnection( transformGraticle.GetOutputPort() )
    graticleActor.SetMapper( graticleMapper )
  
    renderWindow = vtk.vtkRenderWindow()
    renderer = vtk.vtkRenderer()
    interactor = vtk.vtkRenderWindowInteractor()
    renderWindow.SetInteractor( interactor )
    renderWindow.AddRenderer( renderer )
    renderWindow.SetSize(640, 480)
    renderer.SetBackground(colors.GetColor3d("BurlyWood"))
    
    renderer.AddActor( readerActor )
    renderer.AddActor( graticleActor )
    
    renderWindow.Render()  	
    interactor.Initialize()
    interactor.Start()
예제 #7
0
def list_projections():
    """
        Print a formatted list of available map projections
        to stdout.
    """
    proj = vtk.vtkGeoProjection()
    print("Index   Short Name   Description")
    print("=================================")
    for idx in range(0, proj.GetNumberOfProjections()):
        print("%3i     %10s   %s" %
              (idx, proj.GetProjectionName(idx),
               proj.GetProjectionDescription(idx).split("\n")[0]))
예제 #8
0
def llrprojection(map_projection_name):
    """
        Return a vtkGeoTransform object to transform a
        vtkPoints object with longitude-latitude (+radius)
        coordinates using a map projection selected by
        string "map_projection_name".
    """

    # Source points
    latlonproj = vtk.vtkGeoProjection()
    latlonproj.SetName('latlon')
    latlonproj.SetCentralMeridian(0)

    # Projected target points
    targetproj = vtk.vtkGeoProjection()
    targetproj.SetName(map_projection_name)
    targetproj.SetCentralMeridian(0)

    # Set up vtkGeoTransform object
    transform = vtk.vtkGeoTransform()
    transform.SetSourceProjection(latlonproj)
    transform.SetDestinationProjection(targetproj)
    return transform
예제 #9
0
  Y = origin[1]+ (opposite[1]-origin[1] )*(y-wc[2])/(wc[3]-wc[2])
  return X,Y

def R2World(ren,x,y):
  """Converts renderer's x/y to WorldCoordinate for a given Renderer"""
  ren.SetDisplayPoint(x,y,0)
  ren.DisplayToWorld()
  return wp

def vtkWorld2Renderer(ren,x,y):
  ren.SetWorldPoint(x,y,0,0)
  ren.WorldToDisplay()
  renpts = ren.GetDisplayPoint()
  return renpts

p=vtk.vtkGeoProjection()
vtkProjections = [ p.GetProjectionName(i) for i in range(p.GetNumberOfProjections()) ]
def checkProjType(self,name,value):
  if value in vtkProjections:
    warnings.warn("%s is a VTK backend specific projection, it might not work if you are not using the VTK backend" % value)
    return 200+vtkProjections.index(value)
  raise Exception("%s is not a known VTK projection" % value)
def checkProjParameters(self,name,value):
  if not isinstance(value,dict):
    raise ValueError("VTK specific projections parameters attribute needs to be a dictionary")
  return value
def getProjType(value):
  return vtkProjections[value-200]

def starPoints(radius_outer, x, y, number_points = 5):
  """Defines coordinate points for an arbitrary star"""
예제 #10
0
    cam = Renderer.GetActiveCamera()
    cam.ParallelProjectionOn()
    cam.SetParallelScale(yd)
    cd = cam.GetDistance()
    cam.SetPosition(xc, yc, cd)
    cam.SetFocalPoint(xc, yc, 0.)
    if geo is None:
        if flipY:
            cam.Elevation(180.)
            cam.Roll(180.)
            pass
        if flipX:
            cam.Azimuth(180.)


p = vtk.vtkGeoProjection()
vtkProjections = [
    p.GetProjectionName(i) for i in range(p.GetNumberOfProjections())
]


def checkProjType(self, name, value):
    if value in vtkProjections:
        warnings.warn(
            "%s is a VTK backend specific projection, it might not work if you are not using the VTK backend"
            % value)
        return 200 + vtkProjections.index(value)
    raise Exception("%s is not a known VTK projection" % value)


def checkProjParameters(self, name, value):
예제 #11
0
        class Pipeline:

            # Define source of pipeline
            grid = coprocessor.CreateProducer(datadescription, "input")

            if (write_full_output == True):
                fullWriter = pvs.XMLPUnstructuredGridWriter(
                    Input=grid, DataMode="Appended", CompressorType="ZLib")
                coprocessor.RegisterWriter(fullWriter,
                                           filename='full_output_%t.pvtu',
                                           freq=1)

            # Horizontal slice at the bottom
            slice = pvs.Slice(Input=grid)
            slice.SliceType = 'Plane'
            slice.SliceOffsetValues = [0.0]
            slice.SliceType.Origin = [0.0, 0.0, 101.94]
            slice.SliceType.Normal = [0.0, 0.0, 1.0]
            slice.Triangulatetheslice = False

            # Set up spherical projection filter - we need to bridge into the
            # VTK universe and use a VTK transform filter; the ParaView transform filter
            # does not support geo transforms

            # Source projection - simulation data is provided in lon lat rad coordinates
            latlonproj = vtk.vtkGeoProjection()
            latlonproj.SetName('lonlat')
            latlonproj.SetCentralMeridian(0)

            # Target projection - use Mollweide here
            targetproj = vtk.vtkGeoProjection()
            targetproj.SetName('moll')
            targetproj.SetCentralMeridian(0)

            # Set up vtkGeoTransform object that defines the transformation
            transform = vtk.vtkGeoTransform()
            transform.SetSourceProjection(latlonproj)
            transform.SetDestinationProjection(targetproj)

            # Set up VTK transform filter object
            tffilter = vtk.vtkTransformFilter()
            tffilter.SetTransform(transform)
            tffilter.SetInputConnection(
                slice.GetClientSideObject().GetOutputPort(0))

            # Return to ParaView universe by using a simple PassThrough filter to receive
            # output of the VTK transform filter
            passthrough = pvs.PassThrough()
            passthrough.GetClientSideObject().SetInputConnection(
                tffilter.GetOutputPort())

            # Create a new render view
            renderView = pvs.CreateView('RenderView')
            renderView.ViewSize = [1500, 768]
            renderView.AxesGrid = 'GridAxes3DActor'
            renderView.StereoType = 0
            renderView.CameraPosition = [0, 0, 4]
            renderView.CameraParallelScale = 1.7
            renderView.Background = [0.32, 0.34, 0.43]
            renderView.ViewTime = datadescription.GetTime()

            # Register the view with coprocessor
            # and provide it with information such as the filename to use,
            # how frequently to write the images, etc.
            coprocessor.RegisterView(renderView,
                                     filename='spherical_slice_%t.png',
                                     freq=1,
                                     fittoscreen=1,
                                     magnification=1,
                                     width=1500,
                                     height=768,
                                     cinema={})

            # Create colour transfer function for field
            LUT = pvs.GetColorTransferFunction(fieldname)
            LUT.RGBPoints = [
                dataRange[0], 0.23, 0.30, 0.75, 0.5 * sum(dataRange), 0.87,
                0.87, 0.87, dataRange[1], 0.71, 0.016, 0.15
            ]
            LUT.ScalarRangeInitialized = 1.0

            # Show surface and colour by field value (which is cell data) using lookup table
            sphereDisplay = pvs.Show(passthrough, renderView)
            sphereDisplay.Representation = 'Surface'
            sphereDisplay.ColorArrayName = ['CELLS', fieldname]
            sphereDisplay.LookupTable = LUT