void CloudsVisualSystemYellowTail::selfBegin(){

    //MA: changed ofGetWidth() to getCanvasWidth() and ofGetHeight() to getCanvasHeight()
    Gesture *introGesture = new Gesture(getCanvasWidth(), getCanvasHeight());
    introGesture->fromXMLFile( getVisualSystemDataPath() + "strokes/y_stroke.xml" );
    gestures.push_back(introGesture);
}
//--------------------------------------------------------------
void CloudsVisualSystemYellowTail::selfInteractionStarted(CloudsInteractionEventArgs& args){
    int touchId = args.playerId;
	
	/*
	 if (neverTouchedBefore) {
	 clearGestures();
	 neverTouchedBefore = false;
	 }
	 */
	
//    if (touchId%2 == 0){
        mNewGestureStyle = GestureStyleTraveling;
//    } else {
//        mNewGestureStyle = GestureStyleInPlace;
//    } 
    
    //MA: changed ofGetWidth() to getCanvasWidth() and ofGetHeight() to getCanvasHeight()
	Gesture *newGesture = new Gesture(getCanvasWidth(), getCanvasHeight());
	newGesture->clear();
	newGesture->clearPolygons();
	newGesture->addPoint((float)args.position.x, (float)args.position.y);
	newGesture->setStyle(mNewGestureStyle);
    
    potentialGestures.insert(newGesture);
    
    gestureForTouch[touchId] = newGesture;
}
Exemplo n.º 3
0
vector<double> GestureHMM::train(vector< Gesture* > train_set, int max_iter) {

	this->_trainset = train_set;

	field<rowvec> data(train_set.size(),1);
	vector< Gesture* >::const_iterator iter;
	int r = 0;
	for ( iter = train_set.begin(); iter != train_set.end(); ++iter ) {
		Gesture * g = *iter;
		vector<int> x = g->labels();
		data(r++,0) = conv_to< rowvec >::from(g->labels());
	}

	return HMM::train(data, max_iter);
}
//--------------------------------------------------------------
void CloudsVisualSystemYellowTail::selfInteractionDragged(CloudsInteractionEventArgs& args){
    int touchId = args.playerId;
	
    map<int,Gesture *>::iterator G = gestureForTouch.find(touchId);
	//JG removed asserts as they are a stability problem
//    assert(G != gestureForTouch.end());
	if(G == gestureForTouch.end()){
		return;
	}
    Gesture *gesture = G->second;
    
    if (gesture->distanceToLastPoint((float)args.position.x, (float)args.position.y) > minimumTravelForNewPoint) {
        
        float distanceThresholdForAdding = minimumTravelForNewPoint * 8.0;
        if (gesture->pointCount > 10){ distanceThresholdForAdding = minimumTravelForNewPoint * 2.0;}
        gesture->addPointAndHalfwayPoint((float)args.position.x, (float)args.position.y, distanceThresholdForAdding);
        
        gesture->smooth(22.0);
        gesture->compile();
    }
}
//--------------------------------------------------------------
void CloudsVisualSystemYellowTail::selfInteractionEnded(CloudsInteractionEventArgs& args){
    int touchId = args.playerId;
	
    map<int,Gesture *>::iterator G = gestureForTouch.find(touchId);
    	//JG removed asserts as they are a stability problem
	//assert(G != gestureForTouch.end());
	if(G == gestureForTouch.end()){
		return;
	}
    
	Gesture *gesture = G->second;
    
    gestureForTouch.erase(G);
    potentialGestures.erase(find(potentialGestures.begin(), potentialGestures.end(), gesture));
    
    if (gesture->isValid()) {
        gestures.push_back(gesture);
    } else {
        delete gesture;
    }
}
Exemplo n.º 6
0
void Parser::sGesture() {
    if (m_reader.isEndElement() && m_reader.name() == "gesture") {
        state.removeLast();
        return;
    } else if (m_reader.isStartElement() && m_reader.name() == "action") {
        state.append("ACTION");
        auto attrs = m_reader.attributes();
        if (!attrs.hasAttribute("type"))
            throw(err("Attribute 'type' expected."));

        Group *g = Memory::getGroup(appKey);
        g->addGest(ges->num, Lists::gT(ges->type), Lists::gD(ges->direction));
        Gesture *gest = g->getGest(ges->num, Lists::gT(ges->type), Lists::gD(ges->direction));
        gest->setAction(Lists::aT(attrs.value("type").toString()));
        //sAction(g->getGest(ges->num, Lists::gT(ges->type), Lists::gD(ges->direction))->getAction());->setAction(Lists::aT(attrs.value("type").toString()))
        QStringList params = m_reader.readElementText().split(":");
        foreach(const QString &p, params)
            gest->getAction()->addParam(p.section("=",0,0),p.section("=",1));

        state.removeLast();
    } else
Exemplo n.º 7
0
void MyListener::onFrame(const Controller& controller) 
{
    const Frame frame = controller.frame();
    const GestureList gestures = frame.gestures();
    HandList hands = frame.hands();
    
    for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
        const Hand hand = *hl;
        // Smoothing and stabilization is performed in order to make this 
        // value more suitable for interaction with 2D content. The stabilized 
        // position lags behind the palm position by a variable amount, 
        // depending primarily on the speed of movement.
        Vector position = hand.stabilizedPalmPosition();

        if (m_positionChanged)
            m_positionChanged(position[0], position[1], position[2], 
                              frame.fingers().extended().count(), 
                              hand.direction(),
                              hand.palmVelocity());

        if (m_pinch)
            m_pinch(hand.pinchStrength());

        if (m_grab)
            m_grab(hand.grabStrength());
    }

    for (int g = 0; g < gestures.count(); ++g) {
        Gesture gesture = gestures[g];
        switch (gesture.type()) {
        case Gesture::TYPE_KEY_TAP:
        case Gesture::TYPE_SCREEN_TAP:
            if (m_tapped)
                m_tapped();
            break;
        case Gesture::TYPE_SWIPE:
            break;
        }
    }
}
Exemplo n.º 8
0
// TODO : move to an external class (kind of serialization factory)
void GestureHMM::save(string filename) {
	Gesture *g;
	stringstream ss;
	fix_stream(ss);
	ofxXmlSettings XML;

	XML.clear();

	XML.addValue("name", name);

	XML.addValue("alphabet", alphabet);
	XML.addValue("hiddenStates", hiddenStates);

	XML.addValue( "prior", matrix_to_string(prior) );
	XML.addValue( "transmat", matrix_to_string(transmat) );
	XML.addValue( "obsmat", matrix_to_string(obsmat) );

	XML.addTag("gestures");
	XML.pushTag("gestures");

	int trainset_size = _trainset.size();
	for (int i = 0; i < trainset_size; ++i) {
		g = _trainset[i];

		XML.addTag("train_gestures");
		XML.addAttribute("train_gestures","num",i, i);

		XML.pushTag("train_gestures", i);
		{
			XML.addValue("labeled", to_string(g->labels()));
			XML.addValue("raw", to_string( g->points()) );
		}
		XML.popTag();
	}
	XML.popTag();

	XML.saveFile(filename);
}
Exemplo n.º 9
0
int main()
{
  GestureDB db("gesture_data.db");
  db.load();

  //cout<<*db<<endl;
  /// fetch the 7th gesture
  Gesture* gesture = db[7];
  cout<<*gesture<<endl;
  cout<<gesture->numPoint();

  gesture->filter();
  //cout<<gesture->numPoint();

  gesture->sample(17);
  cout<<*gesture<<endl;

  cout<<"similarity score"<<smith_waterman(gesture, gesture)<<endl;

  //db.save();

  return 0;
}
Exemplo n.º 10
0
void Quantizer2::init(Gesture gesture){

    radius = (gesture.getMaxacc() + gesture.getMinacc()) / 2;

    double pi = M_PI;

    // inizializza i centroidi
    centroids[0] = Sample_3d(radius, 0, 0);
    centroids[1] = Sample_3d(cos(pi/4)*radius, 0, sin(pi/4)*radius);
    centroids[2] = Sample_3d(0, 0, radius);
    centroids[3] = Sample_3d(cos(pi*3/4)*radius, 0, sin(pi*3/4)*radius);
    centroids[4] = Sample_3d(-radius, 0, 0);
    centroids[5] = Sample_3d(cos(pi*5/4)*radius, 0, sin(pi*5/4)*radius);
    centroids[6] = Sample_3d(0, 0, -radius);
    centroids[7] = Sample_3d(cos(pi*7/4)*radius, 0, sin(pi*7/4)*radius);
    centroids[8] = Sample_3d(0, radius, 0);
    centroids[9] = Sample_3d(0, cos(pi/4)*radius, sin(pi/4)*radius);
    centroids[10] = Sample_3d(0, cos(pi*3/4)*radius, sin(pi*3/4)*radius);
    centroids[11] = Sample_3d(0, -radius, 0);
    centroids[12] = Sample_3d(0, cos(pi*5/4)*radius, sin(pi*5/4)*radius);
    centroids[13] = Sample_3d(0, cos(pi*7/4)*radius, sin(pi*7/4)*radius);

}
Exemplo n.º 11
0
std::string& DTWRecognizer::decideGesture(std::vector<Recognition *>& recognitionArray, std::vector<Ogre::Vector3>& inputPattern)
{
  float minDistance = numeric_limits<float>::max();
  Recognition *minRecog = NULL;
  int minNumSamples;
  static std::string noDetect("NO_DETECT");

  std::vector<Recognition *>::iterator itr1 = recognitionArray.begin();


  for ( ; itr1 != recognitionArray.end(); itr1++)
  {
      Recognition *dataRecog = *itr1;
      std::vector<Gesture *>::iterator itr2 = dataRecog->getGestureArray().begin();
      for ( ; itr2 != dataRecog->getGestureArray().end(); itr2++)
      {
          Gesture *dataGesture = *itr2;
          SimpleDTW<Ogre::Vector3>  dtw(inputPattern, dataGesture->getLocalAccelerationArray(), ptr_fun(ogreVectorLength));
          float result = dtw.calculateDistance();
          PRINTF("(%10s(%2d)<-->Input(%2d) : %f", 
              dataRecog->getName().c_str(), dataGesture->getLocalAccelerationArray().size(),
              inputPattern.size(), result);
          if (result < minDistance) 
          {
              minDistance = result;
              minRecog = dataRecog;
              minNumSamples = dataGesture->getLocalAccelerationArray().size();
          }
      }
  }

  PRINTF("DECISION: %10s(%2d, %2d)(distance:%5.1f)", minRecog->getName().c_str(), minNumSamples, inputPattern.size(), minDistance);

  return minRecog->getName();

  return (minDistance < 256.0f ? minRecog->getName() : noDetect);
}
Exemplo n.º 12
0
std::vector<int> Quantizer2::getDiscreteSequence(Gesture& gesture){

    this->init(gesture);
    std::vector<Sample_3d> data = gesture.getData();
    int size = data.size();

    // associazioni (componente della gesture) <-> centroide
    std::vector<int> assoc;
    for(int i=0; i<size; i++)
        assoc.push_back(-1);

    // n° vettori associati a ciascun centroide
    int numVectPerCentroid[n_centroids];
    for(int i=0; i<n_centroids; i++ )
        numVectPerCentroid[i] = 0;


    // determina centroide a distanza minima per ogni vettore
    for(int i=0; i<size; i++){

        // minima distanza finora riscontrata
        double min_dist = std::numeric_limits<double>::max();
        // centroide a minima distanza
        int centroid_count = -1;

        for(int j=0; j<n_centroids; j++){

            // calcola la distanza dell'elemento dal centroide corrente
            double d = distance(data.at(i), centroids[j]);

            // se la nuova distanza è minore della minima finora riscontrata,
            // allora il centroide è il più vicino
            if(d < min_dist){
                min_dist = d;
                centroid_count = j;
            }

        }//j

        // associa il sample al centroide più vicino
        if(assoc.at(i) != centroid_count){
            assoc.at(i) = centroid_count;
        }
    }//i

    return assoc;

}
Exemplo n.º 13
0
Gesture *GestureHandler::createGesture(const QString &type, int id, const QHash<QString, QVariant>& attrs,
    bool isComposedGesture) const
{
    // Creamos el gesto sin su acción
    Gesture *ret;
    if (isComposedGesture)
        ret = this->gestureFact->createComposedGesture(type, id, attrs);
    else
        ret = this->gestureFact->createSimpleGesture(type, id, attrs);

    if (ret == NULL)
        return NULL;

    // Vemos sobre que ventana se ha ejecutado
    Window gestureWindow = this->getGestureWindow(attrs.value(GEIS_GESTURE_ATTRIBUTE_CHILD_WINDOW_ID).toInt());
    if (gestureWindow == None)
        return NULL;
    QString appClass = this->getAppClass(gestureWindow);

    // Creamos y asignamos la acción asociada al gesto
    ActionTypeEnum::ActionType actionType = this->config->getAssociatedAction(appClass, ret->getType(),
            ret->getNumFingers(), ret->getDirection());
    QString actionSettings = this->config->getAssociatedSettings(appClass, ret->getType(), ret->getNumFingers(),
            ret->getDirection());

    ret->setAction(this->actionFact->createAction(actionType, actionSettings, gestureWindow));

    // Mostramos los datos sobre el gesto
    qDebug() << "[+] New gesture:";
    qDebug() << "\tType      -> " << GestureTypeEnum::getValue(ret->getType());
    qDebug() << "\tFingers   -> " << ret->getNumFingers();
    qDebug() << "\tDirection -> " << GestureDirectionEnum::getValue(ret->getDirection());
    qDebug() << "\tAction    -> " << ActionTypeEnum::getValue(actionType);
    qDebug() << "\tApp Class -> " << appClass;

    return ret;
}
Exemplo n.º 14
0
void Leap::LeapListener::onFrame( const Controller& controller )
{
	Frame frame = controller.frame();
	HandList hands = frame.hands();
	Leap::DirectionDetector::Direction direction;
	//bool handExtended;
	Hand leftHand;
	Hand rightHand;

	//jurik
	//takin just first gesture (gestures are defined for each finger)
	Gesture gesture = frame.gestures()[0];


	if ( arMode ) {
		for ( int i=0; i< hands.count(); ++i ) {
			if ( hands[i].isRight() ) {
				rightHand = hands[i];
			}
			else {
				leftHand = hands[i];
			}
		}
		leapActions->updateARHands( leftHand,rightHand );
	}
	else {
		for ( int i=0; i< hands.count(); ++i ) {
			if ( hands[i].isRight() ) {
				direction = Leap::DirectionDetector::getPalmDirection( hands[i] );
				//using cameramanipulator
				//leapActions->changeViewAngle( direction );
				//using pickhandler class
				leapActions->rotateAruco( direction );

				if ( gesture.type() == Gesture::TYPE_KEY_TAP ) {
					leapActions->scaleNodes( true );
				}
			}
			else {
				direction = Leap::DirectionDetector::getPalmDirection( hands[i] );
				//leapActions.changeViewAngle( direction );
				leapActions->scaleEdges( direction );
				if ( gesture.type() == Gesture::TYPE_KEY_TAP ) {
					leapActions->scaleNodes( false );
				}

				/*handExtended = Leap::FingerPositionDetector::isHandExtended( hands[i] );
				if ( handExtended ) {
					leapActions->startMovingForward();
				}
				else {
					leapActions->stopMovingForward();
				}*/
			}
		}
	}

	//std::cout << "id: " << frame.id();
	/*
	    const GestureList gestures = frame.gestures();
	      for (int g = 0; g < gestures.count(); ++g) {
	        Gesture gesture = gestures[g];

	        HandList hands = gesture.hands();
	        Hand firstHand = hands[0];

	        switch (gesture.type()) {
	          case Gesture::TYPE_CIRCLE:
	          {
				leapActions->zoomGraph(gesture);
	            break;
	          }
	          case Gesture::TYPE_SWIPE:
	          {
	            if(firstHand.isRight()){
					if(leapActions->isCameraMoving)
						leapActions->moveCamera(gesture);
	                else
					  leapActions->rotateGraph(gesture);
	            }
	            break;
	          }
	          case Gesture::TYPE_KEY_TAP:
	          {
	            if(firstHand.isLeft())
					leapActions->onKeyTap(gesture);
	            break;
	          }
	          case Gesture::TYPE_SCREEN_TAP:
	          {
				leapActions->onScreenTap(gesture);
	            break;
	          }
	          default:
	            qDebug() << "Unknown gesture type.";
	            break;
	        }
	      }*/


}
Exemplo n.º 15
0
void SampleListener::onFrame(const Controller& controller) {
  // Get the most recent frame and report some basic information
  const Frame frame = controller.frame();
  std::cout << "Frame id: " << frame.id()
            << ", timestamp: " << frame.timestamp()
            << ", hands: " << frame.hands().count()
            << ", fingers: " << frame.fingers().count()
            << ", tools: " << frame.tools().count()
            << ", gestures: " << frame.gestures().count() << std::endl;

  if (!frame.hands().isEmpty()) {
    // Get the first hand
    const Hand hand = frame.hands()[0];

    // Check if the hand has any fingers
    const FingerList fingers = hand.fingers();
    if (!fingers.isEmpty()) {
      // Calculate the hand's average finger tip position
      Vector avgPos;
      for (int i = 0; i < fingers.count(); ++i) {
        avgPos += fingers[i].tipPosition();
      }
      avgPos /= (float)fingers.count();
      std::cout << "Hand has " << fingers.count()
                << " fingers, average finger tip position" << avgPos << std::endl;
    }

    // Get the hand's sphere radius and palm position
    std::cout << "Hand sphere radius: " << hand.sphereRadius()
              << " mm, palm position: " << hand.palmPosition() << std::endl;

    // Get the hand's normal vector and direction
    const Vector normal = hand.palmNormal();
    const Vector direction = hand.direction();

    // Calculate the hand's pitch, roll, and yaw angles
    std::cout << "Hand pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
              << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
              << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;
  }

  // Get gestures
  const GestureList gestures = frame.gestures();
  for (int g = 0; g < gestures.count(); ++g) {
    Gesture gesture = gestures[g];

    switch (gesture.type()) {
      case Gesture::TYPE_CIRCLE:
      {
        CircleGesture circle = gesture;
        std::string clockwiseness;

        if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) {
          clockwiseness = "clockwise";
        } else {
          clockwiseness = "counterclockwise";
        }

        // Calculate angle swept since last frame
        float sweptAngle = 0;
        if (circle.state() != Gesture::STATE_START) {
          CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
          sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
        }
        std::cout << "Circle id: " << gesture.id()
                  << ", state: " << gesture.state()
                  << ", progress: " << circle.progress()
                  << ", radius: " << circle.radius()
                  << ", angle " << sweptAngle * RAD_TO_DEG
                  <<  ", " << clockwiseness << std::endl;
        break;
      }
      case Gesture::TYPE_SWIPE:
      {
        SwipeGesture swipe = gesture;
        std::cout << "Swipe id: " << gesture.id()
          << ", state: " << gesture.state()
          << ", direction: " << swipe.direction()
          << ", speed: " << swipe.speed() << std::endl;
        break;
      }
      case Gesture::TYPE_KEY_TAP:
      {
        KeyTapGesture tap = gesture;
        std::cout << "Key Tap id: " << gesture.id()
          << ", state: " << gesture.state()
          << ", position: " << tap.position()
          << ", direction: " << tap.direction()<< std::endl;
        break;
      }
      case Gesture::TYPE_SCREEN_TAP:
      {
        ScreenTapGesture screentap = gesture;
        std::cout << "Screen Tap id: " << gesture.id()
        << ", state: " << gesture.state()
        << ", position: " << screentap.position()
        << ", direction: " << screentap.direction()<< std::endl;
        break;
      }
      default:
        std::cout << "Unknown gesture type." << std::endl;
        break;
    }
  }

  if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
    std::cout << std::endl;
  }
}
Exemplo n.º 16
0
	void SampleListener::onFrame(const Controller& controller) 
	{
	  
		// Get the most recent frame and report some basic information
	  const Frame frame = controller.frame();

		int currentFrameId = frame.id();
		//std::cout << "CurrentFrameId " << currentFrameId << std::endl;

		if (frame.hands().count() > 0)
		{	
				//std::cout << "Frame id: " << frame.id()
				//<< ", timestamp: " << frame.timestamp()
				//<< ", hands: " << frame.hands().count()
			//	<< ", fingers: " << frame.fingers().count()
			//	<< ", tools: " << frame.tools().count()
			//	<< ", gestures: " << frame.gestures().count() << std::endl;
	
				// Dealing with the hands

		  if (!frame.hands().empty()) 
		  {
			// Get the first hand
			const Hand hand = frame.hands()[0];

			// Check if the hand has any fingers
			const FingerList fingers = hand.fingers();
			if (!fingers.empty()) {
			  // Calculate the hand's average finger tip position
			  Vector avgPos;
			  for (int i = 0; i < fingers.count(); ++i) {
				avgPos += fingers[i].tipPosition();
			  }
			  avgPos /= (float)fingers.count();
			  //std::cout << "Hand has " << fingers.count()
						//<< " fingers, average finger tip position" << avgPos << std::endl;
			}

			// Get the hand's sphere radius and palm position
			/*std::cout << "Hand sphere radius: " << hand.sphereRadius()
					  << " mm, palm position: " << hand.palmPosition() << std::endl;*/

			//deatecting Up and Down hand motions
			Vector myPalmPosition = hand.palmPosition();

			double currentPalmPositionY = myPalmPosition.y;

			if (currentPalmPositionY > lastPalmPositionY) 
			{
				std::cout << "[moving up";
			}
			else
			{
				std::cout << "[moving down";
			}

			lastPalmPositionY = currentPalmPositionY;

			//deatecting left and right hand motions
			myPalmPosition = hand.palmPosition();

			double currentPalmPositionX = myPalmPosition.x;

			if (currentPalmPositionX > lastPalmPositionX) 
			{
				std::cout << "/right] ";
			}
			else
			{
				std::cout << "/left] ";
			}

			lastPalmPositionX = currentPalmPositionX;

			// Get the hand's normal vector and direction
			const Vector normal = hand.palmNormal();
			const Vector direction = hand.direction();

			// Calculate the hand's pitch, roll, and yaw angles
			//std::cout << "Hand pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
					//  << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
					//<< "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;
	 
			//Find Gestures
// Get gestures
	  const GestureList gestures = frame.gestures();
	  for (int g = 0; g < gestures.count(); ++g) {
		Gesture gesture = gestures[g];

		switch (gesture.type()) {
		  case Gesture::TYPE_CIRCLE:
		  {
			CircleGesture circle = gesture;
			std::string clockwiseness;

			if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) {
			  std::cout << " CLOCKWISE";
			} else {
			  std::cout << " ANTICLOCKWISE";
			}
			break;
		  }
		  case Gesture::TYPE_SWIPE:
		  {
			std::cout << " SWIPE";
			break;
		  }
		  case Gesture::TYPE_KEY_TAP:
		  {
			std::cout << " KEY TAP";
			break;
		  }
		  case Gesture::TYPE_SCREEN_TAP:
		  {
			std::cout << " SCREEN TAP";
			break;
		  }
		  default:
			std::cout << "Unknown gesture type." << std::endl;
			break;
		}
	  }
			if (!frame.hands().empty()) {
					std::cout << std::endl;
			}

  } // end if frame print
  } // end on frame
} /* end class SampleListener */
Exemplo n.º 17
0
void LeapListener::onFrame(const Controller & controller) {
    // Get the most recent frame and report some basic information
    const Frame frame = controller.frame();
    std::cout << "Frame id: " << frame.id()
    << ", timestamp: " << frame.timestamp()
    << ", hands: " << frame.hands().count()
    << ", extended fingers: " << frame.fingers().extended().count()
    << ", tools: " << frame.tools().count()
    << ", gestures: " << frame.gestures().count() << std::endl;

    HandList hands = frame.hands();
    for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
        // Get the first hand
        const Hand hand = *hl;
        std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
        std::cout << std::string(2, ' ') << handType << ", id: " << hand.id()
        << ", palm position: " << hand.palmPosition() << std::endl;
        // Get the hand's normal vector and direction
        const Vector normal = hand.palmNormal();
        const Vector direction = hand.direction();

        // Calculate the hand's pitch, roll, and yaw angles
        std::cout << std::string(2, ' ') <<  "pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
        << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
        << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;

        // Get the Arm bone
        Arm arm = hand.arm();
        std::cout << std::string(2, ' ') <<  "Arm direction: " << arm.direction()
        << " wrist position: " << arm.wristPosition()
        << " elbow position: " << arm.elbowPosition() << std::endl;

        // Get fingers
        const FingerList fingers = hand.fingers();
        for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
            const Finger finger = *fl;
            std::cout << std::string(4, ' ') <<  fingerNames[finger.type()]
            << " finger, id: " << finger.id()
            << ", length: " << finger.length()
            << "mm, width: " << finger.width() << std::endl;

            // Get finger bones
            for (int b = 0; b < 4; ++b) {
                Bone::Type boneType = static_cast<Bone::Type>(b);
                Bone bone = finger.bone(boneType);
                std::cout << std::string(6, ' ') <<  boneNames[boneType]
                << " bone, start: " << bone.prevJoint()
                << ", end: " << bone.nextJoint()
                << ", direction: " << bone.direction() << std::endl;
            }
        }
    }

    // Get tools
    const ToolList tools = frame.tools();
    for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
        const Tool tool = *tl;
        std::cout << std::string(2, ' ') <<  "Tool, id: " << tool.id()
        << ", position: " << tool.tipPosition()
        << ", direction: " << tool.direction() << std::endl;
    }

    // Get gestures
    const GestureList gestures = frame.gestures();
    for (int g = 0; g < gestures.count(); ++g) {
        Gesture gesture = gestures[g];

        switch (gesture.type()) {
            case Gesture::TYPE_CIRCLE: {
                CircleGesture circle = gesture;
                std::string clockwiseness;

                if (circle.pointable().direction().angleTo(circle.normal()) <= PI/2) {
                    clockwiseness = "clockwise";
                } else {
                    clockwiseness = "counterclockwise";
                }

                // Calculate angle swept since last frame
                float sweptAngle = 0;
                if (circle.state() != Gesture::STATE_START) {
                    CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
                    sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
                }
                std::cout << std::string(2, ' ')
                << "Circle id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", progress: " << circle.progress()
                << ", radius: " << circle.radius()
                << ", angle " << sweptAngle * RAD_TO_DEG
                <<  ", " << clockwiseness << std::endl;
                break;
            }
            case Gesture::TYPE_SWIPE: {
                SwipeGesture swipe = gesture;
                std::cout << std::string(2, ' ')
                << "Swipe id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", direction: " << swipe.direction()
                << ", speed: " << swipe.speed() << std::endl;
                break;
            }
            case Gesture::TYPE_KEY_TAP: {
                KeyTapGesture tap = gesture;
                std::cout << std::string(2, ' ')
                << "Key Tap id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", position: " << tap.position()
                << ", direction: " << tap.direction()<< std::endl;
                break;
            }
            case Gesture::TYPE_SCREEN_TAP: {
                ScreenTapGesture screentap = gesture;
                std::cout << std::string(2, ' ')
                << "Screen Tap id: " << gesture.id()
                << ", state: " << stateNames[gesture.state()]
                << ", position: " << screentap.position()
                << ", direction: " << screentap.direction() << std::endl;
                break;
            }
            default:
                std::cout << std::string(2, ' ')  << "Unknown gesture type." << std::endl;
                break;
        }
    }

    if (!frame.hands().isEmpty() || !gestures.isEmpty())
        std::cout << std::endl;
}
Exemplo n.º 18
0
void QLeapEventListener::onFrame(const Controller & controller)
{
    const Frame frame = controller.frame();
    // Get gestures
    const GestureList gestures = frame.gestures();
    for (int g = 0; g < gestures.count(); ++g) {
      Gesture gesture = gestures[g];

      switch (gesture.type()) {
        case Gesture::TYPE_CIRCLE:
        {
          CircleGesture circle = gesture;
          std::string clockwiseness;

          if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) {
            clockwiseness = "clockwise";
          } else {
            clockwiseness = "counterclockwise";
          }

          // Calculate angle swept since last frame
          float sweptAngle = 0;
          if (circle.state() != Gesture::STATE_START) {
            CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
            sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
          }
          std::cout << "Circle id: " << gesture.id()
                    << ", state: " << gesture.state()
                    << ", progress: " << circle.progress()
                    << ", radius: " << circle.radius()
                    << ", angle " << sweptAngle * RAD_TO_DEG
                    <<  ", " << clockwiseness << std::endl;
          break;
        }
        case Gesture::TYPE_SWIPE:
        {
          SwipeGesture swipe = gesture;
          std::cout << "Swipe id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", direction: " << swipe.direction()
            << ", speed: " << swipe.speed() << std::endl;
          onSwipe(swipe);
          break;
        }
        case Gesture::TYPE_KEY_TAP:
        {
          KeyTapGesture tap = gesture;
          std::cout << "Key Tap id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", position: " << tap.position()
            << ", direction: " << tap.direction()<< std::endl;
          break;
        }
        case Gesture::TYPE_SCREEN_TAP:
        {
          ScreenTapGesture screentap = gesture;
          std::cout << "Screen Tap id: " << gesture.id()
          << ", state: " << gesture.state()
          << ", position: " << screentap.position()
          << ", direction: " << screentap.direction()<< std::endl;
          break;
        }
        default:
          std::cout << "Unknown gesture type." << std::endl;
          break;
      }
    }
}
Exemplo n.º 19
0
void LeapHands::onFrame(const Controller& controller) 
{
	//Game::Instance()->PrintFloat("Hand children: ", childrenMap.size());	
	std::map<string, BoneData> tempBoneData;
	HandList hands = controller.frame().hands();
	int handId = 0;

	hands[0].fingers()[(int) Finger::Type::TYPE_THUMB];

	for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
		// Get the first hand
		const Hand hand = *hl;
		// Get fingers
		const FingerList fingers = hand.fingers();
		int fingerId = 0;
		bool firstFinger = true;
		Finger previousFinger;

		stringstream ass;
		ass << "Arm: 0 Hand: " << handId;
		tempBoneData[ass.str()] = BoneData(ass.str(), LeapToGlVec3(hand.arm().wristPosition()), LeapToGlVec3(hand.arm().elbowPosition()), true);
		ass.clear();

		glm::vec3 thumbBone = LeapToGlVec3(hand.fingers()[Finger::Type::TYPE_THUMB].bone(Bone::Type::TYPE_DISTAL).nextJoint());
		glm::vec3 indexBone = LeapToGlVec3(hand.fingers()[Finger::Type::TYPE_INDEX].bone(Bone::Type::TYPE_DISTAL).nextJoint());
		pinchDist = glm::length(thumbBone - indexBone);
		if (pinchDist < 5.0f)
		{
			pinch = true;
		}
		else
		{
			pinch = false;
		}

		for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
			const Finger finger = *fl;

			// Get finger bones
			for (int b = 0; b < 4; ++b) {
				Bone::Type boneType = static_cast<Bone::Type>(b);
				Bone bone = finger.bone(boneType);
				stringstream ss;
				ss << "Hand: " << handId << " Finger: " << fingerId << " Bone: " << b;
				tempBoneData[ss.str()] = BoneData(ss.str(), LeapToGlVec3(bone.prevJoint()), LeapToGlVec3(bone.nextJoint()), true);


			}
			// Draw some other bits of the hand
			if (!firstFinger)
			{
				for (int b = 0; b < 2; ++b)
				{
					stringstream ss;
					ss << "Hand: " << handId << "Finger: " << (fingerId - 1) << "Finger: " << (fingerId) << " Bone: " << b;
					Bone startBone = previousFinger.bone(static_cast<Bone::Type>(b));
					Bone endBone = finger.bone(static_cast<Bone::Type>(b));
					if ((b == 1) && (fingerId == 1))
					{
						tempBoneData[ss.str()] = BoneData(ss.str(), LeapToGlVec3(startBone.nextJoint()), LeapToGlVec3(endBone.prevJoint()), false);
					}
					else
					{
						tempBoneData[ss.str()] = BoneData(ss.str(), LeapToGlVec3(startBone.prevJoint()), LeapToGlVec3(endBone.prevJoint()), false);
					}
				}
			}

			const GestureList gestures = controller.frame().gestures();
			for (int g = 0; g < gestures.count(); ++g) 
			{
				Gesture gesture = gestures[g];

				switch (gesture.type())
				{
					case Gesture::TYPE_CIRCLE:
					{
						CircleGesture circle = gesture;
						if (gesture.durationSeconds() > 1)
						{
							if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) {
								
								spawn = vehicle;
							}
							else {
								spawn = model;
							}
						}
					}
				}
			}

			previousFinger = finger;
			firstFinger = false;
			++fingerId;
		}
		++handId;
	}	
	EnterCriticalSection(&criticalSection);
	trackedHands = handId;
	map<string, BoneData>::iterator it = tempBoneData.begin();
	boneData = tempBoneData;
	LeaveCriticalSection(&criticalSection);
}
Exemplo n.º 20
0
    //old gesture config
    void KinectARTTransfUnit::GESTURE(const GestureEvent * event){

        Gesture recGesture = event->getPayload();
        std::cout << "gesture arrived with id: " << recGesture << std::endl;

        if(recGesture.getGestureType() == Gesture::Wave){
            std::cout << "wave !!" << std::endl;
            m_dev = (m_dev+1)%3;
        }
        else if(recGesture.getGestureType() == Gesture::Click){
            std::cout << "click !!" << std::endl;

            if(m_dev == 2){
                DigitalChangedEvent * dig_event = new DigitalChangedEvent();

                if(clicked)
                    dig_event->setPayload(0);
                else
                    dig_event->setPayload(1);

                clicked = !clicked;

                map<string, IEventSink *>::iterator iter = this->registeredEventSinkMap->find("Menu_OUT");

                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(dig_event);
                } else {
                    TFERROR("not found");
                }

            }

        }
        else if(recGesture.getGestureType() == Gesture::Grab){
            std::cout << "grab it !!" << std::endl;
            DigitalChangedEvent * dig_event = new DigitalChangedEvent();

            dig_event->setPayload(1);

            map<string, IEventSink *>::iterator iter;

            if(m_dev == 0){
                iter = this->registeredEventSinkMap->find("Draw_OUT");
                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(dig_event);
                } else {
                    TFERROR("not found");
                }
            }
            else if (m_dev == 1){
                iter = this->registeredEventSinkMap->find("Grab_OUT");
                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(dig_event);
                } else {
                    TFERROR("not found");
                }
            }
            else{
                AnalogChangedEvent * ana_event = new AnalogChangedEvent();

                ana_event->setPayload(1.0f);

                map<string, IEventSink *>::iterator  iter = this->registeredEventSinkMap->find("DrawStroke_OUT");
                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(ana_event);
                } else {
                    TFERROR("not found");
                }
            }

        }
        else if(recGesture.getGestureType() == Gesture::NoMoreGrab){
            std::cout << "no more grab !!" << std::endl;
            DigitalChangedEvent * dig_event = new DigitalChangedEvent();

            dig_event->setPayload(0);

            map<string, IEventSink *>::iterator iter;

            if(m_dev == 0){
                iter = this->registeredEventSinkMap->find("Draw_OUT");
                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(dig_event);
                } else {
                    TFERROR("not found");
                }
            }
            else if (m_dev == 1){
                iter = this->registeredEventSinkMap->find("Grab_OUT");
                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(dig_event);
                } else {
                    TFERROR("not found");
                }
            }
            else{
                AnalogChangedEvent * ana_event = new AnalogChangedEvent();

                ana_event->setPayload(0.0f);

                map<string, IEventSink *>::iterator  iter = this->registeredEventSinkMap->find("DrawStroke_OUT");
                if (iter != this->registeredEventSinkMap->end()) {
                    (*iter).second->push(ana_event);
                } else {
                    TFERROR("not found");
                }
            }
        }
        else if(recGesture.getGestureType() == Gesture::NoGesture){
            std::cout << "no gesture !!" << std::endl;
        }
    }
Exemplo n.º 21
0
void LeapInput::onFrame(const Controller& controller)
{
	Frame frame = controller.frame();
	HandList hands = frame.hands();
	this->hands = hands.count();
	if(hands.count() == 2)
	{
		Hand leftHand = hands.leftmost();
		Hand rightHand = hands.rightmost();
		leftHandY = leftHand.palmPosition().y;
		rightHandY = rightHand.palmPosition().y;
		leftFingers = leftHand.fingers().count();
		rightFingers = rightHand.fingers().count();

		float threshold = tanf(5* 3.141592f / 180.0f);
		float maxTan = tanf(45 * 3.141592f / 180.0f);
		if(leftHand.palmPosition().x != rightHand.palmPosition().x){
			float tanValue = fabs((leftHand.palmPosition().y - rightHand.palmPosition().y) / (leftHand.palmPosition().x - rightHand.palmPosition().x));
			if(tanValue > threshold){
				curve = tanValue  / maxTan;
				if(curve > 1)
					curve = 1;
			}else
				curve = 0;
		}else
			curve = 0;
	}
	else
	{
		leftHandY = rightHandY = 0;
	}

	boost = false;
	GestureList gestureList = frame.gestures();
	for(GestureList::const_iterator i = gestureList.begin(); i != gestureList.end(); ++i)
	{
		Gesture gesture = *i;
		if(gesture.state() != Gesture::State::STATE_INVALID)
		{
			switch(gesture.type())
			{
			case Gesture::Type::TYPE_SCREEN_TAP:
				boost = true;
				break;
			}
			
		}
	}

	back = false;
	if(hands.count() == 2 && leftFingers == 1 && rightFingers == 1 &&
		hands.leftmost().fingers()[0].direction().z > 0 &&
		hands.rightmost().fingers()[0].direction().z > 0)
	{
		back = true;
	}

	//accelGesture = brakeGesture = false;
	//GestureList gestureList = frame.gestures();
	//for(GestureList::const_iterator i = gestureList.begin(); i != gestureList.end(); ++i)
	//{
	//	Gesture gesture = *i;
	//	if(gesture.state() != Gesture::State::STATE_INVALID)
	//	{
	//		if(typeid(gesture) == typeid(MyGesture))
	//		{
	//			accelGesture = true;
	//		}
	//		
	//	}
	//}
}
Exemplo n.º 22
0
/*----------------------------------------------------------------------------------------------------*/
void Gestures::sendGesture(const Gesture& pGesture) {
    if ( !pGesture.isValid() ) {
        return;
    }

    Gesture::Type type = pGesture.type();
    Gesture::State state = pGesture.state();
    int64_t duration = pGesture.duration();

    Leap::Vector position;
    Leap::Vector direction;
    float progress = 0;
    float speed = 0;
    float radius = 0;
    std::string typeKey;
    std::string stateName;

    ////

    if ( type == Gesture::TYPE_CIRCLE ) {
        CircleGesture circle = (CircleGesture)pGesture;
        position = circle.center();
        progress = circle.progress();
        radius = circle.radius();
        typeKey = GestureKey::Circle;
    }
    else if ( type == Gesture::TYPE_SWIPE ) {
        SwipeGesture swipe = (SwipeGesture)pGesture;
        position = swipe.startPosition();
        direction = swipe.direction();
        speed = swipe.speed();
        typeKey = GestureKey::Swipe;
    }
    else if ( type == Gesture::TYPE_KEY_TAP ) {
        KeyTapGesture keyTap = (KeyTapGesture)pGesture;
        position = keyTap.position();
        direction = keyTap.direction();
        progress = keyTap.progress();
        typeKey = GestureKey::KeyTap;
    }
    else if ( type == Gesture::TYPE_SCREEN_TAP ) {
        ScreenTapGesture screenTap = (ScreenTapGesture)pGesture;
        position = screenTap.position();
        direction = screenTap.direction();
        progress = screenTap.progress();
        typeKey = GestureKey::ScreenTap;
    }
    else {
        std::cout << "[LEAP] Unsupported gesture type: " << type << std::endl;
        return;
    }

    ////

    switch ( state ) {
    case Gesture::STATE_INVALID:
        stateName = "Invalid";
        break;

    case Gesture::STATE_START:
        stateName = "Start";
        break;

    case Gesture::STATE_UPDATE:
        stateName = "Update";
        break;

    case Gesture::STATE_STOP:
        stateName = "Stop";
        break;

    default:
        std::cout << "[LEAP] Unsupported state type: " << state << std::endl;
        return;
    }

    ////

    std::cout << "GESTURE MESSAGE" <<
              "\n - type: " << type << " (" << typeKey << ")" <<
              "\n - stat: " << state << " (" << stateName << ")" <<
              "\n - dura: " << duration <<
              "\n - pos:  " << position <<
              "\n - dir:  " << direction <<
              "\n - prog: " << progress <<
              "\n - radi: " << radius <<
              "\n - spd:  " << speed <<
              "\n" << std::endl;
}
Exemplo n.º 23
0
    FREObject LNLeapDevice::getFrame() {
        
        Frame frame = controller->frame();
        
        // TODO: Only continue with valid Frame?
        
        FREObject freCurrentFrame;
        FRENewObject( (const uint8_t*) "com.leapmotion.leap.Frame", 0, NULL, &freCurrentFrame, NULL);
        
        FREObject freFrameId;
        FRENewObjectFromInt32((int32_t) frame.id(), &freFrameId);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "id", freFrameId, NULL);
        
        const Vector frameTranslation = frame.translation(lastFrame);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "translationVector", createVector3(frameTranslation.x, frameTranslation.y, frameTranslation.z), NULL);
        
        const Matrix frameRotation = frame.rotationMatrix(lastFrame);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "rotation", createMatrix(
                     createVector3(frameRotation.xBasis[0], frameRotation.xBasis[1], frameRotation.xBasis[2]),
                     createVector3(frameRotation.yBasis[0], frameRotation.yBasis[1], frameRotation.yBasis[2]),
                     createVector3(frameRotation.zBasis[0], frameRotation.zBasis[1], frameRotation.zBasis[2]),
                     createVector3(frameRotation.origin[0], frameRotation.origin[1], frameRotation.origin[2])
        ), NULL);
        
        FREObject freFrameScaleFactor;
        FRENewObjectFromDouble(frame.scaleFactor(lastFrame), &freFrameScaleFactor);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "scaleFactorNumber", freFrameScaleFactor, NULL);
        
        FREObject freTimestamp;
        FRENewObjectFromInt32((int32_t) frame.timestamp(), &freTimestamp);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "timestamp", freTimestamp, NULL);
        
        std::map<int, FREObject> freHandsMap;
        if (!frame.hands().empty()) {
            
            FREObject freHands;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "hands", &freHands, NULL);
            
            for(int i = 0; i < frame.hands().count(); i++) {
                const Hand hand = frame.hands()[i];
                
                FREObject freHand;
                FRENewObject( (const uint8_t*) "com.leapmotion.leap.Hand", 0, NULL, &freHand, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "frame", freCurrentFrame, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "direction", createVector3(hand.direction()[0], hand.direction()[1], hand.direction()[2]), NULL);
                
                FREObject freHandId;
                FRENewObjectFromInt32(hand.id(), &freHandId);
                FRESetObjectProperty(freHand, (const uint8_t*) "id", freHandId, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmNormal", createVector3(hand.palmNormal()[0], hand.palmNormal()[1], hand.palmNormal()[2]), NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmPosition", createVector3(hand.palmPosition()[0], hand.palmPosition()[1], hand.palmPosition()[2]), NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmVelocity", createVector3(hand.palmVelocity()[0], hand.palmVelocity()[1], hand.palmVelocity()[2]), NULL);
                
                const Matrix rotation = hand.rotationMatrix(lastFrame);
                FRESetObjectProperty(freHand, (const uint8_t*) "rotation", createMatrix(
                                     createVector3(rotation.xBasis[0], rotation.xBasis[1], rotation.xBasis[2]),
                                     createVector3(rotation.yBasis[0], rotation.yBasis[1], rotation.yBasis[2]),
                                     createVector3(rotation.zBasis[0], rotation.zBasis[1], rotation.zBasis[2]),
                                     createVector3(rotation.origin[0], rotation.origin[1], rotation.origin[2])
                ), NULL);
                
                FREObject freScaleFactor;
                FRENewObjectFromDouble(hand.scaleFactor(lastFrame), &freScaleFactor);
                FRESetObjectProperty(freHand, (const uint8_t*) "scaleFactorNumber", freScaleFactor, NULL);
                
                FRESetObjectProperty(freHand, (const uint8_t*) "sphereCenter", createVector3(hand.sphereCenter()[0], hand.sphereCenter()[1], hand.sphereCenter()[2]), NULL);
                
                FREObject freSphereRadius;
                FRENewObjectFromDouble(hand.sphereRadius(), &freSphereRadius);
                FRESetObjectProperty(freHand, (const uint8_t*) "sphereRadius", freSphereRadius, NULL);
                
                const Vector translation = hand.translation(lastFrame);
                FRESetObjectProperty(freHand, (const uint8_t*) "translationVector", createVector3(translation.x, translation.y, translation.z), NULL);
                
                FRESetArrayElementAt(freHands, i, freHand);
                
                freHandsMap[hand.id()] = freHand;
            }
        }
        
        std::map<int, FREObject> frePointablesMap;
        if(!frame.pointables().empty()) {
            
            FREObject frePointables;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "pointables", &frePointables, NULL);
            
            for(int i = 0; i < frame.pointables().count(); i++) {
                const Pointable pointable = frame.pointables()[i];
                
                FREObject frePointable;
                if(pointable.isTool()) {
                    FRENewObject( (const uint8_t*) "com.leapmotion.leap.Tool", 0, NULL, &frePointable, NULL);
                } else {
                    FRENewObject( (const uint8_t*) "com.leapmotion.leap.Finger", 0, NULL, &frePointable, NULL);
                }
                
                FRESetObjectProperty(frePointable, (const uint8_t*) "frame", freCurrentFrame, NULL);
                
                FREObject frePointableId;
                FRENewObjectFromInt32(pointable.id(), &frePointableId);
                FRESetObjectProperty(frePointable, (const uint8_t*) "id", frePointableId, NULL);
                
                FREObject frePointableLength;
                FRENewObjectFromDouble(pointable.length(), &frePointableLength);
                FRESetObjectProperty(frePointable, (const uint8_t*) "length", frePointableLength, NULL);

                FREObject frePointableWidth;
                FRENewObjectFromDouble(pointable.width(), &frePointableWidth);
                FRESetObjectProperty(frePointable, (const uint8_t*) "width", frePointableWidth, NULL);

                FRESetObjectProperty(frePointable, (const uint8_t*) "direction", createVector3(pointable.direction().x, pointable.direction().y, pointable.direction().z), NULL);
                FRESetObjectProperty(frePointable, (const uint8_t*) "tipPosition", createVector3(pointable.tipPosition().x, pointable.tipPosition().y, pointable.tipPosition().z), NULL);
                FRESetObjectProperty(frePointable, (const uint8_t*) "tipVelocity", createVector3(pointable.tipVelocity().x, pointable.tipVelocity().y, pointable.tipVelocity().z), NULL);
                
                //map to hand & back
                if(pointable.hand().isValid()) {
                    FREObject freHand = freHandsMap[pointable.hand().id()];
                    FRESetObjectProperty(frePointable, (const uint8_t*) "hand", freHand, NULL);
                    
                    FREObject frePointables;
                    FREGetObjectProperty(freHand, (const uint8_t*) "pointables", &frePointables, NULL);
                    
                    uint32_t numPointables;
                    FREGetArrayLength(frePointables, &numPointables);
                    FRESetArrayElementAt(frePointables, numPointables, frePointable);
                    
                    FREObject freSpecificHandPointables;
                    if(pointable.isTool()) {
                        FREGetObjectProperty(freHand, (const uint8_t*) "tools", &freSpecificHandPointables, NULL);
                    } else {
                        FREGetObjectProperty(freHand, (const uint8_t*) "fingers", &freSpecificHandPointables, NULL);
                    }
                    uint32_t numSpecificHandTools;
                    FREGetArrayLength(freSpecificHandPointables, &numSpecificHandTools);
                    FRESetArrayElementAt(freSpecificHandPointables, numSpecificHandTools, frePointable);
                }
                
                //push it in current frame
                FRESetArrayElementAt(frePointables, i, frePointable);
                
                //specific
                FREObject freSpecificPointables;
                if(pointable.isTool()) {
                    FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "tools", &freSpecificPointables, NULL);
                } else {
                    FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "fingers", &freSpecificPointables, NULL);
                }
                uint32_t numSpecificTools;
                FREGetArrayLength(freSpecificPointables, &numSpecificTools);
                FRESetArrayElementAt(freSpecificPointables, numSpecificTools, frePointable);
                frePointablesMap[pointable.id()] = frePointable;
            }
        }
        
        if(!frame.gestures().empty()) {
            
            FREObject freGestures;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "gesturesVector", &freGestures, NULL);
            
            for(int i = 0; i < frame.gestures().count(); i++) {
                const Gesture gesture = frame.gestures()[i];
                
                int state;
                switch (gesture.state()) {
                    case Gesture::STATE_INVALID:
                        state = 0;
                        break;
                    case Gesture::STATE_START:
                        state = 1;
                        break;
                    case Gesture::STATE_UPDATE:
                        state = 2;
                        break;
                    case Gesture::STATE_STOP:
                        state = 3;
                        break;
                        
                    default:
                        break;
                }
                
                int type;
                FREObject freGesture;
                switch (gesture.type()) {
                    case Gesture::TYPE_SWIPE:
                    {
                        type = 5;
                        SwipeGesture swipe = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.SwipeGesture", 0, NULL, &freGesture, NULL);
                        
                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(swipe.direction().x, swipe.direction().y, swipe.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(swipe.position().x, swipe.position().y, swipe.position().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "startPosition", createVector3(swipe.startPosition().x, swipe.startPosition().y, swipe.startPosition().z), NULL);
                        
                        FREObject freSwipeGestureSpeed;
                        FRENewObjectFromDouble(swipe.speed(), &freSwipeGestureSpeed);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "speed", freSwipeGestureSpeed, NULL);

                        break;
                    }
                    case Gesture::TYPE_CIRCLE:
                    {
                        type = 6;
                        CircleGesture circle = gesture;

                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.CircleGesture", 0, NULL, &freGesture, NULL);
                        
                        FRESetObjectProperty(freGesture, (const uint8_t*) "center", createVector3(circle.center().x, circle.center().y, circle.center().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "normal", createVector3(circle.normal().x, circle.normal().y, circle.normal().z), NULL);
                        
                        FREObject freCircleGestureProgress;
                        FRENewObjectFromDouble(circle.progress(), &freCircleGestureProgress);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "progress", freCircleGestureProgress, NULL);
                        
                        FREObject freCircleGestureRadius;
                        FRENewObjectFromDouble(circle.radius(), &freCircleGestureRadius);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "radius", freCircleGestureRadius, NULL);
                    
                        FREObject frePointable = frePointablesMap[circle.pointable().id()];
                        if(frePointable != NULL)
                        {
                            FRESetObjectProperty(freGesture, (const uint8_t*) "pointable", frePointable, NULL);
                        }

                        break;
                    }
                    case Gesture::TYPE_SCREEN_TAP:
                    {
                        type = 7;
                        ScreenTapGesture screentap = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.ScreenTapGesture", 0, NULL, &freGesture, NULL);

                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(screentap.direction().x, screentap.direction().y, screentap.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(screentap.position().x, screentap.position().y, screentap.position().z), NULL);

                        break;
                    }
                    case Gesture::TYPE_KEY_TAP:
                    {
                        type = 8;
                        KeyTapGesture tap = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.KeyTapGesture", 0, NULL, &freGesture, NULL);

                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(tap.direction().x, tap.direction().y, tap.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(tap.position().x, tap.position().y, tap.position().z), NULL);
                        
                        break;
                    }
                    default:
                    {
                        type = 4;
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.Gesture", 0, NULL, &freGesture, NULL);
                        break;
                    }
                }
                
                FREObject freGestureState;
                FRENewObjectFromInt32(state, &freGestureState);
                FRESetObjectProperty(freGesture, (const uint8_t*) "state", freGestureState, NULL);
                
                FREObject freGestureType;
                FRENewObjectFromInt32(type, &freGestureType);
                FRESetObjectProperty(freGesture, (const uint8_t*) "type", freGestureType, NULL);

                FREObject freGestureDuration;
                FRENewObjectFromInt32((int32_t) gesture.duration(), &freGestureDuration);
                FRESetObjectProperty(freGesture, (const uint8_t*) "duration", freGestureDuration, NULL);
                
                FREObject freGestureDurationSeconds;
                FRENewObjectFromDouble(gesture.durationSeconds(), &freGestureDurationSeconds);
                FRESetObjectProperty(freGesture, (const uint8_t*) "durationSeconds", freGestureDurationSeconds, NULL);
                
                FRESetObjectProperty(freGesture, (const uint8_t*) "frame", freCurrentFrame, NULL);
                
                FREObject freGestureId;
                FRENewObjectFromInt32(gesture.id(), &freGestureId);
                FRESetObjectProperty(freGesture, (const uint8_t*) "id", freGestureId, NULL);
                
                if (!gesture.hands().empty()) {
                    
                    FREObject freGestureHands;
                    FREGetObjectProperty(freGesture, (const uint8_t*) "hands", &freGestureHands, NULL);
                    
                    for(int i = 0; i < gesture.hands().count(); i++) {
                        const Hand hand = gesture.hands()[i];
                        
                        FREObject freHand = freHandsMap[hand.id()];
                        FRESetArrayElementAt(freGestureHands, i, freHand);
                    }
                }
                
                if (!gesture.pointables().empty()) {
                    
                    FREObject freGesturePointables;
                    FREGetObjectProperty(freGesture, (const uint8_t*) "pointables", &freGesturePointables, NULL);
                    
                    for(int i = 0; i < gesture.pointables().count(); i++) {
                        const Pointable pointable = gesture.pointables()[i];
                        
                        FREObject frePointable = frePointablesMap[pointable.id()];
                        FRESetArrayElementAt(freGesturePointables, i, frePointable);
                    }
                }
                
                //push it in current gesture vector
                FRESetArrayElementAt(freGestures, i, freGesture);
            }
        }
        
        lastFrame = frame;
        
        return freCurrentFrame;
    }
