X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=f704e7992b60ad11a0dc04db59279144b70f1aed;hb=06066d9192936b4c4cc69847cd4c1f5aa7017829;hp=a3343ab8a9523b5a6ce57d372c6b3be7399bb5ef;hpb=2093dcb9760e9261299ebbab4f8ff203e4d9af77;p=ctsim.git diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index a3343ab..f704e79 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.28 2002/06/03 16:57:22 kevin Exp $ +** $Id: graph3dview.cpp,v 1.33 2003/01/30 21:53:16 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 @@ -25,11 +25,6 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -#ifdef __GNUG__ -#pragma implementation -#pragma interface -#endif - #include "wx/wxprec.h" #ifndef WX_PRECOMP @@ -166,34 +161,33 @@ bool Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { m_pFrame = CreateChildFrame(doc, this); + SetFrame (m_pFrame); m_pCanvas = CreateCanvas (m_pFrame); m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); - SetFrame (m_pFrame); m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); m_pFrame->SetTitle("Graph3dFileView"); - m_pCanvas->SetCurrent(); - - InitGL(); - - m_pFrame->SetFocus(); - m_pFrame->Show(true); - Activate(true); - + m_pCanvas->SetCurrent(); + InitGL(); + m_pCanvas->SwapBuffers(); + m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor); m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting); m_pViewMenu->Check (GRAPH3D_VIEW_SMOOTH, m_bSmooth); m_pViewMenu->Check (GRAPH3D_VIEW_WIREFRAME, m_bWireframe); + + m_pFrame->SetFocus(); + m_pFrame->Show(true); + Activate(true); + return true; } Graph3dFileCanvas* Graph3dFileView::CreateCanvas (wxFrame* parent) { - Graph3dFileCanvas* pCanvas; - - pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0); + Graph3dFileCanvas* pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->Clear(); @@ -286,7 +280,7 @@ Graph3dFileView::CreateDisplayList() 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; + double dIntensity1 = 0., dIntensity2 = 0.; if (m_bColor) { dIntensity1 = (v[ix][0] - dMin) / dIntensityScale; dIntensity2 = (v[ix+1][0] - dMin) / dIntensityScale; @@ -296,12 +290,13 @@ Graph3dFileView::CreateDisplayList() intensityToColor (dIntensity1, vecColor); glColor3fv (vecColor); } - glVertex3dv (p1); - glNormal3dv (n1); + glVertex3dv (p1); glNormal3dv (n1); + if (m_bColor) { intensityToColor (dIntensity2, vecColor); glColor3fv (vecColor); - glVertex3dv (p2); - glNormal3dv (n1); + } + glVertex3dv (p2); 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++, dYPos++) { @@ -309,14 +304,18 @@ Graph3dFileView::CreateDisplayList() 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]; - dIntensity1 = (v[ix][iy] - dMin) / dIntensityScale; - dIntensity2 = (v[ix+1][iy] - dMin) / dIntensityScale; - intensityToColor (dIntensity1, vecColor); - glColor3fv (vecColor); - glVertex3dv (p1); glNormal3dv (n1); - intensityToColor (dIntensity2, vecColor); - glColor3fv (vecColor); - glVertex3dv (p2); glNormal3dv (n1); + if (m_bColor) { + dIntensity1 = (v[ix][iy] - dMin) / dIntensityScale; + dIntensity2 = (v[ix+1][iy] - dMin) / dIntensityScale; + intensityToColor (dIntensity1, vecColor); + glColor3fv (vecColor); + } + glVertex3dv (p1); glNormal3dv (n1); + if (m_bColor) { + intensityToColor (dIntensity2, vecColor); + glColor3fv (vecColor); + } + glVertex3dv (p2); glNormal3dv (n1); } glEnd(); // QUAD_STRIP } @@ -403,6 +402,9 @@ Graph3dFileView::OnDraw (wxDC* dc) { if (m_pCanvas) { m_pCanvas->SetCurrent(); +//#ifdef DEBUG + *theApp->getLog() << "Drawing 3d surface\n"; +//#endif Draw(); m_pCanvas->SwapBuffers(); } @@ -605,6 +607,10 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) m_dColorScaleMax = max; } double dRadius = maxValue (nx, ny) * SQRT2 / 2; + + if (m_pCanvas) + m_pCanvas->SetCurrent(); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (-dRadius, dRadius, -dRadius, dRadius, dRadius*5, -dRadius*5); @@ -620,9 +626,11 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) #endif CreateDisplayList(); - - if (m_pCanvas) + + if (m_pCanvas) { + m_pCanvas->SwapBuffers(); m_pCanvas->Refresh(); + } } bool @@ -645,11 +653,25 @@ Graph3dFileView::OnClose (bool deleteWindow) if (deleteWindow) { delete m_pFrame; m_pFrame = NULL; + if (GetDocument() && GetDocument()->getBadFileOpen()) + ::wxYield(); // wxWindows bug workaround } return true; } +void +Graph3dFileView::setInitialClientSize () +{ + if (m_pFrame && m_pCanvas) { + wxSize bestSize = m_pCanvas->GetBestSize(); + + m_pFrame->SetClientSize (bestSize); + m_pFrame->Show (true); + m_pFrame->SetFocus(); + } +} + void Graph3dFileView::OnScaleAuto (wxCommandEvent& event) { @@ -682,7 +704,7 @@ Graph3dFileView::OnScaleSet (wxCommandEvent& event) unsigned int nx = GetDocument()->nx(); unsigned int ny = GetDocument()->ny(); const ImageFileArrayConst v = GetDocument()->getArray(); - double dMin, dMax; + double dMin = 0., dMax = 0.; if (! m_bColorScaleMinSet && ! m_bColorScaleMaxSet) { dMax = dMin = v[0][0]; for (unsigned ix = 0; ix < nx; ix++) @@ -801,9 +823,10 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) + BEGIN_EVENT_TABLE(Graph3dFileCanvas, wxGLCanvas) -EVT_SIZE(Graph3dFileCanvas::OnSize) EVT_PAINT(Graph3dFileCanvas::OnPaint) +EVT_SIZE(Graph3dFileCanvas::OnSize) EVT_CHAR(Graph3dFileCanvas::OnChar) EVT_MOUSE_EVENTS(Graph3dFileCanvas::OnMouseEvent) EVT_ERASE_BACKGROUND(Graph3dFileCanvas::OnEraseBackground) @@ -811,14 +834,11 @@ END_EVENT_TABLE() - Graph3dFileCanvas::Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos, - const wxSize& size, long style): -wxGLCanvas (parent, -1, pos, size, style, _T("Graph3dCanvas") - ), m_pView(view) + const wxSize& size, long style) + : wxGLCanvas (parent, -1, pos, size, style), m_pView(view) { - parent->Show (true); - SetCurrent(); +// parent->Show (true); #if 0 // Make sure server supports the vertex array extension char* extensions = (char *) glGetString( GL_EXTENSIONS ); @@ -834,8 +854,9 @@ Graph3dFileCanvas::~Graph3dFileCanvas() } void -Graph3dFileCanvas::OnDraw (wxDC& dc) +Graph3dFileCanvas::OnPaint (wxPaintEvent& event) { + wxPaintDC dc(this); if (m_pView) m_pView->OnDraw(& dc); } @@ -851,10 +872,9 @@ void Graph3dFileCanvas::OnSize (wxSizeEvent& event) { #ifndef __WXMOTIF__ - if (!GetContext()) return; + // if (!GetContext()) return; #endif - SetCurrent(); int width, height; GetClientSize (&width, &height); Reshape (width, height); @@ -913,7 +933,9 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event) void Graph3dFileCanvas::Reshape (int width, int height) { + SetCurrent(); glViewport (0, 0, (GLint)width, (GLint)height); + SwapBuffers(); }