]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewRoi.cpp
#3065 creaMaracasVisu Bug New Normal - Refresh manual contour
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualViewRoi.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 "manualViewRoi.h"
27
28 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31
32 manualViewRoi::manualViewRoi()
33 {
34         _sizePointsContour=5;
35 }
36 // ----------------------------------------------------------------------------
37 manualViewRoi::~manualViewRoi()
38 {
39 }
40
41
42 // ----------------------------------------------------------------------------
43 manualViewRoi * manualViewRoi :: Clone()
44 {
45         manualViewRoi * clone = new manualViewRoi();
46         CopyAttributesTo(clone);
47         return clone;
48 }
49
50 // ---------------------------------------------------------------------------
51
52 void manualViewRoi::CopyAttributesTo( manualViewRoi * cloneObject)
53 {
54         // Fathers object
55         manualViewBaseContour::CopyAttributesTo(cloneObject);
56 }
57
58 // ----------------------------------------------------------------------------
59 void manualViewRoi::RefreshContour() // virtual
60 {
61     unsigned int i,ii, np;
62     np  = GetNumberOfPoints( );
63 //EED01 
64         if ( np > 0)
65         {
66                 if (np>=2)
67                 {
68                         manualPoint     *mp;
69                         for( i = 0; i < np+1; i++ ) {
70                                 ii=i%np;
71                                 mp = _manContModel->GetManualPoint(ii);
72
73         //EEDx6
74                                 double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
75         //                      wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
76         //                      wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
77
78         //EED 27 sep 2007
79         //                      _pts->SetPoint(i, XX,YY,ZZ );
80                                 _pts->SetPoint(i, XX*_spc[0] , YY*_spc[1] , ZZ*_spc[2] );
81                         } //  rof
82
83                 } else {
84                                 _pts->SetPoint(0, 0 , 0 , 0);
85                                 _pts->SetPoint(1, 0 , 0 , 0);
86                 } // if
87         }
88
89 //EED 2017-03-02
90         if (_pts!=NULL) 
91         {
92                 _pts->Modified();
93         }
94 }
95
96 // ----------------------------------------------------------------------------
97 int manualViewRoi::GetType() // virtual
98 {
99         return 2;
100 }
101
102 // ----------------------------------------------------------------------------
103
104 void manualViewRoi::GetMinMax(double &minX,double &minY, double &maxX, double &maxY)
105 {
106         double  pp[3];
107         manualPoint *mp;
108     unsigned int i;
109
110         minX=99999;
111         minY=99999;
112         maxX=-99999;
113         maxY=-99999;
114
115         unsigned int size=(unsigned int) _manContModel->GetSizeLstPoints();
116
117         for( i = 0; i < size; i++ )
118         {
119
120                 mp=_manContModel->GetManualPoint(i);
121                 pp[0]=mp->GetX();
122                 pp[1]=mp->GetY();
123
124                 // min X
125                 if (pp[0]<minX)
126                 {
127                         minX=pp[0];
128                 }
129                 //min Y
130                 if (pp[1]<minY)
131                 {
132                         minY=pp[1];
133                 }
134                 //max X
135                 if (pp[0]>maxX)
136                 {
137                         maxX=pp[0];
138                 }
139                 // max Y
140                 if (pp[1]>maxY)
141                 {
142                         maxY=pp[1];
143                 }
144         }
145
146         if ( size<1 )
147         {
148                 minX=0;
149                 maxX=0;
150                 minY=0;
151                 maxY=0;
152         }
153 }
154
155 // ----------------------------------------------------------------------------
156
157
158 bool manualViewRoi::ifTouchContour(int x,int y, int z) // virtual
159 {
160         bool    result=false;
161         double  px1=99999,py1=99999,px2=-99999,py2=-99999;
162
163         GetMinMax(px1,py1, px2, py2);
164
165         double xx=x;
166         double yy=y;
167         double zz=z;
168         TransfromCoordViewWorld(xx,yy,zz);
169
170         bool ok1=false;
171         bool ok2=false;
172         double ddx=GetRange();
173         double ddy=GetRange();
174
175         if ((xx>px1-ddx)&&(xx<px2+ddx) &&  (yy>py1-ddy)&&(yy<py2+ddy))
176         {
177                 ok1=true;
178         }
179
180         if ((xx>px1+ddx)&&(xx<px2-ddx) &&  (yy>py1+ddy)&&(yy<py2-ddy))
181         {
182                 ok2=true;
183         }
184
185         if ((ok1==true) && (ok2==false))
186         {
187                 result=true;
188         }
189                 
190         return result;
191 }
192
193 // ----------------------------------------------------------------------------
194
195 void manualViewRoi::InitMove(int x, int y, int z)  // virtual
196 {
197         manualPoint *mp;
198         double XX=x;
199         double YY=y;
200         double ZZ=z;
201         TransfromCoordViewWorld(XX,YY,ZZ);
202
203         if (_manContModel->GetSizeLstPoints()==4){
204                 mp = _manContModel->GetManualPoint(0);
205                 _dp0[0]= mp->GetX() - XX;
206                 _dp0[1]= mp->GetY() - YY;
207                 _dp0[2]= mp->GetZ();
208
209                 mp = _manContModel->GetManualPoint(1);
210                 _dp1[0]= mp->GetX() - XX;
211                 _dp1[1]= mp->GetY() - YY;
212                 _dp1[2]= mp->GetZ();
213
214                 mp = _manContModel->GetManualPoint(2);
215                 _dp2[0]= mp->GetX() - XX;
216                 _dp2[1]= mp->GetY() - YY;
217                 _dp2[2]= mp->GetZ();
218
219                 mp = _manContModel->GetManualPoint(3);
220                 _dp3[0]= mp->GetX() - XX;
221                 _dp3[1]= mp->GetY() - YY;
222                 _dp3[2]= mp->GetZ();
223         }
224 }
225
226 // ----------------------------------------------------------------------------
227
228 void manualViewRoi::MoveContour(int x, int y, int z) // virtual
229 {
230         manualPoint *mp;
231         double XX=x;
232         double YY=y;
233         double ZZ=z;
234         TransfromCoordViewWorld(XX,YY,ZZ);
235
236         mp = _manContModel->GetManualPoint(0);
237         mp->SetPoint(_dp0[0]+XX,_dp0[1]+YY,_dp0[2]);
238
239         mp = _manContModel->GetManualPoint(1);
240         mp->SetPoint(_dp1[0]+XX,_dp1[1]+YY,_dp0[2]);
241
242         mp = _manContModel->GetManualPoint(2);
243         mp->SetPoint(_dp2[0]+XX,_dp2[1]+YY,_dp0[2]);
244
245         mp = _manContModel->GetManualPoint(3);
246         mp->SetPoint(_dp3[0]+XX,_dp3[1]+YY,_dp0[2]);
247
248         UpdateViewPoint(0);
249         UpdateViewPoint(1);
250         UpdateViewPoint(2);
251         UpdateViewPoint(3);
252
253 }