X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=d92912fb09a653f164d88460d4067eb86bfd8ac7;hb=9ff5b5165b2c8871bd4b29ccd5ca794638414615;hp=d0d53edeb839b0293cd1e40b5147b0a7e0a7213c;hpb=1f72f3289ee6be64ec607ea93b4fcfe8b5dff3eb;p=ctsim.git diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index d0d53ed..d92912f 100644 --- a/src/graph3dview.cpp +++ b/src/graph3dview.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: graph3dview.cpp,v 1.10 2001/02/04 21:28:19 kevin Exp $ +** $Id: graph3dview.cpp,v 1.19 2001/03/13 04:44:25 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -30,13 +30,8 @@ #pragma interface #endif -// For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - #ifndef WX_PRECOMP #include "wx/wx.h" #endif @@ -172,7 +167,7 @@ EVT_MENU(GRAPH3D_VIEW_SCALE_FULL, Graph3dFileView::OnScaleFull) END_EVENT_TABLE() Graph3dFileView::Graph3dFileView () -: m_pFileMenu(NULL), m_pViewMenu(NULL) + : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pCanvas(NULL), m_pFrame(NULL) { m_bDoubleBuffer = true; m_bSmooth = true; @@ -197,7 +192,6 @@ bool Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { m_pFrame = CreateChildFrame(doc, this); - (m_pFrame); int width, height; m_pFrame->GetClientSize (&width, &height); @@ -230,20 +224,7 @@ Graph3dFileView::CreateCanvas (wxFrame* parent) int width, height; parent->GetClientSize (&width, &height); -#ifdef __WXMSW__ - int *gl_attrib = NULL; -#else - int gl_attrib[20] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER, None }; -#endif - - if(! m_bDoubleBuffer) { -#ifdef __WXGTK__ - gl_attrib[9] = None; -#endif - } - - pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(0, 0), wxSize(200, 200), 0, gl_attrib); + pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(0, 0), wxSize(200, 200), 0); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->Clear(); @@ -280,10 +261,9 @@ Graph3dFileView::DrawSurface() unsigned int nx = GetDocument()->nx(); unsigned int ny = GetDocument()->ny(); glRotated (m_dZRotate, 0.0, 1.0, 0.0); - glTranslated (-static_cast(nx) / 2, 0.0, -static_cast(ny) / 2); - glRotated (m_dYRotate, 1.0, 0.0, 0.0); glRotated (m_dXRotate, 0.0, 0.0, 1.0); - + glRotated (m_dYRotate, 1.0, 0.0, 0.0); + glTranslated (-static_cast(nx - 1) / 2, 0.0, -static_cast(ny - 1) / 2); glCallList (DISPLAYLIST_SURFACE); } @@ -305,18 +285,24 @@ Graph3dFileView::CreateDisplayList() double dIntensityScale = m_dColorScaleMax - m_dColorScaleMin; double actOffset = m_dGraphMin; double actScale = 0.4 * sqrt(nx*nx+ny*ny) / (m_dGraphMax - m_dGraphMin); - + double dXOffset = -(static_cast(nx) - 1) / 2.; + double dYOffset = -(static_cast(ny) - 1) / 2.; + dXOffset = 0; + dYOffset = 0; + if (! m_bColor) glColor3f (1.0f, 1.0f, 1.0f); - for (unsigned ix = 0; ix < nx - 1; ix++) { + double dXPos = -dXOffset; + for (unsigned ix = 0; ix < nx - 1; ix++, dXPos++) { + double dYPos = -dYOffset; glBegin(GL_QUAD_STRIP); - double p1[3], p2[3], p3[3]; - double n1[3]; - p1[0] = ix; p1[1] = actScale * (v[ix][0] + actOffset); p1[2] = 0; - p2[0] = ix+1; p2[1] = actScale * (v[ix+1][0] + actOffset); p2[2] = 0; - p3[0] = ix; p3[1] = actScale * (v[ix][1] + actOffset); p3[2] = 1; + double p1[3], p2[3], p3[3], n1[3]; + p1[0] = dXPos; p1[1] = actScale * (v[ix][0] + actOffset); p1[2] = dYPos; + p2[0] = dXPos+1; p2[1] = actScale * (v[ix+1][0] + actOffset); p2[2] = dYPos; + p3[0] = dXPos; p3[1] = actScale * (v[ix][1] + actOffset); p3[2] = dYPos + 1; CalculateVectorNormal (p1, p2, p3, &n1[0], &n1[1], &n1[2]); + double dIntensity1, dIntensity2; if (m_bColor) { dIntensity1 = (v[ix][0] - dMin) / dIntensityScale; @@ -337,9 +323,9 @@ Graph3dFileView::CreateDisplayList() glNormal3dv (n1); double lastP[3]; lastP[0] = ix; lastP[1] = actScale * (v[ix][0] + actOffset); lastP[2] = 0; - for (unsigned int iy = 1; iy < ny - 1; iy++) { - p1[0] = ix; p1[1] = actScale * (v[ix][iy] + actOffset); p1[2] = iy; - p2[0] = ix+1; p2[1] = actScale * (v[ix+1][iy] + actOffset); p2[2] = iy; + for (unsigned int iy = 1; iy < ny - 1; iy++, dYPos++) { + p1[0] = dXPos; p1[1] = actScale * (v[ix][iy] + actOffset); p1[2] = dYPos; + p2[0] = dXPos+1; p2[1] = actScale * (v[ix+1][iy] + actOffset); p2[2] = dYPos; CalculateVectorNormal (p1, p2, lastP, &n1[0], &n1[1], &n1[2]); lastP[0] = p1[0]; lastP[1] = p1[1]; lastP[2] = p1[2]; if (m_bColor) { @@ -410,11 +396,14 @@ Graph3dFileView::OnSmooth (wxCommandEvent& event) void Graph3dFileView::OnDraw (wxDC* dc) { + if (! m_pCanvas) + return; + m_pCanvas->SetCurrent(); + #ifndef __WXMOTIF__ - if (! m_pCanvas->GetContext()) return; + // if (! m_pCanvas->GetContext()) return; #endif - m_pCanvas->SwapBuffers(); Draw(); std::ostringstream os; os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate << ", Zangle=" << m_dZRotate; @@ -590,8 +579,8 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) if (! GetDocument()) return; - int nx = GetDocument()->nx(); - int ny = GetDocument()->ny(); + unsigned int nx = GetDocument()->nx(); + unsigned int ny = GetDocument()->ny(); const ImageFileArrayConst v = GetDocument()->getArray(); if (v != NULL && nx != 0 && ny != 0) { double min = v[0][0]; @@ -619,7 +608,7 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); -#if 1 +#if 0 GLfloat eyep[3], lookp[3], up[3]; eyep[0] = -nx/2; eyep[1] = 0; eyep[2] = -ny/2; lookp[0] = 0; lookp[1] = 0, lookp[2] = 0; @@ -777,7 +766,6 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) wxMenu *help_menu = new wxMenu; help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1"); - help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H"); help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); wxMenuBar *menu_bar = new wxMenuBar; @@ -789,23 +777,18 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) subframe->SetMenuBar(menu_bar); subframe->Centre(wxBOTH); - - wxAcceleratorEntry accelEntries[12]; - accelEntries[0].Set (wxACCEL_CTRL, static_cast('O'), wxID_OPEN); - accelEntries[1].Set (wxACCEL_CTRL, static_cast('H'), MAINMENU_HELP_TOPICS); - accelEntries[2].Set (wxACCEL_CTRL, static_cast('P'), MAINMENU_FILE_CREATE_PHANTOM); - accelEntries[3].Set (wxACCEL_CTRL, static_cast('F'), MAINMENU_FILE_CREATE_FILTER); - accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS); - accelEntries[5].Set (wxACCEL_CTRL, static_cast('R'), GRAPH3D_VIEW_SURFACE); - accelEntries[6].Set (wxACCEL_CTRL, static_cast('L'), GRAPH3D_VIEW_COLOR); - accelEntries[7].Set (wxACCEL_CTRL, static_cast('G'), GRAPH3D_VIEW_LIGHTING); - accelEntries[8].Set (wxACCEL_CTRL, static_cast('M'), GRAPH3D_VIEW_SMOOTH); - accelEntries[9].Set (wxACCEL_CTRL, static_cast('E'), GRAPH3D_VIEW_SCALE_MINMAX); - accelEntries[10].Set (wxACCEL_CTRL, static_cast('A'), GRAPH3D_VIEW_SCALE_AUTO); - accelEntries[11].Set (wxACCEL_CTRL, static_cast('U'), GRAPH3D_VIEW_SCALE_FULL); - wxAcceleratorTable accelTable (12, accelEntries); + + wxAcceleratorEntry accelEntries[7]; + accelEntries[0].Set (wxACCEL_CTRL, static_cast('R'), GRAPH3D_VIEW_SURFACE); + accelEntries[1].Set (wxACCEL_CTRL, static_cast('L'), GRAPH3D_VIEW_COLOR); + accelEntries[2].Set (wxACCEL_CTRL, static_cast('G'), GRAPH3D_VIEW_LIGHTING); + accelEntries[3].Set (wxACCEL_CTRL, static_cast('M'), GRAPH3D_VIEW_SMOOTH); + accelEntries[4].Set (wxACCEL_CTRL, static_cast('E'), GRAPH3D_VIEW_SCALE_MINMAX); + accelEntries[5].Set (wxACCEL_CTRL, static_cast('A'), GRAPH3D_VIEW_SCALE_AUTO); + accelEntries[6].Set (wxACCEL_CTRL, static_cast('U'), GRAPH3D_VIEW_SCALE_FULL); + wxAcceleratorTable accelTable (7, accelEntries); subframe->SetAcceleratorTable (accelTable); - + return subframe; } @@ -823,8 +806,9 @@ END_EVENT_TABLE() Graph3dFileCanvas::Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos, - const wxSize& size, long style, int* gl_attrib): -wxGLCanvas (parent, -1, pos, size, style, _T("Graph3dCanvas"), gl_attrib), m_pView(view) + const wxSize& size, long style): +wxGLCanvas (parent, -1, pos, size, style, _T("Graph3dCanvas") + ), m_pView(view) { parent->Show (true); SetCurrent();