Esempio n. 1
0
void
ClipPlanes::drawPoints(int ic, QList<Vec> hpts)
{
  Vec voxelScaling = Global::voxelScaling();
  Vec pos = VECPRODUCT(m_clips[ic]->position(), voxelScaling);
  Vec cnormal = m_clips[ic]->m_tang;
  int clipThickness = m_clips[ic]->thickness();

  glEnable(GL_POINT_SPRITE);
  glActiveTexture(GL_TEXTURE0);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, Global::spriteTexture());
  glTexEnvf( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
  glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
  glEnable(GL_POINT_SMOOTH);
  glBegin(GL_POINTS);
  for(int ip=0; ip<hpts.count(); ip++)
    {
      Vec pt = VECPRODUCT(hpts[ip], voxelScaling);
      if (qAbs((pt-pos)*cnormal)<(clipThickness+1.0))
	glVertex3f(pt.x, pt.y, pt.z);
    }
  glEnd();
  glDisable(GL_POINT_SPRITE);
  glActiveTexture(GL_TEXTURE0);
  glDisable(GL_TEXTURE_2D);
  glDisable(GL_POINT_SMOOTH);
}
Esempio n. 2
0
void
ClipPlanes::drawOtherSlicesInViewport(QGLViewer *viewer, int ic)
{
  Vec voxelScaling = Global::voxelScaling();
  Vec pos = m_clips[ic]->position();
  Vec cxaxis = m_clips[ic]->m_xaxis;
  cxaxis = VECPRODUCT(cxaxis, voxelScaling);
  cxaxis.normalize();
  Vec cyaxis = m_clips[ic]->m_yaxis;
  cyaxis = VECPRODUCT(cyaxis, voxelScaling);
  cyaxis.normalize();
  Vec cnormal = m_clips[ic]->m_tang;
  cnormal = VECPRODUCT(cnormal, voxelScaling);
  cnormal.normalize();

  float aspectRatio = viewer->aspectRatio(); 
  float cdist = 2*viewer->sceneRadius()/m_clips[ic]->viewportScale(); 
  float fov = viewer->camera()->fieldOfView(); 
  float yf = cdist*tan(fov*0.5); 
  float xf = yf*aspectRatio;

  Vec vc[4];
  vc[0] = pos - xf*cxaxis - yf*cyaxis;
  vc[1] = pos + xf*cxaxis - yf*cyaxis;
  vc[2] = pos - xf*cxaxis + yf*cyaxis;
  vc[3] = pos + xf*cxaxis + yf*cyaxis;

  if (m_clips[ic]->showOtherSlice())
    {
      glColor4f(0.5, 0.5, 0.5, 0.8);
      for (int tic=0; tic<m_clips.count(); tic++)
	{
	  if (tic != ic)
	    {
	      Vec postic = m_clips[tic]->position();
	      Vec cnormaltic = m_clips[tic]->m_tang;
	      cnormaltic = VECPRODUCT(cnormaltic, voxelScaling);
	      cnormaltic.normalize();
	      int thickness = m_clips[tic]->thickness();
	      Vec cc = m_clips[tic]->color();

	      glLineWidth(3);
	      glColor4f(cc.x*0.5, cc.y*0.5, cc.z*0.5, 0.5);
	      drawViewportIntersections(postic-thickness*cnormaltic, cnormaltic, vc);

	      glLineWidth(2);
	      glColor4f(cc.x*0.7, cc.y*0.7, cc.z*0.7, 0.7);
	      drawViewportIntersections(postic, cnormaltic, vc);

	      glLineWidth(1);
	      glColor4f(cc.x*0.5, cc.y*0.5, cc.z*0.5, 0.5);
	      drawViewportIntersections(postic+thickness*cnormaltic, cnormaltic, vc);
	    }
	}
    }
}
Esempio n. 3
0
void
PaintBall::bound()
{
  Vec voxelScaling = Global::voxelScaling();
  Vec bmin, bmax;
  bmin = VECPRODUCT(m_dataMin, voxelScaling);
  bmax = VECPRODUCT(m_dataMax, voxelScaling);

  Vec pos = StaticFunctions::clampVec(bmin, bmax,
				      m_frame.position());

  if ((m_fpos-pos).squaredNorm() > 0.01)
    {
      m_fpos = pos;
      m_frame.setPosition(pos);
      setSizeBounds();
      return;
    }

  Vec pb0 = Vec(m_bounds[1].position().x,
		m_bounds[3].position().y,
		m_bounds[5].position().z);

  Vec pb1 = Vec(m_bounds[0].position().x,
		m_bounds[2].position().y,
		m_bounds[4].position().z);

  if ((pb0 - m_pb0).squaredNorm() > 0.01 ||
      (pb1 - m_pb1).squaredNorm() > 0.01)
    {
      pos = Vec(m_bounds[1].position().x+m_bounds[0].position().x,
		m_bounds[3].position().y+m_bounds[2].position().y,
		m_bounds[5].position().z+m_bounds[4].position().z);
      pos /= 2;
      m_frame.setPosition(pos);
      
      m_size = Vec(m_bounds[1].position().x-m_bounds[0].position().x,
		   m_bounds[3].position().y-m_bounds[2].position().y,
		   m_bounds[5].position().z-m_bounds[4].position().z);
      
      if (m_size.x < 0) m_size.x = -m_size.x;
      if (m_size.y < 0) m_size.y = -m_size.y;
      if (m_size.z < 0) m_size.z = -m_size.z;

      m_size = m_size/2;

      setSizeBounds();
    }
}
Esempio n. 4
0
void
GiLightObject::postdrawPointNumbers(QGLViewer *viewer)
{
  Vec voxelScaling = Global::voxelScaling();
  for(int i=0; i<m_points.count();i++)
    {
      Vec pt = VECPRODUCT(m_points[i], voxelScaling);
      Vec scr = viewer->camera()->projectedCoordinatesOf(pt);
      int x = scr.x;
      int y = scr.y;
      
      //---------------------
      x *= viewer->size().width()/viewer->camera()->screenWidth();
      y *= viewer->size().height()/viewer->camera()->screenHeight();
      //---------------------
      
      QString str = QString("%1").arg(i);
      QFont font = QFont();
      QFontMetrics metric(font);
      int ht = metric.height();
      int wd = metric.width(str);
      y += ht/2;
      
      StaticFunctions::renderText(x+2, y, str, font, Qt::black, Qt::green);
    }
}
Esempio n. 5
0
void
ImageCaptionGrabber::checkIfGrabsMouse(int x, int y,
				       const Camera* const camera)
{
  if (m_pressed)
    {
      // mouse button pressed so keep grabbing
      setGrabsMouse(true);
      return;
    }
  Vec voxelSize = Global::voxelScaling();
  Vec pos = position();
  if (pos.z > -100000)
    {
      pos = VECPRODUCT(pos, voxelSize);  
      pos = camera->projectedCoordinatesOf(pos);
    }
  else
    {
      pos.x = camera->screenWidth()*pos.x;
      pos.y = camera->screenHeight()*pos.y;
      //QPoint scr = mapFromGlobal(pos);
    }
  QPoint hp(pos.x, pos.y);
  if ((hp-QPoint(x,y)).manhattanLength() < 50)
    setGrabsMouse(true);
  else
    setGrabsMouse(false);
}
Esempio n. 6
0
void
ClipObject::drawCaptionImage()
{
  glLineWidth(1);
 
  float s1 = m_tscale1;
  float s2 = m_tscale2;

  glColor4f(0, 0, 0, m_opacity);
  if (m_applyOpacity)
    glColor4f(m_opacity,
	      m_opacity,
	      m_opacity,
	      m_opacity);
  else
    glColor4f(1,1,1,1);
  
  if (m_applyFlip)
    {
      s2 = -s2;
    }

  Vec tang = m_tang;
  Vec xaxis = m_xaxis;
  Vec yaxis = m_yaxis;
  tang = Matrix::rotateVec(m_xform, tang);
  xaxis = Matrix::rotateVec(m_xform, xaxis);
  yaxis = Matrix::rotateVec(m_xform, yaxis);

  Vec voxelScaling = Global::voxelScaling();
  Vec opt = VECPRODUCT(m_position, voxelScaling);
  opt = Matrix::xformVec(m_xform, opt);
  Vec c0, c1, c2, c3;
  c0 = opt - s1*xaxis + s2*yaxis;
  c1 = opt - s1*xaxis - s2*yaxis;
  c2 = opt + s1*xaxis - s2*yaxis;
  c3 = opt + s1*xaxis + s2*yaxis;

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_imageTex);
  glTexEnvf(GL_TEXTURE_ENV,
	    GL_TEXTURE_ENV_MODE,
	    GL_MODULATE);
  glEnable(GL_TEXTURE_RECTANGLE_ARB);
  
  glEnable(GL_POLYGON_OFFSET_FILL);
  glPolygonOffset(1.0, 1.0);
  glBegin(GL_QUADS);
  glTexCoord2f(0, 0);                             glVertex3fv(c0);
  glTexCoord2f(0, m_textureHeight);               glVertex3fv(c1);
  glTexCoord2f(m_textureWidth, m_textureHeight);  glVertex3fv(c2);
  glTexCoord2f(m_textureWidth, 0);                glVertex3fv(c3);
  glEnd();
  glPolygonOffset(0.0, 0.0);
  glDisable(GL_POLYGON_OFFSET_FILL);

  glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
