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