作为一款开源跨平台的数据可视化代码库,VTK以其清晰的流水线工作方式、丰富的后处理算法、异种渲染/交互方式,而被众多CAx软件选作后处理实施方案。而异种渲染/交互方式的实现,主要是倚重于VTK的类型系统,因此,有必要对这个问题予以研究分析。
另外,结合前面对FreeCAD类型系统的分析,本文旨在导出类型系统在设计与实现等方面的(非)技术约束。
本文涉及的主要知识点包括,
- Factory Method Pattern
- Type Registration
注1:限于研究水平,分析难免不当,欢迎批评指正。
注2:文章内容会不定期更新。
一、相关组件
1.1 vtkObjectBase
vtkObjectBase定义了类型信息、引用计数等相关接口,而类型信息主要是基于其内部维护的类型名称字符串。
1.2 vtkObject
vtkObject派生于vtkObjectBase,增加了对象动态创建接口。
// Macro to use when you are a direct child class of vtkObjectBase, instead
// of vtkTypeMacro. This is required to properly specify NewInstanceInternal
// as a virtual method.
// It is used to determine whether a class is the same class or a subclass
// of the named class.
#define vtkBaseTypeMacro(thisClass, superclass) \
vtkAbstractTypeMacro(thisClass, superclass); \
\
protected: \
virtual vtkObjectBase* NewInstanceInternal() const { return thisClass::New(); } \
\
public:
// Same as vtkTypeMacro, but adapted for cases where thisClass is abstract.
#define vtkAbstractTypeMacro(thisClass, superclass) \
vtkAbstractTypeMacroWithNewInstanceType(thisClass, superclass, thisClass, #thisClass); \
\
public:
// Allows definiti