VTK 三维轮廓等值面的提取
来源:互联网 发布:淘宝装修代码教程 编辑:程序博客网 时间:2024/05/26 02:54
目的: 学习VTK可视化
案例一
<span style="font-size:12px;">/************************************************************************//* 可视化基础算法-三维轮廓面(等值面)提取 *//************************************************************************//#include "stdafx.h"#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); #include "vtkActor.h"#include "vtkCamera.h"#include "vtkPolyData.h"#include "vtkRenderer.h"#include "vtkRenderWindow.h"#include "vtkPolyDataMapper.h"#include "vtkRenderWindowInteractor.h"#include <vtkImageData.h>#include <vtkVectorNorm.h> #include <vtkMergePoints.h> #include <vtkSmartPointer.h>#include <vtkMarchingCubes.h> #include <vtkVolume16Reader.h>#include <vtkPolyDataMapper.h> int _tmain(int argc, _TCHAR* argv[]){vtkSmartPointer<vtkVolume16Reader> pVol16Read = vtkVolume16Reader::New();pVol16Read->SetDataDimensions(64, 64); // 设置每幅图像的像数尺寸pVol16Read->SetDataByteOrderToLittleEndian(); // 标识所读取文件的字节序,对于PC机,进行该设置pVol16Read->SetFilePrefix("F:\\ZYHWorkspace\\Data\\headsq\\quarter"); //设置读取的图像文件名前缀pVol16Read->SetImageRange(1, 93);pVol16Read->SetDataOrigin(0, 0, 0);pVol16Read->SetDataSpacing(3.2, 3.2, 1.5);// 归并重合的点vtkSmartPointer<vtkMergePoints> pMergePoints = vtkMergePoints::New();pMergePoints->SetDivisions(32, 32, 46);pMergePoints->SetNumberOfPointsPerBucket(100);// 定义移动立方体过滤器对象vtkSmartPointer<vtkMarchingCubes> pMarchCube = vtkMarchingCubes::New();pMarchCube->SetInputData((vtkDataObject *) pVol16Read->GetOutput()); // 处理体数据pMarchCube->SetValue(0, 1150); // 设置提取的等值面的值pMarchCube->ComputeGradientsOn();pMarchCube->ComputeScalarsOff();pMarchCube->SetLocator(pMergePoints); // 生成等值面单元、顶点的标量值vtkSmartPointer<vtkVectorNorm> pVectorNormal = vtkVectorNorm::New();pVectorNormal->SetInputData(pMarchCube->GetOutput());double Rang[2];pVectorNormal->GetOutput()->GetScalarRange(Rang);// 得到生成的标量值范围vtkSmartPointer<vtkPolyDataMapper> pMapper = vtkPolyDataMapper::New();pMapper->SetInputData((vtkPolyData *) pVectorNormal->GetOutput());pMapper->ScalarVisibilityOn();pMapper->SetScalarRange(0, 1250);vtkSmartPointer<vtkActor> pActor = vtkActor::New();pActor->SetMapper(pMapper);vtkSmartPointer<vtkRenderer> pRen = vtkRenderer::New();pRen->AddActor(pActor);pRen->ResetCamera();pRen->SetBackground(1, 1, 1);vtkSmartPointer<vtkRenderWindow> pRenWin = vtkRenderWindow::New();pRenWin->AddRenderer(pRen);pRenWin->SetSize(500, 500);pRenWin->Render();vtkSmartPointer<vtkRenderWindowInteractor> pRenI = vtkRenderWindowInteractor::New();pRenI->SetRenderWindow(pRenWin);pRenI->Start();return 0;}</span><span style="font-size:14px;"></span>
案例二
// MarchingCubeVTK2.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); #include <vtkRenderer.h>#include <vtkRenderWindow.h>#include <vtkRenderWindowInteractor.h>#include <vtkVolume16Reader.h>#include <vtkPolyDataMapper.h>#include <vtkActor.h>#include <vtkOutlineFilter.h>#include <vtkCamera.h>#include <vtkProperty.h>#include <vtkPolyDataNormals.h>#include <vtkContourFilter.h>#include <vtkSmartPointer.h>int _tmain(int argc, _TCHAR* argv[]){// Create the renderer, the render window, and the interactor. The renderer// draws into the render window, the interactor enables mouse- and // keyboard-based interaction with the data within the render window.//vtkSmartPointer<vtkRenderer> aRenderer = vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();renWin->AddRenderer(aRenderer);vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();iren->SetRenderWindow(renWin);// The following reader is used to read a series of 2D slices (images)// that compose the volume. The slice dimensions are set, and the// pixel spacing. The data Endianness must also be specified. The reader// uses the FilePrefix in combination with the slice number to construct// filenames using the format FilePrefix.%d. (In this case the FilePrefix// is the root name of the file: quarter.)vtkSmartPointer<vtkVolume16Reader> v16 = vtkSmartPointer<vtkVolume16Reader>::New();v16->SetDataDimensions (64,64);v16->SetImageRange (1,93);v16->SetDataByteOrderToLittleEndian();v16->SetFilePrefix ("F:\\ZYHWorkspace\\Data\\headsq\\quarter");v16->SetDataSpacing (3.2, 3.2, 1.5);// An isosurface, or contour value of 500 is known to correspond to the// skin of the patient. Once generated, a vtkPolyDataNormals filter is// is used to create normals for smooth surface shading during rendering.vtkSmartPointer<vtkContourFilter> skinExtractor = vtkSmartPointer<vtkContourFilter>::New();skinExtractor->SetInputConnection(v16->GetOutputPort());skinExtractor->SetValue(0, 500);vtkSmartPointer<vtkPolyDataNormals> skinNormals = vtkSmartPointer<vtkPolyDataNormals>::New();skinNormals->SetInputConnection(skinExtractor->GetOutputPort());skinNormals->SetFeatureAngle(60.0);vtkSmartPointer<vtkPolyDataMapper> skinMapper = vtkSmartPointer<vtkPolyDataMapper>::New();skinMapper->SetInputConnection(skinNormals->GetOutputPort());skinMapper->ScalarVisibilityOff();vtkSmartPointer<vtkActor> skin = vtkSmartPointer<vtkActor>::New();skin->SetMapper(skinMapper);// An outline provides context around the data.vtkSmartPointer<vtkOutlineFilter> outlineData = vtkSmartPointer<vtkOutlineFilter>::New();outlineData->SetInputConnection(v16->GetOutputPort());vtkSmartPointer<vtkPolyDataMapper> mapOutline = vtkSmartPointer<vtkPolyDataMapper>::New();mapOutline->SetInputConnection(outlineData->GetOutputPort());vtkSmartPointer<vtkActor> outline = vtkSmartPointer<vtkActor>::New();outline->SetMapper(mapOutline);outline->GetProperty()->SetColor(0,0,0);// It is convenient to create an initial view of the data. The FocalPoint// and Position form a vector direction. Later on (ResetCamera() method)// this vector is used to position the camera to look at the data in// this direction.vtkSmartPointer<vtkCamera> aCamera = vtkSmartPointer<vtkCamera>::New();aCamera->SetViewUp (0, 0, -1);aCamera->SetPosition (0, 1, 0);aCamera->SetFocalPoint (0, 0, 0);aCamera->ComputeViewPlaneNormal();aCamera->Azimuth(30.0);aCamera->Elevation(30.0);// Actors are added to the renderer. An initial camera view is created.// The Dolly() method moves the camera towards the FocalPoint,// thereby enlarging the image.aRenderer->AddActor(outline);aRenderer->AddActor(skin);aRenderer->SetActiveCamera(aCamera);aRenderer->ResetCamera ();aCamera->Dolly(2.5);// Set a background color for the renderer and set the size of the// render window (expressed in pixels).aRenderer->SetBackground(.2, .3, .4);renWin->SetSize(640, 480);// Note that when camera movement occurs (as it does in the Dolly()// method), the clipping planes often need adjusting. Clipping planes// consist of two planes: near and far along the view direction. The // near plane clips out objects in front of the plane; the far plane// clips out objects behind the plane. This way only what is drawn// between the planes is actually rendered.aRenderer->ResetCameraClippingRange ();// Initialize the event loop and then start it.iren->Initialize();iren->Start();return 0;}
读取数据有问题吗? 不应该啊我都设置成绝对路径了,怎么还不对!
0 0
- VTK 三维轮廓等值面的提取
- VTK教程之十 可视化基础算法-三维轮廓面(等值面)提取
- vtk 提取等值面并显示
- VTK 表面重建-等值面提取
- VTK轮廓提取
- VTK:对输入的三维模型在某个方向等间距提取模型的切面轮廓线
- MarchingCubes算法提取等值面的基本原理
- VTK修炼之道55:图形基本操作进阶_表面重建技术(等值面提取)
- VTK 面绘制 三维数据源
- 图像轮廓的提取
- 聚焦等值面的创建
- 聚焦等值面的创建
- 计算提取轮廓的面积
- 【VTK】VTK中设置默认的三维切片方向
- 从分析blender轮廓提取技术中学习opengl如何绘制三维模型轮廓
- VTK修炼之道61:体绘制_光线投影+最大密度投影+等值面法
- 轮廓提取
- 轮廓提取
- java反射机制
- lintcode segment-tree-query 线段树的查询
- 如何在高并发分布式系统中生成全局唯一Id
- Axure心得体会
- MVVM-Reactive框架
- VTK 三维轮廓等值面的提取
- CSS display 属性
- Exception:两个类具有相同的 XML 类型名称,请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称
- Make Your Shoe Shopping Wiser
- [libevent]event_process_active()
- C/C++的内存泄漏检测工具Valgrind memcheck的使用经历
- 解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variabl
- 安装jieba分词库
- HDU2141