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=affe13c876cbe3c28c0a631115771bc2ce2acfc8;hpb=1bf58cfa1758464b422d1d0cca808e528043e691;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 affe13c..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 */ @@ -8,6 +33,7 @@ #include "HistogramWidget.h" #include "vtkImageCast.h" #include + // ---------------------------------------------------------------------------- // WX headers inclusion. // For compilers that support precompilation, includes . @@ -15,8 +41,9 @@ #ifndef WX_PRECOMP #include - #endif + #endif +#include //---------------------------------------------------------------------------- // Class implementation //---------------------------------------------------------------------------- @@ -41,30 +68,68 @@ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint } */ HistogramWidget::HistogramWidget( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flag,vtkImageData* imageData,int type): - wxPanel(parent,id,pos,size,flag) + wxPanel(parent,id,wxDefaultPosition,wxDefaultSize) { SetBackgroundColour(wxColour(255,255,255)); //histogram histogram= new pHistogram(imageData); + //plotter plotter=new pPlotter(this, 400,350); - + //is a plotter of histograms 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(); + //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); + + //is a plotter of histograms + 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;; + this->SetAutoLayout(true); + this->Refresh(); + } + + + + void HistogramWidget::initializeHistogram(vtkImageData* img){ + if(histogram ==NULL) + { + histogram= new pHistogram(img); + } + //draw + drawHistogram(); + drawTransferenceFunction(); } HistogramWidget::~HistogramWidget() @@ -91,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); @@ -127,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) { @@ -156,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 } /* @@ -172,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(); } @@ -193,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(); } } /* @@ -219,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 @@ -269,8 +341,11 @@ 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); } +//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; } @@ -334,20 +409,40 @@ printf("EED %p HistogramWidget::addPointToTransferenceFunction tp%p x%f y%f %d\n 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) + { + plotter->GetValuesPointsFunction(greylevel,value,histogramSize); + } +/** +** Returns two vectors, the grey level of the point and its value, the red, green +** and blue value is between [0,1] +**/ + void HistogramWidget::GetValuesColorPointsFunction(std::vector& greylevel, + std::vector& red, + std::vector& green, + std::vector& blue) + { + plotter->GetValuesColorPointsFunction(greylevel,red,green,blue); + }