参考文章​​【vtk】some-press-key-operations-for-default-renderwindowiterator​​ ,我们可以通过按下w切换到wireframe mode,按下s键切换到surfaces mode.



但是这并不是我们要求的bounding box,要画出bounding box,可以这样:

#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkLight.h>
#include <vtkCamera.h>
#include <vtkActor2D.h>
#include <vtkOutlineFilter.h>
#include <vtkPolyDataNormals.h>

using namespace std;

int main()
{
vtkSmartPointer<vtkConeSource> cone =
vtkSmartPointer<vtkConeSource>::New();

vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection( cone->GetOutputPort() );

vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper( mapper );

// --------------------- start to draw bounding box ------------------------
vtkSmartPointer<vtkPolyDataNormals> normals =
vtkSmartPointer<vtkPolyDataNormals>::New();
normals->SetInputConnection( cone->GetOutputPort() );

vtkSmartPointer<vtkOutlineFilter> outlineFilter =
vtkSmartPointer<vtkOutlineFilter>::New();
outlineFilter->SetInputConnection( normals->GetOutputPort() );

vtkSmartPointer<vtkPolyDataMapper> outLinemapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
outLinemapper->SetInputConnection( outlineFilter->GetOutputPort() );

vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper( outLinemapper );
outlineActor->GetProperty()->SetColor( 1,1,1 );
// --------------------- Drawing bounding box end------------------------

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor( actor );
renderer->AddActor( outlineActor );
renderer->SetBackground( 0, 0, 0 );

vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer( renderer );

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow( renderWindow );

renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}



获取bounds的(x, y, z)数据:

double *vtkActor::GetBounds();