7 #ifndef VTKFIG_CHARTXY_H
8 #define VTKFIG_CHARTXY_H
10 #include <vtkDoubleArray.h>
11 #include <vtkChartXY.h>
14 #include <vtkPointData.h>
15 #include <vtkContextActor.h>
29 static std::shared_ptr<ChartXY> New();
31 std::string
SubClassName() override final {
return std::string(
"ChartXY");}
33 void Title(
const char *title);
36 void LineType(
const T *type)
37 {
for (
int i=0;i<desclen;i++)
39 next_plot_info.line_type[i]=static_cast<double>(type[i]);
40 if (type[i]==
'\0')
break;
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;}
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];}
47 template<
typename V>
void AddPlot(
const V &x,
const V &y);
59 void ServerMPSend(vtkSmartPointer<internals::Communicator> communicator)
override final;
61 void ClientMPReceive(vtkSmartPointer<internals::Communicator> communicator)
override final;
66 virtual void RTBuildAllVTKPipelines(vtkSmartPointer<vtkRenderer> renderer)
override final;
70 vtkSmartPointer<vtkChartXY> chartxy;
71 vtkSmartPointer<vtkContextActor> ctxactor;
72 static const int desclen=4;
73 std::string title=
"test";
78 double line_type[desclen]={
'-',0,0,0};
79 double line_rgb[3]={0,0,0};
84 plot_info next_plot_info;
85 std::vector<plot_info> all_plot_info;
87 double all_plot_range[4]={1.0e100,-1.0e100,1.0e100,-1.0e100};
94 void ChartXY::AddPlot(
const V &x,
const V &y)
99 vtkSmartPointer<vtkDoubleArray> X;
100 vtkSmartPointer<vtkDoubleArray> Y;
101 vtkSmartPointer<vtkTable> table;
103 auto line=chartxy->GetPlot(num_plot);
106 X=vtkSmartPointer<vtkDoubleArray>::New();
107 Y=vtkSmartPointer<vtkDoubleArray>::New();
110 table=vtkSmartPointer<vtkTable>::New();
114 line=chartxy->AddPlot(vtkChartXY::LINE);
115 line->SetInputData(table, 0, 1);
118 table=line->GetInput();
120 table->SetNumberOfRows(N);
122 assert(x.size()==y.size());
123 double xmin=1.0e100,xmax=-1.0e100;
124 double ymin=1.0e100,ymax=-1.0e100;
126 for (
int i=0; i<N; i++)
128 table->SetValue(i,0,x[i]);
129 table->SetValue(i,1,y[i]);
131 ymin=std::min(ymin,y[i]);
132 xmax=std::max(xmax,x[i]);
133 ymax=std::max(ymax,y[i]);
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]);