** This is part of the CTSim program
** Copyright (c) 1983-2001 Kevin Rosenberg
**
-** $Id: graph3dview.cpp,v 1.9 2001/02/03 18:43:43 kevin Exp $
+** $Id: graph3dview.cpp,v 1.12 2001/02/08 22:38:23 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
#include <sstream_subst>
#endif
-// 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)
-static void
-intensityToColor (double dIntensity, float vecColor[3])
+void
+Graph3dFileView::intensityToColor (double dIntensity, GLfloat* vecColor)
{
- double dRange = dIntensity * 5;
- int iRange = static_cast<int>(floor (dRange));
- double dFrac = dRange - iRange;
+ if (dIntensity < 0 || dIntensity > 1) {
+ vecColor[0] = vecColor[1] = vecColor[2] = 1;
+ return;
+ }
+
+ float fRange = dIntensity * 5;
+ int iRange = static_cast<int>(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 - dFrac; vecColor[1] = 0; vecColor[2] = 1;
+ vecColor[0] = 1.0f - fFrac; vecColor[1] = 0.0f; vecColor[2] = 1.0f;
break;
case 1:
- vecColor[0] = 0; vecColor[1] = dFrac; vecColor[2] = 1;
+ vecColor[0] = 0.0f; vecColor[1] = fFrac; vecColor[2] = 1.0f;
break;
case 2:
- vecColor[0] = 0; vecColor[1] = 1; vecColor[2] = 1 - dFrac;
+ vecColor[0] = 0.0f; vecColor[1] = 1.0f; vecColor[2] = 1.0f - fFrac;
break;
case 3:
- vecColor[0] = dFrac; vecColor[1] = 1; vecColor[2] = 0;
+ vecColor[0] = fFrac; vecColor[1] = 1.0f; vecColor[2] = 0.0f;
break;
case 4:
- vecColor[0] = 0; vecColor[1] = 1 - dFrac; vecColor[2] = 0;
+ vecColor[0] = 1.0f; vecColor[1] = 1.0f - fFrac; vecColor[2] = 0.0f;
break;
case 5:
- vecColor[0] = 1; vecColor[1] = 0; vecColor[2] = 0;
+ vecColor[0] = 1.0f; vecColor[1] = 0.0f; vecColor[2] = 0.0f;
break;
}
}
// fNormalZ == Z vector for the normal vector
//*************************************************************************
-
-GLvoid CalculateVectorNormal (GLfloat fVert1[], GLfloat fVert2[],
- GLfloat fVert3[], GLfloat *fNormalX,
- GLfloat *fNormalY, GLfloat *fNormalZ)
+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];
}
+void
+CalculateVectorNormal (GLdouble fVert1[], GLdouble fVert2[],
+ GLdouble fVert3[], GLdouble *fNormalX,
+ GLdouble *fNormalY, GLdouble *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];
+
+ *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(GRAPH3D_VIEW_COLOR, Graph3dFileView::OnColor)
EVT_MENU(GRAPH3D_VIEW_SMOOTH, Graph3dFileView::OnSmooth)
EVT_MENU(GRAPH3D_VIEW_SURFACE, Graph3dFileView::OnSurface)
+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_pViewMenu(NULL)
{
- m_bUseVertexArrays = false;
m_bDoubleBuffer = true;
m_bSmooth = true;
m_bLighting = true;
m_dXRotate = -45;
m_dYRotate = 0;
m_dZRotate = -45;
+ m_bColorScaleMinSet = false;
+ m_bColorScaleMaxSet = false;
}
Graph3dFileView::~Graph3dFileView()
{
GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
- GetDocumentManager()->ActivateView(this, FALSE, TRUE);
+ GetDocumentManager()->ActivateView(this, false, true);
}
bool
m_pFrame->SetTitle("Graph3dFileView");
m_pCanvas = CreateCanvas (m_pFrame);
- m_pFrame->Show(TRUE);
+ m_pFrame->Show (true);
m_pCanvas->SetCurrent();
InitGL();
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();
}
-
void
Graph3dFileView::DrawSurface()
{
-#ifdef GL_EXT_vertex_array
- if (m_bUseVertexArrays) {
- // glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, nVertices );
+ if (m_bSmooth) {
+ glShadeModel (GL_SMOOTH);
+ } else {
+ glShadeModel (GL_FLAT);
}
- else {
-#endif
- double edge = 1.;
- unsigned int nx = GetDocument()->nx();
- unsigned int ny = GetDocument()->ny();
- const ImageFileArrayConst v = GetDocument()->getArray();
- if (nx == 0 || ny == 0 || ! v)
- return;
-
- InitMaterials();
-
- glRotatef( m_dXRotate, 1.0, 0.0, 0.0 );
- glRotatef( m_dZRotate, 0.0, 1.0, 0.0 );
- glRotatef( m_dYRotate, 0.0, 0.0, 1.0 );
- glTranslatef (-static_cast<double>(nx) / 2., 0., -static_cast<double>(ny) / 2.);
-
-
- if (m_bSmooth) {
- glShadeModel (GL_SMOOTH);
- } else {
- glShadeModel (GL_FLAT);
+
+ if (m_bLighting) {
+ glEnable (GL_LIGHTING);
+ } else {
+ 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<double>(nx - 1) / 2, 0.0, -static_cast<double>(ny - 1) / 2);
+ glCallList (DISPLAYLIST_SURFACE);
+}
+
+void
+Graph3dFileView::CreateDisplayList()
+{
+ if (! GetDocument())
+ return;
+
+ unsigned int nx = GetDocument()->nx();
+ unsigned int ny = GetDocument()->ny();
+ const ImageFileArrayConst v = GetDocument()->getArray();
+ if (nx == 0 || ny == 0 || ! v)
+ return;
+
+ glNewList (DISPLAYLIST_SURFACE, 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<double>(nx) - 1) / 2.;
+ double dYOffset = -(static_cast<double>(ny) - 1) / 2.;
+ 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;
+ glBegin(GL_QUAD_STRIP);
+ double p1[3], p2[3], p3[3];
+ double 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;
+ dIntensity2 = (v[ix+1][0] - dMin) / dIntensityScale;
}
-
- if (m_bLighting) {
- glEnable (GL_LIGHTING);
- } else {
- glDisable (GL_LIGHTING);
+ float vecColor[3];
+ if (m_bColor) {
+ intensityToColor (dIntensity1, vecColor);
+ glColor3fv (vecColor);
}
-
- double dMin = v[0][0];
- double dMax = dMin;
- unsigned int ix;
- for (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];
-
- double dIntensityScale = dMax - dMin;
- double actOffset = dMin;
- double actScale = 0.3 * sqrt(nx*nx+ny*ny) / (dMax - dMin);
-
- // glNewList(opnListNum++,GL_COMPILE);
- if (! m_bColor)
- glColor3f (1.0, 1.0, 1.0);
-
- glDisable (GL_CULL_FACE);
- for (ix = 0; ix < nx-1; ix++) {
- for (unsigned int iy = 0; iy < ny-1; iy++) {
-
- float p1[3], p2[3], p3[3], p4[3];
- float n1[3], n2[3], n3[3], n4[3];
- if (m_bSurface)
- glBegin(GL_QUADS);
- else
- glBegin(GL_LINE_LOOP);
-
- 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;
- p3[0] = ix+1; p3[1] = actScale * (v[ix+1][iy+1] + actOffset); p3[2] = iy+1;
- p4[0] = ix; p4[1] = actScale * (v[ix][iy+1] + actOffset); p4[2] = iy+1;
-
- // n1[0] = -(p2[1] - p1[1])*(p3[2] - p1[2]) + (p2[2] - p1[2])*(p3[1] - p2[1]);
- // n1[1] = -(p2[2] - p1[2])*(p3[0] - p2[0]) + (p2[0] - p1[0])*(p3[2] - p2[2]);
- // n1[2] = -(p2[0] - p1[0])*(p3[1] - p2[1]) + (p2[1] - p1[1])*(p3[0] - p2[0]);
- CalculateVectorNormal (p1, p2, p4, &n1[0], &n1[1], &n1[2]);
- //CalculateVectorNormal (p2, p1, p3, &n2[0], &n2[1], &n2[2])
- //CalculateVectorNormal (p3, p2, p4, &n1[0], &n1[1], &n1[2])
- double dIntensity1, dIntensity2, dIntensity3, dIntensity4;
- if (m_bColor) {
- dIntensity1 = (v[ix][iy] - dMin) / dIntensityScale;
- dIntensity2 = (v[ix+1][iy] - dMin) / dIntensityScale;
- dIntensity3 = (v[ix+1][iy+1] - dMin) / dIntensityScale;
- dIntensity4 = (v[ix][iy+1] - dMin) / dIntensityScale;
- }
- float vecColor[3];
- if (m_bColor) {
- intensityToColor (dIntensity1, vecColor);
- glColor3fv (vecColor);
- }
- glVertex3fv (p1); glNormal3fv (n1);
- if (m_bColor) {
- intensityToColor (dIntensity2, vecColor);
- glColor3fv (vecColor);
- }
- glVertex3fv (p2); glNormal3fv (n1);
- if (m_bColor) {
- intensityToColor (dIntensity3, vecColor);
- glColor3fv (vecColor);
- }
- glVertex3fv (p3); glNormal3fv (n1);
- if (m_bColor) {
- intensityToColor (dIntensity4, vecColor);
- glColor3fv (vecColor);
- }
- glVertex3fv (p4); glNormal3fv (n1);
- glEnd();
- }
-
- }
- glEndList();
-
-#ifdef GL_EXT_vertex_array
+ glVertex3dv (p1);
+ glNormal3dv (n1);
+ if (m_bColor) {
+ intensityToColor (dIntensity2, vecColor);
+ glColor3fv (vecColor);
+ }
+ 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;
+ }
+ 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
}
-#endif
+ glEndList();
}
{
m_bColor = ! m_bColor;
m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor);
- m_pCanvas->Refresh();
+ OnUpdate (this, NULL);
}
void
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;
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
- DrawSurface();
-
+ DrawSurface();
glPopMatrix();
glFlush();
}
int ny = GetDocument()->ny();
#if 1
- static float ambient[] = {0.1, 0.1, 0.1, 1.0};
- static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
- static float position0[] = {-nx/2, -ny/2, -ny/2, 0, 0.0};
- static float position1[] = {-nx/2, -ny/2, ny/2, 0.0};
- static float ambient1[] = {0.5, 0.5, 0.5, 1.0};
- static float diffuse1[] = {1.0, 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[] = {5.0};
- static float front_mat_specular[] = {0.1, 0.1, 0.1, 1.0};
- static float front_mat_diffuse[] = {0.3, 0.3, 0.3, 1.0};
+ 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 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};
+ // static float position1[] = {0.0f, 0.0f, -20.0f, 0.0f};
+ static float front_mat_shininess[] = {5.0f};
+ static float front_mat_specular[] = {0.1f, 0.1f, 0.1f, 1.0f};
+ static float front_mat_diffuse[] = {0.3f, 0.3f, 0.3f, 1.0f};
/*
- static float back_mat_shininess[] = {60.0};
- static float back_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
- static float back_mat_diffuse[] = {1.0, 1.0, 1.0, 1.0};
+ static float back_mat_shininess[] = {60.0f};
+ static float back_mat_specular[] = {0.2f, 0.2f, 0.2f, 1.0f};
+ static float back_mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
*/
- static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
+ static float lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
static float lmodel_twoside[] = {GL_FALSE};
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
// glColorMaterial (GL_FRONT_AND_BACK, GL_SPECULAR);
glEnable(GL_COLOR_MATERIAL);
#else
- GLfloat impLPos[] = {1.0, 1.0, 1.0, 0.0};
+ GLfloat impLPos[] = {1.0f, 1.0f, 1.0f, 0.0f};
- GLfloat defaultLightAmb [] = {.2, .2, .2, 1.0};
- GLfloat defaultLightDiff [] = {.2, .2, .2, 1.0};
- GLfloat defaultLightSpec [] = { .3, .3, .3, 1.0};
+ GLfloat defaultLightAmb [] = {.2f, .2f, .2f, 1.0f};
+ GLfloat defaultLightDiff [] = {.2f, .2f, .2f, 1.0f};
+ GLfloat defaultLightSpec [] = { .3f, .3f, .3f, 1.0f};
- GLfloat defaultGlobalAmb [] = {.3, .3, .3, 1.0};
- GLfloat defaultGlobalDiff[] = {.3, .3, .3, 1.0};
+ GLfloat defaultGlobalAmb [] = {.3f, .3f, .3f, 1.0f};
+ GLfloat defaultGlobalDiff[] = {.3f, .3f, .3f, 1.0f};
- GLfloat defaultMatShine[] = { 30.0 };
- GLfloat defaultMatSpec[] = { .4, .4, .4, 1.0};
- GLfloat defaultMatAmb[] = { .3, .3, .3, 1.0};
- GLfloat defaultMatDiff[] = { .5, .5, .5, 1.0};
+ 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[] = { .33, .22, .03, 1.0};
- GLfloat brassMatDiff[] = { .78, .57, .11, 1.0};
- GLfloat brassMatSpec[] = { .99, .91, .81, 1.0};
- GLfloat brassMatShine[] = { 27.8 };
+ 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[] = { .021, .1745 , .021, 1.0};
- GLfloat emeraldMatDiff[] = { .075, .6142 , .075, 1.0 };
- GLfloat emeraldMatSpec[] = { .633, .7278 , .633, 1.0 };
- GLfloat emeraldMatShine[] = { 76.8 };
+ 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[] = { .02, .02 , .02, 1.0 };
- GLfloat slateMatDiff[] = { .02, .01 , .01, 1.0 };
- GLfloat slateMatSpec[] = { .4, .4 , .4 , 1.0 };
- GLfloat slateMatShine[] = { .768 };
+ 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;
// glutInitWindowPosition (100, 100);
// glutCreateWindow ("- imp3D graphics -" );
- glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel (GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
void
Graph3dFileView::InitGL ()
{
- glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
- glEnable(GL_DEPTH_TEST);
+ glDisable (GL_CULL_FACE);
+ glEnable (GL_DEPTH_TEST);
}
void
Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
{
- int nVertices = GetDocument()->m_nVertices;
- glTripleFloat* pVertices = GetDocument()->m_pVertices;
- glTripleFloat* pNormals = GetDocument()->m_pNormals;
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
if (! GetDocument())
return;
+
int nx = GetDocument()->nx();
int ny = GetDocument()->ny();
- int maxDim = maxValue<int> (nx, ny);
+ const ImageFileArrayConst v = GetDocument()->getArray();
+ if (v != NULL && nx != 0 && ny != 0) {
+ 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;
+ }
+ m_dGraphMin = min;
+ m_dGraphMax = max;
+ if (! m_bColorScaleMinSet)
+ m_dColorScaleMin = min;
+ if (! m_bColorScaleMaxSet)
+ m_dColorScaleMax = max;
+ }
+
+ double dRadius = maxValue<int> (nx, ny) * SQRT2 / 2;
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho (-dRadius, dRadius, -dRadius, dRadius, dRadius*5, -dRadius*5);
- glOrtho (-maxDim * 0.71, maxDim * 0.71, -maxDim * 0.71, maxDim * 0.71, maxDim * 0.71, -maxDim * 0.71);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+#if 1
GLfloat eyep[3], lookp[3], up[3];
eyep[0] = -nx/2; eyep[1] = 0; eyep[2] = -ny/2;
- lookp[1] = 0; lookp[1] = 0, lookp[2] = 0;
+ 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]);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
-
-#ifdef GL_EXT_vertex_array
- if (m_bUseVertexArrays) {
- // glVertexPointerEXT( 3, GL_FLOAT, 0, nVertices, pVertices );
- // glNormalPointerEXT( GL_FLOAT, 0, nVertices, pNormals );
- glEnable( GL_VERTEX_ARRAY_EXT );
- glEnable( GL_NORMAL_ARRAY_EXT );
- }
+ 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->Refresh();
}
Activate (false);
if (m_pCanvas) {
- // m_pCanvas->Show(false);
m_pCanvas->setView(NULL);
m_pCanvas = NULL;
}
SetFrame(NULL);
if (deleteWindow) {
- // m_pFrame->Show(false);
delete m_pFrame;
m_pFrame = NULL;
- // if (GetDocument() && GetDocument()->getBadFileOpen())
- // ::wxYield(); // wxWindows bug workaround
}
return true;
}
+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, dMax;
+ 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(), "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
GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
m_pViewMenu = new wxMenu;
- m_pViewMenu->Append(GRAPH3D_VIEW_SURFACE, "&Surface\tCtrl-U", "", true);
- m_pViewMenu->Append(GRAPH3D_VIEW_SMOOTH, "&Smooth\tCtrl-M", "", true);
- m_pViewMenu->Append(GRAPH3D_VIEW_COLOR, "&Color\tCtrl-R", "", true);
- m_pViewMenu->Append(GRAPH3D_VIEW_LIGHTING, "&Lighting\tCtrl-L", "", true);
+ m_pViewMenu->Append(GRAPH3D_VIEW_SURFACE, "Su&rface\tCtrl-R", "", true);
+ m_pViewMenu->Append(GRAPH3D_VIEW_SMOOTH, "S&mooth\tCtrl-M", "", true);
+ m_pViewMenu->Append(GRAPH3D_VIEW_COLOR, "Co&lor\tCtrl-L", "", true);
+ m_pViewMenu->Append(GRAPH3D_VIEW_LIGHTING, "Li&ghting\tCtrl-G", "", true);
+ m_pViewMenu->AppendSeparator();
+ m_pViewMenu->Append(GRAPH3D_VIEW_SCALE_MINMAX, "Color Scale S&et Min/Max...\tCtrl-E");
+ m_pViewMenu->Append(GRAPH3D_VIEW_SCALE_AUTO, "Color Scale &Auto...\tCtrl-A");
+ m_pViewMenu->Append(GRAPH3D_VIEW_SCALE_FULL, "Color F&ull Scale\tCtrl-U");
+
wxMenu *help_menu = new wxMenu;
help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
subframe->Centre(wxBOTH);
- wxAcceleratorEntry accelEntries[10];
+ wxAcceleratorEntry accelEntries[12];
accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
- accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('U'), GRAPH3D_VIEW_SURFACE);
- accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('R'), GRAPH3D_VIEW_COLOR);
- accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), GRAPH3D_VIEW_LIGHTING);
+ accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('R'), GRAPH3D_VIEW_SURFACE);
+ accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('L'), GRAPH3D_VIEW_COLOR);
+ accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('G'), GRAPH3D_VIEW_LIGHTING);
accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('M'), GRAPH3D_VIEW_SMOOTH);
- wxAcceleratorTable accelTable (9, accelEntries);
+ accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('E'), GRAPH3D_VIEW_SCALE_MINMAX);
+ accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('A'), GRAPH3D_VIEW_SCALE_AUTO);
+ accelEntries[11].Set (wxACCEL_CTRL, static_cast<int>('U'), GRAPH3D_VIEW_SCALE_FULL);
+ wxAcceleratorTable accelTable (12, accelEntries);
subframe->SetAcceleratorTable (accelTable);
return subframe;
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);
+ parent->Show (true);
SetCurrent();
- /* Make sure server supports the vertex array extension */
+#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)
+Graph3dFileCanvas::OnDraw (wxDC& dc)
{
if (m_pView)
m_pView->OnDraw(& dc);
}
void
-Graph3dFileCanvas::OnSize(wxSizeEvent& event)
+Graph3dFileCanvas::OnSize (wxSizeEvent& event)
{
#ifndef __WXMOTIF__
if (!GetContext()) return;
wxCommandEvent dummyEvent;
switch (event.KeyCode()) {
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 'z': case 'Z':
- m_pView->m_dZRotate += 15.0;
+ case 'y': case 'Y':
+ m_pView->m_dYRotate += 15.0;
+ Refresh (false);
break;
- case 'x': case 'X':
- m_pView->m_dZRotate -= 15.0;
+ case 't': case 'T':
+ m_pView->m_dYRotate -= 15.0;
+ Refresh (false);
+ break;
+ case 'r': case 'R':
+ m_pView->OnSurface (dummyEvent);
break;
case 's': case 'S':
m_pView->OnSmooth (dummyEvent);
m_pView->OnColor (dummyEvent);
break;
default:
- {
- event.Skip();
- return;
- }
+ event.Skip();
+ return;
}
-
- Refresh (false);
}
void
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();
void
Graph3dFileCanvas::OnEraseBackground(wxEraseEvent& event)
{
-// wxGLCanvas::OnEraseBackground(event); // Do nothing: avoid flashing.
+ // Do nothing: avoid flashing.
}
-
-
#endif // wxUSE_GLCANVAS