+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
/*
This class plots image's histograms in a plotter
*/
//----------------------------------------------------------------------------
IMPLEMENT_CLASS(HistogramWidget, wxWindow)
+
//----------------------------------------------------------------------------
// Event Table
//----------------------------------------------------------------------------
plotter->setType(2);
//setting the popMenu
plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
- histogramSize=0;
- idTransferenceFunction=-1;
- idHistogram=-1;
- transferenceFunctionHasColor=true;
- transferenceFunctionHasPoints=true;
+ histogramSize = 0;
+ idTransferenceFunction = -1;
+ idHistogram = -1;
+ transferenceFunctionHasColor = true;
+ transferenceFunctionHasPoints = true;
this->type=type;
this->SetAutoLayout(true);
//drawing
drawHistogram();
drawTransferenceFunction();
-
}
HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id)
: wxPanel(parent,id){
-
SetBackgroundColour(wxColour(255,255,255));
histogram = NULL;
-
//plotter
plotter=new pPlotter(this, 400,350);
plotter->setType(2);
//setting the popMenu
plotter->setPopUpMenu(true,true,true,true,true,true,false,false,false,false,false,false,false);
- histogramSize=0;
- idTransferenceFunction=-1;
- idHistogram=-1;
- transferenceFunctionHasColor=true;
- transferenceFunctionHasPoints=true;
- this->type=type;;
+ histogramSize = 0;
+ idTransferenceFunction = -1;
+ idHistogram = -1;
+ transferenceFunctionHasColor = true;
+ transferenceFunctionHasPoints = true;
+ this->type = type;;
this->SetAutoLayout(true);
this->Refresh();
-
-
}
void HistogramWidget::initializeHistogram(vtkImageData* img){
- if(histogram ==NULL){
+ if(histogram ==NULL)
+ {
histogram= new pHistogram(img);
}
//draw
xValues=(double*)malloc(NUM_POINTS*sizeof(double));
yValues=(double*)malloc(NUM_POINTS*sizeof(double));
- unsigned short* histogramPointer=(unsigned short*)histogramImageData->GetScalarPointer(0,0,0);
-
- for(int i=0; i< histogramSize; i++)
+ double* histogramPointer=(double*)histogramImageData->GetScalarPointer(0,0,0);
+ int i;
+ for(i=0; i< histogramSize; i++)
{
xValues[i]=i;
- yValues[i]=log( (double) histogramPointer[i]);
- }
+ if (histogramPointer[i]==0)
+ {
+ yValues[i]=0;
+ } else {
+ yValues[i]=log(histogramPointer[i])*10;
+ } // histogramPointer
+ } // for i
pGraphicalFunction* histogramFunction=plotter->getFunctionForVectors(xValues,histogramSize,yValues,histogramSize);
*/
void HistogramWidget::drawTransferenceFunction()
{
-
double xValues[5],yValues[5];
//xValues
int maxValueGrey=histogram->getMaximumLevelOfGrey();
- xValues[0]=0;
- xValues[1]=maxValueGrey/16;
- xValues[2]=maxValueGrey/8;
- xValues[3]=maxValueGrey/16+(maxValueGrey-maxValueGrey/2)/2;
- xValues[4]=maxValueGrey;
+ xValues[0] = 0;
+ xValues[1] = maxValueGrey/16;
+ xValues[2] = maxValueGrey/8;
+ xValues[3] = maxValueGrey/16+(maxValueGrey-maxValueGrey/2)/2;
+ xValues[4] = maxValueGrey;
//yValues
- yValues[0]=0;
- yValues[1]=25;
- yValues[2]=100;
- yValues[3]=25;
- yValues[4]=0;
+ yValues[0] = 0;
+ yValues[1] = 25;
+ yValues[2] = 100;
+ yValues[3] = 25;
+ yValues[4] = 0;
pGraphicalFunction * tf = plotter ->getFunctionForVectors( xValues, 5, yValues, 5 );
- printf("EED %p HistogramWidget::drawTransferenceFunction %p\n", this , tf);
+ printf("EED %p HistogramWidget::drawTransferenceFunction %p\n", this , tf);
// Including and drawing the created function in the plotter
if (tf)
{
tf->SetShowPoints(true);
idTransferenceFunction=plotter->addFunction( tf );
if(type==1)
+ {
plotter->addFunctionToMove(tf);
+ }
wxPen mypen(*wxBLACK,0.5, wxSOLID );
mypen.SetWidth(2);
tf->SetPen( mypen );
- }
+ } // if tf
}
/*
GetClientSize(&scrX,&scrY);
plotter->SetSize(scrX,scrY);
pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction);
- if(actual!=NULL){
+ if(actual!=NULL)
+ {
actual->setScreens(scrX,scrY);
actual->setScales();
}
void HistogramWidget::getTransferenceFunctionPoint(int index,int& x,int& y)
{
pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
- if(tf)
+ if(tf!=NULL)
{
- wxNode* pnode=tf->GetPointAt(index);
- pFunctionPoint* point=(pFunctionPoint*)pnode->GetData();
- x=point->getRealX();
- y=point->getRealY();
+ wxNode* pnode = tf->GetPointAt(index);
+ pFunctionPoint* point = (pFunctionPoint*)pnode->GetData();
+ x = point->getRealX();
+ y = point->getRealY();
}
}
/*
/*
get a color int the bqr color
*/
- void HistogramWidget:: getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
+ void HistogramWidget::getDataBarColorPoint(int index,int&x, int& red,int& green,int& blue)
{
- double tmp=x;
+ double tmp = x;
plotter->getBarColorDataAt(index,tmp,red,green,blue);
- x=(int)tmp;
+ x = (int)tmp;
}
/*
Returns the maximum value ot the histogram that is show to the user
*/
float HistogramWidget::getMaxShowedPorcentage()
{
- float porcentageMaxX=plotter->getMaxShowedPorcentage();
- pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
- int min=histogramFunction->getMinX();
- float x=porcentageMaxX*(histogramFunction->getMaxX()-min);
- return min+ x;
+ float porcentageMaxX = plotter->getMaxShowedPorcentage();
+ pGraphicalFunction* histogramFunction = plotter->getFunction(idHistogram);
+ int min = histogramFunction->getMinX();
+ float x = porcentageMaxX*(histogramFunction->getMaxX()-min);
+ return min + x;
}
/*
Returns the minimum value ot the histogram that is show to the user
*/
float HistogramWidget::getMinShowedPorcentage()
{
- float porcentageMinX=plotter->getMinShowedPorcentage();
- pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
- int min=histogramFunction->getMinX();
- float x=porcentageMinX*(histogramFunction->getMaxX()-min);
- return min+ x;
+ float porcentageMinX = plotter->getMinShowedPorcentage();
+ pGraphicalFunction* histogramFunction = plotter->getFunction(idHistogram);
+ int min = histogramFunction->getMinX();
+ float x = porcentageMinX*(histogramFunction->getMaxX()-min);
+ return min + x;
}
/*
Returns the minimum value ot the histogram that is show to the user
*/
float HistogramWidget::getActualShowedPorcentage()
{
- float porcentageActualX=plotter->getMinShowedPorcentage();
- pGraphicalFunction* histogramFunction=plotter->getFunction(idHistogram);
- int min=histogramFunction->getMinX();
- float x=porcentageActualX*(histogramFunction->getMaxX()-min);
- return min+ x;
+ float porcentageActualX = plotter->getMinShowedPorcentage();
+ pGraphicalFunction* histogramFunction = plotter->getFunction(idHistogram);
+ int min = histogramFunction->getMinX();
+ float x = porcentageActualX*(histogramFunction->getMaxX()-min);
+ return min + x;
}
//---------------------------------------
// setting data in transferences function
{
bool result=false;
pGraphicalFunction* tf=plotter->getFunction(idTransferenceFunction);
-printf("EED %p HistogramWidget::addPointToTransferenceFunction tp%p x%f y%f %d\n",this, tf, x ,y, idTransferenceFunction);
- if (tf!=NULL) { result=tf->AddPoint(x,y); }
+//printf("EED %p HistogramWidget::addPointToTransferenceFunction tp%p x%f y%f %d\n",this, tf, x ,y, idTransferenceFunction);
+ if (tf!=NULL)
+ {
+ result=tf->AddPoint(x,y);
+ } // if tf
return result;
}
void HistogramWidget::setTransferenceFunctionHasPoints(bool hasPoints)
{
- transferenceFunctionHasPoints=hasPoints;
+ transferenceFunctionHasPoints = hasPoints;
}
void HistogramWidget::setTransferenceFunctionHasColor(bool hasColorPoints)
{
- transferenceFunctionHasPoints=hasColorPoints;
+ transferenceFunctionHasPoints = hasColorPoints;
}
+
int HistogramWidget::getHistogramSize()
{
return histogramSize;
}
+
void HistogramWidget::setType(int type)
{
- this->type=type;
+ this->type = type;
}
/**
** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
**/
- void HistogramWidget::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value){
+ void HistogramWidget::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value)
+ {
plotter->GetValuesPointsFunction(greylevel,value,histogramSize);
}