Exemplo n.º 24
0
    void m_bang()
    {

        Frame frame;
        t_atom generalInfo[6];
        int num_hands, num_tools, num_gestures;
        frame = dispatcher.frame;
        num_hands = frame.hands().count();
        num_tools = frame.tools().count();
        num_gestures = frame.gestures().count();
        
        if(general_flag){
            SETFLOAT(&generalInfo[0], (float)frame.id());
            SETFLOAT(&generalInfo[1], (float)frame.timestamp());
            SETFLOAT(&generalInfo[2], (float)num_hands);
            SETFLOAT(&generalInfo[3], (float)frame.fingers().count());
            SETFLOAT(&generalInfo[4], (float)frame.tools().count());
            SETFLOAT(&generalInfo[5], (float)frame.gestures().count());
            ToOutList(0, 6, generalInfo);        
        }
        // tools
        for(int i = 0; i<num_tools; i++){
            Tool tool;
            tool = frame.tools()[i];

            t_atom toolInfo[5];
            if(tools_position_flag) {
                SETFLOAT(&toolInfo[0], i);
                SETSYMBOL(&toolInfo[1], gensym("direction"));
                SETFLOAT(&toolInfo[2], tool.direction().x);
                SETFLOAT(&toolInfo[3], tool.direction().y);
                SETFLOAT(&toolInfo[4], tool.direction().z);
                ToOutAnything(1, gensym("tool"), 5, toolInfo);
            }
            if(tools_position_flag) {
                SETFLOAT(&toolInfo[0], i);
                SETSYMBOL(&toolInfo[1], gensym("position"));
                SETFLOAT(&toolInfo[2], tool.tipPosition().x);
                SETFLOAT(&toolInfo[3], tool.tipPosition().y);
                SETFLOAT(&toolInfo[4], tool.tipPosition().z);
                ToOutAnything(1, gensym("tool"), 5, toolInfo);
            }
            if(tools_velocity_flag){
                SETFLOAT(&toolInfo[0], i);
                SETSYMBOL(&toolInfo[1], gensym("velocity"));
                SETFLOAT(&toolInfo[2], tool.tipVelocity().x);
                SETFLOAT(&toolInfo[3], tool.tipVelocity().y);
                SETFLOAT(&toolInfo[4], tool.tipVelocity().z);
                ToOutAnything(1, gensym("tool"), 5, toolInfo);
            }
            if(tools_size_flag){
                SETFLOAT(&toolInfo[0], i); 
                SETSYMBOL(&toolInfo[1], gensym("size"));
                SETFLOAT(&toolInfo[2], tool.width());
                SETFLOAT(&toolInfo[3], tool.length());
                ToOutAnything(1, gensym("tool"), 4, toolInfo);
            }
        }
        // hands and fingers
        for(int i = 0; i<num_hands; i++){
            Hand hand;
            hand = frame.hands()[i];
            int num_fingers = hand.fingers().count();
            int num_tools = hand.tools().count();
            t_atom handInfo[5];

            if(hands_direction_flag){
                // direction
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("direction"));
                SETFLOAT(&handInfo[2], hand.direction().x);
                SETFLOAT(&handInfo[3], hand.direction().y);
                SETFLOAT(&handInfo[4], hand.direction().z);
                ToOutAnything(1, gensym("hand"), 5, handInfo);
            }
            if(hands_palm_position_flag){
                // position
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("palm_position"));
                SETFLOAT(&handInfo[2], hand.palmPosition().x);
                SETFLOAT(&handInfo[3], hand.palmPosition().y);
                SETFLOAT(&handInfo[4], hand.palmPosition().z);
                ToOutAnything(1, gensym("hand"), 5, handInfo);
            }
            if(hands_palm_velocity_flag){
                // velocity
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("palm_velocity"));
                SETFLOAT(&handInfo[2], hand.palmVelocity().x);
                SETFLOAT(&handInfo[3], hand.palmVelocity().y);
                SETFLOAT(&handInfo[4], hand.palmVelocity().z);
                ToOutAnything(1, gensym("hand"), 5, handInfo);
            }
            if(hands_palm_normal_flag){
                // normal
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("palm_normal"));
                SETFLOAT(&handInfo[2], hand.palmNormal().x);
                SETFLOAT(&handInfo[3], hand.palmNormal().y);
                SETFLOAT(&handInfo[4], hand.palmNormal().z);
                ToOutAnything(1, gensym("hand"), 5, handInfo);
            }
            if(hands_sphere_radius_flag){
                // sphere radius
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("sphere_radius"));
                SETFLOAT(&handInfo[2], hand.sphereRadius());
                ToOutAnything(1, gensym("hand"), 3, handInfo);
            }
            if(hands_sphere_center_flag){
                // sphere center
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("sphere_center"));
                SETFLOAT(&handInfo[2], hand.sphereCenter().x);
                SETFLOAT(&handInfo[3], hand.sphereCenter().y);
                SETFLOAT(&handInfo[4], hand.sphereCenter().z);
                ToOutAnything(1, gensym("hand"), 5, handInfo);
            }
            if(hands_finger_count_flag){
                // finger count
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("finger_count"));
                SETFLOAT(&handInfo[2], num_fingers);
                ToOutAnything(1, gensym("hand"), 3, handInfo);
            }
            if(hands_tool_count_flag){
                // tool count
                SETFLOAT(&handInfo[0], i);
                SETSYMBOL(&handInfo[1], gensym("tool_count"));
                SETFLOAT(&handInfo[2], num_tools);
                ToOutAnything(1, gensym("hand"), 3, handInfo);
            }
            for(int j = 0; j<num_fingers; j++){
                Finger finger;
                finger = hand.fingers()[j];                    
                t_atom fingerInfo[7];
                if(fingers_direction_flag){
                    SETFLOAT(&fingerInfo[0], i); // index
                    SETSYMBOL(&fingerInfo[1], gensym("fingers"));
                    SETFLOAT(&fingerInfo[2], j);
                    SETSYMBOL(&fingerInfo[3], gensym("direction"));
                    SETFLOAT(&fingerInfo[4], finger.direction().x);
                    SETFLOAT(&fingerInfo[5], finger.direction().y);
                    SETFLOAT(&fingerInfo[6], finger.direction().z);
                    ToOutAnything(1, gensym("hand"), 7, fingerInfo);
                }
                if(fingers_position_flag){
                    SETFLOAT(&fingerInfo[0], i); // index
                    SETSYMBOL(&fingerInfo[1], gensym("fingers"));
                    SETFLOAT(&fingerInfo[2], j);
                    SETSYMBOL(&fingerInfo[3], gensym("position"));
                    SETFLOAT(&fingerInfo[4], finger.tipPosition().x);
                    SETFLOAT(&fingerInfo[5], finger.tipPosition().y);
                    SETFLOAT(&fingerInfo[6], finger.tipPosition().z);
                    ToOutAnything(1, gensym("hand"), 7, fingerInfo);
                }
                if(fingers_velocity_flag){
                    SETFLOAT(&fingerInfo[0], i); // index
                    SETSYMBOL(&fingerInfo[1], gensym("fingers"));
                    SETFLOAT(&fingerInfo[2], j);
                    SETSYMBOL(&fingerInfo[3], gensym("velocity"));
                    SETFLOAT(&fingerInfo[4], finger.tipVelocity().x);
                    SETFLOAT(&fingerInfo[5], finger.tipVelocity().y);
                    SETFLOAT(&fingerInfo[6], finger.tipVelocity().z);
                    ToOutAnything(1, gensym("hand"), 7, fingerInfo);
                }
                if(fingers_size_flag){
                    SETFLOAT(&fingerInfo[0], i); // index
                    SETSYMBOL(&fingerInfo[1], gensym("fingers"));
                    SETFLOAT(&fingerInfo[2], j);
                    SETSYMBOL(&fingerInfo[3], gensym("size"));
                    SETFLOAT(&fingerInfo[4], finger.width());
                    SETFLOAT(&fingerInfo[5], finger.length());
                    ToOutAnything(1, gensym("hand"), 6, fingerInfo);
                }
            }
        }
        t_atom gestureCountInfo[1];            
        for(int i = 0;i < num_gestures; i++){
            Gesture gesture;
            gesture = frame.gestures()[i];
            //type
            t_atom gestureTypeInfo[3];
            SETFLOAT(&gestureTypeInfo[0], i);
            SETSYMBOL(&gestureTypeInfo[1], gensym("type"));
            switch(gesture.type())
            {
                case Gesture::TYPE_INVALID:
                    SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_INVALID"));
                    break;
                case Gesture::TYPE_SWIPE:
                    SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_SWIPE"));
                    break;
                case Gesture::TYPE_CIRCLE:
                    SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_CIRCLE"));
                    break;
                case Gesture::TYPE_SCREEN_TAP:
                    SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_SCREEN_TAP"));
                    break;
                case Gesture::TYPE_KEY_TAP:
                    SETSYMBOL(&gestureTypeInfo[2], gensym("TYPE_KEY_TAP"));
                    break;
            }
            ToOutList(2, 3, gestureTypeInfo);

            //state
            t_atom gestureStateInfo[3];
            SETFLOAT(&gestureStateInfo[0], i);
            SETSYMBOL(&gestureStateInfo[1], gensym("state"));
            switch(gesture.state())
            {
                case Gesture::STATE_INVALID:
                    SETSYMBOL(&gestureStateInfo[2], gensym("STATE_INVALID"));
                    break;
                case Gesture::STATE_START:
                    SETSYMBOL(&gestureStateInfo[2], gensym("TYPE_START"));
                    break;
                case Gesture::STATE_UPDATE:
                    SETSYMBOL(&gestureStateInfo[2], gensym("STATE_UPDATE"));
                    break;
                case Gesture::STATE_STOP:
                    SETSYMBOL(&gestureStateInfo[2], gensym("TYPE_STOP"));
                    break;
            }
            ToOutList(2, 3, gestureStateInfo);

            t_atom gestureDurationInfo[3];
            SETFLOAT(&gestureDurationInfo[0], i);
            SETSYMBOL(&gestureDurationInfo[1], gensym("duration"));
            SETFLOAT(&gestureDurationInfo[2], gesture.duration());
            ToOutList(2, 3, gestureDurationInfo);

            t_atom gestureIdInfo[3];
            SETFLOAT(&gestureIdInfo[0], i);
            SETSYMBOL(&gestureIdInfo[1], gensym("id"));
            SETFLOAT(&gestureIdInfo[2], gesture.id());
            ToOutList(2, 3, gestureIdInfo);

        }
    }
