VTKFIG  0.25.0
Easy VTK based in situ visualization
vtkfigChartXY.h
Go to the documentation of this file.
1 
7 #ifndef VTKFIG_CHARTXY_H
8 #define VTKFIG_CHARTXY_H
9 
10 #include <vtkDoubleArray.h>
11 #include <vtkChartXY.h>
12 #include <vtkTable.h>
13 #include <vtkPlot.h>
14 #include <vtkPointData.h>
15 #include <vtkContextActor.h>
16 
17 
18 #include "vtkfigFigure.h"
19 
20 namespace vtkfig
21 {
25  class ChartXY: public Figure
26  {
27 
28  public:
29  static std::shared_ptr<ChartXY> New();
30 
31  std::string SubClassName() override final {return std::string("ChartXY");}
32 
33  void Title(const char *title);
34 
35  template <typename T>
36  void LineType(const T *type)
37  { for (int i=0;i<desclen;i++)
38  {
39  next_plot_info.line_type[i]=static_cast<double>(type[i]);
40  if (type[i]=='\0') break;
41  }
42  }
43  void LineColorRGB(double r, double g, double b) { next_plot_info.line_rgb[0]=r; next_plot_info.line_rgb[1]=g; next_plot_info.line_rgb[2]=b;}
44 
45  void LineColorRGB(double rgb[3]) { next_plot_info.line_rgb[0]=rgb[0]; next_plot_info.line_rgb[1]=rgb[1]; next_plot_info.line_rgb[2]=rgb[2];}
46 
47  template<typename V> void AddPlot(const V &x, const V &y);
48 
49  void Clear();
50 
51 
52  protected:
53  ChartXY();
54  ~ChartXY(){};
55 
56  private:
57 
58  int num_plot=0;
59  void ServerMPSend(vtkSmartPointer<internals::Communicator> communicator) override final;
60 
61  void ClientMPReceive(vtkSmartPointer<internals::Communicator> communicator) override final;
62 
63 
64  void AddPlot();
65 
66  virtual void RTBuildAllVTKPipelines(vtkSmartPointer<vtkRenderer> renderer) override final;
67 
68 
69 
70  vtkSmartPointer<vtkChartXY> chartxy;
71  vtkSmartPointer<vtkContextActor> ctxactor;
72  static const int desclen=4;
73  std::string title="test";
74 
75 
76  struct plot_info
77  {
78  double line_type[desclen]={'-',0,0,0};
79  double line_rgb[3]={0,0,0};
80  plot_info(){};
81  ~plot_info(){};
82  };
83 
84  plot_info next_plot_info;
85  std::vector<plot_info> all_plot_info;
86 
87  double all_plot_range[4]={1.0e100,-1.0e100,1.0e100,-1.0e100};
88 
89  };
90 
91 
92  template<typename V>
93  inline
94  void ChartXY::AddPlot(const V &x, const V &y)
95  {
96 
97  int N=x.size();
98 
99  vtkSmartPointer<vtkDoubleArray> X;
100  vtkSmartPointer<vtkDoubleArray> Y;
101  vtkSmartPointer<vtkTable> table;
102 
103  auto line=chartxy->GetPlot(num_plot);
104  if (!line)
105  {
106  X=vtkSmartPointer<vtkDoubleArray>::New();
107  Y=vtkSmartPointer<vtkDoubleArray>::New();
108  X->SetName("X");
109  Y->SetName("Y");
110  table=vtkSmartPointer<vtkTable>::New();
111  table->AddColumn(X);
112  table->AddColumn(Y);
113 
114  line=chartxy->AddPlot(vtkChartXY::LINE);
115  line->SetInputData(table, 0, 1);
116  }
117  else
118  table=line->GetInput();
119 
120  table->SetNumberOfRows(N);
121 
122  assert(x.size()==y.size());
123  double xmin=1.0e100,xmax=-1.0e100;
124  double ymin=1.0e100,ymax=-1.0e100;
125 
126  for (int i=0; i<N; i++)
127  {
128  table->SetValue(i,0,x[i]);
129  table->SetValue(i,1,y[i]);
130  xmin=std::min(xmin,x[i]);
131  ymin=std::min(ymin,y[i]);
132  xmax=std::max(xmax,x[i]);
133  ymax=std::max(ymax,y[i]);
134  }
135 
136  all_plot_range[0]=std::min(xmin,all_plot_range[0]);
137  all_plot_range[1]=std::max(xmax,all_plot_range[1]);
138  all_plot_range[2]=std::min(ymin,all_plot_range[2]);
139  all_plot_range[3]=std::max(ymax,all_plot_range[3]);
140 
141  line->Modified();
142  table->Modified();
143  AddPlot();
144  }
145 
146 
147 }
148 
149 #endif
vtkfigFigure.h
vtkfig::Figure::xmin
double xmin
View volume data.
Definition: vtkfigFigure.h:475
vtkfig::ChartXY::SubClassName
std::string SubClassName() override final
Get subclass name (for s-c communication, should be replaced by tag.
Definition: vtkfigChartXY.h:31
vtkfig::Figure
Base class for all figures.
Definition: vtkfigFigure.h:61
vtkfig::ChartXY
Experimental class trying to use the chartxy widget - don't use!
Definition: vtkfigChartXY.h:25