VTK/Examples/Cxx/Visualization/ScalarBarActor

转载 2018年04月14日 22:47:05

VTK/Examples/Cxx/Visualization/ScalarBarActor

VTK‎ | Examples‎ | Cxx
VTK Examples Baseline Visualization TestScalarBarActor.png

This example demonstrates how to make a color bar to that reflects the range of values associated with a data set.

ScalarBarActor.cxx

#include <vtkVersion.h>
#include <vtkActor.h>
#include <vtkFloatArray.h>
#include <vtkLookupTable.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkScalarBarActor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
 
int main (int, char *[])
{
  // Create a sphere for some geometry
  vtkSmartPointer<vtkSphereSource> sphere = 
    vtkSmartPointer<vtkSphereSource>::New();
  sphere->SetCenter(0,0,0);
  sphere->SetRadius(1);
  sphere->Update();
 
  // Create scalar data to associate with the vertices of the sphere
  int numPts = sphere->GetOutput()->GetPoints()->GetNumberOfPoints();
  vtkSmartPointer<vtkFloatArray> scalars =
    vtkSmartPointer<vtkFloatArray>::New();
  scalars->SetNumberOfValues( numPts );
  for( int i = 0; i < numPts; ++i )
    {
    scalars->SetValue(i,static_cast<float>(i)/numPts);
    }
  vtkSmartPointer<vtkPolyData> poly =
    vtkSmartPointer<vtkPolyData>::New();
  poly->DeepCopy(sphere->GetOutput());
  poly->GetPointData()->SetScalars(scalars);
 
  vtkSmartPointer<vtkPolyDataMapper> mapper = 
    vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
  mapper->SetInput(poly);
#else
  mapper->SetInputData(poly);
#endif
  mapper->ScalarVisibilityOn();
  mapper->SetScalarModeToUsePointData();
  mapper->SetColorModeToMapScalars();
 
  vtkSmartPointer<vtkActor> actor = 
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
 
  vtkSmartPointer<vtkScalarBarActor> scalarBar = 
    vtkSmartPointer<vtkScalarBarActor>::New();
  scalarBar->SetLookupTable(mapper->GetLookupTable());
  scalarBar->SetTitle("Title");
  scalarBar->SetNumberOfLabels(4);
 
  // Create a lookup table to share between the mapper and the scalarbar
  vtkSmartPointer<vtkLookupTable> hueLut =
    vtkSmartPointer<vtkLookupTable>::New();
  hueLut->SetTableRange (0, 1);
  hueLut->SetHueRange (0, 1);
  hueLut->SetSaturationRange (1, 1);
  hueLut->SetValueRange (1, 1);
  hueLut->Build();
 
  mapper->SetLookupTable( hueLut );
  scalarBar->SetLookupTable( hueLut );
 
  // Create a renderer and render window
  vtkSmartPointer<vtkRenderer> renderer = 
    vtkSmartPointer<vtkRenderer>::New();
 
  renderer->GradientBackgroundOn();
  renderer->SetBackground(1,1,1);
  renderer->SetBackground2(0,0,0);
 
  vtkSmartPointer<vtkRenderWindow> renderWindow = 
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
 
  // Create an interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
  // Add the actors to the scene
  renderer->AddActor(actor);
  renderer->AddActor2D(scalarBar);
 
  // Render the scene (lights and cameras are created automatically)
  renderWindow->Render();
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;

}

zhuan :https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/ScalarBarActor

VTK/Examples/Cxx/Meshes/ColoredElevationMap

ColoredElevationMap.cxx #include &amp;lt;vtkVersion.h&amp;gt; #include &amp;lt;vtkSmartPointer.h&am...
  • eric_e
  • eric_e
  • 2018-04-02 01:21:08
  • 15

VTK/Examples/Cxx/Filtering/TransformPolyData

VTK/Examples/Cxx/Filtering/TransformPolyData&amp;lt; VTK‎ | Examples‎ | CxxThis example demonstrates...
  • eric_e
  • eric_e
  • 2018-04-20 22:01:12
  • 2

VTK/Examples/Cxx/PolyData/PolyDataPointNormals

This demo adds a normal to each point in a polydata. PolyDataPointNormals.cxx #include #inc...
  • u010025211
  • u010025211
  • 2014-05-15 19:39:50
  • 870

VTK/Examples/Cxx/PolyData/Curvatures

VTK/Examples/Cxx/PolyData/Curvatures&amp;lt; VTK‎ | Examples‎ | CxxContents [hide] 1 Curvatures.cxx2...
  • eric_e
  • eric_e
  • 2018-04-14 22:45:07
  • 1

VTK/Examples/Cxx/PolyData/VertexConnectivity

原文转自: http://www.paraview.org/Wiki/VTK/Examples/Cxx/PolyData/VertexConnectivity
  • u010025211
  • u010025211
  • 2014-05-07 20:42:38
  • 925

在VS2013上运行VTK实例

在相应的VTK环境已经配置好的前提下,以VTK EXAMPLE中turorial里面的step2为例:1. 在step2\Cxx目录下面新建build文件 2.用cmake生成工程先configure...
  • juneheen_csdn
  • juneheen_csdn
  • 2018-02-21 17:11:17
  • 131

The Visualization Toolkit (vtk)

The Visualization Toolkit (vtk)The Visualization toolkit (vtk) is a freely available C++ class libra...
  • majcos
  • majcos
  • 2007-03-09 10:49:00
  • 1869

在原有3306端口mysqld服务的情况再搭建第二个3308端口的mysql实例

1 download the tar.gz [root@472322 tmp]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5....
  • mchdba
  • mchdba
  • 2013-09-12 16:32:33
  • 4330

VTK-7.1.0/Examples/Medical/Medical4例子运行

1.CMake编译 用CMake编译例子程序,打开Medical.sln工程文件,生成Medical4项目,如果未成功,则需要设置项目属性中的附加包含目录、附加库目录以及附加依赖项,并在main函数...
  • cuihaolong
  • cuihaolong
  • 2016-12-27 15:55:00
  • 505

cmake使用实践(一)

cmake使用实践(一) 1.初试cmake,编写简单的helloworld 本节选择了一个最简单的例子Helloworld来演练一下cmake的完整构建过程,本节并不会深入的探讨cmake,...
  • sinat_33508334
  • sinat_33508334
  • 2016-09-26 17:52:17
  • 60
收藏助手
不良信息举报
您举报文章:VTK/Examples/Cxx/Visualization/ScalarBarActor
举报原因:
原因补充:

(最多只允许输入30个字)