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 # ------------------------------------------------------------------------ */
27 #include "manualViewPerpPlaneContour.h"
29 #include "vtkPlane2DView.h"
31 manualViewPerpPlaneContour::manualViewPerpPlaneContour()
34 // ----------------------------------------------------------------------------
35 manualViewPerpPlaneContour::~manualViewPerpPlaneContour()
40 // ----------------------------------------------------------------------------
41 manualViewPerpPlaneContour * manualViewPerpPlaneContour :: Clone()
43 manualViewPerpPlaneContour * clone = new manualViewPerpPlaneContour();
44 CopyAttributesTo(clone);
48 // ---------------------------------------------------------------------------
50 void manualViewPerpPlaneContour::CopyAttributesTo( manualViewPerpPlaneContour * cloneObject)
53 manualViewContour::CopyAttributesTo(cloneObject);
59 // ----------------------------------------------------------------------------
60 void manualViewPerpPlaneContour::UpdateViewPoint(int id)
63 manualPoint *mp = _manContModel->GetManualPoint(id);
67 FilterCordinateXYZ(x,y,z);
69 _lstViewPoints[id]->SetPositionXY( x , y ,GetRange(), z );
70 if ((z>=-1) && (z<=1))
72 _lstViewPoints[id]->GetVtkActor()->VisibilityOn();
74 _lstViewPoints[id]->GetVtkActor()->VisibilityOff();
77 // ----------------------------------------------------------------------------
78 void manualViewPerpPlaneContour::FilterCordinateXYZ (double &x, double &y, double &z)
80 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
81 vtkMPRBaseData *vtkmprbasedata = vtkplane2Dview->GetVtkmprbasedata();
82 vtkTransform *transf1 = vtkTransform::New();
83 vtkTransform *transf2 = vtkmprbasedata->GetTransformOrientation();
84 transf1->SetMatrix( transf2->GetMatrix() );
88 double center = vtkplane2Dview->GetImgSize() / 2;
90 in[0] = x - vtkmprbasedata->GetX();
91 in[1] = y - vtkmprbasedata->GetY();
92 in[2] = z - vtkmprbasedata->GetZ();
95 transf1->MultiplyPoint(in,out);
101 this->GetWxVtkBaseView()->GetSpacing(spc);
109 // ----------------------------------------------------------------------------
110 void manualViewPerpPlaneContour::TransfromCoordViewWorld( double &X,double &Y,double &Z,int type )
113 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
114 vtkplane2Dview->TransfromCoordViewWorld2(X,Y,Z);
118 // ----------------------------------------------------------------------------
119 void manualViewPerpPlaneContour::RefreshContour() // virtual
121 // manualViewContour::RefreshContour();
127 // JSTG 25-02-08 ----------------------------------------------------------
129 //--------------------------------------------------------
135 double dist,distMin = 99999999;
137 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
138 double center = vtkplane2Dview->GetImgSize() / 2;
141 np = GetNumberOfPoints( );
143 //JSTG 25-02-08 ------------------------------------------
145 //nps = GetNumberOfPointsSpline();
146 nps = _manContModel->GetNumberOfPointsSpline();
147 //delta = ( double ) ( np ) / ( double ) ( nps-1 );
148 _manContModel->UpdateSpline();
149 //--------------------------------------------------------
153 for( i = 0; i < nps; i++ )
155 // JSTG 25-02-08 ----------------------------------------------------------
156 //t = delta * (double)i ;
157 //tt = delta * (double)(i+1) ;
158 //_manContModel->GetSplinePoint(t ,pp1[0],pp1[1],pp1[2]);
159 //_manContModel->GetSplinePoint(tt,pp2[0],pp2[1],pp2[2]);
160 _manContModel->GetSpline_i_Point(i ,&pp1[0],&pp1[1],&pp1[2]);
161 _manContModel->GetSpline_i_Point(i+1,&pp2[0],&pp2[1],&pp2[2]);
162 //--------------------------------------------------------------------------
163 FilterCordinateXYZ(pp1[0],pp1[1],pp1[2]);
164 FilterCordinateXYZ(pp2[0],pp2[1],pp2[2]);
165 if (pp2[2]*pp1[2]<=0)
167 if (pp1[2]-pp2[2]!=0) {
168 u = -pp2[2] / (pp1[2]-pp2[2]);
172 pp[0] = ( pp1[0]-pp2[0] )*u + pp2[0];
173 pp[1] = ( pp1[1]-pp2[1] )*u + pp2[1];
174 pp[2] = ( pp1[2]-pp2[2] )*u + pp2[2];
175 ppC[0] = pp[0] - center;
176 ppC[1] = pp[1] - center;
178 dist = sqrt( ppC[0]*ppC[0] + ppC[1]*ppC[1] + ppC[2]*ppC[2] );
190 _pts->SetPoint(0, 0 , 0 , 0);
191 _pts->SetPoint(1, 0 , 0 , 0);
195 ppB[0]=ppB[0]*_spc[0];
196 ppB[1]=ppB[1]*_spc[1];
198 _pts->SetPoint( 0, ppB[0] , ppB[1]+1 , 1 );
199 _pts->SetPoint( 1, ppB[0] , ppB[1]-1 , 1 );
200 _pts->SetPoint( 2, ppB[0] , ppB[1] , 1 );
201 _pts->SetPoint( 3, ppB[0]-1 , ppB[1] , 1 );
202 _pts->SetPoint( 4, ppB[0]+1 , ppB[1] , 1 );
205 for( i = 5; i < nps; i++ )
207 _pts->SetPoint( i, ppB[0] , ppB[1] , 1 );
212 //---------------------------------------------------------------------------
213 bool manualViewPerpPlaneContour::ifTouchContour( int x, int y, int z)
216 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
220 vtkplane2Dview->TransFromCoordScreenToWorld(X,Y,Z);
223 _pts->GetPoint(0, ppA);
224 if (sqrt( (ppA[0]-X)*(ppA[0]-X) + (ppA[1]-Y)*(ppA[1]-Y) ) <=2)