www.pudn.com > 20050325_c_Pyramid.rar > PyramidView.cpp
// PyramidView.cpp : implementation of the CPyramidView class // #include "stdafx.h" #include "Pyramid.h" #include "PyramidDoc.h" #include "PyramidView.h" #include#include #include #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define PartX 300//每块的x方向长度限制 #define PartY 200//每块的y方向长度限制 #define RGB_Base 255/12535 ///////////////////////////////////////////////////////////////////////////// // CPyramidView IMPLEMENT_DYNCREATE(CPyramidView, CScrollView) BEGIN_MESSAGE_MAP(CPyramidView, CScrollView) //{{AFX_MSG_MAP(CPyramidView) ON_COMMAND(ID_Area400, OnArea400) ON_COMMAND(ID_Area800, OnArea800) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPyramidView construction/destruction CPyramidView::CPyramidView() { // TODO: add construction code here } CPyramidView::~CPyramidView() { } BOOL CPyramidView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs AfxMessageBox("数据处理中请稍等!!!"); MyReadTxt("20050315.txt",1354,4920); MyMakePyramid(m_array,1354,4920,10,40); OriginPartLengthX=MyGetPartLengthX(1354,10,0); OriginPartLengthY=MyGetPartLengthY(4920,40,0); InputDisplayLenthX=200; InputDisplayLenthY=200; //CString ss; //ss.Format("%d",m_array[0][0]); //AfxMessageBox(ss); return CScrollView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CPyramidView drawing void CPyramidView::OnDraw(CDC* pDC) { CPyramidDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); MyDisplay(MyPyramid,0,0,InputDisplayLenthX,InputDisplayLenthY,0,0,0); // TODO: add draw code for native data here } void CPyramidView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; // TODO: calculate the total size of this view sizeTotal.cx = sizeTotal.cy = 100; SetScrollSizes(MM_TEXT, sizeTotal); } ///////////////////////////////////////////////////////////////////////////// // CPyramidView printing BOOL CPyramidView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CPyramidView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CPyramidView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CPyramidView diagnostics #ifdef _DEBUG void CPyramidView::AssertValid() const { CScrollView::AssertValid(); } void CPyramidView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } CPyramidDoc* CPyramidView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPyramidDoc))); return (CPyramidDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPyramidView message handlers void CPyramidView::MyReadTxt(char * txtname,int array_x, int array_y) { m_array_x=array_x; //二维数组的列 m_array_y=array_y; //二维数组的行 char *txtfilename=""; //定义文件名 // CString txtfilename; // txtfilename=txtname; fstream file; //定义一个文件对象 //txtfilename="output1.txt"; //给定文件名 txtfilename=txtname; //给定文件名 //strcat(txtfilename, txtname); file.open(txtfilename,ios::in);//打开文件为读写模式 int x ; m_array=new int *[m_array_y]; for (int i=0;i ='0'&&abite[0]<='9') { strcat(strt, abite); //将读到的一个字符保存进临时字符串 }//将读到的一个一个的字符连续存入临时字符串,用来转换为整型 else { x=atoi(strt); m_array[i][j]=x; } //遇到制表符则不再读取,将已经得到的字符串转换为整型存入数组 } while(abite[0]>='0'&&abite[0]<='9');//如果读到的字符是数字就继续,否则跳出 } } } int CPyramidView::MyDivideX(double Dm_Scale,int DBeginX, int DEndX)//x方向分块数量 { mDivideX=(int)ceil(((double)abs(DBeginX-DEndX)*Dm_Scale)/PartX); return mDivideX; } int CPyramidView::MyDivideY(double Dm_Scale, int DBeginY, int DEndY)//y方向分块数量 { mDivideY=(int)ceil(((double)abs(DBeginY-DEndY)*Dm_Scale)/PartY); return mDivideY; } int CPyramidView::MyGetPartLengthX(int arrayX, int divideX,int indexx)//得到每个分块的X方向长度 { int lengthX; if(indexx SetPixel(j*OriginPartLengthX+l+OffSetX,i*OriginPartLengthY+k+OffSetY,RGB(TargetPyramid[i][j][k][l]*(int)RGB_Base,TargetPyramid[i][j][k][l]*(int)RGB_Base,TargetPyramid[i][j][k][l]*(int)RGB_Base)); } } } } } void CPyramidView::OnArea400() { // TODO: Add your command handler code here InputDisplayLenthX=400; InputDisplayLenthY=400; Invalidate(); } void CPyramidView::OnArea800() { // TODO: Add your command handler code here InputDisplayLenthX=800; InputDisplayLenthY=800; Invalidate(); }