admin管理员组

文章数量:1642458

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

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

本文标签: 之道体系结构VTK