]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualView3VContour.cpp
27f0b07b450ba22675547c0ef4be3278d97cb372
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualView3VContour.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 "manualView3VContour.h"
27
28
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
32
33 manualView3VContour::manualView3VContour(int type)
34 {
35         _type=type;
36 // JSTG 25-02-08 ------------------------------
37         //_manContModel= new manualContourModel();
38 //---------------------------------------------
39 }
40 // ----------------------------------------------------------------------------
41 manualView3VContour::~manualView3VContour()
42 {
43 }
44
45
46
47 // ----------------------------------------------------------------------------
48 manualView3VContour * manualView3VContour :: Clone()
49 {
50         manualView3VContour * clone = new manualView3VContour( GetType() );
51         CopyAttributesTo(clone);
52         return clone;
53 }
54
55 // ---------------------------------------------------------------------------
56
57 void manualView3VContour::CopyAttributesTo( manualView3VContour * cloneObject)
58 {
59         // Fathers object
60         manualViewContour::CopyAttributesTo(cloneObject);
61 }
62
63 int manualView3VContour::GetType()
64 {
65         return _type;
66 }
67
68 // ----------------------------------------------------------------------------
69 void manualView3VContour::FilterCordinateXYZ(double &x,double &y,double &z)
70 {
71         if (_type==0)
72         {
73                 x=-1000;
74         }
75         if (_type==1)
76         {
77                 y=500;
78         }
79         if (_type==2)
80         {
81                 z=-1000;
82         }
83 }
84 // ----------------------------------------------------------------------------
85
86 void manualView3VContour::RefreshContour()  // virtula
87 {
88         manualViewContour::RefreshContour();
89         int i;
90         
91         //EED 27 Juin 2012
92     //Boundaring box    
93         _minX=99999;
94         _minY=99999;
95         _minZ=99999;
96         _maxX=-99999;
97         _maxY=-99999;
98         _maxZ=-99999;
99         
100         
101         double pp[3];
102 // JSTG 25-02-08 ----------------------------------------
103         //int nps = GetNumberOfPointsSpline();
104         int nps = _manContModel->GetNumberOfPointsSpline();
105 //-------------------------------------------------------
106         for( i = 0; i < nps; i++ )
107         {
108                 _pts->GetPoint( i, pp );
109                 FilterCordinateXYZ(pp[0],pp[1],pp[2]);
110
111 //EED 27 sep 2006
112                 _pts->SetPoint( i, pp[0] , pp[1] ,pp[2] );
113                 
114                 
115                 //EED 27 Juin 2012
116                 //Boundaring box
117                 if (pp[0] < _minX) { _minX = pp[0]; }
118                 if (pp[1] < _minY) { _minY = pp[1]; }
119                 if (pp[2] < _minZ) { _minZ = pp[2]; }
120                 if (pp[0] > _maxX) { _maxX = pp[0]; }
121                 if (pp[1] > _maxY) { _maxY = pp[1]; }           
122                 if (pp[2] > _maxZ) { _maxY = pp[2]; }           
123                 
124         }// for
125
126 }
127
128 // ----------------------------------------------------------------------------
129
130 void manualView3VContour::UpdateViewPoint(int id){  // virtual
131         double x,y,z;
132         manualPoint             *mp             = _manContModel->GetManualPoint(id);
133         x=mp->GetX();
134         y=mp->GetY();
135         z=mp->GetZ();
136
137         FilterCordinateXYZ(x,y,z);
138         _lstViewPoints[id]->SetPositionXY( x , y ,GetRange(), z );
139 }
140
141 // ----------------------------------------------------------------------------
142
143 int     manualView3VContour::GetIdPoint(int x, int y, int z) // virtual
144 {
145         int ii=-1;
146         if (_manContModel!=NULL){
147                 double xx=x;
148                 double yy=y;
149                 double zz=z;
150                 TransfromCoordViewWorld(xx,yy,zz,-1);
151                 ii=_manContModel->GetIdPoint(xx,yy,zz,GetRange(),_type);
152         }
153         return ii;
154 }
155
156 // ----------------------------------------------------------------------------
157 bool manualView3VContour::ifTouchContour(int x,int y,int z){ // virtual
158         bool result=false;
159         double xx=x;
160         double yy=y;
161         double zz=z;
162         double ppA[3];
163         double ppB[3];
164         double d1,d2,d3;
165         TransfromCoordViewWorld(xx,yy,zz,-1);
166
167 //EED 27 sep 2006
168         xx = xx * _spc[0];
169         yy = yy * _spc[1];
170         zz = zz * _spc[2];
171
172         if ( (xx>=_minX) &&  (yy>=_minY) && (xx<=_maxX) && (yy<=_maxY)) {  //  boundaring box   
173                 unsigned int i, nps,nps_t;
174                 nps       = _sizePointsContour;
175                 if (this->_manContModel->IfCloseContour()==true)
176                 {
177                         nps_t = nps;
178                 } else {
179                         nps_t = nps-1;
180                 }
181                 FilterCordinateXYZ(xx,yy,zz);
182
183                 for( i = 0; i < nps_t; i++ ) {
184                         _pts->GetPoint(i%nps, ppA);
185                         _pts->GetPoint((i+1)%nps, ppB);
186                         FilterCordinateXYZ(ppA[0],ppA[1],ppA[2]);
187                         FilterCordinateXYZ(ppB[0],ppB[1],ppB[2]);
188                         d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
189                         d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
190                         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]));
191                         if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) {
192                                 result=true;
193                                 i=nps;
194                         } // if d1 d2 d3
195                 }// for i
196         } // boundaring box
197         return result;
198 }