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

本文详细探讨了VTK的体系结构,包括OverView综述,Low-Level Object Model,尤其是引用计数和运行时类型信息。重点介绍了渲染引擎的各个组件,如vtkProp、vtkAbstractMapper、vtkProperty、vtkVolumeProperty、vtkCamera、vtkLight、vtkRenderer、vtkRenderWindow及交互操作,并提到了vtkLookupTable、vtkColorTransferFunction和vtkPiecewiseFunction在渲染过程中的作用。
摘要由CSDN通过智能技术生成

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 thecompiled classes using the languages Java, Tcl, and Python.

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();

从上面我们可以看到,对象的创建以及销毁完全靠手动完成,万一我们不小心,无疑这将会造成内存泄漏。为了避免这是,可以采用 “智能指针”。(智能指针是通过类模板进行定义
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值