]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualViewPerpPlaneContour.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualViewPerpPlaneContour.cxx
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
27 #include "manualViewPerpPlaneContour.h"
28
29 #include "vtkPlane2DView.h"
30
31 manualViewPerpPlaneContour::manualViewPerpPlaneContour()
32 {
33 }
34 // ----------------------------------------------------------------------------
35 manualViewPerpPlaneContour::~manualViewPerpPlaneContour()
36 {
37 }
38
39
40 // ----------------------------------------------------------------------------
41 manualViewPerpPlaneContour * manualViewPerpPlaneContour :: Clone()
42 {
43         manualViewPerpPlaneContour * clone = new manualViewPerpPlaneContour();
44         CopyAttributesTo(clone);
45         return clone;
46 }
47
48 // ---------------------------------------------------------------------------
49
50 void manualViewPerpPlaneContour::CopyAttributesTo( manualViewPerpPlaneContour * cloneObject)
51 {
52         // Fathers object
53         manualViewContour::CopyAttributesTo(cloneObject);
54 }
55
56
57
58
59 // ----------------------------------------------------------------------------
60 void manualViewPerpPlaneContour::UpdateViewPoint(int id)
61 {  // virtual
62         double x,y,z;
63         manualPoint *mp = _manContModel->GetManualPoint(id);
64         x = mp->GetX();
65         y = mp->GetY();
66         z = mp->GetZ();
67         FilterCordinateXYZ(x,y,z);
68
69         _lstViewPoints[id]->SetPositionXY( x , y ,GetRange(), z );
70         if ((z>=-1) && (z<=1))
71         {
72                 _lstViewPoints[id]->GetVtkActor()->VisibilityOn();
73         } else {
74                 _lstViewPoints[id]->GetVtkActor()->VisibilityOff();
75         }
76 }
77 // ----------------------------------------------------------------------------
78 void manualViewPerpPlaneContour::FilterCordinateXYZ (double &x, double &y, double &z)
79 {
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() ); 
85         transf1->Inverse();
86
87         double in[4], out[4];
88         double center = vtkplane2Dview->GetImgSize() / 2;
89
90         in[0] = x - vtkmprbasedata->GetX();
91         in[1] = y - vtkmprbasedata->GetY();
92         in[2] = z - vtkmprbasedata->GetZ();
93         in[3] = 0;
94
95         transf1->MultiplyPoint(in,out);
96         z = out[0];
97         x = out[1]+center;
98         y = out[2]+center;
99
100         double spc[3];
101         this->GetWxVtkBaseView()->GetSpacing(spc);
102         x = x / spc[0];
103         y = y / spc[1];
104         z = z / spc[2];
105
106         transf1->Delete();
107 }
108
109 // ----------------------------------------------------------------------------
110 void manualViewPerpPlaneContour::TransfromCoordViewWorld( double &X,double &Y,double &Z,int type )
111 {
112         Z = 0;
113         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
114         vtkplane2Dview->TransfromCoordViewWorld2(X,Y,Z);
115 }
116
117
118 // ----------------------------------------------------------------------------
119 void manualViewPerpPlaneContour::RefreshContour() // virtual
120 {
121 //      manualViewContour::RefreshContour();
122
123         double pp1[3];
124         double pp2[3];
125         double u;
126                 
127 // JSTG 25-02-08 ----------------------------------------------------------
128 //              tt;
129 //--------------------------------------------------------
130
131         double pp[3];
132         double ppB[3];
133         double ppC[3];
134         ppB[0] = 999999;
135         double dist,distMin = 99999999;
136
137         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
138         double center = vtkplane2Dview->GetImgSize() / 2;
139
140         int i,np,nps;
141         np              = GetNumberOfPoints( );
142
143 //JSTG 25-02-08 ------------------------------------------
144         //double t,delta;
145     //nps               = GetNumberOfPointsSpline(); 
146         nps = _manContModel->GetNumberOfPointsSpline();
147         //delta = ( double ) ( np  ) / ( double ) ( nps-1  );
148         _manContModel->UpdateSpline();
149 //--------------------------------------------------------
150
151         if ( np >= 2 )
152         {
153                 for( i = 0; i < nps; i++ ) 
154                 {
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)
166                         {
167                                 if (pp1[2]-pp2[2]!=0) { 
168                                         u = -pp2[2] / (pp1[2]-pp2[2]);
169                                 } else  {
170                                         u=9999999;
171                                 }
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;
177                                 ppC[2] = pp[2] ;
178                                 dist = sqrt( ppC[0]*ppC[0] + ppC[1]*ppC[1] + ppC[2]*ppC[2] );
179                                 if (dist<distMin)
180                                 {
181                                         distMin=dist;
182                                         ppB[0] = pp[0];
183                                         ppB[1] = pp[1];
184                                         ppB[2] = pp[2];
185                                 }
186                         }
187
188                 }// for 
189         } else {
190                         _pts->SetPoint(0, 0 , 0 , 0);   
191                         _pts->SetPoint(1, 0 , 0 , 0);   
192         } // if
193
194 //EED 27 sep 2006
195         ppB[0]=ppB[0]*_spc[0];
196         ppB[1]=ppB[1]*_spc[1];
197
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 );   
203
204
205         for( i = 5; i < nps; i++ ) 
206         {
207                 _pts->SetPoint( i, ppB[0] , ppB[1] , 1 );       
208         }
209
210 }
211
212 //---------------------------------------------------------------------------
213 bool manualViewPerpPlaneContour::ifTouchContour( int x, int y, int z)
214 {
215         bool ok=false;
216         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
217         double X=x;
218         double Y=y;
219         double Z=z;
220         vtkplane2Dview->TransFromCoordScreenToWorld(X,Y,Z);
221         
222         double ppA[3];
223         _pts->GetPoint(0, ppA);
224         if (sqrt( (ppA[0]-X)*(ppA[0]-X) + (ppA[1]-Y)*(ppA[1]-Y) ) <=2)
225         {
226                 ok = true;
227         }
228         return ok;
229 }
230