[vtkusers] Vertices with defined normal - visualization problem

David Doria daviddoria at gmail.com
Sun Dec 2 11:10:58 EST 2012


On Sun, Dec 2, 2012 at 8:07 AM, amutka <alan.mutka at gmail.com> wrote:
> Dear All,
> i have problem with visualization of vtkPolyData which contains
> points(vertices). If I set normals for each point then in visualization I
> can see point only if the normal shows toward the camera. The backface
> culling effect cannot be disabled what ever I do.
> I have tried everything, changing the backface cooling parameters, adding
> additional scalars, changing all possible vtkActor propery and mapper
> parameters. Please help.
>
> Here is a simple example...based on online example adding normals to
> vertices
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataCellNormals
>
> Here is my example...
> ........................................................
> /vtkSmartPointer<vtkPoints> points =  vtkSmartPointer<vtkPoints>::New();
> points->InsertNextPoint(1.0, 0.0, 0.0);
> points->InsertNextPoint(0.0, 0.0, 0.0);
> points->InsertNextPoint(0.0, 1.0, 0.0);
>
> vtkSmartPointer<vtkCellArray>
> cloudCells=vtkSmartPointer<vtkCellArray>::New();
> for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++)
> {
>           cloudCells->InsertNextCell(1, &i);
> }
>
>   *// Add the points to a polydata*
>   vtkSmartPointer<vtkPolyData> polydata =
> vtkSmartPointer<vtkPolyData>::New();
>   polydata->SetPoints(points);
>   polydata->SetVerts(cloudCells);/
>
> *///NOW CREATE NORMALS*
>   vtkSmartPointer<vtkDoubleArray> pointNormalsArray =
>     vtkSmartPointer<vtkDoubleArray>::New();
>   pointNormalsArray->SetNumberOfComponents(3); //3d normals (ie x,y,z)
>   pointNormalsArray->SetNumberOfTuples(polydata->GetNumberOfPoints());
>
> *  // Construct the normal vectors*
> /  double pN1[3] = {1.0, 0.0, 0.0};
>   double pN2[3] = {0.0, 1.0, 0.0};
>   double pN3[3] = {0.0, 0.0, 1.0};/
>
>  * // Add the data to the normals array*
> /  pointNormalsArray->SetTuple(0, pN1) ;
>   pointNormalsArray->SetTuple(1, pN2) ;
>   pointNormalsArray->SetTuple(2, pN3) ;/
>
> *//ADD NORMALS TO POLYDATA*
>
> /polydata->GetPointData()->SetNormals(pointNormalsArray);
>
>   vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();
>   mapper->SetInput(polydata);
>   mapper->SetColorModeToMapScalars();/
>
>
> *  //RENDERING*
>
>  / vtkActor * actor= vtkActor::New();
>   actor->GetProperty()->SetColor(1,1,0);
>   actor->SetMapper(mapper);
>   actor->GetProperty()->SetOpacity(0.8);
>
>    vtkRenderWindowInteractor * iren1 = vtkRenderWindowInteractor::New();
>   vtkRenderer * ren1 = vtkRenderer::New();
>   vtkRenderWindow * renWin = vtkRenderWindow::New();
>
>   ren1->AddActor(actor);
>   ren1->SetBackground(0,0,0);
>
>   renWin->AddRenderer(ren1);
>   iren1->SetRenderWindow(renWin);
>   iren1->Initialize();
>   iren1->Start();/
>
>
>

You just need:

 actor->GetProperty()->SetInterpolationToFlat();

Also, when you post examples, make sure they don't have extra
characters (/ and *) all around that have to be deleted, and include
the include statements. This way we can copy+paste+compile to help you
faster.

David



More information about the vtkusers mailing list