[vtkusers] 3D surface to 2D silhouette

Lars Friedrich Lars lars-friedrich at gmx.net
Fri Dec 4 10:08:19 EST 2009


Yes, this is basically true. In my first experiments with this class, using a simple sphere source with low theta/phi resolution and the active camera of the renderer for the silhouette filter, my impression was the same as yours.
However, there are two arguments why (I think) I need the silhouette in 2D representation:
1. I need to export it to another application as 2D contour
2. As soon as I used more complex poly data surfaces (e.g. skull), I recognized that there are lots of artifacts (e.g. wrong islands of 'border' edges). I think that I can automatically detect these 'island'-artifacts and the casual artifacts at the border (line crosses) when I have it in 2D representation.

I attached a simple program and an example poly data file where you can see what's going on when you invoke the interactor:


#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataSilhouette.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkCleanPolyData.h"
#include "vtkXMLPolyDataWriter.h"
#include "vtkSmartPointer.h"
#include "vtkPolyDataSilhouette.h"

#define VSPNEW(instance, type) vtkSmartPointer<type> instance = vtkSmartPointer<type>::New();

int main(int argc, char *argv[])
{
  VSPNEW(ren, vtkRenderer)
  VSPNEW(renWin, vtkRenderWindow)
  VSPNEW(iren, vtkRenderWindowInteractor)

  renWin->AddRenderer(ren);
  iren->SetRenderWindow(renWin);

//	VSPNEW(sphere, vtkSphereSource)
//	sphere->SetCenter(50,50,50);
//	sphere->SetRadius(15);
//	sphere->SetThetaResolution(5);
//	sphere->SetPhiResolution(5);
//	sphere->Update();

	VSPNEW(reader, vtkXMLPolyDataReader)
  reader->SetFileName("struct1.xml");

	VSPNEW(cleaner1, vtkCleanPolyData)
  cleaner1->SetInput(reader->GetOutput());
  cleaner1->SetConvertLinesToPoints(true);
  cleaner1->SetConvertPolysToLines(true);
  cleaner1->SetConvertStripsToPolys(true);
  cleaner1->SetPieceInvariant(true);
  cleaner1->SetPointMerging(true);

  VSPNEW(mapper, vtkPolyDataMapper)
//	mapper->SetInput(sphere->GetOutput());
	mapper->SetInput(cleaner1->GetOutput());
	VSPNEW(actor, vtkActor)
	actor->SetMapper(mapper);
	actor->GetProperty()->SetColor(1, 0, 0);
  ren->AddActor(actor);

	VSPNEW(silhouette, vtkPolyDataSilhouette)
//	silhouette->SetInput(sphere->GetOutput());
	silhouette->SetInput(cleaner1->GetOutput());
	silhouette->SetEnableFeatureAngle(false);
	silhouette->SetBorderEdges(true);
	silhouette->SetPieceInvariant(false);
	silhouette->SetDirectionToCameraOrigin();
	silhouette->SetCamera(ren->GetActiveCamera());

	VSPNEW(mapper2, vtkPolyDataMapper)
	mapper2->SetInput(silhouette->GetOutput());
	VSPNEW(actor2, vtkActor)
	actor2->SetMapper(mapper2);
	actor2->GetProperty()->SetColor(0.5, 0.5, 1);
  ren->AddActor(actor2);

  renWin->SetSize(400, 400);
  renWin->Render();

	ren->ResetCamera();

  renWin->Render();

  VSPNEW(writer, vtkXMLPolyDataWriter)
  writer->SetFileName("silhouette.xml");
  writer->SetInput(silhouette->GetOutput());
  writer->Update();

  iren->Initialize();
  iren->Start();

  return EXIT_SUCCESS;
}




-------- Original-Nachricht --------
> Datum: Fri, 4 Dec 2009 09:11:42 -0500
> Von: Cory Quammen <cquammen at cs.unc.edu>
> An: Lars Friedrich Lars <lars-friedrich at gmx.net>
> CC: vtkusers at vtk.org
> Betreff: Re: [vtkusers] 3D surface to 2D silhouette

> I haven't used this class, but the documentation says that it
> generates the edges of the poly data that form the silhouette. Won't
> rendering these edges into an image get you where you want, assuming
> the vtkPolyDataSilhouette class uses the same vtkCamera as the
> renderer?
> 
> Cory
> 
> On Fri, Dec 4, 2009 at 7:46 AM, Lars Friedrich Lars
> <lars-friedrich at gmx.net> wrote:
> > Hello,
> >
> > I would like to project the silhouette of a 3D surface (e.g. a sphere)
> onto an arbitrary 2D plane in space following a specified projection
> geometry (e.g. the geometry of the active camera).
> > I thought that the class vtkPolyDataSilhouette does exactly this. After
> some experiments with this class I recognized that the silhouette generated
> by this class lies not on a plane, it is still 3D.
> > Is there a way of implementing this behavior?
> >
> > regards,
> > lars
> > --
> > GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> > _______________________________________________
> > 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
> >
> 
> 
> 
> -- 
> Cory Quammen
> Center for Computer Integrated Systems for Microscopy and Manipulation
> (CISMM)
> Department of Computer Science
> University of North Carolina at Chapel Hill
> http://www.cs.unc.edu/~cquammen

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
-------------- next part --------------
A non-text attachment was scrubbed...
Name: struct1.xml
Type: application/octet-stream
Size: 65397 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091204/8a824f8b/attachment.obj>


More information about the vtkusers mailing list