예제 #1
0
def show_texture(cur_source, cur_view):
    # get mesh file name
    name = ""
    if hasattr(cur_source, 'FileNames') and cur_source.FileNames[0]:
        name = cur_source.FileNames[0]
    if hasattr(cur_source, 'FileName'):
        name = cur_source.FileName

    # set texture picture name
    if name == "":
        return
    ext_list = [".jpg", ".png", ".bmp", ".ppm", ".tiff"]
    stem = os.path.splitext(name)[0]
    ext = ""
    for ei in ext_list:
        if os.path.exists(stem + ei):
            ext = ei
            break
    if ext == "":
        name = ""
    else:
        name = stem + ext

    cur_display = GetDisplayProperties(cur_source, cur_view)
    # set texture
    set_texture(cur_display, name)
예제 #2
0
def plotOverLine(gds, desc, step, output_dir):
    import math
    from paraview.simple import CreateXYPlotView, SetActiveView
    from paraview.simple import SetActiveView, GetActiveSource, servermanager
    from paraview.simple import PlotOverLine, Calculator, GetDisplayProperties

    logger = logging.getLogger('gcm.pv_render.plotOverLine')

    title = desc.xpathEval('title/text()')
    if len(title) == 1:
        title = title[0].getContent()
    else:
        title = None
    output = desc.prop('output')

    logger.debug('Processing plotOverLine section')
    logger.debug('Title: ' + str(title))
    logger.debug('Output file name pattern: ' + output)

    quantities = [x.getContent() for x in desc.xpathEval('quantities/quantity/text()')]

    logger.debug('List of quantities to draw: ' + str(quantities))

    line_from = [float(x) for x in desc.prop('from').split(';')]
    line_to = [float(x) for x in desc.prop('to').split(';')]

    logger.debug('Line: %s -> %s' % (str(line_from), str(line_to)))

    view = CreateXYPlotView()
    view.ViewSize = [1000, 1000]
    view.ChartTitle = title
    SetActiveView(view)

    leftAxis = desc.xpathEval('axes/left')
    if len(leftAxis) == 1:
        leftAxis = [float(leftAxis[0].prop('from')), float(leftAxis[0].prop('to'))]
        logger.debug('Using custom Y axis range: ' + str(leftAxis))
    else:
        logger.debug('Using auto Y axis range')
        leftAxis = None

    if not leftAxis is None:
        if USE_API_4_2:
            view.LeftAxisRangeMinimum = leftAxis[0]
            view.LeftAxisRangeMaximum = leftAxis[1]
            view.LeftAxisUseCustomRange = True
        else:
            view.LeftAxisRange = leftAxis
            view.AxisUseCustomRange = [1, 0, 0, 0]

    bottomAxis = desc.xpathEval('axes/bottom')
    if len(bottomAxis) == 1:
        bottomAxis = [float(bottomAxis[0].prop('from')), float(bottomAxis[0].prop('to'))]
        logger.debug('Using custom labels for X axis: ' + str(bottomAxis))
    else:
        logger.debug('Using default X axis labels')
        bottomAxis = None

    if bottomAxis:
        logger.debug('Creating custom calculator to draw proper X axis labels')
        calc = Calculator(gds)
        calc.ResultArrayName = 'xindex'
        calc.Function = '%(index_from)f+%(len)f*sqrt((coordsX-(%(from_x)f))^2 + (coordsY-(%(from_y)f))^2 + (coordsZ-(%(from_z)f))^2)/%(line_len)f' % {
            'index_from': bottomAxis[0],
            'len': bottomAxis[1]-bottomAxis[0],
            'from_x': line_from[0],
            'from_y': line_from[1],
            'from_z': line_from[2],
            'line_len': math.sqrt((line_from[0]-line_to[0])**2+(line_from[1]-line_to[1])**2+(line_from[2]-line_to[2])**2)
        }

        src = calc
    else:
        src = gds

    logger.debug('Creating POL object')
    pol = PlotOverLine(src)
    pol.Source.Point1 = line_from
    pol.Source.Point2 = line_to


    active_src = GetActiveSource()
    filter = servermanager.Fetch(active_src)
    pd = filter.GetPointData()

    if USE_API_4_2:
        _sv = quantities
    else:
        logger.debug('Filing default series visibility list (hide all)')

        sv = {
            'Points (0)': '0',
            'Points (1)': '0',
            'Points (2)': '0',
            'Points (Magnitude)': '0',
            'vtkOriginalIndices': '0',
        }

        for i in range(pd.GetNumberOfArrays()):
            arr = pd.GetArray(i)
            sz = arr.GetNumberOfComponents()
            name = arr.GetName()
            if sz == 1:
                sv[name] = '0'
            else:
                for j in range(sz):
                    sv[name + ' (' + str(j) + ')'] = '0'
                sv[name + ' (Magnitude)'] = '0'

        for q in quantities:
            logger.debug('Showing plot for ' + q)
            sv[q] = '1'

        _sv = []
        for v in sv:
            _sv.append(v)
        _sv.append(sv[v])

    logger.debug('Setting display properties for POL object')
    dp = GetDisplayProperties(pol)
    dp.SeriesVisibility = _sv

    if not bottomAxis is None:
        dp.UseIndexForXAxis = 0
        dp.XArrayName = 'xindex'


    render(step, output, output_dir)
