Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkImageModel.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkImageModel_h
00012 #define __mitkImageModel_h
00013 
00014 #include "mitkDataModel.h"
00015 #include "mitkRCPtr.h"
00016 #include "mitkICVolume.h"
00017 
00033 class MITK_VISUALIZATION_API mitkImageModel : public mitkDataModel
00034 {
00035 public:
00036     MITK_TYPE(mitkImageModel,mitkDataModel)
00037         
00038     virtual void PrintSelf(ostream& os);
00039     
00040     mitkImageModel();   
00041 
00053     enum ViewMode
00054     {
00055         VIEW_XY, 
00056         VIEW_YZ, 
00057         VIEW_XZ  
00058     };
00059 
00064     void SetData(mitkVolume *data);
00065 
00070     mitkVolume* GetData();
00071 
00079     virtual int Render(mitkScene *scene);
00080   
00086     void SetViewMode(ViewMode viewMode);
00087 
00093     ViewMode GetViewMode() const { return m_ViewMode; }
00094     
00099     void SetCurrentSliceNumber(int sliceNo);
00100 
00105     int GetCurrentSliceNumber() const { return m_CurrentSlice; }
00106 
00111     void NextSlice();
00112 
00117     void PrevSlice();
00118 
00123     int GetTotalSliceNumber() const { return m_TotalSlice; }
00124 
00128     int GetWidth() const { return m_TexImageWidth; }
00129 
00133     int GetHeight() const { return m_TexImageHeight; }
00134 
00138     float GetSpacingX() const { return m_Spacings[0]; }
00139 
00143     float GetSpacingY() { return m_Spacings[1]; }
00144 
00148     float GetSpacingZ() const { return m_Spacings[2]; }
00149 
00154     void SetOpacity(float opacity) { m_Opacity = opacity; }
00155 
00160     float GetOpacity() const { return m_Opacity; }
00161 
00166     virtual bool IsOpaque() { return (m_Opacity >= 1.0f); }
00167 
00171     void CleanUp();
00172 
00180     void AdjustWidthCenter(int viewWidth, int viewHeight, float deltX, float deltY);
00181 
00186     float GetWindowWidth() const { return m_WindowWidth; }
00187 
00192     float GetWindowCenter() const { return m_WindowCenter; }
00193 
00198     void SetWindowWidth(float winWidth);
00199 
00204     void SetWindowCenter(float winCenter);
00205 
00209     void ResetWindowWidthCenter();
00210 
00228     void GetDataValueAndCoordinate(float objectX, float objectY, int &vx, int &vy, int &vz, float &rValue, float &gValue, float &bValue) const;
00229 
00241     void GetCoordinate(float objectX, float objectY, int &vx, int &vy, int &vz) const;
00242 
00253     void GetXYCoordinate(float objectX, float objectY, int &vx, int &vy) const;
00254 
00265     void GetXYCoordinate(float objectX, float objectY, float &vx, float &vy) const;
00266 
00275     void GetXYCoordinateDelta(float odx, float ody, float &vdx, float &vdy) const;
00276 
00285     void GetObjectCoordinate(int vx, int vy, float &objX, float &objY);
00286 
00296     void GetObjectCoordinate(int vx, int vy, int vz, float &objX, float &objY);
00297 
00306     float GetActualLength(float opt0[2], float opt1[2]) const;
00307 
00316     float GetActualLength(float x0, float y0, float x1, float y1) const;
00317 
00323     float GetActualXLength(float objXLen) const;
00324 
00330     float GetActualYLength(float objYLen) const;
00331 
00336     unsigned int GetTextureID() const { return m_TexId; }
00337 
00345     void GetIncrements(int incs[3]) const { incs[0] = m_Incs[0]; incs[1] = m_Incs[1]; incs[2] = m_Incs[2]; }
00346 
00353     mitkVolume* GetCurrentSlice();
00354 
00360     void EnablePseudocolor(bool enable = true) { m_EnablePseudocolor = enable; }
00361 
00367     void UpdatePseudocolor(bool rectChanged);
00368 
00369     void SetSliceChanged() { m_CurrentTex = -1; }
00370 
00371 
00372 protected:
00373     virtual ~mitkImageModel();
00374     virtual float* _getBounds();
00375 
00376     mitkRCPtr<mitkVolume> m_Data;
00377 
00378     float m_Opacity;
00379     ViewMode m_ViewMode;
00380     unsigned int m_TexId;
00381     int   m_TexImageWidth, m_TexImageHeight;
00382     float m_RectLeft, m_RectRight;
00383     float m_RectTop,  m_RectBottom;
00384 
00385     int  m_CurrentSlice;
00386     int  m_TotalSlice;
00387 
00388     int  m_CurrentTex;
00389 
00390     float m_Spacings[3];
00391     int   m_Incs[3];
00392 
00393     int   m_DummyTexWidth;
00394     int   m_DummyTexHeight;
00395 
00396     float m_WindowCenter;   
00397     float m_WindowWidth;
00398     float m_DefaultWindowCenter;    
00399     float m_DefaultWindowWidth;
00400 
00401     bool  m_NeedSetDummyTexture;
00402     bool  m_EnablePseudocolor;
00403 
00404 private:
00405     mitkImageModel(const mitkImageModel&);
00406     void operator=(const mitkImageModel&);
00407 
00408 
00409     bool _loadTexture();    
00410     void _switchViewMode();
00411     void _setDummyTexture();
00412 };
00413 
00414 inline void mitkImageModel::GetCoordinate(float objectX, float objectY, int &vx, int &vy, int &vz) const
00415 {
00416 //  float volumeX = (objectX - m_RectLeft) * (m_TexImageWidth - 1.0f) / (m_RectRight - m_RectLeft);
00417 //  float volumeY = (objectY - m_RectBottom) * (m_TexImageHeight - 1.0f) / (m_RectTop - m_RectBottom);
00418     float volumeX = (objectX - m_RectLeft) * (m_TexImageWidth) / (m_RectRight - m_RectLeft);
00419     float volumeY = (objectY - m_RectBottom) * (m_TexImageHeight) / (m_RectTop - m_RectBottom);
00420 
00421     switch(m_ViewMode)
00422     {
00423         case VIEW_XY:
00424             vx = (int) (volumeX + 0.5f);
00425             vy = (int) (volumeY + 0.5f);
00426             vz = m_CurrentSlice;            
00427         break;
00428 
00429         case VIEW_YZ:
00430             vx = m_CurrentSlice;
00431             vy = (int) (volumeX + 0.5f);                
00432             vz = (int) (volumeY + 0.5f);                    
00433         break;
00434 
00435         case VIEW_XZ:
00436             vx = (int) (volumeX + 0.5f);
00437             vy = m_CurrentSlice;                
00438             vz = (int) (volumeY + 0.5f);                    
00439         break;
00440     }
00441 }
00442 
00443 inline void mitkImageModel::GetXYCoordinate(float objectX, float objectY, int &vx, int &vy) const
00444 {
00445     vx = (int)((objectX - m_RectLeft) * m_TexImageWidth / (m_RectRight - m_RectLeft) + 0.5);
00446     vy = (int)((objectY - m_RectBottom) * m_TexImageHeight / (m_RectTop - m_RectBottom) + 0.5);
00447 }
00448 
00449 inline void mitkImageModel::GetXYCoordinate(float objectX, float objectY, float &vx, float &vy) const
00450 {
00451     vx = (objectX - m_RectLeft) * (float)m_TexImageWidth / (m_RectRight - m_RectLeft);
00452     vy = (objectY - m_RectBottom) * (float)m_TexImageHeight / (m_RectTop - m_RectBottom);
00453 }
00454 
00455 inline void mitkImageModel::GetXYCoordinateDelta(float odx, float ody, float &vdx, float &vdy) const
00456 {
00457     vdx = this->GetActualXLength(odx);
00458     vdy = this->GetActualYLength(ody);
00459 }
00460 
00461 inline float mitkImageModel::GetActualXLength(float objXLen) const
00462 {
00463     return (objXLen * (float)m_TexImageWidth / (m_RectRight - m_RectLeft));
00464 }
00465 
00466 inline float mitkImageModel::GetActualYLength(float objYLen) const
00467 {
00468     return (objYLen * (float)m_TexImageHeight / (m_RectBottom - m_RectTop));
00469 }
00470 
00471 inline float mitkImageModel::GetActualLength(float x0, float y0, float x1, float y1) const
00472 {
00473     float xlen = this->GetActualXLength(x1-x0);
00474     float ylen = this->GetActualYLength(y1-y0);
00475     return (sqrtf(xlen*xlen + ylen*ylen));
00476 }
00477 
00478 inline float mitkImageModel::GetActualLength(float opt0[2], float opt1[2]) const
00479 {
00480     return this->GetActualLength(opt0[0], opt0[1], opt1[0], opt1[1]);
00481 }
00482 
00483  
00484 //#define DEFINED_mitkImageModel
00485  
00486 
00487 
00488 #endif
00489 

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3