]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pHistogram.cxx
#2482 creaMaracasVisu Bug New High - ColorLayer refresh missing. The MPR is not...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pHistogram.cxx
index 7a395e05affc5afac18ac93dcf9c78af7dff39e8..cbfee52eeac8aedf549fbf9c1f1a37af899b9699 100644 (file)
@@ -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.
+# ------------------------------------------------------------------------ */
+
 
 //----------------------------------------------------------------------------
 // Class definition include
 #include "pHistogram.h"
 //#include "vtkJPEGReader.h"
 #include "vtkImageData.h"
-#include  "vtkImageCast.h"
-//-----------------
-// C++
-//-----------------
+#include "vtkImageCast.h"
+#include "vtkComputeHistogram2DOutliers.h"
+#include "vtkTable.h"
+
+
 #include <iostream>
 #include <fstream>
 #include <string>
 //----------------------------------------------------------------------------
 pHistogram::pHistogram(std::string filePath)
 {
-       path=filePath;
-       points= vtkImageData::New();
-       size=100;
-       sizeImage=0;
+       path                    = filePath;
+       points          = vtkImageData::New();
+       size                    = 100;
+       sizeImage       = 0;
        buildHistogram();
 }
 
 pHistogram::pHistogram(vtkImageData* imageData)
 {
-       points= vtkImageData::New();
-       size=100;
-       sizeImage=0;
+       points          = vtkImageData::New();
+       size                    = 100;
+       sizeImage       = 0;
        //cast
        /*
        vtkImageCast* cast= vtkImageCast::New();
@@ -59,19 +85,19 @@ pHistogram::pHistogram(vtkImageData* imageData)
        buildHistogram(imageData);
 }
 
+//----------------------------------------------------------------------------
 pHistogram::~pHistogram()
 {
        if(points!=NULL)points->Delete();
 }
-//----------------------------------------------------------------------------
-// Methods
-//----------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------
 void pHistogram::setImagePath(std::string filePath)
 {
        path=filePath;
 }
 
+//----------------------------------------------------------------------------
 void pHistogram::buildHistogram()
 {
        /*
@@ -95,7 +121,6 @@ void pHistogram::buildHistogram()
        imageData->GetScalarRange(range);
        initializePoints(size);
        setPoints(imageData);
-       
 }
 
 /*
@@ -117,7 +142,8 @@ void pHistogram::initializePoints(int xDimension)
 {
        //setting image data of the points
        points->SetDimensions(xDimension,1,1);
-       points->SetScalarTypeToUnsignedShort();
+//EED  points->SetScalarTypeToUnsignedShort();
+       points->SetScalarTypeToDouble();
        points->AllocateScalars();
        points->Update();
 }
@@ -127,37 +153,58 @@ void pHistogram::initializePoints(int xDimension)
 */
 void pHistogram::setPoints(vtkImageData* imageData)
 {
+
+printf("EED pHistogram::setPoints Trinng new histogram ..\n");
+/*
+printf("EED pHistogram::setPoints Test: vtkPComputeHistogram2DOutliers\n");
+vtkComputeHistogram2DOutliers *vtkhist = vtkComputeHistogram2DOutliers::New();
+vtkhist->SetPreferredNumberOfOutliers(10);
+vtkhist->SetInput(imageData);
+vtkTable *resulttable = vtkhist->GetOutputTable();
+
+printf("EED pHistogram::setPoints rows:%d\n", (int)(resulttable->GetNumberOfRows()) );
+printf("EED pHistogram::setPoints colums:%d\n", (int)(resulttable->GetNumberOfColumns()) );
+*/
+
        /*
                Pointers
        */
-       unsigned short* dataImagePointer=NULL;
-       unsigned short* dataHistogramPointer=NULL;
 
-       dataImagePointer=(unsigned short*)imageData->GetScalarPointer(0,0,0);
-       dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
+       char*                           dataImagePointerC               = (char*)imageData->GetScalarPointer(0,0,0);
+       unsigned char*  dataImagePointerUC      = (unsigned char*)imageData->GetScalarPointer(0,0,0);
+       short*                          dataImagePointerS               = (short*)imageData->GetScalarPointer(0,0,0);
+       unsigned short*         dataImagePointerUS      = (unsigned short*)imageData->GetScalarPointer(0,0,0);
+       float*                          dataImagePointerF               = (float*)imageData->GetScalarPointer(0,0,0);
+       double*                                 dataImagePointerD               = (double*)imageData->GetScalarPointer(0,0,0);
+
+       double* dataHistogramPointer                            = (double*)points->GetScalarPointer(0,0,0);
        
        /*
         Range of greys
        */
        double range[2];
        if(imageData==NULL)
-               range[1]=1;
-       else
+       {
+               range[1] = 1;
+       } else {
                imageData->GetScalarRange(range);
+       } // imageData
+
        /*
         Setting the  minimun and maximum levels of grey
        */
-       maxLevelOfGrey=(int)range[1];
-       minLevelOfGrey=(int)range[0];
+       maxLevelOfGrey = range[1];
+       minLevelOfGrey = range[0];
+       //std::cout<<"maxLevelOfGrey "<<maxLevelOfGrey<<" minLevelOfGrey "<<minLevelOfGrey<<std::endl;
        /*
         Image Size
        */
        int ext[6];
        imageData->GetExtent(ext);
        int sx,sy,sz;
-       sx=ext[1]+1;
-       sy=ext[3]+1;
-       sz=ext[5]+1;
+       sx=ext[1]-ext[0]+1;
+       sy=ext[3]-ext[2]+1;
+       sz=ext[5]-ext[4]+1;
 
        sizeImage=sx*sy*sz;
 
@@ -170,34 +217,75 @@ void pHistogram::setPoints(vtkImageData* imageData)
                dataHistogramPointer[i]=0;
        }
        
-       /*
-       Constructing the Histogram
-       */
-       //int k=size/(maxLevelOfGrey-minLevelOfGrey);
        int j=0;
-       for(i=0;i<sizeImage;i++)
+
+
+       if (imageData->GetScalarType()==VTK_CHAR)
        {
-               /*
-                hashing the histogram
-               */
-               //double p=((float)*dataImagePointer-minLevelOfGrey);
-               //j=p*k;
-               
-               j=getIndex(*dataImagePointer);
-               dataHistogramPointer[j]++;
-               dataImagePointer++;
-       }
-       /*
-       BORRAME
-       */
-       /*
-       k=0;
-       for(i=0;i<size;i++)
+               for(i=0;i<sizeImage;i++)
+               {
+                       j=getIndex(*dataImagePointerC);
+                       dataImagePointerC++;
+                       dataHistogramPointer[j]++;
+               }  // for i
+       } //  CHAR
+
+       if (imageData->GetScalarType()==VTK_UNSIGNED_CHAR)
        {
-               k=dataHistogramPointer[i];
-       }
-       */
+               for(i=0;i<sizeImage;i++)
+               {
+                       j=getIndex(*dataImagePointerUC);
+                       dataImagePointerUC++;
+                       dataHistogramPointer[j]++;
+               }  // for i
+       } // UNSIGNED CHAR
+
+
+       if (imageData->GetScalarType()==VTK_SHORT)
+       {
+               for(i=0;i<sizeImage;i++)
+               {
+                       j=getIndex(*dataImagePointerS);
+                       dataImagePointerS++;
+                       dataHistogramPointer[j]++;
+               }  // for i
+       } // SHORT
+
+       if (imageData->GetScalarType()==VTK_UNSIGNED_SHORT)
+       {
+               for(i=0;i<sizeImage;i++)
+               {
+                       j=getIndex(*dataImagePointerUS);
+                       dataImagePointerUS++;
+                       dataHistogramPointer[j]++;
+               }  // for i
+       } // UNSIGNED SHORT
+
+
+       if (imageData->GetScalarType()==VTK_FLOAT)
+       {
+               for(i=0;i<sizeImage;i++)
+               {
+                       j=getIndex(*dataImagePointerF);
+                       dataImagePointerF++;
+                       dataHistogramPointer[j]++;
+               }  // for i
+       } // FLOAT
+
+
+       if (imageData->GetScalarType()==VTK_DOUBLE)
+       {
+               for(i=0;i<sizeImage;i++)
+               {
+                       j=getIndex(*dataImagePointerD);
+                       dataImagePointerD++;
+                       dataHistogramPointer[j]++;
+               }  // for i
+       } // DOUBLE
+
 }
+
+
 /*
 Returns the poins of the histograms
 */
@@ -211,10 +299,12 @@ hash por getting the index for the histogram vector of the original
 image
 @gValue: Level of grey for which wants the index in the histogrram
 */
-int pHistogram::getIndex(int gValue)
+int pHistogram::getIndex(double gValue)
 {
-       double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
+
+       double p=((double)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
        double k=p*(size-1);
+       //std::cout<<"gValue "<<gValue<<" k "<<k<<std::endl;
        return (int)k;
 }
 /*
@@ -258,12 +348,10 @@ int pHistogram::getMinimumLevelOfGrey()
 */
 int pHistogram::getHistogramPoint(int gValue)
 {
-       double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey);
-       double k=p*size;
-
-       unsigned short* dataHistogramPointer=NULL;
-       dataHistogramPointer=(unsigned short*)points->GetScalarPointer(0,0,0);
+       //double p=((float)gValue-minLevelOfGrey)/(maxLevelOfGrey-minLevelOfGrey); // JPRx
+       //double k=p*size;
 
+       double* dataHistogramPointer = dataHistogramPointer=(double*)points->GetScalarPointer(0,0,0);
        return dataHistogramPointer[gValue];
 }