예제 #3
0
def render3d(gds, desc, step, output_dir):
    from paraview.simple import CreateRenderView, SetActiveView, GetActiveView
    from paraview.simple import CreateScalarBar, GetLookupTableForArray
    from paraview.simple import Threshold, Clip, GetDisplayProperties

    def MakeCoolToWarmLT(name, min, max):
        r=0.137255
        g=0.239216
        b=0.709804
        r2=0.67451
        g2=0.141176
        b2=0.12549
        lt = GetLookupTableForArray(name, 1, RGBPoints = [min, r, g, b, max, r2, g2, b2], ColorSpace = "Diverging")
        lt.VectorMode = "Magnitude"
        lt.RGBPoints.SetData([min, r, g, b, max, r2, g2, b2])
        return lt

    logger = logging.getLogger('gcm.pv_render.render3d')

    title = desc.xpathEval('title/text()')
    if len(title) == 1:
        title = title[0].getContent()
    else:
        title = None
    output = desc.prop('output')

    logger.debug('Processing plotOverLine section')
    logger.debug('Title: ' + str(title))
    logger.debug('Output file name pattern: ' + output)

    q = desc.xpathEval('quantity')[0]
    quantity = q.getContent()
    qmin = float(q.prop('min'))
    qmax = float(q.prop('max'))

    camera = desc.xpathEval('camera')
    if len(camera) == 1:
        camera = camera[0]
    else:
        logger.fatal('Camera settings not provided')

    cpos = [float(x) for x in camera.prop('position').split(';')]
    cup = [float(x) for x in camera.prop('up').split(';')]
    cfocal = [float(x) for x in camera.prop('focal').split(';')]
    cangle = float(camera.prop('angle'))

    logger.debug('Camera position: ' + str(cpos))
    logger.debug('Camera up: ' + str(cup))
    logger.debug('Camera focal point: ' + str(cfocal))
    logger.debug('Camera view angle: ' + str(cangle))

    view = CreateRenderView()

    view.ViewSize = [1000, 1000]
    view.Background = [0.3, 0.3, 0.4]
    view.CenterAxesVisibility = 0


    view.CameraViewUp = cup
    view.CameraFocalPoint = cfocal
    view.CameraViewAngle = cangle
    view.CameraPosition = cpos

    SetActiveView(view)

    logger.debug('Quantity to render: ' + quantity)

    src = gds

    logger.debug('Processing thresholds')

    for thr in desc.xpathEval('thresholds/threshold'):
        scalar = thr.prop('scalar')
        tmin = float(thr.prop('min'))
        tmax = float(thr.prop('max'))

        logger.debug('Creating threshold on array %s with range [%f, %f]' % (scalar, tmin, tmax))

        src = Threshold(src)
        src.Scalars = ['POINTS', scalar]
        src.ThresholdRange = [tmin, tmax]

    logger.debug('Processing clips')

    for cl in desc.xpathEval('clips/clip'):
        origin = [float(x) for x in cl.prop('origin').split(';')]
        normal = [float(x) for x in cl.prop('normal').split(';')]

        logger.debug('Creating clip with origin %s and normal %s' % (origin, normal))

        src = Clip(src)
        src.ClipType.Origin = origin
        src.ClipType.Normal = normal

    dp = GetDisplayProperties(src)
    dp.LookupTable = MakeCoolToWarmLT(quantity, qmin, qmax)

    if USE_API_4_2:
        dp.ColorArrayName = ('POINTS', quantity)
    else:
        dp.ColorArrayName = quantity
        dp.ColorAttributeType = 'POINT_DATA'

    bar = CreateScalarBar(LookupTable=dp.LookupTable, Title=quantity, TitleFontSize = 10, LabelFontSize = 10)
    GetActiveView().Representations.append(bar)



    render(step, output, output_dir)
