[vtkusers] Smooth shading
Yoshinori KONISHI
ykoni at ari.ncl.omron.co.jp
Fri May 16 01:15:20 EDT 2014
Dear Simon,
The imported data has no normal information as you pointed.
I added some codes for normal calculation and can get a
smoothly shaded result.
Thank you for your advice :-)
(VTK 6.1, Win7 64bit)-----------------------------------
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
polyData->DeepCopy(reader->GetOutput());
// calculate normals
vtkSmartPointer<vtkPolyDataNormals> normalGenerator = vtkSmartPointer<vtkPolyDataNormals>::New();
normalGenerator->SetInputData(polyData);
normalGenerator->ComputePointNormalsOn();
normalGenerator->ComputeCellNormalsOn();
normalGenerator->Update();
polyData = normalGenerator->GetOutput();
vtkSmartPointer<vtkPolyDataMapper> cadMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
cadMapper->SetInputData(polyData);
vtkSmartPointer<vtkActor> cadActor = vtkSmartPointer<vtkActor>::New();
cadActor->SetMapper(cadMapper);
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
ren1->AddActor(cadActor);
ren1->SetBackground(0.1, 0.2, 0.4);
-------------------------------------------------------------
>Hi,
>
>I think you need to generate the normals in order to have a proper shading.
>If you add a vtkPolyDataNormals filter to your pipeline right after the
>reader, it should look better (If i understand the problem properly !)
>This example should help :
>http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals
>Good luck
>Simon
>
>
>2014-05-15 11:10 GMT+02:00 Yoshinori KONISHI <ykoni at ari.ncl.omron.co.jp>:
>
>> Hello all,
>>
>> Though I am trying to get a smooth shaded CAD object (.stl),
>> the rendered image looks like that of flat shading (not smooth).
>> Could anyone tell me how to correct my code ?
>>
>> --------------------------- (VTK 6.1.0 on Win7 64bit)
>> vtkSmartPointer<vtkSTLReader> reader =
>> vtkSmartPointer<vtkSTLReader>::New();
>> reader->SetFileName(inputFilename.c_str());
>> reader->Update();
>>
>> vtkSmartPointer<vtkPolyDataMapper> cadMapper =
>> vtkSmartPointer<vtkPolyDataMapper>::New();
>> cadMapper->SetInputConnection(reader->GetOutputPort());
>>
>> vtkSmartPointer<vtkActor> cadActor =
>> vtkSmartPointer<vtkActor>::New();
>> cadActor->SetMapper(cadMapper);
>> cadActor->GetProperty()->SetInterpolation(VTK_GOURAUD);
>>
>> vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
>> ren1->AddActor(cadActor);
>> ren1->SetBackground(0.1, 0.2, 0.4);
>>
>> vtkSmartPointer<vtkRenderWindow> renWin =
>> vtkSmartPointer<vtkRenderWindow>::New();
>> renWin->AddRenderer(ren1);
>> renWin->SetSize(640, 480);
>> --------------------------------------
>>
>> Thank you.
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>
>
>
>--
>------------------------------------------------------------------
>Simon Esneault
>13 rue Vasselot
>35000 Rennes, France
>Tel : 06 64 61 30 94
>Mail : simon.esneault at gmail.com
>------------------------------------------------------------------
>
>
>---html-part included links-------
>mailto:ykoni at ari.ncl.omron.co.jp
>http://www.kitware.com
>mailto:simon.esneault at gmail.com
--
Yoshinori KONISHI
Technology Development Center
OMRON Corporation
Phone: +81-774-74-2162
FAX: +81-774-74-2002
Toll: 7-232-6562
E-mail: ykoni at ari.ncl.omron.co.jp
More information about the vtkusers
mailing list