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