X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=747e983d39a419e20282f0055cdcaad92191a4f9;hp=fdcb82369e391b49254c8f030a2fcd8bb56f203d;hb=f7ee98f7d964ed361068179f0e7ea4475ed1abdf;hpb=ba8635d790ee847d9746c6da24b60bd4cb6d9116 diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index fdcb823..747e983 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.1 2001/01/30 07:32:13 kevin Exp $ +** $Id$ ** ** 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,23 +25,14 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ - -#ifdef __GNUG__ -#pragma implementation -#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 +#if wxUSE_GLCANVAS + #if !wxUSE_GLCANVAS #error Please set wxUSE_GLCANVAS to 1 in setup.h. #endif @@ -69,6 +60,40 @@ #include #endif +inline void +Graph3dFileView::intensityToColor (double dIntensity, GLfloat* vecColor) +{ + if (dIntensity < 0 || dIntensity > 1) { + vecColor[0] = vecColor[1] = vecColor[2] = 1; + return; + } + + float fRange = dIntensity * 5; + int iRange = static_cast(floor (fRange)); + float fFrac = fRange - iRange; + + // Rainbow: Purple->Blue->Cyan->Green->Yellow->Red = (1,0,1)-(0,0,1)-(0,1,1)-(0,1,0)-(1,1,0)-(1,0,0) + switch (iRange) { + case 0: + vecColor[0] = 1.0f - fFrac; vecColor[1] = 0.0f; vecColor[2] = 1.0f; + break; + case 1: + vecColor[0] = 0.0f; vecColor[1] = fFrac; vecColor[2] = 1.0f; + break; + case 2: + vecColor[0] = 0.0f; vecColor[1] = 1.0f; vecColor[2] = 1.0f - fFrac; + break; + case 3: + vecColor[0] = fFrac; vecColor[1] = 1.0f; vecColor[2] = 0.0f; + break; + case 4: + vecColor[0] = 1.0f; vecColor[1] = 1.0f - fFrac; vecColor[2] = 0.0f; + break; + case 5: + vecColor[0] = 1.0f; vecColor[1] = 0.0f; vecColor[2] = 0.0f; + break; + } +} //*********************************************************************** // Function: CalculateVectorNormal @@ -87,180 +112,325 @@ // fNormalZ == Z vector for the normal vector //************************************************************************* - -GLvoid CalculateVectorNormal (GLfloat fVert1[], GLfloat fVert2[], - GLfloat fVert3[], GLfloat *fNormalX, - GLfloat *fNormalY, GLfloat *fNormalZ) +template +static void +CalculateVectorNormal (T fVert1[], T fVert2[], T fVert3[], T *fNormalX, T *fNormalY, T *fNormalZ) { - GLfloat Qx = fVert2[0] - fVert1[0]; - GLfloat Qy = fVert2[1] - fVert1[1]; - GLfloat Qz = fVert2[2] - fVert1[2]; - GLfloat Px = fVert3[0] - fVert1[0]; - GLfloat Py = fVert3[1] - fVert1[1]; - GLfloat Pz = fVert3[2] - fVert1[2]; - + T Qx = fVert2[0] - fVert1[0]; + T Qy = fVert2[1] - fVert1[1]; + T Qz = fVert2[2] - fVert1[2]; + T Px = fVert3[0] - fVert1[0]; + T Py = fVert3[1] - fVert1[1]; + T Pz = fVert3[2] - fVert1[2]; + *fNormalX = Py*Qz - Pz*Qy; *fNormalY = Pz*Qx - Px*Qz; *fNormalZ = Px*Qy - Py*Qx; - -} +} IMPLEMENT_DYNAMIC_CLASS(Graph3dFileView, wxView) BEGIN_EVENT_TABLE(Graph3dFileView, wxView) EVT_MENU(IFMENU_FILE_PROPERTIES, Graph3dFileView::OnProperties) +EVT_MENU(GRAPH3D_VIEW_LIGHTING, Graph3dFileView::OnLighting) +EVT_MENU(GRAPH3D_VIEW_COLOR, Graph3dFileView::OnColor) +EVT_MENU(GRAPH3D_VIEW_SMOOTH, Graph3dFileView::OnSmooth) +EVT_MENU(GRAPH3D_VIEW_WIREFRAME, Graph3dFileView::OnWireframe) +EVT_MENU(GRAPH3D_VIEW_SCALE_MINMAX, Graph3dFileView::OnScaleSet) +EVT_MENU(GRAPH3D_VIEW_SCALE_AUTO, Graph3dFileView::OnScaleAuto) +EVT_MENU(GRAPH3D_VIEW_SCALE_FULL, Graph3dFileView::OnScaleFull) END_EVENT_TABLE() Graph3dFileView::Graph3dFileView () -: m_pFileMenu(NULL) -{ - m_bUseVertexArrays = GL_FALSE; - m_bDoubleBuffer = GL_TRUE; - m_bSmooth = GL_TRUE; - m_bLighting = GL_TRUE; - -} + : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pStatusBar(NULL), m_pCanvas(NULL), + m_dXRotate(-180), m_dYRotate(-210), m_dZRotate(195), + m_bDoubleBuffer(true), m_bSmooth(true), m_bWireframe(false), + m_bLighting(false), m_bColor(true), m_bUseVertexArrays(false), + m_bColorScaleMinSet(false), m_bColorScaleMaxSet(false), + m_pFrame(NULL) +{} + Graph3dFileView::~Graph3dFileView() { GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu); - GetDocumentManager()->ActivateView(this, FALSE, TRUE); + GetDocumentManager()->ActivateView(this, false); } -bool +bool Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { m_pFrame = CreateChildFrame(doc, this); - (m_pFrame); - - int width, height; - m_pFrame->GetClientSize (&width, &height); - m_pFrame->SetTitle("Graph3dFileView"); + SetFrame (m_pFrame); m_pCanvas = CreateCanvas (m_pFrame); - - m_pFrame->Show(TRUE); + + m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); + m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); + m_pFrame->SetTitle(_T("Graph3dFileView")); + m_pCanvas->SetCurrent(); - InitGL(); - - int x, y; // X requires a forced resize - m_pFrame->GetSize(&x, &y); - m_pFrame->SetSize(-1, -1, x, y); + 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* +Graph3dFileCanvas* Graph3dFileView::CreateCanvas (wxFrame* parent) { - Graph3dFileCanvas* pCanvas; - 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->SetScrollbars(20, 20, 50, 50); + Graph3dFileCanvas* pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0); + pCanvas->SetBackgroundColour(*wxWHITE); - pCanvas->Clear(); - + pCanvas->ClearBackground(); + return pCanvas; } - void Graph3dFileView::DrawSurface() { -#ifdef GL_EXT_vertex_array - if (m_bUseVertexArrays) { - glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, m_nVerts ); + if (! GetDocument()) + return; + + if (m_bSmooth) { + glShadeModel (GL_SMOOTH); + } else { + glShadeModel (GL_FLAT); } - else { -#endif - glBegin( GL_TRIANGLE_STRIP ); - for (GLint i = 0;i < m_nVerts; i++) { - // glNormal3fv( &m_vecNorms[i] ); - // glVertex3fv( &m_vecVerts[i] ); + + if (m_bLighting) { + glEnable (GL_LIGHTING); + } else { + glDisable (GL_LIGHTING); + } + + unsigned int nx = GetDocument()->nx(); + unsigned int ny = GetDocument()->ny(); + + glRotated (m_dZRotate, 0.0, 1.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); + + InitMaterials(); + if (m_bWireframe) { + if (! m_bColor) + glColor3f (1.0f, 1.0f, 1.0f); + glPolygonOffset (1.0f, 1.0f); + glEnable (GL_POLYGON_OFFSET_FILL); + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + glCallList (DISPLAYLIST_COLOR); + + glEnable (GL_DEPTH_TEST); + glColor3f (1.0f, 1.0f, 1.0f); + glPolygonOffset (0.0f, 0.0f); + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + glCallList (DISPLAYLIST_NO_COLOR); + + } else { + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + if (! m_bColor) { + glColor3f (1.0f, 1.0f, 1.0f); + glCallList (DISPLAYLIST_NO_COLOR); + } else { + glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable (GL_COLOR_MATERIAL); + glShadeModel (GL_FLAT); + glCallList (DISPLAYLIST_COLOR); } - glEnd(); -#ifdef GL_EXT_vertex_array } -#endif -} +} void -Graph3dFileView::OnProperties (wxCommandEvent& event) +Graph3dFileView::CreateDisplayList() { - const ImageFile& rIF = GetDocument()->getImageFile(); - if (rIF.nx() == 0 || rIF.ny() == 0) - *theApp->getLog() << "Properties: empty imagefile\n"; - else { - const std::string& rFilename = rIF.getFilename(); - std::ostringstream os; - double min, max, mean, mode, median, stddev; - rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev); - os << "Filename: " << rFilename << "\n"; - os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n"; - os << "Data type: "; - if (rIF.isComplex()) - os << "Complex\n"; - else - os << "Real\n"; - os << "Minimum: "<nx(); + unsigned int ny = GetDocument()->ny(); + const ImageFileArrayConst v = GetDocument()->getArray(); + if (nx == 0 || ny == 0 || ! v) + return; + + glNewList (DISPLAYLIST_COLOR, GL_COMPILE); + + double dMin = m_dColorScaleMin; + 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; + + double dXPos = -dXOffset; + unsigned int ix; + for (ix = 0; ix < nx - 1; ix++, dXPos++) { + double dYPos = -dYOffset; + glBegin(GL_QUAD_STRIP); + 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 = 0., dIntensity2 = 0.; + if (m_bColor) { + dIntensity1 = (v[ix][0] - dMin) / dIntensityScale; + dIntensity2 = (v[ix+1][0] - dMin) / dIntensityScale; + } + float vecColor[3]; + if (m_bColor) { + intensityToColor (dIntensity1, vecColor); + glColor3fv (vecColor); } - if (rIF.nLabels() > 0) { - rIF.printLabelsBrief (os); + glVertex3dv (p1); glNormal3dv (n1); + if (m_bColor) { + intensityToColor (dIntensity2, vecColor); + glColor3fv (vecColor); } - *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n"; - wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION); - dialogMsg.ShowModal(); + 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++) { + 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) { + 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 + } + glEndList(); + + + glNewList (DISPLAYLIST_NO_COLOR, GL_COMPILE); + dXPos = -dXOffset; + for (ix = 0; ix < nx - 1; ix++, dXPos++) { + double dYPos = -dYOffset; + glBegin(GL_QUAD_STRIP); + 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]); + + glVertex3dv (p1); + 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++) { + 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]; + glVertex3dv (p1); glNormal3dv (n1); + glVertex3dv (p2); glNormal3dv (n1); + } + glEnd(); // QUAD_STRIP } + glEndList(); } +void +Graph3dFileView::OnProperties (wxCommandEvent& event) +{ + wxString os; + *theApp->getLog() << _T(">>>>\n") << os << _T("<<<<\n"); + wxMessageDialog dialogMsg (getFrameForChild(), os, + _T("Imagefile Properties"), + wxOK | wxICON_INFORMATION); + dialogMsg.ShowModal(); +} + +void +Graph3dFileView::OnLighting (wxCommandEvent& event) +{ + m_bLighting = ! m_bLighting; + m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting); + m_pCanvas->Refresh(); +} -void +void +Graph3dFileView::OnWireframe (wxCommandEvent& event) +{ + m_bWireframe = ! m_bWireframe; + m_pViewMenu->Check (GRAPH3D_VIEW_WIREFRAME, m_bWireframe); + m_pCanvas->Refresh(); +} + +void +Graph3dFileView::OnColor (wxCommandEvent& event) +{ + m_bColor = ! m_bColor; + m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor); + m_pCanvas->Refresh(); +} + +void +Graph3dFileView::OnSmooth (wxCommandEvent& event) +{ + m_bSmooth = ! m_bSmooth; + m_pViewMenu->Check (GRAPH3D_VIEW_SMOOTH, m_bSmooth); + m_pCanvas->Refresh(); +} + + + +void Graph3dFileView::OnDraw (wxDC* dc) { -#ifndef __WXMOTIF__ - if (! m_pCanvas->GetContext()) return; + if (m_pCanvas) { + m_pCanvas->SetCurrent(); +#ifdef DEBUG + *theApp->getLog() << _T("Drawing 3d surface\n"); #endif - - Draw(); - m_pCanvas->SwapBuffers(); + Draw(); + m_pCanvas->SwapBuffers(); + } + + if (m_pStatusBar) { + wxString os; + os << _T("Xangle=") << m_dXRotate << _T(", Yangle=") << m_dYRotate + << _T(", Zangle=") << m_dZRotate; + m_pStatusBar->SetStatusText (os); + } } -void +void Graph3dFileView::Draw () { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); - glRotatef( m_dYRotate, 0.0, 1.0, 0.0 ); - glRotatef( m_dXRotate, 1.0, 0.0, 0.0 ); - DrawSurface(); - glPopMatrix(); glFlush(); } @@ -269,110 +439,214 @@ Graph3dFileView::Draw () void Graph3dFileView::InitMaterials() { - static float ambient[] = {0.1, 0.1, 0.1, 1.0}; - static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; - static float position0[] = {0.0, 0.0, 20.0, 0.0}; - static float position1[] = {0.0, 0.0, -20.0, 0.0}; - static float front_mat_shininess[] = {60.0}; - static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; - static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; - /* - static float back_mat_shininess[] = {60.0}; - static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; - static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; - */ - static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; - static float lmodel_twoside[] = {GL_FALSE}; - - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); - glLightfv(GL_LIGHT0, GL_POSITION, position0); - glEnable(GL_LIGHT0); - - glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); - glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); - glLightfv(GL_LIGHT1, GL_POSITION, position1); - glEnable(GL_LIGHT1); - - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); - glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + if (! GetDocument()) + return; + int nx = GetDocument()->nx(); + int ny = GetDocument()->ny(); + +#if 1 + static float position0[] = {nx/2, ny*2, -ny*2, 0.0f,}; + static float ambient0[] = {.1f, .1f, .1f, 1.0f}; + static float diffuse0[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static float position1[] = {-nx/2, -ny*2, -ny*2, 0.0f,}; + static float ambient1[] = {.1f, .1f, .1f, .1f}; + static float diffuse1[] = {1.0f, 1.0f, 1.0f, 1.0f}; + // static float position0[] = {0.0f, 0.0f, 20.0f, 0.0f}; + // static float position1[] = {0.0f, 0.0f, -20.0f, 0.0f}; + static float front_mat_shininess[] = {60.0f}; + static float front_mat_specular[] = {0.2f, 0.2f, 0.2f, 1.0f}; + static float front_mat_diffuse[] = {0.3f, 0.3f, 0.3f, 1.0f}; + static float back_mat_shininess[] = {10.0f}; + static float back_mat_specular[] = {0.1f, 0.1f, 0.1f, 1.0f}; + static float back_mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static float lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static float lmodel_twoside[] = {GL_TRUE}; + + //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glHint(GL_LINE_SMOOTH, GL_DONT_CARE); + glEnable(GL_NORMALIZE); + + glLightfv (GL_LIGHT0, GL_AMBIENT, ambient0); + glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse0); + glLightfv (GL_LIGHT0, GL_POSITION, position0); + glEnable (GL_LIGHT0); + + glLightfv (GL_LIGHT1, GL_AMBIENT, ambient1); + glLightfv (GL_LIGHT1, GL_DIFFUSE, diffuse1); + glLightfv (GL_LIGHT1, GL_POSITION, position1); + glEnable (GL_LIGHT1); + + glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv (GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + + glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess); + glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular); + glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv (GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv (GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv (GL_BACK, GL_DIFFUSE, back_mat_diffuse); + + glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); + glColorMaterial (GL_FRONT_AND_BACK, GL_SPECULAR); + glEnable(GL_COLOR_MATERIAL); +#else + GLfloat impLPos[] = {1.0f, 1.0f, 1.0f, 0.0f}; + + GLfloat defaultLightAmb [] = {.2f, .2f, .2f, 1.0f}; + GLfloat defaultLightDiff [] = {.2f, .2f, .2f, 1.0f}; + GLfloat defaultLightSpec [] = { .3f, .3f, .3f, 1.0f}; + + GLfloat defaultGlobalAmb [] = {.3f, .3f, .3f, 1.0f}; + GLfloat defaultGlobalDiff[] = {.3f, .3f, .3f, 1.0f}; + + GLfloat defaultMatShine[] = { 30.0f }; + GLfloat defaultMatSpec[] = { .4f, .4f, .4f, 1.0f}; + GLfloat defaultMatAmb[] = { .3f, .3f, .3f, 1.0f}; + GLfloat defaultMatDiff[] = { .5f, .5f, .5f, 1.0f}; + + GLfloat brassMatAmb[] = { .33f, .22f, .03f, 1.0f}; + GLfloat brassMatDiff[] = { .78f, .57f, .11f, 1.0f}; + GLfloat brassMatSpec[] = { .99f, .91f, .81f, 1.0f}; + GLfloat brassMatShine[] = { 27.8f }; + + GLfloat emeraldMatAmb[] = { .02f1, .1745f , .021f, 1.0f }; + GLfloat emeraldMatDiff[] = { .075f, .6142f , .075f, 1.0f }; + GLfloat emeraldMatSpec[] = { .633f, .7278f , .633f, 1.0f }; + GLfloat emeraldMatShine[] = { 76.8f }; + + GLfloat slateMatAmb[] = { .02f, .02f , .02f, 1.0f }; + GLfloat slateMatDiff[] = { .02f, .01f , .01f, 1.0f }; + GLfloat slateMatSpec[] = { .4f, .4f , .4f , 1.0f }; + GLfloat slateMatShine[] = { .768f }; + + // double opnX = nx, opnY = ny, opnZ = z; + // eyeX = 1; eyeY = 1, eyeZ = 1; + + impLPos[0] = nx/2.; impLPos[1]= ny/2.; impLPos[2] = 0.; + //opnListNum = 1; + //impGraphicsFlag = IMP__3D; + + // glutInitDisplayMode (GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH | GLUT_ACCUM); + // glutInitWindowSize (IMP_WIN_X, IMP_WIN_Y); + // glutInitWindowPosition (100, 100); + // glutCreateWindow ("- imp3D graphics -" ); + + glClearColor (0.0f, 0.0f, 0.0f, 0.0f); + + glShadeModel (GL_SMOOTH); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glHint(GL_LINE_SMOOTH, GL_DONT_CARE); + glEnable(GL_NORMALIZE); + + + glEnable(GL_DEPTH_TEST); + + glLightfv(GL_LIGHT0, GL_AMBIENT, defaultLightAmb); + glLightfv(GL_LIGHT0, GL_DIFFUSE, defaultLightDiff); + glLightfv(GL_LIGHT0, GL_SPECULAR,defaultLightSpec); + + glLightfv(GL_LIGHT1, GL_AMBIENT, defaultLightAmb); + glLightfv(GL_LIGHT1, GL_DIFFUSE, defaultLightDiff); + glLightfv(GL_LIGHT1, GL_SPECULAR,defaultLightSpec); + + glLightfv(GL_LIGHT2, GL_AMBIENT , defaultLightAmb); + glLightfv(GL_LIGHT2, GL_DIFFUSE , defaultLightDiff); + glLightfv(GL_LIGHT2, GL_SPECULAR, defaultLightSpec); + + glLightfv(GL_LIGHT0, GL_POSITION,impLPos); + glLightfv(GL_LIGHT1, GL_POSITION,impLPos); + glLightfv(GL_LIGHT2, GL_POSITION,impLPos); + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT , defaultMatAmb); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE , defaultMatDiff); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR , defaultMatSpec); + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, defaultMatShine); + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, defaultGlobalAmb); + + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_LIGHTING); - - glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse); + glEnable(GL_LIGHT1); + glEnable(GL_LIGHT2); + glEnable(GL_LIGHT0); +#endif + } -void +void Graph3dFileView::InitGL () { - glClearColor(0.0, 0.0, 0.0, 0.0); - - glShadeModel(GL_SMOOTH); - glEnable(GL_DEPTH_TEST); - - InitMaterials(); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 ); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef( 0.0, 0.0, -6.0 ); - -#ifdef GL_EXT_vertex_array - if (m_bUseVertexArrays) { - // glVertexPointerEXT( 3, GL_FLOAT, 0, m_nVerts, verts ); - // glNormalPointerEXT( GL_FLOAT, 0, m_nVerts, norms ); - glEnable( GL_VERTEX_ARRAY_EXT ); - glEnable( GL_NORMAL_ARRAY_EXT ); - } -#endif + glClearColor (0.0f, 0.0f, 0.0f, 0.0f); + + glDisable (GL_CULL_FACE); + glEnable (GL_DEPTH_TEST); + } -void +void Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - const ImageFile& rIF = GetDocument()->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); + if (! GetDocument()) + return; + + unsigned int nx = GetDocument()->nx(); + unsigned int ny = GetDocument()->ny(); + const ImageFileArrayConst v = GetDocument()->getArray(); if (v != NULL && nx != 0 && ny != 0) { -#if 0 - unsigned char* imageData = new unsigned char [nx * ny * 3]; - for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy < ny; iy++) { - double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255; - int intensity = static_cast(scaleValue + 0.5); - intensity = clamp (intensity, 0, 255); - int baseAddr = ((ny - 1 - iy) * nx + ix) * 3; - imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity; + double min = v[0][0]; + double max = min; + for (unsigned int ix = 0; ix < nx; ix++) + for (unsigned int iy = 0; iy < ny; iy++) { + double dVal = v[ix][iy]; + if (min > dVal) + min = dVal; + else if (max < dVal) + max = dVal; } - } - wxImage image (nx, ny, imageData, true); - m_bitmap = image.ConvertToBitmap(); - delete imageData; - int xSize = nx; - int ySize = ny; - ySize = clamp (ySize, 0, 800); - m_pFrame->SetClientSize (xSize, ySize); - m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20); - m_pCanvas->SetBackgroundColour(*wxWHITE); -#endif - } - + m_dGraphMin = min; + m_dGraphMax = max; + if (! m_bColorScaleMinSet) + m_dColorScaleMin = min; + if (! m_bColorScaleMaxSet) + 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); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +#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; + up[0] = 0; up[1] = 1; up[2] = 0; + gluLookAt (eyep[0], eyep[1], eyep[2], lookp[0], lookp[1], lookp[2], up[0], up[1], up[2]); +#endif + + CreateDisplayList(); + + if (m_pCanvas) { + m_pCanvas->SwapBuffers(); m_pCanvas->Refresh(); + } } -bool +bool Graph3dFileView::OnClose (bool deleteWindow) { if (! GetDocument() || ! GetDocument()->Close()) return false; - + Activate (false); if (m_pCanvas) { m_pCanvas->setView(NULL); @@ -381,19 +655,99 @@ Graph3dFileView::OnClose (bool deleteWindow) wxString s(theApp->GetAppName()); if (m_pFrame) m_pFrame->SetTitle(s); - + SetFrame(NULL); - + if (deleteWindow) { - m_pFrame->Destroy(); + 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) +{ +#if 0 + const ImageFile& rIF = GetDocument()->getImageFile(); + double min, max, mean, mode, median, stddev; + rIF.statistics(min, max, mean, mode, median, stddev); + DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor); + int iRetVal = dialogAutoScale.ShowModal(); + if (iRetVal == wxID_OK) { + m_bMinSpecified = true; + m_bMaxSpecified = true; + double dMin, dMax; + if (dialogAutoScale.getMinMax (&dMin, &dMax)) { + m_dMinPixel = dMin; + m_dMaxPixel = dMax; + m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor(); + OnUpdate (this, NULL); + } + } +#endif +} + +void +Graph3dFileView::OnScaleSet (wxCommandEvent& event) +{ + if (! GetDocument()) + return; + + unsigned int nx = GetDocument()->nx(); + unsigned int ny = GetDocument()->ny(); + const ImageFileArrayConst v = GetDocument()->getArray(); + double dMin = 0., dMax = 0.; + if (! m_bColorScaleMinSet && ! m_bColorScaleMaxSet) { + dMax = dMin = v[0][0]; + for (unsigned ix = 0; ix < nx; ix++) + for (unsigned int iy = 0; iy < ny; iy++) + if (v[ix][iy] < dMin) + dMin = v[ix][iy]; + else if (v[ix][iy] > dMax) + dMax = v[ix][iy]; + } + if (m_bColorScaleMinSet) + dMin = m_dColorScaleMin; + if (m_bColorScaleMaxSet) + dMax = m_dColorScaleMax; + + DialogGetMinMax dialogMinMax (getFrameForChild(), _T("Set Color Scale Minimum & Maximum"), dMin, dMax); + int retVal = dialogMinMax.ShowModal(); + if (retVal == wxID_OK) { + m_bColorScaleMinSet = true; + m_bColorScaleMaxSet = true; + m_dColorScaleMin = dialogMinMax.getMinimum(); + m_dColorScaleMax = dialogMinMax.getMaximum(); + OnUpdate (this, NULL); + } +} + +void +Graph3dFileView::OnScaleFull (wxCommandEvent& event) +{ + if (m_bColorScaleMinSet || m_bColorScaleMaxSet) { + m_bColorScaleMinSet = false; + m_bColorScaleMaxSet = false; + OnUpdate (this, NULL); + } +} + #if CTSIM_MDI wxDocMDIChildFrame* #else @@ -402,105 +756,85 @@ wxDocChildFrame* Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view) { #if CTSIM_MDI - wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Graph3dFile Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #else - wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Graph3dFile Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #endif theApp->setIconForFrame (subframe); - + +// status bar text not showing tested with enlightenment. disabling for now... +#if 0 + m_pStatusBar = new wxStatusBar (subframe, -1); + subframe->SetStatusBar (m_pStatusBar); + m_pStatusBar->Show(true); +#endif + m_pFileMenu = new wxMenu; - - m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P"); - m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F"); - m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O"); - m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S"); - m_pFileMenu->Append(wxID_SAVEAS, "Save &As..."); - m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W"); - m_pFileMenu->Append(wxID_REVERT, "Re&vert"); - + + m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P")); + m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F")); + m_pFileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl-O")); + m_pFileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl-W")); + m_pFileMenu->AppendSeparator(); - m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties"); - m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export..."); - + m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, _T("P&roperties")); + m_pFileMenu->AppendSeparator(); - m_pFileMenu->Append(wxID_PRINT, "&Print..."); - m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - m_pFileMenu->Append(wxID_PREVIEW, "Print Preview"); -#ifdef CTSIM_MDI + m_pFileMenu->Append(wxID_PRINT, _T("&Print...")); + m_pFileMenu->Append(wxID_PRINT_SETUP, _T("Print &Setup...")); + m_pFileMenu->Append(wxID_PREVIEW, _T("Print Preview")); m_pFileMenu->AppendSeparator(); - m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif + m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces...")); + m_pFileMenu->Append(MAINMENU_FILE_EXIT, _T("E&xit")); + GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); - - wxMenu *view_menu = new wxMenu; - view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E"); - view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A"); - view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U"); - - wxMenu* filter_menu = new wxMenu; - filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values"); - filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square"); - filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root"); - filter_menu->Append (IFMENU_FILTER_LOG, "&Log"); - filter_menu->Append (IFMENU_FILTER_EXP, "&Exp"); - filter_menu->AppendSeparator(); -#ifdef HAVE_FFT - filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT"); - filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT"); - filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows"); - filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows"); - filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns"); - filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns"); - filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier"); - filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier"); -#else - filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier"); - filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier"); -#endif - filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order"); - filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order"); - filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude"); - filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase"); - + + m_pViewMenu = new wxMenu; + m_pViewMenu->Append(GRAPH3D_VIEW_WIREFRAME, _T("Wi&reframe\tCtrl-R"), _T(""), true); + m_pViewMenu->Append(GRAPH3D_VIEW_SMOOTH, _T("S&mooth\tCtrl-M"), _T(""), true); + m_pViewMenu->Append(GRAPH3D_VIEW_COLOR, _T("Co&lor\tCtrl-L"), _T(""), true); + m_pViewMenu->Append(GRAPH3D_VIEW_LIGHTING, _T("Li&ghting\tCtrl-G"), _T(""), true); + m_pViewMenu->AppendSeparator(); + m_pViewMenu->Append(GRAPH3D_VIEW_SCALE_MINMAX, _T("Color Scale S&et Min/Max...\tCtrl-E")); + m_pViewMenu->Append(GRAPH3D_VIEW_SCALE_AUTO, _T("Color Scale &Auto...\tCtrl-A")); + m_pViewMenu->Append(GRAPH3D_VIEW_SCALE_FULL, _T("Color F&ull Scale\tCtrl-U")); + + 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"); - + help_menu->Append(MAINMENU_HELP_CONTENTS, _T("&Contents\tF1")); + help_menu->Append(MAINMENU_HELP_ABOUT, _T("&About")); + wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(m_pFileMenu, "&File"); - menu_bar->Append(view_menu, "&View"); - menu_bar->Append(filter_menu, "Fi<er"); - menu_bar->Append(help_menu, "&Help"); - + + menu_bar->Append(m_pFileMenu, _T("&File")); + menu_bar->Append(m_pViewMenu, _T("&View")); + menu_bar->Append(help_menu, _T("&Help")); + subframe->SetMenuBar(menu_bar); - + subframe->Centre(wxBOTH); - - wxAcceleratorEntry accelEntries[10]; - accelEntries[0].Set (wxACCEL_CTRL, static_cast('O'), wxID_OPEN); - accelEntries[1].Set (wxACCEL_CTRL, static_cast('S'), wxID_SAVE); - accelEntries[2].Set (wxACCEL_CTRL, static_cast('W'), wxID_CLOSE); - accelEntries[3].Set (wxACCEL_CTRL, static_cast('H'), MAINMENU_HELP_TOPICS); - accelEntries[4].Set (wxACCEL_CTRL, static_cast('P'), MAINMENU_FILE_CREATE_PHANTOM); - accelEntries[5].Set (wxACCEL_CTRL, static_cast('F'), MAINMENU_FILE_CREATE_FILTER); - accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS); - accelEntries[7].Set (wxACCEL_CTRL, static_cast('A'), IFMENU_VIEW_SCALE_AUTO); - accelEntries[8].Set (wxACCEL_CTRL, static_cast('U'), IFMENU_VIEW_SCALE_FULL); - accelEntries[9].Set (wxACCEL_CTRL, static_cast('E'), IFMENU_VIEW_SCALE_MINMAX); - wxAcceleratorTable accelTable (10, accelEntries); + + wxAcceleratorEntry accelEntries[7]; + accelEntries[0].Set (wxACCEL_CTRL, static_cast('R'), GRAPH3D_VIEW_WIREFRAME); + 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; } + 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) @@ -508,113 +842,127 @@ 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) +Graph3dFileCanvas::Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos, + const wxSize& size, long style) + : wxGLCanvas (parent, -1, pos, size, style), m_pView(view) { - parent->Show(TRUE); - SetCurrent(); - /* Make sure server supports the vertex array extension */ +// parent->Show (true); +#if 0 + // Make sure server supports the vertex array extension char* extensions = (char *) glGetString( GL_EXTENSIONS ); if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" )) { m_pView->m_bUseVertexArrays = GL_FALSE; } +#endif } -Graph3dFileCanvas::~Graph3dFileCanvas(void) +Graph3dFileCanvas::~Graph3dFileCanvas() { - m_pView = NULL; } -void -Graph3dFileCanvas::OnDraw(wxDC& dc) +void +Graph3dFileCanvas::OnPaint (wxPaintEvent& event) { + wxPaintDC dc(this); if (m_pView) m_pView->OnDraw(& dc); } -void -Graph3dFileCanvas::OnSize(wxSizeEvent& event) + +wxSize +Graph3dFileCanvas::GetBestSize() const +{ + return wxSize (400,400); +} + +void +Graph3dFileCanvas::OnSize (wxSizeEvent& event) { #ifndef __WXMOTIF__ - if (!GetContext()) return; + // if (!GetContext()) return; #endif - - SetCurrent(); + int width, height; GetClientSize (&width, &height); Reshape (width, height); } -void +void Graph3dFileCanvas::OnChar(wxKeyEvent& event) { if (! m_pView) return; - - switch(event.KeyCode()) { - case WXK_ESCAPE: - exit(0); + + wxCommandEvent dummyEvent; + switch (event.GetKeyCode()) { case WXK_LEFT: - m_pView->m_dYRotate -= 15.0; + m_pView->m_dZRotate += 15.0; + Refresh (false); break; case WXK_RIGHT: - m_pView->m_dYRotate += 15.0; + m_pView->m_dZRotate -= 15.0; + Refresh (false); break; case WXK_UP: m_pView->m_dXRotate += 15.0; + Refresh (false); break; case WXK_DOWN: m_pView->m_dXRotate -= 15.0; + Refresh (false); + break; + case 'y': case 'Y': + m_pView->m_dYRotate += 15.0; + Refresh (false); + break; + case 't': case 'T': + m_pView->m_dYRotate -= 15.0; + Refresh (false); + break; + case 'w': case 'W': + m_pView->OnWireframe (dummyEvent); break; case 's': case 'S': - m_pView->m_bSmooth = !m_pView->m_bSmooth; - if (m_pView->m_bSmooth) { - glShadeModel(GL_SMOOTH); - } else { - glShadeModel(GL_FLAT); - } + m_pView->OnSmooth (dummyEvent); break; case 'l': case 'L': - m_pView->m_bLighting = !m_pView->m_bLighting; - if (m_pView->m_bLighting) { - glEnable(GL_LIGHTING); - } else { - glDisable(GL_LIGHTING); - } + m_pView->OnLighting (dummyEvent); + break; + case 'c': case 'C': + m_pView->OnColor (dummyEvent); break; default: - { - event.Skip(); - return; - } + event.Skip(); + return; } - - Refresh(FALSE); } void Graph3dFileCanvas::Reshape (int width, int height) { - glViewport(0, 0, (GLint)width, (GLint)height); + SetCurrent(); + glViewport (0, 0, (GLint)width, (GLint)height); + SwapBuffers(); } -void +void Graph3dFileCanvas::OnMouseEvent(wxMouseEvent& event) { static int dragging = 0; static float last_x, last_y; - + + if (! m_pView) + return; + if(event.LeftIsDown()) { - if(!dragging) { + if(! dragging) { dragging = 1; } else { - m_pView->m_dXRotate += (event.GetX() - last_x)*1.0; - m_pView->m_dYRotate += (event.GetY() - last_y)*1.0; - Refresh(FALSE); + m_pView->m_dXRotate -= (event.GetY() - last_y)*1.0; + m_pView->m_dZRotate += (event.GetX() - last_x)*1.0; + Refresh (false); } last_x = event.GetX(); last_y = event.GetY(); @@ -622,12 +970,11 @@ Graph3dFileCanvas::OnMouseEvent(wxMouseEvent& event) dragging = 0; } -void +void Graph3dFileCanvas::OnEraseBackground(wxEraseEvent& event) { // Do nothing: avoid flashing. } - - +#endif // wxUSE_GLCANVAS