[vtkusers] vtkPolyDataToImageStencil noise issue
Raghuram.O.S.
raghuramos1987 at gmail.com
Mon Mar 19 13:15:12 EDT 2012
I have attached a slice of the generated mhd image.
On Mon, Mar 19, 2012 at 11:50 AM, Raghuram.O.S. <raghuramos1987 at gmail.com>wrote:
>
>
> On Mon, Mar 19, 2012 at 7:35 AM, Jothybasu Selvaraj <jothybasu at gmail.com>wrote:
>
>> What is your polydata made of?
>>
>> Is it from 2D contours?
>>
>
> My polydata has 3D triangles. Here is the DumpXML output for it.
> ------------------------
> out_p_w.vtk
> contains a
> vtkPolyData that has 1310888 cells and 1772275 points.
> Cell type vtkTriangle occurs 1310888 times.
> contains point data with 2 arrays.
> Array 0 is named scalars
> Array 1 is named Normals
> contains cell data with 0 arrays.
> contains field data with 0 arrays.
>
>
>
>>
>> You may post your code, that would make people to help you better.
>>
>
> Sorry, I should have done that.
>
> int main(int, char *[])
> {
> vtkSmartPointer<vtkPolyDataReader> pdR =
> vtkSmartPointer<vtkPolyDataReader>::New();
> vtkSmartPointer<vtkSphereSource> sphereSource =
> vtkSmartPointer<vtkSphereSource>::New();
> vtkSmartPointer<vtkWarpScalar> warp=
> vtkSmartPointer<vtkWarpScalar>::New();
> sphereSource->SetRadius(20);
> sphereSource->SetPhiResolution(30);
> sphereSource->SetThetaResolution(30);
> pdR->SetFileName("../../data/vtk/out_p_w.vtk");
> //pdR->SetFileName("../../data/vtk/out_poly_append_one.vtk");
> //pdR->SetFileName("../../vis/out_poly.vtk");
> //vtkSmartPointer<vtkPolyData> pd = sphereSource->GetOutput();
> pdR->Update();
> vtkSmartPointer<vtkPolyData> pd = pdR->GetOutput();
> //warp->SetInput(pd);
> //warp->SetScaleFactor(10);
> //warp->Update();
> //vtkSmartPointer<vtkPolyData> pd =
> //pd = warp->GetOutput();
> //sphereSource->Update();
>
> vtkSmartPointer<vtkImageData> whiteImage =
> vtkSmartPointer<vtkImageData>::New();
> double bounds[6];
> pd->GetBounds(bounds);
> double spacing[3]; // desired volume spacing
> spacing[0] = 0.31;
> spacing[1] = 0.31;
> spacing[2] = 0.31;
> whiteImage->SetSpacing(spacing);
>
> // compute dimensions
> int dim[3];
> for (int i = 0; i < 3; i++)
> {
> dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) /
> spacing[i]));
> }
> whiteImage->SetDimensions(dim);
> whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);
>
> double origin[3];
> origin[0] = bounds[0] + spacing[0] / 2;
> origin[1] = bounds[2] + spacing[1] / 2;
> origin[2] = bounds[4] + spacing[2] / 2;
> whiteImage->SetOrigin(origin);
>
> #if VTK_MAJOR_VERSION <= 5
> whiteImage->SetScalarTypeToUnsignedChar();
> whiteImage->AllocateScalars();
> #else
> whiteImage->AllocateScalars(VTK_UNSIGNED_SHORT,1);
> #endif
> // 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);
> }
>
> // polygonal data --> image stencil:
> vtkSmartPointer<vtkPolyDataToImageStencil> pol2stenc =
> vtkSmartPointer<vtkPolyDataToImageStencil>::New();
> #if VTK_MAJOR_VERSION <= 5
> pol2stenc->SetInput(pd);
> #else
> pol2stenc->SetInputData(pd);
> #endif
> pol2stenc->SetOutputOrigin(origin);
> pol2stenc->SetOutputSpacing(spacing);
> pol2stenc->SetOutputWholeExtent(whiteImage->GetExtent());
> pol2stenc->Update();
>
> vtkSmartPointer<vtkImplicitFunctionToImageStencil> func2stenc =
> vtkImplicitFunctionToImageStencil::New();
> //vtkSmartPointer<vtkElevationFilter> elev = vtkElevationFilter::New();
> //elev->SetInput(pd);
> //vtkSmartPointer<vtkImplicitDataSet> imp = vtkImplicitDataSet::New();
> //imp->SetDataSet(elev->GetOutput());
>
> //func2stenc->SetThreshold(0.1);
> //func2stenc->SetInput(imp);
> //func2stenc->SetOutputOrigin(origin);
> //func2stenc->SetOutputSpacing(spacing);
> //func2stenc->SetOutputWholeExtent(whiteImage->GetExtent());
> //func2stenc->Update();
>
> // cut the corresponding white image and set the background:
> vtkSmartPointer<vtkImageStencil> imgstenc =
> vtkSmartPointer<vtkImageStencil>::New();
> #if VTK_MAJOR_VERSION <= 5
> imgstenc->SetInput(whiteImage);
> imgstenc->SetStencil(pol2stenc->GetOutput());
> //imgstenc->SetStencil(func2stenc->GetOutput());
> #else
> imgstenc->SetInputData(whiteImage);
> imgstenc->SetStencilConnection(pol2stenc->GetOutputPort());
> //imgstenc->SetStencilConnection(func2stenc->GetOutputPort());
> #endif
> //imgstenc->ReverseStencilOff();
> imgstenc->SetBackgroundValue(outval);
> imgstenc->Update();
>
> vtkSmartPointer<vtkMetaImageWriter> writer =
> vtkSmartPointer<vtkMetaImageWriter>::New();
> writer->SetFileName("SphereVolume_p_w.mhd");
> #if VTK_MAJOR_VERSION <= 5
> writer->SetInput(imgstenc->GetOutput());
> #else
> writer->SetInputData(imgstenc->GetOutput());
> #endif
> writer->Write();
>
> return EXIT_SUCCESS;
> }
>
>
>
>
>
>>
>> Jothy
>>
>> On Mon, Mar 19, 2012 at 2:51 AM, Raghuram.O.S. <raghuramos1987 at gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I have been trying to convert polydata to imagedata using the image
>>> stencil filter. I seem to be running into an issue of noise in the
>>> converted image. I get random triangles in the image which are pretty huge
>>> in the middle of actual data. I saw this post
>>> http://www.vtk.org/pipermail/vtkusers/2011-October/119302.html and
>>> tried using the implicit function. But, the post doesnt have a full example
>>> and there doesnt seem to be an example of
>>> vtkImplicitFunctionToImageStencil.
>>>
>>> My polydata doesnt seem to have any issues when I render it using
>>> polydatamapper. I have been using the example on the site at
>>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData (as
>>> indicated in the previous post also).
>>> --
>>> Regards,
>>> Onti
>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>
>>
>> --
>> Jothy
>>
>>
>
>
> --
> Regards,
> Onti
>
--
Regards,
Onti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120319/e8762501/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image_mhd.png
Type: image/png
Size: 6648 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120319/e8762501/attachment.png>
More information about the vtkusers
mailing list