[vtkusers] Rendering/Computing normals of a surface

Kilgus, Thomas t.kilgus at Dkfz-Heidelberg.de
Fri Apr 12 09:11:38 EDT 2013


Sorry for writing multiple mails. Thank you for your effort Bill!

Here is the output of the filter for my Kinect mesh. Do you see any reason why the glyph3d should not work with it?

vtkPolyData (0x29936d0)
  Debug: Off
  Modified Time: 708
  Reference Count: 1
  Registered Events: (none)
  Source: (none)
  Information: 0x2994680
  Data Released: False
  Global Release Data: Off
  UpdateTime: 727
  Release Data: Off
  UpdateExtent: Not Initialized
  Update Number Of Pieces: 1
  Update Piece: 0
  Update Ghost Level: 0
  MaximumNumberOfPieces: 1
  RequestExactExtent: Off
   Field Data:
    Debug: Off
    Modified Time: 297
    Reference Count: 2
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 233170
  Number Of Cells: 456138
  Cell Data:
    Debug: Off
    Modified Time: 702
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 1
    Array 0 name = Normals
    Number Of Components: 3
    Number Of Tuples: 456138
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals:
      Debug: Off
      Modified Time: 687
      Reference Count: 1
      Registered Events: (none)
      Name: Normals
      Data type: float
      Size: 1368414
      MaxId: 1368413
      NumberOfComponents: 3
      Information: 0
      Name: Normals
      Number Of Components: 3
      Number Of Tuples: 456138
      Size: 1368414
      MaxId: 1368413
      LookupTable: (none)
      Array: 0x4697260
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
  Point Data:
    Debug: Off
    Modified Time: 705
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 3
    Array 0 name = Scalars_
    Array 1 name = TCoords_
    Array 2 name = Normals
    Number Of Components: 6
    Number Of Tuples: 233170
    Copy Tuple Flags: ( 1 1 0 1 1 0 1 1 )
    Interpolate Flags: ( 1 1 0 1 1 0 0 1 )
    Pass Through Flags: ( 1 1 0 1 1 1 1 1 )
    Scalars:
      Debug: Off
      Modified Time: 349
      Reference Count: 2
      Registered Events: (none)
      Name: Scalars_
      Data type: float
      Size: 233170
      MaxId: 233169
      NumberOfComponents: 1
      Information: 0
      Name: Scalars_
      Number Of Components: 1
      Number Of Tuples: 233170
      Size: 233170
      MaxId: 233169
      LookupTable: (none)
      Array: 0x29a7f30
    Vectors: (none)
    Normals:
      Debug: Off
      Modified Time: 698
      Reference Count: 1
      Registered Events: (none)
      Name: Normals
      Data type: float
      Size: 699510
      MaxId: 699509
      NumberOfComponents: 3
      Information: 0
      Name: Normals
      Number Of Components: 3
      Number Of Tuples: 233170
      Size: 699510
      MaxId: 699509
      LookupTable: (none)
      Array: 0x4bcf7e0
    TCoords:
      Debug: Off
      Modified Time: 354
      Reference Count: 2
      Registered Events: (none)
      Name: TCoords_
      Data type: float
      Size: 466340
      MaxId: 466339
      NumberOfComponents: 2
      Information: 0
      Name: TCoords_
      Number Of Components: 2
      Number Of Tuples: 233170
      Size: 466340
      MaxId: 466339
      LookupTable: (none)
      Array: 0x2a8ba80
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
  Bounds:
    Xmin,Xmax: (-817.453, 791.692)
    Ymin,Ymax: (-401.920, 704.801)
    Zmin,Zmax: (590.000, 1467.000)
  Compute Time: 739
  Number Of Points: 233170
  Point Coordinates: 0x2998b70
  Locator: 0
  Number Of Vertices: 0
  Number Of Lines: 0
  Number Of Polygons: 456138
  Number Of Triangle Strips: 0
  Number Of Pieces: 1
  Piece: 0
  Ghost Level: 0

From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Kilgus, Thomas
Sent: Freitag, 12. April 2013 15:04
To: Bill Lorensen
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Rendering/Computing normals of a surface

And how would I get the normal of a certain vertex? Especially with SplittingOn()

From: Bill Lorensen [mailto:bill.lorensen at gmail.com]
Sent: Freitag, 12. April 2013 14:57
To: Kilgus, Thomas
Cc: vtkusers at vtk.org<mailto:vtkusers at vtk.org>
Subject: Re: [vtkusers] Rendering/Computing normals of a surface

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<mailto: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<mailto:bill.lorensen at gmail.com>]
Sent: Freitag, 12. April 2013 14:36
To: Kilgus, Thomas
Cc: vtkusers at vtk.org<mailto: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<mailto: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<tel:%2B49%280%29%206221-42-3545>


_______________________________________________
Powered by www.kitware.com<http://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/722e3da6/attachment.htm>


More information about the vtkusers mailing list