VTK source code reading--time stamp-vtkTimeStamp class

foreword        

        In the VTK framework, most classes are derived from vtkObject. vtkObject implements the observer/command (Observer/Command) design pattern and maintains a modification time internally to control the execution of the visualization pipeline. The visualization pipeline is an important concept in VTK, and the connection of the pipeline should be connected using the SetInputConnection()/GetOutputPort() interface. VTK adopts the "lazy evaluation" (Lazy Evaluation) scheme to control the execution of the pipeline. Only when the "request data" is issued, the pipeline will be executed.

        Specifically, lazy assignment refers to deciding when to execute the pipeline based on the internal modification time of each object. Only when you or the program sends a "request data" will the pipeline be executed (the vtkObject mentioned earlier has an important vtkTimeStamp The member variable MTime of the type , each object in the pipeline derived from vtkObject will track its own internal modification time ( Modified() ), when encountering "request data", the object will compare the modification time, if found The modification time is changed and the object executes.). In other words, VTK uses a command-driven (Demand Driven) method to control the execution of the pipeline. The advantage of this method is that when a change is made to a data object, it does not need to be calculated immediately, and only when a request is issued, it starts processing. It minimizes the time required for calculations for smoother interaction with data.

        Usually, we don't need to explicitly call the Update() function, because at the end of the rendering engine, when we call the Render() function, the Actor will receive a rendering request, and then the Actor will request the Mapper to send data to it, and The Mapper will request the data of the Filter on the upper layer, and the Filter finally requests the Source to give it data, so the entire pipeline is executed. Unless, as listed in the above code segment, you want to output some information after reading the data, you should explicitly call the Update() function before getting the information.

vtkTimeStamp

        The vtkTimeStamp class is an important link in the implementation of "lazy assignment" in the previous article, and it is the timestamp class of VTK;

        The vtkTimeStamp class records the execution (execution) and modification (modification) time of the object;

        The vtkTimeStamp class records the unique time when the method Modified() executes. This time is guaranteed to be monotonically increasing. The vtkObject class and its derived classes use this object to record modification and execution time. The vtkTimeStamp class supports binary < and > comparison operators between two vtkTimeStamp objects .

        The vtkMTimeType type is defined in the vtkType.h file:

typedef vtkTypeUInt64 vtkMTimeType;
#define VTK_MTIME_TYPE_IMPL VTK_TYPE_UINT64
#define VTK_MTIME_MIN VTK_TYPE_UINT64_MIN
#define VTK_MTIME_MAX VTK_TYPE_UINT64_MAX

        The detailed code content is as follows:

class vtkTimeStamp
{
public:
  vtkTimeStamp() { this->ModifiedTime = 0; }
  static vtkTimeStamp* New() { return new vtkTimeStamp; }
  void Delete() { delete this; }
  // 修改对象的修改时间
  void Modified(){
	#if defined(VTK_USE_64BIT_TIMESTAMPS) || VTK_SIZEOF_VOID_P == 8
	static std::atomic<uint64_t> GlobalTimeStamp(0U);
	#else
	static std::atomic<uint32_t> GlobalTimeStamp(0U);
	#endif
	this->ModifiedTime = (vtkMTimeType)++GlobalTimeStamp;
  }
  // 获取对象的修改时间
  // 当前时间只是一个单调递增的无符号长整数
  // 这个数字有可能回绕回零,整数溢出,从最大值溢出成0
  // 这应该只发生在已经运行了很长时间的进程中,同时在程序中不断地改变对象
  // 当这种情况发生时,典型的后果应该是某些过滤器会在真正不需要时进行自我更新
  vtkMTimeType GetMTime() const { return this->ModifiedTime; }

  // 比较两个vtkTimeStamp对象的时间早和晚
  bool operator>(vtkTimeStamp& ts) { return (this->ModifiedTime > ts.ModifiedTime); }
  bool operator<(vtkTimeStamp& ts) { return (this->ModifiedTime < ts.ModifiedTime); }

  // 允许vtkTimeStamp类型转换为vtkMTimeType类型时返回unsigned long
  operator vtkMTimeType() const { return this->ModifiedTime; }

private:
  vtkMTimeType ModifiedTime;
};

Guess you like

Origin blog.csdn.net/liushao1031177/article/details/124516678