X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FpPlotter%2FHistogramWidget.cxx;h=eb6d6333cde0e8af09cfef6ef48d58f81d539ffe;hb=dea0efc567d8332b2e7eb936e3ba4ac1c11b2542;hp=d3dbfc46b1898b5599aa4500d64b48504cd3cb73;hpb=f70f07396065237d1d4fabea4e9524ad4d9c7d13;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx index d3dbfc4..eb6d633 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramWidget.cxx @@ -1,3 +1,28 @@ +/*# --------------------------------------------------------------------- +# +# 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 */ @@ -57,11 +82,11 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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); @@ -70,17 +95,14 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint //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); @@ -88,22 +110,21 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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 @@ -135,13 +156,18 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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); @@ -171,25 +197,24 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint */ 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) { @@ -200,11 +225,13 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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 } /* @@ -216,7 +243,8 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint GetClientSize(&scrX,&scrY); plotter->SetSize(scrX,scrY); pGraphicalFunction* actual=plotter->getFunction(idTransferenceFunction); - if(actual!=NULL){ + if(actual!=NULL) + { actual->setScreens(scrX,scrY); actual->setScales(); } @@ -237,12 +265,12 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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(); } } /* @@ -263,44 +291,44 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint /* 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 @@ -314,7 +342,10 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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); } + if (tf!=NULL) + { + result=tf->AddPoint(x,y); + } // if tf return result; } @@ -378,26 +409,29 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint 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& greylevel,std::vector& value){ + void HistogramWidget::GetValuesPointsFunction(std::vector& greylevel,std::vector& value) + { plotter->GetValuesPointsFunction(greylevel,value,histogramSize); }