]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ContourView.cxx
080f484a6e3a930dabbbe31a741fcdcb3759ad65
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ContourView.cxx
1
2
3 #include "ContourView.h"
4
5
6 // ----------------------------------------------------------------------------
7 // ----------------------------------------------------------------------------
8 // ----------------------------------------------------------------------------
9
10 ContourView::ContourView()
11 {
12         _wxvtkbaseview = NULL;
13 }
14
15 // ----------------------------------------------------------------------------
16 ContourView::~ContourView()
17 {
18         DeleteContours();
19 }
20
21 // ----------------------------------------------------------------------------
22 void ContourView::DeleteContours()
23 {
24         DeleteVtkObjects();
25         contour_mapped.clear();
26         contour_actor.clear();
27 }
28
29 // ----------------------------------------------------------------------------
30 void ContourView::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
31 {
32         _wxvtkbaseview = wxvtkbaseview;
33 }
34
35 // ----------------------------------------------------------------------------
36 void ContourView::Refresh()
37 {
38         _wxvtkbaseview->GetRenWin()->Render();
39 }
40
41 // ----------------------------------------------------------------------------
42 void ContourView::CreateNewContour(vtkPolyData *contour, int type)
43 {
44         contour_mapped.push_back(vtkPolyDataMapper::New());
45         contour_mapped.back()->ImmediateModeRenderingOn();
46         contour_mapped.back()->ScalarVisibilityOff( );
47         contour_mapped.back()->SetInput(contour);
48
49         contour_actor.push_back(vtkActor::New());
50         contour_actor.back()->SetMapper(contour_mapped.back());
51         contour_actor.back()->GetProperty()->BackfaceCullingOff();
52         
53         switch (type)
54         {
55         case ContourView::BLUE :        contour_actor.back()->GetProperty()->SetDiffuseColor(0, 0, 1);
56                                                                 break;
57         case ContourView::MAGENTA : contour_actor.back()->GetProperty()->SetDiffuseColor(1, 0, 1);
58                                                                 break;
59         case ContourView::GREEN :       contour_actor.back()->GetProperty()->SetDiffuseColor(0, 1, 0);
60                                                                 break;
61         case ContourView::YELLOW :      contour_actor.back()->GetProperty()->SetDiffuseColor(0, 1, 1);
62                                                                 break;
63         default:                                        contour_actor.back()->GetProperty()->SetDiffuseColor(0, 0, 1);
64
65         }
66         contour_actor.back()->GetProperty()->SetLineWidth(2);
67         contour_actor.back()->ApplyProperties();
68
69         _wxvtkbaseview->GetRenderer()->AddActor(contour_actor.back());
70         _wxvtkbaseview->GetRenWin()->Render();
71 }
72
73 // ----------------------------------------------------------------------------
74 void ContourView::DeleteVtkObjects()
75 {
76         int i,size=contour_mapped.size();
77         for (i=0;i<size; i++){
78                 if ( contour_mapped[i]  != NULL )       { 
79                         contour_mapped[i]  -> Delete(); 
80                 }
81                 if ( contour_actor[i]   != NULL )       { 
82                         _wxvtkbaseview->GetRenderer()->RemoveActor(contour_actor[i]);
83                         contour_actor[i]  -> Delete(); 
84                 }
85                 contour_actor[i] = NULL;
86                 contour_mapped[i] = NULL;
87         }
88 }