[vtkusers] Does vtkImageBlend or vtkAppendPolyData generate 3D / Volumetric representation of 2D Image Data or PolyData respectively

Cory Quammen cory.quammen at kitware.com
Thu Jul 16 09:49:14 EDT 2015


On Mon, Jul 13, 2015 at 8:10 PM, Neel007 <sayanmaity.10 at gmail.com> wrote:

> Dear Cory,
>
> I was following the second-step you mentioned: "Alternatively, you could
> *create a 3D image from your input 2D image*s, then use *vtkThreshold to
> create an unstructured grid of just the white parts of the 3D image*. To
> convert the resulting hexahedral elements in the *unstructured grid to
> tetrahedra, use vtkDataSetTriangleFilter*." I am able to complete the first
> step successfully the second one partially. I have included the code & the
> output window, if you can have a look and give me some input It will be
> very
> much appreciated. Thank you for your time.
>
>
> */create a 3D image from your input 2D images...(Working Fine as I have
> visualized it similar as Matlab)/*
>
> // Start by loading some data.
>   vtkSmartPointer<vtkTIFFReader> reader =
>   vtkSmartPointer<vtkTIFFReader>::New();
>   reader->SetFileNameSliceOffset(1);
>   reader->SetFileNameSliceSpacing(1);
>
>
> reader->SetFilePattern("C:\\Users\\Neel\\Desktop\\VTK_try\\test_images\\2.%d.bspline.tif");
>   reader->SetDataExtent(0, 63, 0, 63, 1, 551);
>
>   reader->SetOrientationType(3);
>   reader->Update();
>
>
> */vtkThreshold to create an unstructured grid of just the white parts of
> the
> 3D image/*
>

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.


> As you have suggested to use vtkThreshold but the input data being binary
> "Image Thresholding" operation is not applicable.


vtkThreshold should work directly with output from the vtkTIFFReader, as in

vtkSmartPointer<vtkThreshold> threshold =
vtkSmartPointer<vtkThreshold>::New();
threshold->SetInputConnection(reader->GetOutputPort());
threshold->ThresholdByUpper(1);

See if you can get this to work. If not, let me know.

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.


> Thus, I tried to convert
> the 3D volume of *.tif stack of images to vtkImageData and trying to use
> vtkClipVolume to create an unstructured grid using the white pixels. Here
> I'm facing an issue: vtkImageData pixel values of the Binary Image
> resulting
> -5.4861292803319049e+303 ; Instead of 0 & 1;  Any suggestion if I am
> missing
> something here. The code snippet & the output-window:
> <http://vtk.1045678.n5.nabble.com/file/n5732876/1.png>
> // Create an image data
>   vtkSmartPointer<vtkImageData> imageData =
>     vtkSmartPointer<vtkImageData>::New();
>   //vtkImageData *imageData=0;
>   imageData->AllocateScalars(VTK_DOUBLE,1);
>   imageData =reader->GetOutput() ;
>

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,

reader->Update(); // make sure to do this somewhere before getting the
output
vtkImageData* imageData = reader->GetOutput();

  int* dims = imageData->GetDimensions();
>   // int dims[3]; // can't do this
>
>   std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: "
> << dims[2] << std::endl;
>
>   std::cout << "Number of points: " << imageData->GetNumberOfPoints() <<
> std::endl;
>   std::cout << "Number of cells: " << imageData->GetNumberOfCells() <<
> std::endl;
>   int extent[6];
>   imageData->GetExtent(extent) ;
>
> <http://vtk.1045678.n5.nabble.com/file/n5732876/2.png>
>
>   vtkIdType numberOfPointArrays =
> imageData->GetPointData()->GetNumberOfArrays();
>   std::cout << "Number of PointData arrays: " << numberOfPointArrays <<
> std::endl;
>
>   cout<< "Number of Scalar Components:
> "<<imageData->GetNumberOfScalarComponents()<<endl;
>
>   for(vtkIdType i = 0; i < numberOfPointArrays; i++)
>     {
>     // The following two lines are equivalent
>
> //arrayNames.push_back(polydata->GetPointData()->GetArray(i)->GetName());
>     //arrayNames.push_back(polydata->GetPointData()->GetArrayName(i));
>     int dataTypeID = imageData->GetPointData()->GetArray(i)->GetDataType();
>     std::cout << "Array " << i << ": " <<
> reader->GetOutput()->GetPointData()->GetArrayName(i)
>               << " (type: " << dataTypeID << ")" << std::endl;
>
>     }
>
> vtkSmartPointer<vtkClipVolume> vol =
>     vtkSmartPointer<vtkClipVolume>::New();
>
>         vol->SetInputData(imageData);
>         double tryval=-5.4861292803319049e+303;//* */Not sure which value
> I should
> for clipping/*
>         vol->SetValue(tryval);
>         vol->Update();
>
> *For few slices (50) vtkClipVolume is working but for entire series it
> throwing memory exception. I think I might need to use some other
> functionalities. Please give me some suggestion.*
>

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.

Best regards,
Cory

-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/ea34d6fa/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ThresholdImageData.png
Type: image/png
Size: 6201 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/ea34d6fa/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ClipImageData.png
Type: image/png
Size: 16688 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/ea34d6fa/attachment-0001.png>


More information about the vtkusers mailing list