8 #include "vtkUnstructuredGrid.h" 9 #include "vtkPointData.h" 10 #include "vtkFloatArray.h" 12 #include "vtkOutlineFilter.h" 14 #include "vtkCubeAxesActor.h" 15 #include "vtkTextProperty.h" 16 #include "vtkPolyLine.h" 17 #include "vtkDataSetMapper.h" 18 #include "vtkAxisActor.h" 19 #include "vtkContextScene.h" 22 #include "vtkPlotGrid.h" 23 #include "vtkDoubleArray.h" 25 #include "vtkPlotLine.h" 30 #include "vtkLegendBoxActor.h" 37 SetZAxisVisibility(0);
38 SetYAxisVisibility(1);
39 SetXAxisVisibility(1);
41 SetDrawXInnerGridlines(1);
43 GetLabelTextProperty(0)->SetFontSize(15);;
44 GetTitleTextProperty(0)->SetFontSize(15);;
45 GetLabelTextProperty(0)->SetColor(0,0,0);
46 GetTitleTextProperty(0)->SetColor(0,0,0);
47 GetLabelTextProperty(1)->SetFontSize(15);;
48 GetTitleTextProperty(1)->SetFontSize(15);;
49 GetLabelTextProperty(1)->SetColor(0,0,0);
50 GetTitleTextProperty(1)->SetColor(0,0,0);
52 GetXAxesLinesProperty()->SetColor(0, 0, 0);
53 GetXAxesLinesProperty()->SetLineWidth(2);
54 GetYAxesLinesProperty()->SetColor(0, 0, 0);
55 GetYAxesLinesProperty()->SetLineWidth(2);
59 GetXAxesGridlinesProperty()->SetLineWidth(0.5);
60 GetXAxesGridlinesProperty()->SetColor(0, 0, 0);
61 GetYAxesGridlinesProperty()->SetColor(0, 0, 0);
62 SetTickLocationToOutside();
78 static std::shared_ptr<myplot0>
New() {
return std::make_shared<myplot0>();}
79 virtual std::string
SubClassName() {
return std::string(
"myplot0");}
83 auto coordsys=vtkSmartPointer<CoordSystemActor>::New();
84 coordsys->SetUse2DMode(1);
85 coordsys->SetBounds(0,1,0.001,100,0,0);
88 coordsys->SetXTitle(
"x");
89 coordsys->SetXUnits(
"cm");
90 coordsys->SetYTitle(
"y");
96 coordsys->SetCamera(renderer->GetActiveCamera());
100 Figure::RTAddActor(coordsys);
104 auto polyLinePoints = vtkSmartPointer<vtkPoints>::New();
105 auto polyLine = vtkSmartPointer<vtkPolyLine>::New();
107 polyLinePoints->SetNumberOfPoints(N);
108 polyLine->GetPointIds()->SetNumberOfIds(N);
113 for (
int i=0;i<N;i++,x+=h)
115 polyLinePoints->InsertPoint(i, x, exp(sin(10.0*x)), 0);
116 polyLine->GetPointIds()->SetId(i,i);
119 auto polyLineGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
120 polyLineGrid->Allocate(1, 1);
121 polyLineGrid->InsertNextCell(polyLine->GetCellType(), polyLine->GetPointIds());
122 polyLineGrid->SetPoints(polyLinePoints);
124 auto polyLineMapper = vtkSmartPointer<vtkDataSetMapper>::New();
125 polyLineMapper->SetInputData(polyLineGrid);
127 auto polyLineActor =vtkSmartPointer<vtkActor>::New();
128 polyLineActor->SetMapper(polyLineMapper);
129 polyLineActor->GetProperty()->SetColor(1,0,0);
130 polyLineActor->GetProperty()->SetLineWidth(2.5);
131 polyLineActor->GetProperty()->BackfaceCullingOn();
133 Figure::RTAddActor(polyLineActor);
135 auto lbox=vtkSmartPointer<vtkLegendBoxActor>::New();
149 static std::shared_ptr<myplot>
New() {
return std::make_shared<myplot>();}
154 auto ctxactor= vtkSmartPointer<vtkContextActor>::New();
155 auto XAxis=vtkSmartPointer<vtkAxis>::New();
157 double P00x=0.1;
double P00y=0.1;
158 double P01x=0.1;
double P01y=0.9;
159 double P10x=0.9;
double P10y=0.1;
160 double P11x=0.9;
double P11y=0.9;
161 renderer->NormalizedDisplayToDisplay(P00x,P00y);
162 renderer->NormalizedDisplayToDisplay(P10x,P10y);
163 renderer->NormalizedDisplayToDisplay(P01x,P01y);
164 renderer->NormalizedDisplayToDisplay(P11x,P11y);
166 XAxis->SetPoint1(P00x,P00y);
167 XAxis->SetPoint2(P10x,P10y);
168 cout << P10x <<
" " << P10y << endl;
169 XAxis->SetPosition(vtkAxis::BOTTOM);
170 XAxis->SetRange(0,10);
171 XAxis->SetAxisVisible(1);
172 XAxis->SetGridVisible(1);
173 XAxis->SetScene(ctxactor->GetScene());
177 auto YAxis=vtkSmartPointer<vtkAxis>::New();
178 YAxis->SetPoint1(P00x,P00y);
179 YAxis->SetPoint2(P01x,P01y);
180 YAxis->SetPosition(vtkAxis::LEFT);
181 YAxis->SetRange(0.01,10);
184 YAxis->SetAxisVisible(1);
185 YAxis->SetGridVisible(1);
186 YAxis->SetScene(ctxactor->GetScene());
191 auto Grid=vtkSmartPointer<vtkPlotGrid>::New();
192 Grid->SetXAxis(XAxis);
193 Grid->SetYAxis(YAxis);
196 cout << ctxactor->GetScene()->GetViewWidth() <<
" "<< ctxactor->GetScene()->GetViewHeight() << endl;
197 cout << ctxactor->GetScene()->GetSceneWidth() <<
" "<< ctxactor->GetScene()->GetSceneHeight() << endl;
201 vtkSmartPointer<vtkDoubleArray> X;
202 vtkSmartPointer<vtkDoubleArray> Y;
203 vtkSmartPointer<vtkTable> table;
204 vtkSmartPointer<vtkPlotLine> line;
206 X=vtkSmartPointer<vtkDoubleArray>::New();
207 Y=vtkSmartPointer<vtkDoubleArray>::New();
210 table=vtkSmartPointer<vtkTable>::New();
215 table->SetNumberOfRows(N);
218 for (
int i=0;i<N;i++,x+=h)
220 table->SetValue(i,0,10*x);
221 table->SetValue(i,1,exp(sin(10.0*x)));
225 line=vtkSmartPointer<vtkPlotLine>::New();
226 line->SetInputData(table, 0, 1);
227 line->SetXAxis(XAxis);
228 line->SetYAxis(YAxis);
229 line->SetPolyLine(
true);
230 line->SetColor(1,0,0);
235 ctxactor->GetScene()->AddItem(Grid);
236 ctxactor->GetScene()->AddItem(XAxis);
237 ctxactor->GetScene()->AddItem(YAxis);
238 ctxactor->GetScene()->AddItem(line);
239 Figure::RTAddContextActor(ctxactor);
256 frame->AddFigure(plot);
265 for (
int i=0; i<Nx; i++)
266 for (
int j=0; j<Ny; j++)
267 z[j*Nx+i] =
G(x[i],y[j],t);
271 for (
int j = 0; j < Ny; j++)
273 for (
int i = 0; i < Nx; i++)
277 vmin=std::min(v,vmin);
278 vmax=std::max(v,vmax);
280 points->GetPoint(k,p);
282 points->SetPoint(k,p);
283 colors->InsertComponent(k, 0,v);
289 gridfunc->Modified();
291 lut->SetTableRange(vmin,vmax);
298 auto t1=std::chrono::system_clock::now();
299 double dt=std::chrono::duration_cast<std::chrono::duration<double>>(t1-t0).count();
303 printf(
"Frame rate: %.2f fps\n",(
double)(i1-i0)/4.0);
304 t0=std::chrono::system_clock::now();
static std::shared_ptr< Frame > New()
Create frame with multiple subframes.
static CoordSystemActor * New()
double G(double x, double y, double t)
void RTBuildAllVTKPipelines(vtkSmartPointer< vtkRenderer > renderer)
Default implementation for 2D/3d datasets.
virtual std::string SubClassName()
Get subclass name (for s-c communication, should be replaced by tag.
static std::shared_ptr< myplot0 > New()
static std::shared_ptr< myplot > New()
void RTBuildAllVTKPipelines(vtkSmartPointer< vtkRenderer > renderer)
Default implementation for 2D/3d datasets.
virtual std::string SubClassName()
Get subclass name (for s-c communication, should be replaced by tag.
Define Frame class providing a window for rendering.