[vtkusers] No result when probing unstructured grid.
Sergey Ryadno
sergey.ryadno at gmail.com
Mon Feb 27 06:16:11 EST 2012
Hi,
i have problem when i try to probe vtkUnstructuredGrid with
vtkProbeFilter. in result i have only blank plane without any expected
result. What i am doing wrong?
code example see below..
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
#define SIZE_X 10
#define SIZE_Y 5
#define SIZE_Z 1
#define SHIFT_X 150
#define SHIFT_Y 150
#define CELL_SIZE 5
//create grid 10x10x1
void createUnstrGrid(vtkUnstructuredGrid* grid)
{
VTK_CREATE(vtkPoints, points);
VTK_CREATE(vtkIdList, idList);
points->Allocate(SIZE_X*SIZE_Y*8); // 8 coords for each cell
int pointIndx = 0;
for(int y = 0; y < SIZE_Y; y++)
{
for(int x = 0; x < SIZE_X; x++)
{
// bottom side
points->InsertNextPoint(CELL_SIZE*x, CELL_SIZE*y, CELL_SIZE); // 0
points->InsertNextPoint(CELL_SIZE*x + CELL_SIZE, CELL_SIZE*y, CELL_SIZE);
// 1
points->InsertNextPoint(CELL_SIZE*x + CELL_SIZE, CELL_SIZE*y, CELL_SIZE*0);
// 2
points->InsertNextPoint(CELL_SIZE*x, CELL_SIZE*y, CELL_SIZE*0); // 3
//top side
points->InsertNextPoint(CELL_SIZE*x, CELL_SIZE*y + CELL_SIZE, CELL_SIZE);
// 4
points->InsertNextPoint(CELL_SIZE*x + CELL_SIZE, CELL_SIZE*y + CELL_SIZE,
CELL_SIZE); // 5
points->InsertNextPoint(CELL_SIZE*x + CELL_SIZE, CELL_SIZE*y + CELL_SIZE,
CELL_SIZE*0); // 6
points->InsertNextPoint(CELL_SIZE*x, CELL_SIZE*y + CELL_SIZE, CELL_SIZE*0);
// 7
grid->SetPoints(points);
idList->Reset();
idList->InsertNextId(pointIndx++); // 0
idList->InsertNextId(pointIndx++); // 1
idList->InsertNextId(pointIndx++); // 2
idList->InsertNextId(pointIndx++); // 3
idList->InsertNextId(pointIndx++); // 4
idList->InsertNextId(pointIndx++); // 5
idList->InsertNextId(pointIndx++); // 6
idList->InsertNextId(pointIndx++); // 7
grid->InsertNextCell(VTK_HEXAHEDRON, idList);
}
}
grid->Update();
VTK_CREATE(vtkFloatArray, scalars);
float val_x = 0.1;
float val_y = 0.05;
for(int y = 0; y < SIZE_Y; y++)
{
for(int x = 0; x < SIZE_X; x++)
{
scalars->InsertNextValue(y*val_y +x*val_x);
}
}
grid->GetCellData()->SetScalars(scalars);
grid->Update();
return;
}
int main(int argc, char* argv[])
{
vtkRenderer *renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
renderer->Delete();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renWin->Delete();
VTK_CREATE(vtkUnstructuredGrid, grid);
createUnstrGrid(grid);
vtkIndent indent;
grid->PrintSelf(cout, indent);
// Create the probe plane
vtkPlaneSource *plane = vtkPlaneSource::New();
plane->SetResolution(200, 200);
vtkTransform *transp = vtkTransform::New();
transp->Translate(10.0, 10.0 ,0);
transp->Scale(20, 20, 20);
transp->RotateX(90);
vtkTransformPolyDataFilter *tpd = vtkTransformPolyDataFilter::New();
tpd->SetInputConnection(0, plane->GetOutputPort(0));
tpd->SetTransform(transp);
tpd->Update();
vtkProbeFilter *probe= vtkProbeFilter::New();
probe->SetInputConnection(0, tpd->GetOutputPort(0));
probe->SetSource(grid);
probe->Update();
assert(probe->GetOutput()!=0);
// This creates a blue to red lut.
vtkLookupTable *lut = vtkLookupTable::New();
lut->SetHueRange (0.667, 0.0);
vtkDataSetMapper *gridMapper = vtkDataSetMapper::New();
vtkDataSetMapper *planeMapper = vtkDataSetMapper::New();
planeMapper->SetLookupTable(lut);
gridMapper->SetInputConnection(grid->GetProducerPort());
planeMapper->SetInputConnection(probe->GetOutputPort());
if(probe->GetOutput()->GetPointData()!= 0)
{
if(probe->GetOutput()->GetPointData()->GetScalars()!= 0) // it always == 0!
why??
{
planeMapper->SetScalarRange( probe->GetOutput()->GetPointData()->
GetScalars()->GetRange());
}
}
vtkActor *gridActor = vtkActor::New();
gridActor->SetMapper(gridMapper);
gridActor->GetProperty()->SetEdgeColor(0.0, 0.0, 0.0);
gridActor->GetProperty()->SetEdgeVisibility(1);
vtkActor *planeActor = vtkActor::New();
planeActor->SetMapper(planeMapper);
renderer->AddActor(planeActor);
// renderer->AddActor(gridActor);
// Standard testing code.
renderer->SetBackground(0.5,0.5,0.5);
renWin->SetSize(300,300);
renWin->Render();
iren->Start();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120227/49277af2/attachment.htm>
More information about the vtkusers
mailing list