00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __mitkCamera_h
00012 #define __mitkCamera_h
00013
00014 #include "mitkObject.h"
00015 #include "mitkMatrix.h"
00016 #include "mitkVisualizationIncludes.h"
00017
00024 class MITK_VISUALIZATION_API mitkCamera : public mitkObject
00025 {
00026 public:
00027 MITK_TYPE(mitkCamera,mitkObject)
00028
00029 virtual void PrintSelf(ostream& os);
00030
00031 mitkCamera();
00032
00039 void GetPosition(float &x, float &y, float &z)
00040 {
00041 x = m_InverseViewMatrix->ele[12];
00042 y = m_InverseViewMatrix->ele[13];
00043 z = m_InverseViewMatrix->ele[14];
00044 }
00045
00052 void GetPosition(float a[3])
00053 {
00054 a[0] = m_InverseViewMatrix->ele[12];
00055 a[1] = m_InverseViewMatrix->ele[13];
00056 a[2] = m_InverseViewMatrix->ele[14];
00057 }
00058
00065 void GetFocalPoint(float &x, float &y, float &z)
00066 {
00067 x = m_FocalPoint[0];
00068 y = m_FocalPoint[1];
00069 z = m_FocalPoint[2];
00070 }
00071
00078 void GetFocalPoint(float a[3])
00079 {
00080 a[0] = m_FocalPoint[0];
00081 a[1] = m_FocalPoint[1];
00082 a[2] = m_FocalPoint[2];
00083 }
00084
00089 float GetThickness() { return m_Thickness; }
00090
00096 bool IsParallelProjection() { return m_ParallelProjection; }
00097
00101 void SetProjectionToParallel() { m_ParallelProjection = true; m_Modified = true; }
00102
00106 void SetProjectionToPerspective() { m_ParallelProjection = false; m_Modified = true; }
00107
00112 bool IsModified() { return m_Modified; }
00113
00118 virtual void LookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz);
00119
00123 virtual void Ortho(float left, float right, float bottom, float top, float zNear, float zFar);
00124
00128 virtual void Frustum(float left, float right, float bottom, float top, float zNear, float zFar);
00129
00133 virtual void Perspective(float fovy, float aspect, float zNear, float zFar);
00134
00138 void GetViewMatrix(mitkMatrix *m);
00139
00143 void GetViewMatrix(float m[16]);
00144
00148 const mitkMatrix* GetViewMatrix() {return m_ViewMatrix;}
00149
00153 void GetProjectionMatrix(mitkMatrix *m);
00154
00158 void GetProjectionMatrix(float m[16]);
00159
00163 const mitkMatrix* GetProjectionMatrix() {return m_ProjectionMatrix;}
00164
00168 void GetInverseOfProjectionMatrix(mitkMatrix *m);
00169
00173 void GetInverseOfProjectionMatrix(float m[16]);
00174
00178 const mitkMatrix* GetInverseOfProjectionMatrix() {return m_InverseProjectionMatrix;}
00179
00183 void GetInverseOfViewMatrix(mitkMatrix *m);
00184
00188 void GetInverseOfViewMatrix(float m[16]);
00189
00193 const mitkMatrix* GetInverseOfViewMatrix() {return m_InverseViewMatrix;}
00194
00198 void WorldToCamera(const float worldPoint[4], float cameraPoint[4]);
00199
00203 void WorldToView(const float worldPoint[4], float viewPoint[4]);
00204
00208 void CameraToView(const float cameraPoint[4], float viewPoint[4]);
00209
00213 void CameraToWorld(const float cameraPoint[4], float worldPoint[4]);
00214
00218 void ViewToWorld(const float viewPoint[4], float worldPoint[4]);
00219
00223 void ViewToCamera(const float viewPoint[4], float cameraPoint[4]);
00224
00225
00226 protected:
00227 virtual ~mitkCamera();
00228
00229 float m_FocalPoint[3];
00230 float m_Thickness;
00231
00232
00233 mitkMatrix *m_ViewMatrix;
00234 mitkMatrix *m_ProjectionMatrix;
00235 mitkMatrix *m_InverseProjectionMatrix;
00236 mitkMatrix *m_InverseViewMatrix;
00237
00238 bool m_ParallelProjection;
00239 bool m_Modified;
00240
00241 private:
00242 mitkCamera(const mitkCamera&);
00243 void operator=(const mitkCamera&);
00244
00245 };
00246
00247
00248 inline void mitkCamera::WorldToCamera(const float worldPoint[4], float cameraPoint[4])
00249 {
00250 mitkVector temp(worldPoint);
00251 temp *= *m_ViewMatrix;
00252 cameraPoint[0] = temp.ele[0];
00253 cameraPoint[1] = temp.ele[1];
00254 cameraPoint[2] = temp.ele[2];
00255 cameraPoint[3] = temp.ele[3];
00256 }
00257
00258 inline void mitkCamera::WorldToView(const float worldPoint[4], float viewPoint[4])
00259 {
00260 mitkVector temp(worldPoint);
00261 temp *= *m_ViewMatrix;
00262 temp *= *m_ProjectionMatrix;
00263 viewPoint[0] = temp.ele[0];
00264 viewPoint[1] = temp.ele[1];
00265 viewPoint[2] = temp.ele[2];
00266 viewPoint[3] = temp.ele[3];
00267 if(!m_ParallelProjection)
00268 {
00269 float ftemp = 1.0f / viewPoint[3];
00270 viewPoint[0] *= ftemp;
00271 viewPoint[1] *= ftemp;
00272 viewPoint[2] *= ftemp;
00273 viewPoint[3] = 1.0f;
00274 }
00275 }
00276
00277 inline void mitkCamera::CameraToView(const float cameraPoint[4], float viewPoint[4])
00278 {
00279 mitkVector temp(cameraPoint);
00280 temp *= *m_ProjectionMatrix;
00281 viewPoint[0] = temp.ele[0];
00282 viewPoint[1] = temp.ele[1];
00283 viewPoint[2] = temp.ele[2];
00284 viewPoint[3] = temp.ele[3];
00285 if(!m_ParallelProjection)
00286 {
00287 float ftemp = 1.0f / viewPoint[3];
00288 viewPoint[0] *= ftemp;
00289 viewPoint[1] *= ftemp;
00290 viewPoint[2] *= ftemp;
00291 viewPoint[3] = 1.0f;
00292 }
00293 }
00294
00295 inline void mitkCamera::CameraToWorld(const float cameraPoint[4], float worldPoint[4])
00296 {
00297 mitkVector temp(cameraPoint);
00298 temp *= *m_InverseViewMatrix;
00299 worldPoint[0] = temp.ele[0];
00300 worldPoint[1] = temp.ele[1];
00301 worldPoint[2] = temp.ele[2];
00302 worldPoint[3] = temp.ele[3];
00303 }
00304
00305 inline void mitkCamera::ViewToWorld(const float viewPoint[4], float worldPoint[4])
00306 {
00307 mitkVector temp(viewPoint);
00308 temp *= *m_InverseProjectionMatrix;
00309 if(!m_ParallelProjection)
00310 {
00311 float ftemp = 1.0f / temp.ele[3];
00312 temp.ele[0] *= ftemp;
00313 temp.ele[1] *= ftemp;
00314 temp.ele[2] *= ftemp;
00315 temp.ele[3] = 1.0f;
00316 }
00317 temp *= *m_InverseViewMatrix;
00318 worldPoint[0] = temp.ele[0];
00319 worldPoint[1] = temp.ele[1];
00320 worldPoint[2] = temp.ele[2];
00321 worldPoint[3] = temp.ele[3];
00322 }
00323
00324 inline void mitkCamera::ViewToCamera(const float viewPoint[4], float cameraPoint[4])
00325 {
00326 mitkVector temp(viewPoint);
00327 temp *= *m_InverseProjectionMatrix;
00328 if(!m_ParallelProjection)
00329 {
00330 float ftemp = 1.0f / temp.ele[3];
00331 temp.ele[0] *= ftemp;
00332 temp.ele[1] *= ftemp;
00333 temp.ele[2] *= ftemp;
00334 temp.ele[3] = 1.0f;
00335 }
00336 cameraPoint[0] = temp.ele[0];
00337 cameraPoint[1] = temp.ele[1];
00338 cameraPoint[2] = temp.ele[2];
00339 cameraPoint[3] = temp.ele[3];
00340 }
00341
00342
00343
00344
00345
00346
00347 #endif
00348
00349
00350
00351
00352