[vtkusers] How to set the normals for a surface ?

Konstantinos Kelg kkelgeor at yahoo.gr
Thu Apr 2 09:06:05 EDT 2009


OK. I found it !
I needed to set myself the normals for each vertex (I had the vertex normal data).
In the following code the "NormP" is a pointer to a float array that contains the normal vector coordinates :
{vertNorm1_x, vertNorm1_y, vertNorm1_z, vertNorm2_x, vertNorm2_y, vertNorm2_z, ...}

vtkFloatArray* arr = vtkFloatArray::New();
arr->SetNumberOfComponents(3);
arr->SetArray((float*)NormP, m_NumOfVertices, 0/*NormP will be deleted by VTK*/);
polyData->GetPointData()->SetNormals(arr);
arr->Delete();

I should call "GetPointData()->SetNormals(..)" to set the vertex normals. I guess the "GetCellData()->SetNormals(..)" sets the normals for each triangle (cell).
Reasonable enough...
Thanks.

--- Στις Πέμ., 02/04/09, ο/η 王君臣 <wangjunchen at gmail.com> έγραψε:

> Από: 王君臣 <wangjunchen at gmail.com>
> Θέμα: Re: [vtkusers] How to set the normals for a surface ?
> Προς: kkelgeor at yahoo.gr, "VTKUserMailLIst" <vtkusers at vtk.org>
> Ημερομηνία: Πέμπτη, 2 Απρίλιος 2009, 11:47
> 2009/4/2 Konstantinos Kelg <kkelgeor at yahoo.gr>
> 
> >
> > Hello,
> >
> >
> > I need to set the normals of a surface.
> > I have 1 normal for each vertex of the mesh.
> > I try this but I get a crash:
> >
> >
> > vtkFloatArray* arr = vtkFloatArray::New();
> > arr->SetNumberOfComponents(3);
> > arr->SetArray((float*)NormP, m_NumOfVertices, 0);
> > polyData->GetCellData()->SetNormals(arr);
> > arr->Delete();
> >
> >
> > I found this piece of code on the web but it's not
> complete:
> >
> > vtkPolyDataNormals *normals =
> vtkPolyDataNormals::New();
> > normals->SetInput(yourData); // Is
> "yourData" the normals per vertex ?
> 
>                                ~~~~~~~yourData is the
> polydata whose vertex
> normal is to be calculated, and the ouput of the
> vtkPolyDataNormals is the
> polydata that contains the normals, you can check the
> instance of the
> vtkPointData or vtkCellData to retrieve the normals
> 
> >
> > normals->ComputeCellNormalsOn();
> > normals->ComputePointNormalsOff();
> > normals->Update();
> >
> > Does anyone know which is the way to do this and how
> do I actually set the
> > vtkPolyDataNormals if I should follow the 2nd way ?
> >
> > Thanks.
> >
> >
> >
> >
> >
> >
> ___________________________________________________________
> > Χρησιμοποιείτε Yahoo!;
> > Βαρεθήκατε τα ενοχλητικά
> μηνύματα (spam); Το Yahoo! Mail
> > διαθέτει την καλύτερη δυνατή
> προστασία κατά των ενοχλητικών
> > μηνυμάτων
> http://login.yahoo.com/config/mail?.intl=gr
> >
> >
> > _______________________________________________
> > 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
> >
> 
> 
> 
> -- 
> 王君臣


      
___________________________________________________________ 
Χρησιμοποιείτε Yahoo!; 
Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail 
διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών 
μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr 





More information about the vtkusers mailing list