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