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