Esempio n. 7
0
void
PaintBall::setBounds(Vec dataMin, Vec dataMax)
{
  m_dataMin = dataMin;
  m_dataMax = dataMax;

  Vec voxelScaling = Global::voxelScaling();
  Vec bmin, bmax;
  bmin = VECPRODUCT(m_dataMin, voxelScaling);
  bmax = VECPRODUCT(m_dataMax, voxelScaling);

  Vec pos = StaticFunctions::clampVec(bmin, bmax,
				      m_frame.position());

  m_fpos = pos;
  m_frame.setPosition(pos);
  setSizeBounds();
}
Esempio n. 8
0
bool
ClipPlanes::viewportKeypressEvent(int i, QKeyEvent *event)
{
  if (i >= 0 && i < m_clips.count())
    {
      if (event->key() == Qt::Key_Delete)
	{
	  QMessageBox::information(0, "", "Switching off the viewport");
	  m_clips[i]->setViewport(QVector4D(-1,-1,-1,-1));
	  return true;
	}

      bool ok = m_clips[i]->keyPressEvent(event);
      if (ok)
	{
	  if (m_clips[i]->mopClip())
	    {
	      Vec pos = m_clips[i]->position();
	      Vec normal = m_clips[i]->m_tang;
	      Vec voxelScaling = Global::voxelScaling();
	      normal = VECPRODUCT(normal, voxelScaling);
	      normal.normalize();
	      pos = VECPRODUCT(pos, voxelScaling);
	      emit mopClip(pos, normal);
	    }
	  if (m_clips[i]->saveSliceImage())
	    emit saveSliceImage(i, m_clips[i]->resliceSubsample());
	  else if (m_clips[i]->resliceVolume())
	    {
	      int subsample = m_clips[i]->resliceSubsample();
	      int tagvalue = m_clips[i]->resliceTag();
	      emit extractClip(i, subsample, tagvalue);
	    }
	  else if (m_clips[i]->reorientCamera())
	    emit reorientCameraUsingClipPlane(i);
	}
      return ok;
    }

  return false;
}
Esempio n. 9
0
void
ClipObject::drawGrid()
{
  float s1 = m_tscale1;
  float s2 = m_tscale2;

  glColor4f(m_color.x*m_opacity,
	    m_color.y*m_opacity,
	    m_color.z*m_opacity,
	    m_opacity);

  Vec tang = m_tang;
  Vec xaxis = m_xaxis;
  Vec yaxis = m_yaxis;
  tang = Matrix::rotateVec(m_xform, tang);
  xaxis = Matrix::rotateVec(m_xform, xaxis);
  yaxis = Matrix::rotateVec(m_xform, yaxis);

  Vec voxelScaling = Global::voxelScaling();
  Vec opt = VECPRODUCT(m_position, voxelScaling);
  opt = Matrix::xformVec(m_xform, opt);
  Vec c0, c1, c2, c3;
  c0 = opt - s1*xaxis + s2*yaxis;
  c1 = opt - s1*xaxis - s2*yaxis;
  c2 = opt + s1*xaxis - s2*yaxis;
  c3 = opt + s1*xaxis + s2*yaxis;

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, Global::boxTexture());
  glEnable(GL_TEXTURE_2D);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 

  glEnable(GL_POLYGON_OFFSET_FILL);
  glPolygonOffset(1.0, 1.0);
  glBegin(GL_QUADS); 
  glTexCoord2f(0, 0);              glVertex3fv(c0);
  glTexCoord2f(0, m_gridY);        glVertex3fv(c1);
  glTexCoord2f(m_gridX, m_gridY);  glVertex3fv(c2);
  glTexCoord2f(m_gridX, 0);        glVertex3fv(c3);
  glEnd();
  glPolygonOffset(0.0, 0.0);
  glDisable(GL_POLYGON_OFFSET_FILL);

  glDisable(GL_TEXTURE_2D);
}
Esempio n. 10
0
void
ClipGrabber::mousePressEvent(QMouseEvent* const event,
				 Camera* const camera)
{
  m_pointPressed = -1;
  m_pressed = true;
  m_prevPos = event->pos();

  Vec voxelScaling = Global::voxelScaling();
  Vec pp = Vec(m_prevPos.x(), m_prevPos.y(), 0);
  Vec pos = VECPRODUCT(position(), voxelScaling);
  pos = Matrix::xformVec(m_xform, pos);

  bool flag;

  if (xActive(camera, pos, pp, flag))
    {
      if (flag)
	setMoveAxis(MoveX0);
      else
	setMoveAxis(MoveX1);
      emit selectForEditing();
      return;
    }
  else if (yActive(camera, pos, pp, flag))
    {
      if (flag)
	setMoveAxis(MoveY0);
      else
	setMoveAxis(MoveY1);
      emit selectForEditing();
      return;
    }
  else if (zActive(camera, pos, pp))
    {
      setMoveAxis(MoveZ);
      emit selectForEditing();
      return;
    }
}
Esempio n. 11
0
void
ClipGrabber::checkIfGrabsMouse(int x, int y,
			       const Camera* const camera)
{
  if (m_pressed)
    {
      // mouse button pressed so keep grabbing
      setActive(true);
      setGrabsMouse(true);
      return;
    }

  int sz = 20;

  m_lastX = x;
  m_lastY = y;

  Vec voxelScaling = Global::voxelScaling();
  Vec pos = VECPRODUCT(position(), voxelScaling);
  pos = Matrix::xformVec(m_xform, pos);

  Vec pp = Vec(x, y, 0);
    
  bool flag;
  if (xActive(camera, pos, pp, flag) ||
      yActive(camera, pos, pp, flag) ||
      zActive(camera, pos, pp))
    {
      setActive(true);
      setGrabsMouse(true);
      return;
    }

  setActive(false);
  setGrabsMouse(false);
}
Esempio n. 12
0
void
ClipObject::drawLines(QGLViewer *viewer,
		      bool backToFront)
{
  bool noimage = !m_imagePresent && !m_captionPresent;
  bool quad = noimage && m_active;

  glEnable(GL_BLEND);
//  glEnable(GL_LINE_SMOOTH);
//  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

  Vec voxelScaling = Global::voxelScaling();
  Vec opt = VECPRODUCT(m_position, voxelScaling);
  opt = Matrix::xformVec(m_xform, opt);

  float r = m_size;
  float s1 = m_tscale1;
  float s2 = m_tscale2;

  Vec tang = m_tang;
  Vec xaxis = m_xaxis;
  Vec yaxis = m_yaxis;

  tang = Matrix::rotateVec(m_xform, tang);
  xaxis = Matrix::rotateVec(m_xform, xaxis);
  yaxis = Matrix::rotateVec(m_xform, yaxis);

  if (backToFront)
    {
      if (m_active)
        glLineWidth(3);
      else
        glLineWidth(1);

      glColor3f(m_color.x, m_color.y, m_color.z);

      if (m_thickness > 0 && m_showThickness)
	DRAWTHICKNESS()
      else
	DRAWCLIPWIDGET()
    }


  glLineWidth(1);

  if (!m_solidColor || m_active)
    {
      Vec c0, ca, cb, c1;
      c0 = opt + s1*xaxis;
      ca = opt - 0.2*s2*yaxis;
      c1 = opt - s1*xaxis;
      cb = opt + 0.2*s2*yaxis;
      glColor4f(m_opacity, 0.5*m_opacity, 0, m_opacity);
      if (quad &&
	  m_moveAxis >= MoveX0 &&
	  m_moveAxis <= MoveX1) glBegin(GL_QUADS);
      else glBegin(GL_LINE_STRIP);
      glVertex3fv(c0);
      glVertex3fv(ca);
      glVertex3fv(c1);
      glVertex3fv(cb);
      if (!(quad && m_moveAxis == MoveZ)) glVertex3fv(c0);
      glEnd();

      c0 = opt + s2*yaxis;
      ca = opt - 0.2*s1*xaxis;
      c1 = opt - s2*yaxis;
      cb = opt + 0.2*s1*xaxis;
      glColor4f(0.5*m_opacity, m_opacity, 0, m_opacity);
      if (quad &&
	  m_moveAxis >= MoveY0 &&
	  m_moveAxis <= MoveY1) glBegin(GL_QUADS);
      else glBegin(GL_LINE_STRIP);
      glVertex3fv(c0);
      glVertex3fv(ca);
      glVertex3fv(c1);
      glVertex3fv(cb);
      if (!quad) glVertex3fv(c0);
      glEnd();
      
      c0 = opt + r*tang;
      Vec cax = opt - 0.2*s1*xaxis;
      Vec cbx = opt + 0.2*s1*xaxis;
      Vec cay = opt - 0.2*s2*yaxis;
      Vec cby = opt + 0.2*s2*yaxis;
      glColor4f(0, 0.5*m_opacity, m_opacity, m_opacity);
      if (quad && m_moveAxis == MoveZ) glBegin(GL_TRIANGLES);
      else glBegin(GL_LINE_STRIP);
      glVertex3fv(c0);
      glVertex3fv(cax);
      glVertex3fv(cbx);
      glVertex3fv(c0);
      glVertex3fv(cay);
      glVertex3fv(cby);
      if (!(quad && m_moveAxis == MoveZ)) glVertex3fv(c0);
      glEnd();
    }

  //  glDisable(GL_LINE_SMOOTH);


  if (!backToFront)
    {
      if (m_active)
        glLineWidth(3);
      else
        glLineWidth(1);

      glColor3f(m_color.x, m_color.y, m_color.z);

      if (m_thickness > 0 && m_showThickness)
	DRAWTHICKNESS()
      else
	DRAWCLIPWIDGET()
    }

  if (!m_solidColor || m_active)
    {
      glEnable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, Global::spriteTexture());
      glTexEnvf( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
      glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
      glEnable(GL_POINT_SMOOTH);

      if (m_active)
	{
	  glColor3f(1,0,0);
	  glPointSize(25);
	}
      else
	{
	  glColor3f(m_color.x, m_color.y, m_color.z);
	  glPointSize(20);
	}	
      glBegin(GL_POINTS);
      glVertex3fv(opt);
      glEnd();

      glPointSize(1);  
      
      glDisable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glDisable(GL_TEXTURE_2D);
  
      glDisable(GL_POINT_SMOOTH);
    }

  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);      
}
Esempio n. 13
0
void
PaintBall::draw()
{
  if (m_show == false)
    return;

  bound();

  Vec dataSize = m_dataMax-m_dataMin+Vec(1,1,1);
  float scale = 0.1*qMax(dataSize.x,
			 qMax(dataSize.y, dataSize.z));
  
//  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
//  glEnable(GL_LINE_SMOOTH);

  glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
  glEnable(GL_POINT_SMOOTH);

  glPushMatrix();
  glMultMatrixd(m_frame.matrix());

  Vec linecolor = Vec(0.9f,0.8f,0.5f);
  if (m_frame.grabsMouse())
    linecolor = Vec(0,0.8f,0);

  Vec sz = m_size;

  glColor4f(linecolor.x,
	    linecolor.y,
	    linecolor.z,
	    0.9f);
  glLineWidth(1);
  glBegin(GL_LINES);
  glVertex3f(sz.x, 0, 0);
  glVertex3f(-sz.x,0, 0);
  glVertex3f(0, sz.y, 0);
  glVertex3f(0,-sz.y, 0);
  glVertex3f(0, 0, sz.z);
  glVertex3f(0, 0,-sz.z);
  glEnd();

  //------------------------------
  int nst;  
  
  glBegin(GL_LINE_STRIP);
  nst = 101*qMax<float>((float)(sz.x/dataSize.x), (float)(sz.y/dataSize.y));
  if (nst < 5) nst = 5;
  for(int i=0; i<nst; i++)
    {
      float t = (float)i/(float)(nst-1);
      float x = sz.x * cos(6.2831853*t);
      float y = sz.y * sin(6.2831853*t);
      glVertex3f(x, y, 0);
    }
  glEnd();

  glBegin(GL_LINE_STRIP);
  nst = 101*qMax<float>((float)(sz.z/dataSize.z), (float)(sz.y/dataSize.y));
  if (nst < 5) nst = 5;
  for(int i=0; i<nst; i++)
    {
      float t = (float)i/(float)(nst-1);
      float y = sz.y * cos(6.2831853*t);
      float z = sz.z * sin(6.2831853*t);
      glVertex3f(0, y, z);
    }
  glEnd();

  glBegin(GL_LINE_STRIP);
  nst = 101*qMax<float>((float)(sz.x/dataSize.x), (float)(sz.z/dataSize.z));
  if (nst < 5) nst = 5;
  for(int i=0; i<nst; i++)
    {
      float t = (float)i/(float)(nst-1);
      float x = sz.x * cos(6.2831853*t);
      float z = sz.z * sin(6.2831853*t);
      glVertex3f(x, 0, z);
    }
  glEnd();

  
  //------------------------------
  glPointSize(11);
  glBegin(GL_POINTS);
  // draw center point
  if (m_frame.grabsMouse())
    glColor4f(0,0.9f,0, 0.9f);
  else
    glColor4f(0.9f,0.8f,0.5f, 0.9f);
  glVertex3fv(Vec(0,0,0));
  // now draw the face points
  for(int i=0; i<6; i++)
    {      
      Vec v = m_bounds[i].position() - m_frame.position();
      if (m_bounds[i].grabsMouse())
	glColor4f(0.9f,0,0, 0.9f);
      else
	glColor4f(0.9f,0.8f,0.5f, 0.9f);

      glVertex3fv(v);
    }
  glEnd();  
  //------------------------------


  glEnable(GL_LIGHTING);

  //glColor3fv(linecolor);
  if (m_constraints && m_constraints->translationConstraintType() == AxisPlaneConstraint::AXIS)
    {
      Vec dir = m_constraints->translationConstraintDirection();
      if (dir.norm() > 0)
	dir.normalize();
      Vec pos = VECPRODUCT(sz, dir);
      pos += dir;
      dir *= scale;
      QGLViewer::drawArrow(pos,   pos+dir, 0.5f, 7);
      QGLViewer::drawArrow(-pos, -pos-dir, 0.5f, 7);
    }
  else if (m_constraints && m_constraints->translationConstraintType() == AxisPlaneConstraint::FREE)
    {
      for(int i=0; i<3; i++)
	{
	  Vec pos, dir;
	  dir = Vec((i==0),(i==1),(i==2));
	  pos = VECPRODUCT(sz, dir);
	  pos += dir;
	  dir *= scale;
	  QGLViewer::drawArrow(pos,   pos+dir, 0.5f, 7);
	  QGLViewer::drawArrow(-pos, -pos-dir, 0.5f, 7);
	}
    }
  glDisable(GL_LIGHTING);

  glPopMatrix();
}
Esempio n. 14
0
void
GiLightObject::computePath(QList<Vec> points)
{
  Vec voxelScaling = Global::voxelScaling();
  Vec voxelSize = VolumeInformation::volumeInformation().voxelSize;

  // -- collect path points for length computation
  QList<Vec> lengthPath;
  lengthPath.clear();

  m_path.clear();

  int npts = points.count();
  if (npts == 1)
    {
      m_path << VECPRODUCT(points[0], voxelScaling);
      m_pathT << Vec(0,0,1);
      m_pathX << Vec(0,1,0);
      m_pathY << Vec(1,0,0);
      return;
    }

  Vec prevPt;
  if (m_segments == 1)
    {
      for(int i=0; i<npts; i++)
	{
	  Vec v = VECPRODUCT(points[i], voxelScaling);
	  m_path.append(v);

	  // for length calculation
	  v = VECPRODUCT(points[i], voxelSize);
	  lengthPath.append(v);
	}

      computePathVectors();
  
      computeLength(lengthPath);
      return;
    }

  // for number of segments > 1 apply spline-based interpolation
  for(int i=1; i<npts; i++)
    {
      for(int j=0; j<m_segments; j++)
	{
	  float frc = (float)j/(float)m_segments;
	  Vec pos = interpolate(i-1, i, frc);

	  Vec pv = VECPRODUCT(pos, voxelScaling);
	  m_path.append(pv);

	  // for length calculation
	  pv = VECPRODUCT(pos, voxelSize);
	  lengthPath.append(pv);
	}
    }

  // last point
  Vec pos = VECPRODUCT(points[points.count()-1],
		       voxelScaling);
  m_path.append(pos);

  // for length calculation
  pos = VECPRODUCT(points[points.count()-1],
		   voxelSize);
  lengthPath.append(pos);
  
  computePathVectors();

  computeLength(lengthPath);
}
Esempio n. 15
0
void
GiLightObject::drawLines(QGLViewer *viewer,
		      bool active,
		      bool backToFront)
{
  glEnable(GL_BLEND);
//  glEnable(GL_LINE_SMOOTH);
//  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

  //Vec col = m_opacity*m_color;
  Vec col = m_color;
  if (backToFront)
    {
      if (active)
	glLineWidth(7);
      else
	glLineWidth(3);
	
      glColor4f(col.x*0.5,
		col.y*0.5,
		col.z*0.5,
		0.5);
		//m_opacity*0.5);
      
      glBegin(GL_LINE_STRIP);
      for(int i=0; i<m_path.count(); i++)
	glVertex3fv(m_path[i]);
      glEnd();
    }

  if (m_showPoints)
    {
      glColor3f(m_color.x,
		m_color.y,
		m_color.z);


      glEnable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, Global::lightTexture());
      glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
      glEnable(GL_POINT_SMOOTH);

      Vec voxelScaling = Global::voxelScaling();
      glPointSize(50);
      if (m_lightType == 1)
	{ // draw only first point
	  glBegin(GL_POINTS);
	  Vec pt = VECPRODUCT(m_points[0], voxelScaling);
	  glVertex3fv(pt);
	  glEnd();
	}
      else
	{
	  glBegin(GL_POINTS);
	  for(int i=0; i<m_points.count();i++)
	    {
	      Vec pt = VECPRODUCT(m_points[i], voxelScaling);
	      glVertex3fv(pt);
	    }
	  glEnd();
	}


      if (m_pointPressed > -1)
	{
	  glColor3f(1,0,0);
	  Vec voxelScaling = Global::voxelScaling();
	  glPointSize(75);
	  glBegin(GL_POINTS);
	  Vec pt = VECPRODUCT(m_points[m_pointPressed], voxelScaling);
	  glVertex3fv(pt);
	  glEnd();
	}

      // "inverse ambient light"
      if (m_rad == 0)
	{
	  glColor3f(1,1,1);	  

	  glEnable(GL_POINT_SPRITE);
	  glActiveTexture(GL_TEXTURE0);
	  glEnable(GL_TEXTURE_2D);
	  glBindTexture(GL_TEXTURE_2D, Global::hollowSpriteTexture());
	  glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
	  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	  glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
	  glEnable(GL_POINT_SMOOTH);
	  Vec voxelScaling = Global::voxelScaling();
	  glPointSize(50);
	  glBegin(GL_POINTS);
	  Vec pt = VECPRODUCT(m_points[0], voxelScaling);
	  glVertex3fv(pt);
	  glEnd();
	}

      glPointSize(1);  

      glDisable(GL_POINT_SPRITE);
      glDisable(GL_TEXTURE_2D);
  
      glDisable(GL_POINT_SMOOTH);
    }

  //glColor4f(col.x, col.y, col.z, qMin(1.0f,m_opacity));
  glColor4f(col.x, col.y, col.z, 1.0f);

  if (m_path.count() > 1)
    {
      if (active)
	glLineWidth(3);
      else
	glLineWidth(1);

      glBegin(GL_LINE_STRIP);
      for(int i=0; i<m_path.count(); i++)
	glVertex3fv(m_path[i]);
      glEnd();

      if (!backToFront)
	{
	  if (active)
	    glLineWidth(7);
	  else
	    glLineWidth(3);
	  
	  glColor4f(col.x*0.5,
		    col.y*0.5,
		    col.z*0.5,
		    0.5);
		    //m_opacity*0.5);
	  
	  glBegin(GL_LINE_STRIP);
	  for(int i=0; i<m_path.count(); i++)
	    glVertex3fv(m_path[i]);
	  glEnd();
	}
      glLineWidth(1);
    }

  //  glDisable(GL_LINE_SMOOTH);
}
Esempio n. 16
0
void
Tick::draw(Camera *cam, double *Xform)
{
  if (Tick::tickSize() <= 0)
    return;

  Vec dataMin, dataMax, dataSize;
  Global::bounds(dataMin, dataMax);
  Vec voxelScaling = Global::voxelScaling();
  Vec bmin = VECPRODUCT(dataMin,voxelScaling);
  Vec bmax = VECPRODUCT(dataMax,voxelScaling);

  int i;

  Vec Volcrd[8];
  Volcrd[0] = Vec(bmin.x, bmin.y, bmin.z);
  Volcrd[1] = Vec(bmax.x, bmin.y, bmin.z);
  Volcrd[2] = Vec(bmax.x, bmax.y, bmin.z);
  Volcrd[3] = Vec(bmin.x, bmax.y, bmin.z);
  Volcrd[4] = Vec(bmin.x, bmin.y, bmax.z);
  Volcrd[5] = Vec(bmax.x, bmin.y, bmax.z);
  Volcrd[6] = Vec(bmax.x, bmax.y, bmax.z);
  Volcrd[7] = Vec(bmin.x, bmax.y, bmax.z);
  
  for (i=0; i<8; i++)
    Volcrd[i] = Matrix::xformVec(Xform, Volcrd[i]);

  int pairx[4][2] = { {0,1}, {3,2}, {4,5}, {7,6} };
  int pairy[4][2] = { {0,3}, {1,2}, {4,7}, {5,6} };
  int pairz[4][2] = { {0,4}, {1,5}, {2,6}, {3,7} };

  //-----------------------------------------------------
  // get positioning

  GLdouble objz, sxmin, sxmax, symin, symax;
  GLdouble scrx[10], scry[10];

  GLdouble OModel[16];
  glMatrixMode(GL_MODELVIEW);
  glGetDoublev(GL_MODELVIEW_MATRIX, OModel);
	 
  GLdouble OProj[16];
  glMatrixMode(GL_PROJECTION);
  glGetDoublev(GL_PROJECTION_MATRIX, OProj);
	 
  GLint Oviewport[4];
  glGetIntegerv(GL_VIEWPORT, Oviewport);
	 
  Vec centroid;
  centroid = (Volcrd[0] + Volcrd[6])/2;

  gluProject((GLdouble)centroid.x,
	     (GLdouble)centroid.y,
	     (GLdouble)centroid.z,
	     OModel, OProj,
	     Oviewport,
	     &scrx[8], &scry[8], &objz);

  for(i=0; i<8; i++)
    {
      gluProject((GLdouble)Volcrd[i].x,
		 (GLdouble)Volcrd[i].y,
		 (GLdouble)Volcrd[i].z,
		 OModel, OProj,
		 Oviewport,
		 &scrx[i], &scry[i], &objz);
    }
  //-----------------------------------------------------


  //-----------------------------------------------------
  // now go into ortho mode
//  glDepthMask(GL_TRUE);
  glDisable(GL_DEPTH_TEST);
//  glDisable(GL_BLEND);
//  glDisable(GL_LIGHTING);  


  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0, cam->screenWidth(),
	  0, cam->screenHeight(),
	  -1, 1);

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  

  //-----------------------------------------------------
  // get positioning and scaling
  GLdouble MModel[16];
  GLdouble MProj[16];
  GLint viewport[4];

  glMatrixMode(GL_MODELVIEW);
  glGetDoublev(GL_MODELVIEW_MATRIX, MModel);
	 
  glMatrixMode(GL_PROJECTION);
  glGetDoublev(GL_PROJECTION_MATRIX, MProj);
	 
  glGetIntegerv(GL_VIEWPORT, viewport);
	 
  GLdouble mousez = (float)0/(pow((double)2, (double)32)-1);

  gluUnProject((GLdouble)10,
	       (GLdouble)10,
	       (GLdouble)mousez,
	       MModel, MProj,
	       viewport,
	       &sxmin, &symin, &objz);

  gluUnProject((GLdouble)20,
	       (GLdouble)20,
	       (GLdouble)mousez,
	       MModel, MProj,
	       viewport,
	       &sxmax, &symax, &objz);

  float deltax = fabs(sxmax-sxmin);
  float deltay = fabs(symax-symin);
  float sclx, scly;
  sclx = deltax*0.005 * (1+Tick::tickSize()*0.2);
  scly = deltay*0.005 * (1+Tick::tickSize()*0.2);

  GLdouble newx[10], newy[10];
  for (i=0; i<9; i++)
    {
      newx[i] = scrx[i];
      newy[i] = scry[i];
    }

  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
  glEnable(GL_LINE_SMOOTH);
  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

  int idx;
  float xc0, yc0, xc1, yc1;
  float bgintensity;
  Vec bgcolor = Global::backgroundColor();
  bgintensity = (0.3*bgcolor.x +
                 0.5*bgcolor.y +
		 0.2*bgcolor.z);

  if (bgintensity < 0.5)
    {
      glColor4f(0.9, 0.9, 0.9, 0.9);
      m_textColor = Qt::white;
    }
  else
    {
      glColor4f(0, 0, 0, 0.9);
      m_textColor = Qt::black;
    }


  //-----------------------------------------------------

  glLineWidth(1.5);

  idx = Tick::findMaxDistance(pairx, newx, newy);
  xc0 = newx[pairx[idx][0]];
  yc0 = newy[pairx[idx][0]];
  xc1 = newx[pairx[idx][1]];
  yc1 = newy[pairx[idx][1]];
  Tick::drawTick(Tick::tickStep(),
		 Volcrd[pairx[idx][0]], Volcrd[pairx[idx][1]],
		 newx[8], newy[8], 0,
		 sclx, scly,
		 OModel, OProj, Oviewport);

  idx = Tick::findMaxDistance(pairy, newx, newy);
  xc0 = newx[pairy[idx][0]];
  yc0 = newy[pairy[idx][0]];
  xc1 = newx[pairy[idx][1]];
  yc1 = newy[pairy[idx][1]];
  Tick::drawTick(Tick::tickStep(),
		 Volcrd[pairy[idx][0]], Volcrd[pairy[idx][1]],
		 newx[8], newy[8], 1,
		 sclx, scly,
		 OModel, OProj, Oviewport);

  idx = Tick::findMaxDistance(pairz, newx, newy);
  xc0 = newx[pairz[idx][0]];
  yc0 = newy[pairz[idx][0]];
  xc1 = newx[pairz[idx][1]];
  yc1 = newy[pairz[idx][1]];
  Tick::drawTick(Tick::tickStep(),
		 Volcrd[pairz[idx][0]], Volcrd[pairz[idx][1]],
		 newx[8], newy[8], 2,
		 sclx, scly,
		 OModel, OProj, Oviewport);

  //-----------------------------------------------------

  //-----------------------------------------------------
  // get back to original mode
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glPopMatrix();

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glPopMatrix();

  glEnable(GL_DEPTH_TEST);
}
Esempio n. 17
0
void
ClipGrabber::mouseMoveEvent(QMouseEvent* const event,
			    Camera* const camera)
{
  if (!m_pressed)
    return;
  
  QPoint delta = event->pos() - m_prevPos;

  Vec voxelScaling = Global::voxelScaling();

  Vec tang = m_tang;
  Vec xaxis = m_xaxis;
  Vec yaxis = m_yaxis;
  tang = Matrix::rotateVec(m_xform, tang);
  xaxis = Matrix::rotateVec(m_xform, xaxis);
  yaxis = Matrix::rotateVec(m_xform, yaxis);

  if (event->buttons() != Qt::LeftButton)
    {
      tang = VECDIVIDE(tang, voxelScaling);
      xaxis = VECDIVIDE(xaxis, voxelScaling);
      yaxis = VECDIVIDE(yaxis, voxelScaling);

      Vec trans(delta.x(), -delta.y(), 0.0f);
      
      // Scale to fit the screen mouse displacement
      trans *= 2.0 * tan(camera->fieldOfView()/2.0) *
	             fabs((camera->frame()->coordinatesOf(Vec(0,0,0))).z) /
	             camera->screenHeight();

      // Transform to world coordinate system.
      trans = camera->frame()->orientation().rotate(trans);

      Vec voxelScaling = Global::voxelScaling();
      trans = VECDIVIDE(trans, voxelScaling);

      if (event->modifiers() & Qt::ControlModifier ||
	  event->modifiers() & Qt::MetaModifier)
	{
	  if (moveAxis() < MoveY0)
	    {
	      float vx = trans*m_xaxis;
	      if (moveAxis() == MoveX0)
		setScale1(scale1() + 0.05*vx);
	      else
		setScale1(scale1() - 0.05*vx);
	    }
	  else if (moveAxis() < MoveZ)
	    {
	      float vy = trans*m_yaxis;
	      if (moveAxis() == MoveY0)
		setScale2(scale2() + 0.05*vy);
	      else
		setScale2(scale2() - 0.05*vy);
	    }
	}
      else
	{
	  if (moveAxis() < MoveY0)
	    {
	      float vx = trans*xaxis;
	      trans = vx*xaxis;
	    }
	  else if (moveAxis() < MoveZ)
	    {
	      float vy = trans*yaxis;
	      trans = vy*yaxis;
	    }
	  else if (moveAxis() == MoveZ)
	    {
	      float vz = trans*tang;
	      trans = vz*tang;
	    }
	  
	  translate(trans);
	}
    }
  else
    {
      Vec axis;
      if (moveAxis() < MoveY0) axis = xaxis;
      else if (moveAxis() < MoveZ) axis = yaxis;
      else if (moveAxis() == MoveZ) axis = tang;

      Vec voxelScaling = Global::voxelScaling();
      Vec pos = VECPRODUCT(position(), voxelScaling);
      pos = Matrix::xformVec(m_xform, pos);

      float r = size();
      Vec trans(delta.x(), -delta.y(), 0.0f);

      Vec p0 = camera->projectedCoordinatesOf(pos); p0 = Vec(p0.x, p0.y, 0);
      Vec c0 = pos + r*axis;
      c0 = camera->projectedCoordinatesOf(c0); c0 = Vec(c0.x, c0.y, 0);
      Vec perp = c0-p0;
      perp = Vec(-perp.y, perp.x, 0);
      perp.normalize();

      float angle = perp * trans;
      rotate(axis, angle);
    }

  m_prevPos = event->pos();
}