Commit 9c8e81d5 authored by Cyrille Valladeau's avatar Cyrille Valladeau

ENH : add histo list size control (segfault for image with less than 3 channels)

parent 2cfd35e7
......@@ -121,7 +121,7 @@ StandardImageViewer<TImage,TVectorData,TWidgetManager>
typename VectorDataExtractROIType::Pointer vdextract;
// Colors
typename HistogramCurveType::ColorType red,green,blue;
typename HistogramCurveType::ColorType red,green,blue,gray;
red.Fill(0);
red[0]=1.;
red[3]=0.5;
......@@ -134,6 +134,8 @@ StandardImageViewer<TImage,TVectorData,TWidgetManager>
blue[2]=1.;
blue[3]=0.5;
gray.Fill(0.6);
// If there is a VectorData
if(m_VectorData.IsNotNull())
......@@ -224,26 +226,44 @@ StandardImageViewer<TImage,TVectorData,TWidgetManager>
m_RenderingModel->Update();
// adding histograms rendering
typename HistogramCurveType::Pointer rhistogram = HistogramCurveType::New();
// rhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(m_RenderingFunction->GetPixelRepresentationFunction().GetRedChannelIndex()));
rhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(0));
rhistogram->SetHistogramColor(red);
rhistogram->SetLabelColor(red);
typename HistogramCurveType::Pointer ghistogram = HistogramCurveType::New();
// ghistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(m_RenderingFunction->GetPixelRepresentationFunction().GetGreenChannelIndex()));
ghistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(1));
ghistogram->SetHistogramColor(green);
ghistogram->SetLabelColor(green);
typename HistogramCurveType::Pointer bhistogram = HistogramCurveType::New();
// bhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(m_RenderingFunction->GetPixelRepresentationFunction().GetBlueChannelIndex()));
bhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(2));
bhistogram->SetHistogramColor(blue);
bhistogram->SetLabelColor(blue);
m_CurveWidget->AddCurve(rhistogram);
m_CurveWidget->AddCurve(ghistogram);
m_CurveWidget->AddCurve(bhistogram);
unsigned int listSize = m_ImageLayer->GetHistogramList()->Size();
if(listSize>0)
{
if(listSize==1)
{
typename HistogramCurveType::Pointer grayhistogram = HistogramCurveType::New();
grayhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(0));
grayhistogram->SetHistogramColor(gray);
grayhistogram->SetLabelColor(gray);
m_CurveWidget->AddCurve(grayhistogram);
}
else
{
typename HistogramCurveType::Pointer rhistogram = HistogramCurveType::New();
rhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(0));
rhistogram->SetHistogramColor(red);
rhistogram->SetLabelColor(red);
m_CurveWidget->AddCurve(rhistogram);
}
if(listSize>1)
{
typename HistogramCurveType::Pointer ghistogram = HistogramCurveType::New();
ghistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(1));
ghistogram->SetHistogramColor(green);
ghistogram->SetLabelColor(green);
m_CurveWidget->AddCurve(ghistogram);
}
if(listSize>2)
{
typename HistogramCurveType::Pointer bhistogram = HistogramCurveType::New();
bhistogram->SetHistogram(m_ImageLayer->GetHistogramList()->GetNthElement(2));
bhistogram->SetHistogramColor(blue);
bhistogram->SetLabelColor(blue);
m_CurveWidget->AddCurve(bhistogram);
}
}
m_CurveWidget->SetXAxisLabel("Pixels");
m_CurveWidget->SetYAxisLabel("Frequency");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment