ZProject.cpp
上传用户:wangdan
上传日期:2022-06-30
资源大小:739k
文件大小:3k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. // ZProject.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Test1.h"
  5. #include "ZProject.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CZProject
  14. extern GLfloat Databuf[ArrayOne][ArrayTwo];
  15. extern bool gbIsGetData;
  16. extern bool gbDataIsEmpty;
  17. IMPLEMENT_DYNCREATE(CZProject, CView)
  18. CZProject::CZProject()
  19. {
  20. }
  21. CZProject::~CZProject()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CZProject, CView)
  25. //{{AFX_MSG_MAP(CZProject)
  26. ON_WM_ERASEBKGND()
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CZProject drawing
  31. void CZProject::OnDraw(CDC* pDC)
  32. {
  33. CDocument* pDoc = GetDocument();
  34. CRect rc;
  35. GetClientRect(&rc);
  36. pDC->SetTextAlign(TA_CENTER);
  37. pDC->SetTextColor(YELLOW);
  38. pDC->SetBkMode(1);
  39. CFont *OldFont = pDC->SelectObject(&this->m_pFr->m_13Font);
  40. CPen *pen = new CPen(PS_SOLID,1,GREEN);
  41. CPen *pOldPen = pDC->SelectObject(pen);
  42. pDC->TextOut(rc.right/2,2,"Z轴投影-密度");
  43. //x轴
  44. pDC->MoveTo(10,rc.bottom-20);
  45. pDC->LineTo(rc.right-30,rc.bottom-20);
  46. pDC->MoveTo(rc.right-30,rc.bottom-20);
  47. pDC->LineTo(rc.right-30-5,rc.bottom-20-5);
  48. pDC->MoveTo(rc.right-30,rc.bottom-20);
  49. pDC->LineTo(rc.right-30-5,rc.bottom-20+5);
  50. //y轴
  51. pDC->MoveTo(10,rc.bottom-20);
  52. pDC->LineTo(10,25);
  53. pDC->MoveTo(10,25);
  54. pDC->LineTo(5,30);
  55. pDC->MoveTo(10,25);
  56. pDC->LineTo(15,30);
  57. this->DrawZCoordinate(pDC);
  58. this->ZProjection(pDC);
  59. pDC->SelectObject(pOldPen);
  60. pDC->SelectObject(OldFont);
  61. delete pen;
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CZProject diagnostics
  65. #ifdef _DEBUG
  66. void CZProject::AssertValid() const
  67. {
  68. CView::AssertValid();
  69. }
  70. void CZProject::Dump(CDumpContext& dc) const
  71. {
  72. CView::Dump(dc);
  73. }
  74. #endif //_DEBUG
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CZProject message handlers
  77. BOOL CZProject::OnEraseBkgnd(CDC* pDC) 
  78. {
  79. CBrush Brush (BLACK); 
  80.     CBrush* pOldBrush = pDC->SelectObject(&Brush);     
  81. CRect ViewClip; 
  82. pDC->GetClipBox(&ViewClip);     
  83. pDC->PatBlt(ViewClip.left,ViewClip.top,ViewClip.Width(),ViewClip.Height(),PATCOPY);    
  84. pDC->SelectObject (pOldBrush );
  85. return TRUE;
  86. }
  87. void CZProject::OnInitialUpdate() 
  88. {
  89. CView::OnInitialUpdate();
  90. this->m_pFr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  91. }
  92. void CZProject::DrawZCoordinate(CDC *pDC)
  93. {
  94. CRect rc;
  95. this->GetClientRect(&rc);
  96. pDC->SetTextAlign(TA_LEFT);
  97. pDC->TextOut(2,rc.bottom-15,"0");
  98. pDC->TextOut(rc.right-30,rc.bottom-25,"声波");
  99. pDC->TextOut(0,10,"中子");
  100. }
  101. void CZProject::ZProjection(CDC *pDC)
  102. {
  103. if (::gbIsGetData)
  104. return;
  105. if (::gbDataIsEmpty)
  106. return;
  107. CRect rc;
  108. GetClientRect(&rc);
  109. for (int i=0; i<ArrayOne; i++)
  110. {
  111. if ((GLfloat)Databuf[i][0] >= this->m_pFr->m_pView->m_nMinDepth 
  112. && (GLfloat)Databuf[i][0] <= this->m_pFr->m_pView->m_nMaxDepth )
  113. {
  114. pDC->SetPixel(Databuf[i][this->m_pFr->m_pView->m_First]/3-10
  115. ,(rc.bottom-20) -( Databuf[i][this->m_pFr->m_pView->m_Second]*3+20 )
  116. ,BLUE);
  117. }
  118. }
  119. }