当前位置:首页 > 服务端 > vtk旋转扫描实体示例:vtkQuadRotationalExtrusionFilter、vtkRotationalExtrusionFilter

vtk旋转扫描实体示例:vtkQuadRotationalExtrusionFilter、vtkRotationalExtrusionFilter

 

一、vtkQuadRotationalExtrusionFilter 

Detailed Description

sweep polygonal data creating "skirt" from free edges and lines, and lines from vertices

vtkQuadRotationalExtrusionFilter is a modeling filter. It takes polygonal data as input and generates polygonal data on output. The input dataset is swept around the z-axis to create new polygonal primitives. These primitives form a "skirt" or swept surface. For example, sweeping a line results in a cylindrical shell, and sweeping a circle creates a torus.

There are a number of control parameters for this filter. You can control whether the sweep of a 2D object (i.e., polygon or triangle strip) is capped with the generating geometry via the "Capping" instance variable. Also, you can control the angle of rotation, and whether translation along the z-axis is performed along with the rotation. (Translation is useful for creating "springs".) You also can adjust the radius of the generating geometry using the "DeltaRotation" instance variable.

The skirt is generated by locating certain topological features. Free edges (edges of polygons or triangle strips only used by one polygon or triangle strips) generate surfaces. This is true also of lines or polylines. Vertices generate lines.

This filter can be used to model axisymmetric objects like cylinders, bottles, and wine glasses; or translational/rotational symmetric objects like springs or corkscrews.

Warning:
If the object sweeps 360 degrees, radius does not vary, and the object does not translate, capping is not performed. This is because the cap is unnecessary.
Some polygonal objects have no free edges (e.g., sphere). When swept, this will result in two separate surfaces if capping is on, or no surface if capping is off.
See also:
vtkLinearExtrusionFilter  vtkRotationalExtrusionFilter
Thanks:
This class was initially developed by Daniel Aguilera, CEA/DIF Ported and modified by Philippe Pebay, Kitware, 2011
Tests:
vtkQuadRotationalExtrusionFilter (Tests)

Definition at line 74 of file vtkQuadRotationalExtrusionFilter.h.

示例代码:

#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
#include <iostream>

