[vtkusers] need help using vtkHyperOctree and vtkHyperOctreeContourFilter
Rob Harris
rharris at iastate.edu
Tue Oct 14 22:21:02 EDT 2008
I am still unable to plot correct contours on a vtkHyperOctree. Again, as a
simple test case I would like to plot lines of constant x on a unit square.
For this, I have defined a 2D vtkHyperOctree of 16 cells (4x4). The grid is
plotted correctly, but the contours are incorrect. Here is the my xml grid
file (vto file):
<?xml version="1.0"?>
<VTKFile type="HyperOctree" version="0.1" byte_order="LittleEndian"
compressor="vtkZLibDataCompressor">
<HyperOctree Dimension="2" Size="1 1 0.5" Origin="0.5 0 0">
<Topology>
<DataArray type="Int32" Name="Topology" NumberOfTuples="21"
format="ascii" RangeMin="0" RangeMax="1">
0 0 1 1 1 1
0 1 1 1 1 0
1 1 1 1 0 1
1 1 1
</DataArray>
</Topology>
<PointData Scalars="LinearFunction">
<DataArray type="Float64" Name="LinearFunction" format="ascii"
RangeMin="0.125" RangeMax="0.875">
0.125 0.375 0.125 0.375 0.625 0.875
0.625 0.875 0.125 0.375 0.125 0.375
0.625 0.875 0.625 0.875
</DataArray>
</PointData>
<CellData>
</CellData>
</HyperOctree>
</VTKFile>
I read in this file and render with the code below:
#include "vtkActor.h"
#include "vtkDataSetMapper.h"
#include "vtkPolyDataMapper.h"
#include "vtkOutputWindow.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkHyperOctree.h"
#include "vtkXMLHyperOctreeReader.h"
#include "vtkProperty.h"
#include "vtkHyperOctreeContourFilter.h"
#include "vtkLookupTable.h"
int main(int argc, char* argv[])
{
int NCONTOURS = 5;
vtkOutputWindow::GetInstance()->PromptUserOn();
// read in *.vto grid
vtkXMLHyperOctreeReader *xmlReader=vtkXMLHyperOctreeReader::New();
xmlReader->SetFileName(argv[1]);
xmlReader->Update();
vtkHyperOctreeContourFilter *contour=vtkHyperOctreeContourFilter::New();
double
*range=xmlReader->GetOutput()->GetPointData()->GetScalars()->GetRange();
contour->SetNumberOfContours(NCONTOURS);
contour->GenerateValues(NCONTOURS,range[0],range[1]);
contour->SetInputConnection(0,xmlReader->GetOutputPort(0));
contour->Update();
vtkPolyDataMapper *smapper;
smapper=vtkPolyDataMapper::New();
vtkLookupTable *lut3d = vtkLookupTable::New();
lut3d->SetHueRange(0.667,0.0);
smapper->SetInputConnection(0,contour->GetOutputPort(0));
smapper->SetLookupTable(lut3d);
smapper->SetScalarRange(xmlReader->GetOutput()->GetPointData()->GetScalars()->GetRange());
// setup actor
vtkActor *actor = vtkActor::New();
actor->SetMapper(smapper);
// render now
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(actor);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renWin->SetFullScreen(1);
renWin->Render();
iren->Start();
// free memory here
xmlReader->Delete();
smapper->Delete();
actor->Delete();
ren->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
Using the above, the grid is rendered correctly but the contours are
completely incorrect. I must have something fundamentally wrong here, and I
am unable to find any documentation to point me in the right direction. I
would be extremely grateful if anyone could help me figure this out.
Thanks,
-Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081014/20bac3bd/attachment.htm>
More information about the vtkusers
mailing list