1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "manualViewContour.h"
28 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 manualViewContour::manualViewContour()
34 _id_viewPoint_for_text = 0;
36 _initialConoturModel = new manualContourModel();
44 // ----------------------------------------------------------------------------
45 manualViewContour::~manualViewContour()
47 delete _initialConoturModel;
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
52 manualViewContour * manualViewContour :: Clone()
54 manualViewContour * clone = new manualViewContour();
55 CopyAttributesTo(clone);
59 // ---------------------------------------------------------------------------
61 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
63 // Call to Fathers object
64 manualViewBaseContour::CopyAttributesTo(cloneObject);
66 cloneObject->SetMesureScale(_mesureScale);
69 // ---------------------------------------------------------------------------
71 int manualViewContour::GetType() // virtual
76 // ----------------------------------------------------------------------------
78 void manualViewContour::Save(FILE *pFile)
80 manualViewBaseContour::Save(pFile);
83 // ----------------------------------------------------------------------------
85 void manualViewContour::Open(FILE *pFile)
89 // ----------------------------------------------------------------------------
90 void manualViewContour::RefreshContour() // virtual
94 //JSTG 25-02-08 --------------------
95 //double t,delta, x,y,z;
98 //----------------------------------
100 _manContModel->UpdateSpline();
101 np = GetNumberOfPoints( );
102 //nps = GetNumberOfPointsSpline();
103 nps = _manContModel->GetNumberOfPointsSpline();
104 //delta=( double ) ( np ) / ( double ) ( nps-1 ); //JSTG 25-02-08
117 for( i = 0; i < nps; i++ )
119 //JSTG 25-02-08 ------------------------------------------------
120 //t = delta * (double)i;
121 //_manContModel->GetSplinePoint(t,x,y,z);
122 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
123 //--------------------------------------------------------------
125 // _pts->SetPoint(i, x,y,z );
129 _pts->SetPoint(i,xx,yy,zz );
133 if (xx < _minX) { _minX = xx; }
134 if (yy < _minY) { _minY = yy; }
135 if (xx > _maxX) { _maxX = xx; }
136 if (yy > _maxY) { _maxY = yy; }
142 _pts->SetPoint(0, 0 , 0 , 0);
143 _pts->SetPoint(1, 0 , 0 , 0);
148 // ----------------------------------------------------------------------------
149 void manualViewContour::RefreshText() // virtual
151 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
152 int size = GetNumberOfPoints();
154 char resultText[250];
155 strcpy(resultText, "000");
156 char resultText2[250];
157 strcpy(resultText2, "000");
159 //CMRU 19-08-09 ----------------------------------
161 label = _manContModel->GetLabel();
162 // ------------------------------------
166 strcpy(resultText,"L= ");
167 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
168 strcat(resultText,text);
169 strcat(resultText,"p");
171 //CMRU 19-08-09 ----------------------------------
172 strcat(resultText," ");
173 strcat(resultText,label.c_str());
175 strcpy(resultText2,"L= ");
176 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
177 strcat(resultText2,text);
178 strcat(resultText2,"u");
180 //------------------------------------------------
184 if (_manContModel->IfCloseContour()==true)
186 strcpy(resultText,"P= ");
187 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
188 strcat(resultText,text);
189 strcat(resultText,"p");
191 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea(), 5, text );
192 strcat(resultText," A= ");
193 strcat(resultText,text);
194 strcat(resultText,"p^2 ");
197 strcpy(resultText2,"P= ");
198 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
199 strcat(resultText2,text);
200 strcat(resultText2,"u");
202 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea(), 5, text );
203 strcat(resultText2," A= ");
204 strcat(resultText2,text);
205 strcat(resultText2,"u^2 ");
208 strcpy(resultText,"L= ");
209 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
210 strcat(resultText,text);
211 strcat(resultText,"p");
213 strcpy(resultText2,"L= ");
214 gcvt ( _mesureScale * this->_manContModel->GetPathSize(), 5, text );
215 strcat(resultText2,text);
216 strcat(resultText2,"u");
219 //CMRU 19-08-09 ----------------------------------
220 strcat(resultText,label.c_str());
221 //------------------------------------------------
224 _textActor->SetInput(resultText);
225 _textActor2->SetInput(resultText2);
230 for (i=0; i<size; i++)
232 if (_lstViewPoints[i]->GetPosibleSelected()==true)
234 _id_viewPoint_for_text = i;
238 if (_id_viewPoint_for_text>=size)
240 _id_viewPoint_for_text=0;
243 double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
244 double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
250 _textActor->SetPosition(px+GetRange()+1,py);
251 _textActor2->SetPosition(px+GetRange()+1,py+2);
256 // ----------------------------------------------------------------------------
257 bool manualViewContour::ifTouchContour(int x,int y,int z)
266 TransfromCoordViewWorld(xx,yy,zz);
273 if ( (xx>=_minX) && (yy>=_minY) && (xx<=_maxX) && (yy<=_maxY)) { // inside the boundaring box
275 unsigned int i, nps,nps_t;
276 nps = _sizePointsContour;
278 if (this->_manContModel->IfCloseContour()==true)
285 printf("EED Warning manualViewContour::ifTouchContour \n");
287 for( i = 0; i < nps_t; i++ )
289 _pts->GetPoint(i%nps, ppA);
290 _pts->GetPoint((i+1)%nps, ppB);
291 d1 = sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
292 d2 = sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
293 d3 = sqrt( (ppB[0]-ppA[0])*(ppB[0]-ppA[0]) + (ppB[1]-ppA[1])*(ppB[1]-ppA[1]) + (ppB[2]-ppA[2])*(ppB[2]-ppA[2]));
295 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
305 // ----------------------------------------------------------------------------
306 void manualViewContour::DeletePoint(int id) // virtual
308 if (_lstViewPoints.size()>2)
310 manualViewBaseContour::DeletePoint( id );
313 // ----------------------------------------------------------------------------
315 void manualViewContour::ClearPoint(int id)
317 manualViewBaseContour::DeletePoint( id );
320 //-------------------------------------------------------------------
321 void manualViewContour::SetMesureScale(double mesureScale)
323 _mesureScale = mesureScale;
325 //-------------------------------------------------------------------
326 void manualViewContour::InitMove(int x, int y, int z)
328 _initialConoturModel->DeleteAllPoints();
330 manualPoint *mp = NULL;
334 TransfromCoordViewWorld(XX,YY,ZZ);
336 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
337 for ( i=0; i<manualPointsSZ; i++ )
339 mp = _manContModel->GetManualPoint( i );
340 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
343 //-------------------------------------------------------------------
344 void manualViewContour::MoveContour(int x, int y, int z)
346 manualPoint *mpOrigin = NULL;
347 manualPoint *mpMoving = NULL;
352 TransfromCoordViewWorld(XX,YY,ZZ);
354 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
355 for ( i=0; i<manualPointsSZ; i++ )
357 mpOrigin = _manContModel->GetManualPoint( i );
358 mpMoving = _initialConoturModel->GetManualPoint(i);
359 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
363 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
365 manualPoint *mpOrigin = NULL;
367 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
368 for ( i=0; i<manualPointsSZ; i++ )
370 mpOrigin = _manContModel->GetManualPoint( i );
371 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );