<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 13, 2015 at 8:10 PM, Neel007 <span dir="ltr"><<a href="mailto:sayanmaity.10@gmail.com" target="_blank">sayanmaity.10@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Cory,<br>
<br>
I was following the second-step you mentioned: "Alternatively, you could<br>
*create a 3D image from your input 2D image*s, then use *vtkThreshold to<br>
create an unstructured grid of just the white parts of the 3D image*. To<br>
convert the resulting hexahedral elements in the *unstructured grid to<br>
tetrahedra, use vtkDataSetTriangleFilter*." I am able to complete the first<br>
step successfully the second one partially. I have included the code & the<br>
output window, if you can have a look and give me some input It will be very<br>
much appreciated. Thank you for your time.<br>
<br>
<br>
*/create a 3D image from your input 2D images...(Working Fine as I have<br>
visualized it similar as Matlab)/*<br>
<br>
// Start by loading some data.<br>
<span> vtkSmartPointer<vtkTIFFReader> reader =<br>
vtkSmartPointer<vtkTIFFReader>::New();<br>
reader->SetFileNameSliceOffset(1);<br>
reader->SetFileNameSliceSpacing(1);<br>
<br>
reader->SetFilePattern("C:\\Users\\Neel\\Desktop\\VTK_try\\test_images\\2.%d.bspline.tif");<br>
reader->SetDataExtent(0, 63, 0, 63, 1, 551);<br>
<br>
reader->SetOrientationType(3);<br>
reader->Update();<br>
<br>
<br>
</span>*/vtkThreshold to create an unstructured grid of just the white parts of the<br>
3D image/*<br></blockquote><div><br></div><div>Great, I'm glad it works. TIFF files can be difficult to work with, so I'm glad whatever is writing your TIFF files does so in a format that is readable by VTK. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As you have suggested to use vtkThreshold but the input data being binary<br>
"Image Thresholding" operation is not applicable.</blockquote><div><br></div><div>vtkThreshold should work directly with output from the vtkTIFFReader, as in</div><div><br></div><div>vtkSmartPointer<vtkThreshold> threshold = vtkSmartPointer<vtkThreshold>::New();</div><div>threshold->SetInputConnection(reader->GetOutputPort());</div><div>threshold->ThresholdByUpper(1);</div><div><br></div><div>See if you can get this to work. If not, let me know. </div><div><br></div><div>One thing to know is that vtkThreshold will give you a "blocky" mesh - it extracts whole voxels from the image. vtkClipVolume will give you a surface slightly smoother surface because it performs interpolation along voxel edges. See attached images showing the difference between the two.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Thus, I tried to convert<br>
the 3D volume of *.tif stack of images to vtkImageData and trying to use<br>
vtkClipVolume to create an unstructured grid using the white pixels. Here<br>
I'm facing an issue: vtkImageData pixel values of the Binary Image resulting<br>
-5.4861292803319049e+303 ; Instead of 0 & 1; Any suggestion if I am missing<br>
something here. The code snippet & the output-window:<br>
<<a href="http://vtk.1045678.n5.nabble.com/file/n5732876/1.png" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/file/n5732876/1.png</a>><br>
// Create an image data<br>
vtkSmartPointer<vtkImageData> imageData =<br>
vtkSmartPointer<vtkImageData>::New();<br>
//vtkImageData *imageData=0;<br>
imageData->AllocateScalars(VTK_DOUBLE,1);<br>
imageData =reader->GetOutput() ;<br></blockquote><div><br></div><div>You don't need to create a new vtkImageData object here. In fact, you are creating one, then setting the pointer to a different vtkImageData object, so you aren't even using the newly created vtkImageData. Instead, you can just create a vtkImageData object pointer and assign it to the output of the reader, .e.g, </div><div><br></div><div>reader->Update(); // make sure to do this somewhere before getting the output</div><div>vtkImageData* imageData = reader->GetOutput(); </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
int* dims = imageData->GetDimensions();<br>
// int dims[3]; // can't do this<br>
<br>
std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: "<br>
<< dims[2] << std::endl;<br>
<br>
std::cout << "Number of points: " << imageData->GetNumberOfPoints() <<<br>
std::endl;<br>
std::cout << "Number of cells: " << imageData->GetNumberOfCells() <<<br>
std::endl;<br>
int extent[6];<br>
imageData->GetExtent(extent) ;<br>
<br>
<<a href="http://vtk.1045678.n5.nabble.com/file/n5732876/2.png" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/file/n5732876/2.png</a>><br>
<br>
vtkIdType numberOfPointArrays =<br>
imageData->GetPointData()->GetNumberOfArrays();<br>
std::cout << "Number of PointData arrays: " << numberOfPointArrays <<<br>
std::endl;<br>
<br>
cout<< "Number of Scalar Components:<br>
"<<imageData->GetNumberOfScalarComponents()<<endl;<br>
<br>
for(vtkIdType i = 0; i < numberOfPointArrays; i++)<br>
{<br>
// The following two lines are equivalent<br>
<br>
//arrayNames.push_back(polydata->GetPointData()->GetArray(i)->GetName());<br>
//arrayNames.push_back(polydata->GetPointData()->GetArrayName(i));<br>
int dataTypeID = imageData->GetPointData()->GetArray(i)->GetDataType();<br>
std::cout << "Array " << i << ": " <<<br>
reader->GetOutput()->GetPointData()->GetArrayName(i)<br>
<< " (type: " << dataTypeID << ")" << std::endl;<br>
<br>
}<br>
<br>
vtkSmartPointer<vtkClipVolume> vol =<br>
vtkSmartPointer<vtkClipVolume>::New();<br>
<br>
vol->SetInputData(imageData);<br>
double tryval=-5.4861292803319049e+303;//* */Not sure which value I should<br>
for clipping/*<br>
vol->SetValue(tryval);<br>
vol->Update();<br>
<br>
*For few slices (50) vtkClipVolume is working but for entire series it<br>
throwing memory exception. I think I might need to use some other<br>
functionalities. Please give me some suggestion.*<br></blockquote><div><br></div><div>If you can run your program through a debugger, it should show you where it is failing. Please try that and send us a stack trace if you need additional help.</div><div><br></div><div>Best regards,</div><div>Cory</div></div><div><br></div>-- <br><div>Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div></div>