6 #ifndef VTKFIG_SURF2D_H
7 #define VTKFIG_SURF2D_H
9 #include <vtkRectilinearGrid.h>
10 #include <vtkStructuredGrid.h>
11 #include <vtkPointData.h>
12 #include <vtkDoubleArray.h>
13 #include <vtkWarpScalar.h>
19 #include "internals/vtkfigCommunicator.h"
29 static std::shared_ptr<Surf2D> New();
31 virtual std::string
SubClassName() override final {
return std::string(
"Surf2D");}
35 void SetGrid(
const V &xcoord,
39 void UpdateValues(
const V &values);
41 void SetRGBTable(
RGBTable & tab,
int tabsize)
43 state.rgbtab_size=tabsize;
44 state.rgbtab_modified=
true;
46 lut=internal::BuildLookupTable(tab,tabsize);
48 void ShowColorbar(
bool b) {show_colorbar=b;}
50 void ServerMPSend(vtkSmartPointer<internals::Communicator> communicator)
override
52 communicator->SendCharBuffer((
char*)&state,
sizeof(state));
53 if (state.rgbtab_modified)
55 communicator->SendRGBTable(rgbtab);
57 communicator->Send(gridfunc,1,1);
58 state.rgbtab_modified=
false;
61 void ClientMPReceive(vtkSmartPointer<internals::Communicator> communicator)
override
63 communicator->ReceiveCharBuffer((
char*)&state,
sizeof(state));
64 if (state.rgbtab_modified)
67 communicator->ReceiveRGBTable(new_rgbtab);
68 SetRGBTable(new_rgbtab,state.rgbtab_size);
70 communicator->Receive(gridfunc,1,1);
71 update_warp_and_lut();
81 void RTBuildVTKPipeline() override final;
84 vtkSmartPointer<vtkStructuredGrid> gridfunc;
85 vtkSmartPointer<vtkPoints> points;
86 vtkSmartPointer<vtkDoubleArray> colors;
87 vtkSmartPointer<vtkWarpScalar> warp;
93 RGBTable rgbtab{{0,0,1},{1,0,0}};
102 bool rgbtab_modified=
false;
105 vtkSmartPointer<vtkLookupTable> lut;
106 bool show_colorbar=
true;
108 void update_warp_and_lut()
110 state.Lz = state.vmax-state.vmin;
111 lut->SetTableRange(state.vmin,state.vmax);
114 double scale = state.Lxy/state.Lz;
116 warp->SetScaleFactor(scale);
124 void Surf2D::SetGrid(
const V &x,
const V &y)
130 if (x[Nx-1]-x[0] > y[Ny-1]-y[0])
131 state.Lxy = x[Nx-1]-x[0];
133 state.Lxy = y[Ny-1]-y[0];
138 gridfunc->SetDimensions(Nx, Ny, 1);
140 points = vtkSmartPointer<vtkPoints>::New();
141 for (j = 0; j < Ny; j++)
143 for (i = 0; i < Nx; i++)
145 points->InsertNextPoint(x[i], y[j], 0);
148 gridfunc->SetPoints(points);
150 colors = vtkSmartPointer<vtkDoubleArray>::New();
151 colors->SetNumberOfComponents(1);
152 colors->SetNumberOfTuples(Nx*Ny);
154 for (j = 0; j < Ny; j++)
155 for (i = 0; i < Nx; i++)
157 colors->InsertComponent(k, 0, 0);
161 gridfunc->GetPointData()->SetScalars(colors);
167 void Surf2D::UpdateValues(
const V &z)
169 for (
int j = 0; j < Ny; j++)
171 for (
int i = 0; i < Nx; i++)
175 state.vmin=std::min(v,state.vmin);
176 state.vmax=std::max(v,state.vmax);
178 points->GetPoint(k,p);
180 points->SetPoint(k,p);
181 colors->InsertComponent(k, 0,v);
187 gridfunc->Modified();
189 update_warp_and_lut();