using namespace std;
#include "vtkCamera.h"
#include "vtkInformation.h"
#include "vtkLineSource.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkQuadRotationalExtrusionFilter.h"
#include "vtkTestUtilities.h"
int main()
{
    // Create a line source
    vtkNew<vtkLineSource> line;
    line->SetPoint1( 0., 1., 0. );
    line->SetPoint2( 0., 1., 2. );
    line->SetResolution( 10 );
    line->Update();

    // Create mapper for line segment
    vtkNew<vtkPolyDataMapper> lineMapper;
    lineMapper->SetInputConnection( line->GetOutputPort() );

    // Create actor for line segment
    vtkNew<vtkActor> lineActor;
    lineActor->SetMapper( lineMapper.GetPointer() );
    lineActor->GetProperty()->SetLineWidth( 5 );
    lineActor->GetProperty()->SetColor( 0., .749, 1. ); // deep sky blue

    // Create multi-block data set for quad-based sweep
    vtkNew<vtkMultiBlockDataSet> lineMB;
    lineMB->SetNumberOfBlocks( 1 );
    lineMB->GetMetaData( static_cast<unsigned>( 0 ) )->Set( vtkCompositeDataSet::NAME(), "Line" );
    lineMB->SetBlock( 0, line->GetOutput() );

    // Create 3/4 of a cylinder by rotational extrusion
    vtkNew<vtkQuadRotationalExtrusionFilter> lineSweeper;
    lineSweeper->SetResolution( 20 );
    lineSweeper->SetInputData( lineMB.GetPointer() );
    lineSweeper->SetDefaultAngle( 270 );
    lineSweeper->Update();

    // Retrieve polydata output
    vtkMultiBlockDataSet* cylDS = vtkMultiBlockDataSet::SafeDownCast( lineSweeper->GetOutputDataObject( 0 ) );
    vtkPolyData* cyl = vtkPolyData::SafeDownCast( cylDS->GetBlock( 0 ) );

    // Create normals for smooth rendering
    vtkNew<vtkPolyDataNormals> normals;
    normals->SetInputData( cyl );

    // Create mapper for surface representation
    vtkNew<vtkPolyDataMapper> cylMapper;
    cylMapper->SetInputConnection( normals->GetOutputPort() );
    cylMapper->SetResolveCoincidentTopologyToPolygonOffset();

    // Create mapper for wireframe representation
    vtkNew<vtkPolyDataMapper> cylMapperW;
    cylMapperW->SetInputData( cyl );
    cylMapperW->SetResolveCoincidentTopologyToPolygonOffset();

    // Create actor for surface representation
    vtkNew<vtkActor> cylActor;
    cylActor->SetMapper( cylMapper.GetPointer() );
    cylActor->GetProperty()->SetRepresentationToSurface();
    cylActor->GetProperty()->SetInterpolationToGouraud();
    cylActor->GetProperty()->SetColor( 1., 0.3882, .2784 ); // tomato

    // Create actor for wireframe representation
    vtkNew<vtkActor> cylActorW;
    cylActorW->SetMapper( cylMapperW.GetPointer() );
    cylActorW->GetProperty()->SetRepresentationToWireframe();
    cylActorW->GetProperty()->SetColor( 0., 0., 0.);
    cylActorW->GetProperty()->SetAmbient( 1. );
    cylActorW->GetProperty()->SetDiffuse( 0. );
    cylActorW->GetProperty()->SetSpecular( 0. );

    // Create a renderer, add actors to it
    vtkNew<vtkRenderer> ren1;
    ren1->AddActor( lineActor.GetPointer() );
    ren1->AddActor( cylActor.GetPointer() );
    ren1->AddActor( cylActorW.GetPointer() );
    ren1->SetBackground( 1., 1., 1. );

    // Create a renderWindow
    vtkNew<vtkRenderWindow> renWin;
    renWin->AddRenderer( ren1.GetPointer() );
    renWin->SetSize( 300, 300 );
    renWin->SetMultiSamples( 0 );

    // Create a good view angle
    vtkNew<vtkCamera> camera;
    camera->SetClippingRange( 0.576398, 28.8199 );
    camera->SetFocalPoint( 0.0463079, -0.0356571, 1.01993 );
    camera->SetPosition( -2.47044, 2.39516, -3.56066 );
    camera->SetViewUp( 0.607296, -0.513537, -0.606195 );
    ren1->SetActiveCamera( camera.GetPointer() );

    // Create interactor
    vtkNew<vtkRenderWindowInteractor> iren;
    iren->SetRenderWindow( renWin.GetPointer() );
    // Render and test
    renWin->Render();
        iren->Start();

    return 0;
}

运行显示结果:

vtk旋转扫描实体示例:vtkQuadRotationalExtrusionFilter、vtkRotationalExtrusionFilter _ JavaClub全栈架构师技术笔记

 

 

2、vtkRotationalExtrusionFilter

Detailed Description

sweep polygonal data creating "skirt" from free edges and lines, and lines from vertices

vtkRotationalExtrusionFilter is a modeling filter. It takes polygonal data as input and generates polygonal data on output. The input dataset is swept around the z-axis to create new polygonal primitives. These primitives form a "skirt" or swept surface. For example, sweeping a line results in a cylindrical shell, and sweeping a circle creates a torus.

There are a number of control parameters for this filter. You can control whether the sweep of a 2D object (i.e., polygon or triangle strip) is capped with the generating geometry via the "Capping" instance variable. Also, you can control the angle of rotation, and whether translation along the z-axis is performed along with the rotation. (Translation is useful for creating "springs".) You also can adjust the radius of the generating geometry using the "DeltaRotation" instance variable.

The skirt is generated by locating certain topological features. Free edges (edges of polygons or triangle strips only used by one polygon or triangle strips) generate surfaces. This is true also of lines or polylines. Vertices generate lines.

This filter can be used to model axisymmetric objects like cylinders, bottles, and wine glasses; or translational/rotational symmetric objects like springs or corkscrews.

Warning:
If the object sweeps 360 degrees, radius does not vary, and the object does not translate, capping is not performed. This is because the cap is unnecessary.
Some polygonal objects have no free edges (e.g., sphere). When swept, this will result in two separate surfaces if capping is on, or no surface if capping is off.
See also:
vtkLinearExtrusionFilter
Examples:
vtkRotationalExtrusionFilter (Examples)
Tests:
vtkRotationalExtrusionFilter (Tests)

示例代码:

#include <iostream>
#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
#endif
using namespace std;
// .SECTION Thanks
// This test was written by Philippe Pebay, Kitware SAS 2011

#include "vtkCamera.h"
#include "vtkLineSource.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRotationalExtrusionFilter.h"


