[vtkusers] How do I save all slices of a volume from vtkCutter to another canvas?
Magnus Elden
magnus_elden at hotmail.com
Mon Sep 19 16:43:54 EDT 2016
I tried following the advice I was provided, but using reslice and using the cutter to get a single cut end up with nothing for the reslice and a blank plane for the cutter.
If I render the volume by itself it works fine, but I only need a single slice of that volume with the transfer functions. I have been able to save an image to another canvas, so all I need is a xPixels*yPixels image rendered so that I can copy it into its slot on the big canvas.
Below you have the minimum code that ever rendered anything for me. I followed the examples as best I could, but I was unable to make sense of this.
vtkSmartPointer<vtkImageData> imageData =
vtkSmartPointer<vtkImageData>::New();
vtkSmartPointer<vtkXMLImageDataReader> reader =
vtkSmartPointer<vtkXMLImageDataReader>::New();
reader->SetFileName(path.c_str());
reader->Update();
reader->GetOutput()->Register(reader);
imageData->ShallowCopy(reader->GetOutput());
double bounds[6];
reader->GetOutput()->GetBounds(bounds);//Get the bounds of the volume. X0x1, y0y1, z0z1
vtkSmartPointer<vtkPlane> plane =
vtkSmartPointer<vtkPlane>::New();//This plane is used to define the cutting plane.
plane->SetOrigin(0, 0, 0);
plane->SetNormal(0, 1, 0);
// Create model actor
vtkSmartPointer<vtkLookupTable> lut =
vtkSmartPointer<vtkLookupTable>::New();//This seems to be required to render anything at all.
lut->SetRange(0.3, 1); // image intensity range
lut->SetValueRange(0.3, 1.0); // from black to white
lut->SetSaturationRange(0.3, 1.0); // no color saturation
lut->SetTableRange(0.2, 1.0);
lut->SetRampToLinear();
lut->SetBelowRangeColor(1, 1, 1, 1);
lut->Build();
vtkSmartPointer<vtkCutter> cutter =
vtkSmartPointer<vtkCutter>::New();//The object doing the cutting for us.
cutter->SetInputConnection(reader->GetOutputPort());
cutter->SetCutFunction(plane);
cutter->GenerateValues(1, 0.1, 0.1);
vtkSmartPointer<vtkImageReslice> reslice =
vtkSmartPointer<vtkImageReslice>::New();//No idea what this is supposed to do.
reslice->SetOutputExtent(0, 600, 0, 600, 0, 0);
reslice->SetInputData(reader->GetOutput());
reslice->Update();
vtkSmartPointer<vtkPolyDataMapper> cutterMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
cutterMapper->SetInputConnection(cutter->GetOutputPort());//Change betweent he cutter and reslice here
cutterMapper->SetLookupTable(lut);
cutterMapper->UseLookupTableScalarRangeOn();
// Create cut actor
vtkSmartPointer<vtkActor> sliceActor =
vtkSmartPointer<vtkActor>::New();
sliceActor->SetMapper(cutterMapper);
Thank you for your time.
Yours,
Magnus Elden
From: Sankhesh Jhaveri [mailto:sankhesh.jhaveri at kitware.com]
Sent: Monday, 12 September, 2016 15:36
To: Magnus Elden <magnus_elden at hotmail.com>
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] How do I save all slices of a volume from vtkCutter to another canvas?
Hi Magnus,
First of all, if the goal is to just slice the volume consider using vtkImageReslice (http://www.vtk.org/Wiki/VTK/Examples/Cxx/ImageData/ImageReslice) instead of vtkCutter.
You can simply set the output image data of the vtkImageReslice to a vtkImageActor and add it to a vtkRenderer as in http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/InteractWithImage
Hope that helps.
Sankhesh Jhaveri
Sr. Research & Development Engineer | Kitware<http://www.kitware.com> | (518) 881-4417
On Sat, Sep 10, 2016 at 8:01 PM, Magnus Elden <magnus_elden at hotmail.com<mailto:magnus_elden at hotmail.com>> wrote:
I have a volume that the class vtkCutter cuts into n slices. Now I need to save a render of each slice to another larger canvas to generate something similar to this: http://previews.123rf.com/images/bunyos/bunyos1403/bunyos140300039/26777884-MRI-scan-of-the-human-brain-Stock-Photo.jpg
I am able to render it by linking the cutter output to a mapper and then into a vtkActor that I add to the renderer, but I have no idea how I can render each slice to a canvas. In the worst case I just want the renders to be all stored to disk.
Thank you for your help.
Yours,
Magnus Elden
_______________________________________________
Powered by www.kitware.com<http://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
Search the list archives at: http://markmail.org/search/?q=vtkusers
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160919/8cfc8307/attachment.html>
More information about the vtkusers
mailing list