]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoint.cpp
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualViewPoint.cpp
1 #include "manualViewPoint.h"
2
3
4 // ---------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
7
8 //int manualViewPoint::range=1;
9
10
11 manualViewPoint::manualViewPoint(wxVtkBaseView *wxvtkbaseview){
12         _selected                = false;
13         _posibleSelected = false;
14         _pts                     = NULL;
15         _pd                              = NULL;
16         _pointVtkActor   = NULL;
17         _bboxMapper              = NULL;
18         _wxvtkbaseview   = wxvtkbaseview;
19         _spc[0]                  = 1;
20         _spc[1]                  = 1;
21         _spc[2]                  = 1;
22
23         _widthline               = 1;
24
25 }
26 // ----------------------------------------------------------------------------
27 manualViewPoint::~manualViewPoint(){
28         DeleteVtkObjects();
29 }
30
31 // ----------------------------------------------------------------------------
32 void manualViewPoint::SetWidthLine( double width)
33 {
34         _widthline = width;
35 }
36
37 // ----------------------------------------------------------------------------
38 void manualViewPoint::SetSelected(bool selected){
39         _selected=selected;
40 }
41 // ----------------------------------------------------------------------------
42 void manualViewPoint::SetPosibleSelected(bool posibleSelected){
43         _posibleSelected=posibleSelected;
44 }
45 // ----------------------------------------------------------------------------
46 bool manualViewPoint::GetSelected(){
47         return _selected;
48 }
49 // ----------------------------------------------------------------------------
50 bool manualViewPoint::GetPosibleSelected(){
51         return _posibleSelected;
52 }
53 // ----------------------------------------------------------------------------
54 void manualViewPoint::DeleteVtkObjects(){
55         if (_pointVtkActor      !=NULL)         { _pointVtkActor->Delete(); }
56         if (_bboxMapper         !=NULL)         { _bboxMapper   ->Delete();     }
57         if (_pts                        !=NULL)         { _pts                  ->Delete();     }
58         if (_pd                         !=NULL)         { _pd                   ->Delete();     }
59         _pointVtkActor  =       NULL;
60         _bboxMapper             =       NULL;
61         _pts                    =       NULL;
62         _pd                             =       NULL;
63 }
64
65
66
67 // ----------------------------------------------------------------------------
68 vtkActor* manualViewPoint::CreateVtkPointActor()
69 {
70         DeleteVtkObjects();
71
72         _pts = vtkPoints::New();
73         _pts->SetNumberOfPoints(8);
74
75         _pts->SetPoint(0, -1000 , -1000 , 0 );
76         _pts->SetPoint(1,  1000 , -1000 , 0 );
77         _pts->SetPoint(2,  1000 ,  1000 , 0 );
78         _pts->SetPoint(3, -1000 ,  1000 , 0 );
79         _pts->SetPoint(4, -1000 ,  1000 , 0 );
80         _pts->SetPoint(5, -1000 ,  1000 , 0 );
81         _pts->SetPoint(6, -1000 ,  1000 , 0 );
82         _pts->SetPoint(7, -1000 ,  1000 , 0 );
83         
84         vtkCellArray *lines = vtkCellArray::New();
85         lines->InsertNextCell(17);
86         lines->InsertCellPoint(0);
87         lines->InsertCellPoint(1);
88         lines->InsertCellPoint(2);
89         lines->InsertCellPoint(3);
90         lines->InsertCellPoint(0);
91         lines->InsertCellPoint(4);
92         lines->InsertCellPoint(5);
93         lines->InsertCellPoint(6);
94         lines->InsertCellPoint(7);
95         lines->InsertCellPoint(4);
96         lines->InsertCellPoint(0);
97         lines->InsertCellPoint(3);
98         lines->InsertCellPoint(7);
99         lines->InsertCellPoint(6);
100         lines->InsertCellPoint(2);
101         lines->InsertCellPoint(1);
102         lines->InsertCellPoint(5);
103
104         _pd = vtkPolyData::New();
105         _pd->SetPoints( _pts );
106         _pd->SetLines( lines );
107 //      lines->Delete();  //do not delete lines ??
108
109         _pointVtkActor  =       vtkActor::New();
110     _bboxMapper         =       vtkPolyDataMapper::New();
111
112         _bboxMapper->SetInput(_pd);
113 //      _bboxMapper->ImmediateModeRenderingOn();
114         _pointVtkActor->SetMapper(_bboxMapper);
115 //      _pointVtkActor->GetProperty()->BackfaceCullingOn();
116         UpdateColorActor();
117 //      _pd->ComputeBounds();
118
119         return _pointVtkActor;
120 }
121 // ----------------------------------------------------------------------------
122 vtkActor* manualViewPoint::GetVtkActor(){
123         return _pointVtkActor;
124 }
125 // ----------------------------------------------------------------------------
126 void manualViewPoint::SetPositionXY(double x, double y,double i_range,double posZ)
127 {
128 //      double range=0.2; // i_range;
129 //      double range=(double)manualViewPoint::range;
130
131         double range=i_range;
132
133 //EED 27 sep 2006
134         x        = x * _spc[0];
135         y        = y * _spc[1];
136         posZ = posZ * _spc[2];
137
138         if (_pts!=NULL){
139                 _pts->SetPoint(0, x-range, y+range, posZ-range);
140                 _pts->SetPoint(1, x+range, y+range, posZ-range);
141                 _pts->SetPoint(2, x+range, y-range, posZ-range);
142                 _pts->SetPoint(3, x-range, y-range, posZ-range);
143                 _pts->SetPoint(4, x-range, y+range, posZ+range);
144                 _pts->SetPoint(5, x+range, y+range, posZ+range);
145                 _pts->SetPoint(6, x+range, y-range, posZ+range);
146                 _pts->SetPoint(7, x-range, y-range, posZ+range);
147         }
148 }
149
150
151 // ----------------------------------------------------------------------------
152 void manualViewPoint::UpdateColorActor()
153 {
154         if (_pointVtkActor!=NULL){
155 //EED03
156                 _pointVtkActor->GetProperty()->SetLineWidth( _widthline );
157                 _pointVtkActor->GetProperty()->SetDiffuseColor(1,0,0);
158                 if (_posibleSelected==true){
159                         _pointVtkActor->GetProperty()->SetDiffuseColor(1,1,0);
160                 }
161         }
162 }
163 // ----------------------------------------------------------------------------
164 void manualViewPoint::GetSpacing(double spc[3])
165 {
166         spc[0] = _spc[0];
167         spc[1] = _spc[1];
168         spc[2] = _spc[2];
169 }
170 // ----------------------------------------------------------------------------
171 void manualViewPoint::SetSpacing(double spc[3])
172 {
173         _spc[0] = spc[0];
174         _spc[1] = spc[1];
175         _spc[2] = spc[2];
176 }
177