[vtkusers] how to combine x and y direction slices together

ruhu ruhu43 at qq.com
Mon Aug 11 22:13:53 EDT 2014


Hi friends,
 
 I have a  question that Puzzled for a long time.
 The original data is composed of X and Y two direction data, I use 
vtkimagedata to get the 3D data, then   i want combine the X and Y  slices
together.  But only the X *or* Y slice  can be displayed ,How can display
the combine slice of X *and* Y. 
 
could anyone help me ?

the  source  code as follows :
void CCBCTVRDoc::OnFileOpen()
{
CString FilePathName; 
	 CFileDialog dlg( TRUE, NULL, NULL,  

		 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,  

		 (LPCTSTR)_TEXT("segy Files (*.seg)|*.lte|All Files (*.*)|*.*||"),  

		 NULL );  
	 if(dlg.DoModal()==IDOK)  

	 {  
		 
		 FilePathName=dlg.GetPathName();  
		 CFile file;
		 file.Open(FilePathName,CFile::modeRead);
		 vtkSmartPointer<vtkJPEGReader> reader =
vtkSmartPointer<vtkJPEGReader>::New();  
		
		  short* m_pOriginalData;
		 m_pOriginalData=new   short [1024*180*42];//
		 file.Seek(1024,CFile::begin);
		 file.Read(m_pOriginalData,1024*180*42*2);//
		
		 vtkSmartPointer<vtkImageData>img=vtkSmartPointer<vtkImageData>::New();
		  img->SetDimensions(180,21,1024);
		  img->SetScalarTypeToUnsignedChar();
		  img->SetNumberOfScalarComponents(1);
		  img->SetSpacing(2.8,24,0.5); 
		  img->AllocateScalars();
		  int index=0;
		  
		  for (int j=0;j<21;j++)
		  {
			  for (int i=0;i<180;i++)
			  {
				  for (int k=0;k<1024;k++)
				  {
					  unsigned char * pixel =(unsigned char*)img->GetScalarPointer(i,j ,
k);
					  *pixel=m_pOriginalData[index++]/256+128;
				  }
			  }
		  }

		vtkImageShrink3D* mask = vtkImageShrink3D::New();
		mask->SetShrinkFactors(3,3,3);
		mask->SetInput(img);
	

		vtkSmartPointer<vtkImageData>img1=vtkSmartPointer<vtkImageData>::New();
		img1->SetDimensions(21,180,1024);
		img1->SetScalarTypeToUnsignedChar();
		img1->SetNumberOfScalarComponents(1);
		img1->SetSpacing(24,2.8,0.5); 
		img1->AllocateScalars();
		
		  for (int j=0;j<21;j++)
		  {
			  for (int i=0;i<180;i++)
			  {
				  for (int k=0;k<1024;k++)
				  {
					  unsigned char * pixel =(unsigned char*)img1->GetScalarPointer(j,i ,
k);
					  *pixel=m_pOriginalData[index++]/256+128;
				  }
			  }
		  }

		vtkImageShrink3D* mask1 = vtkImageShrink3D::New();
		mask1->SetShrinkFactors(3,3,3);
		mask1->SetInput(img1);


		 int extent[6];
		 double spacing[3];
		 double origin[3];
		 mask->GetOutput()->GetExtent(extent);
		 mask->GetOutput()->GetSpacing(spacing);
		 mask->GetOutput()->GetOrigin(origin);

		 double center[3];
		 center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
		 center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
		center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);
		static double axialElements[16] = {
			1, 0, 0, 0,
			0, 1, 0, 0,
			0, 0, 1, 0,
			0, 0, 0, 1 };
			
		vtkSmartPointer<vtkMatrix4x4> resliceAxes
=vtkSmartPointer<vtkMatrix4x4>::New();
		resliceAxes->DeepCopy(axialElements);
		resliceAxes->SetElement(0, 3, center[0]);
		resliceAxes->SetElement(1, 3, center[1]);
		resliceAxes->SetElement(2, 3, center[2]);


		 int extent1[6];
		 double spacing1[3];
		 double origin1[3];
		 mask1->GetOutput()->GetExtent(extent1);
		 mask1->GetOutput()->GetSpacing(spacing1);
		 mask1->GetOutput()->GetOrigin(origin1);

		 double center1[3];
		 center1[0] = origin1[0] + spacing1[0] * 0.5 * (extent1[0] + extent1[1]);
		 center1[1] = origin1[1] + spacing1[1] * 0.5 * (extent1[2] + extent1[3]);
		 center1[2] = origin1[2] + spacing1[2] * 0.5 * (extent1[4] + extent1[5]);
		static double axialElements1[16] = {
			1, 0, 0, 0,
			0, 1, 0, 0,
			0, 0, 1, 0,
			0, 0, 0, 1 };
			/*	1, 0, 0, 0,
			0, 0, 1, 0,
			0,-1, 0, 0,
			0, 0, 0, 1 };*/
			/*1, 0, 0, 0,
			0, 0.866025, -0.5, 0,
			0, 0.5, 0.866025, 0,
			0, 0, 0, 1 }; */
		vtkSmartPointer<vtkMatrix4x4> resliceAxes1
=vtkSmartPointer<vtkMatrix4x4>::New();
		resliceAxes1->DeepCopy(axialElements1);
		resliceAxes1->SetElement(0, 3, center1[0]);
		resliceAxes1->SetElement(1, 3, center1[1]);
		resliceAxes1->SetElement(2, 3, center1[2]);


		vtkSmartPointer<vtkImageReslice> reslice
=vtkSmartPointer<vtkImageReslice>::New();
		vtkSmartPointer<vtkImageReslice> reslice1
=vtkSmartPointer<vtkImageReslice>::New();

	
		 reslice->SetInputConnection(mask->GetOutputPort());
		 reslice->SetOutputDimensionality(2);
		 reslice->SetResliceAxes(resliceAxes);
		 reslice->SetInterpolationModeToLinear();

		 reslice1->SetInputConnection(mask1->GetOutputPort());
		 reslice1->SetOutputDimensionality(2);
		 reslice1->SetResliceAxes(resliceAxes);
		 reslice1->SetInterpolationModeToLinear();

		 vtkSmartPointer<vtkLookupTable> colorTable
=vtkSmartPointer<vtkLookupTable>::New();
		 colorTable->SetRange(0, 256);
		 colorTable->SetValueRange(0.0, 255);
		  colorTable->SetSaturationRange(0.0, 0.0);
		  colorTable->SetRampToLinear();
		   colorTable->Build();
		   vtkSmartPointer<vtkImageMapToColors> colorMap =
			vtkSmartPointer<vtkImageMapToColors>::New();
		   colorMap->SetLookupTable(colorTable);
		   colorMap->SetInputConnection(reslice->GetOutputPort());
		   vtkSmartPointer<vtkImageActor> imgActor =
			  vtkSmartPointer<vtkImageActor>::New();
		   imgActor->SetInput(colorMap->GetOutput());
		   vtkSmartPointer<vtkRenderer> renderer =
			   vtkSmartPointer<vtkRenderer>::New();

		   vtkSmartPointer<vtkLookupTable> colorTable1
=vtkSmartPointer<vtkLookupTable>::New();
		   colorTable1->SetRange(0, 256);
		   colorTable1->SetValueRange(0.0, 255);
		   colorTable1->SetSaturationRange(0.0, 0.0);
		   colorTable1->SetRampToLinear();
		   colorTable1->Build();
		   vtkSmartPointer<vtkImageMapToColors> colorMap1=
			   vtkSmartPointer<vtkImageMapToColors>::New();
		   colorMap1->SetLookupTable(colorTable1);
		   colorMap1->SetInputConnection(reslice1->GetOutputPort());
		   vtkSmartPointer<vtkImageActor> imgActor1 =
			   vtkSmartPointer<vtkImageActor>::New();
		   imgActor1->SetInput(colorMap1->GetOutput());
		  
		renderer->AddActor(imgActor);
		 renderer->AddActor(imgActor1);
		   renderer->SetBackground(.4, .5, .6);
		   vtkSmartPointer<vtkRenderWindow> renderWindow =
			 vtkSmartPointer<vtkRenderWindow>::New();
		   renderWindow->SetSize(500, 500);
		   renderWindow->AddRenderer(renderer);
		   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
			   vtkSmartPointer<vtkRenderWindowInteractor>::New();
		  vtkSmartPointer<vtkInteractorStyleImage> imagestyle =
			   vtkSmartPointer<vtkInteractorStyleImage>::New();

		   vtkSmartPointer<vtkImageInteractionCallback> callback =

			   vtkSmartPointer<vtkImageInteractionCallback>::New();

		   callback->SetImageReslice(reslice);
		   callback->SetInteractor(renderWindowInteractor);
		   imagestyle->AddObserver(vtkCommand::MouseMoveEvent, callback);
		   imagestyle->AddObserver(vtkCommand::LeftButtonPressEvent, callback);
		   imagestyle->AddObserver(vtkCommand::LeftButtonReleaseEvent, callback);
		    renderWindowInteractor->SetInteractorStyle(imagestyle);
		   renderWindowInteractor->SetRenderWindow(renderWindow);
		   renderWindowInteractor->Initialize();
		   renderWindowInteractor->Start();

	 }
}
 

1.jpg <http://vtk.1045678.n5.nabble.com/file/n5728183/1.jpg>  
2.jpg <http://vtk.1045678.n5.nabble.com/file/n5728183/2.jpg>  
The target image
03.jpg <http://vtk.1045678.n5.nabble.com/file/n5728183/03.jpg>  
Thanks!! 



--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-combine-x-and-y-direction-slices-together-tp5728183.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list