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;
35 _initialConoturModel = new manualContourModel();
42 // ----------------------------------------------------------------------------
43 manualViewContour::~manualViewContour()
45 delete _initialConoturModel;
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
50 manualViewContour * manualViewContour :: Clone()
52 manualViewContour * clone = new manualViewContour();
53 CopyAttributesTo(clone);
57 // ---------------------------------------------------------------------------
59 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
61 // Call to Fathers object
62 manualViewBaseContour::CopyAttributesTo(cloneObject);
65 // ---------------------------------------------------------------------------
67 int manualViewContour::GetType() // virtual
72 // ----------------------------------------------------------------------------
74 void manualViewContour::Save(FILE *pFile)
76 manualViewBaseContour::Save(pFile);
79 // ----------------------------------------------------------------------------
80 void manualViewContour::Open(FILE *pFile)
84 // ----------------------------------------------------------------------------
85 bool manualViewContour::ShowLineVersion() // virtual
88 int np = GetNumberOfPoints( );
96 // ----------------------------------------------------------------------------
97 void manualViewContour::RefreshContour() // virtual
100 //JSTG 25-02-08 --------------------
101 //double t,delta, x,y,z;
104 //----------------------------------
105 if ( ShowLineVersion()==true )
108 manualPoint *mpA = _manContModel->GetManualPoint(0);
109 manualPoint *mpB = _manContModel->GetManualPoint(1);
112 xx = mpA->GetX() * _spc[0];
113 yy = mpA->GetY() * _spc[1];
114 zz = mpA->GetZ() * _spc[2];
119 _pts->SetPoint(0 , xx , yy , zz );
120 xx=mpB->GetX() * _spc[0];
121 yy=mpB->GetY() * _spc[1];
122 zz=mpB->GetZ() * _spc[2];
123 if (xx<_minX) _minX=xx;
124 if (yy<_minY) _minY=yy;
125 if (xx>_maxX) _maxX=xx;
126 if (yy>_maxY) _maxY=yy;
127 _pts->SetPoint(1 , xx , yy , zz );
131 _manContModel->UpdateSpline();
132 //nps = GetNumberOfPointsSpline();
133 nps = _manContModel->GetNumberOfPointsSpline();
134 //delta=( double ) ( np ) / ( double ) ( nps-1 ); //JSTG 25-02-08
144 int np = GetNumberOfPoints( );
147 for( i = 0; i < nps; i++ )
149 //JSTG 25-02-08 ------------------------------------------------
150 //t = delta * (double)i;
151 //_manContModel->GetSplinePoint(t,x,y,z);
152 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
153 //--------------------------------------------------------------
155 // _pts->SetPoint(i, x,y,z );
159 _pts->SetPoint(i,xx,yy,zz );
163 if (xx < _minX) { _minX = xx; }
164 if (yy < _minY) { _minY = yy; }
165 if (xx > _maxX) { _maxX = xx; }
166 if (yy > _maxY) { _maxY = yy; }
169 _pts->SetPoint(0, 0 , 0 , 0);
170 _pts->SetPoint(1, 0 , 0 , 0);
186 // ----------------------------------------------------------------------------
187 void manualViewContour::RefreshText() // virtual
189 if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
190 int size = GetNumberOfPoints();
192 char resultText[250];
193 strcpy(resultText, "000");
194 char resultText2[250];
195 strcpy(resultText2, "000");
201 //CMRU 19-08-09 ----------------------------------
202 std::string label = _manContModel->GetLabel();
203 std::string label2 = " (" + _manContModel->GetLabel2() + "z) ";
204 // ------------------------------------
208 strcpy(resultText,"L= ");
209 gcvt ( this->_manContModel->GetPathSize( spcP ), 5, text );
210 strcat(resultText,text);
211 strcat(resultText,"p");
213 //CMRU 19-08-09 ----------------------------------
214 strcat(resultText," ");
215 strcat(resultText,label.c_str());
217 strcpy(resultText2,"L= ");
218 gcvt ( this->_manContModel->GetPathSize( _spc ), 5, text );
219 strcat(resultText2,text);
220 strcat(resultText2,"u");
222 //------------------------------------------------
226 if (_manContModel->IfCloseContour()==true)
228 strcpy(resultText,"P= ");
229 gcvt ( this->_manContModel->GetPathSize( spcP ), 5, text );
230 strcat(resultText,text);
231 strcat(resultText,"p");
233 gcvt ( this->_manContModel->GetPathArea( spcP ), 5, text );
234 strcat(resultText," A= ");
235 strcat(resultText,text);
236 strcat(resultText,"p^2 ");
239 strcpy(resultText2,"P= ");
240 gcvt ( this->_manContModel->GetPathSize( _spc ), 5, text );
241 strcat(resultText2,text);
242 strcat(resultText2,"u");
244 gcvt ( this->_manContModel->GetPathArea( _spc ), 5, text );
245 strcat(resultText2," A= ");
246 strcat(resultText2,text);
247 strcat(resultText2,"u^2 ");
250 strcpy(resultText,"L= ");
251 gcvt ( this->_manContModel->GetPathSize( spcP ), 5, text );
252 strcat(resultText,text);
253 strcat(resultText,"p");
255 strcpy(resultText2,"L= ");
256 gcvt ( this->_manContModel->GetPathSize( _spc ), 5, text );
257 strcat(resultText2,text);
258 strcat(resultText2,"u");
260 //CMRU 19-08-09 ----------------------------------
261 strcat(resultText,label2.c_str());
262 strcat(resultText,label.c_str());
263 //------------------------------------------------
266 _textActor->SetInput(resultText);
267 _textActor2->SetInput(resultText2);
272 for (i=0; i<size; i++)
274 if (_lstViewPoints[i]->GetPosibleSelected()==true)
276 _id_viewPoint_for_text = i;
279 if (_id_viewPoint_for_text>=size)
281 _id_viewPoint_for_text = 0;
283 double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
284 double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
288 _textActor->SetPosition(px+GetRange()+1,py);
289 _textActor2->SetPosition(px+GetRange()+1,py+2);
294 // ----------------------------------------------------------------------------
295 bool manualViewContour::ifTouchContour(int x,int y,int z)
304 TransfromCoordViewWorld(xx,yy,zz);
309 if ( (xx>=_minX) && (yy>=_minY) && (xx<=_maxX) && (yy<=_maxY))
310 { // inside the boundaring box
311 if ( ShowLineVersion()==true )
313 _pts->GetPoint(0, ppA);
314 _pts->GetPoint(1, ppB);
316 // direction of the segment
317 dirVec[0] = ppB[0] - ppA[0];
318 dirVec[1] = ppB[1] - ppA[1];
319 dirVec[2] = ppB[2] - ppA[2];
320 // proj = mpA + k*dirVec
324 num = dirVec[0]*( xx-ppA[0] );
325 num = num + dirVec[1]*( yy-ppA[1] );
326 num = num + dirVec[2]*( zz-ppA[2] );
328 den=dirVec[0]*dirVec[0] + dirVec[1]*dirVec[1] + dirVec[2]*dirVec[2];
336 // projection of th point xx,yy,zz in segment mpA,mpB
337 double projX = ppA[0] + k*dirVec[0];
338 double projY = ppA[1] + k*dirVec[1];
339 double projZ = ppA[2] + k*dirVec[2];
342 // distance [projX,projY,projZ] and (xx,yy,zz]
343 double d1= sqrt( (projX-xx)*(projX-xx) + (projY-yy)*(projY-yy) +(projZ-zz)*(projZ-zz) );
349 unsigned int i, nps,nps_t;
350 nps = _sizePointsContour;
351 if (this->_manContModel->IfCloseContour()==true)
357 for( i = 0; i < nps_t; i++ )
359 _pts->GetPoint(i%nps, ppA);
360 _pts->GetPoint((i+1)%nps, ppB);
361 d1 = sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
362 d2 = sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
363 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]));
364 if ( ((d1+d2)>=d3) && ((d1+d2)<=d3*1.3) )
370 } // if GetSizeLstPoints()==2
375 // ----------------------------------------------------------------------------
376 void manualViewContour::DeletePoint(int id) // virtual
378 if (_lstViewPoints.size()>2)
380 manualViewBaseContour::DeletePoint( id );
383 // ----------------------------------------------------------------------------
385 void manualViewContour::ClearPoint(int id)
387 manualViewBaseContour::DeletePoint( id );
390 //-------------------------------------------------------------------
391 void manualViewContour::InitMove(int x, int y, int z)
393 _initialConoturModel->DeleteAllPoints();
395 manualPoint *mp = NULL;
399 TransfromCoordViewWorld(XX,YY,ZZ);
401 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
402 for ( i=0; i<manualPointsSZ; i++ )
404 mp = _manContModel->GetManualPoint( i );
405 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
409 //-------------------------------------------------------------------
410 void manualViewContour::MoveContour(int x, int y, int z)
412 manualPoint *mpOrigin = NULL;
413 manualPoint *mpMoving = NULL;
418 TransfromCoordViewWorld(XX,YY,ZZ);
420 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
421 for ( i=0; i<manualPointsSZ; i++ )
423 mpOrigin = _manContModel->GetManualPoint( i );
424 mpMoving = _initialConoturModel->GetManualPoint(i);
425 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
430 //-------------------------------------------------------------------
431 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
433 manualPoint *mpOrigin = NULL;
435 int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
436 for ( i=0; i<manualPointsSZ; i++ )
438 mpOrigin = _manContModel->GetManualPoint( i );
439 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );