]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualRoiControler.cpp
DFCH: imageUndoRedo + Manual Paint: It doesn't works :s :s
[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
97     printf("manualRoiControler::MouseClickLeft %d %d\n",x ,y);
98
99         int z=GetZ();
100
101 //      this->_vtkInteractorStyleBaseView->
102
103
104         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
105         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
106
107
108         if ( (GetState()==5) || (GetState()==1) ){
109                 SetPoint( bakIdPoint , x , y ,z);
110                 if (bakIdPoint==0)
111                 {
112                         SetPointX( 1 , x );
113                         SetPointY( 3 , y );
114                 }
115                 if (bakIdPoint==1)
116                 {
117                         SetPointX( 0 , x );
118                         SetPointY( 2 , y );
119                 }
120                 if (bakIdPoint==2)
121                 {
122                         SetPointX( 3 , x );
123                         SetPointY( 1 , y );
124                 }
125                 if (bakIdPoint==3)
126                 {
127                         SetPointX( 2 , x );
128                         SetPointY( 0 , y );
129                 }
130         }
131         if (GetState()==6){
132                 GetManualViewBaseContour()->MoveContour(x,y,z);
133         }
134         GetManualViewBaseContour()->Refresh();
135 }
136 // ----------------------------------------------------------------------------
137 void manualRoiControler::DeleteActualMousePoint(int x, int y)  // virtual
138 {
139 }
140 // ----------------------------------------------------------------------------
141 void manualRoiControler::InitRoi(int ww, int hh, double porcentage)
142 {
143         int zz;
144         manualPoint *mp;
145
146         if (GetManualContourModel()->GetSizeLstPoints() ==0)
147         {
148                 zz = GetZ();
149                 AddPoint(0,0,zz);
150                 AddPoint(0,0,zz);
151                 AddPoint(0,0,zz);
152                 AddPoint(0,0,zz);
153         }
154
155         double pp1=porcentage;
156         double pp2=1-porcentage;
157
158         mp = GetManualContourModel()->GetManualPoint(2);
159         zz=(int)mp->GetZ();
160         mp->SetPoint(ww*pp1,hh*pp1,zz);
161
162         mp = GetManualContourModel()->GetManualPoint(1);
163         zz=(int)mp->GetZ();
164         mp->SetPoint(ww*pp2,hh*pp1,zz);
165
166         mp = GetManualContourModel()->GetManualPoint(0);
167         zz=(int)mp->GetZ();
168         mp->SetPoint(ww*pp2,hh*pp2,zz);
169
170         mp = GetManualContourModel()->GetManualPoint(3);
171         zz=(int)mp->GetZ();
172         mp->SetPoint(ww*pp1,hh*pp2,zz);
173
174         GetManualViewBaseContour() ->UpdateViewPoint(0);
175         GetManualViewBaseContour() ->UpdateViewPoint(1);
176         GetManualViewBaseContour() ->UpdateViewPoint(2);
177         GetManualViewBaseContour() ->UpdateViewPoint(3);
178
179         SetState(0);
180         GetManualViewBaseContour()->Refresh();
181 }
182
183 // ----------------------------------------------------------------------------
184 void manualRoiControler::SetRoi(int x1, int y1,int x2, int y2)
185 {
186         manualPoint *mp;
187         InitRoi( 0 , 0 , 0.2 );
188         mp = GetManualContourModel()->GetManualPoint(2);
189         mp->SetPointX(x1);
190         mp->SetPointY(y1);
191
192         mp = GetManualContourModel()->GetManualPoint(1);
193         mp->SetPointX(x2);
194         mp->SetPointY(y1);
195
196         mp = GetManualContourModel()->GetManualPoint(0);
197         mp->SetPointX(x2);
198         mp->SetPointY(y2);
199
200         mp = GetManualContourModel()->GetManualPoint(3);
201         mp->SetPointX(x1);
202         mp->SetPointY(y2);
203
204         GetManualViewBaseContour() ->UpdateViewPoint(0);
205         GetManualViewBaseContour() ->UpdateViewPoint(1);
206         GetManualViewBaseContour() ->UpdateViewPoint(2);
207         GetManualViewBaseContour() ->UpdateViewPoint(3);
208 }
209