r3162: *** empty log message ***
[ctsim.git] / src / graph3dview.cpp
index 8855cdade69acebd39f0de729b63c5ea8c952bd1..9c9b8fa699411e71228a3d6ad68c90d40d69a2dd 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: graph3dview.cpp,v 1.23 2001/09/24 10:05:01 kevin Exp $
+**  $Id: graph3dview.cpp,v 1.31 2002/10/24 21:05:28 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
@@ -65,7 +65,7 @@
 #include <sstream_subst>
 #endif
 
-void 
+inline void 
 Graph3dFileView::intensityToColor (double dIntensity, GLfloat* vecColor)
 {
   if (dIntensity < 0 || dIntensity > 1) {
@@ -147,20 +147,14 @@ EVT_MENU(GRAPH3D_VIEW_SCALE_FULL, Graph3dFileView::OnScaleFull)
 END_EVENT_TABLE()
 
 Graph3dFileView::Graph3dFileView ()
-  : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pCanvas(NULL), m_pFrame(NULL)
-{
-  m_bDoubleBuffer = true;
-  m_bSmooth = true;
-  m_bLighting = true;
-  m_bWireframe = false;
-  m_bLighting = true;
-  m_bColor = true;
-  m_dXRotate = -180;
-  m_dYRotate = -210;
-  m_dZRotate = -195;
-  m_bColorScaleMinSet = false;
-  m_bColorScaleMaxSet = false;
-}
+  : 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(true), m_bColor(true), m_bUseVertexArrays(false),
+    m_bColorScaleMinSet(false), m_bColorScaleMaxSet(false),
+    m_pFrame(NULL)
+{}
+
 
 Graph3dFileView::~Graph3dFileView()
 {
@@ -172,20 +166,17 @@ bool
 Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
 {
   m_pFrame = CreateChildFrame(doc, this);
-  
-  int width, height;
-  m_pFrame->GetClientSize (&width, &height);
-  m_pFrame->SetTitle("Graph3dFileView");
   m_pCanvas = CreateCanvas (m_pFrame);
-  
-  m_pFrame->Show (true);
+
+  m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
+  SetFrame (m_pFrame);
+  m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
+  m_pFrame->SetTitle("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_pFrame->SetFocus();
   m_pFrame->Show(true);
   Activate(true);
@@ -201,10 +192,8 @@ Graph3dFileCanvas*
 Graph3dFileView::CreateCanvas (wxFrame* parent)
 {
   Graph3dFileCanvas* pCanvas;
-  int width, height;
-  parent->GetClientSize (&width, &height);
   
-  pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(0, 0), wxSize(200, 200), 0);
+  pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
   
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
@@ -287,7 +276,8 @@ Graph3dFileView::CreateDisplayList()
   dYOffset = 0;
 
   double dXPos = -dXOffset;
-  for (unsigned ix = 0; ix < nx - 1; ix++, dXPos++) {
+  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]; 
@@ -296,7 +286,7 @@ Graph3dFileView::CreateDisplayList()
     p3[0] = dXPos; p3[1] = actScale * (v[ix][1] + actOffset); p3[2] = dYPos + 1;
     CalculateVectorNormal<double> (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;
@@ -306,12 +296,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++) {       
@@ -319,14 +310,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
   }
@@ -335,7 +330,7 @@ Graph3dFileView::CreateDisplayList()
 
   glNewList (DISPLAYLIST_NO_COLOR, GL_COMPILE);
   dXPos = -dXOffset;
-  for (unsigned int ix = 0; ix < nx - 1; ix++, dXPos++) {
+  for (ix = 0; ix < nx - 1; ix++, dXPos++) {
     double dYPos = -dYOffset;
     glBegin(GL_QUAD_STRIP);
     double p1[3], p2[3], p3[3], n1[3]; 
@@ -369,7 +364,8 @@ Graph3dFileView::OnProperties (wxCommandEvent& event)
 {
   std::ostringstream os;
   *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
-  wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
+  wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), 
+                            "Imagefile Properties", wxOK | wxICON_INFORMATION);
   dialogMsg.ShowModal();
 }
 
@@ -378,7 +374,6 @@ Graph3dFileView::OnLighting (wxCommandEvent& event)
 {
   m_bLighting = ! m_bLighting;
   m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting);
-  
   m_pCanvas->Refresh();
 }
 
@@ -411,19 +406,18 @@ Graph3dFileView::OnSmooth (wxCommandEvent& event)
 void 
 Graph3dFileView::OnDraw (wxDC* dc)
 {
-  if (! m_pCanvas)
-    return;
-  m_pCanvas->SetCurrent();
+  if (m_pCanvas) {
+    m_pCanvas->SetCurrent();
+    Draw();
+    m_pCanvas->SwapBuffers();
+  }
 
-#ifndef __WXMOTIF__
-  //  if (! m_pCanvas->GetContext()) return;
-#endif
-  
-  Draw();
-  std::ostringstream os;
-  os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate << ", Zangle=" << m_dZRotate;
-  m_pStatusBar->SetStatusText (os.str().c_str());
-  m_pCanvas->SwapBuffers();
+  if (m_pStatusBar) {
+    std::ostringstream os;
+    os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate 
+       << ", Zangle=" << m_dZRotate;
+    m_pStatusBar->SetStatusText (os.str().c_str());
+  }
 }
 
 
@@ -693,7 +687,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++)
@@ -737,15 +731,19 @@ 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, "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, "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");
@@ -808,9 +806,10 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
 
 
 
+
 BEGIN_EVENT_TABLE(Graph3dFileCanvas, wxGLCanvas)
+EVT_PAINT(Graph3dFileCanvas::OnDraw)
 EVT_SIZE(Graph3dFileCanvas::OnSize)
-EVT_PAINT(Graph3dFileCanvas::OnPaint)
 EVT_CHAR(Graph3dFileCanvas::OnChar)
 EVT_MOUSE_EVENTS(Graph3dFileCanvas::OnMouseEvent)
 EVT_ERASE_BACKGROUND(Graph3dFileCanvas::OnEraseBackground)
@@ -847,6 +846,13 @@ Graph3dFileCanvas::OnDraw (wxDC& dc)
     m_pView->OnDraw(& dc);
 }
 
+
+wxSize
+Graph3dFileCanvas::GetBestSize() const
+{
+  return wxSize (400,400);
+}
+
 void 
 Graph3dFileCanvas::OnSize (wxSizeEvent& event)
 {