]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ContourView.cxx
#3404 creaMaracasVisu Feature New Normal - vtk8itk5wx3-macos
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ContourView.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
28 #include "ContourView.h"
29
30
31 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
34
35 ContourView::ContourView()
36 {
37         _wxvtkbaseview = NULL;
38 }
39
40 // ----------------------------------------------------------------------------
41 ContourView::~ContourView()
42 {
43         DeleteContours();
44 }
45
46 // ----------------------------------------------------------------------------
47 void ContourView::DeleteContours()
48 {
49         DeleteVtkObjects();
50         contour_mapped.clear();
51         contour_actor.clear();
52 }
53
54 // ----------------------------------------------------------------------------
55 void ContourView::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
56 {
57         _wxvtkbaseview = wxvtkbaseview;
58 }
59
60 // ----------------------------------------------------------------------------
61 void ContourView::Refresh()
62 {
63         _wxvtkbaseview->GetRenWin()->Render();
64 }
65
66 // ----------------------------------------------------------------------------
67 void ContourView::CreateNewContour(vtkPolyData *contour, int type)
68 {
69         contour_mapped.push_back(vtkPolyDataMapper::New());
70         contour_mapped.back()->ScalarVisibilityOff( );
71
72
73 //EED 2017-01-01 Migration VTK7
74 #if VTK_MAJOR_VERSION <= 5
75         contour_mapped.back()->ImmediateModeRenderingOn();
76         contour_mapped.back()->SetInput(contour);
77 #else
78         contour_mapped.back()->SetInputData(contour);
79 #endif
80
81
82         contour_actor.push_back(vtkActor::New());
83         contour_actor.back()->SetMapper(contour_mapped.back());
84         contour_actor.back()->GetProperty()->BackfaceCullingOff();
85         
86         switch (type)
87         {
88         case ContourView::BLUE :        contour_actor.back()->GetProperty()->SetDiffuseColor(0, 0, 1);
89                                                                 break;
90         case ContourView::MAGENTA : contour_actor.back()->GetProperty()->SetDiffuseColor(1, 0, 1);
91                                                                 break;
92         case ContourView::GREEN :       contour_actor.back()->GetProperty()->SetDiffuseColor(0, 1, 0);
93                                                                 break;
94         case ContourView::YELLOW :      contour_actor.back()->GetProperty()->SetDiffuseColor(0, 1, 1);
95                                                                 break;
96         default:                                        contour_actor.back()->GetProperty()->SetDiffuseColor(0, 0, 1);
97
98         }
99         contour_actor.back()->GetProperty()->SetLineWidth(2);
100         contour_actor.back()->ApplyProperties();
101
102         _wxvtkbaseview->GetRenderer()->AddActor(contour_actor.back());
103         _wxvtkbaseview->GetRenWin()->Render();
104 }
105
106 // ----------------------------------------------------------------------------
107 void ContourView::DeleteVtkObjects()
108 {
109         int i,size=contour_mapped.size();
110         for (i=0;i<size; i++){
111                 if ( contour_mapped[i]  != NULL )       { 
112                         contour_mapped[i]  -> Delete(); 
113                 }
114                 if ( contour_actor[i]   != NULL )       { 
115                         _wxvtkbaseview->GetRenderer()->RemoveActor(contour_actor[i]);
116                         contour_actor[i]  -> Delete(); 
117                 }
118                 contour_actor[i] = NULL;
119                 contour_mapped[i] = NULL;
120         }
121 }