Ejemplo n.º 1
0
registration generateRegistration()
{
  registration reg;

  reg.plate = generateLicense();
  reg.color = COLORS[getRandomIndex(0, NUM_COLORS)];
  reg.owner = NAMES[getRandomIndex(0, NUM_NAMES)];

  return reg;
}
Ejemplo n.º 2
0
template <typename PointSource, typename PointTarget, typename FeatureT> void 
pcl::SampleConsensusInitialAlignment<PointSource, PointTarget, FeatureT>::selectSamples (
    const PointCloudSource &cloud, int nr_samples, float min_sample_distance, 
    std::vector<int> &sample_indices)
{
  if (nr_samples > (int) cloud.points.size ())
  {
    PCL_ERROR ("[pcl::%s::selectSamples] ", getClassName ().c_str ());
    PCL_ERROR ("The number of samples (%d) must not be greater than the number of points (%d)!\n",
               nr_samples, (int) cloud.points.size ());
    return;
  }

  // Iteratively draw random samples until nr_samples is reached
  int iterations_without_a_sample = 0;
  int max_iterations_without_a_sample = (int) (3 * cloud.points.size ());
  sample_indices.clear ();
  while ((int) sample_indices.size () < nr_samples)
  {
    // Choose a sample at random
    int sample_index = getRandomIndex ((int) cloud.points.size ());

    // Check to see if the sample is 1) unique and 2) far away from the other samples
    bool valid_sample = true;
    for (size_t i = 0; i < sample_indices.size (); ++i)
    {
      float distance_between_samples = euclideanDistance (cloud.points[sample_index], cloud.points[sample_indices[i]]);

      if (sample_index == sample_indices[i] || distance_between_samples < min_sample_distance)
      {
        valid_sample = false;
        break;
      }
    }

    // If the sample is valid, add it to the output
    if (valid_sample)
    {
      sample_indices.push_back (sample_index);
      iterations_without_a_sample = 0;
    }
    else
    {
      ++iterations_without_a_sample;
    }

    // If no valid samples can be found, relax the inter-sample distance requirements
    if (iterations_without_a_sample >= max_iterations_without_a_sample)
    {
      PCL_WARN ("[pcl::%s::selectSamples] ", getClassName ().c_str ());
      PCL_WARN ("No valid sample found after %d iterations. Relaxing min_sample_distance_ to %f\n",
                iterations_without_a_sample, 0.5*min_sample_distance);

      min_sample_distance_ *= 0.5;
      min_sample_distance = min_sample_distance_;
      iterations_without_a_sample = 0;
    }
  }

}
Ejemplo n.º 3
0
int main()
{
    srand((unsigned)time(NULL));
    int N = 40000;
    int low = 0,high = N-1;
    PointList* L = newPointList(N);
    int i;
    for(i = 0; i < N; i++)
    {
        L->list[i].x = getRandomIndex(low,high)*67;
    }
    for(i = 0; i < N; i++)
    {
        L->list[i].x += getRandomIndex(low,high)*31;
    }
    for(i = 0; i < N; i++)
    {
        L->list[i].y = getRandomIndex(low,high)*73;
    }
    for(i = 0; i < N; i++)
    {
        L->list[i].y += getRandomIndex(low,high)*24;
    }
    //printPointList(L,N);
    printf("===============\n");
    quickSort(L,low,high);
    //printPointList(L,N);
    PointClosed pointClosed;
    pointClosed.space = 60000;
    BruteForce(L,&pointClosed,0,N-1);
    printf("最近点为:a:");
    printPoint(pointClosed.a);
    printf(" b:");
    printPoint(pointClosed.b);
    printf(" 距离:%lf\n",pointClosed.space);
    PointClosed pointClosed_2;
    pointClosed_2.space = 60000;
    DivideAndConquer(L,&pointClosed_2,low,high);
    printf("最近点为:a:");
    printPoint(pointClosed_2.a);
    printf(" b:");
    printPoint(pointClosed_2.b);
    printf(" 距离:%lf\n",pointClosed_2.space);
    return 0;
}
Ejemplo n.º 4
0
int randomPartition(PointList *array,int low,int high)
{
    if(high <= low)
    {
        return low;
    }
    int random_index = getRandomIndex(low,high);
    swap(&array->list[low],&array->list[random_index]);
    return partition(array,low,high);
}
Ejemplo n.º 5
0
void Apply_knn:: display(double arr[][2],int arr_size,int lable[] )
{
    double temp[arr_size][2];
    cout<<"\n\nInside the display of Apply_knn\n";
    cout<<"\nDisplaying the contents of the array\n";
    for(int index_i=0;index_i<arr_size;index_i++)
    {
        cout<<"Index Number:\t"<<index_i<<"\n";
        cout<<arr[index_i][0]<<"\t"<<arr[index_i][1]<<"\n";
        temp[index_i][0]=arr[index_i][0];
        temp[index_i][1]=arr[index_i][1];
    }
    cout<<"Total Size is: \t"<<arr_size<<"\n";
    getRandomIndex(arr_size,temp,lable);
}
Ejemplo n.º 6
0
template <typename PointSource, typename PointTarget, typename FeatureT> void 
pcl::SampleConsensusInitialAlignment<PointSource, PointTarget, FeatureT>::findSimilarFeatures (
    const FeatureCloud &input_features, const std::vector<int> &sample_indices, 
    std::vector<int> &corresponding_indices)
{
  std::vector<int> nn_indices (k_correspondences_);
  std::vector<float> nn_distances (k_correspondences_);

  corresponding_indices.resize (sample_indices.size ());
  for (size_t i = 0; i < sample_indices.size (); ++i)
  {
    // Find the k features nearest to input_features.points[sample_indices[i]]
    feature_tree_->nearestKSearch (input_features, sample_indices[i], k_correspondences_, nn_indices, nn_distances);

    // Select one at random and add it to corresponding_indices
    int random_correspondence = getRandomIndex (k_correspondences_);
    corresponding_indices[i] = nn_indices[random_correspondence];
  }
}