I have a lot of unsorted 2D points which represent the positions of randomized picked pixels of an image.
In the next step I try sort/rasterize them in a 2D array, by point with smallest x, y value at
array[0][0]
and Point with highest x,y value at
array[n][k]
with condition 1:
all the other 2D should be between this boundaries and almost sorted.
condition 2:
all rows of the array should be filled nearly with same number of values, same for the columns.
Any ideas how to solve this problem?
I computed delaunay-triangulation and thought about a voronoi diagram for going step by step threw each cell, but I don´t know if I am on the right path.
My random positions are created in that way:
std::vector<Point_d> sample_rand_points(){
std::cout<<"sampling random points\n";
std::vector<Point_d> output_pattern;
//PREPARE:
std::vector<std::pair<int, int> > not_sampled_yet;
for(int x=0; x<_X; x++)
{
for(int y=0; y<_Y; y++)
{
not_sampled_yet.push_back(std::pair<int,int>(x,y));
}
}
//SAMPLING
Point_d pix;
for (int i=0; i<_Amount; i++)
{
//std::cout<<i<<"\n";
int n= rand()% not_sampled_yet.size();
pix.x= (double)not_sampled_yet[n].first;
pix.y= (double)not_sampled_yet[n].second;
not_sampled_yet[n]=not_sampled_yet.back();
not_sampled_yet.pop_back();
output_pattern.push_back(pix);
}
return output_pattern;
}
Output is one vector with Points {{x1,y1},{x2,y2},......}