[vtkusers] Rendering/Computing normals of a surface
Bill Lorensen
bill.lorensen at gmail.com
Fri Apr 12 08:57:03 EDT 2013
2) vtkPlaneSource generates normals. Many of the source's do.
After
normalGenerator->Update();
try
normalGenerator->GetOutput()->Print(std::cout);
to see if there are normals present
On Fri, Apr 12, 2013 at 8:45 AM, Kilgus, Thomas <t.kilgus at dkfz-heidelberg.de
> wrote:
> Unfortunately, that is a bit complicated and inside our own framework. But
> basically, this happens:****
>
> ** **
>
> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();****
>
> points->SetDataTypeToDouble();****
>
> vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
> ****
>
> ** **
>
> for loop for all pixels of the depth image****
>
> {****
>
> Insert 3d point into points****
>
> ** **
>
> Insert cell points for valid (!=0) points with valid neighbors (simple
> triangulation)****
>
> }****
>
> ** **
>
> vtkSmartPointer<vtkPolyData> mesh = vtkSmartPointer<vtkPolyData>::New();**
> **
>
> mesh->SetPoints(points);****
>
> mesh->SetPolys(polys);****
>
> ** **
>
> We also add texture coordinates and scalars, but this is not related to
> normals, is it?****
>
> ** **
>
> You can see the details here:
> http://mitk.org/git/?p=MITK.git;a=blob;f=Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp;h=2b24b193315c2db97bce1d4f8aed90df42c99d1f;hb=HEAD
> ****
>
> ** **
>
> My questions 3. and 4. are not related to the Kinect data, are they?****
>
> ** **
>
> Regards,****
>
> Thomas****
>
> ** **
>
> ** **
>
> ** **
>
> *From:* Bill Lorensen [mailto:bill.lorensen at gmail.com]
> *Sent:* Freitag, 12. April 2013 14:36
> *To:* Kilgus, Thomas
> *Cc:* vtkusers at vtk.org
> *Subject:* Re: [vtkusers] Rendering/Computing normals of a surface****
>
> ** **
>
> How are you creating your Kinect mesh?****
>
> ** **
>
> On Fri, Apr 12, 2013 at 8:28 AM, Kilgus, Thomas <
> t.kilgus at dkfz-heidelberg.de> wrote:****
>
> Hi everyone,****
>
> ****
>
> I’m trying to compute and render normals of certain vertices of a mesh (in
> fact a Kinect mesh). I assume that I have to compute the normals via
> vtkPolyDataNormals and display them using a vtkGlyph3d? ****
>
> ****
>
> I observed some strange behavior which really confused me:****
>
> ****
>
> 1. If I create a vtkPlaneSource or load a ball from hard disc and
> compute normals for that data, everything seems fine. If I load an “open”
> surface (my Kinect mesh), there are no normals displayed. The documentation
> says that SetAutoOrientNormals does only work with closed surfaces. But at
> the moment I don’t care about orientation. There should be normals for at
> least some vertices of an open mesh, shouldn’t there?****
>
> 2. If I load my Kinect mesh and make a new polydata which contains
> as much points at (0,0,0) as I have normals and set the normals for the new
> polydata, the glyph will produce arrows pointing from (0,0,0) to somewhere.
> This looks pretty good could but could be a random result with empty
> memory. ****
>
> 3. If I connect my vtkPlaneSource or the ball directly to the glyph
> (I skip the vtkPolyDataNormals), normals are still rendered correctly. Does
> this mean my vtkPlaneSource already contains them from the beginning? Are
> they computed in the background somewhere inside the glyph3d? Is the
> vtkPolyDataNormals even necessary? This only works for the plane and the
> ball - not for the Kinect mesh. I can imagine that a plane automatically
> computes its normal on Update(), but why does my ball have normals already?
> ****
>
> 4. How can I get the normal of a certain vertex Id? If I use
> vtkFloatArray::SafeDownCast(output->GetPointData()->GetNormals()) are Id’s
> equal to the vertex Id’s of the polydata? What happens if I turn splitting
> on and get multiple normals for each vertex? How is the mapping done?****
>
> ****
>
> My code looks as follows:****
>
> ****
>
> vtkSmartPointer<vtkPolyData> inputPolyData = //load some data****
>
> ****
>
> // Generate normals****
>
> vtkSmartPointer<vtkPolyDataNormals> normalGenerator =
> vtkSmartPointer<vtkPolyDataNormals>::New();****
>
> normalGenerator->SetInput( inputPolyData );****
>
> normalGenerator->ComputePointNormalsOn();****
>
> normalGenerator->ComputeCellNormalsOff();****
>
> normalGenerator->SetSplitting(0); //I want exactly one normal per vertex
> ****
>
> normalGenerator->Update();****
>
> ****
>
> vtkSmartPointer<vtkPolyDataMapper> mapperNormals =****
>
> vtkSmartPointer<vtkPolyDataMapper>::New();****
>
> ****
>
> //I chose arrows as representation****
>
> vtkSmartPointer<vtkArrowSource> arrow =
> vtkSmartPointer<vtkArrowSource>::New();****
>
> arrow->Update();****
>
> ****
>
> //use the output of vtkPolyDataNormals as input for the glyph3d****
>
> vtkSmartPointer<vtkGlyph3D> glyph =
> vtkSmartPointer<vtkMaskedGlyph3D>::New();****
>
> glyph->SetInput( normalGenerator->GetOutput() );****
>
> glyph->SetSourceConnection(arrow->GetOutputPort());****
>
> glyph->OrientOn();****
>
> glyph->SetVectorModeToUseNormal();****
>
> glyph->Update();****
>
> ****
>
> mapperNormals->SetInputConnection(glyph->GetOutputPort());****
>
> ****
>
> //now follows standard code which could be taken from almost any example…*
> ***
>
> vtkSmartPointer<vtkActor> actorNormals =****
>
> vtkSmartPointer<vtkActor>::New();****
>
> actorNormals->SetMapper(mapperNormals);****
>
> ****
>
> // Create a renderer, render window, and interactor****
>
> vtkSmartPointer<vtkRenderer> renderer =****
>
> vtkSmartPointer<vtkRenderer>::New();****
>
> vtkSmartPointer<vtkRenderWindow> renderWindow =****
>
> vtkSmartPointer<vtkRenderWindow>::New();****
>
> renderWindow->AddRenderer(renderer);****
>
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =****
>
> vtkSmartPointer<vtkRenderWindowInteractor>::New();****
>
> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();****
>
> renderWindowInteractor->SetInteractorStyle(style);****
>
> renderWindowInteractor->SetRenderWindow(renderWindow);****
>
> ****
>
> // Add the actor to the scene****
>
> renderer->AddActor(actorNormals);****
>
> ****
>
> // Render and interact****
>
> renderWindow->Render();****
>
> renderWindowInteractor->Start();****
>
> ****
>
> Regards,****
>
> Thomas****
>
> ****
>
> ****
>
> Thomas Kilgus****
>
> German Cancer Research Center (DKFZ)****
>
> Div. Medical and Biological Informatics ****
>
> Junior group: Computer-assisted Interventions (E131)****
>
> Im Neuenheimer Feld 280****
>
> 69120 Heidelberg, Germany****
>
> Phone: +49(0) 6221-42-3545****
>
> ****
>
>
> _______________________________________________
> 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****
>
>
>
> ****
>
> ** **
>
> --
> Unpaid intern in BillsBasement at noware dot com****
>
--
Unpaid intern in BillsBasement at noware dot com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130412/a419bdb3/attachment.htm>
More information about the vtkusers
mailing list