Exemplo n.º 25
0
void ExecutionManager::newSkeletonData(QString pData)
{
    if(this->role == INACTIVE)
    {
        return;
    }
    DAOLayer *daoLayer = DAOLayer::getInstance();
    if(daoLayer != NULL)
    {
        RawJointState * rjs = RawJointState::fromInputLine(pData);
        if(rjs == NULL)
        {
            qDebug() << "rjs is NULL";
            return;
        }
        if (rjs->jointsCount < SkeletonData::leftPelvis)
        {
            delete rjs;
            qDebug() << "rjs is NULL";
            return;
        }
        if(this->segmenter->addState(rjs))
        {
            InputGesture *ig = this->segmenter->getLastInputGesture();
            QList<QPair<Record*, double>* >* results = this->lra->recognizeSingleGesture(ig);
            if(results == NULL)
            {
                qDebug() << "results are NULL";
                return;
            }
            switch(role)
            {
            case RECORDER:
            {
                Gesture *g = InputGesture::toGesture(ig);
                // TODO MANAGE CONFLICT
                /*if (results->count() > 0 && results->first()->second > 0.8f)
                {
                    qDebug()<<"Conflict with "<<results->first()->first->getName()<<" at "<<results->first()->second;
                    emit this->gestureConflict(g);
                }
                else*/
                {
                    qDebug()<<"Nb frames "<<g->getFrames()->count();
                    emit this->gestureRecorded(g);
                }
                break;
            }
            case RECOGNIZER:
                qDebug("-----------------------------");
                for(int i=0; i<results->count(); i++)
                {
                    if (results->at(i)->first == NULL)
                    {
                        continue;
                    }
                    qDebug()<< results->at(i)->first->getName()<< " "<< results->at(i)->second;
                }
                qDebug("-----------------------------");

                // Compute threshold
                float thresh = pow(0.9f, results->count());
                /*if(thresh < 0.45f)
                {
                    thresh = 0.45f;
                }*/
                qDebug()<<"Thresh "<<thresh;

                // Consider recognized
                DAOLayer *daoLayer = DAOLayer::getInstance();
                if (daoLayer != NULL && results->count() > 0 && results->first()->second > thresh)
                {
                    Record *r = daoLayer->getSingleRecord(results->first()->first->getId());
                    if(r != NULL && r->isGestureActive() && !r->isDeleted())
                    {
                        qDebug("Recognize with : %f", results->first()->second);
                        daoLayer->gestureRecognized(r);
                    }
                }
                break;
            }
            // qDebug()<<"Clear segmenter";
            this->segmenter->clear();
            delete results;
        }
    }
}
Exemplo n.º 26
0
void SampleListener::onFrame(const Controller& controller) {
	//tictoc_stack.push(clock());
	// Get the most recent frame and report some basic information
	const Frame frame = controller.frame();

	HandList hands = frame.hands();
	for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
		// Get the first hand
		const Hand hand = *hl;
		std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
		
		const Vector normal = hand.palmNormal();
		const Vector direction = hand.direction();

		// Get the Arm bone
		Arm arm = hand.arm();

		// Get fingers
		const FingerList fingers = hand.fingers();
		for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
			const Finger finger = *fl;
	
			myfile << std::string(4, ' ') << fingerNames[finger.type()]
				<< ": " << hand.palmPosition().distanceTo(finger.tipPosition());

			// Get finger bones
			for (int b = 0; b < 4; ++b) {
				Bone::Type boneType = static_cast<Bone::Type>(b);
				Bone bone = finger.bone(boneType);
			}
		}
	}

	// Get tools
	const ToolList tools = frame.tools();
	for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
		const Tool tool = *tl;
	}

	// Get gestures
	const GestureList gestures = frame.gestures();
	for (int g = 0; g < gestures.count(); ++g) {
		Gesture gesture = gestures[g];

		switch (gesture.type()) {
		case Gesture::TYPE_CIRCLE:
		{
			CircleGesture circle = gesture;
			std::string clockwiseness;

			if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) {
				clockwiseness = "clockwise";
			}
			else {
				clockwiseness = "counterclockwise";
			}

			// Calculate angle swept since last frame
			float sweptAngle = 0;
			if (circle.state() != Gesture::STATE_START) {
				CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
				sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
			}
			break;
		}
		case Gesture::TYPE_SWIPE:
		{
			SwipeGesture swipe = gesture;
			break;
		}
		case Gesture::TYPE_KEY_TAP:
		{
			KeyTapGesture tap = gesture;
			break;
		}
		case Gesture::TYPE_SCREEN_TAP:
		{
			ScreenTapGesture screentap = gesture;
			break;
		}
		default:
			break;
		}
	}

	if (!frame.hands().isEmpty() || !gestures.isEmpty()) {
		std::cout << std::endl;
	}
	myfile << " Time elapsed: "
		<< ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC;
	tictoc_stack.pop();
	myfile << endl;

}
Exemplo n.º 27
0
void GestureHandler::executeGestureUpdate(const QString &type, int id, const QHash<QString, QVariant>& attrs)
{
    // If is an update of the current gesture execute it
    if (this->currentGesture != NULL && this->currentGesture->getId() == id && !this->timerTap->isActive()) {
        qDebug() << "\tGesture Update" << id << type;
        this->currentGesture->setAttrs(attrs);
        this->currentGesture->update();

    // If no gesture is running the gesture is a TAP, an unsupported gesture, or in Precise a DRAG
    } else if (this->currentGesture == NULL) {

        Gesture *gesture = this->createGesture(type, id, attrs, false);
        if (gesture != NULL) {
            this->currentGesture = gesture;

            // If the gesture is a tap allow to make a tap & hold
            if (gesture->getType() == GestureTypeEnum::TAP) {
                this->timerTap->start();

            // In Precise the DeltaX and DeltaY attrs in start are 0. Create the Drag here
            } else if (gesture->getType() == GestureTypeEnum::DRAG) {
                qDebug() << "\tGesture Start";
                this->currentGesture->start();
                qDebug() << "\tGesture Update" << id << type;
                this->currentGesture->update();
            }
        }

    // If is an update whith the timer running it is a DOUBLE_TAP or a TAP_AND_HOLD
    } else if (this->currentGesture != NULL && this->timerTap->isActive()) {
        this->timerTap->stop();

        int currentNumFingers = this->currentGesture->getAttrs().value(GEIS_GESTURE_ATTRIBUTE_TOUCHES).toInt();
        int newNumFingers     = attrs.value(GEIS_GESTURE_ATTRIBUTE_TOUCHES).toInt();
        Gesture *gesture      = this->createGesture(type, id, attrs, true);

        if (gesture != NULL && currentNumFingers == newNumFingers) {

            // TAP_AND_HOLD
            if (gesture->getType() == GestureTypeEnum::TAP_AND_HOLD) {
                this->currentGesture = gesture;

                qDebug() << "\tGesture Start";
                this->currentGesture->start();

                qDebug() << "\tGesture Update";
                this->currentGesture->update();

            // DOUBLE_TAP
            } else if (gesture->getType() == GestureTypeEnum::DOUBLE_TAP) {
                this->currentGesture = gesture;

                qDebug() << "\tGesture Start";
                this->currentGesture->start();

                qDebug() << "\tGesture Update";
                this->currentGesture->update();

                qDebug() << "\tGesture Finish";
                this->currentGesture->finish();

                delete this->currentGesture;
                this->currentGesture = NULL;
            }

        }
    }
}
Exemplo n.º 28
0
void AppListener::onFrame(const Controller& controller) {
    // Get the most recent frame and report some basic information
    const Frame frame = controller.frame();

    ::Sleep(1);

    const HandList&     hands       = frame.hands();
    const FingerList&   fingers     = frame.fingers();
    const ToolList&     tools       = frame.tools();
    const GestureList&  gestures    = frame.gestures();

    if (hands.empty() && fingers.empty() && tools.empty() && gestures.empty())
        return;

#if 0
    std::cout 
        << "Frame id: "     << frame.id()
        << ", timestamp: "  << frame.timestamp()
        << " hands: "       << hands.count()
        << " fingers: "     << fingers.count()
        << " tools: "       << tools.count()
        << " gestures: "    << gestures.count() 
        << std::endl;
#endif
    ofxOscBundle bundle;

    ofxOscMessage alive;
    {
        alive.setAddress("/tuio/2Dcur");
        alive.addStringArg("alive");
    }

    ofxOscMessage fseq;
    {
        fseq.setAddress( "/tuio/2Dcur" );
        fseq.addStringArg( "fseq" );
        fseq.addIntArg(frame.id());
    }

    if (!hands.empty()) {
        // Get the first hand
        const Hand& hand = hands[0];

        // Check if the hand has any fingers
        const FingerList& fingers = hand.fingers();
        if (!fingers.empty()) {
            for (int i = 0; i < fingers.count(); ++i) {
                const Vector& tipPos = fingers[i].tipPosition();
                const Vector& tipVel = fingers[i].tipVelocity();
                {
#ifdef INIT_BBOX
                    // max/min bbox
                    bboxMax.x = std::max<float>(bboxMax.x, tipPos.x);
                    bboxMax.y = std::max<float>(bboxMax.y, tipPos.y);
                    bboxMax.z = std::max<float>(bboxMax.z, tipPos.z);

                    bboxMin.x = std::min<float>(bboxMin.x, tipPos.x);
                    bboxMin.y = std::min<float>(bboxMin.y, tipPos.y);
                    bboxMin.z = std::min<float>(bboxMin.z, tipPos.z);
#endif
                    Vector tuioPos;
                    tuioPos.x = normalize(tipPos.x, bboxMin.x, bboxMax.x);
                    tuioPos.y = normalize(tipPos.y, bboxMax.y, bboxMin.y);
                    tuioPos.z = normalize(tipPos.z, bboxMin.z, bboxMax.z);

                    // tuio
                    {
                        ofxOscMessage m;
                        m.setAddress( "/tuio/2Dcur" );
                        m.addStringArg("set");
                        m.addIntArg(fingers[i].id());				// id
                        m.addFloatArg(tuioPos.x);	// x
                        m.addFloatArg(tuioPos.y);	// y
                        // TOTO
                        m.addFloatArg(tipVel.x / 400);			// dX
                        m.addFloatArg(tipVel.y / 400);			// dY
                        m.addFloatArg(0);		// maccel
                        bundle.addMessage(m);
                        alive.addIntArg(fingers[i].id());				// add blob to list of ALL active IDs
                    }
                }
            }
#ifdef INIT_BBOX            
            std::cout << "min: " << bboxMin << std::endl;
            std::cout << "max: " << bboxMax << std::endl;
#endif
        }
#if 0
        // Get the hand's sphere radius and palm position
        std::cout << "Hand sphere radius: " << hand.sphereRadius()
            << " mm, palm position: " << hand.palmPosition() << std::endl;
#endif

        // Get the hand's normal vector and direction
        const Vector normal = hand.palmNormal();
        const Vector direction = hand.direction();

#if 0
        // Calculate the hand's pitch, roll, and yaw angles
        std::cout << "Hand pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
            << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
            << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;
#endif
    }

    bundle.addMessage(alive);
    bundle.addMessage(fseq);
    tuioSender.sendBundle(bundle);

    // Get gestures
    for (int g = 0; g < gestures.count(); ++g) {
        Gesture gesture = gestures[g];

        switch (gesture.type()) {
case Gesture::TYPE_CIRCLE:
    {
        CircleGesture circle = gesture;
        std::string clockwiseness;

        if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) {
            clockwiseness = "clockwise";
        } else {
            clockwiseness = "counterclockwise";
        }

        // Calculate angle swept since last frame
        float sweptAngle = 0;
        if (circle.state() != Gesture::STATE_START) {
            CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id()));
            sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI;
        }
        std::cout << "Circle id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", progress: " << circle.progress()
            << ", radius: " << circle.radius()
            << ", angle " << sweptAngle * RAD_TO_DEG
            <<  ", " << clockwiseness << std::endl;
        break;
    }
