<div><br></div><div><br><div class="gmail_quote">On Mon, Mar 19, 2012 at 7:35 AM, Jothybasu Selvaraj <span dir="ltr"><<a href="mailto:jothybasu@gmail.com">jothybasu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">What is your polydata made of? <br><br>Is it from 2D contours?<br></div></blockquote><div><br></div><div>My polydata has 3D triangles. Here is the DumpXML output for it.</div><div><div>------------------------</div>
<div>out_p_w.vtk</div><div> contains a </div><div>vtkPolyData that has 1310888 cells and 1772275 points.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Cell type vtkTriangle occurs 1310888 times.</div>
<div> contains point data with 2 arrays.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Array 0 is named scalars</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Array 1 is named Normals</div>
<div> contains cell data with 0 arrays.</div><div> contains field data with 0 arrays.</div></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br>You may post your code, that would make people to help you better.<br></div></blockquote><div><br></div>Sorry, I should have done that. </div><div class="gmail_quote"><br></div><div class="gmail_quote">
<div class="gmail_quote">int main(int, char *[])</div><div class="gmail_quote">{</div><div class="gmail_quote"> vtkSmartPointer<vtkPolyDataReader> pdR =</div><div class="gmail_quote"> vtkSmartPointer<vtkPolyDataReader>::New();</div>
<div class="gmail_quote"> vtkSmartPointer<vtkSphereSource> sphereSource =</div><div class="gmail_quote"> vtkSmartPointer<vtkSphereSource>::New();</div><div class="gmail_quote"> vtkSmartPointer<vtkWarpScalar> warp=</div>
<div class="gmail_quote"> vtkSmartPointer<vtkWarpScalar>::New();</div><div class="gmail_quote"> sphereSource->SetRadius(20);</div><div class="gmail_quote"> sphereSource->SetPhiResolution(30);</div><div class="gmail_quote">
sphereSource->SetThetaResolution(30);</div><div class="gmail_quote"> pdR->SetFileName("../../data/vtk/out_p_w.vtk");</div><div class="gmail_quote"> //pdR->SetFileName("../../data/vtk/out_poly_append_one.vtk");</div>
<div class="gmail_quote"> //pdR->SetFileName("../../vis/out_poly.vtk");</div><div class="gmail_quote"> //vtkSmartPointer<vtkPolyData> pd = sphereSource->GetOutput();</div><div class="gmail_quote">
pdR->Update();</div>
<div class="gmail_quote"> vtkSmartPointer<vtkPolyData> pd = pdR->GetOutput();</div><div class="gmail_quote"> //warp->SetInput(pd);</div><div class="gmail_quote"> //warp->SetScaleFactor(10);</div><div class="gmail_quote">
//warp->Update();</div><div class="gmail_quote"> //vtkSmartPointer<vtkPolyData> pd =</div><div class="gmail_quote"> //pd = warp->GetOutput();</div><div class="gmail_quote"> //sphereSource->Update();</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"> vtkSmartPointer<vtkImageData> whiteImage =</div><div class="gmail_quote"> vtkSmartPointer<vtkImageData>::New();</div><div class="gmail_quote"> double bounds[6];</div>
<div class="gmail_quote"> pd->GetBounds(bounds);</div><div class="gmail_quote"> double spacing[3]; // desired volume spacing</div><div class="gmail_quote"> spacing[0] = 0.31;</div><div class="gmail_quote"> spacing[1] = 0.31;</div>
<div class="gmail_quote"> spacing[2] = 0.31;</div><div class="gmail_quote"> whiteImage->SetSpacing(spacing);</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // compute dimensions</div><div class="gmail_quote">
int dim[3];</div><div class="gmail_quote"> for (int i = 0; i < 3; i++)</div><div class="gmail_quote"> {</div><div class="gmail_quote"> dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) / spacing[i]));</div>
<div class="gmail_quote"> }</div><div class="gmail_quote"> whiteImage->SetDimensions(dim);</div><div class="gmail_quote"> whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);</div><div class="gmail_quote">
<br></div><div class="gmail_quote"> double origin[3];</div><div class="gmail_quote"> origin[0] = bounds[0] + spacing[0] / 2;</div><div class="gmail_quote"> origin[1] = bounds[2] + spacing[1] / 2;</div><div class="gmail_quote">
origin[2] = bounds[4] + spacing[2] / 2;</div><div class="gmail_quote"> whiteImage->SetOrigin(origin);</div><div class="gmail_quote"><br></div><div class="gmail_quote">#if VTK_MAJOR_VERSION <= 5</div><div class="gmail_quote">
whiteImage->SetScalarTypeToUnsignedChar();</div><div class="gmail_quote"> whiteImage->AllocateScalars();</div><div class="gmail_quote">#else</div><div class="gmail_quote"> whiteImage->AllocateScalars(VTK_UNSIGNED_SHORT,1);</div>
<div class="gmail_quote">#endif</div><div class="gmail_quote"> // fill the image with foreground voxels:</div><div class="gmail_quote"> unsigned char inval = 255; unsigned char outval = 0;</div><div class="gmail_quote">
vtkIdType count = whiteImage->GetNumberOfPoints();</div><div class="gmail_quote"> for (vtkIdType i = 0; i < count; ++i)</div><div class="gmail_quote"> {</div><div class="gmail_quote"> whiteImage->GetPointData()->GetScalars()->SetTuple1(i, inval);</div>
<div class="gmail_quote"> }</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // polygonal data --> image stencil:</div><div class="gmail_quote"> vtkSmartPointer<vtkPolyDataToImageStencil> pol2stenc =</div>
<div class="gmail_quote"> vtkSmartPointer<vtkPolyDataToImageStencil>::New();</div><div class="gmail_quote">#if VTK_MAJOR_VERSION <= 5</div><div class="gmail_quote"> pol2stenc->SetInput(pd);</div><div class="gmail_quote">
#else</div><div class="gmail_quote"> pol2stenc->SetInputData(pd);</div><div class="gmail_quote">#endif</div><div class="gmail_quote"> pol2stenc->SetOutputOrigin(origin);</div><div class="gmail_quote"> pol2stenc->SetOutputSpacing(spacing);</div>
<div class="gmail_quote"> pol2stenc->SetOutputWholeExtent(whiteImage->GetExtent());</div><div class="gmail_quote"> pol2stenc->Update();</div><div class="gmail_quote"><br></div><div class="gmail_quote"> vtkSmartPointer<vtkImplicitFunctionToImageStencil> func2stenc =</div>
<div class="gmail_quote"> vtkImplicitFunctionToImageStencil::New();</div><div class="gmail_quote"> //vtkSmartPointer<vtkElevationFilter> elev = vtkElevationFilter::New();</div><div class="gmail_quote"> //elev->SetInput(pd);</div>
<div class="gmail_quote"> //vtkSmartPointer<vtkImplicitDataSet> imp = vtkImplicitDataSet::New();</div><div class="gmail_quote"> //imp->SetDataSet(elev->GetOutput());</div><div class="gmail_quote"><br></div>
<div class="gmail_quote">
//func2stenc->SetThreshold(0.1);</div><div class="gmail_quote"> //func2stenc->SetInput(imp);</div><div class="gmail_quote"> //func2stenc->SetOutputOrigin(origin);</div><div class="gmail_quote"> //func2stenc->SetOutputSpacing(spacing);</div>
<div class="gmail_quote"> //func2stenc->SetOutputWholeExtent(whiteImage->GetExtent());</div><div class="gmail_quote"> //func2stenc->Update();</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // cut the corresponding white image and set the background:</div>
<div class="gmail_quote"> vtkSmartPointer<vtkImageStencil> imgstenc =</div><div class="gmail_quote"> vtkSmartPointer<vtkImageStencil>::New();</div><div class="gmail_quote">#if VTK_MAJOR_VERSION <= 5</div>
<div class="gmail_quote"> imgstenc->SetInput(whiteImage);</div><div class="gmail_quote"> imgstenc->SetStencil(pol2stenc->GetOutput());</div><div class="gmail_quote"> //imgstenc->SetStencil(func2stenc->GetOutput());</div>
<div class="gmail_quote">#else</div><div class="gmail_quote"> imgstenc->SetInputData(whiteImage);</div><div class="gmail_quote"> imgstenc->SetStencilConnection(pol2stenc->GetOutputPort());</div><div class="gmail_quote">
//imgstenc->SetStencilConnection(func2stenc->GetOutputPort());</div><div class="gmail_quote">#endif</div><div class="gmail_quote"> //imgstenc->ReverseStencilOff();</div><div class="gmail_quote"> imgstenc->SetBackgroundValue(outval);</div>
<div class="gmail_quote"> imgstenc->Update();</div><div class="gmail_quote"><br></div><div class="gmail_quote"> vtkSmartPointer<vtkMetaImageWriter> writer =</div><div class="gmail_quote"> vtkSmartPointer<vtkMetaImageWriter>::New();</div>
<div class="gmail_quote"> writer->SetFileName("SphereVolume_p_w.mhd");</div><div class="gmail_quote">#if VTK_MAJOR_VERSION <= 5</div><div class="gmail_quote"> writer->SetInput(imgstenc->GetOutput());</div>
<div class="gmail_quote">#else</div><div class="gmail_quote"> writer->SetInputData(imgstenc->GetOutput());</div><div class="gmail_quote">#endif</div><div class="gmail_quote"> writer->Write();</div><div class="gmail_quote">
<br></div><div class="gmail_quote"> return EXIT_SUCCESS;</div><div class="gmail_quote">}</div><div><br></div><div><br></div><div> </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br>Jothy<br><br><div class="gmail_quote"><div><div class="h5">On Mon, Mar 19, 2012 at 2:51 AM, Raghuram.O.S. <span dir="ltr"><<a href="mailto:raghuramos1987@gmail.com" target="_blank">raghuramos1987@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">Hi,<div><br></div><div><div>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 <a href="http://www.vtk.org/pipermail/vtkusers/2011-October/119302.html" target="_blank">http://www.vtk.org/pipermail/vtkusers/2011-October/119302.html</a> and tried using the implicit function. But, the post doesnt have a full example and there doesnt seem to be an example of <span style>vtkImplicitFunctionToImageStencil. </span></div>
<div><span style><br></span></div><div><span style>My polydata doesnt seem to have any issues when I render it using polydatamapper. I have been using the example on the site at </span><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData</a> (as indicated in the previous post also).</div>
-- <br><font color="#888888">Regards,<br>Onti<br>
</font></div>
<br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br><div dir="ltr">Jothy<br></div><br>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Regards,<br>Onti<br>
</div>