Exemplo n.º 1
0
Vector AgentDetector::getSkeletonPattern(Player p)
{
    //Create the skeleton pattern
    Vector pattern(5);

    pattern[0] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_ELBOW_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_L]);
    pattern[1] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_C]);
    pattern[2] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_C], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_R]);
    pattern[3] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_C], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SPINE]);
    pattern[4] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_C], p.skeleton[EFAA_OPC_BODY_PART_TYPE_HEAD]);

    //Arms
    //pattern[0] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_HAND_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_WRIST_L]);
    //pattern[1] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_WRIST_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_ELBOW_L]);
    //pattern[2] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_ELBOW_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_L]);
    //pattern[3] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_C]);
    //pattern[4] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_C], p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_R]);
    //pattern[5] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_SHOULDER_R], p.skeleton[EFAA_OPC_BODY_PART_TYPE_ELBOW_R]);
    //pattern[6] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_ELBOW_R], p.skeleton[EFAA_OPC_BODY_PART_TYPE_WRIST_R]);
    //pattern[7] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_WRIST_R], p.skeleton[EFAA_OPC_BODY_PART_TYPE_HAND_R]);

    //Legs
    //pattern[8] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_FOOT_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_ANKLE_L]);
    //pattern[9] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_ANKLE_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_KNEE_L]);
    //pattern[10] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_KNEE_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_HIP_L]);
    //pattern[11] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_HIP_L], p.skeleton[EFAA_OPC_BODY_PART_TYPE_HIP_C]);
    //pattern[12] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_HIP_C], p.skeleton[EFAA_OPC_BODY_PART_TYPE_HIP_R]);
    //pattern[13] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_HIP_R], p.skeleton[EFAA_OPC_BODY_PART_TYPE_KNEE_R]);
    //pattern[14] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_KNEE_R], p.skeleton[EFAA_OPC_BODY_PART_TYPE_ANKLE_R]);
    //pattern[15] = distanceVector(p.skeleton[EFAA_OPC_BODY_PART_TYPE_ANKLE_R], p.skeleton[EFAA_OPC_BODY_PART_TYPE_FOOT_R]); 

    return pattern;
}
Exemplo n.º 2
0
Object* getSelectedObject(std::list<Object*>* allObjects, Player* player)
{
	if(!allObjects || allObjects->empty())
		return NULL;
	float a,b,c,d,e,f; 
	float minDistance = 999999999999;
	Object* closestObject;
	cv::Vec3f objectPosition;
	cv::Vec4f distanceVector;
	cv::Vec4f playerPosition(player->position[0], player->position[1], player->position[2], 1);
	cv::Vec4f lookAt(player->lookAtVector[0], player->lookAtVector[1], player->lookAtVector[2], 1);
	cv::Matx<float,4,4> plueckerCoords = playerPosition*lookAt.t() - lookAt*playerPosition.t();
	a = plueckerCoords(0,1);
	b = plueckerCoords(0,2);
	c = plueckerCoords(0,3);
	d = plueckerCoords(1,2);
	e = plueckerCoords(1,3);
	f = plueckerCoords(2,3);

	cv::Matx<float,4,4> dualPlueckerCoords(0, f, -e, d,
										   -f, 0, c, -b,
										   e, -c, 0, a,
										   -d, b, -a, 0);

	cv::Matx<float,3,3> A(0, f, -e,
						  -f, 0, c,
						  e, -c, 0);

	A = A.t()*A;

	dualPlueckerCoords = sqrt(2)/(A(0,0)*A(1,1)*A(2,2))*dualPlueckerCoords;
	
	
	for(std::list<Object*>::iterator it = allObjects->begin(); it != allObjects->end(); ++it)
	{
		objectPosition = (*it)->position;
		distanceVector = dualPlueckerCoords*cv::Vec4f(objectPosition(0), objectPosition(1), objectPosition(2), 1);
		std::cout << "vectorNorm" << cv::norm(cv::Vec3f(distanceVector(0),distanceVector(1),distanceVector(2))) << std::endl;
		if (minDistance > cv::norm(cv::Vec3f(distanceVector(0),distanceVector(1),distanceVector(2))))
		{
			minDistance = cv::norm(cv::Vec3f(distanceVector(0),distanceVector(1),distanceVector(2)));
			closestObject = (*it);
		}

	}
	std::cout << "plueckerCoords: " << plueckerCoords << std::endl;
	std::cout << "dualPlueckerCoords: " << dualPlueckerCoords << std::endl;
	std::cout << "plueckerCoords: " << a << "  " << b << "  " << c << "  " << d << "  " << e << "  " << f << std::endl;
	std::cout << "Minimum distance " << minDistance << std::endl;
	
	return closestObject;

	
	return NULL;
		
}
Exemplo n.º 3
0
vector<float> ReconnaissanceHandler::recognise(vector<float>& caracteristicVector, vector<vector<float>>& classes)
{
	vector<float> dist;
	for (int i = 0; i < classes.size(); ++i)
	{
		dist.push_back(distanceVector(caracteristicVector, classes.at(i)));
	}
	return dist;
}
// По координатам курсора получает уникальный номер вершины, которая
// попадает под него. В противном случае возвращает номер вешины,
// следующей за последней в списке вершин (то есть verticesList.size()).
VertexIndex MaxFlowVisualizer::getVertexUnderCursor(QPoint cursorPosition) {
    QVector2D cursor(cursorPosition);
    for (VertexIndex vertex = 0; vertex < verteciesList.size(); ++vertex) {
        QVector2D currentVertexCenter(verteciesList[vertex].getCenterCoordX(), verteciesList[vertex].getCenterCoordY());
        QVector2D distanceVector(currentVertexCenter - cursor);
        if (distanceVector.length() < verteciesList[vertex].getRadius()) {
            return vertex;
        }
    }
    return verteciesList.size();
}
Exemplo n.º 5
0
bool Enemy::isPlayerInRadius(int radius)
{
  sf::Vector2f playerPos = Game::getPlayersPosition();
  sf::Vector2f enemyPos = this->GetCenterPosition();
  sf::Vector2f distanceVector(playerPos.x - enemyPos.x,
                          playerPos.y - enemyPos.y);
  if(sqrt(pow(distanceVector.x,2) + pow(distanceVector.y,2)) <= radius)
  {
    return true;
  }
  return false;
}
Exemplo n.º 6
0
int getValue(GradientInfo *gradInfo, ImageInfo *image, int x, int y)
{	
	int x_pos_in_cell = x % gradInfo->grid_cell_width;
	int y_pos_in_cell = y % gradInfo->grid_cell_height;
	
	double x_weight = (double)x_pos_in_cell / (double)gradInfo->grid_cell_width;
	double y_weight = (double)y_pos_in_cell / (double)gradInfo->grid_cell_height;

	int x_grid_cell = x / gradInfo->grid_cell_width;
	int y_grid_cell = y / gradInfo->grid_cell_height;

	int x0 = x_grid_cell;
	int x1 = x0 + 1;
	int y0 = y_grid_cell;
	int y1 = y0 + 1;

	Vector2 p;
	p.x = x_weight + x_grid_cell;
	p.y = y_weight + y_grid_cell;

	// ERROR!!!!!! Redo these distance vector calculations!
	Vector2 d0 = distanceVector(Vector2((double)x0, (double)y0), p);
	Vector2 d1 = distanceVector(Vector2((double)x1, (double)y0), p);
	Vector2 d2 = distanceVector(Vector2((double)x0, (double)y1), p);
	Vector2 d3 = distanceVector(Vector2((double)x1, (double)y1), p);

	double dp0 = dotProduct(d0, gradInfo->Gradient[x0][y0]);
	double dp1 = dotProduct(d1, gradInfo->Gradient[x1][y0]);
	double dp2 = dotProduct(d2, gradInfo->Gradient[x0][y1]);
	double dp3 = dotProduct(d3, gradInfo->Gradient[x1][y1]);

	double m = lerp(dp0, dp1, x_weight);
	double n = lerp(dp2, dp3, x_weight);

	double r = lerp(m, n, y_weight);

	return abs((int)(500 * r));
}
Exemplo n.º 7
0
bool calculatePaths(struct distance_table * dt, struct link_costs * ln, 
  struct route_table * rt, struct neighbors * nb, int node_id)
{
  bool b_update = false;

