r477: *** empty log message ***
[ctsim.git] / src / graph3dview.cpp
index fdcb82369e391b49254c8f030a2fcd8bb56f203d..eb5cbf4a8afd8a72dfa5c9c989e3e158b7fae250 100644 (file)
@@ -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: graph3dview.cpp,v 1.4 2001/01/31 01:01:22 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,7 +25,6 @@
 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************/
 
-
 #ifdef __GNUG__
 #pragma implementation
 #pragma interface
@@ -42,6 +41,8 @@
 #include "wx/wx.h"
 #endif
 
+#if wxUSE_GLCANVAS
+
 #if !wxUSE_GLCANVAS
 #error Please set wxUSE_GLCANVAS to 1 in setup.h.
 #endif
@@ -118,7 +119,8 @@ Graph3dFileView::Graph3dFileView ()
   m_bDoubleBuffer = GL_TRUE;
   m_bSmooth = GL_TRUE;
   m_bLighting = GL_TRUE;
-  
+  m_dXRotate = 0;
+  m_dYRotate = 0;
 }
 
 Graph3dFileView::~Graph3dFileView()
@@ -158,7 +160,7 @@ Graph3dFileView::CreateCanvas (wxFrame* parent)
 {
   Graph3dFileCanvas* pCanvas;
   int width, height;
-  parent->GetClientSize(&width, &height);
+  parent->GetClientSize (&width, &height);
   
 #ifdef __WXMSW__
   int *gl_attrib = NULL;
@@ -175,7 +177,6 @@ Graph3dFileView::CreateCanvas (wxFrame* parent)
   
   pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(0, 0), wxSize(200, 200), 0, gl_attrib);
   
-  pCanvas->SetScrollbars(20, 20, 50, 50);
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
   
@@ -187,18 +188,67 @@ Graph3dFileView::CreateCanvas (wxFrame* parent)
 void
 Graph3dFileView::DrawSurface()
 {
+  int nVertices = GetDocument()->m_nVertices;
+  glTripleFloat* pVertices = GetDocument()->m_pVertices;
+  glTripleFloat* pNormals = GetDocument()->m_pNormals;
+
 #ifdef GL_EXT_vertex_array
   if (m_bUseVertexArrays) {
-    glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, m_nVerts );
+    glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, nVertices );
   }
   else {
 #endif
-    glBegin( GL_TRIANGLE_STRIP );
-    for (GLint i = 0;i < m_nVerts; i++) {
-      //         glNormal3fv( &m_vecNorms[i] );
-      //         glVertex3fv( &m_vecVerts[i] );
-    }
-    glEnd();
+       double edge = 1.;       
+       unsigned int nx = GetDocument()->m_nx;
+  unsigned int ny = GetDocument()->m_ny;
+  const ImageFileArray v = GetDocument()->m_array;
+  if (nx == 0 || ny == 0 || ! v)
+    return;
+
+  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 actOffset = dMin;
+  double actScale = 0.3 * sqrt(nx*nx+ny*ny) / (dMax - dMin);
+
+  glRotatef( m_dYRotate, 0.0, 0.0, 1.0 );
+  glRotatef( m_dXRotate, 1.0, 0.0, 0.0 );
+  glTranslatef (-static_cast<double>(nx) / 2, -static_cast<double>(ny) / 2, 0);
+
+//     glNewList(opnListNum++,GL_COMPILE);             
+               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];
+                               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;
+                               p4[0] = ix;  p4[1] = actScale * (v[ix][iy+1] + actOffset); p4[2] = iy;
+                                                                                       
+                               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]);
+                                       
+                               glVertex3fv(p1); glNormal3fv(n1);                                       
+                               glVertex3fv(p2); glNormal3fv(n1);                                       
+                               glVertex3fv(p3); glNormal3fv(n1);                                       
+                               glVertex3fv(p4); glNormal3fv(n1);                                                                                                                                               
+        glEnd();                               
+                       }                       
+                       
+               }
+       glEndList();
+               
 #ifdef GL_EXT_vertex_array
   }
 #endif
@@ -208,33 +258,10 @@ Graph3dFileView::DrawSurface()
 void
 Graph3dFileView::OnProperties (wxCommandEvent& event)
 {
-  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: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
-    if (rIF.isComplex()) {
-      rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
-      os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
-    }
-    if (rIF.nLabels() > 0) {
-      rIF.printLabelsBrief (os);
-    }
     *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
     wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
     dialogMsg.ShowModal();
-  }
 }
 
 
@@ -256,9 +283,6 @@ 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();
@@ -316,31 +340,25 @@ Graph3dFileView::InitGL ()
   
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
-  glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );
-  
+  glOrtho (-300, 300, -300, 300, 200, -200);
   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
 }
 
 void 
 Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 {
+  int nVertices = GetDocument()->m_nVertices;
+  glTripleFloat* pVertices = GetDocument()->m_pVertices;
+  glTripleFloat* pNormals = GetDocument()->m_pNormals;
+
+#if 0    
   const ImageFile& rIF = GetDocument()->getImageFile();
   ImageFileArrayConst v = rIF.getArray();
   int nx = rIF.nx();
   int ny = rIF.ny();
   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++) {
@@ -360,9 +378,17 @@ Graph3dFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
     m_pFrame->SetClientSize (xSize, ySize);
     m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
     m_pCanvas->SetBackgroundColour(*wxWHITE);
-#endif
   } 
+#endif
   
+#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 );
+  }
+#endif
   if (m_pCanvas)
     m_pCanvas->Refresh();
 }
@@ -416,11 +442,9 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
   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->AppendSeparator();
   m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
-  m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
   
   m_pFileMenu->AppendSeparator();
   m_pFileMenu->Append(wxID_PRINT, "&Print...");
@@ -433,36 +457,6 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
   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");
-  
   wxMenu *help_menu = new wxMenu;
   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
@@ -471,8 +465,6 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
   wxMenuBar *menu_bar = new wxMenuBar;
   
   menu_bar->Append(m_pFileMenu, "&File");
-  menu_bar->Append(view_menu, "&View");
-  menu_bar->Append(filter_menu, "Fi&lter");
   menu_bar->Append(help_menu, "&Help");
   
   subframe->SetMenuBar(menu_bar);
@@ -555,8 +547,6 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event)
     return;
   
   switch(event.KeyCode()) {
-  case WXK_ESCAPE:
-    exit(0);
   case WXK_LEFT:
        m_pView->m_dYRotate -= 15.0;
     break;
@@ -592,13 +582,13 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event)
     }
   }
   
-  Refresh(FALSE);
+  Refresh (false);
 }
 
 void
 Graph3dFileCanvas::Reshape (int width, int height)
 {
-  glViewport(0, 0, (GLint)width, (GLint)height);
+  glViewport (0, 0, (GLint)width, (GLint)height);
 }
 
 
@@ -631,3 +621,4 @@ Graph3dFileCanvas::OnEraseBackground(wxEraseEvent& event)
 
 
 
+#endif // wxUSE_GLCANVAS