00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __mitkModel_h
00012 #define __mitkModel_h
00013
00014 #include "mitkObject.h"
00015 #include "mitkMatrix.h"
00016 #include "mitkQuaternion.h"
00017 #include "mitkVisualizationIncludes.h"
00018
00019 class mitkScene;
00020 class mitkObserver;
00021
00026 class MITK_VISUALIZATION_API mitkModel : public mitkObject
00027 {
00028 public:
00029 MITK_TYPE(mitkModel,mitkObject)
00030
00031
00032
00033
00034 enum RenderMode
00035 {
00036 Rough,
00037 Medium,
00038 Refined
00039 };
00040
00041 virtual void PrintSelf(ostream& os);
00042
00046 void VisibilityOn(void) {m_Visibility = 1;}
00047
00051 void VisibilityOff(void) {m_Visibility = 0;}
00052
00057 void SetVisibility(int isVisible){m_Visibility = isVisible;}
00058
00063 int GetVisibility(void) const {return m_Visibility;}
00064
00071 virtual int Render(mitkScene *scene) { return 0; }
00072
00080 virtual void Select(mitkScene *scene) {}
00081
00089 void SetOrigin(float x, float y, float z)
00090 {
00091 m_Origin[0] = x;
00092 m_Origin[1] = y;
00093 m_Origin[2] = z;
00094 m_MatrixModified = 1;
00095 }
00096
00104 void SetOrigin(float origin[3])
00105 {
00106 m_Origin[0] = origin[0];
00107 m_Origin[1] = origin[1];
00108 m_Origin[2] = origin[2];
00109 m_MatrixModified = 1;
00110 }
00111
00117 float const * GetOrigin(void) const {return m_Origin;}
00118
00126 void GetOrigin(float origin[3]) const {origin[0] = m_Origin[0]; origin[1] = m_Origin[1]; origin[2] = m_Origin[2];}
00127
00134 void SetTranslation(float x, float y, float z)
00135 {
00136 m_Translation[0] = x;
00137 m_Translation[1] = y;
00138 m_Translation[2] = z;
00139 m_MatrixModified = 1;
00140 }
00141
00148 void SetTranslation(float trans[3])
00149 {
00150 m_Translation[0] = trans[0];
00151 m_Translation[1] = trans[1];
00152 m_Translation[2] = trans[2];
00153 m_MatrixModified = 1;
00154 }
00155
00160 float const * GetTranslation(void) const {return m_Translation;}
00161
00168 void GetTranslation(float trans[3]) const {trans[0] = m_Translation[0]; trans[1] = m_Translation[1]; trans[2] = m_Translation[2];}
00169
00176 void SetRotation(float x, float y, float z)
00177 {
00178 m_Rotation->EulerDegToQuat(x, y, z);
00179 m_MatrixModified = 1;
00180 }
00181
00188 void SetRotation(float rot[3])
00189 {
00190 this->SetRotation(rot[0], rot[1], rot[2]);
00191 }
00192
00197 void SetRotation(const mitkQuaternion &q)
00198 {
00199 *m_Rotation = q;
00200 m_MatrixModified = 1;
00201 }
00202
00210 void SetRotation(float ax, float ay, float az, float angle)
00211 {
00212 m_Rotation->AxisDegToQuat(ax, ay, az, angle);
00213 m_MatrixModified = 1;
00214 }
00215
00220 mitkQuaternion const * GetRotation(void) const {return m_Rotation;}
00221
00228 void GetRotation(float rot[3]) const { m_Rotation->GetEulerDeg(rot[0], rot[1], rot[2]); }
00229
00237 void GetRotation(float &ax, float &ay, float &az, float &angle) const
00238 {
00239 m_Rotation->GetAxisDeg(ax, ay, az, angle);
00240 }
00241
00248 void SetScale(float sx, float sy, float sz)
00249 {
00250 m_Scale[0] = sx;
00251 m_Scale[1] = sy;
00252 m_Scale[2] = sz;
00253 m_MatrixModified = 1;
00254 }
00255
00262 void SetScale(float scale[3])
00263 {
00264 m_Scale[0] = scale[0];
00265 m_Scale[1] = scale[1];
00266 m_Scale[2] = scale[2];
00267 m_MatrixModified = 1;
00268 }
00269
00274 void SetScale(float scale)
00275 {
00276 m_Scale[2] = m_Scale[1] = m_Scale[0] = scale;
00277 m_MatrixModified = 1;
00278 }
00279
00284 float const * GetScale(void) const {return m_Scale;}
00285
00292 void GetScale(float scale[3]) const
00293 {
00294 scale[0] = m_Scale[0];
00295 scale[1] = m_Scale[1];
00296 scale[2] = m_Scale[2];
00297 }
00298
00305 void GetModelMatrix(mitkMatrix *m);
00306
00320 void GetModelMatrix(float m[16]);
00321
00328 mitkMatrix const * GetModelMatrix();
00329
00334 void GetInverseOfModelMatrix(mitkMatrix *m);
00335
00347 void GetInverseOfModelMatrix(float m[16]);
00348
00353 mitkMatrix const * GetInverseOfModelMatrix();
00354
00361 float const * GetBounds();
00362
00370 void GetBounds(float bounds[6]);
00371
00383 void GetBounds(float &xMin, float &xMax, float &yMin, float &yMax, float &zMin, float &zMax);
00384
00389 float const * GetCenter();
00390
00395 void GetCenter(float c[3]);
00396
00401 float GetLength();
00402
00406 void Reset();
00407
00414 void ModelToWorld(float const modelPoint[4], float worldPoint[4]);
00415
00422 void WorldToModel(float const worldPoint[4], float modelPoint[4]);
00423
00429 virtual bool IsOpaque() = 0;
00430
00435 bool GetDataModifyStatus() const {return m_DataChanged;}
00436
00441 void SetDataModifyStatus(bool isModify) {m_DataChanged = isModify;}
00442
00449 void SetRenderMode(RenderMode mode) { m_RenderMode = mode; m_RenderModeChanged=true;}
00450
00456 void SetRenderModeToRough() { m_RenderMode = Rough; m_RenderModeChanged=true;}
00457
00463 void SetRenderModeToMedium() { m_RenderMode = Medium; m_RenderModeChanged=true;}
00464
00470 void SetRenderModeToRefined() { m_RenderMode = Refined; m_RenderModeChanged=true;}
00471
00476 RenderMode GetRenderMode() const { return m_RenderMode; }
00477
00478 void SetRenderModeUnchanged() { m_RenderModeChanged=false;}
00479
00480 bool IsMatrixModified() const { return m_MatrixModified!=0;}
00481 bool IsRenderModeChanged() const {return m_RenderModeChanged;}
00482
00483 protected:
00484 mitkModel();
00485 virtual ~mitkModel();
00486 void _computeMatrix();
00487 virtual float* _getBounds() = 0;
00488
00489 mitkMatrix *m_Matrix;
00490 mitkMatrix *m_InverseMatrix;
00491
00492 mitkQuaternion *m_Rotation;
00493
00494 float m_Origin[3];
00495
00496 float m_Translation[3];
00497
00498 float m_Scale[3];
00499
00500 float m_Center[3];
00501 float m_Bounds[6];
00502
00503 RenderMode m_RenderMode;
00504
00505 short m_Visibility;
00506 short m_MatrixModified;
00507 bool m_DataChanged;
00508 bool m_RenderModeChanged;
00509
00510 private:
00511 mitkModel(const mitkModel&);
00512 void operator=(const mitkModel&);
00513
00514 };
00515
00516
00517 inline void mitkModel::ModelToWorld(float const modelPoint[4], float worldPoint[4])
00518 {
00519 if(m_MatrixModified)
00520 this->_computeMatrix();
00521 mitkVector temp(modelPoint);
00522 temp *= *m_Matrix;
00523 worldPoint[0] = temp.ele[0];
00524 worldPoint[1] = temp.ele[1];
00525 worldPoint[2] = temp.ele[2];
00526 worldPoint[3] = temp.ele[3];
00527 }
00528
00529 inline void mitkModel::WorldToModel(float const worldPoint[4], float modelPoint[4])
00530 {
00531 if(m_MatrixModified)
00532 this->_computeMatrix();
00533 mitkVector temp(worldPoint);
00534 temp *= *m_InverseMatrix;
00535 modelPoint[0] = temp.ele[0];
00536 modelPoint[1] = temp.ele[1];
00537 modelPoint[2] = temp.ele[2];
00538 modelPoint[3] = temp.ele[3];
00539 }
00540
00541
00542
00543
00544
00545
00546 #endif
00547
00548
00549