  // Now calculate paths
  for (int i = 0; i < 4; i++)
  {
    // Obviously don't calculate the path to itself
    if (node_id == i) continue;

    // Determine the best path using the distance vector algo
    bool visited[4] = {(node_id==0), (node_id==1), (node_id==2), (node_id==3)};
    struct path_value pv = distanceVector(dt, ln, node_id, i, 0, &visited);

    // If the path changes, notify - this could be a different value, or different route
    if (pv.value != dt->costs[pv.node_id][node_id] ||
        rt->route[i][0] != pv.route[0] || rt->route[i][1] != pv.route[1] || 
        rt->route[i][2] != pv.route[2] || rt->route[i][3] != pv.route[3])
    {
      // Set the new path value
      b_update = true;
      setNewPathValue(dt, rt, node_id, pv);

      // Console Notifications
      printf("rtupdate%d: cost to node #%d updated to %d\r\n", node_id, pv.node_id, pv.value);
    }
  }

  if (b_update)
  {
    printf("rtupdate%d: sending out packets to neighbors with new values: [%d,%d,%d,%d]\r\n", 
      node_id, dt->costs[0][node_id], dt->costs[1][node_id], dt->costs[2][node_id], dt->costs[3][node_id]);

    // Deliver packets to other nodes
    sendPackets(dt, rt, nb, node_id);
  }

