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