[vtkusers] HierarchicalBoxPipeline

jelle jelleferinga at gmail.com
Mon Aug 27 06:15:49 EDT 2007



Hi,

Currently I'm working on a project for which I'd like to use the AMR 
facilities in vtk. So I started to convert HierarchicalBoxPipeline.cxx -> 
HierarchicalBoxPipeline.py as a start.

Somehow I wasn't able to get the vtkOutlineFilter to work, but I'm afraid I 
haven't been able to work my way around it. Likely this is because this method 
just supports SetInput while the rest of the program is using 
SetInputConnection? What am I doing wrong here?

What's worse is that the program crashes, while not spitting out any error 
info, making it hard to debuf this. The render window appears, displays the 
geometry correctly and pretty much halts after this. Might this be due to the 
way I've set up the render?

Many thanks,

-jelle

## This example demonstrates how hierarchical box (uniform rectilinear)
## AMR datasets can be processed using the new vtkHierarchicalBoxDataSet 

import vtk
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

xml_file = VTK_DATA_ROOT + '\\Data\\chombo3d\\chombo3d.vtm'

'''
  vtkXMLHierarchicalBoxDataReader* reader = 
    vtkXMLHierarchicalBoxDataReader::New();
  reader->SetFileName(cfname);
  delete[] cfname;
'''
reader = vtk.vtkXMLHierarchicalBoxDataReader()
reader.SetFileName(xml_file)

'''
  // geometry filter
  vtkHierarchicalDataSetGeometryFilter* geom = 
    vtkHierarchicalDataSetGeometryFilter::New();
  geom->SetInput(0, reader->GetOutputPort(0));
'''

geom = vtk.vtkHierarchicalDataSetGeometryFilter()
geom.SetInputConnection(reader.GetOutputPort(0))

'''
  vtkShrinkPolyData* shrink = vtkShrinkPolyData::New();
  shrink->SetShrinkFactor(0.5);
  shrink->SetInput(0, geom->GetOutputPort(0));
'''

shrink = vtk.vtkShrinkPolyData()
shrink.SetShrinkFactor(0.5)
shrink.SetInputConnection( geom.GetOutputPort(0) )

'''
  // Rendering objects
  vtkHierarchicalPolyDataMapper* shMapper = vtkHierarchicalPolyDataMapper::New
();
  shMapper->SetInput(0, shrink->GetOutputPort(0));
  vtkActor* shActor = vtkActor::New();
  shActor->SetMapper(shMapper);
  shActor->GetProperty()->SetColor(0, 0, 1);
  ren->AddActor(shActor);
'''

#---fucks up!!---#000000#FFFFFF------------------------------------------------
-

sh_mapper = vtk.vtkHierarchicalPolyDataMapper()
sh_mapper.SetInputConnection(shrink.GetOutputPort(0))

sh_actor = vtk.vtkActor()
sh_actor.SetMapper(sh_mapper)
sh_actor.GetProperty().SetColor(0,0,1)


'''
  // corner outline
  vtkOutlineCornerFilter* ocf = vtkOutlineCornerFilter::New();
  ocf->SetInput(0, reader->GetOutputPort(0));
'''
#---ARGGGH---#000000#FFFFFF----------------------------------------------------
-
##ocf = vtk.vtkOutlineCornerFilter()
##ocf.SetInputConnection( reader.GetOutputPort(0) )

'''
  // Rendering objects
  // This one is actually just a vtkPolyData so it doesn't need a hierarchical
  // mapper, but we use this one to test hierarchical mapper with polydata 
input
  vtkHierarchicalPolyDataMapper* ocMapper = vtkHierarchicalPolyDataMapper::New
();
  ocMapper->SetInput(0, ocf->GetOutputPort(0));
  vtkActor* ocActor = vtkActor::New();
  ocActor->SetMapper(ocMapper);
  ocActor->GetProperty()->SetColor(1, 0, 0);
  ren->AddActor(ocActor);
'''
##oc_mapper = vtk.vtkHierarchicalPolyDataMapper()
##oc_mapper.SetInputConnection(ocf.GetOutputPort(0))
##
##oc_actor = vtk.vtkActor()
##oc_actor.SetMapper(oc_mapper)
##oc_actor.GetProperty().SetColor(1,0,0)

'''
  // cell 2 point and contour
  vtkHierarchicalDataExtractLevel* el = vtkHierarchicalDataExtractLevel::New();
  el->SetInput(0, reader->GetOutputPort(0));
  el->SetLevelRange(2,2);
'''

el = vtk.vtkHierarchicalDataExtractLevel()
el.SetInput( reader.GetOutput() )
el.SetLevelRange(2,2)

'''
  vtkCellDataToPointData* c2p = vtkCellDataToPointData::New();
  c2p->SetInput(0, el->GetOutputPort(0));
'''

c2p = vtk.vtkCellDataToPointData()
c2p.SetInputConnection(el.GetOutputPort(0))

'''
  vtkContourFilter* contour = vtkContourFilter::New();
  contour->SetInput(0, c2p->GetOutputPort(0));
  contour->SetValue(0, -0.013);
  contour->SetInputArrayToProcess(
    0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS,"phi");
'''

cf = vtk.vtkContourFilter()
cf.SetInputConnection(c2p.GetOutputPort(0))
cf.SetValue(0, -0.013)
#---NOT GETTING THIS PART!---#000000#FFFFFF------------------------------------
-
#cf.SetInputArrayToProcess( 0, 0 , 0, vtk.vtkDataObject.FIELD_ASSOCIATION
('phi'))

cf.SetInputArrayToProcess(0,0,0,0,'phi')

'''
  // Rendering objects
  vtkHierarchicalPolyDataMapper* contMapper = 
    vtkHierarchicalPolyDataMapper::New();
  contMapper->SetInput(0, contour->GetOutputPort(0));
  vtkActor* contActor = vtkActor::New();
  contActor->SetMapper(contMapper);
  contActor->GetProperty()->SetColor(1, 0, 0);
  ren->AddActor(contActor);
'''

cf_mapper = vtk.vtkHierarchicalPolyDataMapper()
cf_mapper.SetInputConnection( cf.GetOutputPort(0) )

cf_actor = vtk.vtkActor()
cf_actor.GetProperty().SetColor(1,0,0)

#---set up renderer---#000000#FFFFFF-------------------------------------------
-


ren = vtk.vtkRenderer()
ren.Background=(0.1,0.2,0.4)
ren.AddActor(cf_actor)
ren.AddActor(sh_actor)
#ren.AddActor(oc_actor)


rw = vtk.vtkRenderWindow()
rw.Size=(600, 600)
rw.AddRenderer(ren)

ren.ResetCamera()
ren.ResetCameraClippingRange()

rw.Initialize()
#rw.Render()
rw.Start() 




More information about the vtkusers mailing list