]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/LineView.cxx
#3404 creaMaracasVisu Feature New Normal - vtk8itk5wx3-macos
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / LineView.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 "LineView.h"
29
30
31
32
33 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
36 LineView::LineView()
37 {
38         _wxvtkbaseview = NULL;
39 }
40
41 // ----------------------------------------------------------------------------
42 LineView::~LineView()
43 {
44         DeleteLines();
45 }
46
47 // ----------------------------------------------------------------------------
48 void LineView::DeleteLines() 
49 {
50         DeleteVtkObjects();
51         contour_mapped.clear();
52         contour_actor.clear();
53 }
54
55 // ----------------------------------------------------------------------------
56 void LineView::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
57 {
58         _wxvtkbaseview = wxvtkbaseview;
59 }
60
61 // ----------------------------------------------------------------------------
62 void LineView::Refresh()
63 {
64         _wxvtkbaseview->GetRenWin()->Render();
65 }
66
67 // ----------------------------------------------------------------------------
68 void LineView::CreateNewLine(double x1, double y1, double z1, double x2, double y2, double z2)
69 {
70
71         vtkPoints*  pointsLine = vtkPoints::New();
72         vtkPolyLine* aLine = vtkPolyLine::New();
73         vtkUnstructuredGrid* aLineGrid = vtkUnstructuredGrid::New();
74         contour_mapped.push_back(vtkDataSetMapper::New());
75         contour_actor.push_back(vtkActor::New());
76
77     pointsLine->SetNumberOfPoints(2);
78         pointsLine->InsertPoint(0,x1,y1,z1);
79         pointsLine->InsertPoint(1,x2,y2,z2);
80
81         (aLine->GetPointIds())->SetNumberOfIds(2);
82         (aLine->GetPointIds())->SetId(0,0);
83         (aLine->GetPointIds())->SetId(1,1);
84
85         aLineGrid->Allocate(1,1);
86         aLineGrid->InsertNextCell(aLine->GetCellType(),aLine->GetPointIds());
87         aLineGrid->SetPoints(pointsLine);
88         
89 //EED 2017-01-01 Migration VTK7
90 #if VTK_MAJOR_VERSION <= 5
91         contour_mapped.back()->SetInput(aLineGrid);
92         contour_mapped.back()->ImmediateModeRenderingOn();
93 #else
94         contour_mapped.back()->SetInputData(aLineGrid);
95 #endif
96
97
98         contour_actor.back()->SetMapper(contour_mapped.back());
99         contour_actor.back()->GetProperty()->BackfaceCullingOn();
100         contour_actor.back()->GetProperty()->SetDiffuseColor(0, 0, 1);
101         contour_actor.back()->ApplyProperties();
102
103         _wxvtkbaseview->GetRenderer()->AddActor(contour_actor.back());
104         _wxvtkbaseview->GetRenWin()->Render();
105
106 }
107
108 // ----------------------------------------------------------------------------
109 void LineView::DeleteVtkObjects()
110 {
111         int i,size=contour_mapped.size();
112         for (i=0;i<size; i++){
113                 if ( contour_mapped[i]  != NULL )       { 
114                         contour_mapped[i]  -> Delete(); 
115                 }
116                 if ( contour_actor[i]   != NULL )       { 
117                         _wxvtkbaseview->GetRenderer()->RemoveActor(contour_actor[i]);
118                         contour_actor[i]  -> Delete(); 
119                 }
120                 contour_actor[i] = NULL;
121                 contour_mapped[i] = NULL;
122         }
123 }
124