VTK绘制Bounding Box

Posted theArcticOcean

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VTK绘制Bounding Box相关的知识,希望对你有一定的参考价值。

参考文章【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();

以上是关于VTK绘制Bounding Box的主要内容,如果未能解决你的问题,请参考以下文章

Bounding-box 回归

yolo 算法 网格的两个bounding box大小是怎么确定的

python plot_bounding_box.py

Bounding-Box(BB)regression

目标检测中bounding box regression

Bounding Box回归