├── NMRI ├── res │ ├── NMRI.ico │ ├── NMRI.rc2 │ ├── NMRIDoc.ico │ ├── Toolbar.bmp │ ├── Toolbar256.bmp │ ├── properties.bmp │ ├── properties_hc.bmp │ ├── properties_wnd.ico │ └── properties_wnd_hc.ico ├── UserImages.bmp ├── stdafx.cpp ├── NMRI.vcxproj.user ├── targetver.h ├── FFT.cpp ├── NMRI.h ├── NMRIDoc.h ├── NMRIView.h ├── NMRIFile.cpp ├── MainFrm.h ├── MemoryBitmap.h ├── stdafx.h ├── resource.h ├── PropertiesWnd.h ├── NMRIFile.h ├── VTKView.h ├── NMRIDoc.cpp ├── NMRI.vcxproj.filters ├── MemoryBitmap.cpp ├── NMRIView.cpp ├── NMRI.cpp ├── ReadMe.txt ├── PropertiesWnd.cpp ├── FFT.h ├── MainFrm.cpp ├── NMRI.rc ├── VTKView.cpp └── NMRI.vcxproj ├── .gitignore ├── NMRI.sln ├── README.md └── LICENSE /NMRI/res/NMRI.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/NMRI.ico -------------------------------------------------------------------------------- /NMRI/res/NMRI.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/NMRI.rc2 -------------------------------------------------------------------------------- /NMRI/UserImages.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/UserImages.bmp -------------------------------------------------------------------------------- /NMRI/res/NMRIDoc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/NMRIDoc.ico -------------------------------------------------------------------------------- /NMRI/res/Toolbar.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/Toolbar.bmp -------------------------------------------------------------------------------- /NMRI/res/Toolbar256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/Toolbar256.bmp -------------------------------------------------------------------------------- /NMRI/res/properties.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/properties.bmp -------------------------------------------------------------------------------- /NMRI/res/properties_hc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/properties_hc.bmp -------------------------------------------------------------------------------- /NMRI/res/properties_wnd.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/properties_wnd.ico -------------------------------------------------------------------------------- /NMRI/res/properties_wnd_hc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aromanro/NMRI/HEAD/NMRI/res/properties_wnd_hc.ico -------------------------------------------------------------------------------- /NMRI/stdafx.cpp: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.cpp : source file that includes just the standard includes 3 | // NMRI.pch will be the pre-compiled header 4 | // stdafx.obj will contain the pre-compiled type information 5 | 6 | #include "stdafx.h" 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .vs/NMRI/v15/.suo 3 | *.db 4 | *.ipch 5 | .vs/NMRI/v16/.suo 6 | *.dat 7 | *.obj 8 | *.APS 9 | *.log 10 | *.pch 11 | *.res 12 | *.tlog 13 | *.txt 14 | *.pdb 15 | *.lastcodeanalysissucceeded 16 | *.iobj 17 | *.ipdb 18 | *.exe 19 | -------------------------------------------------------------------------------- /NMRI/NMRI.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | NMRI.rc 5 | 6 | -------------------------------------------------------------------------------- /NMRI/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /NMRI/FFT.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "FFT.h" 4 | 5 | namespace Fourier { 6 | const int FFT::init = fftw_init_threads(); 7 | 8 | std::mutex FFTWPlan::planMutex; 9 | 10 | FFT::FFT(int numThreads) 11 | { 12 | if (numThreads != 0) SetNumThreads(numThreads); 13 | } 14 | 15 | void FFT::SetNumThreads(int numThreads) 16 | { 17 | Clear(); 18 | 19 | std::lock_guard lock(FFTWPlan::planMutex); 20 | 21 | fftw_plan_with_nthreads(numThreads); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /NMRI/NMRI.h: -------------------------------------------------------------------------------- 1 | 2 | // NMRI.h : main header file for the NMRI application 3 | // 4 | #pragma once 5 | 6 | #ifndef __AFXWIN_H__ 7 | #error "include 'stdafx.h' before including this file for PCH" 8 | #endif 9 | 10 | #include "resource.h" // main symbols 11 | 12 | 13 | // CNMRIApp: 14 | // See NMRI.cpp for the implementation of this class 15 | // 16 | 17 | class CNMRIApp : public CWinAppEx 18 | { 19 | public: 20 | CNMRIApp(); 21 | 22 | // Implementation 23 | UINT m_nAppLook; 24 | BOOL m_bHiColorIcons; 25 | 26 | private: 27 | // Overrides 28 | BOOL InitInstance() override; 29 | void PreLoadState() override; 30 | void LoadCustomState() override; 31 | void SaveCustomState() override; 32 | 33 | afx_msg void OnAppAbout(); 34 | DECLARE_MESSAGE_MAP() 35 | }; 36 | 37 | extern CNMRIApp theApp; 38 | -------------------------------------------------------------------------------- /NMRI/NMRIDoc.h: -------------------------------------------------------------------------------- 1 | 2 | // NMRIDoc.h : interface of the CNMRIDoc class 3 | // 4 | 5 | 6 | #pragma once 7 | 8 | 9 | #include "NMRIFile.h" 10 | 11 | class CNMRIDoc : public CDocument 12 | { 13 | protected: // create from serialization only 14 | CNMRIDoc() = default; 15 | DECLARE_DYNCREATE(CNMRIDoc) 16 | 17 | // Attributes 18 | public: 19 | NMRIFile theFile; 20 | 21 | bool animate = true; 22 | 23 | bool colorFunction = true; 24 | bool opacityFunction = true; 25 | bool gradientFunction = true; 26 | int opacityVal = 50; 27 | int gradientVal = 50; 28 | 29 | // Operations 30 | bool Load(const CString& name); 31 | void UpdateViews(); 32 | void Update3DOptions(); 33 | 34 | private: 35 | // Overrides 36 | BOOL OnNewDocument() override; 37 | void Serialize(CArchive& ar) override; 38 | #ifdef SHARED_HANDLERS 39 | void InitializeSearchContent() override; 40 | void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) override; 41 | #endif // SHARED_HANDLERS 42 | 43 | // Implementation 44 | #ifdef _DEBUG 45 | void AssertValid() const override; 46 | void Dump(CDumpContext& dc) const override; 47 | #endif 48 | 49 | // Generated message map functions 50 | DECLARE_MESSAGE_MAP() 51 | 52 | #ifdef SHARED_HANDLERS 53 | // Helper function that sets search content for a Search Handler 54 | void SetSearchContent(const CString& value); 55 | #endif // SHARED_HANDLERS 56 | }; 57 | -------------------------------------------------------------------------------- /NMRI.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.12 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NMRI", "NMRI\NMRI.vcxproj", "{0419845C-98D5-4E5F-8880-19315E366367}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0419845C-98D5-4E5F-8880-19315E366367}.Debug|x64.ActiveCfg = Debug|x64 17 | {0419845C-98D5-4E5F-8880-19315E366367}.Debug|x64.Build.0 = Debug|x64 18 | {0419845C-98D5-4E5F-8880-19315E366367}.Debug|x86.ActiveCfg = Debug|Win32 19 | {0419845C-98D5-4E5F-8880-19315E366367}.Debug|x86.Build.0 = Debug|Win32 20 | {0419845C-98D5-4E5F-8880-19315E366367}.Release|x64.ActiveCfg = Release|x64 21 | {0419845C-98D5-4E5F-8880-19315E366367}.Release|x64.Build.0 = Release|x64 22 | {0419845C-98D5-4E5F-8880-19315E366367}.Release|x86.ActiveCfg = Release|Win32 23 | {0419845C-98D5-4E5F-8880-19315E366367}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {223E4B78-3A33-4BE1-B565-953761FC21E2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NMRI 2 | 2D Fourier Transform of Nuclear Magnetic Resonance Imaging raw data, 3D visualization with VTK 3 | 4 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/9249fa3267d84c819fc48af840b73392)](https://app.codacy.com/gh/aromanro/NMRI?utm_source=github.com&utm_medium=referral&utm_content=aromanro/NMRI&utm_campaign=Badge_Grade_Settings) 5 | [![CodeFactor](https://www.codefactor.io/repository/github/aromanro/nmri/badge)](https://www.codefactor.io/repository/github/aromanro/nmri) 6 | 7 | Description on https://compphys.go.ro/nuclear-magnetic-resonance-and-fourier-transform/ 8 | 9 | Basically this is a quickly implemented project to test some wrapper classes for FFTW library: http://www.fftw.org/ Obviously, the project needs the FFTW library. 10 | A later addition was the 3D visualization, using VTK: https://vtk.org/ 11 | 12 | It's a 2D Fourier Transform of Nuclear Magnetic Resonance Imaging raw data. It displays both the raw data and the image, allows cutting out low and high frequency information. 13 | It also has a 3D view implemented with VTK. 14 | 15 | It needs the Head2D.dat raw data file one can find here: http://download.nvidia.com/developer/GPU_Gems_2/CD/Index.html in the source tree from Chap. 48, Medical Image Reconstruction with the FFT. 16 | By the way, here is the chapter, in case somebody wants to look over it: https://developer.nvidia.com/gpugems/GPUGems2/gpugems2_chapter48.html 17 | 18 | ### PROGRAM IN ACTION 19 | 20 | [![Program video](https://img.youtube.com/vi/toGlT4gNKds/0.jpg)](https://youtu.be/toGlT4gNKds) 21 | -------------------------------------------------------------------------------- /NMRI/NMRIView.h: -------------------------------------------------------------------------------- 1 | 2 | // NMRIView.h : interface of the CNMRIView class 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | #include "MemoryBitmap.h" 9 | 10 | class CNMRIView : public CView 11 | { 12 | protected: // create from serialization only 13 | CNMRIView() = default; 14 | DECLARE_DYNCREATE(CNMRIView) 15 | 16 | // Attributes 17 | public: 18 | CNMRIDoc* GetDocument() const; 19 | 20 | // Operations 21 | // Overrides 22 | private: 23 | void OnDraw(CDC* pDC) override; // overridden to draw this view 24 | BOOL PreCreateWindow(CREATESTRUCT& cs) override; 25 | BOOL OnPreparePrinting(CPrintInfo* pInfo) override; 26 | void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) override; 27 | void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) override; 28 | 29 | // Implementation 30 | #ifdef _DEBUG 31 | void AssertValid() const override; 32 | void Dump(CDumpContext& dc) const override; 33 | #endif 34 | 35 | MemoryBitmap img1; 36 | MemoryBitmap img2; 37 | 38 | int theFrame = 0; 39 | UINT_PTR timer = 0; 40 | 41 | // Generated message map functions 42 | afx_msg void OnFilePrintPreview(); 43 | afx_msg void OnRButtonUp(UINT nFlags, CPoint point); 44 | afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); 45 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 46 | afx_msg void OnDestroy(); 47 | afx_msg BOOL OnEraseBkgnd(CDC* pDC); 48 | afx_msg void OnTimer(UINT_PTR nIDEvent); 49 | 50 | DECLARE_MESSAGE_MAP() 51 | }; 52 | 53 | #ifndef _DEBUG // debug version in NMRIView.cpp 54 | inline CNMRIDoc* CNMRIView::GetDocument() const 55 | { return reinterpret_cast(m_pDocument); } 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /NMRI/NMRIFile.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "NMRIFile.h" 3 | 4 | 5 | NMRIFile::NMRIFile() 6 | : filterHighFreqs(false), filterLowFreqs(false), NrFrames(0), Width(0), Height(0), themax(0), realData(nullptr), imgData(nullptr), theFrame(nullptr), srcFrame(nullptr), fft(4) 7 | { 8 | } 9 | 10 | 11 | NMRIFile::~NMRIFile() 12 | { 13 | delete[] srcFrame; 14 | delete[] theFrame; 15 | delete[] realData; 16 | delete[] imgData; 17 | } 18 | 19 | 20 | bool NMRIFile::Load(const CString& name) 21 | { 22 | FILE *f = nullptr; 23 | if (_wfopen_s(&f, (LPCWSTR)name, L"rb")) return false; 24 | 25 | fread(&NrFrames,sizeof(int),1,f); 26 | fread(&Width,sizeof(int),1,f); 27 | fread(&Height,sizeof(int),1,f); 28 | 29 | const int Size = Width * Height * NrFrames; 30 | 31 | delete[] realData; 32 | delete[] imgData; 33 | delete[] theFrame; 34 | delete[] srcFrame; 35 | 36 | fft.Clear(); 37 | 38 | themax = 0; 39 | 40 | if (Size) 41 | { 42 | realData = new float[Size]; 43 | imgData = new float[Size]; 44 | 45 | fread(realData, sizeof(float)*Size, 1, f); 46 | fread(imgData, sizeof(float)*Size, 1, f); 47 | 48 | theFrame = new std::complex[Width*Height]; 49 | srcFrame = new std::complex[Width*Height]; 50 | } 51 | else 52 | { 53 | realData = nullptr; 54 | imgData = nullptr; 55 | theFrame = nullptr; 56 | srcFrame = nullptr; 57 | } 58 | 59 | fclose(f); 60 | 61 | for (int frame = 0; frame < NrFrames; ++frame) 62 | for (int x = 0; x < Width; ++x) 63 | for (int y = 0; y < Height; ++y) 64 | { 65 | const std::complex val = GetValue(frame, x, y); 66 | 67 | if (themax < std::norm(val)) themax = std::norm(val); 68 | } 69 | 70 | return true; 71 | } 72 | -------------------------------------------------------------------------------- /NMRI/MainFrm.h: -------------------------------------------------------------------------------- 1 | 2 | // MainFrm.h : interface of the CMainFrame class 3 | // 4 | 5 | #pragma once 6 | #include "PropertiesWnd.h" 7 | 8 | class CMainFrame : public CFrameWndEx 9 | { 10 | protected: // create from serialization only 11 | CMainFrame(); 12 | DECLARE_DYNCREATE(CMainFrame) 13 | 14 | // Attributes 15 | // Operations 16 | void Init(); 17 | 18 | private: 19 | // Overrides 20 | BOOL PreCreateWindow(CREATESTRUCT& cs) override; 21 | BOOL LoadFrame(UINT nIDResource, DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, CWnd* pParentWnd = nullptr, CCreateContext* pContext = nullptr) override; 22 | 23 | // Implementation 24 | #ifdef _DEBUG 25 | void AssertValid() const override; 26 | void Dump(CDumpContext& dc) const override; 27 | #endif 28 | 29 | // control bar embedded members 30 | CMFCMenuBar m_wndMenuBar; 31 | CMFCToolBar m_wndToolBar; 32 | CMFCStatusBar m_wndStatusBar; 33 | CMFCToolBarImages m_UserImages; 34 | 35 | CSplitterWnd m_wndSplitter; 36 | 37 | CPropertiesWnd m_wndProperties; 38 | 39 | // Generated message map functions 40 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 41 | afx_msg void OnViewCustomize(); 42 | afx_msg LRESULT OnToolbarCreateNew(WPARAM wp, LPARAM lp); 43 | afx_msg void OnApplicationLook(UINT id); 44 | afx_msg void OnUpdateApplicationLook(CCmdUI* pCmdUI); 45 | BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) override; 46 | 47 | DECLARE_MESSAGE_MAP() 48 | 49 | BOOL CreateDockingWindows(); 50 | void SetDockingWindowIcons(BOOL bHiColorIcons); 51 | 52 | afx_msg void OnFileOpen(); 53 | afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); 54 | afx_msg void OnViewAnimation(); 55 | afx_msg void OnUpdateViewAnimation(CCmdUI* pCmdUI); 56 | }; 57 | 58 | 59 | -------------------------------------------------------------------------------- /NMRI/MemoryBitmap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class MemoryBitmap 6 | { 7 | public: 8 | MemoryBitmap() = default; 9 | MemoryBitmap(const MemoryBitmap& other); // copy constructor 10 | MemoryBitmap(MemoryBitmap&& other) noexcept; // move constructor 11 | MemoryBitmap& operator=(const MemoryBitmap& other); //copy assignment operator 12 | MemoryBitmap& operator=(MemoryBitmap&& other) noexcept; // move assignment operator 13 | 14 | ~MemoryBitmap() noexcept; 15 | 16 | void SetSize(int width, int height); 17 | 18 | void SetMatrix(const double* results, int Width, int Height); 19 | void SetMatrix(const std::complex* results, int Width, int Height); 20 | 21 | void Draw(CDC* pDC) const; 22 | void Draw(CDC* pDC, CRect& rect, int origWidth = 0, int origHeight = 0) const; 23 | 24 | private: 25 | int m_width = 0; 26 | int m_height = 0; 27 | 28 | unsigned char* data = nullptr; 29 | 30 | inline int GetStrideLength() const { 31 | return 4 * ((m_width * 3 + 3) / 4); 32 | } 33 | 34 | inline COLORREF ConvertToColor(double value, int colorType, double minVal, double maxVal) const 35 | { 36 | COLORREF color = 0; 37 | 38 | if (value < minVal) value = minVal; 39 | else if (value > maxVal) value = maxVal; 40 | 41 | if (const double interval = maxVal - minVal; 0 == colorType) // two colors 42 | { 43 | const int B = static_cast((value - minVal) / interval * 255.); 44 | const int R = 255 - B; 45 | 46 | color = RGB(R, 0, B); 47 | } 48 | else if (int v = static_cast((value - minVal) / interval * 255. * 2.); v > 0xff) 49 | { 50 | v -= 0xff; 51 | 52 | const int B = v; 53 | const int G = 255 - v; 54 | 55 | color = RGB(0, G, B); 56 | } 57 | else 58 | { 59 | const int G = v; 60 | const int R = 255 - v; 61 | 62 | color = RGB(R, G, 0); 63 | } 64 | 65 | return color; 66 | } 67 | }; 68 | 69 | -------------------------------------------------------------------------------- /NMRI/stdafx.h: -------------------------------------------------------------------------------- 1 | 2 | // stdafx.h : include file for standard system include files, 3 | // or project specific include files that are used frequently, 4 | // but are changed infrequently 5 | 6 | #pragma once 7 | 8 | #ifndef VC_EXTRALEAN 9 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 10 | #endif 11 | 12 | #include "targetver.h" 13 | 14 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit 15 | 16 | // turns off MFC's hiding of some common and often safely ignored warning messages 17 | #define _AFX_ALL_WARNINGS 18 | 19 | #include // MFC core and standard components 20 | #include // MFC extensions 21 | 22 | 23 | 24 | 25 | 26 | #ifndef _AFX_NO_OLE_SUPPORT 27 | #include // MFC support for Internet Explorer 4 Common Controls 28 | #endif 29 | #ifndef _AFX_NO_AFXCMN_SUPPORT 30 | #include // MFC support for Windows Common Controls 31 | #endif // _AFX_NO_AFXCMN_SUPPORT 32 | 33 | #include // MFC support for ribbons and control bars 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | #ifdef _UNICODE 44 | #if defined _M_IX86 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #elif defined _M_X64 47 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 48 | #else 49 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 50 | #endif 51 | #endif 52 | 53 | 54 | -------------------------------------------------------------------------------- /NMRI/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by NMRI.rc 4 | // 5 | #define IDD_ABOUTBOX 100 6 | #define ID_STATUSBAR_PANE1 120 7 | #define ID_STATUSBAR_PANE2 121 8 | #define IDS_STATUS_PANE1 122 9 | #define IDS_STATUS_PANE2 123 10 | #define IDS_TOOLBAR_STANDARD 124 11 | #define IDS_TOOLBAR_CUSTOMIZE 125 12 | #define ID_VIEW_CUSTOMIZE 126 13 | #define IDR_MAINFRAME 128 14 | #define IDR_MAINFRAME_256 129 15 | #define IDR_NMRITYPE 130 16 | #define ID_VIEW_PROPERTIESWND 150 17 | #define IDS_PROPERTIES_WND 158 18 | #define IDI_PROPERTIES_WND 167 19 | #define IDI_PROPERTIES_WND_HC 168 20 | #define IDR_THEME_MENU 200 21 | #define ID_SET_STYLE 201 22 | #define ID_VIEW_APPLOOK_WIN_2000 205 23 | #define ID_VIEW_APPLOOK_OFF_XP 206 24 | #define ID_VIEW_APPLOOK_WIN_XP 207 25 | #define ID_VIEW_APPLOOK_OFF_2003 208 26 | #define ID_VIEW_APPLOOK_VS_2005 209 27 | #define ID_VIEW_APPLOOK_VS_2008 210 28 | #define ID_VIEW_APPLOOK_OFF_2007_BLUE 215 29 | #define ID_VIEW_APPLOOK_OFF_2007_BLACK 216 30 | #define ID_VIEW_APPLOOK_OFF_2007_SILVER 217 31 | #define ID_VIEW_APPLOOK_OFF_2007_AQUA 218 32 | #define ID_VIEW_APPLOOK_WINDOWS_7 219 33 | #define IDS_EDIT_MENU 306 34 | #define IDC_MFCLINK1 1000 35 | #define IDC_MFCLINK2 1001 36 | #define ID_FILE_OEN 32771 37 | #define ID_VIEW_ 32772 38 | #define ID_VIEW_ANIMATION 32773 39 | #define ID_BUTTON32775 32775 40 | 41 | // Next default values for new objects 42 | // 43 | #ifdef APSTUDIO_INVOKED 44 | #ifndef APSTUDIO_READONLY_SYMBOLS 45 | #define _APS_NEXT_RESOURCE_VALUE 311 46 | #define _APS_NEXT_COMMAND_VALUE 32776 47 | #define _APS_NEXT_CONTROL_VALUE 1001 48 | #define _APS_NEXT_SYMED_VALUE 310 49 | #endif 50 | #endif 51 | -------------------------------------------------------------------------------- /NMRI/PropertiesWnd.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | class CNMRIDoc; 5 | 6 | 7 | // for CSliderProp and CPropSliderCtrl see: https://github.com/jhlee8804/MFC-Feature-Pack/tree/master/NewControls 8 | // modified to allow setting a range 9 | 10 | class CSliderProp : public CMFCPropertyGridProperty 11 | { 12 | public: 13 | CSliderProp(const CString& strName, long nValue, long minVal = 0, long maxVal = 100, LPCTSTR lpszDescr = nullptr, DWORD dwData = 0); 14 | 15 | BOOL OnUpdateValue() override; 16 | 17 | private: 18 | CWnd* CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat) override; 19 | BOOL OnSetCursor() const override { return FALSE; /* Use default */ } 20 | 21 | long m_minVal; 22 | long m_maxVal; 23 | }; 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // CPropSliderCtrl window 27 | 28 | class CPropSliderCtrl : public CSliderCtrl 29 | { 30 | // Construction 31 | public: 32 | CPropSliderCtrl(CSliderProp* pProp, COLORREF clrBack); 33 | 34 | // Attributes 35 | private: 36 | CBrush m_brBackground; 37 | COLORREF m_clrBack; 38 | CSliderProp* m_pProp; 39 | 40 | // Implementation 41 | 42 | //{{AFX_MSG(CPropSliderCtrl) 43 | afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); 44 | //}}AFX_MSG 45 | afx_msg void HScroll(UINT nSBCode, UINT nPos); 46 | 47 | DECLARE_MESSAGE_MAP() 48 | }; 49 | 50 | 51 | class CPropertiesWnd : public CDockablePane 52 | { 53 | // Construction 54 | public: 55 | void AdjustLayout() override; 56 | 57 | // Attributes 58 | void SetVSDotNetLook(BOOL bSet) 59 | { 60 | m_wndPropList.SetVSDotNetLook(bSet); 61 | m_wndPropList.SetGroupNameFullWidth(bSet); 62 | } 63 | 64 | CNMRIDoc* theDoc = nullptr; 65 | 66 | private: 67 | CMFCPropertyGridCtrl m_wndPropList; 68 | 69 | // Implementation 70 | void InitPropList(); 71 | 72 | afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 73 | afx_msg void OnSize(UINT nType, int cx, int cy); 74 | afx_msg void OnSetFocus(CWnd* pOldWnd); 75 | afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection); 76 | afx_msg LRESULT OnPropertyChanged(__in WPARAM wparam, __in LPARAM lparam); 77 | 78 | DECLARE_MESSAGE_MAP() 79 | }; 80 | 81 | -------------------------------------------------------------------------------- /NMRI/NMRIFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "FFT.h" 6 | 7 | class NMRIFile 8 | { 9 | public: 10 | NMRIFile(); 11 | ~NMRIFile(); 12 | 13 | bool filterHighFreqs; 14 | bool filterLowFreqs; 15 | 16 | int NrFrames; 17 | int Width; 18 | int Height; 19 | 20 | int LowPassPercentage = 50; 21 | int HighPassPercentage = 50; 22 | 23 | bool Load(const CString& name); 24 | 25 | void FFT(int frame) 26 | { 27 | if (!Width || !Height) return; 28 | 29 | // this is done due of the order of the frames in the file! 30 | if (frame % 2) frame = frame / 2; 31 | else frame = NrFrames / 2 + frame / 2; 32 | 33 | Filter(frame); 34 | fft.fwd(srcFrame, theFrame, Width, Height); 35 | 36 | Normalize(); 37 | } 38 | 39 | inline double GetRealValue(int posx, int posy) const 40 | { 41 | return std::abs(theFrame[Height*posx + posy]); 42 | } 43 | 44 | const std::complex* GetRealFrame() const { return theFrame; } 45 | const std::complex* GetFrame() const { return srcFrame; } 46 | 47 | private: 48 | inline std::complex GetValue(int frame, int posx, int posy) const 49 | { 50 | if (frame >= NrFrames) return std::complex(0, 0); 51 | 52 | const int pos = Width * Height * frame; 53 | 54 | const float re = realData[pos + Height * posx + posy]; 55 | const float im = imgData[pos + Height * posx + posy]; 56 | 57 | return std::complex(re, im); 58 | } 59 | 60 | inline void Normalize() 61 | { 62 | const double thenorm = sqrt(Width * Height); 63 | 64 | for (int x = 0; x < Width; ++x) 65 | for (int y = 0; y < Height; ++y) 66 | theFrame[y * Width + x] /= thenorm; 67 | } 68 | 69 | inline void Filter(int frame) 70 | { 71 | const double xCenter = Width / 2.; 72 | const double yCenter = Height / 2.; 73 | 74 | const double xLowPass = Width / 32. * LowPassPercentage / 100.; 75 | const double yLowPass = Height / 32. * LowPassPercentage / 100.; 76 | 77 | const double xLowLowLimit = xCenter - xLowPass; 78 | const double xHighLowLimit = xCenter + xLowPass; 79 | const double yLowLowLimit = yCenter - yLowPass; 80 | const double yHighLowLimit = yCenter + yLowPass; 81 | 82 | const double xHighPass = Width / 4. * (2. - HighPassPercentage / 100.); 83 | const double yHighPass = Height / 4. * (2. - HighPassPercentage / 100.); 84 | 85 | 86 | const double xLowHighLimit = xCenter - xHighPass; 87 | const double xHighHighLimit = xCenter + xHighPass; 88 | const double yLowHighLimit = yCenter - yHighPass; 89 | const double yHighHighLimit = yCenter + yHighPass; 90 | 91 | for (int x = 0; x < Width; ++x) 92 | for (int y = 0; y < Height; ++y) 93 | { 94 | if (filterLowFreqs && x > xLowLowLimit && x < xHighLowLimit && y > yLowLowLimit && y < yHighLowLimit) 95 | { 96 | srcFrame[y * Width + x] = 0; 97 | continue; 98 | } 99 | 100 | if (filterHighFreqs && (x < xLowHighLimit || x > xHighHighLimit || y < yLowHighLimit || y > yHighHighLimit)) 101 | { 102 | srcFrame[y * Width + x] = 0; 103 | continue; 104 | } 105 | 106 | const std::complex val = GetValue(frame, x, y); 107 | srcFrame[y * Width + x] = (themax > 1E-14 ? val / themax : val); 108 | } 109 | } 110 | 111 | double themax; 112 | 113 | float* realData; 114 | float* imgData; 115 | 116 | std::complex* theFrame; 117 | std::complex* srcFrame; 118 | 119 | Fourier::FFT fft; 120 | }; 121 | 122 | -------------------------------------------------------------------------------- /NMRI/VTKView.h: -------------------------------------------------------------------------------- 1 | 2 | // VTKView.h : interface of the CVTKView class 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | #ifdef _DEBUG 9 | #define new ::new 10 | #endif 11 | 12 | #include 13 | //#include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | 48 | 49 | #ifdef _DEBUG 50 | #undef new 51 | #endif 52 | 53 | 54 | class CVTKView; 55 | 56 | // class stolen from VTK examples and modified 57 | 58 | class ErrorObserver : public vtkCommand 59 | { 60 | public: 61 | static ErrorObserver *New(); 62 | 63 | bool GetError() const 64 | { 65 | return Error; 66 | } 67 | 68 | bool GetWarning() const 69 | { 70 | return Warning; 71 | } 72 | 73 | void Clear() 74 | { 75 | Error = false; 76 | Warning = false; 77 | ErrorMessage = ""; 78 | WarningMessage = ""; 79 | } 80 | 81 | void Execute(vtkObject *vtkNotUsed(caller), unsigned long event, void *calldata) override; 82 | 83 | std::string GetErrorMessage() const 84 | { 85 | return ErrorMessage; 86 | } 87 | 88 | std::string GetWarningMessage() const 89 | { 90 | return WarningMessage; 91 | } 92 | 93 | void SetView(CVTKView* view) 94 | { 95 | theView = view; 96 | } 97 | 98 | private: 99 | CVTKView* theView = nullptr; 100 | bool Error = false; 101 | bool Warning = false; 102 | std::string ErrorMessage; 103 | std::string WarningMessage; 104 | }; 105 | 106 | 107 | class CVTKView : public CView 108 | { 109 | protected: // create from serialization only 110 | CVTKView(); 111 | DECLARE_DYNCREATE(CVTKView) 112 | 113 | static bool IsHandledMessage(UINT message); 114 | 115 | public: 116 | ~CVTKView() override; 117 | CNMRIDoc* GetDocument() const; 118 | 119 | // Operations 120 | void RecoverFromWarning(); 121 | void GrabResultsFromDoc(); 122 | void UpdateTransferFunctions(); 123 | 124 | private: 125 | // Overrides 126 | void OnDraw(CDC* pDC) override; // overridden to draw this view 127 | BOOL OnPreparePrinting(CPrintInfo* pInfo) override; 128 | void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) override; 129 | void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) override; 130 | 131 | // Implementation 132 | void Pipeline(); 133 | 134 | #ifdef _DEBUG 135 | void AssertValid() const override; 136 | void Dump(CDumpContext& dc) const override; 137 | #endif 138 | 139 | ErrorObserver* errorObserver = nullptr; 140 | vtkImageData* dataImage = nullptr; 141 | 142 | vtkWin32OpenGLRenderWindow *renWin; 143 | vtkRenderer *ren = nullptr; 144 | vtkWin32RenderWindowInteractor *iren = nullptr; 145 | 146 | vtkGPUVolumeRayCastMapper* volumeMapper = nullptr; 147 | vtkVolume* volume = nullptr; 148 | 149 | vtkSmartPointer textActor; 150 | 151 | unsigned int Width = 0; 152 | unsigned int Height = 0; 153 | unsigned int NrFrames = 0; 154 | 155 | // Generated message map functions 156 | afx_msg void OnFilePrintPreview(); 157 | afx_msg void OnSize(UINT nType, int cx, int cy); 158 | afx_msg BOOL OnEraseBkgnd(CDC* pDC); 159 | void OnInitialUpdate() override; 160 | LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) override; 161 | afx_msg void OnDestroy(); 162 | //afx_msg void OnTimer(UINT_PTR nIDEvent); 163 | 164 | DECLARE_MESSAGE_MAP() 165 | }; 166 | 167 | #ifndef _DEBUG // debug version in DFTView.cpp 168 | inline CNMRIDoc* CVTKView::GetDocument() const 169 | { return reinterpret_cast(m_pDocument); } 170 | #endif 171 | 172 | -------------------------------------------------------------------------------- /NMRI/NMRIDoc.cpp: -------------------------------------------------------------------------------- 1 | 2 | // NMRIDoc.cpp : implementation of the CNMRIDoc class 3 | // 4 | 5 | #include "stdafx.h" 6 | // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail 7 | // and search filter handlers and allows sharing of document code with that project. 8 | #ifndef SHARED_HANDLERS 9 | #include "NMRI.h" 10 | #endif 11 | 12 | #include "NMRIDoc.h" 13 | 14 | #include "NMRIFile.h" 15 | #include "MainFrm.h" 16 | 17 | #include "VTKView.h" 18 | 19 | #include 20 | 21 | #ifdef _DEBUG 22 | #define new DEBUG_NEW 23 | #endif 24 | 25 | // CNMRIDoc 26 | 27 | IMPLEMENT_DYNCREATE(CNMRIDoc, CDocument) 28 | 29 | BEGIN_MESSAGE_MAP(CNMRIDoc, CDocument) 30 | END_MESSAGE_MAP() 31 | 32 | 33 | // CNMRIDoc construction/destruction 34 | 35 | BOOL CNMRIDoc::OnNewDocument() 36 | { 37 | if (!CDocument::OnNewDocument()) 38 | return FALSE; 39 | 40 | // TODO: add reinitialization code here 41 | // (SDI documents will reuse this document) 42 | 43 | if (Load(L"Head2D.dat")) 44 | SetTitle(L"Head2D"); 45 | else 46 | SetTitle(L"No file loaded"); 47 | 48 | return TRUE; 49 | } 50 | 51 | 52 | 53 | 54 | // CNMRIDoc serialization 55 | 56 | void CNMRIDoc::Serialize(CArchive& ar) 57 | { 58 | if (ar.IsStoring()) 59 | { 60 | // TODO: add storing code here 61 | } 62 | else 63 | { 64 | // TODO: add loading code here 65 | } 66 | } 67 | 68 | #ifdef SHARED_HANDLERS 69 | 70 | // Support for thumbnails 71 | void CNMRIDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) 72 | { 73 | // Modify this code to draw the document's data 74 | dc.FillSolidRect(lprcBounds, RGB(255, 255, 255)); 75 | 76 | CString strText = _T("TODO: implement thumbnail drawing here"); 77 | LOGFONT lf; 78 | 79 | CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); 80 | pDefaultGUIFont->GetLogFont(&lf); 81 | lf.lfHeight = 36; 82 | 83 | CFont fontDraw; 84 | fontDraw.CreateFontIndirect(&lf); 85 | 86 | CFont* pOldFont = dc.SelectObject(&fontDraw); 87 | dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK); 88 | dc.SelectObject(pOldFont); 89 | } 90 | 91 | // Support for Search Handlers 92 | void CNMRIDoc::InitializeSearchContent() 93 | { 94 | CString strSearchContent; 95 | // Set search contents from document's data. 96 | // The content parts should be separated by ";" 97 | 98 | // For example: strSearchContent = _T("point;rectangle;circle;ole object;"); 99 | SetSearchContent(strSearchContent); 100 | } 101 | 102 | void CNMRIDoc::SetSearchContent(const CString& value) 103 | { 104 | if (value.IsEmpty()) 105 | { 106 | RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid); 107 | } 108 | else 109 | { 110 | CMFCFilterChunkValueImpl *pChunk = nullptr; 111 | ATLTRY(pChunk = new CMFCFilterChunkValueImpl); 112 | if (pChunk != nullptr) 113 | { 114 | pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT); 115 | SetChunkValue(pChunk); 116 | } 117 | } 118 | } 119 | 120 | #endif // SHARED_HANDLERS 121 | 122 | // CNMRIDoc diagnostics 123 | 124 | #ifdef _DEBUG 125 | void CNMRIDoc::AssertValid() const 126 | { 127 | CDocument::AssertValid(); 128 | } 129 | 130 | void CNMRIDoc::Dump(CDumpContext& dc) const 131 | { 132 | CDocument::Dump(dc); 133 | } 134 | #endif //_DEBUG 135 | 136 | 137 | // CNMRIDoc commands 138 | 139 | 140 | bool CNMRIDoc::Load(const CString& name) 141 | { 142 | if (theFile.Load(name)) 143 | { 144 | theFile.FFT(0); 145 | 146 | return true; 147 | } 148 | 149 | return false; 150 | } 151 | 152 | 153 | void CNMRIDoc::UpdateViews() 154 | { 155 | POSITION pos = GetFirstViewPosition(); 156 | while (pos != nullptr) { 157 | CView* pView = GetNextView(pos); 158 | 159 | // the other one refreshes itself by timer 160 | if (pView->IsKindOf(RUNTIME_CLASS(CVTKView))) 161 | { 162 | ((CVTKView*)pView)->GrabResultsFromDoc(); 163 | ((CVTKView*)pView)->Invalidate(); 164 | } 165 | } 166 | } 167 | 168 | 169 | void CNMRIDoc::Update3DOptions() 170 | { 171 | POSITION pos = GetFirstViewPosition(); 172 | while (pos != nullptr) { 173 | CView* pView = GetNextView(pos); 174 | 175 | // the other one refreshes itself by timer 176 | if (pView->IsKindOf(RUNTIME_CLASS(CVTKView))) 177 | { 178 | ((CVTKView*)pView)->UpdateTransferFunctions(); 179 | ((CVTKView*)pView)->Invalidate(); 180 | } 181 | } 182 | } -------------------------------------------------------------------------------- /NMRI/NMRI.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | 91 | 92 | Resource Files 93 | 94 | 95 | 96 | 97 | Resource Files 98 | 99 | 100 | Resource Files 101 | 102 | 103 | Resource Files 104 | 105 | 106 | Resource Files 107 | 108 | 109 | Resource Files 110 | 111 | 112 | Resource Files 113 | 114 | 115 | Resource Files 116 | 117 | 118 | Resource Files 119 | 120 | 121 | Resource Files 122 | 123 | 124 | 125 | 126 | Resource Files 127 | 128 | 129 | -------------------------------------------------------------------------------- /NMRI/MemoryBitmap.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MemoryBitmap.h" 3 | 4 | 5 | #include 6 | #include 7 | 8 | MemoryBitmap::MemoryBitmap(const MemoryBitmap& other) // copy constructor 9 | { 10 | if (other.data) 11 | { 12 | m_width = other.m_width; 13 | m_height = other.m_height; 14 | int size = GetStrideLength() * m_height; 15 | data = new unsigned char[size]; 16 | memcpy(data, other.data, size); 17 | } 18 | else { 19 | data = nullptr; 20 | m_width = m_height = 0; 21 | } 22 | } 23 | 24 | MemoryBitmap::MemoryBitmap(MemoryBitmap&& other) noexcept // move constructor 25 | : data(other.data), m_width(other.m_width), m_height(other.m_height) 26 | { 27 | other.data = nullptr; 28 | other.m_height = other.m_width = 0; 29 | } 30 | 31 | MemoryBitmap& MemoryBitmap::operator=(const MemoryBitmap& other) //copy assignment operator 32 | { 33 | MemoryBitmap temp(other); 34 | 35 | *this = std::move(temp); 36 | 37 | return *this; 38 | } 39 | 40 | MemoryBitmap& MemoryBitmap::operator=(MemoryBitmap&& other) noexcept // move assignment operator 41 | { 42 | delete[] data; 43 | 44 | m_width = other.m_width; 45 | m_height = other.m_height; 46 | 47 | data = other.data; 48 | 49 | other.m_height = other.m_width = 0; 50 | other.data = nullptr; 51 | 52 | return *this; 53 | } 54 | 55 | MemoryBitmap::~MemoryBitmap() noexcept 56 | { 57 | delete[] data; 58 | } 59 | 60 | 61 | void MemoryBitmap::SetSize(int width, int height) 62 | { 63 | assert(width != 0 && height != 0); 64 | 65 | if (m_width != width || m_height != height) 66 | { 67 | delete[] data; 68 | 69 | m_width = width; 70 | m_height = height; 71 | 72 | data = new unsigned char[static_cast(GetStrideLength()) * height]; 73 | } 74 | } 75 | 76 | 77 | 78 | void MemoryBitmap::SetMatrix(const double* results, int Width, int Height) 79 | { 80 | if (Width == 0 || Height == 0 || !results) return; 81 | 82 | SetSize(Width, Height); 83 | 84 | int stride = GetStrideLength(); 85 | 86 | 87 | 88 | for (int i = 0; i < Height; ++i) 89 | { 90 | const int line = (Height - i - 1) * stride; 91 | 92 | for (int j = 0; j < Width; ++j) 93 | { 94 | int pos = line + 3 * j; 95 | 96 | const double val = results[Width*i + j]; 97 | 98 | data[pos] = static_cast(val * 255.); 99 | data[pos + 1] = data[pos]; 100 | data[pos + 2] = data[pos]; 101 | } 102 | } 103 | } 104 | 105 | void MemoryBitmap::SetMatrix(const std::complex* results, int Width, int Height) 106 | { 107 | if (Width == 0 || Height == 0 || !results) return; 108 | 109 | SetSize(Width, Height); 110 | 111 | const int stride = GetStrideLength(); 112 | 113 | for (int i = 0; i < Height; ++i) 114 | { 115 | const int line = (Height - i - 1) * stride; 116 | 117 | for (int j = 0; j < Width; ++j) 118 | { 119 | const int pos = line + 3 * j; 120 | 121 | const double val = std::abs(results[Width*i + j]); 122 | 123 | data[pos] = static_cast(val * 255.); 124 | data[pos + 1] = data[pos]; 125 | data[pos + 2] = data[pos]; 126 | } 127 | } 128 | } 129 | 130 | void MemoryBitmap::Draw(CDC* pDC) const 131 | { 132 | BITMAPINFO bmi; 133 | ZeroMemory(&bmi, sizeof(BITMAPINFOHEADER)); 134 | 135 | bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 136 | bmi.bmiHeader.biWidth = m_width; 137 | bmi.bmiHeader.biHeight = m_height; 138 | bmi.bmiHeader.biPlanes = 1; 139 | bmi.bmiHeader.biBitCount = 24; 140 | bmi.bmiHeader.biCompression = BI_RGB; 141 | 142 | CBitmap bitmap; 143 | 144 | bitmap.CreateCompatibleBitmap(pDC, m_width, m_height); 145 | ::SetDIBits(pDC->GetSafeHdc(), bitmap, 0, m_height, data, &bmi, DIB_RGB_COLORS); 146 | CDC dcMemory; 147 | dcMemory.CreateCompatibleDC(pDC); 148 | CBitmap * pOldBitmap = dcMemory.SelectObject(&bitmap); 149 | pDC->BitBlt(0, 0, m_width, m_height, &dcMemory, 0, 0, SRCCOPY); 150 | dcMemory.SelectObject(pOldBitmap); 151 | } 152 | 153 | void MemoryBitmap::Draw(CDC* pDC, CRect& rect, int origWidth, int origHeight) const 154 | { 155 | BITMAPINFO bmi; 156 | ZeroMemory(&bmi, sizeof(BITMAPINFOHEADER)); 157 | 158 | bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 159 | bmi.bmiHeader.biWidth = m_width; 160 | bmi.bmiHeader.biHeight = m_height; 161 | bmi.bmiHeader.biPlanes = 1; 162 | bmi.bmiHeader.biBitCount = 24; 163 | bmi.bmiHeader.biCompression = BI_RGB; 164 | 165 | CBitmap bitmap; 166 | 167 | bitmap.CreateCompatibleBitmap(pDC, m_width, m_height); 168 | ::SetDIBits(pDC->GetSafeHdc(), bitmap, 0, m_height, data, &bmi, DIB_RGB_COLORS); 169 | CDC dcMemory; 170 | dcMemory.CreateCompatibleDC(pDC); 171 | CBitmap * pOldBitmap = dcMemory.SelectObject(&bitmap); 172 | pDC->StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dcMemory, origWidth ? (m_width - origWidth)/2 : 0, origHeight ? (m_height - origHeight)/2 : 0, origWidth ? origWidth : m_width, origHeight ? origHeight : m_height, SRCCOPY); 173 | dcMemory.SelectObject(pOldBitmap); 174 | } 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /NMRI/NMRIView.cpp: -------------------------------------------------------------------------------- 1 | 2 | // NMRIView.cpp : implementation of the CNMRIView class 3 | // 4 | 5 | #include "stdafx.h" 6 | // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail 7 | // and search filter handlers and allows sharing of document code with that project. 8 | #ifndef SHARED_HANDLERS 9 | #include "NMRI.h" 10 | #endif 11 | 12 | #include "NMRIDoc.h" 13 | #include "NMRIView.h" 14 | 15 | #ifdef _DEBUG 16 | #define new DEBUG_NEW 17 | #endif 18 | 19 | 20 | // CNMRIView 21 | 22 | IMPLEMENT_DYNCREATE(CNMRIView, CView) 23 | 24 | BEGIN_MESSAGE_MAP(CNMRIView, CView) 25 | // Standard printing commands 26 | ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) 27 | ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) 28 | ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CNMRIView::OnFilePrintPreview) 29 | ON_WM_CONTEXTMENU() 30 | ON_WM_RBUTTONUP() 31 | ON_WM_CREATE() 32 | ON_WM_DESTROY() 33 | ON_WM_ERASEBKGND() 34 | ON_WM_TIMER() 35 | END_MESSAGE_MAP() 36 | 37 | // CNMRIView construction/destruction 38 | 39 | BOOL CNMRIView::PreCreateWindow(CREATESTRUCT& cs) 40 | { 41 | // TODO: Modify the Window class or styles here by modifying 42 | // the CREATESTRUCT cs 43 | 44 | return CView::PreCreateWindow(cs); 45 | } 46 | 47 | // CNMRIView drawing 48 | 49 | void CNMRIView::OnDraw(CDC* pDC) 50 | { 51 | const CNMRIDoc* pDoc = GetDocument(); 52 | ASSERT_VALID(pDoc); 53 | if (!pDoc) 54 | return; 55 | 56 | // TODO: add draw code for native data here 57 | 58 | int width = pDoc->theFile.Width; 59 | int height = pDoc->theFile.Height; 60 | 61 | img1.SetMatrix(pDoc->theFile.GetFrame(), width, height); 62 | img2.SetMatrix(pDoc->theFile.GetRealFrame(), width, height); 63 | 64 | CRect rect; 65 | GetClientRect(rect); 66 | 67 | width *= 2; 68 | height *= 2; 69 | 70 | 71 | CRect rct; 72 | rct.top = rect.top + rect.Height() / 2 - height / 2; 73 | rct.left = rect.left + rect.Width() / 2 - width - 5; 74 | rct.right = rct.left + width; 75 | rct.bottom = rct.top + height; 76 | 77 | img1.Draw(pDC, rct); 78 | 79 | rct.left = rect.left + rect.Width() / 2 + 5; 80 | rct.right = rct.left + width; 81 | 82 | img2.Draw(pDC, rct); 83 | 84 | 85 | CBrush whiteBrush(RGB(255,255,255)); 86 | CRect paintRect; 87 | 88 | paintRect.top = rect.top; 89 | paintRect.bottom = rct.top; 90 | paintRect.left = rect.left; 91 | paintRect.right = rect.right; 92 | pDC->FillRect(paintRect, &whiteBrush); 93 | 94 | paintRect.top = rct.bottom; 95 | paintRect.bottom = rect.bottom; 96 | pDC->FillRect(paintRect, &whiteBrush); 97 | 98 | paintRect.right = rect.left + rect.Width() / 2 - width - 5; 99 | paintRect.top = rct.top; 100 | paintRect.bottom = rct.bottom; 101 | pDC->FillRect(paintRect, &whiteBrush); 102 | 103 | paintRect.left = rct.right; 104 | paintRect.right = rect.right; 105 | pDC->FillRect(paintRect, &whiteBrush); 106 | 107 | paintRect.left = rct.left-10; 108 | paintRect.right = rct.left; 109 | pDC->FillRect(paintRect, &whiteBrush); 110 | } 111 | 112 | 113 | // CNMRIView printing 114 | 115 | 116 | void CNMRIView::OnFilePrintPreview() 117 | { 118 | #ifndef SHARED_HANDLERS 119 | AFXPrintPreview(this); 120 | #endif 121 | } 122 | 123 | BOOL CNMRIView::OnPreparePrinting(CPrintInfo* pInfo) 124 | { 125 | // default preparation 126 | return DoPreparePrinting(pInfo); 127 | } 128 | 129 | void CNMRIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 130 | { 131 | // TODO: add extra initialization before printing 132 | } 133 | 134 | void CNMRIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 135 | { 136 | // TODO: add cleanup after printing 137 | } 138 | 139 | void CNMRIView::OnRButtonUp(UINT /* nFlags */, CPoint point) 140 | { 141 | ClientToScreen(&point); 142 | OnContextMenu(this, point); 143 | } 144 | 145 | void CNMRIView::OnContextMenu(CWnd* /* pWnd */, CPoint /*point*/) 146 | { 147 | #ifndef SHARED_HANDLERS 148 | #endif 149 | } 150 | 151 | 152 | // CNMRIView diagnostics 153 | 154 | #ifdef _DEBUG 155 | void CNMRIView::AssertValid() const 156 | { 157 | CView::AssertValid(); 158 | } 159 | 160 | void CNMRIView::Dump(CDumpContext& dc) const 161 | { 162 | CView::Dump(dc); 163 | } 164 | 165 | CNMRIDoc* CNMRIView::GetDocument() const // non-debug version is inline 166 | { 167 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNMRIDoc))); 168 | return dynamic_cast(m_pDocument); 169 | } 170 | #endif //_DEBUG 171 | 172 | 173 | // CNMRIView message handlers 174 | 175 | 176 | int CNMRIView::OnCreate(LPCREATESTRUCT lpCreateStruct) 177 | { 178 | if (CView::OnCreate(lpCreateStruct) == -1) 179 | return -1; 180 | 181 | timer = SetTimer(1, 500, nullptr); 182 | 183 | return 0; 184 | } 185 | 186 | 187 | void CNMRIView::OnDestroy() 188 | { 189 | KillTimer(timer); 190 | 191 | CView::OnDestroy(); 192 | } 193 | 194 | 195 | BOOL CNMRIView::OnEraseBkgnd(CDC* pDC) 196 | { 197 | if (pDC->IsPrinting()) 198 | return CView::OnEraseBkgnd(pDC); 199 | 200 | return TRUE; 201 | } 202 | 203 | 204 | void CNMRIView::OnTimer(UINT_PTR nIDEvent) 205 | { 206 | CView::OnTimer(nIDEvent); 207 | 208 | CNMRIDoc* pDoc = GetDocument(); 209 | ASSERT_VALID(pDoc); 210 | if (!pDoc) 211 | return; 212 | 213 | // the reason why the timer is not stopped is that the image should be updated if the filter is changed 214 | if (pDoc->animate) 215 | { 216 | if (++theFrame >= pDoc->theFile.NrFrames) theFrame = 0; 217 | } 218 | 219 | pDoc->theFile.FFT(theFrame); 220 | Invalidate(); 221 | } 222 | -------------------------------------------------------------------------------- /NMRI/NMRI.cpp: -------------------------------------------------------------------------------- 1 | 2 | // NMRI.cpp : Defines the class behaviors for the application. 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "afxwinappex.h" 7 | #include "afxdialogex.h" 8 | #include "NMRI.h" 9 | #include "MainFrm.h" 10 | 11 | #include "NMRIDoc.h" 12 | #include "NMRIView.h" 13 | 14 | #ifdef _DEBUG 15 | #define new DEBUG_NEW 16 | #endif 17 | 18 | 19 | // CNMRIApp 20 | 21 | BEGIN_MESSAGE_MAP(CNMRIApp, CWinAppEx) 22 | ON_COMMAND(ID_APP_ABOUT, &CNMRIApp::OnAppAbout) 23 | // Standard file based document commands 24 | ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew) 25 | ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen) 26 | // Standard print setup command 27 | ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup) 28 | END_MESSAGE_MAP() 29 | 30 | 31 | // CNMRIApp construction 32 | 33 | CNMRIApp::CNMRIApp() 34 | : m_nAppLook(0), m_bHiColorIcons(TRUE) 35 | { 36 | // support Restart Manager 37 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS; 38 | #ifdef _MANAGED 39 | // If the application is built using Common Language Runtime support (/clr): 40 | // 1) This additional setting is needed for Restart Manager support to work properly. 41 | // 2) In your project, you must add a reference to System.Windows.Forms in order to build. 42 | System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException); 43 | #endif 44 | 45 | // TODO: replace application ID string below with unique ID string; recommended 46 | // format for string is CompanyName.ProductName.SubProduct.VersionInformation 47 | SetAppID(_T("NMRI.AppID.NoVersion")); 48 | 49 | // TODO: add construction code here, 50 | // Place all significant initialization in InitInstance 51 | } 52 | 53 | // The one and only CNMRIApp object 54 | 55 | CNMRIApp theApp; 56 | 57 | 58 | // CNMRIApp initialization 59 | 60 | BOOL CNMRIApp::InitInstance() 61 | { 62 | // InitCommonControlsEx() is required on Windows XP if an application 63 | // manifest specifies use of ComCtl32.dll version 6 or later to enable 64 | // visual styles. Otherwise, any window creation will fail. 65 | INITCOMMONCONTROLSEX InitCtrls; 66 | InitCtrls.dwSize = sizeof(InitCtrls); 67 | // Set this to include all the common control classes you want to use 68 | // in your application. 69 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 70 | InitCommonControlsEx(&InitCtrls); 71 | 72 | CWinAppEx::InitInstance(); 73 | 74 | 75 | EnableTaskbarInteraction(FALSE); 76 | 77 | // AfxInitRichEdit2() is required to use RichEdit control 78 | // AfxInitRichEdit2(); 79 | 80 | // Standard initialization 81 | // If you are not using these features and wish to reduce the size 82 | // of your final executable, you should remove from the following 83 | // the specific initialization routines you do not need 84 | // Change the registry key under which our settings are stored 85 | // TODO: You should modify this string to be something appropriate 86 | // such as the name of your company or organization 87 | SetRegistryKey(_T("NMRI")); 88 | LoadStdProfileSettings(0); // Load standard INI file options (including MRU) 89 | 90 | 91 | InitContextMenuManager(); 92 | 93 | InitKeyboardManager(); 94 | 95 | InitTooltipManager(); 96 | CMFCToolTipInfo ttParams; 97 | ttParams.m_bVislManagerTheme = TRUE; 98 | theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL, 99 | RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams); 100 | 101 | // Register the application's document templates. Document templates 102 | // serve as the connection between documents, frame windows and views 103 | CSingleDocTemplate* pDocTemplate = new CSingleDocTemplate( 104 | IDR_MAINFRAME, 105 | RUNTIME_CLASS(CNMRIDoc), 106 | RUNTIME_CLASS(CMainFrame), // main SDI frame window 107 | RUNTIME_CLASS(CNMRIView)); 108 | if (!pDocTemplate) 109 | return FALSE; 110 | AddDocTemplate(pDocTemplate); 111 | 112 | // Parse command line for standard shell commands, DDE, file open 113 | CCommandLineInfo cmdInfo; 114 | ParseCommandLine(cmdInfo); 115 | 116 | // Dispatch commands specified on the command line. Will return FALSE if 117 | // app was launched with /RegServer, /Register, /Unregserver or /Unregister. 118 | if (!ProcessShellCommand(cmdInfo)) 119 | return FALSE; 120 | 121 | // The one and only window has been initialized, so show and update it 122 | m_pMainWnd->ShowWindow(SW_SHOW); 123 | m_pMainWnd->UpdateWindow(); 124 | 125 | dynamic_cast(m_pMainWnd)->Init(); 126 | 127 | return TRUE; 128 | } 129 | 130 | // CNMRIApp message handlers 131 | 132 | 133 | // CAboutDlg dialog used for App About 134 | 135 | class CAboutDlg : public CDialogEx 136 | { 137 | public: 138 | CAboutDlg(); 139 | 140 | // Dialog Data 141 | #ifdef AFX_DESIGN_TIME 142 | enum { IDD = IDD_ABOUTBOX }; 143 | #endif 144 | 145 | protected: 146 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 147 | 148 | // Implementation 149 | protected: 150 | DECLARE_MESSAGE_MAP() 151 | }; 152 | 153 | CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) 154 | { 155 | } 156 | 157 | void CAboutDlg::DoDataExchange(CDataExchange* pDX) 158 | { 159 | CDialogEx::DoDataExchange(pDX); 160 | } 161 | 162 | BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) 163 | END_MESSAGE_MAP() 164 | 165 | // App command to run the dialog 166 | void CNMRIApp::OnAppAbout() 167 | { 168 | CAboutDlg aboutDlg; 169 | aboutDlg.DoModal(); 170 | } 171 | 172 | // CNMRIApp customization load/save methods 173 | 174 | void CNMRIApp::PreLoadState() 175 | { 176 | } 177 | 178 | void CNMRIApp::LoadCustomState() 179 | { 180 | } 181 | 182 | void CNMRIApp::SaveCustomState() 183 | { 184 | } 185 | 186 | // CNMRIApp message handlers 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /NMRI/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | MICROSOFT FOUNDATION CLASS LIBRARY : NMRI Project Overview 3 | =============================================================================== 4 | 5 | The application wizard has created this NMRI application for 6 | you. This application not only demonstrates the basics of using the Microsoft 7 | Foundation Classes but is also a starting point for writing your application. 8 | 9 | This file contains a summary of what you will find in each of the files that 10 | make up your NMRI application. 11 | 12 | NMRI.vcxproj 13 | This is the main project file for VC++ projects generated using an application wizard. 14 | It contains information about the version of Visual C++ that generated the file, and 15 | information about the platforms, configurations, and project features selected with the 16 | application wizard. 17 | 18 | NMRI.vcxproj.filters 19 | This is the filters file for VC++ projects generated using an Application Wizard. 20 | It contains information about the assciation between the files in your project 21 | and the filters. This association is used in the IDE to show grouping of files with 22 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 23 | "Source Files" filter). 24 | 25 | NMRI.h 26 | This is the main header file for the application. It includes other 27 | project specific headers (including Resource.h) and declares the 28 | CNMRIApp application class. 29 | 30 | NMRI.cpp 31 | This is the main application source file that contains the application 32 | class CNMRIApp. 33 | 34 | NMRI.rc 35 | This is a listing of all of the Microsoft Windows resources that the 36 | program uses. It includes the icons, bitmaps, and cursors that are stored 37 | in the RES subdirectory. This file can be directly edited in Microsoft 38 | Visual C++. Your project resources are in 1033. 39 | 40 | res\NMRI.ico 41 | This is an icon file, which is used as the application's icon. This 42 | icon is included by the main resource file NMRI.rc. 43 | 44 | res\NMRI.rc2 45 | This file contains resources that are not edited by Microsoft 46 | Visual C++. You should place all resources not editable by 47 | the resource editor in this file. 48 | 49 | ///////////////////////////////////////////////////////////////////////////// 50 | 51 | For the main frame window: 52 | The project includes a standard MFC interface. 53 | 54 | MainFrm.h, MainFrm.cpp 55 | These files contain the frame class CMainFrame, which is derived from 56 | CFrameWnd and controls all SDI frame features. 57 | 58 | res\Toolbar.bmp 59 | This bitmap file is used to create tiled images for the toolbar. 60 | The initial toolbar and status bar are constructed in the CMainFrame 61 | class. Edit this toolbar bitmap using the resource editor, and 62 | update the IDR_MAINFRAME TOOLBAR array in NMRI.rc to add 63 | toolbar buttons. 64 | ///////////////////////////////////////////////////////////////////////////// 65 | 66 | The application wizard creates one document type and one view: 67 | 68 | NMRIDoc.h, NMRIDoc.cpp - the document 69 | These files contain your CNMRIDoc class. Edit these files to 70 | add your special document data and to implement file saving and loading 71 | (via CNMRIDoc::Serialize). 72 | 73 | NMRIView.h, NMRIView.cpp - the view of the document 74 | These files contain your CNMRIView class. 75 | CNMRIView objects are used to view CNMRIDoc objects. 76 | 77 | 78 | 79 | 80 | ///////////////////////////////////////////////////////////////////////////// 81 | 82 | Help Support: 83 | 84 | hlp\NMRI.hhp 85 | This file is a help project file. It contains the data needed to 86 | compile the help files into a .chm file. 87 | 88 | hlp\NMRI.hhc 89 | This file lists the contents of the help project. 90 | 91 | hlp\NMRI.hhk 92 | This file contains an index of the help topics. 93 | 94 | hlp\afxcore.htm 95 | This file contains the standard help topics for standard MFC 96 | commands and screen objects. Add your own help topics to this file. 97 | 98 | hlp\afxprint.htm 99 | This file contains the help topics for the printing commands. 100 | 101 | makehtmlhelp.bat 102 | This file is used by the build system to compile the help files. 103 | 104 | hlp\Images\*.gif 105 | These are bitmap files required by the standard help file topics for 106 | Microsoft Foundation Class Library standard commands. 107 | 108 | 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | Other Features: 112 | 113 | Printing and Print Preview support 114 | The application wizard has generated code to handle the print, print setup, and print preview 115 | commands by calling member functions in the CView class from the MFC library. 116 | 117 | ///////////////////////////////////////////////////////////////////////////// 118 | 119 | Other standard files: 120 | 121 | StdAfx.h, StdAfx.cpp 122 | These files are used to build a precompiled header (PCH) file 123 | named NMRI.pch and a precompiled types file named StdAfx.obj. 124 | 125 | Resource.h 126 | This is the standard header file, which defines new resource IDs. 127 | Microsoft Visual C++ reads and updates this file. 128 | 129 | NMRI.manifest 130 | Application manifest files are used by Windows XP to describe an applications 131 | dependency on specific versions of Side-by-Side assemblies. The loader uses this 132 | information to load the appropriate assembly from the assembly cache or private 133 | from the application. The Application manifest maybe included for redistribution 134 | as an external .manifest file that is installed in the same folder as the application 135 | executable or it may be included in the executable in the form of a resource. 136 | ///////////////////////////////////////////////////////////////////////////// 137 | 138 | Other notes: 139 | 140 | The application wizard uses "TODO:" to indicate parts of the source code you 141 | should add to or customize. 142 | 143 | If your application uses MFC in a shared DLL, you will need 144 | to redistribute the MFC DLLs. If your application is in a language 145 | other than the operating system's locale, you will also have to 146 | redistribute the corresponding localized resources MFC100XXX.DLL. 147 | For more information on both of these topics, please see the section on 148 | redistributing Visual C++ applications in MSDN documentation. 149 | 150 | ///////////////////////////////////////////////////////////////////////////// 151 | -------------------------------------------------------------------------------- /NMRI/PropertiesWnd.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "stdafx.h" 3 | 4 | #include "PropertiesWnd.h" 5 | #include "Resource.h" 6 | #include "MainFrm.h" 7 | #include "NMRI.h" 8 | 9 | #include "NMRIDoc.h" 10 | 11 | #ifdef _DEBUG 12 | #undef THIS_FILE 13 | static char THIS_FILE[]=__FILE__; 14 | #define new DEBUG_NEW 15 | #endif 16 | 17 | // for CSliderProp and CPropSliderCtrl see: https://github.com/jhlee8804/MFC-Feature-Pack/tree/master/NewControls 18 | // the code is adjusted to allow setting the range 19 | 20 | ///////////////////////////////////////////////////////////////////////////// 21 | // CPropSliderCtrl 22 | 23 | CPropSliderCtrl::CPropSliderCtrl(CSliderProp* pProp, COLORREF clrBack) { 24 | m_clrBack = clrBack; 25 | m_brBackground.CreateSolidBrush(m_clrBack); 26 | m_pProp = pProp; 27 | } 28 | 29 | BEGIN_MESSAGE_MAP(CPropSliderCtrl, CSliderCtrl) 30 | //{{AFX_MSG_MAP(CPropSliderCtrl) 31 | ON_WM_CTLCOLOR_REFLECT() 32 | ON_WM_HSCROLL_REFLECT() 33 | //}}AFX_MSG_MAP 34 | END_MESSAGE_MAP() 35 | 36 | ///////////////////////////////////////////////////////////////////////////// 37 | // CPropSliderCtrl message handlers 38 | 39 | HBRUSH CPropSliderCtrl::CtlColor(CDC* pDC, UINT /*nCtlColor*/) { 40 | pDC->SetBkColor(m_clrBack); 41 | return m_brBackground; 42 | } 43 | 44 | void CPropSliderCtrl::HScroll(UINT /*nSBCode*/, UINT /*nPos*/) { 45 | ASSERT_VALID(m_pProp); 46 | 47 | m_pProp->OnUpdateValue(); 48 | m_pProp->Redraw(); 49 | } 50 | 51 | //////////////////////////////////////////////////////////////////////////////// 52 | // CSliderProp class 53 | 54 | CSliderProp::CSliderProp(const CString& strName, long nValue, long minVal, long maxVal, LPCTSTR lpszDescr, DWORD dwData) : 55 | CMFCPropertyGridProperty(strName, nValue, lpszDescr, dwData), m_minVal(minVal), m_maxVal(maxVal) 56 | { 57 | } 58 | 59 | CWnd* CSliderProp::CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat) { 60 | CPropSliderCtrl* pWndSlider = new CPropSliderCtrl(this, m_pWndList->GetBkColor()); 61 | 62 | rectEdit.left += rectEdit.Height() + 5; 63 | 64 | pWndSlider->Create(WS_VISIBLE | WS_CHILD, rectEdit, m_pWndList, AFX_PROPLIST_ID_INPLACE); 65 | pWndSlider->SetRange(m_minVal, m_maxVal); 66 | pWndSlider->SetPos(m_varValue.lVal); 67 | 68 | bDefaultFormat = TRUE; 69 | return pWndSlider; 70 | } 71 | 72 | BOOL CSliderProp::OnUpdateValue() { 73 | ASSERT_VALID(this); 74 | ASSERT_VALID(m_pWndInPlace); 75 | ASSERT_VALID(m_pWndList); 76 | ASSERT(::IsWindow(m_pWndInPlace->GetSafeHwnd())); 77 | 78 | long lCurrValue = m_varValue.lVal; 79 | 80 | CSliderCtrl* pSlider = (CSliderCtrl*)m_pWndInPlace; 81 | 82 | m_varValue = (long)pSlider->GetPos(); 83 | 84 | if (lCurrValue != m_varValue.lVal) { 85 | m_pWndList->OnPropertyChanged(this); 86 | } 87 | 88 | return TRUE; 89 | } 90 | 91 | 92 | 93 | ///////////////////////////////////////////////////////////////////////////// 94 | // CResourceViewBar 95 | 96 | 97 | BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane) 98 | ON_WM_CREATE() 99 | ON_WM_SIZE() 100 | ON_WM_SETFOCUS() 101 | ON_WM_SETTINGCHANGE() 102 | ON_REGISTERED_MESSAGE(AFX_WM_PROPERTY_CHANGED, OnPropertyChanged) 103 | END_MESSAGE_MAP() 104 | 105 | ///////////////////////////////////////////////////////////////////////////// 106 | // CResourceViewBar message handlers 107 | 108 | void CPropertiesWnd::AdjustLayout() 109 | { 110 | if (GetSafeHwnd () == nullptr || (AfxGetMainWnd() != nullptr && AfxGetMainWnd()->IsIconic())) 111 | { 112 | return; 113 | } 114 | 115 | CRect rectClient; 116 | GetClientRect(rectClient); 117 | 118 | m_wndPropList.SetWindowPos(nullptr, rectClient.left, rectClient.top, rectClient.Width(), rectClient.Height(), SWP_NOACTIVATE | SWP_NOZORDER); 119 | } 120 | 121 | int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 122 | { 123 | if (CDockablePane::OnCreate(lpCreateStruct) == -1) 124 | return -1; 125 | 126 | CRect rectDummy; 127 | rectDummy.SetRectEmpty(); 128 | 129 | 130 | if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2)) 131 | { 132 | TRACE0("Failed to create Properties Grid \n"); 133 | return -1; // fail to create 134 | } 135 | 136 | InitPropList(); 137 | 138 | 139 | AdjustLayout(); 140 | return 0; 141 | } 142 | 143 | void CPropertiesWnd::OnSize(UINT nType, int cx, int cy) 144 | { 145 | CDockablePane::OnSize(nType, cx, cy); 146 | AdjustLayout(); 147 | } 148 | 149 | 150 | void CPropertiesWnd::InitPropList() 151 | { 152 | m_wndPropList.EnableHeaderCtrl(FALSE); 153 | m_wndPropList.EnableDescriptionArea(); 154 | m_wndPropList.SetVSDotNetLook(); 155 | m_wndPropList.MarkModifiedProperties(); 156 | 157 | CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("Filter")); 158 | 159 | CMFCPropertyGridProperty *prop = new CMFCPropertyGridProperty(_T("Low Frequencies"), (_variant_t)false, _T("Removes the low frequency information")); 160 | 161 | prop->SetData(0); 162 | pGroup1->AddSubItem(prop); 163 | 164 | prop = new CMFCPropertyGridProperty(_T("High Frequencies"), (_variant_t)false, _T("Removes the high frequency information")); 165 | prop->SetData(1); 166 | pGroup1->AddSubItem(prop); 167 | 168 | prop = new CSliderProp(_T("Low filter threshold"), 50, 0, 100, _T("Low filter cutoff value")); 169 | prop->SetData(2); 170 | pGroup1->AddSubItem(prop); 171 | 172 | prop = new CSliderProp(_T("High filter threshold"), 50, 0, 100, _T("High filter cutoff value")); 173 | prop->SetData(3); 174 | pGroup1->AddSubItem(prop); 175 | 176 | 177 | m_wndPropList.AddProperty(pGroup1); 178 | 179 | CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("3D View")); 180 | 181 | prop = new CMFCPropertyGridProperty(_T("Color transfer function"), (_variant_t)true, _T("Color the 3D image with blue for low values, red for high")); 182 | prop->SetData(4); 183 | pGroup2->AddSubItem(prop); 184 | 185 | prop = new CMFCPropertyGridProperty(_T("Scalar opacity transfer function"), (_variant_t)true, _T("Make the small values more transparent than the big ones")); 186 | prop->SetData(5); 187 | pGroup2->AddSubItem(prop); 188 | 189 | prop = new CMFCPropertyGridProperty(_T("Gradient opacity transfer function"), (_variant_t)true, _T("Make the low gradient values more transparent")); 190 | prop->SetData(6); 191 | pGroup2->AddSubItem(prop); 192 | 193 | prop = new CSliderProp(_T("Opacity depth"), 50, 0, 100, _T("Opacity depth where the value is 1")); 194 | prop->SetData(7); 195 | pGroup2->AddSubItem(prop); 196 | 197 | prop = new CSliderProp(_T("Gradient point"), 50, 0, 100, _T("Gradient point where the value is 1")); 198 | prop->SetData(8); 199 | pGroup2->AddSubItem(prop); 200 | 201 | m_wndPropList.AddProperty(pGroup2); 202 | } 203 | 204 | void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd) 205 | { 206 | CDockablePane::OnSetFocus(pOldWnd); 207 | m_wndPropList.SetFocus(); 208 | } 209 | 210 | void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) 211 | { 212 | CDockablePane::OnSettingChange(uFlags, lpszSection); 213 | } 214 | 215 | LRESULT CPropertiesWnd::OnPropertyChanged(__in WPARAM /*wparam*/, __in LPARAM lparam) 216 | { 217 | if (!theDoc) return 0; 218 | 219 | const CMFCPropertyGridProperty *prop = (CMFCPropertyGridProperty *)lparam; 220 | 221 | 222 | if (prop) 223 | { 224 | COleVariant v = prop->GetValue(); 225 | 226 | const auto opt = prop->GetData(); 227 | switch (opt) 228 | { 229 | case 0: 230 | v.ChangeType(VT_BOOL); 231 | theDoc->theFile.filterLowFreqs = v.boolVal; 232 | break; 233 | case 1: 234 | v.ChangeType(VT_BOOL); 235 | theDoc->theFile.filterHighFreqs = v.boolVal; 236 | break; 237 | case 2: 238 | v.ChangeType(VT_INT); 239 | theDoc->theFile.LowPassPercentage = v.intVal; 240 | break; 241 | case 3: 242 | v.ChangeType(VT_INT); 243 | theDoc->theFile.HighPassPercentage = v.intVal; 244 | break; 245 | case 4: 246 | v.ChangeType(VT_BOOL); 247 | theDoc->colorFunction = v.boolVal; 248 | break; 249 | case 5: 250 | v.ChangeType(VT_BOOL); 251 | theDoc->opacityFunction = v.boolVal; 252 | break; 253 | case 6: 254 | v.ChangeType(VT_BOOL); 255 | theDoc->gradientFunction = v.boolVal; 256 | break; 257 | case 7: 258 | v.ChangeType(VT_INT); 259 | theDoc->opacityVal = v.intVal; 260 | break; 261 | case 8: 262 | v.ChangeType(VT_INT); 263 | theDoc->gradientVal = v.intVal; 264 | break; 265 | } 266 | 267 | if (opt <= 3) 268 | theDoc->UpdateViews(); 269 | else 270 | theDoc->Update3DOptions(); 271 | } 272 | 273 | return 0; 274 | } 275 | 276 | 277 | -------------------------------------------------------------------------------- /NMRI/FFT.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | // inspired from unsupported FFT from Eigen 10 | // unfortunately the implementation there does not support 2D and 3D transforms and also multi threading 11 | // I didn't like the way they index plans, either, so here it is, reimplemented 12 | 13 | namespace Fourier { 14 | 15 | class FFTWPlan { 16 | public: 17 | FFTWPlan() = default; 18 | FFTWPlan(const FFTWPlan&) = delete; 19 | FFTWPlan& operator=(const FFTWPlan&) = delete; 20 | 21 | ~FFTWPlan() 22 | { 23 | if (plan) 24 | { 25 | std::lock_guard lock(planMutex); 26 | fftw_destroy_plan(plan); 27 | } 28 | } 29 | 30 | // 1D 31 | 32 | inline void fwd(fftw_complex* src, fftw_complex* dst, unsigned int n) 33 | { 34 | if (!plan) 35 | { 36 | std::lock_guard lock(planMutex); 37 | plan = fftw_plan_dft_1d(n, src, dst, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 38 | } 39 | fftw_execute_dft(plan, src, dst); 40 | } 41 | 42 | inline void inv(fftw_complex* src, fftw_complex* dst, unsigned int n) { 43 | if (!plan) 44 | { 45 | std::lock_guard lock(planMutex); 46 | plan = fftw_plan_dft_1d(n, src, dst, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 47 | } 48 | fftw_execute_dft(plan, src, dst); 49 | } 50 | 51 | inline void fwd(double* src, fftw_complex* dst, unsigned int n) 52 | { 53 | if (!plan) 54 | { 55 | std::lock_guard lock(planMutex); 56 | plan = fftw_plan_dft_r2c_1d(n, src, dst, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 57 | } 58 | fftw_execute_dft_r2c(plan, src, dst); 59 | } 60 | 61 | inline void inv(fftw_complex* src, double* dst, unsigned int n) 62 | { 63 | if (!plan) 64 | { 65 | std::lock_guard lock(planMutex); 66 | plan = fftw_plan_dft_c2r_1d(n, src, dst, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 67 | } 68 | fftw_execute_dft_c2r(plan, src, dst); 69 | } 70 | 71 | // 2D 72 | 73 | inline void fwd(fftw_complex* src, fftw_complex* dst, unsigned int n0, unsigned int n1) 74 | { 75 | if (!plan) 76 | { 77 | std::lock_guard lock(planMutex); 78 | plan = fftw_plan_dft_2d(n0, n1, src, dst, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 79 | } 80 | fftw_execute_dft(plan, src, dst); 81 | } 82 | 83 | inline void inv(fftw_complex* src, fftw_complex* dst, unsigned int n0, unsigned int n1) 84 | { 85 | if (!plan) 86 | { 87 | std::lock_guard lock(planMutex); 88 | plan = fftw_plan_dft_2d(n0, n1, src, dst, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 89 | } 90 | fftw_execute_dft(plan, src, dst); 91 | } 92 | 93 | inline void fwd(double* src, fftw_complex* dst, unsigned int n0, unsigned int n1) 94 | { 95 | if (!plan) 96 | { 97 | std::lock_guard lock(planMutex); 98 | plan = fftw_plan_dft_r2c_2d(n0, n1, src, dst, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 99 | } 100 | fftw_execute_dft_r2c(plan, src, dst); 101 | } 102 | 103 | inline void inv(fftw_complex* src, double* dst, unsigned int n0, unsigned int n1) 104 | { 105 | if (!plan) 106 | { 107 | std::lock_guard lock(planMutex); 108 | plan = fftw_plan_dft_c2r_2d(n0, n1, src, dst, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 109 | } 110 | fftw_execute_dft_c2r(plan, src, dst); 111 | } 112 | 113 | // 3D 114 | 115 | inline void fwd(fftw_complex* src, fftw_complex* dst, unsigned int n0, unsigned int n1, unsigned int n2) 116 | { 117 | if (!plan) 118 | { 119 | std::lock_guard lock(planMutex); 120 | plan = fftw_plan_dft_3d(n0, n1, n2, src, dst, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 121 | } 122 | fftw_execute_dft(plan, src, dst); 123 | } 124 | 125 | inline void inv(fftw_complex* src, fftw_complex* dst, unsigned int n0, unsigned int n1, unsigned int n2) 126 | { 127 | if (!plan) 128 | { 129 | std::lock_guard lock(planMutex); 130 | plan = fftw_plan_dft_3d(n0, n1, n2, src, dst, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 131 | } 132 | fftw_execute_dft(plan, src, dst); 133 | } 134 | 135 | inline void fwd(double* src, fftw_complex* dst, unsigned int n0, unsigned int n1, unsigned int n2) 136 | { 137 | if (!plan) 138 | { 139 | std::lock_guard lock(planMutex); 140 | plan = fftw_plan_dft_r2c_3d(n0, n1, n2, src, dst, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 141 | } 142 | fftw_execute_dft_r2c(plan, src, dst); 143 | } 144 | 145 | inline void inv(fftw_complex* src, double* dst, unsigned int n0, unsigned int n1, unsigned int n2) 146 | { 147 | if (!plan) 148 | { 149 | std::lock_guard lock(planMutex); 150 | plan = fftw_plan_dft_c2r_3d(n0, n1, n2, src, dst, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT); 151 | } 152 | fftw_execute_dft_c2r(plan, src, dst); 153 | } 154 | 155 | static std::mutex planMutex; 156 | 157 | private: 158 | fftw_plan plan = nullptr; 159 | }; 160 | 161 | class FFT 162 | { 163 | public: 164 | explicit FFT(int numThreads = 0); // zero means let it alone for FFTW to decide 165 | 166 | // 1D 167 | 168 | inline void fwd(const std::complex* src, std::complex *dst, unsigned int n) 169 | { 170 | GetPlan(false, false, src, dst, n).fwd(reinterpret_cast(const_cast*>(src)), reinterpret_cast(dst), n); 171 | } 172 | 173 | inline void inv(const std::complex* src, std::complex *dst, unsigned int n) 174 | { 175 | GetPlan(true, false, src, dst, n).inv(reinterpret_cast(const_cast*>(src)), reinterpret_cast(dst), n); 176 | } 177 | 178 | inline void fwd(double* src, std::complex *dst, unsigned int n) 179 | { 180 | GetPlan(false, true, src, dst, n).fwd(src, reinterpret_cast(dst), n); 181 | } 182 | 183 | inline void inv(std::complex* src, double *dst, unsigned int n) 184 | { 185 | GetPlan(true, true, src, dst, n).inv(reinterpret_cast(const_cast*>(src)), dst, n); 186 | } 187 | 188 | // 2D 189 | 190 | inline void fwd(const std::complex* src, std::complex *dst, unsigned int n0, unsigned int n1) 191 | { 192 | GetPlan(false, false, src, dst, n0, n1).fwd(reinterpret_cast(const_cast*>(src)), reinterpret_cast(dst), n0, n1); 193 | } 194 | 195 | inline void inv(const std::complex* src, std::complex *dst, unsigned int n0, unsigned int n1) 196 | { 197 | GetPlan(true, false, src, dst, n0, n1).inv(reinterpret_cast(const_cast*>(src)), reinterpret_cast(dst), n0, n1); 198 | } 199 | 200 | 201 | // 3D 202 | 203 | inline void fwd(const std::complex* src, std::complex *dst, unsigned int n0, unsigned int n1, unsigned int n2) 204 | { 205 | GetPlan(false, false, src, dst, n0, n1, n2).fwd(reinterpret_cast(const_cast*>(src)), reinterpret_cast(dst), n0, n1, n2); 206 | } 207 | 208 | inline void inv(const std::complex* src, std::complex *dst, unsigned int n0, unsigned int n1, unsigned int n2) 209 | { 210 | GetPlan(true, false, src, dst, n0, n1, n2).inv(reinterpret_cast(const_cast*>(src)), reinterpret_cast(dst), n0, n1, n2); 211 | } 212 | 213 | void Clear() 214 | { 215 | Plans1D.clear(); 216 | Plans2D.clear(); 217 | Plans3D.clear(); 218 | //fftw_cleanup_threads(); 219 | } 220 | 221 | void SetNumThreads(int numThreads); 222 | 223 | private: 224 | // in place, aligned, inverse, different types, n 225 | std::map, FFTWPlan> Plans1D; 226 | 227 | // in place, aligned, inverse, different types, n1, n2 228 | std::map, FFTWPlan> Plans2D; 229 | 230 | // in place, aligned, inverse, different types, n1, n2, n3 231 | std::map, FFTWPlan> Plans3D; 232 | 233 | inline bool InPlace(const void *src, const void *dst) { return src == dst; } 234 | inline bool Aligned(const void *src, const void *dst) { return ((reinterpret_cast(src) & 0xF) | (reinterpret_cast(dst) & 0xF)) == 0; } 235 | 236 | inline FFTWPlan& GetPlan(bool inverse, bool differentTypes, const void *src, void* dst, unsigned int n) 237 | { 238 | return Plans1D[std::tuple(InPlace(src, dst), Aligned(src, dst), inverse, differentTypes, n)]; 239 | } 240 | 241 | inline FFTWPlan& GetPlan(bool inverse, bool differentTypes, const void *src, void* dst, unsigned int n0, unsigned int n1) 242 | { 243 | return Plans2D[std::tuple(InPlace(src, dst), Aligned(src, dst), inverse, differentTypes, n0, n1)]; 244 | } 245 | 246 | inline FFTWPlan& GetPlan(bool inverse, bool differentTypes, const void *src, void* dst, unsigned int n0, unsigned int n1, unsigned int n2) 247 | { 248 | return Plans3D[std::tuple(InPlace(src, dst), Aligned(src, dst), inverse, differentTypes, n0, n1, n2)]; 249 | } 250 | 251 | static const int init; 252 | }; 253 | 254 | 255 | } -------------------------------------------------------------------------------- /NMRI/MainFrm.cpp: -------------------------------------------------------------------------------- 1 | 2 | // MainFrm.cpp : implementation of the CMainFrame class 3 | // 4 | 5 | #include "stdafx.h" 6 | #include "NMRI.h" 7 | 8 | #include "MainFrm.h" 9 | #include "NMRIDoc.h" 10 | #include "NMRIView.h" 11 | #include "VTKView.h" 12 | 13 | #ifdef _DEBUG 14 | #define new DEBUG_NEW 15 | #endif 16 | 17 | // CMainFrame 18 | 19 | IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx) 20 | 21 | const int iMaxUserToolbars = 10; 22 | const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40; 23 | const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1; 24 | 25 | BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx) 26 | ON_WM_CREATE() 27 | ON_COMMAND(ID_VIEW_CUSTOMIZE, &CMainFrame::OnViewCustomize) 28 | ON_REGISTERED_MESSAGE(AFX_WM_CREATETOOLBAR, &CMainFrame::OnToolbarCreateNew) 29 | ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnApplicationLook) 30 | ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_WINDOWS_7, &CMainFrame::OnUpdateApplicationLook) 31 | ON_COMMAND(ID_FILE_OPEN, &CMainFrame::OnFileOpen) 32 | ON_COMMAND(ID_VIEW_ANIMATION, &CMainFrame::OnViewAnimation) 33 | ON_UPDATE_COMMAND_UI(ID_VIEW_ANIMATION, &CMainFrame::OnUpdateViewAnimation) 34 | END_MESSAGE_MAP() 35 | 36 | static UINT indicators[] = 37 | { 38 | ID_SEPARATOR, // status line indicator 39 | ID_INDICATOR_CAPS, 40 | ID_INDICATOR_NUM, 41 | ID_INDICATOR_SCRL, 42 | }; 43 | 44 | // CMainFrame construction/destruction 45 | 46 | CMainFrame::CMainFrame() 47 | { 48 | // TODO: add member initialization code here 49 | theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2008); 50 | } 51 | 52 | int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 53 | { 54 | if (CFrameWndEx::OnCreate(lpCreateStruct) == -1) 55 | return -1; 56 | 57 | if (!m_wndMenuBar.Create(this)) 58 | { 59 | TRACE0("Failed to create menubar\n"); 60 | return -1; // fail to create 61 | } 62 | 63 | m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY); 64 | 65 | // prevent the menu bar from taking the focus on activation 66 | CMFCPopupMenu::SetForceMenuFocus(FALSE); 67 | 68 | if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 69 | !m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME)) 70 | { 71 | TRACE0("Failed to create toolbar\n"); 72 | return -1; // fail to create 73 | } 74 | 75 | CString strToolBarName; 76 | BOOL bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD); 77 | ASSERT(bNameValid); 78 | m_wndToolBar.SetWindowText(strToolBarName); 79 | 80 | CString strCustomize; 81 | bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE); 82 | ASSERT(bNameValid); 83 | m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize); 84 | 85 | // Allow user-defined toolbars operations: 86 | InitUserToolbars(nullptr, uiFirstUserToolBarId, uiLastUserToolBarId); 87 | 88 | if (!m_wndStatusBar.Create(this)) 89 | { 90 | TRACE0("Failed to create status bar\n"); 91 | return -1; // fail to create 92 | } 93 | m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)); 94 | 95 | // TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable 96 | m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY); 97 | m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 98 | EnableDocking(CBRS_ALIGN_ANY); 99 | DockPane(&m_wndMenuBar); 100 | DockPane(&m_wndToolBar); 101 | 102 | 103 | // enable Visual Studio 2005 style docking window behavior 104 | CDockingManager::SetDockingMode(DT_SMART); 105 | // enable Visual Studio 2005 style docking window auto-hide behavior 106 | EnableAutoHidePanes(CBRS_ALIGN_ANY); 107 | 108 | // create docking windows 109 | if (!CreateDockingWindows()) 110 | { 111 | TRACE0("Failed to create docking windows\n"); 112 | return -1; 113 | } 114 | 115 | m_wndProperties.EnableDocking(CBRS_ALIGN_ANY); 116 | DockPane(&m_wndProperties); 117 | 118 | // set the visual manager and style based on persisted value 119 | OnApplicationLook(theApp.m_nAppLook); 120 | 121 | // Enable toolbar and docking window menu replacement 122 | EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR); 123 | 124 | // enable quick (Alt+drag) toolbar customization 125 | CMFCToolBar::EnableQuickCustomization(); 126 | 127 | if (CMFCToolBar::GetUserImages() == nullptr) 128 | { 129 | // load user-defined toolbar images 130 | if (m_UserImages.Load(_T(".\\UserImages.bmp"))) 131 | { 132 | CMFCToolBar::SetUserImages(&m_UserImages); 133 | } 134 | } 135 | 136 | // enable menu personalization (most-recently used commands) 137 | // TODO: define your own basic commands, ensuring that each pulldown menu has at least one basic command. 138 | CList lstBasicCommands; 139 | 140 | //lstBasicCommands.AddTail(ID_FILE_OPEN); 141 | lstBasicCommands.AddTail(ID_FILE_PRINT); 142 | lstBasicCommands.AddTail(ID_APP_EXIT); 143 | lstBasicCommands.AddTail(ID_APP_ABOUT); 144 | lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR); 145 | lstBasicCommands.AddTail(ID_VIEW_TOOLBAR); 146 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2003); 147 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_VS_2005); 148 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLUE); 149 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_SILVER); 150 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLACK); 151 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_AQUA); 152 | lstBasicCommands.AddTail(ID_VIEW_APPLOOK_WINDOWS_7); 153 | 154 | CMFCToolBar::SetBasicCommands(lstBasicCommands); 155 | 156 | return 0; 157 | } 158 | 159 | BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 160 | { 161 | if( !CFrameWndEx::PreCreateWindow(cs) ) 162 | return FALSE; 163 | // TODO: Modify the Window class or styles here by modifying 164 | // the CREATESTRUCT cs 165 | 166 | return TRUE; 167 | } 168 | 169 | BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) 170 | { 171 | return static_cast(static_cast(m_wndSplitter.CreateStatic(this, 1, 2)) && m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CNMRIView), CSize(1100, 128), pContext) && m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CVTKView), CSize(128, 128), pContext)); 172 | } 173 | 174 | 175 | BOOL CMainFrame::CreateDockingWindows() 176 | { 177 | BOOL bNameValid; 178 | // Create properties window 179 | CString strPropertiesWnd; 180 | bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND); 181 | ASSERT(bNameValid); 182 | if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI)) 183 | { 184 | TRACE0("Failed to create Properties window\n"); 185 | return FALSE; // failed to create 186 | } 187 | 188 | SetDockingWindowIcons(theApp.m_bHiColorIcons); 189 | return TRUE; 190 | } 191 | 192 | void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons) 193 | { 194 | HICON hPropertiesBarIcon = static_cast(::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0)); 195 | m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE); 196 | } 197 | 198 | // CMainFrame diagnostics 199 | 200 | #ifdef _DEBUG 201 | void CMainFrame::AssertValid() const 202 | { 203 | CFrameWndEx::AssertValid(); 204 | } 205 | 206 | void CMainFrame::Dump(CDumpContext& dc) const 207 | { 208 | CFrameWndEx::Dump(dc); 209 | } 210 | #endif //_DEBUG 211 | 212 | 213 | // CMainFrame message handlers 214 | 215 | void CMainFrame::OnViewCustomize() 216 | { 217 | CMFCToolBarsCustomizeDialog* pDlgCust = new CMFCToolBarsCustomizeDialog(this, TRUE /* scan menus */); 218 | pDlgCust->EnableUserDefinedToolbars(); 219 | pDlgCust->Create(); 220 | } 221 | 222 | LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp) 223 | { 224 | LRESULT lres = CFrameWndEx::OnToolbarCreateNew(wp,lp); 225 | if (lres == 0) 226 | { 227 | return 0; 228 | } 229 | 230 | CMFCToolBar* pUserToolbar = (CMFCToolBar*)lres; 231 | ASSERT_VALID(pUserToolbar); 232 | 233 | BOOL bNameValid; 234 | CString strCustomize; 235 | bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE); 236 | ASSERT(bNameValid); 237 | 238 | pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize); 239 | return lres; 240 | } 241 | 242 | void CMainFrame::OnApplicationLook(UINT id) 243 | { 244 | CWaitCursor wait; 245 | 246 | theApp.m_nAppLook = id; 247 | 248 | switch (theApp.m_nAppLook) 249 | { 250 | case ID_VIEW_APPLOOK_WIN_2000: 251 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManager)); 252 | break; 253 | 254 | case ID_VIEW_APPLOOK_OFF_XP: 255 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOfficeXP)); 256 | break; 257 | 258 | case ID_VIEW_APPLOOK_WIN_XP: 259 | CMFCVisualManagerWindows::m_b3DTabsXPTheme = TRUE; 260 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 261 | break; 262 | 263 | case ID_VIEW_APPLOOK_OFF_2003: 264 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2003)); 265 | CDockingManager::SetDockingMode(DT_SMART); 266 | break; 267 | 268 | case ID_VIEW_APPLOOK_VS_2005: 269 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005)); 270 | CDockingManager::SetDockingMode(DT_SMART); 271 | break; 272 | 273 | case ID_VIEW_APPLOOK_VS_2008: 274 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2008)); 275 | CDockingManager::SetDockingMode(DT_SMART); 276 | break; 277 | 278 | case ID_VIEW_APPLOOK_WINDOWS_7: 279 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows7)); 280 | CDockingManager::SetDockingMode(DT_SMART); 281 | break; 282 | 283 | default: 284 | switch (theApp.m_nAppLook) 285 | { 286 | case ID_VIEW_APPLOOK_OFF_2007_BLUE: 287 | CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue); 288 | break; 289 | 290 | case ID_VIEW_APPLOOK_OFF_2007_BLACK: 291 | CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack); 292 | break; 293 | 294 | case ID_VIEW_APPLOOK_OFF_2007_SILVER: 295 | CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver); 296 | break; 297 | 298 | case ID_VIEW_APPLOOK_OFF_2007_AQUA: 299 | CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua); 300 | break; 301 | } 302 | 303 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007)); 304 | CDockingManager::SetDockingMode(DT_SMART); 305 | } 306 | 307 | RedrawWindow(nullptr, nullptr, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE); 308 | 309 | theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook); 310 | } 311 | 312 | void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI) 313 | { 314 | pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID); 315 | } 316 | 317 | 318 | BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) 319 | { 320 | // base class does the real work 321 | 322 | if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext)) 323 | { 324 | return FALSE; 325 | } 326 | 327 | 328 | // enable customization button for all user toolbars 329 | BOOL bNameValid; 330 | CString strCustomize; 331 | bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE); 332 | ASSERT(bNameValid); 333 | 334 | for (int i = 0; i < iMaxUserToolbars; i ++) 335 | { 336 | CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i); 337 | if (pUserToolbar != nullptr) 338 | { 339 | pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize); 340 | } 341 | } 342 | 343 | return TRUE; 344 | } 345 | 346 | 347 | 348 | void CMainFrame::OnFileOpen() 349 | { 350 | TCHAR szFilters[] = _T("Dat Files (*.dat)|*.dat|All Files (*.*)|*.*||"); 351 | 352 | CFileDialog dlg(TRUE,_T("dat"), _T("*.dat"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters); 353 | 354 | if (IDOK == dlg.DoModal()) 355 | { 356 | CString pathName = dlg.GetPathName(); 357 | 358 | CNMRIDoc* pDoc = dynamic_cast(GetActiveDocument()); 359 | 360 | if (pDoc) 361 | { 362 | if (!pathName.IsEmpty()) 363 | { 364 | if (pDoc->Load(pathName)) 365 | pDoc->SetTitle(dlg.GetFileTitle()); 366 | } 367 | } 368 | } 369 | } 370 | 371 | 372 | 373 | 374 | 375 | void CMainFrame::Init() 376 | { 377 | CNMRIDoc* pDoc = dynamic_cast(GetActiveDocument()); 378 | 379 | if (pDoc) 380 | { 381 | m_wndProperties.theDoc = pDoc; 382 | } 383 | } 384 | 385 | 386 | void CMainFrame::OnViewAnimation() 387 | { 388 | CNMRIDoc* pDoc = dynamic_cast(GetActiveDocument()); 389 | 390 | if (pDoc) 391 | { 392 | pDoc->animate = !pDoc->animate; 393 | } 394 | } 395 | 396 | 397 | void CMainFrame::OnUpdateViewAnimation(CCmdUI* pCmdUI) 398 | { 399 | CNMRIDoc* pDoc = dynamic_cast(GetActiveDocument()); 400 | 401 | if (pDoc) 402 | { 403 | pCmdUI->SetCheck(pDoc->animate); 404 | } 405 | } 406 | -------------------------------------------------------------------------------- /NMRI/NMRI.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #ifndef APSTUDIO_INVOKED 11 | #include "targetver.h" 12 | #endif 13 | #include "afxres.h" 14 | #include "verrsrc.h" 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | #undef APSTUDIO_READONLY_SYMBOLS 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | // English (United States) resources 21 | 22 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 23 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 24 | #pragma code_page(1252) 25 | 26 | #ifdef APSTUDIO_INVOKED 27 | ///////////////////////////////////////////////////////////////////////////// 28 | // 29 | // TEXTINCLUDE 30 | // 31 | 32 | 1 TEXTINCLUDE 33 | BEGIN 34 | "resource.h\0" 35 | END 36 | 37 | 2 TEXTINCLUDE 38 | BEGIN 39 | "#ifndef APSTUDIO_INVOKED\r\n" 40 | "#include ""targetver.h""\r\n" 41 | "#endif\r\n" 42 | "#include ""afxres.h""\r\n" 43 | "#include ""verrsrc.h""\r\n" 44 | "\0" 45 | END 46 | 47 | 3 TEXTINCLUDE 48 | BEGIN 49 | "#define _AFX_NO_OLE_RESOURCES\r\n" 50 | "#define _AFX_NO_TRACKER_RESOURCES\r\n" 51 | "#define _AFX_NO_PROPERTY_RESOURCES\r\n" 52 | "\r\n" 53 | "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" 54 | "LANGUAGE 9, 1\r\n" 55 | "#include ""res\\NMRI.rc2"" // non-Microsoft Visual C++ edited resources\r\n" 56 | "#include ""afxres.rc"" // Standard components\r\n" 57 | "#include ""afxprint.rc"" // printing/print preview resources\r\n" 58 | "#if !defined(_AFXDLL)\r\n" 59 | "#include ""afxribbon.rc"" // MFC ribbon and control bar resources\r\n" 60 | "#endif\r\n" 61 | "#endif\r\n" 62 | "\0" 63 | END 64 | 65 | #endif // APSTUDIO_INVOKED 66 | 67 | 68 | ///////////////////////////////////////////////////////////////////////////// 69 | // 70 | // Icon 71 | // 72 | 73 | // Icon with lowest ID value placed first to ensure application icon 74 | // remains consistent on all systems. 75 | IDR_MAINFRAME ICON "res\\NMRI.ico" 76 | 77 | IDR_NMRITYPE ICON "res\\NMRIDoc.ico" 78 | 79 | IDI_PROPERTIES_WND ICON "res\\properties_wnd.ico" 80 | 81 | IDI_PROPERTIES_WND_HC ICON "res\\properties_wnd_hc.ico" 82 | 83 | 84 | ///////////////////////////////////////////////////////////////////////////// 85 | // 86 | // Bitmap 87 | // 88 | 89 | IDR_MAINFRAME BITMAP "res\\Toolbar.bmp" 90 | 91 | IDR_MAINFRAME_256 BITMAP "res\\Toolbar256.bmp" 92 | 93 | 94 | ///////////////////////////////////////////////////////////////////////////// 95 | // 96 | // Toolbar 97 | // 98 | 99 | IDR_MAINFRAME TOOLBAR 16, 15 100 | BEGIN 101 | BUTTON ID_VIEW_ANIMATION 102 | SEPARATOR 103 | BUTTON ID_FILE_PRINT 104 | BUTTON ID_APP_ABOUT 105 | END 106 | 107 | IDR_MAINFRAME_256 TOOLBAR 16, 15 108 | BEGIN 109 | BUTTON ID_VIEW_ANIMATION 110 | SEPARATOR 111 | BUTTON ID_FILE_PRINT 112 | BUTTON ID_APP_ABOUT 113 | END 114 | 115 | 116 | ///////////////////////////////////////////////////////////////////////////// 117 | // 118 | // Menu 119 | // 120 | 121 | IDR_MAINFRAME MENU 122 | BEGIN 123 | POPUP "&File" 124 | BEGIN 125 | MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT 126 | MENUITEM "Print Pre&view", ID_FILE_PRINT_PREVIEW 127 | MENUITEM "P&rint Setup...", ID_FILE_PRINT_SETUP 128 | MENUITEM SEPARATOR 129 | MENUITEM "E&xit", ID_APP_EXIT 130 | END 131 | POPUP "&View" 132 | BEGIN 133 | POPUP "&Toolbars and Docking Windows" 134 | BEGIN 135 | MENUITEM "", ID_VIEW_TOOLBAR 136 | END 137 | MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR 138 | POPUP "&Application Look" 139 | BEGIN 140 | MENUITEM "Windows &2000", ID_VIEW_APPLOOK_WIN_2000 141 | MENUITEM "Office &XP", ID_VIEW_APPLOOK_OFF_XP 142 | MENUITEM "&Windows XP", ID_VIEW_APPLOOK_WIN_XP 143 | MENUITEM "Office 200&3", ID_VIEW_APPLOOK_OFF_2003 144 | MENUITEM "Visual Studio 200&5", ID_VIEW_APPLOOK_VS_2005 145 | MENUITEM "Visual Studio 200&8", ID_VIEW_APPLOOK_VS_2008 146 | POPUP "Office 200&7" 147 | BEGIN 148 | MENUITEM "&Blue Style", ID_VIEW_APPLOOK_OFF_2007_BLUE 149 | MENUITEM "B&lack Style", ID_VIEW_APPLOOK_OFF_2007_BLACK 150 | MENUITEM "&Silver Style", ID_VIEW_APPLOOK_OFF_2007_SILVER 151 | MENUITEM "&Aqua Style", ID_VIEW_APPLOOK_OFF_2007_AQUA 152 | END 153 | END 154 | MENUITEM SEPARATOR 155 | MENUITEM "A&nimation", ID_VIEW_ANIMATION, CHECKED 156 | END 157 | POPUP "&Help" 158 | BEGIN 159 | MENUITEM "&About NMRI...", ID_APP_ABOUT 160 | END 161 | END 162 | 163 | IDR_HELP_MENU MENU 164 | BEGIN 165 | MENUITEM "&About NMRI...", ID_APP_ABOUT 166 | END 167 | 168 | IDR_THEME_MENU MENU 169 | BEGIN 170 | MENUITEM "Office 2007 (&Blue Style)", ID_VIEW_APPLOOK_OFF_2007_BLUE 171 | MENUITEM "Office 2007 (B&lack Style)", ID_VIEW_APPLOOK_OFF_2007_BLACK 172 | MENUITEM "Office 2007 (&Silver Style)", ID_VIEW_APPLOOK_OFF_2007_SILVER 173 | MENUITEM "Office 2007 (&Aqua Style)", ID_VIEW_APPLOOK_OFF_2007_AQUA 174 | MENUITEM "Win&dows 7", ID_VIEW_APPLOOK_WINDOWS_7 175 | END 176 | 177 | 178 | ///////////////////////////////////////////////////////////////////////////// 179 | // 180 | // Accelerator 181 | // 182 | 183 | IDR_MAINFRAME ACCELERATORS 184 | BEGIN 185 | "P", ID_FILE_PRINT, VIRTKEY, CONTROL, NOINVERT 186 | VK_F6, ID_NEXT_PANE, VIRTKEY, NOINVERT 187 | VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT, NOINVERT 188 | END 189 | 190 | 191 | ///////////////////////////////////////////////////////////////////////////// 192 | // 193 | // Dialog 194 | // 195 | 196 | IDD_ABOUTBOX DIALOGEX 0, 0, 171, 77 197 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 198 | CAPTION "About NMRI" 199 | FONT 8, "MS Shell Dlg", 0, 0, 0x1 200 | BEGIN 201 | ICON IDR_MAINFRAME,IDC_STATIC,14,14,21,20 202 | LTEXT "NMRI, Version 1.0",IDC_STATIC,43,14,114,8,SS_NOPREFIX 203 | DEFPUSHBUTTON "OK",IDOK,114,56,50,14,WS_GROUP 204 | CONTROL "GitHub repository",IDC_MFCLINK1,"MfcLink",WS_TABSTOP,43,24,114,14 205 | CONTROL "Blog description",IDC_MFCLINK2,"MfcLink",WS_TABSTOP,43,40,114,14 206 | END 207 | 208 | 209 | ///////////////////////////////////////////////////////////////////////////// 210 | // 211 | // Version 212 | // 213 | 214 | VS_VERSION_INFO VERSIONINFO 215 | FILEVERSION 1,0,0,1 216 | PRODUCTVERSION 1,0,0,1 217 | FILEFLAGSMASK 0x3fL 218 | #ifdef _DEBUG 219 | FILEFLAGS 0x1L 220 | #else 221 | FILEFLAGS 0x0L 222 | #endif 223 | FILEOS 0x40004L 224 | FILETYPE 0x1L 225 | FILESUBTYPE 0x0L 226 | BEGIN 227 | BLOCK "StringFileInfo" 228 | BEGIN 229 | BLOCK "040904b0" 230 | BEGIN 231 | VALUE "FileDescription", "NMRI" 232 | VALUE "FileVersion", "1.0.0.1" 233 | VALUE "InternalName", "NMRI.exe" 234 | VALUE "OriginalFilename", "NMRI.exe" 235 | VALUE "ProductName", "NMRI" 236 | VALUE "ProductVersion", "1.0.0.1" 237 | END 238 | END 239 | BLOCK "VarFileInfo" 240 | BEGIN 241 | VALUE "Translation", 0x409, 1200 242 | END 243 | END 244 | 245 | 246 | ///////////////////////////////////////////////////////////////////////////// 247 | // 248 | // DESIGNINFO 249 | // 250 | 251 | #ifdef APSTUDIO_INVOKED 252 | GUIDELINES DESIGNINFO 253 | BEGIN 254 | IDD_ABOUTBOX, DIALOG 255 | BEGIN 256 | LEFTMARGIN, 7 257 | RIGHTMARGIN, 164 258 | TOPMARGIN, 7 259 | BOTTOMMARGIN, 70 260 | END 261 | END 262 | #endif // APSTUDIO_INVOKED 263 | 264 | 265 | ///////////////////////////////////////////////////////////////////////////// 266 | // 267 | // AFX_DIALOG_LAYOUT 268 | // 269 | 270 | IDD_ABOUTBOX AFX_DIALOG_LAYOUT 271 | BEGIN 272 | 0 273 | END 274 | 275 | 276 | ///////////////////////////////////////////////////////////////////////////// 277 | // 278 | // Dialog Info 279 | // 280 | 281 | IDD_ABOUTBOX DLGINIT 282 | BEGIN 283 | IDC_MFCLINK1, 0x37c, 189, 0 284 | 0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x673e, 0x7469, 0x7568, 285 | 0x2e62, 0x6f63, 0x2f6d, 0x7261, 0x6d6f, 0x6e61, 0x6f72, 0x4e2f, 0x524d, 286 | 0x3c49, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x3c3e, 0x464d, 287 | 0x4c43, 0x6e69, 0x5f6b, 0x7255, 0x506c, 0x6572, 0x6966, 0x3e78, 0x7468, 288 | 0x7074, 0x3a73, 0x2f2f, 0x2f3c, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x7255, 289 | 0x506c, 0x6572, 0x6966, 0x3e78, 0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x545f, 290 | 0x6f6f, 0x746c, 0x7069, 0x3c3e, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x545f, 291 | 0x6f6f, 0x746c, 0x7069, 0x3c3e, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x7546, 292 | 0x6c6c, 0x6554, 0x7478, 0x6f54, 0x6c6f, 0x6974, 0x3e70, 0x4146, 0x534c, 293 | 0x3c45, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x465f, 0x6c75, 0x546c, 0x7865, 294 | 0x5474, 0x6f6f, 0x746c, 0x7069, "\076" 295 | IDC_MFCLINK2, 0x37c, 229, 0 296 | 0x4d3c, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 0x633e, 0x6d6f, 0x7070, 297 | 0x7968, 0x2e73, 0x6f67, 0x722e, 0x2f6f, 0x756e, 0x6c63, 0x6165, 0x2d72, 298 | 0x616d, 0x6e67, 0x7465, 0x6369, 0x722d, 0x7365, 0x6e6f, 0x6e61, 0x6563, 299 | 0x612d, 0x646e, 0x662d, 0x756f, 0x6972, 0x7265, 0x742d, 0x6172, 0x736e, 300 | 0x6f66, 0x6d72, 0x3c2f, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x555f, 0x6c72, 301 | 0x3c3e, 0x464d, 0x4c43, 0x6e69, 0x5f6b, 0x7255, 0x506c, 0x6572, 0x6966, 302 | 0x3e78, 0x7468, 0x7074, 0x3a73, 0x2f2f, 0x2f3c, 0x464d, 0x4c43, 0x6e69, 303 | 0x5f6b, 0x7255, 0x506c, 0x6572, 0x6966, 0x3e78, 0x4d3c, 0x4346, 0x694c, 304 | 0x6b6e, 0x545f, 0x6f6f, 0x746c, 0x7069, 0x3c3e, 0x4d2f, 0x4346, 0x694c, 305 | 0x6b6e, 0x545f, 0x6f6f, 0x746c, 0x7069, 0x3c3e, 0x464d, 0x4c43, 0x6e69, 306 | 0x5f6b, 0x7546, 0x6c6c, 0x6554, 0x7478, 0x6f54, 0x6c6f, 0x6974, 0x3e70, 307 | 0x4146, 0x534c, 0x3c45, 0x4d2f, 0x4346, 0x694c, 0x6b6e, 0x465f, 0x6c75, 308 | 0x546c, 0x7865, 0x5474, 0x6f6f, 0x746c, 0x7069, "\076" 309 | 0 310 | END 311 | 312 | 313 | ///////////////////////////////////////////////////////////////////////////// 314 | // 315 | // String Table 316 | // 317 | 318 | STRINGTABLE 319 | BEGIN 320 | IDR_MAINFRAME "NMRI\n\nNMRI\n\n\nNMRI.Document\nNMRI.Document" 321 | END 322 | 323 | STRINGTABLE 324 | BEGIN 325 | AFX_IDS_APP_TITLE "NMRI" 326 | AFX_IDS_IDLEMESSAGE "Ready" 327 | END 328 | 329 | STRINGTABLE 330 | BEGIN 331 | ID_INDICATOR_EXT "EXT" 332 | ID_INDICATOR_CAPS "CAP" 333 | ID_INDICATOR_NUM "NUM" 334 | ID_INDICATOR_SCRL "SCRL" 335 | ID_INDICATOR_OVR "OVR" 336 | ID_INDICATOR_REC "REC" 337 | END 338 | 339 | STRINGTABLE 340 | BEGIN 341 | ID_FILE_OPEN "Open an existing document\nOpen" 342 | ID_FILE_PAGE_SETUP "Change the printing options\nPage Setup" 343 | ID_FILE_PRINT_SETUP "Change the printer and printing options\nPrint Setup" 344 | ID_FILE_PRINT "Print the active document\nPrint" 345 | ID_FILE_PRINT_DIRECT "Print the active document using current options\nQuick Print" 346 | ID_FILE_PRINT_PREVIEW "Display full pages\nPrint Preview" 347 | END 348 | 349 | STRINGTABLE 350 | BEGIN 351 | ID_APP_ABOUT "Display program information, version number and copyright\nAbout" 352 | ID_APP_EXIT "Quit the application; prompts to save documents\nExit" 353 | END 354 | 355 | STRINGTABLE 356 | BEGIN 357 | ID_FILE_MRU_FILE1 "Open this document" 358 | ID_FILE_MRU_FILE2 "Open this document" 359 | ID_FILE_MRU_FILE3 "Open this document" 360 | ID_FILE_MRU_FILE4 "Open this document" 361 | ID_FILE_MRU_FILE5 "Open this document" 362 | ID_FILE_MRU_FILE6 "Open this document" 363 | ID_FILE_MRU_FILE7 "Open this document" 364 | ID_FILE_MRU_FILE8 "Open this document" 365 | ID_FILE_MRU_FILE9 "Open this document" 366 | ID_FILE_MRU_FILE10 "Open this document" 367 | ID_FILE_MRU_FILE11 "Open this document" 368 | ID_FILE_MRU_FILE12 "Open this document" 369 | ID_FILE_MRU_FILE13 "Open this document" 370 | ID_FILE_MRU_FILE14 "Open this document" 371 | ID_FILE_MRU_FILE15 "Open this document" 372 | ID_FILE_MRU_FILE16 "Open this document" 373 | END 374 | 375 | STRINGTABLE 376 | BEGIN 377 | ID_NEXT_PANE "Switch to the next window pane\nNext Pane" 378 | ID_PREV_PANE "Switch back to the previous window pane\nPrevious Pane" 379 | END 380 | 381 | STRINGTABLE 382 | BEGIN 383 | ID_WINDOW_SPLIT "Split the active window into panes\nSplit" 384 | END 385 | 386 | STRINGTABLE 387 | BEGIN 388 | ID_EDIT_SELECT_ALL "Select the entire document\nSelect All" 389 | END 390 | 391 | STRINGTABLE 392 | BEGIN 393 | ID_VIEW_STATUS_BAR "Show or hide the status bar\nToggle Status Bar" 394 | END 395 | 396 | STRINGTABLE 397 | BEGIN 398 | AFX_IDS_SCSIZE "Change the window size" 399 | AFX_IDS_SCMOVE "Change the window position" 400 | AFX_IDS_SCMINIMIZE "Reduce the window to an icon" 401 | AFX_IDS_SCMAXIMIZE "Enlarge the window to full size" 402 | AFX_IDS_SCNEXTWINDOW "Switch to the next document window" 403 | AFX_IDS_SCPREVWINDOW "Switch to the previous document window" 404 | AFX_IDS_SCCLOSE "Close the active window and prompts to save the documents" 405 | END 406 | 407 | STRINGTABLE 408 | BEGIN 409 | AFX_IDS_SCRESTORE "Restore the window to normal size" 410 | AFX_IDS_SCTASKLIST "Activate Task List" 411 | END 412 | 413 | STRINGTABLE 414 | BEGIN 415 | AFX_IDS_PREVIEW_CLOSE "Close print preview mode\nCancel Preview" 416 | END 417 | 418 | STRINGTABLE 419 | BEGIN 420 | IDS_STATUS_PANE1 "Pane 1" 421 | IDS_STATUS_PANE2 "Pane 2" 422 | IDS_TOOLBAR_STANDARD "Standard" 423 | IDS_TOOLBAR_CUSTOMIZE "Customize..." 424 | END 425 | 426 | STRINGTABLE 427 | BEGIN 428 | IDS_PROPERTIES_WND "Properties" 429 | END 430 | 431 | STRINGTABLE 432 | BEGIN 433 | IDS_EDIT_MENU "Edit" 434 | END 435 | 436 | STRINGTABLE 437 | BEGIN 438 | ID_VIEW_ANIMATION "Animate\nAnimate" 439 | END 440 | 441 | #endif // English (United States) resources 442 | ///////////////////////////////////////////////////////////////////////////// 443 | 444 | 445 | 446 | #ifndef APSTUDIO_INVOKED 447 | ///////////////////////////////////////////////////////////////////////////// 448 | // 449 | // Generated from the TEXTINCLUDE 3 resource. 450 | // 451 | #define _AFX_NO_OLE_RESOURCES 452 | #define _AFX_NO_TRACKER_RESOURCES 453 | #define _AFX_NO_PROPERTY_RESOURCES 454 | 455 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 456 | LANGUAGE 9, 1 457 | #include "res\NMRI.rc2" // non-Microsoft Visual C++ edited resources 458 | #include "afxres.rc" // Standard components 459 | #include "afxprint.rc" // printing/print preview resources 460 | #if !defined(_AFXDLL) 461 | #include "afxribbon.rc" // MFC ribbon and control bar resources 462 | #endif 463 | #endif 464 | 465 | ///////////////////////////////////////////////////////////////////////////// 466 | #endif // not APSTUDIO_INVOKED 467 | 468 | -------------------------------------------------------------------------------- /NMRI/VTKView.cpp: -------------------------------------------------------------------------------- 1 | 2 | // DFTView.cpp : implementation of the CDFTView class 3 | // 4 | 5 | #include "stdafx.h" 6 | 7 | 8 | // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail 9 | // and search filter handlers and allows sharing of document code with that project. 10 | #ifndef SHARED_HANDLERS 11 | #include "NMRI.h" 12 | #endif 13 | 14 | //#include 15 | 16 | #include "NMRIDoc.h" 17 | #include "VTKView.h" 18 | 19 | #include 20 | 21 | VTK_MODULE_INIT(vtkRenderingOpenGL2); 22 | VTK_MODULE_INIT(vtkInteractionStyle); 23 | VTK_MODULE_INIT(vtkRenderingFreeType); 24 | VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2); 25 | 26 | 27 | #include 28 | 29 | 30 | 31 | ErrorObserver *ErrorObserver::New() 32 | { 33 | return ::new ErrorObserver; 34 | } 35 | 36 | void ErrorObserver::Execute(vtkObject *vtkNotUsed(caller), unsigned long event, void *calldata) 37 | { 38 | switch (event) 39 | { 40 | case vtkCommand::ErrorEvent: 41 | ErrorMessage = static_cast(calldata); 42 | Error = true; 43 | if (theView) theView->RecoverFromWarning(); 44 | break; 45 | case vtkCommand::WarningEvent: 46 | WarningMessage = static_cast(calldata); 47 | Warning = true; 48 | if (theView) theView->RecoverFromWarning(); 49 | break; 50 | } 51 | } 52 | 53 | 54 | #ifdef _DEBUG 55 | #define new DEBUG_NEW 56 | #endif 57 | 58 | 59 | 60 | 61 | // CDFTView 62 | 63 | IMPLEMENT_DYNCREATE(CVTKView, CView) 64 | 65 | BEGIN_MESSAGE_MAP(CVTKView, CView) 66 | // Standard printing commands 67 | ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) 68 | ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) 69 | ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CVTKView::OnFilePrintPreview) 70 | ON_WM_SIZE() 71 | ON_WM_ERASEBKGND() 72 | ON_WM_DESTROY() 73 | ON_WM_TIMER() 74 | END_MESSAGE_MAP() 75 | 76 | // CDFTView construction/destruction 77 | 78 | CVTKView::CVTKView() 79 | { 80 | errorObserver = ErrorObserver::New(); 81 | errorObserver->SetView(this); 82 | 83 | // avoid displaying VTK warning window and log the messages instead 84 | vtkSmartPointer outputWin = vtkSmartPointer::New(); 85 | outputWin->SetFileName("vtkErrors.log"); 86 | vtkOutputWindow::SetInstance(outputWin); 87 | 88 | outputWin->AddObserver(vtkCommand::ErrorEvent, errorObserver); 89 | outputWin->AddObserver(vtkCommand::WarningEvent, errorObserver); 90 | 91 | volumeMapper = vtkGPUVolumeRayCastMapper::New(); 92 | 93 | volume = vtkVolume::New(); 94 | } 95 | 96 | CVTKView::~CVTKView() 97 | { 98 | // Delete the renderer, window and interactor objects. 99 | if (ren) 100 | { 101 | ren->Delete(); 102 | iren->Delete(); 103 | renWin->Delete(); 104 | } 105 | 106 | // Delete the objects used to form the visualization. 107 | 108 | volumeMapper->Delete(); 109 | volume->Delete(); 110 | 111 | errorObserver->Delete(); 112 | 113 | if (dataImage) 114 | dataImage->Delete(); 115 | } 116 | 117 | // CDFTView drawing 118 | 119 | void CVTKView::OnDraw(CDC* pDC) 120 | { 121 | const CNMRIDoc* pDoc = GetDocument(); 122 | ASSERT_VALID(pDoc); 123 | if (!pDoc) 124 | return; 125 | if (!iren || !renWin)return; 126 | 127 | if (!iren->GetInitialized()) 128 | { 129 | iren->SetRenderWindow(renWin); 130 | 131 | CRect rect; 132 | 133 | GetClientRect(&rect); 134 | iren->Initialize(); 135 | renWin->SetSize(rect.right - rect.left, rect.bottom - rect.top); 136 | ren->ResetCamera(); 137 | } 138 | 139 | // Invoke the pipeline 140 | Pipeline(); 141 | 142 | if (pDC->IsPrinting()) 143 | { 144 | BeginWaitCursor(); 145 | 146 | // Obtain the size of the printer page in pixels. 147 | 148 | const int cxPage = pDC->GetDeviceCaps(HORZRES); 149 | const int cyPage = pDC->GetDeviceCaps(VERTRES); 150 | 151 | // Get the size of the window in pixels. 152 | 153 | const int *size = renWin->GetSize(); 154 | int cxWindow = size[0]; 155 | int cyWindow = size[1]; 156 | const float fx = static_cast(cxPage) / static_cast(cxWindow); 157 | const float fy = static_cast(cyPage) / static_cast(cyWindow); 158 | const float scale = min(fx, fy); 159 | const int x = static_cast(scale * static_cast(cxWindow)); 160 | const int y = static_cast(scale * static_cast(cyWindow)); 161 | 162 | // this is from VTK-8.0.1\GUISupport\MFC\vtkMFCWindow.cpp 163 | // with some corrections, they don't do DeleteObject and DeleteDC and here for some reason delete[] pixels crashes 164 | 165 | renWin->SetUseOffScreenBuffers(true); 166 | renWin->Render(); 167 | 168 | const unsigned char *pixels = renWin->GetPixelData(0, 0, cxWindow - 1, cyWindow - 1, 0, 0); 169 | 170 | int dataWidth = ((cxWindow * 3 + 3) / 4) * 4; 171 | 172 | BITMAPINFO MemoryDataHeader; 173 | MemoryDataHeader.bmiHeader.biSize = 40; 174 | MemoryDataHeader.bmiHeader.biWidth = cxWindow; 175 | MemoryDataHeader.bmiHeader.biHeight = cyWindow; 176 | MemoryDataHeader.bmiHeader.biPlanes = 1; 177 | MemoryDataHeader.bmiHeader.biBitCount = 24; 178 | MemoryDataHeader.bmiHeader.biCompression = BI_RGB; 179 | MemoryDataHeader.bmiHeader.biClrUsed = 0; 180 | MemoryDataHeader.bmiHeader.biClrImportant = 0; 181 | MemoryDataHeader.bmiHeader.biSizeImage = dataWidth*cyWindow; 182 | MemoryDataHeader.bmiHeader.biXPelsPerMeter = 10000; 183 | MemoryDataHeader.bmiHeader.biYPelsPerMeter = 10000; 184 | 185 | unsigned char *MemoryData = nullptr; 186 | HDC MemoryHdc = static_cast(CreateCompatibleDC(pDC->GetSafeHdc())); 187 | HBITMAP dib = CreateDIBSection(MemoryHdc, &MemoryDataHeader, DIB_RGB_COLORS, (void **)(&MemoryData), nullptr, 0); 188 | if (dib) 189 | { 190 | // copy the pixels over 191 | if (MemoryData) 192 | { 193 | for (int i = 0; i < cyWindow; ++i) 194 | for (int j = 0; j < cxWindow; ++j) 195 | { 196 | MemoryData[i * dataWidth + j * 3] = pixels[i * cxWindow * 3 + j * 3 + 2]; 197 | MemoryData[i * dataWidth + j * 3 + 1] = pixels[i * cxWindow * 3 + j * 3 + 1]; 198 | MemoryData[i * dataWidth + j * 3 + 2] = pixels[i * cxWindow * 3 + j * 3]; 199 | } 200 | } 201 | 202 | SelectObject(MemoryHdc, dib); 203 | StretchBlt(pDC->GetSafeHdc(), 0, 0, x, y, MemoryHdc, 0, 0, cxWindow, cyWindow, SRCCOPY); 204 | 205 | renWin->SetUseOffScreenBuffers(false); 206 | 207 | DeleteObject(dib); 208 | } 209 | DeleteDC(MemoryHdc); 210 | 211 | // in debug this crashes 212 | #ifndef _DEBUG 213 | delete[] pixels; 214 | #endif 215 | 216 | EndWaitCursor(); 217 | } 218 | else 219 | { 220 | renWin->Render(); 221 | } 222 | } 223 | 224 | 225 | // CDFTView printing 226 | 227 | 228 | void CVTKView::OnFilePrintPreview() 229 | { 230 | #ifndef SHARED_HANDLERS 231 | AFXPrintPreview(this); 232 | #endif 233 | } 234 | 235 | BOOL CVTKView::OnPreparePrinting(CPrintInfo* pInfo) 236 | { 237 | // default preparation 238 | return DoPreparePrinting(pInfo); 239 | } 240 | 241 | void CVTKView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 242 | { 243 | // TODO: add extra initialization before printing 244 | } 245 | 246 | void CVTKView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 247 | { 248 | // TODO: add cleanup after printing 249 | } 250 | 251 | // CDFTView diagnostics 252 | 253 | #ifdef _DEBUG 254 | void CVTKView::AssertValid() const 255 | { 256 | CView::AssertValid(); 257 | } 258 | 259 | void CVTKView::Dump(CDumpContext& dc) const 260 | { 261 | CView::Dump(dc); 262 | } 263 | 264 | CNMRIDoc* CVTKView::GetDocument() const // non-debug version is inline 265 | { 266 | ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNMRIDoc))); 267 | return dynamic_cast(m_pDocument); 268 | } 269 | #endif //_DEBUG 270 | 271 | 272 | // CDFTView message handlers 273 | 274 | 275 | void CVTKView::OnSize(UINT nType, int cx, int cy) 276 | { 277 | CView::OnSize(nType, cx, cy); 278 | 279 | CRect rect; 280 | 281 | GetClientRect(&rect); 282 | 283 | if (renWin) 284 | { 285 | renWin->SetSize(rect.right - rect.left, rect.bottom - rect.top); 286 | if (iren) iren->UpdateSize(rect.Width(), rect.Height()); 287 | } 288 | } 289 | 290 | 291 | BOOL CVTKView::OnEraseBkgnd(CDC* /*pDC*/) 292 | { 293 | return TRUE; 294 | } 295 | 296 | 297 | void CVTKView::OnInitialUpdate() 298 | { 299 | CView::OnInitialUpdate(); 300 | 301 | // Create the renderer, window and interactor objects. 302 | 303 | ren = vtkRenderer::New(); 304 | renWin = vtkWin32OpenGLRenderWindow::New(); 305 | iren = vtkWin32RenderWindowInteractor::New(); 306 | 307 | renWin->AddRenderer(ren); 308 | 309 | 310 | // setup the parent window 311 | 312 | renWin->SetParentId(GetSafeHwnd()); 313 | 314 | iren->SetRenderWindow(renWin); 315 | 316 | // now the other ones 317 | 318 | ren->SetBackground(1, 1, 1); 319 | 320 | // text 321 | 322 | textActor = vtkSmartPointer::New(); 323 | textActor->SetInput("Loading..."); 324 | textActor->SetPosition(10, 10); 325 | textActor->GetTextProperty()->SetFontSize(36); 326 | textActor->GetTextProperty()->SetColor(0., 1.0, 0.); 327 | ren->AddActor2D(textActor); 328 | 329 | volumeMapper->SetBlendModeToComposite(); 330 | volumeMapper->SetAutoAdjustSampleDistances(0); 331 | 332 | vtkVolumeProperty* volumeProperty = volume->GetProperty(); 333 | 334 | /* 335 | volumeProperty->ShadeOn(); 336 | volumeProperty->SetDiffuse(0.7); 337 | volumeProperty->SetAmbient(0.2); 338 | volumeProperty->SetSpecular(0.5); 339 | volumeProperty->SetSpecularPower(70); 340 | */ 341 | 342 | volumeProperty->ShadeOff(); 343 | volumeProperty->SetInterpolationTypeToLinear(); 344 | 345 | UpdateTransferFunctions(); 346 | 347 | volume->SetMapper(volumeMapper); 348 | ren->AddViewProp(volume); 349 | 350 | // initialize the interactor 351 | 352 | CRect rect; 353 | 354 | GetClientRect(&rect); 355 | iren->Initialize(); 356 | renWin->SetSize(rect.right - rect.left, rect.bottom - rect.top); 357 | 358 | GrabResultsFromDoc(); 359 | 360 | // light 361 | /* 362 | vtkSmartPointer light = vtkSmartPointer::New(); 363 | light->SetColor(1, 1, 1); 364 | light->SetIntensity(1); 365 | light->SetFocalPoint(Width / 2, Height / 2, NrFrames * 4 / 2); 366 | light->SetPosition(25, 25, 100); 367 | ren->AddLight(light); 368 | */ 369 | 370 | // camera 371 | ren->GetActiveCamera()->SetFocalPoint(Width / 2, Height / 2, NrFrames * 4 / 2); 372 | ren->GetActiveCamera()->SetPosition(Width, Height * 2, NrFrames * 4 * 3); 373 | 374 | //ren->GetActiveCamera()->ComputeViewPlaneNormal(); 375 | } 376 | 377 | void CVTKView::UpdateTransferFunctions() 378 | { 379 | const CNMRIDoc* pDoc = GetDocument(); 380 | 381 | vtkVolumeProperty* volumeProperty = volume->GetProperty(); 382 | 383 | if (!pDoc || pDoc->colorFunction) 384 | { 385 | vtkSmartPointer colorTransferFunction = vtkSmartPointer::New(); 386 | colorTransferFunction->SetColorSpaceToRGB(); 387 | colorTransferFunction->AddRGBPoint(0, 0., 0., 1.); 388 | colorTransferFunction->AddRGBPoint(1., 1., 0, 0); 389 | volumeProperty->SetColor(colorTransferFunction); 390 | } 391 | else 392 | { 393 | vtkSmartPointer colorTransferFunction; 394 | volumeProperty->SetColor(colorTransferFunction); 395 | } 396 | 397 | 398 | if (!pDoc || pDoc->opacityFunction) 399 | { 400 | double distance = 1; 401 | if (!pDoc || pDoc->gradientFunction) distance = 4; 402 | else distance = 64. * pDoc->opacityVal / 100.; 403 | 404 | volumeProperty->SetScalarOpacityUnitDistance(distance); 405 | 406 | vtkSmartPointer opacityTransferFunction = vtkSmartPointer::New(); 407 | opacityTransferFunction->AddPoint(0.0, 0); 408 | opacityTransferFunction->AddPoint(1, 1); 409 | volumeProperty->SetScalarOpacity(opacityTransferFunction); 410 | } 411 | else 412 | { 413 | volumeProperty->SetScalarOpacityUnitDistance(1); 414 | vtkSmartPointer opacityTransferFunction; 415 | volumeProperty->SetScalarOpacity(opacityTransferFunction); 416 | } 417 | 418 | if (!pDoc || pDoc->gradientFunction) 419 | { 420 | vtkSmartPointer gradientTransferFunction = vtkSmartPointer::New(); 421 | gradientTransferFunction->AddPoint(0.0, 0); 422 | if (pDoc) gradientTransferFunction->AddPoint(pDoc->gradientVal / 100., 1); 423 | gradientTransferFunction->AddPoint(1, 1); 424 | volumeProperty->SetGradientOpacity(gradientTransferFunction); 425 | } 426 | else 427 | { 428 | vtkSmartPointer gradientTransferFunction; 429 | volumeProperty->SetGradientOpacity(gradientTransferFunction); 430 | } 431 | } 432 | 433 | 434 | bool CVTKView::IsHandledMessage(UINT message) 435 | { 436 | return message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || message == WM_MBUTTONDOWN || message == WM_MBUTTONUP || 437 | message == WM_RBUTTONDOWN || message == WM_RBUTTONUP || message == WM_MOUSEMOVE || message == WM_CHAR || message == WM_TIMER; 438 | } 439 | 440 | LRESULT CVTKView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 441 | { 442 | if (IsHandledMessage(message)) 443 | { 444 | if (iren && iren->GetInitialized() && GetSafeHwnd()) 445 | { 446 | LRESULT res = vtkHandleMessage(GetSafeHwnd(), message, wParam, lParam); 447 | //LRESULT res = vtkHandleMessage2(GetSafeHwnd(), message, wParam, lParam, iren); 448 | //if (message != WM_TIMER || wParam != timer) 449 | return res; 450 | } 451 | } 452 | 453 | return CView::WindowProc(message, wParam, lParam); 454 | } 455 | 456 | void CVTKView::RecoverFromWarning() 457 | { 458 | CNMRIDoc* pDoc = GetDocument(); 459 | if (!pDoc) return; 460 | 461 | // do something to recover, if needed 462 | 463 | pDoc->UpdateAllViews(nullptr); 464 | } 465 | 466 | void CVTKView::Pipeline() 467 | { 468 | if (!dataImage) return; 469 | 470 | const CNMRIDoc* pDoc = GetDocument(); 471 | if (!pDoc) return; 472 | 473 | ren->RemoveAllViewProps(); 474 | 475 | vtkVolumeProperty* volumeProperty = volume->GetProperty(); 476 | 477 | vtkPiecewiseFunction* opacityTransferFunction = volumeProperty->GetScalarOpacity(); 478 | opacityTransferFunction->RemoveAllPoints(); 479 | 480 | opacityTransferFunction->AddPoint(0, 0); 481 | 482 | opacityTransferFunction->AddPoint(1, 1); 483 | 484 | volumeMapper->SetInputData(dataImage); 485 | 486 | ren->AddViewProp(volume); 487 | 488 | vtkSmartPointer cube = vtkSmartPointer::New(); 489 | 490 | cube->SetBounds(0, Width - 1, 0, Height - 1, 0, (NrFrames - 1) * 4); 491 | 492 | vtkSmartPointer outlineActor = vtkSmartPointer::New(); 493 | vtkSmartPointer outlineMapper = vtkSmartPointer::New(); 494 | 495 | outlineMapper->SetInputConnection(cube->GetOutputPort()); 496 | 497 | outlineActor->SetMapper(outlineMapper); 498 | outlineActor->GetProperty()->SetRepresentationToWireframe(); 499 | outlineActor->GetProperty()->SetColor(1, 1, 1); 500 | 501 | ren->AddActor(outlineActor); 502 | 503 | textActor = vtkSmartPointer::New(); 504 | CString str("Head2D.dat"); 505 | USES_CONVERSION; 506 | textActor->SetInput(W2A(str)); 507 | textActor->SetPosition(10, 10); 508 | textActor->GetTextProperty()->SetFontSize(36); 509 | textActor->GetTextProperty()->SetColor(0., 1.0, 0.); 510 | ren->AddActor2D(textActor); 511 | } 512 | 513 | 514 | void CVTKView::OnDestroy() 515 | { 516 | CView::OnDestroy(); 517 | } 518 | 519 | 520 | 521 | 522 | void CVTKView::GrabResultsFromDoc() 523 | { 524 | CNMRIDoc* pDoc = GetDocument(); 525 | if (!pDoc) return; 526 | 527 | if (pDoc->theFile.Width <= 0 || pDoc->theFile.Height <= 0 || pDoc->theFile.NrFrames <= 0) return; 528 | 529 | if (dataImage) dataImage->Delete(); 530 | 531 | dataImage = vtkImageData::New(); 532 | 533 | Width = static_cast(pDoc->theFile.Width); 534 | Height = static_cast(pDoc->theFile.Height); 535 | NrFrames = static_cast(pDoc->theFile.NrFrames); 536 | 537 | // they are duplicated in the file 538 | //NrFrames /= 2; 539 | 540 | dataImage->SetDimensions(Width, Height, NrFrames); 541 | 542 | dataImage->SetSpacing(1, 1, 4); 543 | dataImage->AllocateScalars(VTK_FLOAT, 1); 544 | 545 | double m = 0; 546 | for (unsigned int k = 0; k < NrFrames; ++k) 547 | { 548 | pDoc->theFile.FFT(k); 549 | const std::complex* image = pDoc->theFile.GetRealFrame(); 550 | 551 | for (unsigned int i = 0; i < Width; ++i) 552 | for (unsigned int j = 0; j < Height; ++j) 553 | { 554 | const double val = std::abs(image[Width * i + j]); 555 | m = max(m, val); 556 | } 557 | } 558 | 559 | for (unsigned int k = 0; k < NrFrames; ++k) 560 | { 561 | pDoc->theFile.FFT(k); 562 | const std::complex* image = pDoc->theFile.GetRealFrame(); 563 | 564 | for (unsigned int i = 0; i < Width; ++i) 565 | for (unsigned int j = 0; j < Height; ++j) 566 | { 567 | const double val = std::abs(image[Width * i + j]); 568 | dataImage->SetScalarComponentFromDouble(i, Width - j - 1, k, 0, val / m); 569 | } 570 | } 571 | 572 | pDoc->theFile.FFT(0); 573 | } 574 | -------------------------------------------------------------------------------- /NMRI/NMRI.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {0419845C-98D5-4E5F-8880-19315E366367} 24 | NMRI 25 | 10.0 26 | MFCProj 27 | 28 | 29 | 30 | Application 31 | true 32 | v145 33 | Unicode 34 | Dynamic 35 | 36 | 37 | Application 38 | false 39 | v145 40 | true 41 | Unicode 42 | Dynamic 43 | 44 | 45 | Application 46 | true 47 | v145 48 | Unicode 49 | Dynamic 50 | 51 | 52 | Application 53 | false 54 | v145 55 | true 56 | Unicode 57 | Dynamic 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | true 79 | C:\LIBs\VTK-9.2.5\bin\include\vtk-9.2;C:\LIBs\fftw-3.3.5-dll32;$(VC_IncludePath);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath)include;$(FrameworkSDKDir)include;C:\Program Files %28x86%29\Windows Kits\10\Include\10.0.10240.0\ucrt;$(IncludePath) 80 | C:\LIBs\VTK-9.2.5\bin\lib;C:\LIBs\fftw-3.3.5-dll32;$(VCInstallDir)PlatformSDK\lib;$(VCInstallDir)PlatformSDK\common\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)\Lib\x86;C:\Program Files (x86)\Business Objects\Common\3.5;C:\LIBs\JetVC\Intel;C:\LIBs\boost_1_44_0\stage\lib;C:\Program Files (x86)\Java\jdk1.6.0_20\lib;$(LibraryPath) 81 | C:\LIBs\VTK-9.2.5\bin\bin;C:\LIBs\fftw-3.3.5-dll32;$(VCInstallDir)PlatformSDK\bin;$(VCInstallDir)PlatformSDK\common\bin;$(ExecutablePath) 82 | NativeRecommendedRules.ruleset 83 | false 84 | true 85 | 86 | 87 | true 88 | C:\LIBs\VTK-9.2.5\bin\include\vtk-9.2;C:\LIBs\fftw-3.3.5-dll64;$(VCInstallDir)PlatformSDK\include;$(IncludePath) 89 | C:\LIBs\VTK-9.2.5\bin\bin;C:\LIBs\VTK-9.2.5\bin\lib;C:\LIBs\fftw-3.3.5-dll64;$(VCInstallDir)PlatformSDK\lib\amd64;$(VSInstallDir)SDK\v2.0\lib\amd64;$(LibraryPath) 90 | C:\LIBs\VTK-9.2.5\bin\bin;C:\LIBs\fftw-3.3.5-dll64;$(VCInstallDir)PlatformSDK\bin;$(ExecutablePath) 91 | NativeRecommendedRules.ruleset 92 | false 93 | true 94 | 95 | 96 | false 97 | C:\LIBs\VTK-9.2.5\bin\include\vtk-9.2;C:\LIBs\fftw-3.3.5-dll32;$(VC_IncludePath);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath)include;$(FrameworkSDKDir)include;C:\Program Files %28x86%29\Windows Kits\10\Include\10.0.10240.0\ucrt;$(IncludePath) 98 | C:\LIBs\VTK-9.2.5\bin\lib;C:\LIBs\fftw-3.3.5-dll32;$(VCInstallDir)PlatformSDK\lib;$(VCInstallDir)PlatformSDK\common\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2007)\Lib\x86;C:\Program Files (x86)\Business Objects\Common\3.5;C:\LIBs\JetVC\Intel;C:\LIBs\boost_1_44_0\stage\lib;C:\Program Files (x86)\Java\jdk1.6.0_20\lib;$(LibraryPath) 99 | C:\LIBs\VTK-9.2.5\bin\bin;C:\LIBs\fftw-3.3.5-dll32;$(VCInstallDir)PlatformSDK\bin;$(VCInstallDir)PlatformSDK\common\bin;$(ExecutablePath) 100 | 101 | 102 | false 103 | C:\LIBs\VTK-9.2.5\bin\include\vtk-9.2;C:\LIBs\fftw-3.3.5-dll64;$(VCInstallDir)PlatformSDK\include;$(IncludePath) 104 | C:\LIBs\VTK-9.2.5\bin\bin;C:\LIBs\VTK-9.2.5\bin\lib;C:\LIBs\fftw-3.3.5-dll64;$(VCInstallDir)PlatformSDK\lib\amd64;$(VSInstallDir)SDK\v2.0\lib\amd64;$(LibraryPath) 105 | C:\LIBs\VTK-9.2.5\bin\bin;C:\LIBs\fftw-3.3.5-dll64;$(VCInstallDir)PlatformSDK\bin;$(ExecutablePath) 106 | 107 | 108 | 109 | Use 110 | Level4 111 | Disabled 112 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) 113 | true 114 | false 115 | stdcpp17 116 | 117 | 118 | Windows 119 | libfftw3-3.lib;vtkCommonCore-9.2.lib;vtkRenderingCore-9.2.lib;vtkViewsCore-9.2.lib;vtkFiltersCore-9.2.lib;vtkCommonDataModel-9.2.lib;vtkFiltersGeneral-9.2.lib;vtkFiltersGeometry-9.2.lib;vtkRenderingOpenGL2-9.2.lib;vtkCommonExecutionModel-9.2.lib;vtkRenderingAnnotation-9.2.lib;vtkRenderingContextOpenGL2-9.2.lib;vtkRenderingVolumeOpenGL2-9.2.lib;vtkInteractionStyle-9.2.lib;vtkRenderingFreeType-9.2.lib;vtkRenderingVolume-9.2.lib;vtkFiltersModeling-9.2.lib;vtkFiltersSources-9.2.lib;vtkChartsCore-9.2.lib;vtkRenderingContext2D-9.2.lib;vtkViewsContext2D-9.2.lib;vtkSys-9.2.lib;vtkRenderingUI-9.2.lib 120 | 121 | 122 | false 123 | true 124 | _DEBUG;%(PreprocessorDefinitions) 125 | 126 | 127 | 0x0409 128 | _DEBUG;%(PreprocessorDefinitions) 129 | $(IntDir);%(AdditionalIncludeDirectories) 130 | 131 | 132 | 133 | 134 | Use 135 | Level4 136 | Disabled 137 | _WINDOWS;_DEBUG;%(PreprocessorDefinitions) 138 | true 139 | false 140 | stdcpp17 141 | 142 | 143 | Windows 144 | libfftw3-3.lib;vtkCommonCore-9.2.lib;vtkRenderingCore-9.2.lib;vtkViewsCore-9.2.lib;vtkFiltersCore-9.2.lib;vtkCommonDataModel-9.2.lib;vtkFiltersGeneral-9.2.lib;vtkFiltersGeometry-9.2.lib;vtkRenderingOpenGL2-9.2.lib;vtkCommonExecutionModel-9.2.lib;vtkRenderingAnnotation-9.2.lib;vtkRenderingContextOpenGL2-9.2.lib;vtkRenderingVolumeOpenGL2-9.2.lib;vtkInteractionStyle-9.2.lib;vtkRenderingFreeType-9.2.lib;vtkRenderingVolume-9.2.lib;vtkFiltersModeling-9.2.lib;vtkFiltersSources-9.2.lib;vtkChartsCore-9.2.lib;vtkRenderingContext2D-9.2.lib;vtkViewsContext2D-9.2.lib;vtkSys-9.2.lib;vtkRenderingUI-9.2.lib 145 | 146 | 147 | false 148 | true 149 | _DEBUG;%(PreprocessorDefinitions) 150 | 151 | 152 | 0x0409 153 | _DEBUG;%(PreprocessorDefinitions) 154 | $(IntDir);%(AdditionalIncludeDirectories) 155 | 156 | 157 | 158 | 159 | Level3 160 | Use 161 | MaxSpeed 162 | true 163 | true 164 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) 165 | true 166 | stdcpp17 167 | 168 | 169 | Windows 170 | true 171 | true 172 | libfftw3-3.lib;vtkCommonCore-9.2.lib;vtkRenderingCore-9.2.lib;vtkViewsCore-9.2.lib;vtkFiltersCore-9.2.lib;vtkCommonDataModel-9.2.lib;vtkFiltersGeneral-9.2.lib;vtkFiltersGeometry-9.2.lib;vtkRenderingOpenGL2-9.2.lib;vtkCommonExecutionModel-9.2.lib;vtkRenderingAnnotation-9.2.lib;vtkRenderingContextOpenGL2-9.2.lib;vtkRenderingVolumeOpenGL2-9.2.lib;vtkInteractionStyle-9.2.lib;vtkRenderingFreeType-9.2.lib;vtkRenderingVolume-9.2.lib;vtkFiltersModeling-9.2.lib;vtkFiltersSources-9.2.lib;vtkChartsCore-9.2.lib;vtkRenderingContext2D-9.2.lib;vtkViewsContext2D-9.2.lib;vtkSys-9.2.lib;vtkRenderingUI-9.2.lib 173 | 174 | 175 | false 176 | true 177 | NDEBUG;%(PreprocessorDefinitions) 178 | 179 | 180 | 0x0409 181 | NDEBUG;%(PreprocessorDefinitions) 182 | $(IntDir);%(AdditionalIncludeDirectories) 183 | 184 | 185 | 186 | 187 | Level3 188 | Use 189 | MaxSpeed 190 | true 191 | true 192 | _WINDOWS;NDEBUG;%(PreprocessorDefinitions) 193 | true 194 | stdcpp17 195 | 196 | 197 | Windows 198 | true 199 | true 200 | libfftw3-3.lib;vtkCommonCore-9.2.lib;vtkRenderingCore-9.2.lib;vtkViewsCore-9.2.lib;vtkFiltersCore-9.2.lib;vtkCommonDataModel-9.2.lib;vtkFiltersGeneral-9.2.lib;vtkFiltersGeometry-9.2.lib;vtkRenderingOpenGL2-9.2.lib;vtkCommonExecutionModel-9.2.lib;vtkRenderingAnnotation-9.2.lib;vtkRenderingContextOpenGL2-9.2.lib;vtkRenderingVolumeOpenGL2-9.2.lib;vtkInteractionStyle-9.2.lib;vtkRenderingFreeType-9.2.lib;vtkRenderingVolume-9.2.lib;vtkFiltersModeling-9.2.lib;vtkFiltersSources-9.2.lib;vtkChartsCore-9.2.lib;vtkRenderingContext2D-9.2.lib;vtkViewsContext2D-9.2.lib;vtkSys-9.2.lib;vtkRenderingUI-9.2.lib 201 | 202 | 203 | false 204 | true 205 | NDEBUG;%(PreprocessorDefinitions) 206 | 207 | 208 | 0x0409 209 | NDEBUG;%(PreprocessorDefinitions) 210 | $(IntDir);%(AdditionalIncludeDirectories) 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | Create 241 | Create 242 | Create 243 | Create 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------