I’m referring to an example of a line plot, and if the button is pressed with MFC, it’s printed on picture control.
It works normally when the button is pressed for the first time, but if you plot it again, an error will appear. How should I handle this?
my code is here:
vtkNew table;
vtkNew<vtkFloatArray> arrX;
arrX->SetName("X Axis");
table->AddColumn(arrX);
vtkNew<vtkFloatArray> arrC;
arrC->SetName("Line Profile");
table->AddColumn(arrC);
// Fill in the table with some example values
int numPoints = 550;
float inc = 1;//7.5 / (numPoints - 1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
table->SetValue(i, 0, i * inc);
table->SetValue(i, 1, meanMat[i]);//cos(i * inc));
}
// Set up the view
vtkNew<vtkContextView> view;
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
// 추가
view->SetRenderWindow(m_vtkRenderWindow);
// Add multiple line plots, setting the colors etc
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart);
vtkPlot *line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 1);
line->SetColor(255, 0, 0, 255);
line->SetWidth(3.0);
// For dotted line, the line type can be from 2 to 5 for different dash/dot
// patterns (see enum in vtkPen containing DASH_LINE, value 2):
#ifndef WIN32
line->GetPen()->SetLineType(vtkPen::DASH_LINE);
#endif
// (ifdef-ed out on Windows because DASH_LINE does not work on Windows
// machines with built-in Intel HD graphics card…)
//view->GetRenderWindow()->SetMultiSamples(0);
// Start interactor
view->GetRenderWindow()->Render();
view->GetInteractor()->Initialize();