[vtkusers] How can I write a picture to VTK format file ?

zhq 15891495523 at 126.com
Tue Sep 23 09:41:26 EDT 2014


Deal all :

      I want to write a picture into VTK format file . And following code is
my test code :
      (VS2012+VTK6.0)

	vtkSmartPointer<vtkStructuredGridWriter> writer =
vtkSmartPointer<vtkStructuredGridWriter>::New();
	vtkSmartPointer<vtkImageData> Img = vtkSmartPointer<vtkImageData>::New();
	Img->SetDimensions(3,3,3);


	Img->AllocateScalars(VTK_INT,1);
	int cur=1;
	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			for (int k=0;k<3;k++)
			{
				int * pixel = (int *)Img->GetScalarPointer(i,j,k);
				*pixel=cur;
				cur++;
			}
		}
	}

	writer->SetInputData(Img);
	writer->SetFileName("C:\\Users\\zhq\\Desktop\\1.vtk");
	writer->Update();
	writer->Write();


        And the error is :

ERROR: In D:\Program
Files\ITK_VTK\VTK6.0\VTK6.0.0\Common\ExecutionModel\vtkDema
ndDrivenPipeline.cxx, line 815
vtkCompositeDataPipeline (00000000002CA5D0): Input for connection index 0 on
inp
ut port index 0 for algorithm vtkStructuredGridWriter(00000000002C7860) is
of ty
pe vtkImageData, but a vtkStructuredGrid is required.


        Could somebody give me some help ! Thanks in advance !

Zhq



--
View this message in context: http://vtk.1045678.n5.nabble.com/How-can-I-write-a-picture-to-VTK-format-file-tp5728843.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list