Exemple #1
0
void ExtractSES(MinHeapS *mheap, SEEDS *all_seeds, int *heappointer, int xd, int yd, int zd,
		int *atom_index, int atom_num, ATOM *atomlist, float thresh)
{
  int i,j,k;
  int m,n,l, num, c;
  int index,index1;
  float dist;
  FLTVECT seed;
  char visited;


  xdim1 = xd;
  ydim1 = yd;
  zdim1 = zd;
  atom_list = atomlist;
  min_heap = mheap;
  AllSeeds = all_seeds;
  heap_pointer = heappointer;
  threshold = thresh;

  /* Initialize */ 
  index = 0;
  min_heap->size = 0;
  for (k=0; k<zdim1; k++)
    for (j=0; j<ydim1; j++)
      for (i=0; i<xdim1; i++) {
	if (atom_index[IndexVect1(i,j,k)] < 0) { 
	  for (num = 0; num < MaxAtom; num++)
	    AllSeeds[index].atom[num] = -1;
	  num = 0;
	  for (l=k-1; l<=k+1; l++) 
	    for (n=j-1; n<=j+1; n++) 
	      for (m=i-1; m<=i+1; m++) {
		if (m==i||n==j||l==k) {
		  index1 = atom_index[IndexVect1(m,n,l)];
		  if (index1 < 0) {
		    index1 = -index1-1;
		    visited = 0;
		    for (c=0; c<num; c++) {
		      if (index1 == AllSeeds[index].atom[c])
			visited = 1;
		    }
		    if (visited == 0) {
		      AllSeeds[index].atom[num] = index1;		   
		      num++;
		      if (num == MaxAtom)
			num--;
		    }
		  }
		}
	      }
	  	  
	  seed = FindSeed(i,j,k,index);
	  AllSeeds[index].seedx = seed.x;
	  AllSeeds[index].seedy = seed.y;
	  AllSeeds[index].seedz = seed.z;
	  dist = (seed.x-i)*(seed.x-i) + (seed.y-j)*(seed.y-j) + (seed.z-k)*(seed.z-k);
	  min_seed = index;
	  InsertHeap(i,j,k, dist);
	
	  index++;
	}
	else if (atom_index[IndexVect1(i,j,k)] > 0) {
	  heap_pointer[IndexVect1(i,j,k)] = MaxVal;
	}
	else {
	  heap_pointer[IndexVect1(i,j,k)] = -11;
        }
      }


  /* Fast Marching Method */
  while (1){
    GetMinimum();
    if (min_dist >= MaxDist-0.001)
      break;

    Marching();    
  }

}
Exemple #2
0
int main(int argc, char *argv[])
{
    int c;
    unsigned int threads = std::thread::hardware_concurrency();
    uint32_t lowerBoundSeed = 0;
    uint32_t upperBoundSeed = UINT_MAX;
    uint32_t depth = 1000;
    uint32_t seed = 0;
    bool generateFlag = false;
    double minimumConfidence = 100.0;
    PRNGFactory factory;
    std::string rng = factory.getNames()[0];

    while ((c = getopt(argc, argv, "d:i:g:t:r:c:uh")) != -1)
    {
        switch (c)
        {
            case 'g':
            {
                seed = strtoul(optarg, NULL, 10);
                generateFlag = true;
                break;
            }
            case 'u':
            {
                lowerBoundSeed = time(NULL) - ONE_YEAR;
                upperBoundSeed = time(NULL) + ONE_YEAR;
                break;
            }
            case 'r':
            {
                rng = optarg;
                std::vector<std::string> names = factory.getNames();
                if (std::find(names.begin(), names.end(), rng) == names.end())
                {
                    std::cerr << WARN << "ERROR: The PRNG \"" << optarg << "\" is not supported, see -h" << std::endl;
                    return EXIT_FAILURE;
                }
                break;
            }
            case 'd':
            {
                depth = strtoul(optarg, NULL, 10);
                if (depth == 0)
                {
                    std::cerr << WARN << "ERROR: Please enter a valid depth > 1" << std::endl;
                    return EXIT_FAILURE;
                }
                break;
            }
            case 'i':
            {
                std::ifstream infile(optarg);
                if (!infile)
                {
                    std::cerr << WARN << "ERROR: File \"" << optarg << "\" not found" << std::endl;
                }
                std::string line;
                while (std::getline(infile, line))
                {
                    observedOutputs.push_back(strtoul(line.c_str(), NULL, 0));
                }
                break;
            }
            case 't':
            {
                threads = strtoul(optarg, NULL, 10);
                if (threads == 0)
                {
                    std::cerr << WARN << "ERROR: Please enter a valid number of threads > 1" << std::endl;
                    return EXIT_FAILURE;
                }
                break;
            }
            case 'c':
            {
                minimumConfidence = ::atof(optarg);
                if (minimumConfidence <= 0 || 100.0 < minimumConfidence)
                {
                    std::cerr << WARN << "ERROR: Invalid confidence percentage " << std::endl;
                    return EXIT_FAILURE;
                }
                break;
            }
            case 'h':
            {
                Usage(factory, threads);
                return EXIT_SUCCESS;
            }
            case '?':
            {
                if (optopt == 'd')
                   std::cerr << "Option -" << optopt << " requires an argument." << std::endl;
                else if (isprint(optopt))
                   std::cerr << "Unknown option `-" << optopt << "'." << std::endl;
                else
                   std::cerr << "Unknown option character `" << optopt << "'." << std::endl;
                Usage(factory, threads);
                return EXIT_FAILURE;
            }
            default:
            {
                Usage(factory, threads);
                return EXIT_FAILURE;
            }
        }
    }

    if(generateFlag)
    {
        std::vector<uint32_t> results;
        if(observedOutputs.empty())
        {
            results = GenerateSample(seed, depth, rng);
        }
        else
        {
            results = GenerateSample(observedOutputs, depth, rng);
        }
        for (unsigned int index = 0; index < results.size(); ++index)
            std::cout << results.at(index) << std::endl;
        return EXIT_SUCCESS;

    }

    if(observedOutputs.empty())
    {
        Usage(factory, threads);
        std::cerr << WARN << "ERROR: No input numbers provided. Use -i <file> to provide a file" << std::endl;
        return EXIT_FAILURE;
    }

    if(InferState(rng))
    {
        return EXIT_SUCCESS;
    }
    FindSeed(rng, threads, minimumConfidence, lowerBoundSeed, upperBoundSeed, depth);
    return EXIT_SUCCESS;
}