【转】VTK修炼之道2_VTK体系结构1

1.OverView综述

The Visualization Toolkit consists of two basic subsystems: a compiled C++ class library (一个已经编译好的C++类库)and an “interpreted” wrapper layer(一个用于解释的语言层) that lets you manipulate the compiled classes using the languages Java, Tcl, and Python.

Tcl(最早称为“工具命令语言”"Tool Command Language", 但是目前已经不是这个含义,不过我们仍然称呼它为TCL)是一种脚本语言。 由John Ousterhout创建。 TCL很好学,功能很强大。TCL经常被用于 快速原型开发,脚本编程,GUI和测试等方面。TCL念作“踢叩” "tickle".

The Visualization Toolkit is an object-oriented system(面向对象的体系). The key to using VTK effectively is to
develop a good understanding of the underlying object models(想使用好VTK,就要充分理解最基本的对象模型). Doing so will remove much of the mystery surrounding the use of the hundreds of objects in the system. With this understanding in place it’s much easier to combine objects to build applications. You’ll also need to know something about the capabilities of the many objects in the system(同时,我们也应该理解体系中很多对象的基本功能)。

2.Low-Level Object Model低级对象模型

The VTK object model can be thought of as being rooted in the superclass vtkObject. Nearly all VTK
classes are derived from this class, or in some special cases from its superclass vtkObjectBase.(几乎所有的VTK对象都源于超类:vtkObject;除了一些特殊情况下是来源于vtkObjectBase;这里提及到的超类是指一个或者多个来由此派生;) All VTK must be created using the object's New() method, and must be destroyed using the object's Delete() method. VTK objects cannot be allocated on the stack because the constructor is a protected method. (因为VTK的构造函数采用保护类型,所以VTK的对象无法在堆上进行创建并分配内存,只能通过New()和Delete()方法进行对象的创建与销毁)Using a common superclass and a unified method of creating and destroying object, VTK is able to provide several basic object-oriented operations.

2.1 Reference Counting引用计数

Objects explicitly store a count of the number of pointers referencing them. When an object is created through the static New() method of a class its initial reference count is 1 because a raw pointer must be used to refer to the new object:

vtkObjectBase* obj = vtkExampleClass::New();
When other references to the object are created or destroyed the reference count is incremented and
decremented using the Register() and UnRegister() methods. Usually this is handled automatically by
the various “set” methods provided in the object’s API:
otherObject->SetExample(obj);
The reference count is now 2 because both the original pointer and a pointer stored inside the otherobject both refer to it. When the raw pointer originally storing the object is no longer needed the reference is removed using the Delete() method:
obj->Delete();

 

从上面我们可以看到,对象的创建以及销毁完全靠手动完成,一旦我们处理不好,就会造成内存泄漏。为了避免这是,可以采用 “智能指针”。(智能指针是通过类模板进行定义的)

因此,上面的程序代码我们可以改写成:

vtkSmartPointer<vtkObjectBase> obj = vtkSmartPointer<vtkExampleClass>::New();
otherObject->SetExample(obj);
此时,我们就没有必要再去调用Delete()方法撤销对象。

2.2 Run-Time Type Information运行时类型信息

In C++ the real type of an object may be different from the type of pointer used to reference it. (真实的对象类型可能和引用的指针类型不同)All classes in the public interface of VTK have simple identifiers for class names (no templates), so a string is sufficient to identify them. (用一个字符串来标识)The type of a VTK object may be
obtained at run-time with the GetClassName() method(用GetClassName()可以得到VTK对象的类型):


 

<span style="font-size:18px;">const char* type = obj->GetClassName();</span>
An object may be tested for whether it is an instance of a particular class or one of its subclasses using
the IsA() method(通过下面的方法我们可以检测一个对象是否是一个类的实例):
<span style="font-size:18px;">if(obj->IsA("vtkExampleClass")) { ... }</span>

2.3 Object State Display对象状态显示

When debugging(调试中很有用,可以了解到对象当前的描述) it is often useful to display a human-readable description of the current state of an object. This can be obtained for VTK objects using the Print() method:
<span style="font-size:18px;">obj->Print(cout);</span>

3.The Rendering Engine渲染引擎

The VTK rendering engine consists of the classes in VTK that are responsible for taking the results of the visualization pipeline and displaying them into a window(渲染引擎的工作在于获得可视化管道的结果,然后将他们显示在窗口上). This involves the following components. Note that this is not an exhaustive list(此处没有给出详细的清单), but rather a sense of the most commonly used objects in the rendering engine. The subheadings used here are the highest level superclass in VTK that represents this type of object, and in many cases where there are multiple choices these are abstract classes defining the basic API across the various concrete subclasses that implement the functionality.

3.1 vtkProp(道具?)

Visible depictions of data that exist in the scene are represented by a subclass of vtkProp(vtkProp子类用来呈现数据的可视化).The most commonly used subclasses of vtkProp for displaying objects in 3D are vtkActor (used to
represent geometric data in the scene) and vtkVolume (used to represent volumetric data in the scene).There are also props that represent data in 2D such as vtkActor2D. The vtkProp subclass is generally responsible for knowing its position, size, and orientation in the scene(vtkProp子类通常负责知晓视图的位置、尺寸和方向). The parameters used to control the placement of the prop generally depend on whether the prop is for example a 3D object in the scene, or a 2D annotation. For 3D props such as vtkActor and vtkVolume , you can either directly control parameters such as  the object's 3D position, orientation and scale, or you can use a 4x4 transformation matrix(利用一个4*4的矩阵直接控制3D立体的位置、方向和尺寸). For 2D  props that provide annotation such as the vtkScalarBarActor, the size and position of the annotation  can be defined in a variety of ways including specifying a position, width, and height relative to the  size of the entire viewport. In addition to providing placement control, props generally have a mapper  object that holds the data and knows how to render it, and a property object that controls parameters  such as color and opacity.(除了提供位置上的控制,Prop通常也会提供一个映射器对象,这个映射其对象持有数据并且知道如何渲染这些数据;此外还控制一个属性对象,控制颜色和透明度参数)

There are a large number (over 50) of specialized props(专用道具) such as vtkImageActor (used to display
an image) and vtkPieChartActor (used to create a pie chart visual representation of an array of datavalues). Some of these specialized props directly contain the parameters that control appearance, and directly have a reference to the input data to be rendered, and therefore do not require the use of a property or a mapper. The vtkFollower prop is a specialized subclass of vtkActor that will automatically update its orientation in order to continually face a specified camera. This is useful for displaying billboards or text in the 3D scene and having them remain visible as the user rotates. The vtkLODActor is also a subclass of vtkActor that automatically changes its geometric representation in order to maintain interactive frame rates, and vtkLODProp3D is a subclass of vtkProp3D that
selects between a number of different mappers (perhaps even a mixture of volumetric and geometric
mappers) in order to provide interactivity. vtkAssembly allows hierarchies of actors, properly managing the transformations when the hierarchy is translated, rotated or scaled.

3.1 vtkAbstractMapper 抽象映射器

Some props such as vtkActor and vtkVolume use a subclass of vtkAbstractMapper to hold a reference to the input data(保持对输入数据的引用) and to provide the actual rendering functionality(提供实际的渲染功能). The  vtkPolyDataMapper is the primary mapper for rendering polygonal geometry.(对于渲染多边形几何 vtkPolyDataMapper是最主要的映射器) For volumetric objects(对于容积对象), VTK provides several rendering techniques including the vtkFixedPointVolumeRayCastMapper that can be used to rendering vtkImageData, and the vtkProjectedTetrahedra mapper that can be used to
render vtkUnstructuredGrid data.

3.2 vtkProperty and vtkVolumeProperty 属性和体积属性

Some props use a separate property object to hold the various parameters that control the appearance of the data.(属性对象用来控制数据的外观) This allows you to more easily share appearance settings between different objects in your scene. The vtkActor object uses a vtkProperty to store parameters such as color, opacity, and the ambient, diffuse, and specular coefficient of the material.(颜色、透明度、阴影、镜面反射系数)The vtkVolume object instead uses a vtkVolumeProperty to capture the parameters that are applicable to a volumetric object, such as the transfer functions that map the scalar value to color and opacity. Many mappers also provide functionality to set clipping planes that can be used to reveal interior structure.

3.3 vtkCamera 摄像机

The vtkCamera contains the parameters that control how you view the scene.(如何去看一个场景) The vtkCamera has a position, a focal point, and a vector defining the direction of "up" in the scene(位置信息、焦点信息、定义“向上”). Other parameters control the specific viewing transformation (parallel or perspective), the scale or view angle of the image, and the near and far clipping planes of the view frustum.(平行/透视、尺寸、角度、视锥体的远近裁剪平面).

3.4 vtkLight 灯光

When lighting is computed for a scene, one or more vtkLight objects are required. The vtkLight objects store the position and orientation of the light, as well as the color and intensity.(该对象储存着灯光的位置的方向信息,以及灯光的颜色和强度信息) Lights also have a type that describes how the light will move with respect to the camera.(灯光还有一个参数信息,那就是定义灯光如何相对于摄像机移动) For example, a Headlight is always located at the camera's position and shines on the camera's focal point, whereas a SceneLight is located at a stationary position in the scene.

3.5 vtkRenderer 渲染器

The objects that make up a scene including the props, the camera and the lights are collected together in a vtkRenderer. (渲染器对象用于将道具、摄像机、灯光收集到一起组成一个场景)The vtkRenderer is responsible for managing the rendering process for the scene. Multiple vtkRenderer objects can be used together in a single vtkRenderWindow. (在一个舞台上我们可以构建多个渲染器对象,这就是我们平常说的多视窗技术)These  renderers may render into different rectangular regions (known as viewports) of the render window,or may be overlapping.

3.6 vtkRenderWindow 渲染窗口

The vtkRenderWindow provides a connection between the operating system and the VTK rendering engine(渲染窗口类用于联系当地操作系统和VTK渲染引擎). Platform specific subclasses of vtkRenderWindow are responsible for opening a window in the native windowing system on your computer and managing the display pro-cess(主要负责打开一个本地的窗口,然后管理图像显示过程). When you develop with VTK, you simply use the platform-independent vtkRenderWindow which is automatically replaced with the correct platform-specific subclass at runtime. The vtkRenderWindow contains a collection of vtkRenderers, and parameters that control rendering features such as stereo, anti-aliasing, motion blur and focal depth(渲染窗口类主要负责收集渲染器信息以及控制渲染特征的信息,比如立体?运动模糊?焦点深度?).

3.7 vtkRenderWindowInteractor 渲染窗口交互

The vtkRenderWindowInteractor is responsible for processing mouse, key, and timer events (负责处理鼠标、键盘和定时器事件的消息)and routing these through VTK's implementation of the command /observer design pattern. A vtkInteractorStyle listens for these events and processes them in order to provide motion controls such as rotating, panning and zooming. (可以提供类似平移、旋转、缩放的功能)The vtkRenderWindowInteractor automatically creates a default interactor style that works well for 3D scenes, but you can instead select one for 2D image viewing for example, or create your own custom interactor style.

3.8 vtkLookupTable, vtkColorTransferFunction, and vtkPiecewiseFunction

Visualizing scalar data often involves defining a mapping from a scalar value to a color and opacity(标量数据可视化通常会涉及到定义一个标量值到颜色/透明度的映射). This is true both in geometric surface rendering where the opacity will define the translucency of the surface, and in volume rendering where the opacity will represent the opacity accumulated along some length of of ray passing through the volume. For geometric rendering, this mapping is typically created using a vtkLookupTable, and in volume rendering both the vtkColorTransferFunction and the vtkPiecewiseFunction will be utilized.

4.渲染引擎的测试程序

#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);int main()
{// This creates a polygonal cylinder model with eight circumferential facets.vtkCylinderSource *cylinder = vtkCylinderSource::New();cylinder->SetResolution(8);// The mapper is responsible for pushing the geometry into the graphics// library. It may also do color mapping, if scalars or other attributes// are defined.vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New();cylinderMapper->SetInputConnection(cylinder->GetOutputPort());// The actor is a grouping mechanism: besides the geometry (mapper), it// also has a property, transformation matrix, and/or texture map.// Here we set its color and rotate it -22.5 degrees.vtkActor *cylinderActor = vtkActor::New();cylinderActor->SetMapper(cylinderMapper);cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);cylinderActor->RotateX(30.0);cylinderActor->RotateY(-45.0);// Create the graphics structure. The renderer renders into the// render window. The render window interactor captures mouse events// and will perform appropriate camera or actor manipulation// depending on the nature of the events.vtkRenderer *ren1 = vtkRenderer::New();vtkRenderWindow *renWin = vtkRenderWindow::New();renWin->AddRenderer(ren1);vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();iren->SetRenderWindow(renWin);// Add the actors to the renderer, set the background and sizeren1->AddActor(cylinderActor);ren1->SetBackground(0.1, 0.2, 0.4);renWin->SetSize(200, 200);// We'll zoom in a little by accessing the camera and invoking a "Zoom"// method on it.ren1->ResetCamera();ren1->GetActiveCamera()->Zoom(1.5);renWin->Render();// This starts the event loop and as a side effect causes an initial render.iren->Start();// Exiting from here, we have to delete all the instances that// have been created.cylinder->Delete();cylinderMapper->Delete();cylinderActor->Delete();ren1->Delete();renWin->Delete();iren->Delete();return 0;
}
程序运行结果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/436389.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WINCE6.0 DM.EXE 激活驱动失败的原因之一

前些天把WINCE6.0的开发环境建好了&#xff0c;今天定制了一个系统&#xff0c;练习了一下驱动的编写和调试。把DLL文件通过VS2005部署到开发板上&#xff0c;用一位大侠写的DM.EXE工具进行激活&#xff0c;但是发现点击激活按钮式无反应&#xff0c;驱动还是停在“停用”状态&…

Linux:tomcat安装/版本升级

本文适用于安装或更新tomcat版本。 1.进入tomcat目录&#xff0c;查看当前tomcat版本 cd /usr/local/tomcat/bin ./version.sh 2.备份原tomcat 可以拷贝原tomcat&#xff0c;或者直接修改原tomcat的文件夹名称作为备份。 cd /usr/local/ #方法1&#xff1a;创建目录&…

【转】VTK与Qt整合的示例

VTK与Qt整合的示例 VTK附带的程序示例中大多是基于控制台的&#xff0c;作为可视化开发工具包&#xff0c;VTK也可以与很多流行的GUI开发工具整合&#xff0c;比如MFC、Qt(题外话&#xff1a;Qt已经被Digia从诺基亚手中收购了&#xff0c;Qt现在的链接是&#xff1a;http://qt…

WinCE驱动调试助手V2.5

http://www.cnblogs.com/we-hjb/archive/2008/12/15/1280822.html http://blog.chinaunix.net/u1/49088/showart.php?id1279989 工欲善其事&#xff0c;必先利其器。做WinCE驱动的开发已有一段时间了&#xff0c;WinCE驱动调试助手也跟着更新了很多功能。现在只要做驱动&#…

Web应用系统中数据传递的方式汇总

本文转载自sina_blog(siangzhang) 目录 1 Socket方式 2 ftp/文件共享服务器方式 3 数据库共享数据方式 4 message方式 5 案例 随着近年来SOA&#xff08;面向服务技术架构&#xff09;的兴起&#xff0c;越来越多的应用系统开始进行分布式的设计和部署。 系统由原来单一…

【转】CT (电子计算机断层扫描)

CT(Computed Tomography)&#xff0c;即电子计算机断层扫描&#xff0c;它是利用精确准直的X线束、γ射线、超声波等&#xff0c;与灵敏度极高的探测器一同围绕人体的某一部位作一个接一个的断面扫描&#xff0c;具有扫描速度快&#xff0c;图像清晰等特点&#xff0c;可用于多…

Linux:chmod命令-修改文件或目录的权限

给新安装的tomcat/bin目录下的所有文件增加执行权限&#xff08;所有用户、组&#xff09; chmod -R ax /usr/local/tomcat/bin ------------------------------------------------------------------------------------------------------------------- 关于具体的chmod命令…

【转】详解冠状面_水平面_矢状面_窗宽_窗位

在接触人工智能医疗方面时&#xff0c;单是学习算法和代码原理还不够&#xff0c;需要一定的医学影像知识储备。 B超、CT、MR等都算是医疗影像&#xff0c;在现实生活中&#xff0c;从医院检查身体后拿到的胶片是处理过后的二维图像。这些医疗影像其实是三维的。 最常见的图片格…

js+ asp.Net ajax开发163邮箱效果(列表底色、多选拖动等)--checkBox多选

163邮件一个比较爽的功能就是可以通过多选邮件&#xff0c;拖动到左侧的文件夹列表&#xff0c;实现邮件归类的功能关于我对拖动分配的实现将在后文写出这里说说在CheckBox的选择中做得尝试和实现的效果、方法1。点击表格Title实现全选每行这个早有人做了,我这里借鉴一下 一块贴…

【转】医学图像中的窗宽、窗位!!

在CT等医学影像显示领域&#xff0c;我们经常会听到窗宽&#xff08;Window Width,简写WW&#xff09;、窗位&#xff08;Window Level,简写WL&#xff09;的概念&#xff0c;那么到底什么是窗宽、窗位&#xff0c;它们跟医学图像之间的关系又是什么&#xff1f; 先说一下CT值…

【Excel】使用VLOOKUP+IF实现多列条件匹配查询

excel中vlookup函数为精准匹配查找&#xff0c;但此函数局限于单列的精准匹配&#xff0c;如果需求是多列条件进行匹配&#xff0c;怎么通过vlookup函数实现呢&#xff1f; 思路&#xff1a;通过if函数将多列拼成一列再通过vlookup函数进行精准匹配 具体公式为VLOOKUP($F2&…

【转】解密Qt安装目录的结构

转自&#xff1a;C语言中文网 强力推荐 网址&#xff1a;http://c.biancheng.net/view/3866.html 了解 Qt 安装目录的结构虽然不是编程必须的&#xff0c;但是它能练就我们的内功&#xff0c;让我们对 Qt 的编程环境了如指掌。Windows 和 Linux 下 Qt 安装目录的结构非常相似…

发一个自己写的2440驱动1602的资料(电路+代码)

上个星期把MINI2440板上的富余数据线引了出来&#xff0c;看着以前丢下的1602突然有了想用ARM9驱动它的冲动&#xff0c;于是就开始干了。 代码是从以前刚学C51的时候改的&#xff0c;呵呵&#xff0c;看见以前写的代码真觉得很烂&#xff0c;现在已经整理好了。 虽说有点牛刀…

【转】10.Qt编程涉及的术语和名词

本节我们来介绍一下使用 Qt 编程过程中常用的术语和名字&#xff0c;它们不一定专属于 Qt&#xff0c;在其它的 C/C 开发过程中也会使用到。 Project Project 的中文翻译是“项目”或者“工程”&#xff0c;这里的项目是指为实现某个相对独立功能的程序代码合集&#xff0c;这…

【转】17.Qt界面布局管理详解

在上一节&#xff0c;通过一个简单的应用程序&#xff0c;分析了 Qt 创建的 GUI 应用程序中各个文件的作用&#xff0c;剖析了可视化设计的UI文件是如何被转换为 C 的类定义&#xff0c;并自动创建界面的。这些是使用 Qt Creator 可视化设计用户界面&#xff0c;并使各个部分融…

SQL Server 清空或删除所有数据库表中的数据

方法一&#xff1a; --生成数据库脚本的方法最快,处理的也最好 sql2000企业管理器 --右键要清理的数据库 --所有任务 --生成SQL脚本 --<常规>里选择"生成全部对象脚本"","在脚本文件中包含说明性标题&quo…

【转】QT介绍

一、Qt介绍 Qt&#xff0c;坦白来说&#xff0c;并不只是一个界面库&#xff0c;他是C编程思想的集大成者。它是一个经过完善的C应用程序框架。使用Qt&#xff0c;在一定程度上你获得的是一个“一站式”、“全方位”的解决方案&#xff0c;STL、string、XML、数据库、网络这些…

二叉树序列化

文件的大小尽可能的小。 想了四种方法&#xff1a; 第一种方法&#xff1a;把二叉树按前序和中序遍历一遍&#xff0c;存两次二叉树。 第二种方法&#xff1a;将二叉树按左枝为0&#xff0c;右枝为1进行路径编码&#xff0c;那么每个节点都可以表示成&#xff0c;节点信息和路径…

【转】OWIN是什么?

OWIN的英文全称是Open Web Interface for .NET。 如果仅从名称上解析&#xff0c;可以得出这样的信息&#xff1a;OWIN是针对.NET平台的开放Web接口。 那Web接口是谁和谁之间的接口呢&#xff1f;是Web应用程序与Web服务器之间的接口&#xff0c;OWIN就是.NET Web应用程序与W…

java 切换panel会闪烁_【19期】为什么Java线程没有Running状态?

Java虚拟机层面所暴露给我们的状态&#xff0c;与操作系统底层的线程状态是两个不同层面的事。具体而言&#xff0c;这里说的 Java 线程状态均来自于 Thread 类下的 State 这一内部枚举类中所定义的状态&#xff1a;什么是 RUNNABLE&#xff1f;直接看它的 Javadoc 中的说明&am…