[vtkusers] Only flat shading with VRML data

Mika Fischer mika.fischer at zoopnet.de
Fri Jul 6 05:21:39 EDT 2012


Hi,

first of all I have to say that is the first time that I use vtk and I
don't have much experience with 3D graphics.

I have a 3d triangle mesh of a face in wrl format. I also managed to
display it. However the shading of the triangles seems to be flat.
Calling SetInterpolationToGouraud() or SetInterpolationToFlat() seems
to make no difference.

The code used to load the data and display it is below. Am I missing
an important step here?

Also, if I load the file in ParaView, it has the same issue and
switching from Flat to Gouraud makes no visible difference. However if
I use a CylinderSource, the shading is smooth as I would expect it
(and switching to flat makes a huge difference).

Here's a screenshot of the data in paraview: http://zoopnet.de/vrml.png

Any tips would be very much appreciated!

Best,
 Mika

-------------------------------------
vtkSmartPointer<vtkVRMLImporter> importer =
vtkSmartPointer<vtkVRMLImporter>::New();
importer->SetFileName(fileWrl.c_str());
importer->Read();
importer->Update();

vtkActorCollection* actors = importer->GetRenderer()->GetActors();
actors->InitTraversal();
vtkDataSet* pDataset = actors->GetNextActor()->GetMapper()->GetInput();

vtkPolyData* polyData = vtkPolyData::SafeDownCast(pDataset);
polyData->Update();

vtkSmartPointer<vtkPolyDataNormals> skinNormals =
vtkSmartPointer<vtkPolyDataNormals>::New();
skinNormals->SetFeatureAngle(90.0);
skinNormals->SetInput(polyData);
skinNormals->Update();

vtkSmartPointer<vtkPolyDataMapper> solidMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
solidMapper->SetInputConnection(skinNormals->GetOutputPort());
solidMapper->ScalarVisibilityOff();

vtkSmartPointer<vtkActor> solidActor = vtkSmartPointer<vtkActor>::New();
solidActor->SetMapper(solidMapper);
solidActor->GetProperty()->SetInterpolationToGouraud();

-------------------------------------



More information about the vtkusers mailing list