vtkSmartPointer<vtkPolyDataNormals> normalGenerator = vtkSmartPointer<vtkPolyDataNormals>::New();
normalGenerator->SetInput(src);
normalGenerator->ComputePointNormalsOn();
normalGenerator->ComputeCellNormalsOff();
normalGenerator->Update();
// 노멀 데이터를 받아온다. http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals 참고.
vtkFloatArray* normalDataFloat = vtkFloatArray::SafeDownCast(normalGenerator->GetOutput()->GetPointData()->GetArray("Normals"));
// Define some colors
unsigned char red[3] = {255, 0, 0};
unsigned char orange[3] = {255, 150, 0};
unsigned char green[3] = {0, 255, 0};
// Setup the colors array
vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
double viewNormal[3];
render->GetActiveCamera()->GetViewPlaneNormal(viewNormal);
for(int k=0; k<numPts; k++)
{
if(normalDataFloat && ???)
{
double polyNormal[3];
normalDataFloat->GetTuple(k, polyNormal);
if(viewNormal[0]*polyNormal[0]+viewNormal[1]*polyNormal[1]+viewNormal[2]*polyNormal[2] < 0.342) // 70도;
colors->InsertNextTupleValue(orange);
else
colors->InsertNextTupleValue(green);
}
else{
colors->InsertNextTupleValue(red);
}
}
src->GetPointData()->SetScalars(colors);
...
뷰의 normal 값을 받아 각 포인트와 내적을 계산. 여러가지 컬러로 출력.