]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualRoiControler.cpp
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualRoiControler.cpp
1 #include "manualRoiControler.h"
2
3 // ----------------------------------------------------------------------------
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6
7 // _state = 0  // ..nothing..
8 // _state = 5  // move point
9 // _state = 6  // move all
10 // _state = 7  // Empty mouse drag
11
12 manualRoiControler::manualRoiControler()
13 {
14 }
15 // ----------------------------------------------------------------------------
16 manualRoiControler::~manualRoiControler()
17 {
18 }
19 // ----------------------------------------------------------------------------
20 manualRoiControler * manualRoiControler :: Clone()  // virtual
21 {
22         manualRoiControler * clone = new manualRoiControler();
23         CopyAttributesTo(clone);
24         return clone;
25 }
26
27 // ---------------------------------------------------------------------------
28 void manualRoiControler::CopyAttributesTo( manualRoiControler * cloneObject)
29 {
30         // Fathers object
31         manualContourBaseControler::CopyAttributesTo(cloneObject);
32 }
33
34 // ----------------------------------------------------------------------------
35 void manualRoiControler::Configure() //virtual
36 {
37         this->GetManualContourModel()->SetNumberOfPointsSpline(5);
38 }
39
40 // ----------------------------------------------------------------------------
41
42 void manualRoiControler::MouseClickLeft(int x, int y){
43         int z = GetZ();
44         
45         if( IsEditable() )
46         {       // move control point
47           if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) ){
48                   bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
49                   SetState(5);
50           }
51         } // IsEditable
52         
53         // Move contour
54         if ((GetState()==0) && (GetManualViewBaseContour()->GetPosibleSelected()==true))        {
55                 GetManualViewBaseContour()->InitMove(x,y,z);
56                 SetState(6);
57         }
58         
59         // if the firs time create 4 control points and move one point
60         int size=GetManualViewBaseContour()->GetNumberOfPoints();
61         if (GetState()==0) {
62                 if (size==0){
63                         AddPoint(x,y,z);
64                         AddPoint(x,y,z);
65                         AddPoint(x,y,z);
66                         AddPoint(x,y,z);
67                         bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
68                         SetState(1);
69                 }
70         }
71         
72 /*EED 21 Avril 2009
73         if (GetState()==0) {
74                 if (size==0){
75                         AddPoint(x,y,z);
76                         AddPoint(x,y,z);
77                         AddPoint(x,y,z);
78                         AddPoint(x,y,z);
79                 } else {
80                         SetPoint(0,x,y,z);
81                         SetPoint(1,x,y,z);
82                         SetPoint(2,x,y,z);
83                         SetPoint(3,x,y,z);
84                 }
85                 bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
86                 SetState(5);
87         }
88 */
89         
90         GetManualViewBaseContour()->Refresh();
91 }
92
93 // ----------------------------------------------------------------------------
94 void manualRoiControler::MouseMove(int x, int y) // virtual
95 {
96         int z=GetZ();
97
98 //      this->_vtkInteractorStyleBaseView->
99
100                    
101         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
102         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
103
104
105         if ( (GetState()==5) || (GetState()==1) ){
106                 SetPoint( bakIdPoint , x , y ,z);
107                 if (bakIdPoint==0)
108                 {
109                         SetPointX( 1 , x );
110                         SetPointY( 3 , y );
111                 }
112                 if (bakIdPoint==1)
113                 {
114                         SetPointX( 0 , x );
115                         SetPointY( 2 , y );
116                 }
117                 if (bakIdPoint==2)
118                 {
119                         SetPointX( 3 , x );
120                         SetPointY( 1 , y );
121                 }
122                 if (bakIdPoint==3)
123                 {
124                         SetPointX( 2 , x );
125                         SetPointY( 0 , y );
126                 }
127         }
128         if (GetState()==6){
129                 GetManualViewBaseContour()->MoveContour(x,y,z);
130         }
131         GetManualViewBaseContour()->Refresh();
132 }
133 // ----------------------------------------------------------------------------
134 void manualRoiControler::DeleteActualMousePoint(int x, int y)  // virtual
135 {
136 }
137 // ----------------------------------------------------------------------------
138 void manualRoiControler::InitRoi(int ww, int hh, double porcentage)
139 {
140         int zz;
141         manualPoint *mp;
142
143         if (GetManualContourModel()->GetSizeLstPoints() ==0)
144         {
145                 zz = GetZ();
146                 AddPoint(0,0,zz);
147                 AddPoint(0,0,zz);
148                 AddPoint(0,0,zz);
149                 AddPoint(0,0,zz);
150         }
151
152         double pp1=porcentage;
153         double pp2=1-porcentage;
154
155         mp = GetManualContourModel()->GetManualPoint(2);
156         zz=(int)mp->GetZ();
157         mp->SetPoint(ww*pp1,hh*pp1,zz);
158
159         mp = GetManualContourModel()->GetManualPoint(1);
160         zz=(int)mp->GetZ();
161         mp->SetPoint(ww*pp2,hh*pp1,zz);
162
163         mp = GetManualContourModel()->GetManualPoint(0);
164         zz=(int)mp->GetZ();
165         mp->SetPoint(ww*pp2,hh*pp2,zz);
166
167         mp = GetManualContourModel()->GetManualPoint(3);
168         zz=(int)mp->GetZ();
169         mp->SetPoint(ww*pp1,hh*pp2,zz);
170
171         GetManualViewBaseContour() ->UpdateViewPoint(0);
172         GetManualViewBaseContour() ->UpdateViewPoint(1);
173         GetManualViewBaseContour() ->UpdateViewPoint(2);
174         GetManualViewBaseContour() ->UpdateViewPoint(3);
175
176         SetState(0);
177         GetManualViewBaseContour()->Refresh();
178 }
179
180 // ----------------------------------------------------------------------------
181 void manualRoiControler::SetRoi(int x1, int y1,int x2, int y2)
182 {
183         manualPoint *mp;
184         InitRoi( 0 , 0 , 0.2 );
185         mp = GetManualContourModel()->GetManualPoint(2);
186         mp->SetPointX(x1);
187         mp->SetPointY(y1);
188
189         mp = GetManualContourModel()->GetManualPoint(1);
190         mp->SetPointX(x2);
191         mp->SetPointY(y1);
192
193         mp = GetManualContourModel()->GetManualPoint(0);
194         mp->SetPointX(x2);
195         mp->SetPointY(y2);
196
197         mp = GetManualContourModel()->GetManualPoint(3);
198         mp->SetPointX(x1);
199         mp->SetPointY(y2);
200
201         GetManualViewBaseContour() ->UpdateViewPoint(0);
202         GetManualViewBaseContour() ->UpdateViewPoint(1);
203         GetManualViewBaseContour() ->UpdateViewPoint(2);
204         GetManualViewBaseContour() ->UpdateViewPoint(3);
205 }
206