Commit 891dd74e authored by Dave DeMarle's avatar Dave DeMarle
Browse files

Make cell blanking work as expected in structured grids

This change makes it so that the default rendering path will
properly hide blanked cells. When surface filter is given
a structured grid with blanking, it now takes the slow
generic path because blanking will expose interior faces.
In there, it now skips blanked cells and treats faces of
cells that are shared with blanked cells as exterior faces.

Change-Id: I23d6397f8f9c7bbda3c366d160eaa03c4668be48
parent 8d10811c
......@@ -2,3 +2,4 @@ vtk_add_test_python(dataSetSurfaceFilter.py)
vtk_add_test_python(geomFilter.py)
vtk_add_test_python(officeStreamPoints.py)
vtk_add_test_python(rectGrid.py)
vtk_add_test_python(structuredGridBlanking.py)
#!/usr/bin/env python
#test exists to verify that structured grid blanking works as expected
import vtk
from vtk.test import Testing
#make up a toy structured grid with known characteristics
xlim=10
ylim=10
zlim=3
sg = vtk.vtkStructuredGrid()
sg.SetExtent(0,xlim,0,ylim,0,zlim)
#a handy point iterator, calls action() on each point
def forEachPoint(xlim,ylim,zlim, action):
for z in xrange(0,zlim+1):
for y in xrange(0,ylim+1):
for x in xrange(0,xlim+1):
action((x,y,z))
#make geometry
points = vtk.vtkPoints()
def makeCoordinate(pt):
points.InsertNextPoint(pt)
forEachPoint(xlim,ylim,zlim, makeCoordinate)
sg.SetPoints(points)
#make a scalar array
scalars = vtk.vtkDoubleArray()
scalars.SetNumberOfComponents(1)
scalars.SetName("Xcoord")
def makeScalar(pt):
scalars.InsertNextValue(pt[0]+pt[1]+pt[2])
forEachPoint(xlim,ylim,zlim, makeScalar)
sg.GetPointData().SetScalars(scalars)
#blank some arbitrarily chosen cells
numcells = sg.GetNumberOfCells()
if 11 < numcells:
sg.BlankCell(11)
if 64 < numcells:
sg.BlankCell(64)
if 164 < numcells:
sg.BlankCell(164)
for c in xrange(180,261):
if c < sg.GetNumberOfCells():
sg.BlankCell(c)
dsf = vtk.vtkDataSetSurfaceFilter()
dsf.SetInputData(sg)
dsf.Update()
nviscells = dsf.GetOutput().GetNumberOfCells()
if nviscells != 356:
print "Problem"
print "Test expected 356 visible surface polygons but got", \
nviscells
exit(-1)
#render it so we can look at it
mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(sg)
mapper.SetScalarRange(scalars.GetRange())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
ren.AddActor(actor)
renWin = vtk.vtkRenderWindow()
renWin.SetSize(400, 400)
renWin.AddRenderer(ren)
#set position where we can see most of the blanked cells
cam = ren.GetActiveCamera()
cam.SetClippingRange(14.0456, 45.4716)
cam.SetFocalPoint(5, 5, 1.5)
cam.SetPosition(-19.0905, -6.73006, -6.37738)
cam.SetViewUp(-0.400229, 0.225459, 0.888248)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()
#iren.Start()
......@@ -205,11 +205,18 @@ int vtkDataSetSurfaceFilter::RequestData(
case VTK_STRUCTURED_GRID:
{
vtkStructuredGrid *grid = vtkStructuredGrid::SafeDownCast(input);
int* tmpext = grid->GetExtent();
ext[0] = tmpext[0]; ext[1] = tmpext[1];
ext[2] = tmpext[2]; ext[3] = tmpext[3];
ext[4] = tmpext[4]; ext[5] = tmpext[5];
return this->StructuredExecute(grid, output, ext, wholeExt);
if (grid->GetCellBlanking())
{
return this->DataSetExecute(grid, output);
}
else
{
int* tmpext = grid->GetExtent();
ext[0] = tmpext[0]; ext[1] = tmpext[1];
ext[2] = tmpext[2]; ext[3] = tmpext[3];
ext[4] = tmpext[4]; ext[5] = tmpext[5];
return this->StructuredExecute(grid, output, ext, wholeExt);
}
}
case VTK_UNIFORM_GRID:
case VTK_STRUCTURED_POINTS:
......@@ -1059,12 +1066,14 @@ int vtkDataSetSurfaceFilter::DataSetExecute(vtkDataSet *input,
vtkCellData *cd = input->GetCellData();
vtkPointData *outputPD = output->GetPointData();
vtkCellData *outputCD = output->GetCellData();
if (numCells == 0)
{
return 1;
}
vtkStructuredGrid *sgridInput = vtkStructuredGrid::SafeDownCast(input);
bool mayBlank = sgridInput && sgridInput->GetCellBlanking();
cellIds = vtkIdList::New();
pts = vtkIdList::New();
......@@ -1100,6 +1109,10 @@ int vtkDataSetSurfaceFilter::DataSetExecute(vtkDataSet *input,
}
input->GetCell(cellId,cell);
if (mayBlank && !sgridInput->IsCellVisible(cellId))
{
continue;
}
switch (cell->GetCellDimension())
{
// create new points and then cell
......@@ -1125,7 +1138,21 @@ int vtkDataSetSurfaceFilter::DataSetExecute(vtkDataSet *input,
{
face = cell->GetFace(j);
input->GetCellNeighbors(cellId, face->PointIds, cellIds);
if ( cellIds->GetNumberOfIds() <= 0)
bool noNeighbors = cellIds->GetNumberOfIds()<=0;
if (!noNeighbors && mayBlank)
{
//faces with only blank neighbors count as external faces
noNeighbors = true;
for (vtkIdType ci = 0; ci < cellIds->GetNumberOfIds(); ci++)
{
if (sgridInput->IsCellVisible(cellIds->GetId(ci)))
{
noNeighbors = false;
break;
}
}
}
if ( noNeighbors )
{
npts = face->GetNumberOfPoints();
pts->Reset();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment