Example #1
0
extern "C" DLLIMPORT SearchContext* __stdcall create(const Point* points_begin, const Point* points_end)
{
  context.nrOfPoints = points_end - points_begin;

  Point * points = new Point[context.nrOfPoints];    

// ordering points according to rank 
// (!minor cheating! I use that rank goes from 0 to 9999999)
  for (uint32_t i = 0; i<context.nrOfPoints; i++)
    points[ (*(points_begin+i)).rank ] = *(points_begin+i);
  context.points = points;
    
  int32_t clNr = 0;

  std::vector<Point *> sorting;

  for (uint32_t i = 0; i<context.nrOfPoints; i++)
    sorting.push_back(context.points+i);

// sorting points according to X-value
  std::sort( sorting.begin(), sorting.end(), compareX );  
    
  std::vector<Point *>::iterator it = sorting.begin();
  std::vector<Point *>::iterator end = sorting.end();
  
  Cluster * clusters = new Cluster[NUMBER_OF_CLUSTERS];

  while( it < end )
  {
// partitioning the points into vertical strips 
// and sorting the points inside each strip according to Y-value
  	int32_t xCutSize = ( it + X_CUTS <= end ) ? X_CUTS : end-it;		    	
  	std::sort( it, it+xCutSize, compareY );

      
    while( xCutSize > 0 )
  	{
// partitioning the points inside each strip into rectangles 
// and sorting them according to rank --> clusters
	  int32_t xyCutSize = ( XY_CUTS <= xCutSize ) ? XY_CUTS : xCutSize;

      Point * clusterPoints = new Point[xyCutSize];
	  
  	  std::sort( it, it+xyCutSize, compareRank );
  	    	  
	  for (int32_t ptNr = 0; ptNr < xyCutSize; ptNr++)
        clusterPoints[ptNr] = **(it+ptNr);

	  clusters[clNr].points = clusterPoints; 

      clusters[clNr].size = xyCutSize;

	  findBorders( clusters + clNr );    
  	    	          
      it += xyCutSize;
	  xCutSize -= xyCutSize;
  	  clNr++;
    }
  }
  context.nrOfClusters = clNr;
  context.clusters = clusters;

//  sorting.clear();
  
  return &context;              
};
Example #2
0
int main(int argc, char** argv)
{
   ////////// read in 2D array of data
   int N = 100;
   int M = 150;

   int32_t* input;
   float** arr;

   if (argc > 1)
   {
      input = readfile(argv[1], &N, &M);

      arr = (float**)malloc(N*sizeof(float*));
      for (int i=0; i < N; ++i)
      {
         arr[i] = (float*)malloc(M*sizeof(float));
         for (int j=0; j < M; ++j)
         {
            arr[i][j] = (float)(input[i*M + j] != 0.0);
         }
      }
      free(input);
   }

   else
   {
      for (int i=0; i < N; ++i)
      {
         for (int j=0; j < M; ++j)
         {
            if (((45 < (i+j/8)%80 && (i+j/8)%80 < 55) || (i%66 >= 20 && (j+i/3)%28 >= 20)) && i != N-1 && i != 0 && j != M-1 && j != 0)
               arr[i][j] = 0.0;
            else
               arr[i][j] = 1.0;
            printf("%d", arr[i][j] == 1.0);
         }
         printf("\n");
      }
   }
   ////////// normalize array to floats 0.0 and 1.0


   std::vector<ivec2> borders;
   std::queue<ivec2> skeleton;

#pragma omp parallel
  {
#pragma omp for collapse(2)
   for (int i=0; i < N; ++i)
   {
      for (int j=0; j < M; ++j)
      {
         arr[i][j] = findBorders(arr, N, M, i, j);
         if (arr[i][j] == 0.5)
         {
#pragma omp critical
            borders.push_back(ivec2(i,j));
            //printf("%zd (%d,%d)\n", borders.size(), i, j);
         }
      }
      //printf("\n");
   }



#pragma omp for collapse(2)
   for (int i=0; i < N; ++i)
   {
      for (int j=0; j < M; ++j)
      {
         if (arr[i][j] == 0.0 && 0.000 >= forceThin(arr, N, M, i, j, borders))
         {
            arr[i][j] = 0.0;
#pragma omp critical
            skeleton.push(ivec2(i,j));
         }
         else if (arr[i][j] != 0.5)
            arr[i][j] = 1.0;
         //printf("%d", (arr[i][j] != 0.0) + (arr[i][j] == 0.5));
      }
      //printf("\n");
   }
  }
   while (skeleton.size() > 1)
   {
      ivec2 point = skeleton.front();
      skeleton.pop();
      extend(arr, M, N, point, borders, &skeleton);
   }

   if (argc == 1)
   {
      for (int i=0; i < N; ++i)
      {
         for (int j=0; j < M; ++j)
         {
            printf("%d", (arr[i][j] != 0.0) + (arr[i][j] == 0.5));
         }
         printf("\n");
      }
   }
   else
   {
      if (argc == 2)
         writefile(argv[1], arr, N, M);
      else //argc >= 3
         writefile(argv[2], arr, N, M);
   }

   for (int i=0; i < N; ++i)
      free(arr[i]);
   free(arr);

   return 0;
}
Target::Target( const vector< Point >& inputList )
{
	pointList = inputList;
	numberOfPoints = pointList.size();
	findBorders();
}