Dear All,<br><br>I'd like to plot a histogram of an image volume, file type metaImage.<br><br>I've managed to plot a histogram using the xyPlotActor, yet I have no way of verifying if it is alright.<br>It also produces a segmentation fault.<br>
<br>I can't get the same histogram plotted using the BarChartActor.<br><br>Could anybody verify my code of both plots? Sorry, I'm a beginner, and at this point I'm stuck.<br><br>Kind regards,<br><br>Michael<br>
<br>#include <vtkImageData.h><br>#include <vtkMetaImageReader.h><br>#include <vtkImageAccumulate.h><br>#include <vtkSmartPointer.h><br>#include <vtkBarChartActor.h><br>#include "vtkRenderer.h"<br>
#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkPolyDataMapper.h"<br>#include "vtkActor.h"<br>#include "vtkContourFilter.h"<br>#include "vtkImageAccumulate.h"<br>
#include "vtkXYPlotActor.h"<br>#include "vtkImageThreshold.h"<br><br>int main(int argc, char *argv[])<br>{<br>// handle the arguments<br>if(argc != 2)<br> {<br> vtkstd::cout << "Required arguments: filename.mhd" << vtkstd::endl;<br>
}<br> <br>// open a metaimage<br>vtkMetaImageReader * metaImageReader = vtkMetaImageReader::New();<br>metaImageReader->SetFileName(argv[1]);<br><br>//metaImageReader->Update();<br>vtkSmartPointer<vtkImageAccumulate> histogram = vtkSmartPointer<vtkImageAccumulate>::New();<br>
<br>histogram->SetInput(metaImageReader->GetOutput());<br>// sets number of bins: 10 = N# bins<br> histogram->SetComponentExtent(0, 4000, 0, 0, 0, 0);<br> histogram->SetComponentOrigin(0, 0, 0);<br> histogram->SetComponentSpacing(0.16, 0.16, 3.26); // component spacing: depends on spacing of input volume<br>
histogram->UpdateWholeExtent();<br><br> vtkXYPlotActor* plot = vtkXYPlotActor::New();<br> plot->ExchangeAxesOff();<br> plot->SetLabelFormat("%g");<br><br> // plot->SetXRange(0, 320);<br>
// plot->SetYRange(0, 10000);<br> plot->SetXTitle("Iso Surface Level");<br> plot->SetYTitle("Frequency");<br> plot->AddInput(histogram->GetOutput());<br> plot->SetXValuesToValue();<br>
<br> vtkBarChartActor* plot2 = vtkBarChartActor::New();<br> plot2->SetInput(histogram->GetOutput());<br><br> vtkRenderer *aRenderer = vtkRenderer::New();<br> vtkRenderWindow *renWin = vtkRenderWindow::New();<br>
renWin->AddRenderer(aRenderer);<br> vtkRenderWindowInteractor *iren =<br> vtkRenderWindowInteractor::New();<br> iren->SetRenderWindow(renWin);<br><br> aRenderer->AddActor(plot);<br> <br> renWin->SetSize(640, 480);<br>
<br> // Initialize the event loop and then start it.<br> iren->Initialize();<br> iren->Start(); <br><br> vtkRenderer *aRenderer2 = vtkRenderer::New();<br> vtkRenderWindow *renWin2 = vtkRenderWindow::New();<br>
renWin2->AddRenderer(aRenderer2);<br> vtkRenderWindowInteractor *iren2 =<br> vtkRenderWindowInteractor::New();<br> iren2->SetRenderWindow(renWin2);<br><br> aRenderer2->AddActor(plot2);<br> <br> renWin2->SetSize(640, 480);<br>
<br> // Initialize the event loop and then start it.<br> iren2->Initialize();<br> iren2->Start(); <br><br> histogram->Delete();<br> plot->Delete();<br> plot2->Delete();<br> iren->Delete();<br> renWin->Delete();<br>
aRenderer->Delete();<br><br>return (0);<br>}<br><br><br><br><br>