]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasRenderImageTransformation.cpp
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasRenderImageTransformation.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 "wxMaracasRenderImageTransformation.h"
27 #include "wxMaracasRendererView.h"
28
29 /**
30 ** Class constructor
31 **/
32 wxMaracasRenderImageTransformation::wxMaracasRenderImageTransformation(VolumeRendererManager* _vol, wxMaracasSurfaceRenderingManager* _surface1,
33                                                                        wxMaracasSurfaceRenderingManager* _surface2, wxMaracasSurfaceRenderingManager* _surface3, int id)
34 {
35         vol = _vol;
36         surface1 = _surface1;
37         surface2 = _surface2;
38         surface3 = _surface3;
39         
40         propID = id;
41         transformV = vtkTransform::New();
42         transformS1 = vtkTransform::New();
43         transformS2 = vtkTransform::New();
44         transformS3 = vtkTransform::New();
45 }
46
47 /**
48 ** Class destructor
49 **/
50 wxMaracasRenderImageTransformation::~wxMaracasRenderImageTransformation()
51 {       
52         
53 }
54
55 /**
56 ** Transforms a volume by the given value for the X axis
57 **/
58 void wxMaracasRenderImageTransformation::Translate(int tx, int ty, int tz, int rx, int ry, int rz, int sx, int sy, int sz)
59 {
60         //printf("wxMaracasRenderImageManagementPanel::Rotate float:scaleX = %f \n", tx);
61         //printf("wxMaracasRenderImageManagementPanel::Rotate float:scaleY = %f \n", ty);
62         //printf("wxMaracasRenderImageManagementPanel::Rotate float:scaleZ = %f \n", tz);
63
64         double volspX;
65         double volspY;
66         double volspZ;
67         vol->getImageData()->GetSpacing(volspX, volspY, volspZ);
68         
69         double surfspX;
70         double surfspY;
71         double surfspZ;
72         surface1->getImageData()->GetSpacing(surfspX, surfspY, surfspZ);
73
74         int ext[6];
75         vol->getImageData()->GetExtent(ext);
76
77         transformV->Identity();
78         transformS1->Identity();
79         transformS2->Identity();
80         transformS3->Identity();
81
82         transformV->PostMultiply();
83         transformS1->PostMultiply();
84         transformS2->PostMultiply();
85         transformS3->PostMultiply();
86         
87         printf("CPR: wxMaracasRenderImageTransformation::Translate-> %f\n", -(ext[1]-ext[0])*volspX );
88         printf("CPR: wxMaracasRenderImageTransformation::Translate-> %f\n", -(ext[3]-ext[2])*surfspY);
89         printf("CPR: wxMaracasRenderImageTransformation::Translate-> %f\n", -(ext[5]-ext[4])*surfspZ);
90
91         transformV ->Translate( -(ext[1]-ext[0])*volspX/2,  -(ext[3]-ext[2])*volspY/2,  -(ext[5]-ext[4])*volspZ/2  );
92         transformS1->Translate( -(ext[1]-ext[0])*surfspX/2, -(ext[3]-ext[2])*surfspY/2, -(ext[5]-ext[4])*surfspZ/2 );
93         transformS2->Translate( -(ext[1]-ext[0])*surfspX/2, -(ext[3]-ext[2])*surfspY/2, -(ext[5]-ext[4])*surfspZ/2 );
94         transformS3->Translate( -(ext[1]-ext[0])*surfspX/2, -(ext[3]-ext[2])*surfspY/2, -(ext[5]-ext[4])*surfspZ/2 );
95
96         transformV ->Scale( (sx/100.0), (sy/100.0), (sz/100.0) );
97         transformS1->Scale( (sx/100.0), (sy/100.0), (sz/100.0) );
98         transformS2->Scale( (sx/100.0), (sy/100.0), (sz/100.0) );
99         transformS3->Scale( (sx/100.0), (sy/100.0), (sz/100.0) );
100
101         transformV ->RotateX( rx );
102         transformS1->RotateX( rx );
103         transformS2->RotateX( rx );
104         transformS3->RotateX( rx );
105
106         transformV ->RotateY( ry );
107         transformS1->RotateY( ry );
108         transformS2->RotateY( ry );
109         transformS3->RotateY( ry );
110
111         transformV ->RotateZ( rz );
112         transformS1->RotateZ( rz );
113         transformS2->RotateZ( rz );
114         transformS3->RotateZ( rz );
115
116         transformV ->Translate( tx*volspX + (ext[1]-ext[0])*volspX/2,  ty*volspY + (ext[3]-ext[2])*volspY/2,  tz*volspZ + (ext[5]-ext[4])*volspZ/2 );
117         transformS1->Translate( tx*surfspX + (ext[1]-ext[0])*volspX/2, ty*surfspY + (ext[3]-ext[2])*volspY/2, tz*surfspZ + (ext[5]-ext[4])*volspZ/2 );
118         transformS2->Translate( tx*surfspX + (ext[1]-ext[0])*volspX/2, ty*surfspY + (ext[3]-ext[2])*volspY/2, tz*surfspZ + (ext[5]-ext[4])*volspZ/2 );
119         transformS3->Translate( tx*surfspX + (ext[1]-ext[0])*volspX/2, ty*surfspY + (ext[3]-ext[2])*volspY/2, tz*surfspZ + (ext[5]-ext[4])*volspZ/2 );
120
121         Refresh();
122 }
123
124 /**
125 ** Updates each Matrix
126 **/
127 void wxMaracasRenderImageTransformation::Refresh()throw(char*)
128 {
129         transformV->Update();
130         transformS1->Update();
131         transformS2->Update();
132         transformS3->Update();
133
134         vol->getViewData(propID)->getProp3D()->SetUserMatrix(transformV->GetMatrix());
135         //vol->Update(propID);
136
137         surface1->getViewData(propID)->getProp3D()->SetUserMatrix(transformV->GetMatrix());
138         //surface1->Update(propID);
139
140         surface2->getViewData(propID)->getProp3D()->SetUserMatrix(transformV->GetMatrix());
141         //surface2->getRenderer()->Render();
142
143         surface3->getViewData(propID)->getProp3D()->SetUserMatrix(transformV->GetMatrix());
144         //surface3->getRenderer()->Render();
145 }