Changeset 189:c6a94970d7b8


Ignore:
Timestamp:
09/24/2012 04:28:14 PM (6 years ago)
Author:
Dmitry Fedorov <fedorov@…>
Branch:
default
Phase:
public
Message:

new axis, improved reading of gobjects, supporting default view

Location:
bioView3D/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • bioView3D/src/glwidget.cpp

    r188 r189  
    6868: QGLWidget(parent)
    6969{
    70   object_axis = 0;
    7170  gl_gobjects = 0;
    7271  show_axis = true;
     
    166165GLWidget::~GLWidget() {
    167166  makeCurrent();
    168   glDeleteLists(object_axis, 1);
    169167}
    170168
     
    180178}
    181179
    182 void GLWidget::setGLAxisColor( const QColor &c ) {
    183   color_axis = c;
    184   object_axis = makeAxis();
    185   update();
    186 }
    187 
    188180void GLWidget::setGLColors( const QColor &bg, const QColor &ax ) {
    189181  color_background = bg;
    190182  color_axis = ax;
    191183  qglClearColor( color_background );
    192   object_axis = makeAxis();
    193184  update();
    194185}
     
    476467void GLWidget::initializeGL() {
    477468  //setupGL();
    478   object_axis = makeAxis();
     469  this->cone_x = gluNewQuadric();
     470  this->cone_y = gluNewQuadric();
     471  this->cone_z = gluNewQuadric();
    479472}
    480473
     
    527520  // draw axis
    528521  //------------------------------------------------------------------------------------
    529   if (show_axis) {
    530     glPushMatrix();
    531     glRotated(camera_angle[GLWidget::x], 1.0, 0.0, 0.0);
    532     glRotated(camera_angle[GLWidget::y], 0.0, 1.0, 0.0);
    533     glRotated(camera_angle[GLWidget::z], 0.0, 0.0, 1.0); 
    534     glCallList(object_axis);
    535     glPopMatrix();
    536   }
    537 
     522  if (show_axis)
     523      renderAxis();
    538524
    539525  //------------------------------------------------------------------------------------
     
    551537  // translate camera
    552538  glTranslated(camera_position[GLWidget::x], camera_position[GLWidget::y], camera_position[GLWidget::z]);
    553  
    554539   
    555540
     
    600585  //------------------------------------------------------------------------------------
    601586  if (!gobjects_rendering_options.getUseDepth()) renderGObjects();
    602 
     587 
    603588  glPopMatrix();
    604589}
     
    637622  screen_pixel = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2);
    638623  return sqrt( screen_pixel );
     624}
     625
     626void GLWidget::renderAxis() {
     627  if (!this->show_axis) return;
     628
     629  glPushMatrix();
     630  double xr = (double)this->width()/(double)this->height();
     631  glTranslated(-1.0*xr/2.3, 1.0/2.3, 0);
     632
     633  glRotated(camera_angle[GLWidget::x], 1.0, 0.0, 0.0);
     634  glRotated(camera_angle[GLWidget::y], 0.0, 1.0, 0.0);
     635  glRotated(camera_angle[GLWidget::z], 0.0, 0.0, 1.0); 
     636
     637  glScalef( 0.05, 0.05, 0.05 );
     638
     639  GLfloat cone_radius = 0.1f;
     640  GLfloat cone_length = 0.2f;
     641  glLineWidth (2.5);
     642
     643  // axis
     644  glBegin (GL_LINES);
     645  glColor3f (1,0,0); // X axis is red
     646  glVertex3f (0,0,0);
     647  glVertex3f (1,0,0);
     648
     649  glColor3f (0,1,0); // Y axis is green
     650  glVertex3f (0,0,0);
     651  glVertex3f (0,1,0);
     652
     653  glColor3f (0.0f, 0.0f, 1.0f); // z axis is blue
     654  glVertex3f (0,0,0);
     655  glVertex3f (0,0,-1);
     656  glEnd();
     657
     658  // cones and labels
     659  glColor3f (1.0f, 0.0f, 0.0f); // X axis is red
     660  this->renderText ( 0.8, -0.1, 0.0, "X" );
     661  glPushMatrix();
     662        glTranslatef(1.0f, 0.0f, 0.0f);
     663        glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
     664  gluCylinder(this->cone_x, cone_radius, 0.0f, cone_length, 8, 8);
     665  glPopMatrix();
     666
     667  glColor3f (0.0f, 1.0f, 0.0f); // Y axis is green
     668  this->renderText ( 0.1, 0.8, 0.0, "Y" );
     669  glPushMatrix();
     670        glTranslatef(0.0f, 1.0f, 0.0f);
     671        glRotatef(270.0f, 1.0f, 0.0f, 0.0f);
     672  gluCylinder(this->cone_y, cone_radius, 0.0f, cone_length, 8, 8);
     673  glPopMatrix();
     674
     675  glColor3f (0.0f, 0.0f, 1.0f); // z axis is blue
     676  this->renderText ( 0.0, -0.1, -0.8, "Z" );
     677  glPushMatrix();
     678        glTranslatef(0.0f, 0.0f, -1.0f);
     679        glRotatef(180, 1.0, 0.0, 0.0);
     680  gluCylinder(this->cone_z, cone_radius, 0.0f, cone_length, 8, 8);
     681  glPopMatrix();
     682
     683  glPopMatrix ();
     684
    639685}
    640686
     
    826872}
    827873
    828 GLuint GLWidget::makeAxis() {
    829 
    830   if (object_axis != 0) {
    831     glDeleteLists( object_axis, 1 );
    832     object_axis = 0;
    833   }
    834 
    835   GLuint list = glGenLists(1);
    836   glNewList(list, GL_COMPILE);
    837 
    838   //------------------------------------------------------------------------------------
    839   // draw axis
    840   //------------------------------------------------------------------------------------
    841   //glColor4f(1.0, 1.0, 1.0, 1.0);
    842   //glColor4f(0.5, 0.5, 0.5, 1.0);
    843   //glColor4f(0.0, 0.0, 0.0, 1.0);
    844   glColor4ub( color_axis.red(), color_axis.green(), color_axis.blue(), 255 );
    845  
    846   glLineWidth(2.0);
    847 
    848   GLfloat ax_length = 0.44f;
    849   GLfloat cone_radius = 0.008f;
    850   GLfloat cone_length = 0.026f;
    851 
    852   glPushMatrix();
    853   glBegin(GL_LINE_STRIP);
    854   glVertex3f(-ax_length, 0.0f, 0.0f);
    855   glVertex3f(ax_length, 0.0f, 0.0f);
    856   glEnd();
    857  
    858   GLUquadricObj *cone_x = gluNewQuadric();
    859         glTranslatef(ax_length, 0.0f, 0.0f);
    860         glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
    861   gluCylinder(cone_x, cone_radius, 0.0f, cone_length, 4, 4);
    862   glPopMatrix();
    863 
    864   glEnable(GL_LINE_STIPPLE);
    865   glLineStipple(1, 0xFFF0);
    866 
    867   glPushMatrix();
    868   glBegin(GL_LINE_STRIP);
    869   glVertex3f(0.0f, -ax_length, 0.0f);
    870   glVertex3f(0.0f, ax_length, 0.0f);
    871   glEnd();
    872 
    873   GLUquadricObj *cone_y = gluNewQuadric();
    874         glTranslatef(0.0, ax_length, 0.0);
    875         glRotatef(270, 1.0, 0.0, 0.0);
    876   gluCylinder(cone_y, cone_radius, 0.0f, cone_length, 4, 4);
    877   glPopMatrix();
    878 
    879   glLineStipple(1, 0xF0F0);
    880   glPushMatrix();
    881   glBegin(GL_LINE_STRIP);
    882   glVertex3f(0.0f, 0.0f, -ax_length);
    883   glVertex3f(0.0f, 0.0f, ax_length);
    884   glEnd();
    885 
    886   GLUquadricObj *cone_z = gluNewQuadric();
    887         glTranslatef(0.0, 0.0, ax_length);
    888         glRotatef(90, 0.0, 0.0, 1.0);
    889   gluCylinder(cone_z, cone_radius, 0.0f, cone_length, 4, 4);
    890   glPopMatrix();
    891 
    892   glDisable(GL_LINE_STIPPLE);
    893 
    894   //------------------------------------------------------------------------------------
    895   glEndList();
    896   return list;
    897 }
    898 
    899874void GLWidget::renderVolumeBox() {
    900875
  • bioView3D/src/glwidget.h

    r188 r189  
    2727class DProgressWidget;
    2828class DScaleBar;
     29//class GLUquadricObj;
     30typedef struct GLUquadric GLUquadric;
    2931
    3032class GLWidget : public QGLWidget
     
    198200  // Visualization
    199201  void setGLBackgroundColor( const QColor & );
    200   void setGLAxisColor( const QColor & );
    201202  void setGLColors( const QColor &bg, const QColor &ax );
    202203  void setShowAxis( bool s ) { show_axis = s; update(); }
     
    287288  void renderVolumeBox();
    288289  void drawScaleBar( QPainter *p );
     290  void renderAxis();
    289291  double screenPixelSizeInGL();
    290292
    291   GLuint makeAxis();
    292293  GLuint createVoxelBox( const DVoxel<float, unsigned char> &voxel );
    293294  GLuint createVoxelPoint( const DVoxel<float, unsigned char> &voxel );
     
    305306  //GLuint volume_texture_2d;
    306307  //std::vector<GLuint> volume_textures_2d;
    307   GLuint object_axis;
    308308  GLuint object_box;
     309  GLUquadric *cone_x, *cone_y, *cone_z;
    309310 
    310311  //int xRot; int yRot; int zRot;
  • bioView3D/src/gobjects.cpp

    r185 r189  
    2222#include <QtOpenGL>
    2323#include <QtXml>
     24
     25//------------------------------------------------------------------------------------
     26// Gobject nodes
     27//------------------------------------------------------------------------------------
     28
     29QStringList DGObjects::gobject_types = QStringList() << "gobject" << "point"
     30    << "polyline" << "polygon" << "rectangle" << "square" << "circle" << "ellipse" << "label";
    2431
    2532//------------------------------------------------------------------------------------
     
    105112
    106113int DGObject::fromXML( const QDomElement &gobject ) {
    107 
     114  type = gobject.tagName ();
    108115  if ( gobject.hasAttribute("name") ) name = gobject.attribute("name");
    109116  if ( gobject.hasAttribute("type") ) type = gobject.attribute("type");
     
    131138    QString tag_name, tag_value;
    132139
    133     if (tag_node.hasAttribute("name")) tag_name = tag_node.attribute("name");
     140    if (tag_node.hasAttribute("name"))
     141        tag_name = tag_node.attribute("name");
    134142    if (tag_node.hasAttribute("value"))
    135       tag_value = tag_node.attribute("value");
     143        tag_value = tag_node.attribute("value");
    136144    else
    137       tag_value = tag_node.firstChildElement("value").text();
     145        tag_value = tag_node.firstChildElement("value").text();
    138146
    139147    tags.insert( tag_name, tag_value );
     
    146154  children.clear();
    147155
     156  /*
    148157  QDomElement gobject_node = gobject.firstChildElement("gobject");
    149158  while ( !gobject_node.isNull() ) {
     
    151160    gobject_node = gobject_node.nextSiblingElement("gobject");
    152161  } // while
     162  */
     163  for (QDomElement n = gobject.firstChildElement(); !n.isNull(); n = n.nextSiblingElement()) {
     164      if (DGObjects::gobject_types.contains(n.tagName())) {
     165          children << QSharedPointer<DGObject>( new DGObject(n, this) );
     166          QApplication::processEvents();
     167      }
     168  } // for
    153169
    154170  return 0;
     
    253269  clear();
    254270  QDomElement root = dom->documentElement();
     271  /*
    255272  QDomElement gobject_node = root.firstChildElement("gobject");
    256273  while ( !gobject_node.isNull() ) {
     
    259276    QApplication::processEvents();
    260277  } // while
     278  */
     279  for (QDomElement n = root.firstChildElement(); !n.isNull(); n = n.nextSiblingElement()) {
     280      if (DGObjects::gobject_types.contains(n.tagName())) {
     281          *this << QSharedPointer<DGObject>( new DGObject(n) );
     282          QApplication::processEvents();
     283      }
     284  } // for
    261285
    262286  // now load all default render procs
  • bioView3D/src/gobjects.h

    r185 r189  
    210210  QSet<QString> unique_type_names();
    211211  QSet<QString> unique_tag_names();
     212
     213public:
     214  static QStringList gobject_types;
    212215
    213216protected:
  • bioView3D/src/window.cpp

    r188 r189  
    1818#define BV_APPLICATION     "BioView3D"
    1919#define BV_CONFIG_FILE     "bioview3d.ini"
    20 #define BV_VERSION         "0.1.17"
     20#define BV_VERSION         "0.1.18"
    2121
    2222#include <string>
     
    617617void Window::about() {
    618618  QString msg;
    619   msg.sprintf( "<b>bioView3D ver: %s</b>, 2012<br>", BV_VERSION );
     619  msg.sprintf( "<b>bioView3D ver: %s</b>, 2012 (Qt %s)<br>", BV_VERSION, QT_VERSION_STR );
    620620  msg += "Center for BioImage Informatics, UCSB<br />";
    621621  msg += "http://www.bioimage.ucsb.edu/<br />";
Note: See TracChangeset for help on using the changeset viewer.