  // Report results
  return b_update;
}
Exemplo n.º 8
0
vector<float> ReconnaissanceHandler::recognisePCA(vector<float>& caracteristicVector, PCA pca, vector<vector<float>>& classes)
{
	Mat v(caracteristicVector.size(),1, CV_32F);
	int i = 0;
	for (float f : caracteristicVector) {
		v.at<float>(i, 0) = f;
		++i;
	}
	Mat reduceVector = pca.project(v);
	
	vector<float> caractReduced;
	for (i = 0; i < reduceVector.rows; ++i) {
		caractReduced.push_back(reduceVector.at<float>(i, 0));
	}

	vector<float> dist;
	for (int i = 0; i < classes.size(); ++i)
	{
		dist.push_back(distanceVector(caractReduced, classes.at(i)));
	}
	return dist;
}
  bool dunnIndex::apply(const std::vector<dmatrix>& clusteredData,
                        double& index, const dmatrix& centroids) const {
    int nbClusters=clusteredData.size();
    double denominator=0.0;
    int i,j;
    l2Distance<double> dist;
    dvector diameters(nbClusters);
    parameters param;
    param=getParameters();
    // pointer to the function which implements the measure according to the 
    // parameters
    double (lti::clusteringValidity::*diamFunc)(const dmatrix&) const;
    
#ifdef _LTI_MSC_DOT_NET_2003
    // nasty bug in this version of the .NET compiler
#define QUALIFIER
#else 
#define QUALIFIER &lti::dunnIndex::
#endif

    switch (param.diameterMeasure) {
      case parameters::Standard:
        diamFunc=QUALIFIER getStandardDiameter;
        break;
      case parameters::Average:
        diamFunc=QUALIFIER getAverageDiameter;
        break;
      case parameters::Centroid:
        diamFunc=QUALIFIER getAverageToCentroidDiameter;
        break;
      default:
        diamFunc=QUALIFIER getStandardDiameter;
        setStatusString("Unknown diameterMeasure in clusteringValidity\n");
        return false;
    }
    // compute all diameters of all clusters
    for (i=0; i<nbClusters; i++) {
      diameters[i]=(this->*diamFunc)(clusteredData[i]);
    }
    denominator=diameters.maximum();
    // pointer to the function which calculates the distance of the functions
    // a pointer to a function is used, because the function will be called 
    // many times later
    double (lti::clusteringValidity::*distFunc)
      (const dmatrix&,const dmatrix&) const ;
    // set pointer to function which is set by the parameter distanceMeasure
    switch (param.distanceMeasure) {
      case parameters::Minimum:
        distFunc=QUALIFIER getMinimumDistance;
        break;
      case parameters::Maximum:
        distFunc=QUALIFIER getMaximumDistance;
        break;
      case parameters::Mean:
        distFunc=QUALIFIER getAverageDistance;
        break;
      case parameters::Centroids:
        distFunc=QUALIFIER getCentroidDistance;
        break;
      case parameters::Interpoint:
        distFunc=QUALIFIER getAverageInterpointDistance;
        break;
      default:
        distFunc=QUALIFIER getAverageDistance;
        setStatusString("Unknown distanceMeasure in clusteringValidity\n");
        return false;
    }
    // compute the distances of all clusters to each other
    int counter=0;
    dvector distanceVector(static_cast<int>(.5*(nbClusters*(nbClusters-1))));
    for (i=0; i<nbClusters; i++) {
      for (j=i+1; j<nbClusters; j++) {
        if (distFunc==QUALIFIER getCentroidDistance) {
          distanceVector[counter]=dist.apply(centroids.getRow(i),
                                             centroids.getRow(j));
        } else {
          distanceVector[counter]=(this->*distFunc)(clusteredData[i],
                                                    clusteredData[j]);
        }
        counter++;
      }
    }
    distanceVector.divide(denominator);
    index=distanceVector.minimum();

    return true;
  }