예제 #1
0
int TwMousePressQt(QWidget *qw, QMouseEvent *e)
{
    TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y()));
    return TwMouseButton(TW_MOUSE_PRESSED, Qt2TwMouseButtonId(e));
}
예제 #2
0
int TwMouseReleaseQt(QWidget *qw, QMouseEvent *e)
{
    TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y()));
    return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e));
}
예제 #3
0
void AlignPairWidget::paintEvent(QPaintEvent *)
{
  QPainter painter(this);
  painter.beginNativePainting();
  makeCurrent();
  if(!isValid() )return;

  glEnable(GL_DEPTH_TEST);
  glDepthMask(GL_TRUE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if(freeMesh==0 || gluedTree==0) return;

    for(int i=0;i<2;++i)
    {
      if(i==0)
        glViewport (0, 0, (GLsizei) QTLogicalToDevice(this,width()/2), (GLsizei) QTLogicalToDevice(this,height()));
      else
        glViewport (QTLogicalToDevice(this,width()/2), 0, (GLsizei) QTLogicalToDevice(this,width()/2), (GLsizei) QTLogicalToDevice(this,height()));

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(30, (AlignPairWidget::width()/2)/(float)AlignPairWidget::height(), 0.1, 100);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      gluLookAt(0,0,6,   0,0,0,   0,1,0);
      tt[i]->center=vcg::Point3f(0, 0, 0);
      tt[i]->radius= 1;
      tt[i]->GetView();
      tt[i]->Apply();
      vcg::Box3f bb;
      if(i==0) bb=freeMesh->bbox();
      else	   bb=gluedTree->gluedBBox();
      vcg::GLW::DrawMode localDM=vcg::GLW::DMFlat;
      vcg::GLW::ColorMode localCM = vcg::GLW::CMPerMesh;
      if((freeMesh->m->hasDataMask(MeshModel::MM_VERTCOLOR))&&(isUsingVertexColor)) localCM = vcg::GLW::CMPerVert;
      if((freeMesh->m->cm.fn==0)||(usePointRendering)) localDM=vcg::GLW::DMPoints;
      glPushMatrix();
      bool allowScaling = qobject_cast<AlignPairDialog *>(parent())->allowScalingCB->isChecked();
      if(allowScaling)  vcg::glScale(3.0f/bb.Diag());
      else vcg::glScale(3.0f/gluedTree->gluedBBox().Diag());
      vcg::glTranslate(-bb.Center());
      if(i==0)
      {
        freeMesh->m->render(localDM,localCM,vcg::GLW::TMNone);
        drawPickedPoints(&painter, freePickedPointVec,vcg::Color4b(vcg::Color4b::Red));
      } else				{
        foreach(MeshNode *mn, gluedTree->nodeList)
          if(mn->glued && mn != freeMesh && mn->m->visible) mn->m->render(localDM,localCM,vcg::GLW::TMNone);
        drawPickedPoints(&painter, gluedPickedPointVec,vcg::Color4b(vcg::Color4b::Blue));
      }

      int pickSide= ( pointToPick[0] < QTLogicalToDevice(this,(width()/2)) )? 0 : 1;
      if(hasToPick && pickSide==i)
      {
        vcg::Point3f pp;
        hasToPick=false;
        if(vcg::Pick<vcg::Point3f>(pointToPick[0],pointToPick[1],pp))
        {
          std::vector<vcg::Point3f> &curVec = pickSide?gluedPickedPointVec:freePickedPointVec;

          qDebug("Picked point %i %i -> %f %f %f",pointToPick[0],pointToPick[1],pp[0],pp[1],pp[2]);

          if(hasToDelete)
          {
            int bestInd = -1;
            double bestDist =10e100;
            for(int i=0;i<curVec.size();++i)
              if(Distance(pp,curVec[i])<bestDist)
              {
                bestDist = Distance(pp,curVec[i]);
                bestInd=i;
              }
            hasToDelete=false;
            if(bestInd>=0)
              curVec.erase(curVec.begin()+bestInd);
          }
          else curVec.push_back(pp);
          hasToPick=false;
          update();
        }
      }
      glPopMatrix();
      tt[i]->DrawPostApply();
    }
    doneCurrent();
    painter.endNativePainting();
}