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