vtk read jpg

vtkSmartPointer<vtkPolyData>  getPolyData(int start, int index)
{
	vtkSmartPointer<vtkJPEGReader>Reader = vtkSmartPointer<vtkJPEGReader>::New();
	Reader->SetDataScalarTypeToUnsignedChar();
	Reader->SetFileDimensionality(1);
	Reader->SetFilePrefix("./mriUseForVtk-jpg");
	Reader->SetFileNameSliceSpacing(1);
	Reader->SetFilePattern("%s/%d.jpg");
	Reader->SetDataExtent(0, 320, 0, 320, start, index);//设置数据的尺寸,后面为1-100张图片
	// 每张图片的长宽为320 * 320 因此设置为0,320 ;这里因为在000文件夹里面有0.jpg ~ 29.jpg,所以设置为 0,20


	Reader->SetDataSpacing(0.7, 0.7, 4.4);
	Reader->Update();

	vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter =
		vtkSmartPointer<vtkImageGaussianSmooth>::New();
	gaussianSmoothFilter->SetInputConnection(Reader->GetOutputPort());
	gaussianSmoothFilter->SetDimensionality(3);
	gaussianSmoothFilter->SetRadiusFactor(5);
	gaussianSmoothFilter->SetStandardDeviation(1);
	gaussianSmoothFilter->Update();//这是添加的图像平滑处理,高斯平滑

	vtkSmartPointer<vtkMarchingCubes>marchingcube = vtkSmartPointer<vtkMarchingCubes>::New();
	marchingcube->SetInputData(gaussianSmoothFilter->GetOutput());
	//marchingcube->SetInputConnection(Reader->GetOutputPort());      //第⼆种读取数据的⽅法
	marchingcube->SetValue(0, 70);
	marchingcube->ComputeNormalsOn();//计算表面法向量;

	marchingcube->Update();

	vtkSmartPointer<vtkStripper>Stripper = vtkSmartPointer<vtkStripper>::New();
	Stripper->SetInputData(marchingcube->GetOutput());
	Stripper->Update();

	vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();
	poly->DeepCopy(Stripper->GetOutput());
	return poly;
}
int main()
{
	//vtkSmartPointer<vtkJPEGReader>reader =  //读取图像,利用其中方法对
	//	vtkSmartPointer<vtkJPEGReader>::New();
	//reader->SetFilePrefix("./mriUseForVtk-jpg");  //设置序列图片相同部分的路径
	//reader->SetFilePattern("%s/%d.jpg");  //图片格式,%04显示四位数,不足的拿0表示
	//reader->SetDataExtent(0, 255, 0, 255, 1, 51);//设置数据的尺寸,后面为1-100张图片
	// 
	//reader->SetDataSpacing(0.7,0.7,4.4);
	//reader->Update();

	vtkSmartPointer<vtkRenderer>ren = vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow>renWin = vtkSmartPointer<vtkRenderWindow>::New();
	renWin->AddRenderer(ren);
	vtkSmartPointer<vtkRenderWindowInteractor>iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	iren->SetRenderWindow(renWin);


	vtkSmartPointer<vtkPolyData> poly = getPolyData(0,1);


	vtkSmartPointer<vtkPolyDataMapper>polyMapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();


	

	vtkSmartPointer<vtkTransform> pTransformSTL = vtkSmartPointer<vtkTransform>::New();
	//pTransformSTL->SetInput(actorStl->GetUserTransform());
	//pTransformSTL->RotateY(30);
	pTransformSTL->Update();

	vtkSmartPointer<vtkTransformPolyDataFilter> pTransformPolyDataFilterSTL = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
	pTransformPolyDataFilterSTL->SetInputData(poly);
	pTransformPolyDataFilterSTL->SetTransform(pTransformSTL);
	pTransformPolyDataFilterSTL->Update();
 
	vtkSmartPointer<vtkPolyDataMapper>polyMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	polyMapper->SetInputData(pTransformPolyDataFilterSTL->GetOutput());
	polyMapper->ScalarVisibilityOff();


	{
	
		 vtkSmartPointer<vtkPolyData> poly = getPolyData(12,13);
		// 
		//vtkSmartPointer<vtkTransform> pTransformSTL = vtkSmartPointer<vtkTransform>::New();
		pTransformSTL->SetInput(actorStl->GetUserTransform());
		//pTransformSTL->Translate(poly->GetCenter());
		//pTransformSTL->RotateX(90);
		//pTransformSTL->Update();

		vtkSmartPointer<vtkTransformPolyDataFilter> pTransformPolyDataFilterSTL = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
		pTransformPolyDataFilterSTL->SetInputData(poly);
		pTransformPolyDataFilterSTL->SetTransform(pTransformSTL);
		pTransformPolyDataFilterSTL->Update();

		polyMapper1->SetInputData(pTransformPolyDataFilterSTL->GetOutput());
		polyMapper1->ScalarVisibilityOff();
	}



//	vtkSmartPointer<vtkActor>actor = vtkSmartPointer<vtkActor>::New();
//	actor->SetMapper(polyMapper);
//	//actor->GetProperty()->SetDiffuseColor(1, 0.19, 0.15);
//	//actor->GetProperty()->SetSpecular(0.1);
//	//actor->GetProperty()->SetSpecularPower(10);
//	//actor->GetProperty()->SetColor(1, 0, 0);
//	actor->GetProperty()->SetDiffuseColor(1, .49, .25);            //设置皮肤颜色的属性//(1, .49, .25)
actor->GetProperty()->SetDiffuseColor(1, 1, .25);
//	actor->GetProperty()->SetSpecular(0.3);                         //设置反射率
//	actor->GetProperty()->SetSpecularPower(20);                    //设置反射光强度 
//	actor->GetProperty()->SetOpacity(1.0);
//	//actor->GetProperty()->SetColor(1, 0, 0);                 //设置角色的颜色
//	actor->GetProperty()->SetRepresentationToWireframe();


	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();//Created a actor;

	vtkSmartPointer<vtkActor> actor1 = vtkSmartPointer<vtkActor>::New();//Created a actor;

	actor1->SetMapper(polyMapper1);

	actor->SetMapper(polyMapper);//获得皮肤几何数据
	actor->GetProperty()->SetDiffuseColor(1, .49, .25);//设置皮肤颜色;
	actor->GetProperty()->SetSpecular(0.3);//反射率;
	actor->GetProperty()->SetOpacity(1.0);//透明度;
	actor->GetProperty()->SetSpecularPower(20);//反射光强度;
	actor->GetProperty()->SetColor(1, 0.52, 0.30);//设置角的颜色;
	actor->GetProperty()->SetRepresentationToWireframe();//线框;

	vtkSmartPointer<vtkOutlineFilter>outlinefilter = vtkSmartPointer<vtkOutlineFilter>::New();
	//outlinefilter->SetInputConnection(Reader->GetOutputPort());

	vtkSmartPointer<vtkPolyDataMapper>outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
	outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());

	vtkSmartPointer<vtkActor>outlineActor = vtkSmartPointer<vtkActor>::New();
	outlineActor->SetMapper(outlineMapper);
	outlineActor->GetProperty()->SetColor(0, 0, 0);

	vtkSmartPointer<vtkCamera>aCamera = vtkSmartPointer<vtkCamera>::New();
	//aCamera->SetViewUp(0, 0, -1);
	//aCamera->SetPosition(0, 1, 0);
	//aCamera->SetFocalPoint(0, 0, 0);
	//aCamera->ComputeViewPlaneNormal();

	ren->AddActor(actor);
	ren->AddActor(actor1);
	ren->ResetCamera();
	ren->ResetCameraClippingRange();
	ren->SetBackground(0, 0, 0);//设置背景颜色;
	renWin->SetSize(1000, 600);

	//ren->AddActor(outlineActor);
	//ren->SetActiveCamera(aCamera);
	//ren->ResetCamera();
	//aCamera->Dolly(1.5);

	//ren->SetBackground(1, 1, 1);
	//renWin->SetSize(640, 640);


	ren->ResetCameraClippingRange();
	iren->Initialize();
	iren->Start();
	return EXIT_SUCCESS;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恋恋西风

up up up

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值