Print debug info by vtk macro

How to show vtk object’s debug information?
I introduce how to show vtk object’s debug information by the custom class which inherits vtkPolyDataAlgorithm, relevant article: 【VTK】Create source class which is derived from vtkPolyDataAlgorithm
We just need to Star->DebugOn() and use vtkDebugMacro as std::cout.

        vtkDebugMacro( << "works, output getNumberOfCells "
                       << output->GetNumberOfCells() );

Run it, program outputs all debug info

Debug: In /Users/weiyang/code/diff/main.cpp, line 79
StarSource (0x7fb0c8c0bb60): works, output getNumberOfCells 5

The different debug macros such as vtkWarningMacro, vtkDebugMacro and vtkErrorMacro and their definitions are in vtkSetGet.h

PrintSelf in vtkObjectBase

The interface vtkObjectBase::Print contains PrintSelf, that means print does more than vtkObjectBase::PrintSelf

void vtkObjectBase::Print(ostream& os)
  vtkIndent indent;

  this->PrintSelf(os, indent.GetNextIndent());

We can use it like:

Star->Print( std::cout );

Star->PrintSelf( std::cout, vtkIndent() );


Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page