VTK 深度剥离算法(Depth Peeling)半透明实现

#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h" 
#include "vtkRenderer.h" 
#include "vtkActor.h" 
#include "vtkImageSinusoidSource.h"
#include "vtkImageData.h" 
#include "vtkImageDataGeometryFilter.h" 
#include "vtkDataSetSurfaceFilter.h" 
#include "vtkPolyDataMapper.h" 
#include "vtkLookupTable.h" 
#include "vtkCamera.h" 
int main() {
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();  
	vtkRenderWindow *renWin = vtkRenderWindow::New(); 
	renWin->SetMultiSamples(0);  
	renWin->SetAlphaBitPlanes(1); 
	iren->SetRenderWindow(renWin);  
	renWin->Delete();    
	vtkRenderer *renderer = vtkRenderer::New(); 
	renWin->AddRenderer(renderer); 
	renderer->Delete();  
	renderer->SetUseDepthPeeling(1);
	renderer->SetMaximumNumberOfPeels(200); 
	renderer->SetOcclusionRatio(0.1);   
	vtkImageSinusoidSource *imageSource = vtkImageSinusoidSource::New();  
	imageSource->SetWholeExtent(0, 9, 0, 9, 0, 9); 
	imageSource->SetPeriod(5);  imageSource->Update();   
	vtkImageData *image = imageSource->GetOutput();  
	double range[2];  
	image->GetScalarRange(range);    
	vtkDataSetSurfaceFilter *surface = vtkDataSetSurfaceFilter::New(); 
	surface->SetInputConnection(imageSource->GetOutputPort()); 
	imageSource->Delete();
	vtkPolyDataMapper *mapper = vtkPolyDataMapper::New(); 
	mapper->SetInputConnection(surface->GetOutputPort()); 
	surface->Delete();   
	vtkLookupTable *lut = vtkLookupTable::New(); 
	lut->SetTableRange(range);  
	lut->SetAlphaRange(0.5, 0.5); 
	lut->SetHueRange(0.2, 0.7); 
	lut->SetNumberOfTableValues(256); 
	lut->Build();   
	mapper->SetScalarVisibility(1);
	

		mapper->SetLookupTable(lut); 
		lut->Delete();   
		vtkActor *actor = vtkActor::New();
		renderer->AddActor(actor);
		actor->Delete(); 
		actor->SetMapper(mapper); 
		mapper->Delete();  
		renderer->SetBackground(0.1, 0.3, 0.0); 
		renWin->SetSize(400, 400);   
		renWin->Render();  
		if (renderer->GetLastRenderingUsedDepthPeeling()) 
		{ cout << "depth peeling was used" << endl; }
		else
		{ cout << "depth peeling was not used (alpha blending instead)" << endl; } 
		vtkCamera *camera = renderer->GetActiveCamera();  
		camera->Azimuth(-40.0);  
		camera->Elevation(20.0); 
		renWin->Render();   
		iren->Start();
} 
 

VTK 深度剥离算法(Depth Peeling)半透明实现_第1张图片
VTK 深度剥离算法(Depth Peeling)半透明实现_第2张图片

你可能感兴趣的:(VTK,ITK)