AW: [vtkusers] How do i port an image from ITK to VTK

Erbacher, Markus Markus.Erbacher at med.uni-heidelberg.de
Wed Oct 11 10:53:08 EDT 2006


You are missing the vtkRenderWindowInteractor.
 
The way you are creating the window just opens the window, renders the scence once and then the function returns and the programm ends.
 
Use is like this:
 
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

iren->SetRenderWindow(renWin);

renWin->Render();

iren->Start(); // this starts the interactor, and only returns if ypu close the window

 
 

	-----Ursprüngliche Nachricht-----
	Von: Prename Surname [mailto:bsd.diverse at gmail.com] 
	Gesendet: Mittwoch, 11. Oktober 2006 16:40
	An: Erbacher, Markus; vtkusers at vtk.org
	Betreff: Re: [vtkusers] How do i port an image from ITK to VTK
	
	
	Hmmm yes, now i can compile.
	But the output just looks very strange...
	A small window with green noise just flashes, and then the program ends. Maybe i am missing something?
	Thank you very much.
	This is my whole code:
	 

	//Used for the analyze reader
	#include "itkImage.h"
	#include "itkImageFileReader.h"
	#include "itkImageFileWriter.h"//

	#include "itkImageToVTKImageFilter.h"//Makes ITK->VTK pipeline (remember to set path in CMakeLists.txt firs)

	#include "vtkImageViewer.h"//Makes 2D images in VTK

	//Use for volumerendering
	#include "vtkStructuredPointsReader.h"
	#include "vtkPiecewiseFunction.h"
	#include "vtkColorTransferFunction.h"
	#include "vtkVolumeProperty.h" 
	#include "vtkVolumeRayCastCompositeFunction.h"
	#include "vtkVolumeRayCastMapper.h"
	#include "vtkVolume.h"

	
	//Used for the vtk examples
	#include "vtkSphereSource.h"
	#include "vtkPolyDataMapper.h"
	#include "vtkActor.h"
	#include "vtkRenderWindow.h"
	#include "vtkRenderer.h "
	#include "vtkRenderWindowInteractor.h"

	#include "itkVTKImageExport.h"
	#include "vtkImageImport.h"

	//Used for string manipulation in c++
	#include <strstream>
	#include <string>
	#include <iostream>

	void showSphere();
	void readAFile();

	int main( int , char * argv[])
	{
	 typedef unsigned char PixelType;
	 const unsigned int Dimension=3;
	 
	 typedef itk::Image<PixelType,Dimension> ImageType;
	 typedef itk::ImageFileReader<ImageType> ReaderType; 
	 typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;

	 ReaderType::Pointer reader = ReaderType::New();
	 ConnectorType::Pointer connector = ConnectorType::New();
	 
	 reader->SetFileName("D:\\skole\\thesis\\Data\\KDIGWKFN\\ANALYZE\\KDIGWKFN_mpr_pip.img"); 
	 connector->SetInput(reader->GetOutput());//In connector lies now the imagedata. Retrieve it by calling GetOutput()
	 
	 vtkStructuredPointsReader *vtkReader=vtkStructuredPointsReader::New();
	 

	 //Create transfer mapping scalar value to color
	 vtkPiecewiseFunction *opacityTransferfunction=vtkPiecewiseFunction::New();
	 opacityTransferfunction->AddPoint(20.,0.0);
	 opacityTransferfunction->AddPoint(255., 0.2);

	 vtkColorTransferFunction *colorTransferFunction=vtkColorTransferFunction::New();
	 colorTransferFunction->AddRGBPoint(0.0,0.0,0.0,0.0);
	 colorTransferFunction->AddRGBPoint(64.0,1.0,0.0,0.0);
	 colorTransferFunction->AddRGBPoint( 128.0,0.0,0.0,1.0);
	 colorTransferFunction->AddRGBPoint(192.0,0.0,1.0,0.0);
	 colorTransferFunction->AddRGBPoint(255.0,0.0,0.2,0.0);

	 vtkVolumeProperty *volumeProperty=vtkVolumeProperty::New();
	 volumeProperty->SetColor(colorTransferFunction);
	 volumeProperty->SetScalarOpacity(opacityTransferfunction);

	 vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
	 vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
	 volumeMapper->SetVolumeRayCastFunction(compositeFunction); 
	 volumeMapper->SetInput(connector->GetOutput());
	 
	 vtkVolume *volume=vtkVolume::New();
	 volume->SetMapper(volumeMapper);
	 volume->SetProperty(volumeProperty);

	 // A renderer and render window
	 vtkRenderer *ren1 = vtkRenderer::New();
	 vtkRenderWindow *renWin = vtkRenderWindow::New();
	 ren1->AddProp(volume);
	 renWin->AddRenderer(ren1);
	 renWin->Render(); 
	 return 0;
	}



	 
	2006/10/11, Erbacher, Markus <Markus.Erbacher at med.uni-heidelberg.de>: 

		I think you can use 
		 
		vtkVolumeRayCastMapper->SetInput( ...)
		 
		Regards
		Markus

			-----Ursprüngliche Nachricht-----
			Von: vtkusers-bounces+markus.erbacher= med.uni-heidelberg.de at vtk.org <mailto:med.uni-heidelberg.de at vtk.org>  [mailto:vtkusers-bounces+markus.erbacher=med.uni-heidelberg.de at vtk.org ] Im Auftrag von Prename Surname
			Gesendet: Mittwoch, 11. Oktober 2006 16:08
			An: Brian Chacko; vtkusers at vtk.org
			Betreff: Re: [vtkusers] How do i port an image from ITK to VTK
			
			
			Hello Brian.
			I have tried to do what you said, and it makes good sense. I think i almost got i working, but i still have a doubt about how exactly i can connect the 
			itk::ImageToVTKImageFilter to the vtkVolumeRayCastMapper.
			It seems that  ImageToVTKImageFilter->GetOutput(...) returns a vtkImageData, and 
			vtkVolumeRayCastMapper->SetInputConnection(...) only accepts a vtkAlgorithmOutput object.
			 
			So how do i do the final mapping? I really hope you can help me, or any others can. 
			 
			Many regards
			 
			Here is the code:

			int main( int , char * argv[])
			{
			 typedef unsigned char PixelType;
			 const unsigned int Dimension=3;
			 
			 typedef itk::Image<PixelType,Dimension> ImageType;
			 typedef itk::ImageFileReader<ImageType> ReaderType; 
			 typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;

			 ReaderType::Pointer reader = ReaderType::New();
			 ConnectorType::Pointer connector = ConnectorType::New();
			 
			 reader->SetFileName("D:\\skole\\thesis\\Data\\KDIGWKFN\\ANALYZE\\KDIGWKFN_mpr_pip.img"); 
			 connector->SetInput(reader->GetOutput());//In connector lies now the imagedata. Retrieve it by calling GetOutput()
			 
			 vtkStructuredPointsReader *vtkReader=vtkStructuredPointsReader::New();
			 

			 //Create transfer mapping scalar value to color
			 vtkPiecewiseFunction *opacityTransferfunction=vtkPiecewiseFunction::New();
			 opacityTransferfunction->AddPoint(20.,0.0);
			 opacityTransferfunction->AddPoint(255., 0.2);

			 vtkColorTransferFunction *colorTransferFunction=vtkColorTransferFunction::New();
			 colorTransferFunction->AddRGBPoint(0.0,0.0,0.0,0.0);
			 colorTransferFunction->AddRGBPoint(64.0,1.0,0.0,0.0);
			 colorTransferFunction->AddRGBPoint( 128.0,0.0,0.0,1.0);
			 colorTransferFunction->AddRGBPoint(192.0,0.0,1.0,0.0);
			 colorTransferFunction->AddRGBPoint(255.0,0.0,0.2,0.0);

			 vtkVolumeProperty *volumeProperty=vtkVolumeProperty::New();
			 volumeProperty->SetColor(colorTransferFunction);
			 volumeProperty->SetScalarOpacity(opacityTransferfunction);

			 vtkVolumeRayCastCompositeFunction *compositeFunction=vtkVolumeRayCastCompositeFunction::New();
			 vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
			 volumeMapper->SetVolumeRayCastFunction(compositeFunction); 
			 
			 volumeMapper->SetInputConnection(connector->GetOutput()); //This i cannot do. What should i do instead?

			 
			2006/10/11, Brian Chacko <brianchacko at yahoo.com>: 

				Hello! 
				I suggest you go through the link given below. It gives basics of using ITK and visualizing in VTK.
				http://www.itk.org/CourseWare/Training/GettingStarted-II.pdf
				 
				[P.N The header file itkImageToVTKImageFilter.h is not available as it is, when you download the ITK software source. Download  InsightApplications-2.8.1.zip <http://prdownloads.sourceforge.net/itk/InsightApplications-2.8.1.zip?download> . It is available in the ITK download page. Include the header file with the .cxx file in the VTK 5.0\IO\  (or any sub folder of vtk 5.0 which contains headers and source files). Remember to include the appropriate library file in your CMakeLists.txt)].
				 
				To  visualize volume view, try out the volume example in VTK folder 
				Directory path is     "\VTK 5.0\Examples\VolumeRendering\Tcl\SimpleRayCast.tcl".

				Regards
				Brian
				
				 
				 
				Prename Surname <bsd.diverse at gmail.com> wrote:

					
					Hello
					I am reading files from ANALYZE format in ITK. I do processing of the image, and then i want to visualize it in VTK.
					So  my question is how i get the data fra ITK to VTK, and is it then difficult to show a volumne view of the data in VTK?
					A codeexample would be very nice. Thank you very much
					 
					Best of regards
					_______________________________________________
					This is the private VTK discussion list. 
					Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
					Follow this link to subscribe/unsubscribe:
					http://www.vtk.org/mailman/listinfo/vtkusers 
					

				
				

				
________________________________

				How low will we go? Check out Yahoo! Messenger's low PC-to-Phone call rates. <http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com> 

				

				

				

				



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061011/520c5b69/attachment.htm>


More information about the vtkusers mailing list