Re: Help with vtkInterpolateDataSetAttributes
"Andrew E. Slaughter via vtkusers" <[email protected]>
| Newsgroups | gmane.comp.lib.vtk.user |
|---|---|
| Message-ID | <[email protected]> |
The interpolation for point data is working great, I am working on making my script more robust before posting by including cell and global data to the interpolation. I also am interpolating all active data into a vtkMultiBlockDataSetAlgorithm so the end product will behave similarly as a vtkExodusIIReader object. Anyway, I can't get the cell data to interpolate. The point data is working fine (change the variable to 'point') to show this result. I was hoping you could take a look and see what I am missing, I images it is something to do with the vtkPointInterpolator, but I can't seem to find the solution. Thanks, Andrew On 12/5/18, 5:20 PM, "Bill Lorensen" <[email protected]> wrote: I found the problems with your script. vtkPointInterpolator: The point arrays will not be interpolated unless PassPointArrays is off. And the source and input data must add the field data as the active scalar. vtkInterpolateDataSetAttibutes does not interpolate field data. To interpolate field data each input must add the field data as the active scalar. Neither of these are obvious. I have attached a c++ example that is based on your script. I changed a lot of the names to help me debug the problems. I would like to ass this c++ code as an example, once I make a few more changes. Is that OK with you? I would also need to add your datasets. Bill On Tue, Dec 4, 2018 at 3:40 PM Andrew E. Slaughter <[email protected]> wrote: > > Thank you, feel free to email me directly if you need anything more from my end. > > > > From: Bill Lorensen <[email protected]> > Date: Monday, December 3, 2018 at 7:20 PM > To: "Andrew E. Slaughter" <[email protected]> > Cc: VTK Users <[email protected]> > Subject: Re: [vtkusers] Help with vtkInterpolateDataSetAttributes > > > > I suspect that vtkInterpolateDataSetAttributes may be buggy. The are no tests that interpolate scalar data. I'm looking into it. > > > > On Thu, Nov 29, 2018, 8:13 AM Andrew E. Slaughter via vtkusers <[email protected] wrote: > > I am attempting to interpolate between two ExodusII (vtkExodusIIReader) results using the vtkInterpolateDataSetAttributes, but am having trouble getting it to work. I was able to perform an interpolation that mimics the behavior with calls to vtkAbstractArray::InterpolateTuple, but this doesn’t seem like the correct solution. > > > > I have attached a script that show what I am trying to do, including what is working and what is not. I know that for this problem I could use vtkTemporalInterpolator, but for the actual problem I am trying to solve it isn’t appropriate. I am using python bindings with VTK7.1 on MacOS. > > > > I would appreciate any help I can get making this work. > > > > Thanks, > > Andrew > > > > > > _______________________________________________ > Powered by www.kitware.com > > Visit other Kitware open-source projects at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwIFaQ&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=CZ-fngNdgJgN52g8AviZCojUB3AwTUttziM040_wM1g&s=E2eeqfO0l7aGQzYt_-DT6zLV6ALe0sCfFm6z4kfA2vE&e= > > Please keep messages on-topic and check the VTK FAQ at: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.vtk.org_Wiki_VTK-5FFAQ&d=DwIFaQ&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=CZ-fngNdgJgN52g8AviZCojUB3AwTUttziM040_wM1g&s=cZQZE8xkatSI9xZ8-19BijAzdZZhpEzqBD5JiCsyQZk&e= > > Search the list archives at: https://urldefense.proofpoint.com/v2/url?u=http-3A__markmail.org_search_-3Fq-3Dvtkusers&d=DwIFaQ&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=CZ-fngNdgJgN52g8AviZCojUB3AwTUttziM040_wM1g&s=4EuYM4upr3Tp4Rakv_UjS9KZk1TyOLER92KgxprLfv4&e= > > Follow this link to subscribe/unsubscribe: > https://urldefense.proofpoint.com/v2/url?u=https-3A__public.kitware.com_mailman_listinfo_vtkusers&d=DwIFaQ&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=h7heP8xwI1i_HikChvhFbEBurKirgfOCdwgBxB9lM8c&m=CZ-fngNdgJgN52g8AviZCojUB3AwTUttziM040_wM1g&s=smX4duzcBydAraDbmtpSZRONXDLCSc4MycG_F_Jw5I0&e= -- Unpaid intern in BillsParadise at noware dot com _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ Search the list archives at: http://markmail.org/search/?q=vtkusers Follow this link to subscribe/unsubscribe: https://public.kitware.com/mailman/listinfo/vtkusers
input_out.e
(application/octet-stream, 46.2 KB) - not displayed
input_out.e-s002
(application/octet-stream, 29.3 KB) - not displayed
interpolate2.py
(text/x-python-script, 7.2 KB)
#!/usr/bin/env python
import vtk
file0 = 'input_out.e'
file1 = 'input_out.e-s002'
variable = 'cell'
range = [0, 3]
##################################################################################
# FILE 0: COARSE MESH WITH SOLUTION 0
coarseReader = vtk.vtkExodusIIReader()
coarseReader.SetFileName(file0)
coarseReader.UpdateInformation()
coarseReader.SetTimeStep(0)
coarseReader.SetPointResultArrayStatus(variable, 1)
coarseReader.SetElementResultArrayStatus(variable, 1)
coarseReader.SetGlobalResultArrayStatus(variable, 1)
coarseReader.Update()
coarseGeometry = vtk.vtkCompositeDataGeometryFilter()
coarseGeometry.SetInputConnection(0, coarseReader.GetOutputPort(0))
coarseGeometry.Update()
#coarseGeometry.GetOutput().GetPointData().SetActiveScalars(variable)
#coarseGeometry.GetOutput().GetCellData().SetActiveScalars(variable)
coarseMapper = vtk.vtkPolyDataMapper()
coarseMapper.SetInputConnection(coarseGeometry.GetOutputPort())
coarseMapper.SelectColorArray(variable)
if variable == 'cell':
coarseMapper.SetScalarModeToUseCellFieldData()
elif variable == 'point':
coarseMapper.SetScalarModeToUsePointFieldData()
coarseMapper.InterpolateScalarsBeforeMappingOn()
coarseMapper.SetScalarRange(*range)
coarseActor = vtk.vtkActor()
coarseActor.SetMapper(coarseMapper)
coarseActor.GetProperty().SetEdgeVisibility(True)
coarseRenderer = vtk.vtkRenderer()
coarseRenderer.AddViewProp(coarseActor)
coarseRenderer.SetViewport(0, 0, 0.33, 1)
####################################################################################################
# FILE 1: FINE MESH WITH SOLUTION 1
fineReader = vtk.vtkExodusIIReader()
fineReader.SetFileName(file1)
fineReader.UpdateInformation()
fineReader.SetPointResultArrayStatus(variable, 1)
fineReader.SetElementResultArrayStatus(variable, 1)
fineReader.SetGlobalResultArrayStatus(variable, 1)
fineReader.SetGenerateObjectIdCellArray(True)
fineReader.SetTimeStep(0)
fineReader.Update()
fineGeometry = vtk.vtkCompositeDataGeometryFilter()
fineGeometry.SetInputConnection(0, fineReader.GetOutputPort(0))
fineGeometry.Update()
if variable == 'cell':
fineGeometry.GetOutput().GetCellData().SetActiveScalars(variable)
elif variable == 'point':
fineGeometry.GetOutput().GetPointData().SetActiveScalars(variable)
fineMapper = vtk.vtkPolyDataMapper()
fineMapper.SetInputConnection(fineGeometry.GetOutputPort())
fineMapper.SelectColorArray(variable)
if variable == 'cell':
fineMapper.SetScalarModeToUseCellFieldData()
elif variable == 'point':
fineMapper.SetScalarModeToUsePointFieldData()
fineMapper.InterpolateScalarsBeforeMappingOn()
fineMapper.SetScalarRange(*range)
fineActor = vtk.vtkActor()
fineActor.SetMapper(fineMapper)
fineActor.GetProperty().SetEdgeVisibility(True)
fineRenderer = vtk.vtkRenderer()
fineRenderer.AddViewProp(fineActor)
fineRenderer.SetViewport(0.66, 0, 1, 1)
####################################################################################################
# PROJECT SOLUTION FROM FILE 0 to GRID FROM FILE 1
interpReader = vtk.vtkMultiBlockDataSetAlgorithm()
interpReader.GetOutput().DeepCopy(fineReader.GetOutput())
def interpolate(variable, i, j, action):
locator = vtk.vtkStaticPointLocator()# switching this to vtkSaticCellLocator doesn't work because vtkPoinInterpolator expects a AbstractPointLocator
locator.SetDataSet(fineGeometry.GetOutput())
locator.BuildLocator()
kernel = vtk.vtkGaussianKernel()
kernel.SetSharpness(4)
kernel.SetKernelFootprintToNClosest()
kernel.SetNumberOfPoints(10)
kernel.SetSharpness(5.0)
fineInterpolator = vtk.vtkPointInterpolator()
fineInterpolator.SetSourceData(coarseGeometry.GetOutput()) # Pc data set to be probed by input points P
fineInterpolator.SetInputData(fineGeometry.GetOutput())
fineInterpolator.SetKernel(kernel)
fineInterpolator.SetLocator(locator)
fineInterpolator.SetNullPointsStrategyToClosestPoint()
# THIS IS REQUIRED!!!
if action == 'CELL':
fineInterpolator.PassCellArraysOff()
elif action == 'POINT':
fineInterpolator.PassPointArraysOff()
fineInterpolator.Update()
if action == 'CELL':
interpReader.GetOutput().GetBlock(i).GetBlock(j).GetCellData().SetActiveScalars(variable)
fineInterpolator.GetOutput().GetCellData().SetActiveScalars(variable)
elif action == 'POINT':
interpReader.GetOutput().GetBlock(i).GetBlock(j).GetPointData().SetActiveScalars(variable)
fineInterpolator.GetOutput().GetPointData().SetActiveScalars(variable)
fineInterpolateAttributes = vtk.vtkInterpolateDataSetAttributes()
fineInterpolateAttributes.AddInputData(0, interpReader.GetOutput().GetBlock(i).GetBlock(j))
fineInterpolateAttributes.AddInputData(0, fineInterpolator.GetOutput())
fineInterpolateAttributes.SetT(0.5)
fineInterpolateAttributes.Update()
interpReader.GetOutput().GetBlock(i).GetBlock(j).DeepCopy(fineInterpolateAttributes.GetOutput())
for i in xrange(fineReader.GetOutput().GetNumberOfBlocks()):
for j in xrange(fineReader.GetOutput().GetBlock(i).GetNumberOfBlocks()):
data = fineReader.GetOutput().GetBlock(i).GetBlock(j)
if data is None:
continue
# POINT
p_data = fineReader.GetOutput().GetBlock(i).GetBlock(j).GetPointData()
for k in xrange(p_data.GetNumberOfArrays()):
name = p_data.GetArray(k).GetName()
if fineReader.GetPointResultArrayStatus(name):
interpolate(name, i, j, 'POINT')
# CELL
c_data = fineReader.GetOutput().GetBlock(i).GetBlock(j).GetCellData()
for k in xrange(c_data.GetNumberOfArrays()):
name = c_data.GetArray(k).GetName()
if fineReader.GetElementResultArrayStatus(name):
interpolate(name, i, j, 'CELL')
# GLOBAL
fineInterpolatorGeometry = vtk.vtkCompositeDataGeometryFilter()
fineInterpolatorGeometry.SetInputData(0, interpReader.GetOutput())
fineInterpolatorGeometry.Update()
fineInterpolateAttibutesMapper = vtk.vtkPolyDataMapper()
fineInterpolateAttibutesMapper.SetInputConnection(fineInterpolatorGeometry.GetOutputPort(0))
fineInterpolateAttibutesMapper.SelectColorArray(variable)
if variable == 'cell':
fineInterpolateAttibutesMapper.SetScalarModeToUseCellFieldData()
elif variable == 'point':
fineInterpolateAttibutesMapper.SetScalarModeToUsePointFieldData()
fineInterpolateAttibutesMapper.InterpolateScalarsBeforeMappingOn()
fineInterpolateAttibutesMapper.SetScalarRange(*range)
fineInterpolateAttibutesActor = vtk.vtkActor()
fineInterpolateAttibutesActor.SetMapper(fineInterpolateAttibutesMapper)
fineInterpolateAttibutesActor.GetProperty().SetEdgeVisibility(True)
fineInterpolateAttibutesMapperRenderer = vtk.vtkRenderer()
fineInterpolateAttibutesMapperRenderer.AddActor(fineInterpolateAttibutesActor)
fineInterpolateAttibutesMapperRenderer.SetViewport(0.33, 0, 0.66, 1)
####################################################################################################
# Window and Interactor
window = vtk.vtkRenderWindow()
window.AddRenderer(fineRenderer)
window.AddRenderer(fineInterpolateAttibutesMapperRenderer)
window.AddRenderer(coarseRenderer)
window.SetSize(1920, 1080)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
interactor.Initialize()
window.Render()
interactor.Start()