]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/LineView.cxx
f8060a731f83f8915a52a17af89d2443a3431851
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / LineView.cxx
1
2
3 #include "LineView.h"
4
5
6
7
8 // ----------------------------------------------------------------------------
9 // ----------------------------------------------------------------------------
10 // ----------------------------------------------------------------------------
11 LineView::LineView()
12 {
13         _wxvtkbaseview = NULL;
14 }
15
16 // ----------------------------------------------------------------------------
17 LineView::~LineView()
18 {
19         DeleteLines();
20 }
21
22 // ----------------------------------------------------------------------------
23 void LineView::DeleteLines() 
24 {
25         DeleteVtkObjects();
26         contour_mapped.clear();
27         contour_actor.clear();
28 }
29
30 // ----------------------------------------------------------------------------
31 void LineView::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
32 {
33         _wxvtkbaseview = wxvtkbaseview;
34 }
35
36 // ----------------------------------------------------------------------------
37 void LineView::Refresh()
38 {
39         _wxvtkbaseview->GetRenWin()->Render();
40 }
41
42 // ----------------------------------------------------------------------------
43 void LineView::CreateNewLine(double x1, double y1, double z1, double x2, double y2, double z2)
44 {
45
46         vtkPoints*  pointsLine = vtkPoints::New();
47         vtkPolyLine* aLine = vtkPolyLine::New();
48         vtkUnstructuredGrid* aLineGrid = vtkUnstructuredGrid::New();
49         contour_mapped.push_back(vtkDataSetMapper::New());
50         contour_actor.push_back(vtkActor::New());
51
52     pointsLine->SetNumberOfPoints(2);
53         pointsLine->InsertPoint(0,x1,y1,z1);
54         pointsLine->InsertPoint(1,x2,y2,z2);
55
56         (aLine->GetPointIds())->SetNumberOfIds(2);
57         (aLine->GetPointIds())->SetId(0,0);
58         (aLine->GetPointIds())->SetId(1,1);
59
60         aLineGrid->Allocate(1,1);
61         aLineGrid->InsertNextCell(aLine->GetCellType(),aLine->GetPointIds());
62         aLineGrid->SetPoints(pointsLine);
63
64         
65         contour_mapped.back()->SetInput(aLineGrid);
66         contour_mapped.back()->ImmediateModeRenderingOn();
67
68         contour_actor.back()->SetMapper(contour_mapped.back());
69         contour_actor.back()->GetProperty()->BackfaceCullingOn();
70         contour_actor.back()->GetProperty()->SetDiffuseColor(0, 0, 1);
71         contour_actor.back()->ApplyProperties();
72
73         _wxvtkbaseview->GetRenderer()->AddActor(contour_actor.back());
74         _wxvtkbaseview->GetRenWin()->Render();
75
76 }
77
78 // ----------------------------------------------------------------------------
79 void LineView::DeleteVtkObjects()
80 {
81         int i,size=contour_mapped.size();
82         for (i=0;i<size; i++){
83                 if ( contour_mapped[i]  != NULL )       { 
84                         contour_mapped[i]  -> Delete(); 
85                 }
86                 if ( contour_actor[i]   != NULL )       { 
87                         _wxvtkbaseview->GetRenderer()->RemoveActor(contour_actor[i]);
88                         contour_actor[i]  -> Delete(); 
89                 }
90                 contour_actor[i] = NULL;
91                 contour_mapped[i] = NULL;
92         }
93 }
94