예제 #4
0
파일: pv_render.py 프로젝트: mediev/gcm-3d
def plotOverLine(gds, desc, step, output_dir):
    import math
    from paraview.simple import CreateXYPlotView, SetActiveView
    from paraview.simple import SetActiveView, GetActiveSource, servermanager
    from paraview.simple import PlotOverLine, Calculator, GetDisplayProperties

    logger = logging.getLogger('gcm.pv_render.plotOverLine')

    title = desc.xpathEval('title/text()')
    if len(title) == 1:
        title = title[0].getContent()
    else:
        title = None
    output = desc.prop('output')

    logger.debug('Processing plotOverLine section')
    logger.debug('Title: ' + str(title))
    logger.debug('Output file name pattern: ' + output)

    quantities = [
        x.getContent() for x in desc.xpathEval('quantities/quantity/text()')
    ]

    logger.debug('List of quantities to draw: ' + str(quantities))

    line_from = [float(x) for x in desc.prop('from').split(';')]
    line_to = [float(x) for x in desc.prop('to').split(';')]

    logger.debug('Line: %s -> %s' % (str(line_from), str(line_to)))

    view = CreateXYPlotView()
    view.ViewSize = [1000, 1000]
    view.ChartTitle = title
    SetActiveView(view)

    leftAxis = desc.xpathEval('axes/left')
    if len(leftAxis) == 1:
        leftAxis = [
            float(leftAxis[0].prop('from')),
            float(leftAxis[0].prop('to'))
        ]
        logger.debug('Using custom Y axis range: ' + str(leftAxis))
    else:
        logger.debug('Using auto Y axis range')
        leftAxis = None

    if not leftAxis is None:
        if USE_API_4_2:
            view.LeftAxisRangeMinimum = leftAxis[0]
            view.LeftAxisRangeMaximum = leftAxis[1]
            view.LeftAxisUseCustomRange = True
        else:
            view.LeftAxisRange = leftAxis
            view.AxisUseCustomRange = [1, 0, 0, 0]

    bottomAxis = desc.xpathEval('axes/bottom')
    if len(bottomAxis) == 1:
        bottomAxis = [
            float(bottomAxis[0].prop('from')),
            float(bottomAxis[0].prop('to'))
        ]
        logger.debug('Using custom labels for X axis: ' + str(bottomAxis))
    else:
        logger.debug('Using default X axis labels')
        bottomAxis = None

    if bottomAxis:
        logger.debug('Creating custom calculator to draw proper X axis labels')
        calc = Calculator(gds)
        calc.ResultArrayName = 'xindex'
        calc.Function = '%(index_from)f+%(len)f*sqrt((coordsX-(%(from_x)f))^2 + (coordsY-(%(from_y)f))^2 + (coordsZ-(%(from_z)f))^2)/%(line_len)f' % {
            'index_from':
            bottomAxis[0],
            'len':
            bottomAxis[1] - bottomAxis[0],
            'from_x':
            line_from[0],
            'from_y':
            line_from[1],
            'from_z':
            line_from[2],
            'line_len':
            math.sqrt((line_from[0] - line_to[0])**2 +
                      (line_from[1] - line_to[1])**2 +
                      (line_from[2] - line_to[2])**2)
        }

        src = calc
    else:
        src = gds

    logger.debug('Creating POL object')
    pol = PlotOverLine(src)
    pol.Source.Point1 = line_from
    pol.Source.Point2 = line_to

    active_src = GetActiveSource()
    filter = servermanager.Fetch(active_src)
    pd = filter.GetPointData()

    if USE_API_4_2:
        _sv = quantities
    else:
        logger.debug('Filing default series visibility list (hide all)')

        sv = {
            'Points (0)': '0',
            'Points (1)': '0',
            'Points (2)': '0',
            'Points (Magnitude)': '0',
            'vtkOriginalIndices': '0',
        }

        for i in range(pd.GetNumberOfArrays()):
            arr = pd.GetArray(i)
            sz = arr.GetNumberOfComponents()
            name = arr.GetName()
            if sz == 1:
                sv[name] = '0'
            else:
                for j in range(sz):
                    sv[name + ' (' + str(j) + ')'] = '0'
                sv[name + ' (Magnitude)'] = '0'

        for q in quantities:
            logger.debug('Showing plot for ' + q)
            sv[q] = '1'

        _sv = []
        for v in sv:
            _sv.append(v)
        _sv.append(sv[v])

    logger.debug('Setting display properties for POL object')
    dp = GetDisplayProperties(pol)
    dp.SeriesVisibility = _sv

    if not bottomAxis is None:
        dp.UseIndexForXAxis = 0
        dp.XArrayName = 'xindex'

    render(step, output, output_dir)
