VTKFIG  0.20.20181114
Easy VTK based in situ visualization
vtkfigSurf2D.cxx
Go to the documentation of this file.
1 #include <vtkActor.h>
2 #include <vtkProperty.h>
3 #include <vtkTextProperty.h>
4 #include <vtkOutlineFilter.h>
5 #include <vtkStructuredGridGeometryFilter.h>
6 #include <vtkAxesActor.h>
7 #include <vtkCaptionActor2D.h>
8 
9 #include "vtkfigSurf2D.h"
10 #include "config.h"
11 
12 namespace vtkfig
13 {
16  {
17  RGBTable surface_rgb={{0,0,0,1},{1,1,0,0}};
18  lut=BuildLookupTable(surface_rgb,255);
19  warp = vtkSmartPointer<vtkWarpScalar>::New();
20  gridfunc= vtkSmartPointer<vtkStructuredGrid>::New();
21  }
22 
23 
25  {
26 
27  bool do_warp=true;
28  bool draw_box=true;
29 
30  // filter to geometry primitive
31  vtkSmartPointer<vtkStructuredGridGeometryFilter>geometry =
32  vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
33  geometry->SetInputDataObject(gridfunc);
34 
35  // warp to fit in box
36  if (do_warp)
37  {
38  warp->SetInputConnection(geometry->GetOutputPort());
39  }
40 
41  // map gridfunction
42  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
43  if (do_warp)
44  mapper->SetInputConnection(warp->GetOutputPort());
45  else
46  mapper->SetInputConnection(geometry->GetOutputPort());
47 
48 
49  // create plot surface actor
50  vtkSmartPointer<vtkActor> surfplot = vtkSmartPointer<vtkActor>::New();
51  surfplot->SetMapper(mapper);
52  mapper->SetLookupTable(lut);
53  mapper->UseLookupTableScalarRangeOn();
54 
55 
56  // create outline
57  vtkSmartPointer<vtkOutlineFilter> outlinefilter = vtkSmartPointer<vtkOutlineFilter>::New();
58  if (do_warp)
59  outlinefilter->SetInputConnection(warp->GetOutputPort());
60  else
61  outlinefilter->SetInputConnection(geometry->GetOutputPort());
62 
63  vtkSmartPointer<vtkPolyDataMapper>outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
64  outlineMapper->SetInputConnection(outlinefilter->GetOutputPort());
65  vtkSmartPointer<vtkActor> outline = vtkSmartPointer<vtkActor>::New();
66  outline->SetMapper(outlineMapper);
67  outline->GetProperty()->SetColor(0, 0, 0);
68 
69  // create axes
70  vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
71  axes->SetShaftTypeToCylinder();
72  axes->SetNormalizedShaftLength( 0.85, 0.85, 0.85);
73  axes->SetNormalizedTipLength( 0.15, 0.15, 0.15);
74  axes->SetCylinderRadius( 0.500 * axes->GetCylinderRadius() );
75  axes->SetConeRadius( 1.025 * axes->GetConeRadius() );
76  axes->SetSphereRadius( 1.500 * axes->GetSphereRadius() );
77  vtkSmartPointer<vtkTextProperty> text_prop_ax = axes->GetXAxisCaptionActor2D()->
78  GetCaptionTextProperty();
79  text_prop_ax->SetColor(0.0, 0.0, 0.0);
80  text_prop_ax->SetFontFamilyToArial();
81  text_prop_ax->SetFontSize(8);
82  axes->GetYAxisCaptionActor2D()->SetCaptionTextProperty(text_prop_ax);
83  axes->GetZAxisCaptionActor2D()->SetCaptionTextProperty(text_prop_ax);
84 
85 
86 
87  // renderer
88  Figure::RTAddActor(surfplot);
89  if (draw_box)
90  Figure::RTAddActor(outline);
91 // if (draw_axes) Figure::AddActor(axes);
92  if (show_colorbar)
94 
95  }
96 
97 }
vtkSmartPointer< vtkActor > outline
Definition: vtkfigFigure.h:237
void RTAddActor2D(vtkSmartPointer< vtkActor2D > prop)
Add vtk Actor to renderer showing figure.
void RTBuildVTKPipeline() override final
All functions prefixed with "RT" shall be called only from render thread.
vtkSmartPointer< vtkWarpScalar > warp
Definition: vtkfigSurf2D.h:78
Base class for all figures.
Definition: vtkfigFigure.h:52
vtkSmartPointer< vtkStructuredGrid > gridfunc
Definition: vtkfigSurf2D.h:75
vtkSmartPointer< vtkCubeAxesActor2D > axes
Definition: vtkfigFigure.h:236
vtkSmartPointer< vtkLookupTable > BuildLookupTable(RGBTable &xrgb, size_t size)
vtkSmartPointer< vtkLookupTable > lut
Definition: vtkfigSurf2D.h:96
std::vector< RGBPoint > RGBTable
Definition: vtkfigTools.h:26
void RTAddActor(vtkSmartPointer< vtkActor > prop)
Add vtk Actor to renderer showing figure.
vtkSmartPointer< vtkScalarBarActor > BuildColorBar(vtkSmartPointer< vtkPolyDataMapper > mapper, int irank=0)
Definition: vtkfigTools.cxx:88