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