case Gesture::TYPE_SWIPE:
    {
        SwipeGesture swipe = gesture;
        std::cout << "Swipe id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", direction: " << swipe.direction()
            << ", speed: " << swipe.speed() << std::endl;
        break;
    }
case Gesture::TYPE_KEY_TAP:
    {
        KeyTapGesture tap = gesture;
        std::cout << "Key Tap id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", position: " << tap.position()
            << ", direction: " << tap.direction()<< std::endl;
        break;
    }
case Gesture::TYPE_SCREEN_TAP:
    {
        ScreenTapGesture screentap = gesture;
        std::cout << "Screen Tap id: " << gesture.id()
            << ", state: " << gesture.state()
            << ", position: " << screentap.position()
            << ", direction: " << screentap.direction()<< std::endl;
        break;
    }
default:
    std::cout << "Unknown gesture type." << std::endl;
    break;
        }
    }
#if 0
    if (!hands.empty() || !gestures.empty()) {
        std::cout << std::endl;
    }
#endif
}
Exemplo n.º 29
0
void Quantizer2::train(std::vector<Gesture> gestures, int considered_gestures){
    //metagesture: contiene tutte le componenti di tutte le gesture.
    Gesture gesture;

    //costruzione della metagesture
    int gesture_number;
    if(considered_gestures<gestures.size()){
        gesture_number = considered_gestures;
    }else{
        gesture_number = gestures.size();
    }
    for(int k=0; k<gesture_number; k++){
        std::vector<Sample_3d> curGesturData = gestures.at(k).getData();
        for(int w=0; w<curGesturData.size(); w++){
            gesture.add( curGesturData.at(w) );
        }
    }

    this->init(gesture);
    std::vector<Sample_3d> data = gesture.getData();
    int size = data.size();

     // associazioni (componente della gesture) <-> centroide
    int* assoc = new int[size];
    for(int i=0; i<size; i++)
        assoc[i] = -1;

    // n° vettori associati a ciascun centroide
    // contando il centroide stesso! (infatti si inizializza a 1)
    int numVectPerCentroid[n_centroids];
    for(int i=0; i<n_centroids; i++ )
        numVectPerCentroid[i] = 1;

    bool modified;
    int n_iter = 0;

     do{
        // determina centroide a distanza minima per ogni vettore
        modified = false;

        for(int i=0; i<size; i++){

            // minima distanza finora riscontrata
            double min_dist = std::numeric_limits<double>::max();
            // centroide a minima distanza
            int centroid_count = -1;

            for(int j=0; j<n_centroids; j++){

                // calcola la distanza dell'elemento dal centroide corrente
                double d = distance(data.at(i), centroids[j]);

                // se la nuova distanza è minore della minima finora riscontrata,
                // aggiorna il centroide più vicino
                if(d < min_dist){
                    min_dist = d;
                    centroid_count = j;
                }

            }//j

            // associa il sample al centroide più vicino
            if(assoc[i] != centroid_count){
                assoc[i] = centroid_count;
                modified = true;
            }
        }//i

        // ricalcola posizione dei centroidi

        for(int i=0; i<size; i++){

            numVectPerCentroid[assoc[i]]++;
            centroids[assoc[i]] += data.at(i);

        }

        for(int j=0; j<n_centroids; j++)
            centroids[j] /= numVectPerCentroid[j];

        n_iter++;

    }
    while(modified && n_iter < 100);

}
Exemplo n.º 30
0
void MangoListener::onFrame(const Controller& controller) {
  const Frame frame = controller.frame();
    HandList hands = frame.hands();
    int extendedFingers = 0;
    for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
        const Hand hand = *hl;
        for (int i = 0; i < hand.fingers().count(); i++)
        {
            Finger finger = hand.fingers()[i];
            if(finger.isExtended()) extendedFingers++;
        }

        if (!onGesture && !frame.hands().isEmpty() && frame.hands().count() == 1 && extendedFingers == 0)
        {
            preGestureCounter++;
            std::cout << preGestureCounter << std::endl;
            if (preGestureCounter > MAX_PREGESTURE && frameCount == 0)
            {
                onGesture = true;
                preGestureCounter = 0;
                frameCount++;
                note.show();
            }
        }
        else if (preGestureCounter > 0)
        {
            preGestureCounter--;
        }
    }
        if (onGesture && frameCount < MAX_FRAMECOUNT) {

            switch (extendedFingers)
            {
                case 1:
                {
                    std::string command = commands.getCommand("FING3");
                    std::cout << command << std::endl;
                    break;
                }
                case 2:
                {
                    break;
                }
                case 3:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }

            frameCount++;
            const GestureList gestures = frame.gestures();
            for (int g = 0; g < gestures.count(); ++g) {
                Gesture gesture = gestures[g]; //need to move finger detection in here too
                switch (gesture.type()) {
                    case Gesture::TYPE_CIRCLE:
                    {
                        CircleGesture circle = gesture;
                        std::string clockwiseness; //probably simplfy to a bool

                        if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4)
                        {
                          clockwiseness = "clockwise";
                          std::cout << "CIRCLE CLOCKWISE" << std::endl;
                        }
                        else
                        {
                          clockwiseness = "counterclockwise";
                          std::cout << "CIRCLE COUNTERCLOCKWISE" << std::endl;
                        }
                        break;
                    }
                    case Gesture::TYPE_SWIPE:
                    {
                        SwipeGesture swipe = gesture;
                        std::cout << "SWIPE" << std::endl;
                        break;
                    }
                    case Gesture::TYPE_KEY_TAP:
                    {
                        KeyTapGesture tap = gesture;
                        std::cout << "KEY TAP" << std::endl;
                        break;
                    }
                    case Gesture::TYPE_SCREEN_TAP:
                    {
                        ScreenTapGesture screentap = gesture;
                        std::cout << "SCREEN TAP" << std::endl;
                        break;
                    }
                    default:
                    {
                        std::cout << std::string(2, ' ')  << "Unknown gesture type." << std::endl;
                        break;
                    }
                }
                float seconds = gesture.durationSeconds();
                std::cout << seconds << std::endl;
            }
        }
        else if (onGesture == true && frameCount > MAX_FRAMECOUNT)
        {
            note.hide();
            onGesture = false;
            frameCount = 0;
        }
        else if (onGesture)
        {
            frameCount++;
        }
}