]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/ContourExtractData.cxx
#3207
[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         pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(x,y,z);
398         pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(x,y,z);
399         *pMask  = 255;
400         *pValue = (unsigned short)value;
401 }
402
403 //------------------------------------------------------------------------
404 void ContourExtractData::ResetImageResult(int z)
405 {
406         if (okImagesResults==true)
407         {
408                 unsigned short *pValue;
409                 unsigned short *pMask;
410                 pValue  = (unsigned short *)imagedataValueResult->GetScalarPointer(0,0,z);
411                 pMask   = (unsigned short *)imagedataMaskResult->GetScalarPointer(0,0,z);
412
413                 int ext[6];
414                 imagedataValueResult->GetExtent(ext);
415
416                 int size = (ext[1]-ext[0]+1) * (ext[3]-ext[2]+1); 
417                 memset(pValue,0,size*2);
418                 memset(pMask,0,size*2);
419         } // if
420 }
421
422
423 //------------------------------------------------------------------------
424 void ContourExtractData::CalculateImageResult()
425 {
426         if (okImagesResults==true)
427         {
428                 ResetImageResult(zImage);
429
430                 int minPoint[2];
431                 int maxPoint[2];
432                 int i,j;
433                 double value;
434
435                 minPoint[0] = 999999;
436                 minPoint[1] = 999999;
437                 maxPoint[0] = -999999;
438                 maxPoint[1] = -999999;
439
440                 GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
441                 InitLstContoursLinesYPoints();
442
443                 for (j=minPoint[1]; j<=maxPoint[1]; j++)
444                 {
445                         for (i=minPoint[0]; i<=maxPoint[0]; i++)
446                         {
447
448                                 //RaC 20-11-09 Changes specified in isInside (C1)
449                                 int ext[6];
450                                 imagedata->GetExtent(ext);
451
452                                 if ((i>=0) && (i<=ext[1]) && (j>=0) && (j<=ext[3]))
453                                 {
454                   if (isInside(i,j,_typeOperation)==true)
455                                         {
456                                           value = GetDataValue(i,j,zImage);
457                                           if ( (value>=scalarRange[0]) && (value<=scalarRange[1]) )
458                                           {
459                                                 PutVtkImageDataResultValue(i,j,zImage,  value );
460                                           } // scalarRange
461                                         } // if isInside
462
463                                 } // if ext
464                         } // for i
465                 } // for j
466
467
468                 imagedataValueResult->Modified();
469                 imagedataMaskResult->Modified();
470
471 //EED 2017-01-01 Migration VTK7
472 #if VTK_MAJOR_VERSION <= 5
473                 imagedataValueResult->Update();
474                 imagedataMaskResult->Update();
475 #else
476   //...
477 #endif
478
479         } // if
480
481 }
482
483 //------------------------------------------------------------------------
484 void ContourExtractData::GetValuesInsideCrown(  int *numberOfPixels, 
485                                                                                                 std::vector<double> *pLstValue,
486                                                                                                 std::vector<double> *pLstValuePosX,
487                                                                                                 std::vector<double> *pLstValuePosY,
488                                                                                                 std::vector<double> *pLstValuePosZ)
489 {
490         pLstValue->clear();
491         pLstValuePosX->clear();
492         pLstValuePosY->clear();
493         pLstValuePosZ->clear();
494
495         //      if (okImagesResults==true)
496         //      {
497         //              ResetImageResult(zImage);
498         //      }
499
500         int minPoint[2];
501         int maxPoint[2];
502         int i,j;
503         double value;
504         int acum=0;
505
506         minPoint[0] = 999999;
507         minPoint[1] = 999999;
508         maxPoint[0] = -999999;
509         maxPoint[1] = -999999;
510
511         GetMinMaxPoint_Of_LstManConMod(minPoint,maxPoint);
512         InitLstContoursLinesYPoints();
513
514         for (j=minPoint[1]; j<=maxPoint[1]; j++)
515         {
516                 for (i=minPoint[0]; i<=maxPoint[0]; i++)
517                 {
518                         //RaC 20-11-09 Changes specified in isInside (C1)
519                         int ext[6];
520                         imagedata->GetExtent(ext);
521
522                         if ((i>=0) && (i<=ext[1]) && (j>=0) && (j<=ext[3]))
523                         {
524                     if (isInside(i,j,_typeOperation)==true)
525                                 {
526
527                                         acum++;
528                                         value = GetDataValue(i,j,zImage);
529                                         if ( (value>=scalarRange[0]) && (value<=scalarRange[1]) )
530                                         {
531                                                 pLstValue               -> push_back( value );
532                                                 pLstValuePosX   -> push_back( i );
533                                                 pLstValuePosY   -> push_back( j );
534                                                 pLstValuePosZ   -> push_back( -1 );
535                                         } // scalarRange
536                                 } // if isInside
537                         } // if ext
538                 } // for
539         } // for
540
541         *numberOfPixels = acum;
542 }
543
544 //------------------------------------------------------------------------
545
546 vtkImageData *ContourExtractData::GetVtkImageValueResult()
547 {
548         return imagedataValueResult;
549 }
550 //------------------------------------------------------------------------
551 vtkImageData *ContourExtractData::GetVtkImageMaskResult()
552 {
553         return imagedataMaskResult;
554 }
555 // ------------------------------------------------------------------------
556 void ContourExtractData::InitVtkImagesResult()
557 {
558         int ext[6];
559         int newDim[3];
560         double spc[3];
561         int scalartype;
562
563         imagedata->GetSpacing(spc);
564         imagedata->GetExtent(ext);
565         newDim[0]=ext[1]-ext[0]+1;
566         newDim[1]=ext[3]-ext[2]+1;
567         newDim[2]=ext[5]-ext[4]+1;
568         scalartype = imagedata->GetScalarType();
569
570         if (imagedataValueResult!=NULL)
571         {
572                 imagedataValueResult->Delete();
573         }
574         imagedataValueResult = vtkImageData::New();
575         //        imagedataValueResult->SetScalarType(scalartype);
576         imagedataValueResult->SetSpacing(spc);
577         imagedataValueResult->SetDimensions( newDim );
578
579 //EED 2017-01-01 Migration VTK7
580 #if VTK_MAJOR_VERSION <= 5
581         imagedataValueResult->SetScalarTypeToUnsignedShort();
582         imagedataValueResult->AllocateScalars();
583 #else
584         imagedataValueResult->AllocateScalars(VTK_UNSIGNED_SHORT,1);
585 #endif
586
587
588         if (imagedataMaskResult!=NULL)
589         {
590                 imagedataMaskResult->Delete();
591         }
592         imagedataMaskResult  = vtkImageData::New();
593         //        imagedataMaskResult->SetScalarType(scalartype);
594         imagedataMaskResult->SetSpacing(spc);
595         imagedataMaskResult->SetDimensions( newDim );
596
597 //EED 2017-01-01 Migration VTK7
598 #if VTK_MAJOR_VERSION <= 5
599         imagedataMaskResult->SetScalarTypeToUnsignedShort();
600         imagedataMaskResult->AllocateScalars();
601 #else
602         imagedataMaskResult->AllocateScalars(VTK_UNSIGNED_SHORT,1);
603 #endif
604
605 }
606
607
608 //------------------------------------------------------------------------
609 void ContourExtractData::InitVolumeStatistics()
610 {
611         vol_rCountRange                         = 0;
612         vol_rsize                                       = 0;
613         vol_minValue                            = 9999999;
614         vol_maxValue                            =-9999999;
615         vol_acum_average                        = 0;
616         vol_acum_standardeviation       = 0;
617 }
618
619 //------------------------------------------------------------------------
620 void ContourExtractData::SetVolumeStatistics(int rCountRange, 
621                                                                                          int rsize,
622                                                                                          double minValue,
623                                                                                          double maxValue,
624                                                                                          double acum_average,
625                                                                                          double acum_standardeviation)
626 {
627         vol_rCountRange                         = vol_rCountRange + rCountRange; 
628         vol_rsize                                       = vol_rsize + rsize; 
629
630         if (minValue<vol_minValue){ vol_minValue = minValue;  }
631         if (maxValue>vol_maxValue){ vol_maxValue = maxValue;  }
632
633         vol_acum_average                        = vol_acum_average + acum_average; 
634         vol_acum_standardeviation       = vol_acum_standardeviation + acum_standardeviation; 
635 }
636
637 //------------------------------------------------------------------------
638 void ContourExtractData::GetVolumeStatistics(int *vol_rCountRange, 
639                                                                                          int *vol_rsize,
640                                                                                          double *vol_minValue,
641                                                                                          double *vol_maxValue,
642                                                                                          double *vol_average,
643                                                                                          double *vol_standardeviation)
644 {
645         *vol_rCountRange                = this->vol_rCountRange; 
646         *vol_rsize                              = this->vol_rsize; 
647         *vol_minValue                   = this->vol_minValue; 
648         *vol_maxValue                   = this->vol_maxValue; 
649         *vol_average                    = this->vol_acum_average / this->vol_rsize;
650         *vol_standardeviation   = sqrt(this->vol_acum_standardeviation / this->vol_rsize);
651 }
652
653
654 //------------------------------------------------------------------------
655 void ContourExtractData::Statistics( std::vector<double> *inputLstValue, 
656                                                                         int     grayRangeMin,
657                                                                         int     grayRangeMax,
658                                                                         int             *rCountRange, 
659                                                                         int             *rsize, 
660                                                                         double  *rmin, 
661                                                                         double  *rmax,
662                                                                         double  *raverage,
663                                                                         double  *rstandardeviation
664                                                                         )
665 {
666         double min                                              = 0;
667         double max                                              = 0;
668         double average                                  = 0;
669         double standardeviation                 = 0;
670         double acum_average                             = 0;
671         double acum_standardeviation            = 0;
672         int      size                                           = 0;
673         int      countRange                                     = 0;
674         double ng;
675
676         if (inputLstValue!=NULL)
677         {
678                 size=inputLstValue->size();
679                 if (size>0){
680                         max=(*inputLstValue)[0];
681                         min=(*inputLstValue)[0];
682                         // Average , countRange
683                         int i;
684                         for ( i=0; i<size; i++ )
685                         {
686                                 ng=(*inputLstValue)[i];
687                                 acum_average = acum_average + ng;
688                                 if (max<ng) max=ng;             // Max
689                                 if (min>ng) min=ng;     // Min
690                                 if ((ng>=grayRangeMin) && (ng<=grayRangeMax)) countRange++;  // countRange
691                         } // for average
692                         average = acum_average / size;
693
694                         // Standar Deviation
695                         acum_standardeviation=0;
696                         double tmp;
697                         for ( i=0; i<size; i++ )
698                         {
699                                 tmp = (*inputLstValue)[i] - average;
700                                 acum_standardeviation = acum_standardeviation + tmp*tmp;
701                         } // for standar deviation
702                         standardeviation = sqrt(acum_standardeviation/size);
703                         SetVolumeStatistics(countRange, (*rsize),
704                                                                 min,max,
705                                                             acum_average,acum_standardeviation);
706                 } // if size
707         } // if NULL
708
709         // OUTPUT
710         *rsize                          = size; 
711         *rCountRange            = countRange;
712         *rmin                           = min; 
713         *rmax                           = max;
714         *raverage                       = average;
715         *rstandardeviation      = standardeviation;
716 }
717
718 //------------------------------------------------------------------------
719 void ContourExtractData::SetTypeOperation(int type)
720 {
721         _typeOperation=type;
722 }
723
724 //------------------------------------------------------------------------
725 void ContourExtractData::Fill_lstlstlstVecXY(int iContour, int sizeY)
726 {
727         int i,y;
728         double x1,y1,z1,x2,y2,z2;
729         manualBaseModel *manualcontourmodel= lstManConMod[iContour];    
730         int nps = manualcontourmodel->GetNumberOfPointsSpline(); // number of points in the spline
731         manualcontourmodel->UpdateSpline();
732         //------------------------------------------------------------------------------------------------------
733
734         for (y=0;y<sizeY;y++)
735         {
736                 manualcontourmodel->GetSpline_i_Point(0,&x1,&y1,&z1);
737                 x1=x1+0.5; y1=y1+0.5;
738                 for (i=1; i<nps; i++)
739                 {
740                         manualcontourmodel->GetSpline_i_Point(i,&x2,&y2,&z2);
741                         x2=x2+0.5; y2=y2+0.5;
742                         if ( ((y1<y2)&&(y>=y1)&&(y<=y2)) || ((y1>y2)&&(y>=y2)&&(y<=y1)) || ((int)y1==y) || ((int)y2==y)  )
743                         {
744                                 _lstlstlstVecX1[iContour][y].push_back(x1);
745                                 _lstlstlstVecY1[iContour][y].push_back(y1);
746                                 _lstlstlstVecX2[iContour][y].push_back(x2);
747                                 _lstlstlstVecY2[iContour][y].push_back(y2);
748                         } 
749                         x1=x2; y1=y2; z1=z2;
750                 } // for i  Points in spline
751         } // y
752
753 }
754
755 void ContourExtractData::InitLstContoursLinesYPoints()
756 {
757         // init InInside Optimisation  
758         int i;
759
760         _lstlstlstVecX1.clear();
761         _lstlstlstVecY1.clear();
762         _lstlstlstVecX2.clear();
763         _lstlstlstVecY2.clear();
764
765         /* RaC 20-11-09
766         int ext[6];
767         this->imagedata->GetWholeExtent(ext);
768         int sizeY = ext[3]-ext[2]+1;
769         */
770         std::vector<double> vecDouble;
771         std::vector< std::vector<double> > vecVecDouble;
772         for ( i=0 ; i<_sizeImageY ; i++ )
773         {
774                 vecVecDouble.push_back( vecDouble );
775         }
776
777         //Fill structure with points
778         int sizeContours = lstManConMod.size();
779         for( i=0 ; i<sizeContours ; i++ )
780         {
781                 _lstlstlstVecX1.push_back( vecVecDouble );
782                 _lstlstlstVecY1.push_back( vecVecDouble );
783                 _lstlstlstVecX2.push_back( vecVecDouble );
784                 _lstlstlstVecY2.push_back( vecVecDouble );
785                 Fill_lstlstlstVecXY(i,_sizeImageY);
786         }
787
788 }
789
790 void ContourExtractData::SetScalarRange(double min, double max)
791 {
792         scalarRange[0]=min;
793         scalarRange[1]=max;
794 }
795
796 void ContourExtractData::SetSizeImageY(int pSizeImageY)
797 {
798         _sizeImageY=pSizeImageY;
799 }