int main()
{
    // Create a line source
    vtkNew<vtkLineSource> line;
    line->SetPoint1( 0., 1., 0. );
    line->SetPoint2( 0., 1., 2. );
    line->SetResolution( 10 );
    
    // Create mapper for line segment
    vtkNew<vtkPolyDataMapper> lineMapper;
    lineMapper->SetInputConnection( line->GetOutputPort() );
    
    // Create actor for line segment
    vtkNew<vtkActor> lineActor;
    lineActor->SetMapper( lineMapper.GetPointer() );
    lineActor->GetProperty()->SetLineWidth( 5 );
    lineActor->GetProperty()->SetColor( 0., .749, 1. ); // deep sky blue
    
    // Create 3/4 of a cylinder by rotational extrusion
    vtkNew<vtkRotationalExtrusionFilter> lineSweeper;
    lineSweeper->SetResolution( 20 );
    lineSweeper->SetInputConnection( line->GetOutputPort() );
    lineSweeper->SetAngle( 270 );
    
    // Create normals for smooth rendering
    vtkNew<vtkPolyDataNormals> normals;
    normals->SetInputConnection( lineSweeper->GetOutputPort() );
    
    // Create mapper for surface representation
    vtkNew<vtkPolyDataMapper> cylMapper;
    cylMapper->SetInputConnection( normals->GetOutputPort() );
    cylMapper->SetResolveCoincidentTopologyToPolygonOffset();
    
    // Create mapper for wireframe representation
    vtkNew<vtkPolyDataMapper> cylMapperW;
    cylMapperW->SetInputConnection( lineSweeper->GetOutputPort() );
    cylMapperW->SetResolveCoincidentTopologyToPolygonOffset();
    // Create actor for surface representation
    vtkNew<vtkActor> cylActor;
    cylActor->SetMapper( cylMapper.GetPointer() );
    cylActor->GetProperty()->SetRepresentationToSurface();
    cylActor->GetProperty()->SetInterpolationToGouraud();
    cylActor->GetProperty()->SetColor( 1., .3882, .2784 ); // tomato
    // Create actor for wireframe representation
    vtkNew<vtkActor> cylActorW;
    cylActorW->SetMapper( cylMapperW.GetPointer() );
    cylActorW->GetProperty()->SetRepresentationToWireframe();
    cylActorW->GetProperty()->SetColor( 0., 0., 0.);
    cylActorW->GetProperty()->SetAmbient( 1. );
    cylActorW->GetProperty()->SetDiffuse( 0. );
    cylActorW->GetProperty()->SetSpecular( 0. );
    // Create a renderer, add actors to it
    vtkNew<vtkRenderer> ren1;
    ren1->AddActor( lineActor.GetPointer() );
    ren1->AddActor( cylActor.GetPointer() );
    ren1->AddActor( cylActorW.GetPointer() );
    ren1->SetBackground( 1., 1., 1. );
    
    // Create a renderWindow
    vtkNew<vtkRenderWindow> renWin;
    renWin->AddRenderer( ren1.GetPointer() );
    renWin->SetSize( 300, 300 );
    renWin->SetMultiSamples( 0 );
    // Create a good view angle
    vtkNew<vtkCamera> camera;
    camera->SetClippingRange( 0.576398, 28.8199 );
    camera->SetFocalPoint( 0.0463079, -0.0356571, 1.01993 );
    camera->SetPosition( -2.47044, 2.39516, -3.56066 );
    camera->SetViewUp( 0.607296, -0.513537, -0.606195 );
    ren1->SetActiveCamera( camera.GetPointer() );
    
    // Create interactor
    vtkNew<vtkRenderWindowInteractor> iren;
    iren->SetRenderWindow( renWin.GetPointer() );
    
    // Render and test
    renWin->Render();
    iren->Start();
    
    return 0;
}

代码运行结果:

vtk旋转扫描实体示例:vtkQuadRotationalExtrusionFilter、vtkRotationalExtrusionFilter _ JavaClub全栈架构师技术笔记

 

 

 

 

 

 

 

作者:凤凰_1
来源链接:https://www.cnblogs.com/phoenixdsg/p/7511099.html

版权声明:
1、Java侠(https://www.javaxia.com)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaxia.com/server/124920.html

标签: Unnecessary
分享给朋友:

“vtk旋转扫描实体示例:vtkQuadRotationalExtrusionFilter、vtkRotationalExtrusionFilter” 的相关文章