示例#1
0
ControlStrategy::Pinning Main::getPinning(const Pinning &current_pinning) {
	if (new_task_tid == 0) return current_pinning;

	Pinning result = current_pinning;

	int pin_cpu_pos = -1;
	for (auto node : sort_indexes(pinCount)) {
		auto cpus = CpuInfo::getCpusByNode(node);
		for (auto cpu : cpus) {
			Task task = current_pinning[cpu];
			if (task.isCpuFree()) {
				pin_cpu_pos = cpu;
				pinCount[node]++;
				goto LoopEnd;
			}
		}
	}
LoopEnd:

	if (pin_cpu_pos != -1) {
		Task t;
		t.pid = proc.getPid();
		t.tid = new_task_tid;
		result[pin_cpu_pos] = t;
	}

	return result;
}
示例#2
0
// TODO: make this faster, currently copying twice
void CornerExtractor::orderCorners()
{
  std::vector<double> angles;

  // Find the angle between the 
  // vector of the center of mass to the corner and the x axis
  for (size_t i = 0; i < corners_.size(); ++i)
    angles.push_back(angle_wrt_x_axis(corners_[i], *cm_));

  std::vector<size_t> idx = sort_indexes(angles, comp_double);
  std::vector<cv::Point> tmp;
  for (auto i : idx)
    tmp.push_back(corners_[i]);

  corners_.clear();
  // Convert to OpenCV system where bottom left is index 0
  for (size_t i = 0; i < tmp.size(); ++i)
    corners_.push_back(tmp[(i+1) % 4]);
}
示例#3
0
void test_angles()
{
  assert (atan_wrt_x_axis(10, 10) == 45);
  assert (atan_wrt_x_axis(10, -10) == 135);
  assert (atan_wrt_x_axis(-10, -10) == 225);
  assert (atan_wrt_x_axis(-10, 10) == 315);

  assert (angle_wrt_x_axis(cv::Point2f(10, 10), cv::Point2f(0, 0)) == 45);
  cv::Point2f origin (100, 100);
  assert (angle_wrt_x_axis(cv::Point2f(origin.x + 10, origin.y + 10), origin) == 45);
  assert (angle_wrt_x_axis(cv::Point2f(origin.x - 10, origin.y + 10), origin) == 135);
  assert (angle_wrt_x_axis(cv::Point2f(origin.x - 10, origin.y - 10), origin) == 225);
  assert (angle_wrt_x_axis(cv::Point2f(origin.x + 10, origin.y - 10), origin) == 315);

  std::vector<size_t> test_idx = {2, 1, 3, 5, 4, 0};

  std::vector<cv::Point> test_value;
  for (size_t i = 0; i < 6; ++i)
    test_value.push_back(cv::Point2f(i, i));

  std::vector<cv::Point> test_answer;
  test_answer.push_back(cv::Point2f(5, 5));
  test_answer.push_back(cv::Point2f(1, 1));
  test_answer.push_back(cv::Point2f(0, 0));
  test_answer.push_back(cv::Point2f(2, 2));
  test_answer.push_back(cv::Point2f(4, 4));
  test_answer.push_back(cv::Point2f(3, 3));

  reorder_destructive(test_idx.begin(), test_idx.end(), test_value.begin());
  assert (test_value == test_answer);

  std::vector<double> test_nums = { 234.2, 214.5, 123.2, 264.2 };
  std::vector<size_t> answer_idx = { 2, 1, 0, 3};
  std::vector<size_t> least_to_greatest_idx = sort_indexes(test_nums, comp_double);
  assert (least_to_greatest_idx == answer_idx);

}