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