[vtkusers] Closed vtkPolyLine to binary image

Dirk Boye body at nabla.org
Mon Jul 12 10:51:30 EDT 2010


Yes it does!

> Strange.
> Does the circle-polydata define a continuous closed line after stripper?
>
> -------- Original-Nachricht --------
>> Datum: Mon, 12 Jul 2010 16:34:59 +0200
>> Von: "Dirk Boye" <body at nabla.org>
>> An: "Lars Friedrich Lars" <lars-friedrich at gmx.net>
>> CC: "Dirk Boye" <body at nabla.org>, vtkusers at vtk.org
>> Betreff: Re: [vtkusers] Closed vtkPolyLine to binary image
>
>> Hey Lars,
>>
>> Nope it didn't. I can't find the error ^^
>>
>> dirk
>>
>> > Dirk,
>> >
>> > try to place the stripper between polyreader->GetOutput() and circle,
>> i.e.
>> > vtkSmartPointer<vtkPolyData> circle = stripper->GetOutput();
>> > Let me know whether it helped.
>> >
>> > lars
>> >
>> >
>> > -------- Original-Nachricht --------
>> >> Datum: Mon, 12 Jul 2010 16:16:49 +0200
>> >> Von: "Dirk Boye" <body at nabla.org>
>> >> An: "Lars Friedrich Lars" <lars-friedrich at gmx.net>
>> >> CC: "Dirk Boye" <body at nabla.org>, vtkusers at vtk.org
>> >> Betreff: Re: [vtkusers] Closed vtkPolyLine to binary image
>> >
>> >> I ran your example and the only difference between
>> stripper->GetOutput()
>> >> and my outline were the normals.
>> >>
>> >> My code is as follows: (your code but with a readin of my circle
>> >> and given image dimensions etc.)
>> >>
>> >> The vtk File can be found here:
>> >> http://www.nabla.org/circle.vtk
>> >>
>> >> The resulting image is black only.
>> >>
>> >>
>> >> #include <vtkSmartPointer.h>
>> >> #include <vtkPolyData.h>
>> >> #include <vtkImageData.h>
>> >> #include <vtkSphereSource.h>
>> >> #include <vtkMetaImageWriter.h>
>> >> #include <vtkPolyDataToImageStencil.h>
>> >> #include <vtkImageStencil.h>
>> >> #include <vtkPointData.h>
>> >> #include <vtkCutter.h>
>> >> #include <vtkPlane.h>
>> >> #include <vtkStripper.h>
>> >> #include <vtkLinearExtrusionFilter.h>
>> >> #include <vtkXMLPolyDataWriter.h>
>> >> #include <vtkPolyDataReader.h>
>> >>
>> >> int main(int argc, char **argv)
>> >> {
>> >> vtkSmartPointer< vtkPolyDataReader > polyreader=vtkSmartPointer<
>> >> vtkPolyDataReader >::New();
>> >> 	polyreader->SetFileName("circle.vtk");
>> >> 	polyreader->Update();
>> >>
>> >> 	vtkSmartPointer<vtkPolyData> circle = polyreader->GetOutput();
>> >>
>> >> 	// prepare the binary image's voxel grid
>> >> 	vtkSmartPointer<vtkImageData> whiteImage =
>> >> 	  vtkSmartPointer<vtkImageData>::New();
>> >> 	double spacing[3]; // desired volume spacing
>> >> 	spacing[0] = 2.0;
>> >> 	spacing[1] = 2.0;
>> >> 	spacing[2] = 2.0;
>> >> 	whiteImage->SetSpacing(spacing);
>> >>
>> >> 	// compute dimensions
>> >> 	int dim[3]={256,256,1};
>> >> 	whiteImage->SetDimensions(dim);
>> >> 	whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);
>> >> 	double origin[3]={0,0,0};
>> >> 	whiteImage->SetOrigin(origin);
>> >> 	whiteImage->SetScalarTypeToUnsignedChar();
>> >> 	whiteImage->AllocateScalars();
>> >> 	// fill the image with foreground voxels:
>> >> 	unsigned char inval = 255;
>> >> 	unsigned char outval = 0;
>> >> 	vtkIdType count = whiteImage->GetNumberOfPoints();
>> >> 	for (vtkIdType i = 0; i < count; ++i)
>> >> 	{
>> >> 		whiteImage->GetPointData()->GetScalars()->SetTuple1(i, inval);
>> >> 	}
>> >>
>> >> 	// sweep polygonal data (this is the important thing with contours!)
>> >> 	vtkSmartPointer<vtkLinearExtrusionFilter> extruder =
>> >> 	  vtkSmartPointer<vtkLinearExtrusionFilter>::New();
>> >> 	extruder->SetInput(circle);
>> >> 	extruder->SetScaleFactor(1.);
>> >> 	extruder->SetExtrusionTypeToNormalExtrusion();
>> >> 	extruder->SetVector(0, 0, 1);
>> >> 	extruder->Update();
>> >>
>> >> 	// polygonal data --> image stencil:
>> >> 	vtkSmartPointer<vtkPolyDataToImageStencil> pol2stenc =
>> >> 	vtkSmartPointer<vtkPolyDataToImageStencil>::New();
>> >> 	pol2stenc->SetTolerance(0); // important if extruder->SetVector(0,
>> 0,
>> >> 1)
>> >> !!!
>> >> 	pol2stenc->SetInputConnection(extruder->GetOutputPort());
>> >> 	pol2stenc->SetOutputOrigin(origin);
>> >> 	pol2stenc->SetOutputSpacing(spacing);
>> >> 	pol2stenc->SetOutputWholeExtent(whiteImage->GetExtent());
>> >> 	pol2stenc->Update();
>> >>
>> >> 	// cut the corresponding white image and set the background:
>> >> 	vtkSmartPointer<vtkImageStencil> imgstenc =
>> >> 	vtkSmartPointer<vtkImageStencil>::New();
>> >> 	imgstenc->SetInput(whiteImage);
>> >> 	imgstenc->SetStencil(pol2stenc->GetOutput());
>> >> 	imgstenc->ReverseStencilOff();
>> >> 	imgstenc->SetBackgroundValue(outval);
>> >> 	imgstenc->Update();
>> >>
>> >> 	vtkSmartPointer<vtkMetaImageWriter> imageWriter =
>> >> 	vtkSmartPointer<vtkMetaImageWriter>::New();
>> >> 	imageWriter->SetFileName("labelImage.mhd");
>> >> 	imageWriter->SetInput(imgstenc->GetOutput());
>> >> 	imageWriter->Write();
>> >>
>> >> 	return 0;
>> >> };
>> >>
>> >>
>> >> >
>> >> > vtkPolyDataNormals
>> >> >
>> >> > just to satisfy my curiosity:
>> >> > why are you of the opinion that missing normals are a problem for
>> that
>> >> > approach? I copied the piece of example code more or less from an
>> old
>> >> > application I programmed some months ago; as far as I can remember,
>> my
>> >> > input polygons did not have any normals defined, and it worked
>> though
>> >> ...
>> >> >
>> >> > regards,
>> >> > lars
>> >> >
>> >> > -------- Original-Nachricht --------
>> >> >> Datum: Mon, 12 Jul 2010 15:30:01 +0200
>> >> >> Von: "Dirk Boye" <body at nabla.org>
>> >> >> An: "Lars Friedrich Lars" <lars-friedrich at gmx.net>
>> >> >> CC: "Dirk Boye" <body at nabla.org>, vtkusers at vtk.org
>> >> >> Betreff: Re: [vtkusers] Closed vtkPolyLine to binary image
>> >> >
>> >> >> Hi Lars,
>> >> >>
>> >> >> Thank you for your help. My problem now seems to be, that my
>> contour
>> >> >> lines
>> >> >> don't have any normals.
>> >> >>
>> >> >> Do you know if there's some function to generate the normals?
>> >> >>
>> >> >> Cheers,
>> >> >> Dirk
>> >> >>
>> >> >> > Hi,
>> >> >> >
>> >> >> > I added a small example:
>> >> >> >
>> >> >> >
>> >> >>
>> >>
>> http://www.cmake.org/Wiki/VTK/Examples/PolyData/PolyDataContourToImageData
>> >> >> >
>> >> >> > Hope that helps you.
>> >> >> >
>> >> >> > However, please read the NOTE in the description. Maybe you
>> could
>> >> fix
>> >> >> /
>> >> >> > verify the image origin problem.
>> >> >> >
>> >> >> > regards,
>> >> >> > lars
>> >> >> >
>> >> >> > -------- Original-Nachricht --------
>> >> >> >> Datum: Mon, 12 Jul 2010 08:36:32 +0200
>> >> >> >> Von: "Dirk Boye" <body at nabla.org>
>> >> >> >> An: vtkusers at vtk.org
>> >> >> >> Betreff: [vtkusers] Closed vtkPolyLine to binary image
>> >> >> >
>> >> >> >> Dear list,
>> >> >> >>
>> >> >> >> let's say I have a closed vtkPolyLine in 2D and points are
>> >> >> >> ordered clockwise and last point=first point.
>> >> >> >> The resulting Polygon is non-convex.
>> >> >> >>
>> >> >> >> I'd like to create a binary image
>> >> >> >> from that. Ones inside the line, zeros outside. See picture:
>> >> >> >> http://www.nabla.org/circlecontour.png
>> >> >> >>
>> >> >> >> Is there an filter to do that? Or do I have to check all
>> pixels,
>> >> >> >> if they are inside?
>> >> >> >>
>> >> >> >>
>> >> >> >> Cheers,
>> >> >> >> Dirk
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> _______________________________________________
>> >> >> >> 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
>> >> >> >
>> >> >> > --
>> >> >> > GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
>> >> >> > Bis zu 150 EUR Startguthaben inklusive!
>> >> >> http://portal.gmx.net/de/go/dsl
>> >> >> >
>> >> >> >
>> >> >
>> >> > --
>> >> > GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
>> >> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>> >> >
>> >> >
>> >
>> > --
>> > GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
>> > Bis zu 150 EUR Startguthaben inklusive!
>> http://portal.gmx.net/de/go/dsl
>> >
>> >
>
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>
>




More information about the vtkusers mailing list