]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx
801078958158d57a1b217ec054d5fc78c39355d3
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / ContourExtractData.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "ContourExtractData.h"
27
28
29 //----------------------------------------------------------------------
30 ContourExtractData::ContourExtractData( bool okImagesResults)
31 {
32         this->imagedata                 = NULL;
33         imagedataValueResult    = NULL;
34         imagedataMaskResult             = NULL;
35         this->okImagesResults   = okImagesResults;
36         _typeOperation                  = 0;
37 }
38
39 // ------------------------------------------------------------------------
40
41 ContourExtractData::~ContourExtractData()
42 {
43 }
44
45
46 //----------------------------------------------------------------------
47 void ContourExtractData::SetImage( vtkImageData* imagedata)
48 {
49         this->imagedata                 = imagedata;
50         this->imagedata->GetScalarRange(scalarRange);
51
52         // RaC 20-11-09 Changes in InitLstContoursLinesYPoints
53         int ext[6];
54
55 //EED 2017-01-01 Migration VTK7
56 #if VTK_MAJOR_VERSION <= 5
57         this->imagedata->GetWholeExtent(ext);
58 #else
59         this->imagedata->GetExtent(ext);
60 #endif
61
62         _sizeImageY = ext[3]-ext[2]+1;
63
64         // init vtk image result : valuesImage maskImage  
65         if (this->okImagesResults==true){  InitVtkImagesResult(); }
66 }
67 //----------------------------------------------------------------------
68 void ContourExtractData::SetZtoBeAnalys( int z )
69 {
70         this->zImage                    = z;
71 }
72
73 //------------------------------------------------------------------------
74 void ContourExtractData::SetLstManualContourModel( std::vector<manualBaseModel*> lstManConMod)
75 {
76         this->lstManConMod = lstManConMod;
77 }
78
79
80 //------------------------------------------------------------------------
81 void ContourExtractData::GetMinMaxPoint(int *minPoint, 
82                                                                                 int *maxPoint, 
83                                                                                 manualBaseModel *manualcontourmodel
84                                                                                 )
85 {
86         int i;
87         //int   np              = manualcontourmodel->GetSizeLstPoints( );  // number of control points // JPRx
88
89         // JSTG 26-02-08 ---------------------------------------------------------------------------------------
90         //int nps = manualviewbaseecontour->GetNumberOfPointsSpline(); // number of points in the spline
91         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
92         //------------------------------------------------------------------------------------------------------
93
94         // JSTG 26-02-08 ---------------------------------------------------------------------------------------
95         //double x,y,z,t;
96         double x,y,z;
97         //double delta=( double ) ( np  ) / ( double ) ( nps  );
98         manualcontourmodel->UpdateSpline();
99         for (i=0; i<nps; i++)
100         {
101                 //t= delta * (double)i;
102                 //manualcontourmodel->GetSplinePoint(t,x,y,z);
103                 manualcontourmodel->GetSpline_i_Point(i,&x,&y,&z);
104                 if (x<minPoint[0]){ minPoint[0]=(int)x; }
105                 if (y<minPoint[1]){ minPoint[1]=(int)y; }
106                 if (x>maxPoint[0]){ maxPoint[0]=(int)x; }
107                 if (y>maxPoint[1]){ maxPoint[1]=(int)y; }
108         }
109         minPoint[0]--;
110         minPoint[1]--;
111         maxPoint[0]++;
112         maxPoint[1]++;
113         //------------------------------------------------------------------------------------------------------
114 }
115
116 //------------------------------------------------------------------------
117 void ContourExtractData::GetMinMaxPoint_Of_LstManConMod(        int *minPoint, 
118                                                                                                                 int *maxPoint
119                                                                                                                 )
120
121 {
122         int i,size = lstManConMod.size();
123
124         for(i=0 ; i<size ; i++)
125         {
126                 GetMinMaxPoint(minPoint,maxPoint,lstManConMod[i]);
127         }
128 }
129
130
131 //------------------------------------------------------------------------
132 int ContourExtractData::AnalisisContourInsideV2(int x, int y, int iContour )
133 {
134         bool inBorder=false;
135         int result      = 0;
136         int i;
137
138         int nps=_lstlstlstVecX1[iContour][y].size();
139
140         double x1,y1,x2,y2;
141         double borderX, borderY;
142         double xx1, yy1,xx2, yy2;
143         double xx=x, yy=y;
144         double d;
145
146         for (i=0; i<nps; i++)
147         {
148                 x1=_lstlstlstVecX1[iContour][y][i];
149                 y1=_lstlstlstVecY1[iContour][y][i];
150                 x2=_lstlstlstVecX2[iContour][y][i];
151                 y2=_lstlstlstVecY2[iContour][y][i];
152
153                 borderX=x1;
154                 borderY=y1;
155
156                 if (y1<y2) 
157                 { 
158                         xx1=x1; yy1=y1; xx2=x2; yy2=y2;
159                 } else {
160                         xx1=x2; yy1=y2; xx2=x1; yy2=y1; 
161                 } 
162
163                 double difxx2xx1=fabs(xx2-xx1);
164                 if (difxx2xx1==0) difxx2xx1=0.0000000001;
165
166                 // Finding border looking in vertical direction  AND  verifing if pixel is at right of the line 
167                 if  ( (yy>=yy1)&&(yy<=yy2) ) 
168                 {
169                         //by triangle similarity
170                         d = ( fabs(xx2-xx1)*(yy-yy1) ) / (yy2-yy1) ;
171                         if ( (xx1<=xx2)&&(x<(xx1+d)) )  {       result++;       }
172                         if ( (xx1>xx2)&&(x<(xx1-d)) )   {       result++;       } 
173
174                         if ( (yy2-yy1)/difxx2xx1 >= 1.0)
175                         {
176                                 if (xx1<=xx2)   
177                                 { 
178                                         borderX = xx1+d;
179                                         borderY = y;
180                                 } else { 
181                                         borderX = xx1-d;
182                                         borderY = y;
183                                 } 
184                         } 
185                 } // if point inside y 
186
187
188                 // Finding border looking in vertical direction
189                 if ( ((xx1<=xx2)&&(xx>=xx1)&&(xx<xx2)) || ((xx1>xx2)&&(xx>=xx2)&&(xx<xx1)) )
190                 {
191                         if ( (yy2-yy1)/difxx2xx1 <= 1.0)
192                         {
193                                 //by triangle similarity
194                                 d = ( fabs(xx1-xx)*(yy2-yy1) ) / difxx2xx1;
195                                 if (yy1+d<=yy2) {
196                                         borderX=x;
197                                         borderY=yy1+d;
198                                 }
199                         }                       
200                 } // if point inside x                  
201
202
203                 //Border verification
204                 if (   (x==(int)borderX) && (y==(int)borderY)   )  { inBorder=true; }// if point in border
205
206                 // Verification : border in horizontal line 
207                 if ( ((int)y1==(int)y2)  &&  ((int)y1==y) && (x1<x2) && (x>=x1) && (x<=x2))             { inBorder=true;        }
208                 if ( ((int)y1==(int)y2)  &&  ((int)y1==y) && (x2<x1) && (x>=x2) && (x<=x1))             { inBorder=true;        }
209
210                 if (inBorder==true){ i=nps; }           
211         } // for i
212
213         if (inBorder==true)     { result=1;     }
214
215         return result;
216 }
217
218
219
220 //------------------------------------------------------------------------
221 // typeOperation=0 AND
222 // typeOperation=1 OR
223 // typeOperation=2 XOR
224 bool ContourExtractData::isInside(int x, int y, int typeOperation)
225 {
226         bool result                             = false;
227         int numberLeft                  = 0;
228         int i,size                              = this->lstManConMod.size();
229         int numberInside        = 0;
230
231         /* RaC 20-11-09 (C1) Changes to use the method without the image.
232         int ext[6];
233         imagedata->GetExtent(ext);
234
235         if ((x>=0) && (x<=ext[1]) && (y>=0) && (y<=ext[3]))
236         {
237         */
238
239         if (typeOperation==0)  // AND  Intersection
240         {
241                 for (i=0;i<size;i++)
242                 {
243                         // To process the statistics of the Points contour the procedure is different
244                         // RaC 19-09-09
245                         manualBaseModel *mbm = lstManConMod[i];
246                         if(mbm->GetTypeModel()==7)
247                         {
248                                 if(mbm->IsPoint(x,y)==true)
249                                 {
250                                         numberLeft=1;
251                                 }
252                         }//if
253                         else
254                         {
255                                 numberLeft =  AnalisisContourInsideV2(x,y, i );
256                         }//else
257
258                         if ( (numberLeft % 2) ==1){         numberInside++;  }
259                 }
260                 if ( numberInside == (size) ){ result=true; }
261         } // AND  Intersection
262
263         numberLeft=0;
264
265         if (typeOperation==1)  // OR  All
266         {
267                 for (i=0;i<size;i++)
268                 {
269                         // To process the statistics of the Points contour the procedure is different
270                         // RaC 19-09-09
271                         manualBaseModel *mbm = lstManConMod[i];
272                         if(mbm->GetTypeModel()==7)
273                         {
274                                 if(mbm->IsPoint(x,y)==true)
275                                 {
276                                         numberLeft=1;
277                                 }
278                         }//if
279                         else
280                         {
281                                 numberLeft =  AnalisisContourInsideV2(x,y, i );
282                         }//else
283                         if ( (numberLeft % 2) ==1){ result=true;  }
284                 }
285         } // OR  All
286
287         numberLeft=0;
288
289         if (typeOperation==2)  // XOR  crown
290         {
291                 for (i=0;i<size;i++)
292                 {
293                         // To process the statistics of the Points contour the procedure is different
294                         // RaC 19-09-09
295                         manualBaseModel *mbm = lstManConMod[i];
296                         if(mbm->GetTypeModel()==7)
297                         {
298                                 if(mbm->IsPoint(x,y)==true)
299                                 {
300                                         numberLeft=1;
301                                 }
302                         }//if
303                         else
304                         {
305                                 numberLeft =  numberLeft + AnalisisContourInsideV2(x,y, i );
306                         }//else
307
308                 }
309                 if ( numberLeft % 2 ==1){       result = true;  } 
310         }// XOR  crown
311
312
313
314         //RaC }
315
316         return result;
317 }
318
319 //------------------------------------------------------------------------
320
321 double ContourExtractData::GetDataValue(int x, int y, int z)
322 {
323         //      wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)wxvtkbaseview;
324         //      int z = (int)wxvtk2dbaseview->GetVtkBaseData()->GetZ();
325         //JSTG 13-03-08-----
326         //EED OJO avec JS       _zz = z;
327         //------------------
328         double result;
329         void *p;
330         p = imagedata->GetScalarPointer(x,y,z);
331
332         if (imagedata->GetScalarType()==VTK_CHAR)
333         {
334                 char *pp = (char*)p;
335                 result = (double)(*pp);
336         }
337         else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
338         {
339                 signed char *pp = (signed char*)p;
340                 result = (double)(*pp);
341         }
342         else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
343         {
344                 unsigned char *pp = (unsigned char*)p;
345                 result = (double)(*pp);
346         }
347         else if (imagedata->GetScalarType()==VTK_SHORT)
348         {
349                 short *pp = (short*)p;
350                 result = (double)(*pp);
351         }
352         else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
353         {
354                 unsigned short *pp = (unsigned short*)p;
355                 result = (double)(*pp);
356         }
357         else if (imagedata->GetScalarType()==VTK_INT)
358         {
359                 int *pp = (int*)p;
360                 result = (double)(*pp);
361         }
362         else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
363         {
364                 unsigned int *pp = (unsigned int*)p;
365                 result = (double)(*pp);
366         }
367         else if (imagedata->GetScalarType()==VTK_LONG)
368         {
369                 long *pp = (long*)p;
370                 result = (double)(*pp);
371         }
372         else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
373         {
374                 unsigned long *pp = (unsigned long*)p;
375                 result = (double)(*pp);
376         }
377         else if (imagedata->GetScalarType()==VTK_FLOAT)
378         {       
379                 float *pp = (float*)p;
380                 result = (double)(*pp);
381         }
382         else if (imagedata->GetScalarType()==VTK_DOUBLE)
383         {
384                 double *pp = (double*)p;
385                 result = (double)(*pp);
386         }
387
388         return result;
389 }
390
391 //------------------------------------------------------------------------
392
393 void ContourExtractData::PutVtkImageDataResultValue( int x, int y, int z, double value )
394 {
395         unsigned short *pValue;
396         unsigned short *pMask;
397 //EED 2017-12-18
398         imagedataValueResult->SetScalarComponentFromDouble(x,y,z,0,value);
399         imagedataMaskResult->SetScalarComponentFromDouble(x,y,z,0,255);
400 //      pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,z);
401 //      *pValue = (unsigned short)value;
402 //      pMask   = (unsigned char *)imagedataMaskResult->GetScalarPointer(x,y,z);
403 //      *pMask  = 255;
404 }
405
406 //------------------------------------------------------------------------
407 void ContourExtractData::ResetImageResult(int z)
408 {
409         if (okImagesResults==true)
410         {
411                 unsigned short *pValue;
412                 unsigned short *pMask;
413                 pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,z);
414                 pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,z);
415
416                 int ext[6];
417                 imagedataValueResult->GetExtent(ext);
418
419                 int size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); 
420                 memset(pValue,0, size*imagedataValueResult->GetScalarSize() );
421                 memset(pMask,0, size*imagedataMaskResult->GetScalarSize() );
422         } // if
423 }
424
425
426 //------------------------------------------------------------------------
427 void ContourExtractData::CalculateImageResult()
428 {
429         if (okImagesResults==true)
430         {
431                 ResetImageResult(zImage);
432
433                 int minPoint[2];
434                 int maxPoint[2];
435                 int i,j;
436                 double value;
437
438                 minPoint[0] = 999999;
439                 minPoint[1] = 999999;
440                 maxPoint[0] = -999999;
441                 maxPoint[1] = -999999;
442
443                 GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
444                 InitLstContoursLinesYPoints();
445
446                 for (j=minPoint[1]; j<=maxPoint[1]; j++)
447                 {
448                         for (i=minPoint[0]; i<=maxPoint[0]; i++)
449                         {
450
451                                 //RaC 20-11-09 Changes specified in isInside (C1)
452                                 int ext[6];
453                                 imagedata->GetExtent(ext);
454
455                                 if ((i>=0) && (i<=ext[1]) && (j>=0) && (j<=ext[3]))
456                                 {
457                   if (isInside(i,j,_typeOperation)==true)
458                                         {
459                                           value = GetDataValue(i,j,zImage);
460                                           if ( (value>=scalarRange[0]) && (value<=scalarRange[1]) )
461                                           {
462                                                 PutVtkImageDataResultValue(i,j,zImage,  value );
463                                           } // scalarRange
464                                         } // if isInside
465
466                                 } // if ext
467                         } // for i
468                 } // for j
469
470
471                 imagedataValueResult->Modified();
472                 imagedataMaskResult->Modified();
473
474 //EED 2017-01-01 Migration VTK7
475 #if VTK_MAJOR_VERSION <= 5
476                 imagedataValueResult->Update();
477                 imagedataMaskResult->Update();
478 #else
479   //...
480 #endif
481
482         } // if
483
484 }
485
486 //------------------------------------------------------------------------
487 void ContourExtractData::GetValuesInsideCrown(  int *numberOfPixels, 
488                                                                                                 std::vector<double> *pLstValue,
489                                                                                                 std::vector<double> *pLstValuePosX,
490                                                                                                 std::vector<double> *pLstValuePosY,
491                                                                                                 std::vector<double> *pLstValuePosZ)
492 {
493         pLstValue->clear();
494         pLstValuePosX->clear();
495         pLstValuePosY->clear();
496         pLstValuePosZ->clear();
497
498         //      if (okImagesResults==true)
499         //      {
500         //              ResetImageResult(zImage);
501         //      }
502
503         int minPoint[2];
504         int maxPoint[2];
505         int i,j;
506         double value;
507         int acum=0;
508
509         minPoint[0] = 999999;
510         minPoint[1] = 999999;
511         maxPoint[0] = -999999;
512         maxPoint[1] = -999999;
513
514         GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
515         InitLstContoursLinesYPoints();
516
517         for (j=minPoint[1]; j<=maxPoint[1]; j++)
518         {
519                 for (i=minPoint[0]; i<=maxPoint[0]; i++)
520                 {
521                         //RaC 20-11-09 Changes specified in isInside (C1)
522                         int ext[6];
523                         imagedata->GetExtent(ext);
524
525                         if ((i>=0) && (i<=ext[1]) && (j>=0) && (j<=ext[3]))
526                         {
527                     if (isInside(i,j,_typeOperation)==true)
528                                 {
529
530                                         acum++;
531                                         value = GetDataValue(i,j,zImage);
532                                         if ( (value>=scalarRange[0]) && (value<=scalarRange[1]) )
533                                         {
534                                                 pLstValue               -> push_back( value );
535                                                 pLstValuePosX   -> push_back( i );
536                                                 pLstValuePosY   -> push_back( j );
537                                                 pLstValuePosZ   -> push_back( -1 );
538                                         } // scalarRange
539                                 } // if isInside
540                         } // if ext
541                 } // for
542         } // for
543
544         *numberOfPixels = acum;
545 }
546
547 //------------------------------------------------------------------------
548
549 vtkImageData *ContourExtractData::GetVtkImageValueResult()
550 {
551         return imagedataValueResult;
552 }
553 //------------------------------------------------------------------------
554 vtkImageData *ContourExtractData::GetVtkImageMaskResult()
555 {
556         return imagedataMaskResult;
557 }
558 // ------------------------------------------------------------------------
559 void ContourExtractData::InitVtkImagesResult()
560 {
561         int ext[6];
562         int newDim[3];
563         double spc[3];
564         int scalartype;
565
566         imagedata->GetSpacing(spc);
567         imagedata->GetExtent(ext);
568         newDim[0]=ext[1]-ext[0]+1;
569         newDim[1]=ext[3]-ext[2]+1;
570         newDim[2]=ext[5]-ext[4]+1;
571         scalartype = imagedata->GetScalarType();
572
573         if (imagedataValueResult!=NULL)
574         {
575                 imagedataValueResult->Delete();
576         }
577         imagedataValueResult = vtkImageData::New();
578 <<<<<<< HEAD
579         //        imagedataValueResult->SetScalarType(scalartype);
580 =======
581
582 //EED 2017-12-18
583         imagedataValueResult->SetScalarType(scalartype);
584         //imagedataValueResult->SetScalarTypeToUnsignedShort();
585
586 >>>>>>> master
587         imagedataValueResult->SetSpacing(spc);
588         imagedataValueResult->SetDimensions( newDim );
589
590 //EED 2017-01-01 Migration VTK7
591 #if VTK_MAJOR_VERSION <= 5
592         imagedataValueResult->SetScalarTypeToUnsignedShort();
593         imagedataValueResult->AllocateScalars();
594 #else
595         imagedataValueResult->AllocateScalars(VTK_UNSIGNED_SHORT,1);
596 #endif
597
598
599         if (imagedataMaskResult!=NULL)
600         {
601                 imagedataMaskResult->Delete();
602         }
603         imagedataMaskResult  = vtkImageData::New();
604 <<<<<<< HEAD
605         //        imagedataMaskResult->SetScalarType(scalartype);
606 =======
607
608 //EED 2017-12-18
609 //      imagedataMaskResult->SetScalarType(scalartype);
610 //      imagedataMaskResult->SetScalarTypeToUnsignedShort();
611         imagedataMaskResult->SetScalarTypeToUnsignedChar();
612
613 >>>>>>> master
614         imagedataMaskResult->SetSpacing(spc);
615         imagedataMaskResult->SetDimensions( newDim );
616
617 //EED 2017-01-01 Migration VTK7
618 #if VTK_MAJOR_VERSION <= 5
619         imagedataMaskResult->SetScalarTypeToUnsignedShort();
620         imagedataMaskResult->AllocateScalars();
621 #else
622         imagedataMaskResult->AllocateScalars(VTK_UNSIGNED_SHORT,1);
623 #endif
624
625 }
626
627
628 //------------------------------------------------------------------------
629 void ContourExtractData::InitVolumeStatistics()
630 {
631         vol_rCountRange                         = 0;
632         vol_rsize                                       = 0;
633         vol_minValue                            = 9999999;
634         vol_maxValue                            =-9999999;
635         vol_acum_average                        = 0;
636         vol_acum_standardeviation       = 0;
637 }
638
639 //------------------------------------------------------------------------
640 void ContourExtractData::SetVolumeStatistics(int rCountRange, 
641                                                                                          int rsize,
642                                                                                          double minValue,
643                                                                                          double maxValue,
644                                                                                          double acum_average,
645                                                                                          double acum_standardeviation)
646 {
647         vol_rCountRange                         = vol_rCountRange + rCountRange; 
648         vol_rsize                                       = vol_rsize + rsize; 
649
650         if (minValue<vol_minValue){ vol_minValue = minValue;  }
651         if (maxValue>vol_maxValue){ vol_maxValue = maxValue;  }
652
653         vol_acum_average                        = vol_acum_average + acum_average; 
654         vol_acum_standardeviation       = vol_acum_standardeviation + acum_standardeviation; 
655 }
656
657 //------------------------------------------------------------------------
658 void ContourExtractData::GetVolumeStatistics(int *vol_rCountRange, 
659                                                                                          int *vol_rsize,
660                                                                                          double *vol_minValue,
661                                                                                          double *vol_maxValue,
662                                                                                          double *vol_average,
663                                                                                          double *vol_standardeviation)
664 {
665         *vol_rCountRange                = this->vol_rCountRange; 
666         *vol_rsize                              = this->vol_rsize; 
667         *vol_minValue                   = this->vol_minValue; 
668         *vol_maxValue                   = this->vol_maxValue; 
669         *vol_average                    = this->vol_acum_average / this->vol_rsize;
670         *vol_standardeviation   = sqrt(this->vol_acum_standardeviation / this->vol_rsize);
671 }
672
673
674 //------------------------------------------------------------------------
675 void ContourExtractData::Statistics( std::vector<double> *inputLstValue, 
676                                                                         int     grayRangeMin,
677                                                                         int     grayRangeMax,
678                                                                         int             *rCountRange, 
679                                                                         int             *rsize, 
680                                                                         double  *rmin, 
681                                                                         double  *rmax,
682                                                                         double  *raverage,
683                                                                         double  *rstandardeviation
684                                                                         )
685 {
686         double min                                              = 0;
687         double max                                              = 0;
688         double average                                  = 0;
689         double standardeviation                 = 0;
690         double acum_average                             = 0;
691         double acum_standardeviation            = 0;
692         int      size                                           = 0;
693         int      countRange                                     = 0;
694         double ng;
695
696         if (inputLstValue!=NULL)
697         {
698                 size=inputLstValue->size();
699                 if (size>0){
700                         max=(*inputLstValue)[0];
701                         min=(*inputLstValue)[0];
702                         // Average , countRange
703                         int i;
704                         for ( i=0; i<size; i++ )
705                         {
706                                 ng=(*inputLstValue)[i];
707                                 acum_average = acum_average + ng;
708                                 if (max<ng) max=ng;             // Max
709                                 if (min>ng) min=ng;     // Min
710                                 if ((ng>=grayRangeMin) && (ng<=grayRangeMax)) countRange++;  // countRange
711                         } // for average
712                         average = acum_average / size;
713
714                         // Standar Deviation
715                         acum_standardeviation=0;
716                         double tmp;
717                         for ( i=0; i<size; i++ )
718                         {
719                                 tmp = (*inputLstValue)[i] - average;
720                                 acum_standardeviation = acum_standardeviation + tmp*tmp;
721                         } // for standar deviation
722                         standardeviation = sqrt(acum_standardeviation/size);
723                         SetVolumeStatistics(countRange, (*rsize),
724                                                                 min,max,
725                                                             acum_average,acum_standardeviation);
726                 } // if size
727         } // if NULL
728
729         // OUTPUT
730         *rsize                          = size; 
731         *rCountRange            = countRange;
732         *rmin                           = min; 
733         *rmax                           = max;
734         *raverage                       = average;
735         *rstandardeviation      = standardeviation;
736 }
737
738 //------------------------------------------------------------------------
739 void ContourExtractData::SetTypeOperation(int type)
740 {
741         _typeOperation=type;
742 }
743
744 //------------------------------------------------------------------------
745 void ContourExtractData::Fill_lstlstlstVecXY(int iContour, int sizeY)
746 {
747         int i,y;
748         double x1,y1,z1,x2,y2,z2;
749         manualBaseModel *manualcontourmodel= lstManConMod[iContour];    
750         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
751         manualcontourmodel->UpdateSpline();
752         //------------------------------------------------------------------------------------------------------
753
754         for (y=0;y<sizeY;y++)
755         {
756                 manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1);
757                 x1=x1+0.5; y1=y1+0.5;
758                 for (i=1; i<nps; i++)
759                 {
760                         manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2);
761                         x2=x2+0.5; y2=y2+0.5;
762                         if ( ((y1<y2)&&(y>=y1)&&(y<=y2)) || ((y1>y2)&&(y>=y2)&&(y<=y1)) || ((int)y1==y) || ((int)y2==y)  )
763                         {
764                                 _lstlstlstVecX1[iContour][y].push_back(x1);
765                                 _lstlstlstVecY1[iContour][y].push_back(y1);
766                                 _lstlstlstVecX2[iContour][y].push_back(x2);
767                                 _lstlstlstVecY2[iContour][y].push_back(y2);
768                         } 
769                         x1=x2; y1=y2; z1=z2;
770                 } // for i  Points in spline
771         } // y
772
773 }
774
775 void ContourExtractData::InitLstContoursLinesYPoints()
776 {
777         // init InInside Optimisation  
778         int i;
779
780         _lstlstlstVecX1.clear();
781         _lstlstlstVecY1.clear();
782         _lstlstlstVecX2.clear();
783         _lstlstlstVecY2.clear();
784
785         /* RaC 20-11-09
786         int ext[6];
787         this->imagedata->GetWholeExtent(ext);
788         int sizeY = ext[3]-ext[2]+1;
789         */
790         std::vector<double> vecDouble;
791         std::vector< std::vector<double> > vecVecDouble;
792         for ( i=0 ; i<_sizeImageY ; i++ )
793         {
794                 vecVecDouble.push_back( vecDouble );
795         }
796
797         //Fill structure with points
798         int sizeContours = lstManConMod.size();
799         for( i=0 ; i<sizeContours ; i++ )
800         {
801                 _lstlstlstVecX1.push_back( vecVecDouble );
802                 _lstlstlstVecY1.push_back( vecVecDouble );
803                 _lstlstlstVecX2.push_back( vecVecDouble );
804                 _lstlstlstVecY2.push_back( vecVecDouble );
805                 Fill_lstlstlstVecXY(i,_sizeImageY);
806         }
807
808 }
809
810 void ContourExtractData::SetScalarRange(double min, double max)
811 {
812         scalarRange[0]=min;
813         scalarRange[1]=max;
814 }
815
816 void ContourExtractData::SetSizeImageY(int pSizeImageY)
817 {
818         _sizeImageY=pSizeImageY;
819 }