예제 #5
0
파일: pv_render.py 프로젝트: mediev/gcm-3d
def render3d(gds, desc, step, output_dir):
    from paraview.simple import CreateRenderView, SetActiveView, GetActiveView
    from paraview.simple import CreateScalarBar, GetLookupTableForArray
    from paraview.simple import Threshold, Clip, GetDisplayProperties

    def MakeCoolToWarmLT(name, min, max):
        r = 0.137255
        g = 0.239216
        b = 0.709804
        r2 = 0.67451
        g2 = 0.141176
        b2 = 0.12549
        lt = GetLookupTableForArray(name,
                                    1,
                                    RGBPoints=[min, r, g, b, max, r2, g2, b2],
                                    ColorSpace="Diverging")
        lt.VectorMode = "Magnitude"
        lt.RGBPoints.SetData([min, r, g, b, max, r2, g2, b2])
        return lt

    logger = logging.getLogger('gcm.pv_render.render3d')

    title = desc.xpathEval('title/text()')
    if len(title) == 1:
        title = title[0].getContent()
    else:
        title = None
    output = desc.prop('output')

    logger.debug('Processing plotOverLine section')
    logger.debug('Title: ' + str(title))
    logger.debug('Output file name pattern: ' + output)

    q = desc.xpathEval('quantity')[0]
    quantity = q.getContent()
    qmin = float(q.prop('min'))
    qmax = float(q.prop('max'))

    camera = desc.xpathEval('camera')
    if len(camera) == 1:
        camera = camera[0]
    else:
        logger.fatal('Camera settings not provided')

    cpos = [float(x) for x in camera.prop('position').split(';')]
    cup = [float(x) for x in camera.prop('up').split(';')]
    cfocal = [float(x) for x in camera.prop('focal').split(';')]
    cangle = float(camera.prop('angle'))

    logger.debug('Camera position: ' + str(cpos))
    logger.debug('Camera up: ' + str(cup))
    logger.debug('Camera focal point: ' + str(cfocal))
    logger.debug('Camera view angle: ' + str(cangle))

    view = CreateRenderView()

    view.ViewSize = [1000, 1000]
    view.Background = [0.3, 0.3, 0.4]
    view.CenterAxesVisibility = 0

    view.CameraViewUp = cup
    view.CameraFocalPoint = cfocal
    view.CameraViewAngle = cangle
    view.CameraPosition = cpos

    SetActiveView(view)

    logger.debug('Quantity to render: ' + quantity)

    src = gds

    logger.debug('Processing thresholds')

    for thr in desc.xpathEval('thresholds/threshold'):
        scalar = thr.prop('scalar')
        tmin = float(thr.prop('min'))
        tmax = float(thr.prop('max'))

        logger.debug('Creating threshold on array %s with range [%f, %f]' %
                     (scalar, tmin, tmax))

        src = Threshold(src)
        src.Scalars = ['POINTS', scalar]
        src.ThresholdRange = [tmin, tmax]

    logger.debug('Processing clips')

    for cl in desc.xpathEval('clips/clip'):
        origin = [float(x) for x in cl.prop('origin').split(';')]
        normal = [float(x) for x in cl.prop('normal').split(';')]

        logger.debug('Creating clip with origin %s and normal %s' %
                     (origin, normal))

        src = Clip(src)
        src.ClipType.Origin = origin
        src.ClipType.Normal = normal

    dp = GetDisplayProperties(src)
    dp.LookupTable = MakeCoolToWarmLT(quantity, qmin, qmax)

    if USE_API_4_2:
        dp.ColorArrayName = ('POINTS', quantity)
    else:
        dp.ColorArrayName = quantity
        dp.ColorAttributeType = 'POINT_DATA'

    bar = CreateScalarBar(LookupTable=dp.LookupTable,
                          Title=quantity,
                          TitleFontSize=10,
                          LabelFontSize=10)
    GetActiveView().Representations.append(bar)

    render(step, output, output_dir)