X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fgraph3dview.cpp;h=526ab6480ffd3032f3cf6c510b64deff7389ed59;hp=d92912fb09a653f164d88460d4067eb86bfd8ac7;hb=d16eb37cbc73f67fc29a60645e0b1ac7fe32767e;hpb=663448e3173a19f054952806d8f8eca2fe59ec90 diff --git a/src/graph3dview.cpp b/src/graph3dview.cpp index d92912f..526ab64 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.19 2001/03/13 04:44:25 kevin Exp $ +** $Id: graph3dview.cpp,v 1.20 2001/03/18 18:08:26 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 @@ -117,40 +117,20 @@ Graph3dFileView::intensityToColor (double dIntensity, GLfloat* vecColor) // fNormalZ == Z vector for the normal vector //************************************************************************* -void -CalculateVectorNormal (GLfloat fVert1[], GLfloat fVert2[], - GLfloat fVert3[], GLfloat *fNormalX, - GLfloat *fNormalY, GLfloat *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]; - - *fNormalX = Py*Qz - Pz*Qy; - *fNormalY = Pz*Qx - Px*Qz; - *fNormalZ = Px*Qy - Py*Qx; - -} - -void -CalculateVectorNormal (GLdouble fVert1[], GLdouble fVert2[], - GLdouble fVert3[], GLdouble *fNormalX, - GLdouble *fNormalY, GLdouble *fNormalZ) +template +static void +CalculateVectorNormal (T fVert1[], T fVert2[], T fVert3[], T *fNormalX, T *fNormalY, T *fNormalZ) { - GLdouble Qx = fVert2[0] - fVert1[0]; - GLdouble Qy = fVert2[1] - fVert1[1]; - GLdouble Qz = fVert2[2] - fVert1[2]; - GLdouble Px = fVert3[0] - fVert1[0]; - GLdouble Py = fVert3[1] - fVert1[1]; - GLdouble 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) @@ -171,15 +151,16 @@ Graph3dFileView::Graph3dFileView () { m_bDoubleBuffer = true; m_bSmooth = true; - m_bLighting = true; - m_bSurface = true; - m_bLighting = true; - m_bColor = false; - m_dXRotate = -45; - m_dYRotate = 0; - m_dZRotate = -45; + m_bLighting = false; + m_bSurface = false; + m_bLighting = false; + m_bColor = true; + m_dXRotate = -180; + m_dYRotate = -210; + m_dZRotate = -195; m_bColorScaleMinSet = false; m_bColorScaleMaxSet = false; + m_bCalculatedSurfaceBackground = false; } Graph3dFileView::~Graph3dFileView() @@ -236,6 +217,9 @@ Graph3dFileView::CreateCanvas (wxFrame* parent) void Graph3dFileView::DrawSurface() { + if (! GetDocument()) + return; + if (m_bSmooth) { glShadeModel (GL_SMOOTH); } else { @@ -248,23 +232,37 @@ Graph3dFileView::DrawSurface() glDisable (GL_LIGHTING); } - if (m_bSurface) - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - else - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - - InitMaterials(); - - if (! GetDocument()) - return; - 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); - glCallList (DISPLAYLIST_SURFACE); + + InitMaterials(); + if (m_bSurface) { + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + if (! m_bColor) { + glColor3f (1.0f, 1.0f, 1.0f); + glCallList (DISPLAYLIST_NO_COLOR); + } else + glCallList (DISPLAYLIST_COLOR); + } + else { + 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); + + glColor3f (0.0f, 0.0f, 0.0f); + glPolygonOffset (0.0f, 0.0f); + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + glCallList (DISPLAYLIST_NO_COLOR); + } + } void @@ -279,7 +277,7 @@ Graph3dFileView::CreateDisplayList() if (nx == 0 || ny == 0 || ! v) return; - glNewList (DISPLAYLIST_SURFACE, GL_COMPILE); + glNewList (DISPLAYLIST_COLOR, GL_COMPILE); double dMin = m_dColorScaleMin; double dIntensityScale = m_dColorScaleMax - m_dColorScaleMin; @@ -290,9 +288,6 @@ Graph3dFileView::CreateDisplayList() dXOffset = 0; dYOffset = 0; - if (! m_bColor) - glColor3f (1.0f, 1.0f, 1.0f); - double dXPos = -dXOffset; for (unsigned ix = 0; ix < nx - 1; ix++, dXPos++) { double dYPos = -dYOffset; @@ -301,7 +296,7 @@ Graph3dFileView::CreateDisplayList() 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]); + CalculateVectorNormal (p1, p2, p3, &n1[0], &n1[1], &n1[2]); double dIntensity1, dIntensity2; if (m_bColor) { @@ -315,10 +310,8 @@ Graph3dFileView::CreateDisplayList() } glVertex3dv (p1); glNormal3dv (n1); - if (m_bColor) { intensityToColor (dIntensity2, vecColor); glColor3fv (vecColor); - } glVertex3dv (p2); glNormal3dv (n1); double lastP[3]; @@ -328,19 +321,43 @@ 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]; - if (m_bColor) { dIntensity1 = (v[ix][iy] - dMin) / dIntensityScale; dIntensity2 = (v[ix+1][iy] - dMin) / dIntensityScale; - } - if (m_bColor) { 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 @@ -349,6 +366,13 @@ Graph3dFileView::CreateDisplayList() } +void +Graph3dFileView::calculateSurfaceBackground () +{ + if (m_bCalculatedSurfaceBackground) + return; +} + void Graph3dFileView::OnProperties (wxCommandEvent& event) { @@ -380,7 +404,7 @@ Graph3dFileView::OnColor (wxCommandEvent& event) { m_bColor = ! m_bColor; m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor); - OnUpdate (this, NULL); + m_pCanvas->Refresh(); } void @@ -434,8 +458,8 @@ Graph3dFileView::InitMaterials() #if 1 static float ambient[] = {0.1f, 0.1f, 0.1f, 1.0f}; static float diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; - static float position0[] = {-nx/2, -ny/2, -ny/2, 0.0f, 0.0f}; - static float position1[] = {-nx/2, -ny/2, ny/2, 0.0f}; + static float position0[] = {-nx/2, -ny/2, ny/2, 0.0f, 0.0f}; + static float position1[] = {-nx/2, -ny/2, -ny/2, 0.0f}; static float ambient1[] = {0.5f, 0.5f, 0.5f, 1.0f}; static float diffuse1[] = {1.0f, 1.0f, 1.0f, 1.0f}; // static float position0[] = {0.0f, 0.0f, 20.0f, 0.0f}; @@ -600,7 +624,6 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) if (! m_bColorScaleMaxSet) m_dColorScaleMax = max; } - double dRadius = maxValue (nx, ny) * SQRT2 / 2; glMatrixMode(GL_PROJECTION); glLoadIdentity();