]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx
da3d19b816e7aab56e211799800c3660d91ba27c
[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         imagedataValueResult->SetSpacing(spc);
579         imagedataValueResult->SetDimensions( newDim );
580
581 //EED 2017-01-01 Migration VTK7
582 #if VTK_MAJOR_VERSION <= 5
583
584 //EED 2017-12-18
585         imagedataValueResult->SetScalarType(scalartype);
586         //imagedataValueResult->SetScalarTypeToUnsignedShort();
587         imagedataValueResult->AllocateScalars();
588 #else
589         imagedataValueResult->AllocateScalars(scalartype,1);
590 #endif
591
592
593         if (imagedataMaskResult!=NULL)
594         {
595                 imagedataMaskResult->Delete();
596         }
597         imagedataMaskResult  = vtkImageData::New();
598
599
600         imagedataMaskResult->SetSpacing(spc);
601         imagedataMaskResult->SetDimensions( newDim );
602
603 //EED 2017-01-01 Migration VTK7
604 #if VTK_MAJOR_VERSION <= 5
605     //EED 2017-12-18
606     //imagedataMaskResult->SetScalarTypeToUnsignedShort();
607         imagedataMaskResult->SetScalarTypeToUnsignedChar();
608         imagedataMaskResult->AllocateScalars();
609 #else
610         imagedataMaskResult->AllocateScalars(VTK_UNSIGNED_CHAR,1);
611 #endif
612
613 }
614
615
616 //------------------------------------------------------------------------
617 void ContourExtractData::InitVolumeStatistics()
618 {
619         vol_rCountRange                         = 0;
620         vol_rsize                                       = 0;
621         vol_minValue                            = 9999999;
622         vol_maxValue                            =-9999999;
623         vol_acum_average                        = 0;
624         vol_acum_standardeviation       = 0;
625 }
626
627 //------------------------------------------------------------------------
628 void ContourExtractData::SetVolumeStatistics(int rCountRange, 
629                                                                                          int rsize,
630                                                                                          double minValue,
631                                                                                          double maxValue,
632                                                                                          double acum_average,
633                                                                                          double acum_standardeviation)
634 {
635         vol_rCountRange                         = vol_rCountRange + rCountRange; 
636         vol_rsize                                       = vol_rsize + rsize; 
637
638         if (minValue<vol_minValue){ vol_minValue = minValue;  }
639         if (maxValue>vol_maxValue){ vol_maxValue = maxValue;  }
640
641         vol_acum_average                        = vol_acum_average + acum_average; 
642         vol_acum_standardeviation       = vol_acum_standardeviation + acum_standardeviation; 
643 }
644
645 //------------------------------------------------------------------------
646 void ContourExtractData::GetVolumeStatistics(int *vol_rCountRange, 
647                                                                                          int *vol_rsize,
648                                                                                          double *vol_minValue,
649                                                                                          double *vol_maxValue,
650                                                                                          double *vol_average,
651                                                                                          double *vol_standardeviation)
652 {
653         *vol_rCountRange                = this->vol_rCountRange; 
654         *vol_rsize                              = this->vol_rsize; 
655         *vol_minValue                   = this->vol_minValue; 
656         *vol_maxValue                   = this->vol_maxValue; 
657         *vol_average                    = this->vol_acum_average / this->vol_rsize;
658         *vol_standardeviation   = sqrt(this->vol_acum_standardeviation / this->vol_rsize);
659 }
660
661
662 //------------------------------------------------------------------------
663 void ContourExtractData::Statistics( std::vector<double> *inputLstValue, 
664                                                                         int     grayRangeMin,
665                                                                         int     grayRangeMax,
666                                                                         int             *rCountRange, 
667                                                                         int             *rsize, 
668                                                                         double  *rmin, 
669                                                                         double  *rmax,
670                                                                         double  *raverage,
671                                                                         double  *rstandardeviation
672                                                                         )
673 {
674         double min                                              = 0;
675         double max                                              = 0;
676         double average                                  = 0;
677         double standardeviation                 = 0;
678         double acum_average                             = 0;
679         double acum_standardeviation            = 0;
680         int      size                                           = 0;
681         int      countRange                                     = 0;
682         double ng;
683
684         if (inputLstValue!=NULL)
685         {
686                 size=inputLstValue->size();
687                 if (size>0){
688                         max=(*inputLstValue)[0];
689                         min=(*inputLstValue)[0];
690                         // Average , countRange
691                         int i;
692                         for ( i=0; i<size; i++ )
693                         {
694                                 ng=(*inputLstValue)[i];
695                                 acum_average = acum_average + ng;
696                                 if (max<ng) max=ng;             // Max
697                                 if (min>ng) min=ng;     // Min
698                                 if ((ng>=grayRangeMin) && (ng<=grayRangeMax)) countRange++;  // countRange
699                         } // for average
700                         average = acum_average / size;
701
702                         // Standar Deviation
703                         acum_standardeviation=0;
704                         double tmp;
705                         for ( i=0; i<size; i++ )
706                         {
707                                 tmp = (*inputLstValue)[i] - average;
708                                 acum_standardeviation = acum_standardeviation + tmp*tmp;
709                         } // for standar deviation
710                         standardeviation = sqrt(acum_standardeviation/size);
711                         SetVolumeStatistics(countRange, (*rsize),
712                                                                 min,max,
713                                                             acum_average,acum_standardeviation);
714                 } // if size
715         } // if NULL
716
717         // OUTPUT
718         *rsize                          = size; 
719         *rCountRange            = countRange;
720         *rmin                           = min; 
721         *rmax                           = max;
722         *raverage                       = average;
723         *rstandardeviation      = standardeviation;
724 }
725
726 //------------------------------------------------------------------------
727 void ContourExtractData::SetTypeOperation(int type)
728 {
729         _typeOperation=type;
730 }
731
732 //------------------------------------------------------------------------
733 void ContourExtractData::Fill_lstlstlstVecXY(int iContour, int sizeY)
734 {
735         int i,y;
736         double x1,y1,z1,x2,y2,z2;
737         manualBaseModel *manualcontourmodel= lstManConMod[iContour];    
738         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
739         manualcontourmodel->UpdateSpline();
740         //------------------------------------------------------------------------------------------------------
741
742         for (y=0;y<sizeY;y++)
743         {
744                 manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1);
745                 x1=x1+0.5; y1=y1+0.5;
746                 for (i=1; i<nps; i++)
747                 {
748                         manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2);
749                         x2=x2+0.5; y2=y2+0.5;
750                         if ( ((y1<y2)&&(y>=y1)&&(y<=y2)) || ((y1>y2)&&(y>=y2)&&(y<=y1)) || ((int)y1==y) || ((int)y2==y)  )
751                         {
752                                 _lstlstlstVecX1[iContour][y].push_back(x1);
753                                 _lstlstlstVecY1[iContour][y].push_back(y1);
754                                 _lstlstlstVecX2[iContour][y].push_back(x2);
755                                 _lstlstlstVecY2[iContour][y].push_back(y2);
756                         } 
757                         x1=x2; y1=y2; z1=z2;
758                 } // for i  Points in spline
759         } // y
760
761 }
762
763 void ContourExtractData::InitLstContoursLinesYPoints()
764 {
765         // init InInside Optimisation  
766         int i;
767
768         _lstlstlstVecX1.clear();
769         _lstlstlstVecY1.clear();
770         _lstlstlstVecX2.clear();
771         _lstlstlstVecY2.clear();
772
773         /* RaC 20-11-09
774         int ext[6];
775         this->imagedata->GetWholeExtent(ext);
776         int sizeY = ext[3]-ext[2]+1;
777         */
778         std::vector<double> vecDouble;
779         std::vector< std::vector<double> > vecVecDouble;
780         for ( i=0 ; i<_sizeImageY ; i++ )
781         {
782                 vecVecDouble.push_back( vecDouble );
783         }
784
785         //Fill structure with points
786         int sizeContours = lstManConMod.size();
787         for( i=0 ; i<sizeContours ; i++ )
788         {
789                 _lstlstlstVecX1.push_back( vecVecDouble );
790                 _lstlstlstVecY1.push_back( vecVecDouble );
791                 _lstlstlstVecX2.push_back( vecVecDouble );
792                 _lstlstlstVecY2.push_back( vecVecDouble );
793                 Fill_lstlstlstVecXY(i,_sizeImageY);
794         }
795
796 }
797
798 void ContourExtractData::SetScalarRange(double min, double max)
799 {
800         scalarRange[0]=min;
801         scalarRange[1]=max;
802 }
803
804 void ContourExtractData::SetSizeImageY(int pSizeImageY)
805 {
806         _sizeImageY=pSizeImageY;
807 }