]> Creatis software - creaMaracasVisu.git/blob
e69f291a93eaf64d38285f4fbbd8dcdd490c13d7
[creaMaracasVisu.git] /
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 /**
27  *  \file 
28  *  \author Eduardo Davila and Claire Mouton.
29  *  \brief Class bbtk::ThresholdImageView. 
30  *  \date September 2012
31  */
32
33 #include "ColorLayerImageViewManager.h"
34
35
36
37 //=========================================================================
38 //=========================================================================
39 //=========================================================================
40 //=========================================================================
41 ColorLayerImageViewManager::ColorLayerImageViewManager( )
42 {
43     _active         = true;
44     _fitting_mode   = 3;
45         _colorLayerImageViewLst.push_back(NULL);  // 0
46         _colorLayerImageViewLst.push_back(NULL);  // 1
47         _colorLayerImageViewLst.push_back(NULL);  // 2
48 }
49
50 //=========================================================================
51 ColorLayerImageViewManager::~ColorLayerImageViewManager()
52 {
53 }
54 //=========================================================================
55
56 //----------------------------------------------------------------------------
57 void ColorLayerImageViewManager::ResetRefresh()
58 {
59     int i,size =_colorLayerImageViewLst.size();
60     for ( i=0 ; i<size ; i++ )
61     {
62         printf("EED ColorLayerImageViewManager::ResetRefresh 1 %p \n", _colorLayerImageViewLst[i] );
63         if ( _colorLayerImageViewLst[i] !=NULL )
64         {
65             _colorLayerImageViewLst[i]->ResetRefresh();
66         }
67         printf("EED ColorLayerImageViewManager::ResetRefresh 2 \n");
68     } // for i
69 }
70
71 //----------------------------------------------------------------------------
72 void ColorLayerImageViewManager::SetwxVtkBaseView(int id, wxVtkBaseView *baseview)
73 {
74   if (baseview!=NULL)
75   {     
76         int size =_colorLayerImageViewLst.size();
77         if (   (id>=0) && (id<=size) )
78         {
79             if (_colorLayerImageViewLst[id]==NULL)
80             {
81                         _colorLayerImageViewLst[id] = new ColorLayerImageView();
82             }
83                 _colorLayerImageViewLst[id]->SetwxVtkBaseView(baseview);
84         
85         } // if id
86   } // baseview
87 }
88
89
90 wxVtkBaseView*  ColorLayerImageViewManager::GetwxVtkBaseView(int id)
91 {
92         return _colorLayerImageViewLst[id]->GetwxVtkBaseView();
93 }
94
95
96 //----------------------------------------------------------------------------
97 void ColorLayerImageViewManager::SetX2(int x2)  
98 {
99   int i, size=_colorLayerImageViewLst.size();
100   for (i=0;i<size;i++)
101   {
102         if (_colorLayerImageViewLst[i]!=NULL)
103         {
104            _colorLayerImageViewLst[i]->SetX2( x2 );
105         } // if 
106   } // for 
107 }
108
109 //----------------------------------------------------------------------------
110 void ColorLayerImageViewManager::SetY2(int y2)  
111 {
112   int i, size=_colorLayerImageViewLst.size();
113   for (i=0;i<size;i++)
114   {
115         if (_colorLayerImageViewLst[i]!=NULL)
116         {
117            _colorLayerImageViewLst[i]->SetY2( y2 );
118         } // if 
119   } // for 
120
121 }
122
123 //----------------------------------------------------------------------------
124 void ColorLayerImageViewManager::SetZ2(int z2)  
125 {
126   int i, size=_colorLayerImageViewLst.size();
127   for (i=0;i<size;i++)
128   {
129         if (_colorLayerImageViewLst[i]!=NULL)
130         {
131            _colorLayerImageViewLst[i]->SetZ2( z2 );
132         } // if 
133   } // for 
134
135 }
136
137
138
139 //----------------------------------------------------------------------------
140 int ColorLayerImageViewManager::GetX()
141 {
142   int result;
143   int i, size=_colorLayerImageViewLst.size();
144   for (i=0;i<size;i++)
145   {
146         if (_colorLayerImageViewLst[i]!=NULL)
147         {
148            result = _colorLayerImageViewLst[i]->GetX();
149         } // if 
150   } // for 
151   return result;
152 }
153
154 //----------------------------------------------------------------------------
155 int ColorLayerImageViewManager::GetY()
156 {
157   int result;
158   int i, size=_colorLayerImageViewLst.size();
159   for (i=0;i<size;i++)
160   {
161         if (_colorLayerImageViewLst[i]!=NULL)
162         {
163            result = _colorLayerImageViewLst[i]->GetY();
164         } // if 
165   } // for 
166   return result;
167 }
168
169
170
171 //----------------------------------------------------------------------------
172 int ColorLayerImageViewManager::GetZ() // virtual 
173 {
174   int result;
175   int i, size=_colorLayerImageViewLst.size();
176   for (i=0;i<size;i++)
177   {
178         if (_colorLayerImageViewLst[i]!=NULL)
179         {
180            result = _colorLayerImageViewLst[i]->GetZ();
181         } // if 
182   } // for 
183   return result;
184 }
185
186 //----------------------------------------------------------------------------
187 void ColorLayerImageViewManager::SetBaseColors(std::vector<double> & base_color)
188 {
189   int i, size=_colorLayerImageViewLst.size();
190   for (i=0;i<size;i++)
191   {
192         if (_colorLayerImageViewLst[i]!=NULL)
193         {
194            _colorLayerImageViewLst[i]->SetBaseColors( base_color );
195         } // if 
196   } // for 
197 }
198
199 //----------------------------------------------------------------------------
200 void ColorLayerImageViewManager::SetBaseTransparence(std::vector<double> & base_transparence)
201 {
202   int i, size=_colorLayerImageViewLst.size();
203   for (i=0;i<size;i++)
204   {
205         if (_colorLayerImageViewLst[i]!=NULL)
206         {
207            _colorLayerImageViewLst[i]->SetBaseTransparence( base_transparence );
208         } // if 
209   } // for 
210 }
211
212 //----------------------------------------------------------------------------
213 void ColorLayerImageViewManager::SetRangeForColorBar(std::vector<double> &range)
214 {
215   int i, size=_colorLayerImageViewLst.size();
216   for (i=0;i<size;i++)
217   {
218         if (_colorLayerImageViewLst[i]!=NULL)
219         {
220            _colorLayerImageViewLst[i]->SetRangeForColorBar( range );
221         } // if 
222   } // for 
223 }
224
225 //----------------------------------------------------------------------------
226 void ColorLayerImageViewManager::SetColorBarPosition(std::vector<int> &colorbarposition)
227 {
228   int i, size=_colorLayerImageViewLst.size();
229   for (i=0;i<size;i++)
230   {
231         if (_colorLayerImageViewLst[i]!=NULL)
232         {
233            _colorLayerImageViewLst[i]->SetColorBarPosition( colorbarposition );
234         } // if 
235   } // for 
236 }
237
238
239
240
241 //----------------------------------------------------------------------------
242 double ColorLayerImageViewManager::GetBaseColors(unsigned int index)
243 {
244   double result;
245   int i, size=_colorLayerImageViewLst.size();
246   for (i=0;i<size;i++)
247   {
248         if (_colorLayerImageViewLst[i]!=NULL)
249         {
250            result = _colorLayerImageViewLst[i]->GetBaseColors( index );
251         } // if 
252   } // for 
253   return result;
254 }
255
256 //----------------------------------------------------------------------------
257 void ColorLayerImageViewManager::SetGreyLevelBoundaries(std::vector<double> & grey_level_boundary)
258 {
259   int i, size=_colorLayerImageViewLst.size();
260   for (i=0;i<size;i++)
261   {
262         if (_colorLayerImageViewLst[i]!=NULL)
263         {
264            _colorLayerImageViewLst[i]->SetGreyLevelBoundaries( grey_level_boundary );
265         } // if 
266   } // for 
267 }
268
269 //----------------------------------------------------------------------------
270 double ColorLayerImageViewManager::GetGreyLevelBoundaries(unsigned int index)
271 {  
272   double result;
273   int i, size=_colorLayerImageViewLst.size();
274   for (i=0;i<size;i++)
275   {
276         if (_colorLayerImageViewLst[i]!=NULL)
277         {
278            result = _colorLayerImageViewLst[i]->GetGreyLevelBoundaries( index );
279         } // if 
280   } // for 
281   return result;
282 }
283
284 //----------------------------------------------------------------------------
285 void ColorLayerImageViewManager::SetPlainOrGradientColor(bool color_type)
286 {
287   int i, size=_colorLayerImageViewLst.size();
288   for (i=0;i<size;i++)
289   {
290         if (_colorLayerImageViewLst[i]!=NULL)
291         {
292            _colorLayerImageViewLst[i]->SetPlainOrGradientColor( color_type );
293         } // if 
294   } // for 
295
296
297 //----------------------------------------------------------------------------
298 int ColorLayerImageViewManager::GetBaseColorNb()
299 {
300   int result;
301   int i, size=_colorLayerImageViewLst.size();
302   for (i=0;i<size;i++)
303   {
304         if (_colorLayerImageViewLst[i]!=NULL)
305         {
306            result = _colorLayerImageViewLst[i]->GetBaseColorNb();
307         } // if 
308   } // for 
309   return result;
310 }
311
312 //----------------------------------------------------------------------------
313 void ColorLayerImageViewManager::Refresh()
314 {
315   int i, size=_colorLayerImageViewLst.size();
316   for (i=0;i<size;i++)
317   {
318         if (_colorLayerImageViewLst[i]!=NULL)
319         {
320            _colorLayerImageViewLst[i]->Refresh();
321         } // if 
322   } // for 
323 }
324
325 //----------------------------------------------------------------------------
326 void ColorLayerImageViewManager::onThreshold()
327 {
328   int i, size=_colorLayerImageViewLst.size();
329   for (i=0;i<size;i++)
330   {
331         if (_colorLayerImageViewLst[i]!=NULL)
332         {
333            _colorLayerImageViewLst[i]->onThreshold();
334         } // if 
335   } // for 
336 }
337
338 //----------------------------------------------------------------------------
339 void ColorLayerImageViewManager::onThresholdChange()
340 {
341   int i, size=_colorLayerImageViewLst.size();
342   for (i=0;i<size;i++)
343   {
344         if (_colorLayerImageViewLst[i]!=NULL)
345         {
346            _colorLayerImageViewLst[i]->onThresholdChange();
347         } // if 
348   } // for 
349 }
350
351 //----------------------------------------------------------------------------
352 void ColorLayerImageViewManager::onThresholdRemove()
353 {
354   int i, size=_colorLayerImageViewLst.size();
355   for (i=0;i<size;i++)
356   {
357         if (_colorLayerImageViewLst[i]!=NULL)
358         {
359            _colorLayerImageViewLst[i]->onThresholdRemove();
360         } // if 
361   } // for 
362 }
363
364 //----------------------------------------------------------------------------
365 void ColorLayerImageViewManager::onThresholdInterpolation(bool interpolation)
366 {
367   int i, size=_colorLayerImageViewLst.size();
368   for (i=0;i<size;i++)
369   {
370         if (_colorLayerImageViewLst[i]!=NULL)
371         {
372            _colorLayerImageViewLst[i]->onThresholdInterpolation( interpolation );
373         } // if 
374   } // for 
375 }
376
377 //----------------------------------------------------------------------------
378 void ColorLayerImageViewManager::SetSliceFixDynamic( bool fixdyn )
379 {
380   int i, size=_colorLayerImageViewLst.size();
381   for (i=0;i<size;i++)
382   {
383         if (_colorLayerImageViewLst[i]!=NULL)
384         {
385            _colorLayerImageViewLst[i]->SetSliceFixDynamic( fixdyn );
386         } // if 
387   } // for 
388 }
389
390 //----------------------------------------------------------------------------
391 void ColorLayerImageViewManager::onThresholdChangeOpacity( int opacity)
392 {
393   int i, size=_colorLayerImageViewLst.size();
394   for (i=0;i<size;i++)
395   {
396         if (_colorLayerImageViewLst[i]!=NULL)
397         {
398            _colorLayerImageViewLst[i]->onThresholdChangeOpacity( opacity );
399         } // if 
400   } // for 
401 }
402
403 //----------------------------------------------------------------------------
404 void ColorLayerImageViewManager::SetImageStep1(  vtkImageData* img  )
405 {
406     int i, size=_colorLayerImageViewLst.size();
407     for (i=0;i<size;i++)
408     {
409         if (_colorLayerImageViewLst[i]!=NULL)
410         {
411             _colorLayerImageViewLst[i]->SetImage( img );
412         } // if
413     } // for i
414 }
415
416 //----------------------------------------------------------------------------
417 void ColorLayerImageViewManager::SetImageStep2(  vtkImageData* img  )
418 {
419         if (img!=NULL)
420         {
421 //            if (_histogramMinMaxLevel!=NULL)
422 //            {
423 //                _histogramMinMaxLevel->Configure( img );
424 //            }
425 //            _colorLayerImageViewManager->SetImage( img );
426             double      spcOriginalLayer[3];
427             int         dimensionOriginalLayer[3];
428             double      spcBase[3];
429             int         dimensionBase[3];
430             double      newSpc[3];
431             this->GetSpcOriginalLayer(0,spcOriginalLayer);
432             this->GetDimensionOriginalLayer(0,dimensionOriginalLayer);
433             this->GetSpcBase(0,spcBase);
434             this->GetDimensionBase(0,dimensionBase);
435 //            if (_sl_SliceImageX!=NULL)
436 //            {
437 //                _sl_SliceImageX->SetRange( 0 , dimensionOriginalLayer[0] );
438 //                _sl_SliceImageY->SetRange( 0 , dimensionOriginalLayer[1] );
439 //                _sl_SliceImageZ->SetRange( 0 , dimensionOriginalLayer[2] );
440 //            }
441
442             if (     (spcOriginalLayer[0]!=spcBase[0]) ||
443                     (spcOriginalLayer[1]!=spcBase[1]) ||
444                     (spcOriginalLayer[2]!=spcBase[2]) ||
445                      (dimensionOriginalLayer[0]!=dimensionBase[0]) ||
446                     (dimensionOriginalLayer[1]!=dimensionBase[1]) ||
447                     (dimensionOriginalLayer[2]!=dimensionBase[2])
448                 )
449             {
450                    // CM
451                   int typeOfTransformation = _fitting_mode;
452 //                  // In case of the option is set to create a dialog box.
453 //                  if (_fitting_mode == -1)
454 //                  {
455 //                    bool transformOkDlg;
456 //                    wxString msg = _T("The image resolution of both images are not compatible. How do you want to tranform it? ");
457 //                    wxDlgTransformByDimensionBySpacingByPixel dlg;
458 //                    dlg.GetTransformType(this , spcBase , spcOriginalLayer , dimensionBase ,dimensionOriginalLayer ,msg,typeOfTransformation,transformOkDlg);
459 //                    // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
460 //                    if (transformOkDlg == false)
461 //                    {
462 //                        typeOfTransformation = 3;
463 //                    }
464 //                   } else {
465 //                    typeOfTransformation = _fitting_mode;
466 //                  } // _fitting_mode -1
467
468                   //EO CM
469                 if (typeOfTransformation == 1)  // Adapt spacing
470                 {
471                     newSpc[0] = spcBase[0] * dimensionBase[0] / dimensionOriginalLayer[0];
472                     newSpc[1] = spcBase[1] * dimensionBase[1] / dimensionOriginalLayer[1];
473                     newSpc[2] = spcBase[2] * dimensionBase[2] / dimensionOriginalLayer[2];
474                 }
475
476                 if (typeOfTransformation == 2)  // keep spacing of the Layer Image
477                 {
478                     newSpc[0] = spcOriginalLayer[0];
479                     newSpc[1] = spcOriginalLayer[1];
480                     newSpc[2] = spcOriginalLayer[2];
481                 }
482
483                 if (typeOfTransformation == 3)  // Use the spacing of the Base Image
484                 {
485                     newSpc[0] = spcBase[0];
486                     newSpc[1] = spcBase[1];
487                     newSpc[2] = spcBase[2];
488                 }
489                 this->SetNewSpacingLayer(newSpc);
490             } else {
491                     newSpc[0] = spcOriginalLayer[0];
492                     newSpc[1] = spcOriginalLayer[1];
493                     newSpc[2] = spcOriginalLayer[2];
494             } // spc !_spcBase   dim!__dimBase
495             this->SetNewSpacingLayer(newSpc);
496         } // img
497
498     if (_active==true)
499     {
500         this->onThreshold();
501         if (img==NULL)
502         {
503             this->onThresholdRemove( );
504         } // img
505         this->Refresh();
506     } // _active
507 }
508
509 //----------------------------------------------------------------------------
510 vtkImageData* ColorLayerImageViewManager::GetImageChangeInformation(int id)
511 {
512         if (_colorLayerImageViewLst[id]!=NULL)
513         {
514            return _colorLayerImageViewLst[id]->GetImage( );
515         } // if 
516         return NULL;
517 }
518
519 //----------------------------------------------------------------------------
520 vtkLookupTable* ColorLayerImageViewManager::GetLookupTable(int id)
521 {
522         if (_colorLayerImageViewLst[id]!=NULL)
523         {
524            return _colorLayerImageViewLst[id]->GetThresholdTable( );
525         } // if 
526         return NULL;
527 }
528
529 //----------------------------------------------------------------------------
530 void ColorLayerImageViewManager::GetDimensionBase(int id,int *dim)
531 {
532         if (_colorLayerImageViewLst[id]!=NULL)
533         {
534            _colorLayerImageViewLst[id]->GetDimensionBase( dim );
535         } // if 
536 }
537
538 //----------------------------------------------------------------------------
539 void ColorLayerImageViewManager::GetSpcBase(int id,double *spc)
540 {
541         if (_colorLayerImageViewLst[id]!=NULL)
542         {
543            _colorLayerImageViewLst[id]->GetSpcBase( spc );
544         } // if 
545 }
546
547 //----------------------------------------------------------------------------
548 void ColorLayerImageViewManager::GetDimensionOriginalLayer(int id,int *dim)
549 {
550         if (_colorLayerImageViewLst[id]!=NULL)
551         {
552            _colorLayerImageViewLst[id]->GetDimensionOriginalLayer( dim );
553         } // if 
554 }
555
556 //----------------------------------------------------------------------------
557 void ColorLayerImageViewManager::GetSpcOriginalLayer(int id,double *spc)
558 {
559         if (_colorLayerImageViewLst[id]!=NULL)
560         {
561            _colorLayerImageViewLst[id]->GetSpcOriginalLayer( spc );
562         } // if 
563 }
564
565 //----------------------------------------------------------------------------
566 void ColorLayerImageViewManager::SetNewSpacingLayer(double *spc)
567 {
568   int i, size=_colorLayerImageViewLst.size();
569   for (i=0;i<size;i++)
570   {
571         if (_colorLayerImageViewLst[i]!=NULL)
572         {
573            _colorLayerImageViewLst[i]->SetNewSpacingLayer( spc );
574         } // if 
575   } // for 
576 }
577
578 //----------------------------------------------------------------------------
579 void ColorLayerImageViewManager::SetActive(bool active)
580 {
581     _active = active;
582 }
583
584 //----------------------------------------------------------------------------
585 bool ColorLayerImageViewManager::GetActive()
586 {
587     return _active;
588 }
589
590 //----------------------------------------------------------------------------
591 void ColorLayerImageViewManager::SetFittingMode( int fitting_mode )
592 {
593     _fitting_mode = fitting_mode;
594 }
595
596 //----------------------------------------------------------------------------
597 int ColorLayerImageViewManager::GetFittingMode()
598 {
599     return _fitting_mode;
600 }
601
602
603 // EOF
604