[vtkusers] [VTKUser] Help! How to visualize F(x,y,z)=x^2
wuhanzymail
wuhanzymail at 163.com
Sun Sep 30 17:50:48 EDT 2007
Hi everyone, I want to visualize a this function: F(x,y,z)=x^2 using the vtkContourFilter, but there is no output in my renderwindow. I am novice to the VTK, I don't know what's wrong with my c++ code. Would you please help me? Thank you very much! // Create DateSet
static float x[POINTS_DIM]={1,2,3,4,5,6,7,8,9,10};
static float y[POINTS_DIM]={1,2,3,4,5,6,7,8,9,10};
static float z[POINTS_DIM]={1,2,3,4,5,6,7,8,9,10};
vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::New();
vtkPoints *newPts = vtkPoints::New();
vtkFloatArray *newScalars = vtkFloatArray::New(); int index = 0; for(int i=0; i<POINTS_DIM; i++){
for(int j=0; j<POINTS_DIM; j++){
for(int k=0; k<POINTS_DIM; k++){
newPts->InsertPoint(index++, x[i], y[j], z[k]);
newScalars->InsertValue(index, pow(x[i],2));
}
}
} dataSet->SetPoints(newPts);
dataSet->GetPointData()->SetScalars(newScalars); newPts->Delete(); //reference counted - it's okay
newScalars->Delete(); // Construct pipeline
vtkContourFilter *popSurface = vtkContourFilter::New();
popSurface->SetInput(dataSet);
popSurface->GenerateValues(5,1,100);
vtkPolyDataMapper *popMapper = vtkPolyDataMapper::New();
popMapper->SetInputConnection(popSurface->GetOutputPort());
popMapper->ScalarVisibilityOff();
vtkActor *popActor = vtkActor::New();
popActor->SetMapper(popMapper);
popActor->GetProperty()->SetOpacity(0.3);
popActor->GetProperty()->SetColor(.9,.9,.9); // Create an instance of vtkRenderer
vtkRenderer *ren1= vtkRenderer::New();
ren1->SetBackground( 1, 1, 1 );
ren1->AddActor(popActor); // Create an instance of vtkRenderWindow
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren1 );
renWin->SetSize( 300, 300 ); // Create an instance of vtkRenderWindowInteractor
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin); iren->Initialize(); renWin->Render();
iren->Start();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20071001/a3ecf32d/attachment.htm>
More information about the vtkusers
mailing list