void RNDFEditGLView::mouseMoveEvent(QMouseEvent *event) {
  double x2, y2;
  pickPoint(event->x(), event->y(), &x2, &y2);
  double utm_x = x2 + gui->rndf_center.x;
  double utm_y = y2 + gui->rndf_center.y;
  std::string utm_zone = gui->rndf_center.zone;
  gui->last_utm_x = utm_x;
  gui->last_utm_y = utm_y;

  switch (event->modifiers()) {
    case Qt::ControlModifier: // selected object is affected
        // update undo buffer
      if(gui->last_rn_) {delete gui->last_rn_;}
      if(gui->last_rn_search_) {delete gui->last_rn_search_;}
      gui->last_rn_ = new rndf::RoadNetwork(*gui->rn_);
      gui->last_rn_search_ = new rndf::RoadNetworkSearch(*gui->rn_search_, gui->last_rn_);
      if (event->buttons().testFlag(Qt::LeftButton)) {
        gui->moveElement(utm_x, utm_y, utm_zone);
      }
      else if (event->buttons() & Qt::RightButton) {
        gui->rotateElement(utm_x, utm_y, utm_zone);
     }

      gui->updateSmoothedLaneStack();
      requestRedraw();
      break;

    case Qt::NoModifier:
      gui->last_mouse_x = event->x();
      gui->last_mouse_y = event->y();
      if (gui->current_element == RNDF_ELEMENT_EXIT) {
        requestRedraw();
      }
      else {
        GLWidget::mouseMoveEvent(event);
      }

    default: // let base class handle other cases
      GLWidget::mouseMoveEvent(event);
      break;
  }

  gui->last_move_utm_x = utm_x;
  gui->last_move_utm_y = utm_y;
}
예제 #2
0
파일: vao.cpp 프로젝트: omaralvarez/Cube
void VAO::sampleMesh(int samplesPerTriangle) {
    
    if (mode == GL_TRIANGLES) {
    
        this->numOfVertices = 0;
        
        CloudType::Ptr cloud (new CloudType);
    
        cloud->width = this->numOfTriangles * samplesPerTriangle;
        cloud->height  = 1;
        cloud->points.resize(cloud->width * cloud->height);
    
        int line;
        for (int i = 0; i < this->numOfTriangles; i++) {
            for (int j = 0; j < samplesPerTriangle; j++) {
                line = i*3;
            
                glm::vec3 point = pickPoint(this->vertices[line], this->vertices[line+1], this->vertices[line+2]);
                cloud->points[this->numOfVertices].x = point.x;
                cloud->points[this->numOfVertices].y = point.y;
                cloud->points[this->numOfVertices].z = point.z;
                cloud->points[this->numOfVertices].normal_x = this->normals[i].x;
                cloud->points[this->numOfVertices].normal_y = this->normals[i].y;
                cloud->points[this->numOfVertices].normal_z = this->normals[i].z;
                cloud->points[this->numOfVertices].r = this->colors[line].r * 255;
                cloud->points[this->numOfVertices].g = this->colors[line].g * 255;
                cloud->points[this->numOfVertices].b = this->colors[line].b * 255;
            
                this->numOfVertices++;
            }
        }
    
        this->cloud = cloud;
    
        this->mode = GL_POINTS;
    
    }

}
// Parses keyboard commands
void RNDFEditGLView::keyPressEvent(QKeyEvent* event) {

  uint32_t key=(uint32_t)event->key();//(*(event->text().toAscii().constData()));

  double utm_x, utm_y;
  std::string utm_zone;
  const double move_step = 2;

  if(event->modifiers() & Qt::ControlModifier) {  // all element specific keys require control modifier
    switch (event->key()) {
      case Qt::Key_Up:
        if(!gui->currentElementPosition(gui->last_move_utm_x, gui->last_move_utm_y, utm_zone)) {return;}
        printf("up: %f, %f -> %f, %f\n", gui->last_move_utm_x, gui->last_move_utm_y, gui->last_move_utm_x, gui->last_move_utm_y - move_step);
        gui->moveElement(gui->last_move_utm_x, gui->last_move_utm_y - move_step, utm_zone);
        requestRedraw();
        return;

      case Qt::Key_Down:
        if(!gui->currentElementPosition(gui->last_move_utm_x, gui->last_move_utm_y, utm_zone)) {return;}
        printf("down: %f, %f -> %f, %f\n", gui->last_move_utm_x, gui->last_move_utm_y, gui->last_move_utm_x, gui->last_move_utm_y + move_step);
        gui->moveElement(gui->last_move_utm_x, gui->last_move_utm_y + move_step, utm_zone);
        requestRedraw();
        return;

      case Qt::Key_Left:
        if(!gui->currentElementPosition(gui->last_move_utm_x, gui->last_move_utm_y, utm_zone)) {return;}
        printf("left: %f, %f -> %f, %f\n", gui->last_move_utm_x, gui->last_move_utm_y, gui->last_move_utm_x - move_step, gui->last_move_utm_y);
        gui->moveElement(gui->last_move_utm_x - move_step, gui->last_move_utm_y, utm_zone);
        requestRedraw();
        return;

      case Qt::Key_Right:
        if(!gui->currentElementPosition(gui->last_move_utm_x, gui->last_move_utm_y, utm_zone)) {return;}
        printf("right: %f, %f -> %f, %f\n", gui->last_move_utm_x, gui->last_move_utm_y, gui->last_move_utm_x + move_step, gui->last_move_utm_y);
        gui->moveElement(gui->last_move_utm_x + move_step, gui->last_move_utm_y, utm_zone);
        requestRedraw();
        return;
    }

    switch(gui->current_element) {
      case RNDF_ELEMENT_WAYPOINT:
        if(wayPointKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_LANE:
        if(laneKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_SEGMENT:
        if(segmentKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_EXIT:
        if(exitKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_PERIMETERPOINT:
        if(perimeterPointKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_PERIMETER:
        if(perimeterKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_SPOTPOINT:
        if(spotPointKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_SPOT:
        if(spotKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_ZONE:
        if(zoneKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_TRAFFIC_LIGHT:
        if(trafficLightKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;

      case RNDF_ELEMENT_CROSSWALK:
        if(crosswalkKeys(key, event->modifiers())) {requestRedraw(); return;}
        break;
      }
  }

  std::cout << "keyboard: "<< key << " (#"<< (int) key <<") ";

  bool key_handled = true;
  if (event->modifiers() & Qt::ControlModifier) { // all element specific keys require control modifier
    switch (key) {
      case 'A': {
        double x2, y2;
        std::cout << "(add element ";

        pickPoint(gui->last_mouse_x, gui->last_mouse_y, &x2, &y2);

        utm_x = x2 + gui->rndf_center.x;
        utm_y = y2 + gui->rndf_center.y;
        std::string utm_zone = gui->rndf_center.zone;

        gui->addElement(utm_x, utm_y, utm_zone);
      }
      break;

      case 'D':
      case 8:
      case 127:
        gui->removeElement();
        break;

      case 'K':
        gui->copyElement();
        break;

//      case 'F': {
//        printf("-1- %s\n", __PRETTY_FUNCTION__);
//        gui->ui.actionFindWay_Point->activate(QAction::Trigger);
//      }
//      break;

      default:
        key_handled = false;
    }
  }

  if (!key_handled) {
    switch (key) {
      case 'I':
        if (!(event->modifiers() & Qt::ShiftModifier)) {
          gui->showImagery(!gui->showImagery());
          std::cout << (gui->showImagery() ? "imagery: ON" : "imagery: OFF") << std::endl;
        }
        else {
          imagery_->cycleType();
          if (imagery_->currentType() == Imagery::NONE) {
            imagery_->cycleType();
          }
          switch (imagery_->currentType()) {
            case Imagery::COLOR:
              std::cout << "imagery type: COLOR" << std::endl;
              break;
            case Imagery::TOPO:
              std::cout << "imagery type: TOPO" << std::endl;
              break;
            case Imagery::LASER:
              std::cout << "imagery type: LASER" << std::endl;
              break;
            case Imagery::GSAT:
              std::cout << "imagery type: GOOGLE" << std::endl;
              break;
            case Imagery::DARPA:
              std::cout << "imagery type: DARPA" << std::endl;
              break;
            case Imagery::BW:
              std::cout << "imagery type: BW" << std::endl;
              break;
            default:
              std::cout << "imagery type: UNKNOWN" << std::endl;
              break;
          }
        }
        break;

      default:
        std::cout << "(no command)" << std::endl;
        break;
    }
  }

requestRedraw();
}