⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mvolumerender.cpp

📁 virtual reality project. This algorithm for building large image to Volume rendering. Using directx
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//-----------------------------------------------------------------------------
// File: MVolumeRender.cpp
//
// Desc: DirectX MFC dialog application created by the DirectX AppWizard
//-----------------------------------------------------------------------------
#define STRICT
#include "stdafx.h"
#include "MVolumeRender.h"




//-----------------------------------------------------------------------------
// Application globals
//-----------------------------------------------------------------------------
TCHAR*          g_strAppTitle       = _T( "MVolumeRender" );
CApp            g_App;
HINSTANCE       g_hInst = NULL;
CAppForm*       g_AppFormView = NULL;




//-----------------------------------------------------------------------------
// The MFC macros are all listed here
//-----------------------------------------------------------------------------
IMPLEMENT_DYNCREATE( CAppDoc,      CDocument )
IMPLEMENT_DYNCREATE( CAppFrameWnd, CFrameWnd )
IMPLEMENT_DYNCREATE( CAppForm,     CFormView )




BEGIN_MESSAGE_MAP( CApp, CWinApp )
    //{{AFX_MSG_MAP(CApp)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()




BEGIN_MESSAGE_MAP( CAppForm, CFormView )
    //{{AFX_MSG_MAP(CAppForm)
    ON_COMMAND(    IDC_VIEWFULLSCREEN, OnToggleFullScreen )
    ON_BN_CLICKED(IDC_CHANGEDEVICE, OnChangeDevice)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_HSCROLL()
	ON_WM_RBUTTONDOWN()
	ON_BN_CLICKED(IDC_ALLPASS, OnAllpass)
	ON_BN_CLICKED(IDC_RENDERMESHCHECK, OnRendermeshcheck)
	ON_BN_CLICKED(IDC_DRAW_MPR_CURVE, OnDrawMprCurve)
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_MPRCURVEOK, OnMprcurveok)
	ON_BN_CLICKED(IDC_ONLYPASS1, OnAllpass)
	ON_BN_CLICKED(IDC_SHOWDEPTH, OnAllpass)
	ON_BN_CLICKED(IDC_CONTROLMESHCHECK, OnRendermeshcheck)
	ON_BN_CLICKED(IDC_MPRCURVECLEAR, OnMprcurveclear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()




BEGIN_MESSAGE_MAP(CAppDoc, CDocument)
    //{{AFX_MSG_MAP(CAppDoc)
            // NOTE - the ClassWizard will add and remove mapping macros here.
            //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()




BEGIN_MESSAGE_MAP(CAppFrameWnd, CFrameWnd)
    //{{AFX_MSG_MAP(CAppFrameWnd)
    ON_COMMAND(IDM_CHANGEDEVICE, OnChangeDevice)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()




//-----------------------------------------------------------------------------
// Name: CAppForm()
// Desc: Constructor for the dialog resource form.  Paired with ~CAppForm()
//       Member variables should be initialized to a known state here.  
//       The application window has not yet been created and no Direct3D device 
//       has been created, so any initialization that depends on a window or 
//       Direct3D should be deferred to a later stage. 
//-----------------------------------------------------------------------------
CAppForm::CAppForm()
         :CFormView( IDD_FORMVIEW )
{
    //{{AFX_DATA_INIT(CAppForm)
	m_valOtfEdit0 = 0;
	m_valOtfEdit1 = 0;
	m_valOtfAlpha = 0;
	m_renderingPass = -1;
	m_bRenderMesh = FALSE;
	m_bControlMesh = FALSE;
	m_bDrawCurve = FALSE;
	//}}AFX_DATA_INIT

    g_AppFormView          = this;
    m_hwndRenderWindow     = NULL;
    m_hwndRenderFullScreen = NULL;
    m_hWndTopLevelParent   = NULL;

    // Override some CD3DApplication defaults:
    m_dwCreationWidth           = 400;
    m_dwCreationHeight          = 375;
    m_strWindowTitle            = TEXT( "MVolumeRender" );
    m_d3dEnumeration.AppUsesDepthBuffer   = TRUE;
	m_bStartFullscreen			= false;
	m_bShowCursorWhenFullscreen	= false;

    // Create a D3D font using d3dfont.cpp
    m_pFont                     = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
    m_bLoadingApp               = TRUE;
	// D3D pointers 檬扁拳
    m_pVB                       = NULL;
	m_pObjectOrderProxy			= NULL;    
	m_pFinalQuadVB				= NULL;
	m_pMPRGeometryVB			= NULL;
	m_pMPRQuadVB				= NULL;
	m_pMPRRenderTarget			= NULL;
	m_pMPRRenderTargetVB		= NULL;

	m_pVolumeTexture            = NULL;
	m_pGradientTexture			= NULL;

	m_pObjOrderProxyVertexDecl  = NULL;
	m_pImagOrderProxyVertexDecl = NULL;

	m_pPreIntegratedTexture		= NULL;
	m_pIntermediateTexture		= NULL;	
	m_pOldRenderTarget			= NULL;		
	m_pVolumeTexMM				= NULL;
	m_pEffect					= NULL;

    ZeroMemory( &m_UserInput, sizeof(m_UserInput) );
	// 檬扁 雀傈阿 ( 沥搁 : X(3.141592f / 2.0f), Y(3.141592f) )
    m_texCoordRotX   = -3.141592f / 2.0f;
    m_texCoordRotY   = 0;//3.141592f; 
	// MPR_TEST
	// 檬扁蔼 汗荤秦狄.
	m_initTexCoordRotX   = m_texCoordRotX;
	m_initTexCoordRotY	 = m_texCoordRotY;

	m_meshCoordRotX				  = 0;
	m_meshCoordRotY				  = 0;
	m_meshScaleFactor			  = 1.0f;
	
	ZeroMemory( m_volumeData, sizeof(m_volumeData));   // volumeData mem clear
	ZeroMemory( tmp8bitVolume, sizeof(tmp8bitVolume));
	ZeroMemory( m_gradient, sizeof(m_gradient));   // gradientData mem clear
	ZeroMemory( m_linearOtfArray, sizeof(m_linearOtfArray)); // otf array clear
	ZeroMemory( minDenDiv8, sizeof(minDenDiv8));
	ZeroMemory( maxDenDiv8, sizeof(maxDenDiv8)); 

	if(!OpenVolumeData()) {                        // open volume data
		AfxMessageBox("'bighead.den' file not found. !!");
		exit(0);	
	} 

	if(!OpenGradientData()) {                        // open gradient data
		MakeGradientData();	                       // 父距 gradient file 捞 绝栏搁 货肺 积己.
	}
	
	// initiate light & view vector
	light = D3DXVECTOR3( -0.5f, -0.3f, -1.0f);//D3DXVECTOR3( 0.0, -0.0, -1.0); // light vector //( 1.0, -1.5, -1.0),( 0.3, -0.5, -1.0)
	D3DXVec3Normalize( &light, &light);
	view = D3DXVECTOR3( 0.0, 0.0, -1.0);   // view vector -> 沥搁
	D3DXVec3Normalize( &view, &view);

	// set otf parameter value
	SetOtfPram(OTFPARAM0, OTFPARAM1, OTFPARAM2, OTFPARAM3);
	m_otfAlphaValue = OTFALPHAPARAM; // == 255
	m_renderingPass = RENDERALLPASS;        // allpass 肺 檬扁拳

	// set clip plane (using fixed function pixel pipeline) parameter
	//---- (x, y, z) -----------------------
	// +x : left face, -x : right face
	// +y : back face, -y : front face
	// +z : bottom face, -z : top face
	// 1 : 3^(1/2) = x : 15
	clipPoint[0] = D3DXVECTOR3(CLIPTOP, CLIPTOP, CLIPTOP);
	clipPoint[1] = D3DXVECTOR3(CLIPTOP, -CLIPTOP, CLIPTOP);
	clipPoint[2] = D3DXVECTOR3(CLIPTOP, -CLIPTOP, -CLIPTOP);
	clipPoint[3] = D3DXVECTOR3(-CLIPTOP, CLIPTOP, CLIPTOP);
	clipPoint[4] = D3DXVECTOR3(-CLIPTOP, CLIPTOP, -CLIPTOP);
	clipPoint[5] = D3DXVECTOR3(-CLIPTOP, -CLIPTOP, -CLIPTOP);

	// set vs clip plane coord.
	SetVSClipPlaneCoord(CLIPTOP, 0);

	scaleFactor = 20.0f; // 30.0f//41.0f

	// for Min-Max texture
	divX = VOLUMEARRAYSIZE / 8;
	divY = VOLUMEARRAYSIZE / 8;
	divZ = VOLUMEARRAYSIZE / 8;


	// MPR_TEST
	m_vMPRControlPoint.clear();
	mpr_cnt = 2;
	D3DXMatrixIdentity( &matCustomMPR );
	D3DXMatrixIdentity( &matCustomMPRTex );
	m_mprCtrlPntNum = 0;

	//added by taeki------------------------------------------------------------------------------------------------------//
	//initial settings
	m_intDataType = 2; //1 -> BYTE, 2-> WORD
//	strcpy(m_arFileName, "../data.den");
//	strcpy(m_arFileName, "../bighead.den");
	strcpy(m_arFileName, "../LargeData613.den");
	m_intSwapedSubvolume = 0;
	m_intVolumeX = 512;
	m_intVolumeY = 512;
	m_intVolumeZ = 256;
	m_intSubvolumeSizeX = 64;
	m_intSubvolumeSizeY = 64;
	m_intSubvolumeSizeZ = 64;
	m_intVirtualMemorySlotX = 8;
	m_intVirtualMemorySlotY = 8;
	m_intVirtualMemorySlotZ = 8;
	if(m_intDataType == 1)
	{
		m_pbyteVolume = (BYTE*)VirtualAlloc(NULL, sizeof(BYTE)*m_intVolumeX*m_intVolumeY*m_intVolumeZ, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
		ASSERT(m_pbyteVolume);
	}
	if(m_intDataType == 2)
	{
		m_pwordVolume = (WORD*)VirtualAlloc(NULL, sizeof(WORD)*m_intVolumeX*m_intVolumeY*m_intVolumeZ, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
		ASSERT(m_pwordVolume);
	}

	//----------------------------------------------------------------------------------------------------------------------//


}
/*
void allocation(int x, int y, int z, LPBYTE aSliceTable[z])
{
	for(int i=0; i<z; i++) {
		aSliceTable[i] = VirtualAlloc(x*y*sizeof(WORD));	// one slice
	}
}

void copy(int x, int y, int z, LPBYTE aSrc[z], LPBYTE aDst[z])
{
	for(int i=0; i<z; i++)
		memcpy(aDst[z], aSrc[z], x*y*sizeof(WORD));
}

main()
{
	LPBYTE aSliceTable[z];
	aSliceTable[z] + y*width + x;
}
*/
//-----------------------------------------------------------------------------
// Name: CAppForm::OneTimeSceneInit()
// Desc: Paired with FinalCleanup().
//       The window has been created and the IDirect3D9 interface has been
//       created, but the device has not been created yet.  Here you can
//       perform application-related initialization and cleanup that does
//       not depend on a device.
//-----------------------------------------------------------------------------
HRESULT CAppForm::OneTimeSceneInit()
{
    // TODO: perform one time initialization

    m_bLoadingApp = FALSE;

    return S_OK;
}



//-----------------------------------------------------------------------------
// Name: ConfirmDevice()
// Desc: Called during device initialization, this code checks the display device
//       for some minimum set of capabilities
//-----------------------------------------------------------------------------
HRESULT CAppForm::ConfirmDevice( D3DCAPS9* pCaps, DWORD dwBehavior,
                                          D3DFORMAT Format )
{
    UNREFERENCED_PARAMETER( pCaps );
    UNREFERENCED_PARAMETER( dwBehavior );
    UNREFERENCED_PARAMETER( Format );
    BOOL bCapsAcceptable;

    // TODO: Perform checks to see if these display caps are acceptable.
    bCapsAcceptable = TRUE;

    if( bCapsAcceptable )         
        return S_OK;
    else
        return E_FAIL;
}



void CAppForm::CompressedVolume()
{

	int x, y, z; 
	int i, j, k;
//	int nOffsetZ, nOffsetY;

	for(k=0; k<divZ; k++) {
		for(j=0; j<divY; j++) {
			for(i=0; i<divX; i++) {

//				if(m_nDenSize == 12)	minDenDiv8[i][j][k] = 65535; //WORD minDenDiv8[][][]
//				else if(m_nDenSize == 8)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -