Beispiel #1
0
MQSOSubSwarm::MQSOSubSwarm(int size, bool flag):Swarm<CodeVReal,MQSOParticle>(size,flag),m_Nplus(5),m_Nq(5),\
    m_N(5),m_Q(pow(1./4.9,1./0.6)),m_Rcloud(1.0){

	assignType();
	m_swarmType=2;

}
Beispiel #2
0
// --- Properties ---------------------------------------------------------- //
void AmberAtomTyper::setMolecule(const chemkit::Molecule *molecule)
{
    chemkit::AtomTyper::setMolecule(molecule);

    m_types.resize(molecule->atomCount());

    for(size_t i = 0; i < molecule->size(); i++) {
        m_types[i] = assignType(molecule->atom(i));
    }
}
Beispiel #3
0
/**
 * @brief Parser::parse Parses the sentence and creates the trees
 * @return the trees
 */
STvector Parser::parse(){
    SyntaxTree S(new TNpair(GtSpair(SENTENCE,SyntaxWord()))); //At the beginning, CURRENT is at the true root
    std::size_t cutoff = 0;
    while(recDescent(S,cutoff)){ //RecDescends based on the CURRENT pointer in the tree
        _valid.insert(_valid.end(),S);
        if(!findFirstIncomplete(S)) //Sets the CURRENT to the first slowest subtree that has more defs to explore
            break; //If it cannot find any more subtrees with more defs to explore, then stop
        cutoff = S.leavesBefore();
        removePartial(S);
    } //As long as recdescent is able to continue making trees
    for(std::size_t i = 0; i < _valid.size(); ++i){
        _valid[i].shiftToRoot();
        assignType(_valid[i]);
        attachWords(_valid[i]);
        assignHeadWords(_valid[i]);
        assignObjects(_valid[i]);
    }
    removeTrees();
    return _valid;
}
Beispiel #4
0
int main (int argc, char **argv)
{
  struct CCDdev device = {"/dev/ccda"};
  struct CCDexp exposure = {&device};
  unsigned short *pixelRow, *end;
  int overage;
  unsigned avgPixel = 0;
  char *outFn;
  FILE *outFile;

  const static struct option options[] = {
    {"autoexpose", 2, NULL, 'a'},
    {"binning", 1, NULL, 'b'},
    {"bin", 1, NULL, 'b'},
    {"offset", 1, NULL, 'o'},
    {"origin", 1, NULL, 'o'},
    {"size", 1, NULL, 's'},
    {"dark", 0, NULL, 'D'},
//    {"depth", 1, NULL, 'd'},
    {"nowipe", 0, NULL, 'w'},
    {"noclear", 0, NULL, 'c'},
    {"noaccumulation", 0, NULL, 'A'},
    {"tdi", 0, NULL, 't'},
    {"TDI", 0, NULL, 't'},
    {"tiff", 2, NULL, 'T'},
    {"TIFF", 2, NULL, 'T'},
    {"FITS", 0, NULL, 'F'},
    {"fits", 0, NULL, 'F'},
    {"JPEG", 0, NULL, 'J'},
    {"jpeg", 0, NULL, 'J'},
    {"camera", 1, NULL, 'n'},
    {"debug", 2, NULL, 'S'},
    {"help", 0, NULL, 'h'},
    {NULL}
  };

  progName = basename (argv[0]);
  if (write (progressFD, "", 0)) progressFD=fileno(stdout);
  for (;;) {
    int optc = getopt_long_only (argc, argv, "", options, 0);
    switch(optc) {
      case -1:
        goto gotAllOpts;
      case 'a':  //auto exposure
        exposureSecs = 5*60;  //default to 5 minute max exposure time
        if (optarg) {
          char *terminator = optarg;
          if (*optarg != ',') terminator=parseDuration (optarg, &exposureSecs);
          switch (*terminator) {
            case ',':
              switch(*(terminator=parseInt (terminator+1, &maxAutoSignal))) {
                case ',':
                  if (*parseInt(terminator+1, &adcBias))
                    syntaxErr("Junk text after min A/D counts!");
                case '\0':
                  break;
                default:
                  syntaxErr("Junk text after autoexposure max A/D count target!");
              }
            case '\0':
              break;
            default:
              syntaxErr ("Junk text after autoexposure max duration!");
          }
          if (exposureSecs < 0.002)
            syntaxErr ("autoexposure limit must be > 2ms");
        }
        exposureSecs = -exposureSecs;
        break;
      case 'b':  //XY binning
        parseXYoptArg (&binX, &binY);
        if (!validBin(binX) || !validBin(binY))
          syntaxErr ("Binning factors must be between 1 and 4!");
        break;
      case 'o':  //origin offset
        parseXYoptArg (&offsetX, &offsetY);
        if (offsetX < 0 || offsetY < 0)
          syntaxErr ("Negative origin offset specified!");
        break;
      case 's':  //image size
        parseXYoptArg (&sizeX, &sizeY);
        if (sizeX < 0 || sizeY < 0)
          syntaxErr ("Negative image size specified!");
        break;
      case 'd':  //depth
        if (*parseInt (optarg, &CCDdepth))
          syntaxErr ("invalid text after depth option");
        if (CCDdepth <= 0)
          syntaxErr ("Negative # of depth bits specified");
        break;
      case 'S':  //display debuging status info
        debug = optarg ? atoi(optarg) : 1;
        break;
      case 'w':  //suppress CCD wipe
        exposure.flags |= CCD_EXP_FLAGS_NOWIPE_FRAME;
        break;
      case 'c':  //suppress image clear
        exposure.flags |= CCD_EXP_FLAGS_NOCLEAR_FRAME;
        break;
      case 't':  //time delay integration
        exposure.flags |= CCD_EXP_FLAGS_TDI;
        break;
      case 'A':  //no binning accumulation
        exposure.flags |= CCD_EXP_FLAGS_NOBIN_ACCUM;
        break;
      case 'D':  //dard frame
        exposure.flags |= CCD_EXP_FLAGS_NOOPEN_SHUTTER;
        break;
      case 'n':  //camera device file
        device.filename[NAME_STRING_LENGTH]='\0';
        strncpy (device.filename, optarg, NAME_STRING_LENGTH-1);
        break;
      case 'T':  //generate TIFF file
        assignType(TIFFfile);
        if (optarg && toupper(*optarg)=='D')
          setenv ("TIFF_COMPRESSION", "32946", 1);
        break;
      case 'F': //generate FITS file
        assignType(FITSfile);
        break;
      case 'J': //generate JPEG file
        assignType(JPEGfile);
        break;
      case 'h':
        usage();
        return 0;
      default:
        syntaxErr("invalid option: %s", argv[optind]);
    }
  }
gotAllOpts: //on to arguments (exposure time and output file name)
  if (exposureSecs == 0.0) {
    if (!argv[optind])
      syntaxErr ("Missing Exposure Time");
    if (*parseDuration (argv[optind], &exposureSecs))
      syntaxErr ("Junk text after exposure duration");
    if (exposureSecs < 0.001)
      syntaxErr ("Exposure duration must be >= 0.001 seconds");
    ++optind;
  }
  if (!CCDconnect (&device)) {
    fprintf (stderr, "Cannot open camera device: %s\n", device.filename);
    return 1;
  }
  printf ("%s: %dx%d pixel %d-bit CCD camera\n",
    device.camera, device.width, device.height, device.depth);

  outFn = argv[optind];
  if (outFn) {
    char *lastDot;
    outFile = fopen (outFn, "w");
    if (!outFile) {
      perror(outFn);
      return errno;
    }
    if (outputFileType == unspecifiedFile) {
      lastDot = strrchr (outFn, '.');
      if (lastDot) switch (toupper(lastDot[1])) {
        case 'J': outputFileType = JPEGfile;
          break;
        case 'T': outputFileType = TIFFfile;
          break;
        case 'F': outputFileType = FITSfile;
          break;
      }
    }
  }else  //trying to write image to stdout
    syntaxErr ("Missing output image filename!");

  exposure.width = sizeX ? sizeX : device.width;
  exposure.height = sizeY ? sizeY : device.height;
  exposure.xoffset = offsetX;
  exposure.yoffset = offsetY;
  overage = device.width - exposure.width - offsetX;
  if (overage < 0)
    exposure.width += overage;
  overage = device.height - exposure.height - offsetY;
  if (overage < 0)
    exposure.height += overage;
  exposure.xbin = binX;
  exposure.ybin = binY;
  exposure.dacBits = CCDdepth ? CCDdepth : device.dacBits;

  if (exposure.dacBits < 8 || exposure.dacBits > 16)
    syntaxErr ("Pixel depth of %d bits is not currently supported!\n", exposure.dacBits);

  if (exposureSecs < 0.0) {
    exposureSecs = -exposureSecs;
    if (debug) printf(
      "Calibrating <= %g second exposure between %d and %d A/D counts...\n",
                exposureSecs, maxAutoSignal, adcBias);
    exposure.msec = exposureSecs * 1000.0 + 0.5;
    if (optimizeExposure (&exposure)) {
      fprintf (stderr, "Autoexposure calibration failed!\n");
      return 6;
    }
  }else
    exposure.msec = exposureSecs * 1000.0 + 0.5;

  exposureSecs = (double)exposure.msec / 1000.0;
  printf ("Exposing %dx%d pixel %d-bit image for %g seconds\n",
    exposure.width/binX, exposure.height/binY, exposure.dacBits, exposureSecs);

  expose (&exposure);

  /*  Write out the image in the specified format */
  switch (outputFileType) {
    case unspecifiedFile:
      outputFileType = TIFFfile;  //default to TIFF
    case TIFFfile:
      {
        TIFF *tif = TIFFFdOpen (fileno(outFile), outFn, "w");
        if (!tif || saveTIFF (tif, &exposure)) imageWrtFailed();
        TIFFClose(tif);
      }
      break;

    case FITSfile:
      if (saveFITS (fileno(outFile), &exposure)) imageWrtFailed();
      break;

    default:
      syntaxErr("Unsupported image file type:  %s",fileTypeName[outputFileType]);
  }
  printf ("%s: %s Upload Complete\n", outFn, fileTypeName[outputFileType]);
  return 0;
}
/**************************************************************************************************
* Analyze the terrain and assign the proper type
**************************************************************************************************/
void TerrainAnalyzer::analyze(SmurfPolygon*** terrain, int w, int h, float maxHeight, float minHeight) {
	// Iterate through the terrain and analyze each individual terrain piece of terrain
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j+=2) {
			// Clear the probabilities
			clearProbabilities();
			
			// Choose the a piece of terrain and analyze it
			//**********************************************************************************************
			// Analyze slope
			analyzeSlope(terrain[i][j]);

			// Analyze height
			analyzeHeight(terrain[i][j], maxHeight, minHeight);

			/* Analyze adjacent terrains
			* Even
			*	i-1: j-1, j, j+1, j+2, j+3
			*	i: j-2, j-1
			* Odd 
			*	i-1: j, j+1, j+2
			*	i: j-2, j-1
			*/
			int adjacentAnalyzed = 0;
			if(i % 2 == 0) {	// Even
				// case: i - 1
				if(i - 1 >= 0) {
					if(j - 1 >= 0) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j-1]);
						adjacentAnalyzed++;
					}

					analyzeAdjacent(terrain[i][j], terrain[i-1][j]);
					adjacentAnalyzed++;

					if(j + 1 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+1]);
						adjacentAnalyzed++;
					}
					if(j + 2 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+2]);
						adjacentAnalyzed++;
					}
					if(j + 3 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+3]);
						adjacentAnalyzed++;
					}
				}

				// case: i
				if(j - 2 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-2]);
					adjacentAnalyzed++;
				}
				if(j - 1 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-1]);
					adjacentAnalyzed++;
				}
			} else {	// Odd
				// case: i - 1
				if(i - 1 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i-1][j]);
					adjacentAnalyzed++;

					if(j + 1 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+1]);
						adjacentAnalyzed++;
					}
					if(j + 2 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+2]);
						adjacentAnalyzed++;
					}
				}

				// case: i
				if(j - 2 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-2]);
					adjacentAnalyzed++;
				}
				if(j - 1 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-1]);
					adjacentAnalyzed++;
				}					
			}

			if(adjacentAnalyzed == 0)
				adjacentAnalyzed = 1;
			
			// Find the average probability of the adjacent values
			for(int k = 0; k < 6; k++) {
				// Edge case testing. This is to prevent a band of the most probable substance at the seeding 
				// corner, essentially this causes the entire first row of values to act as a seed rather than the first value.
				if(i == 0)
					terrainProbabilities[k][3] = 0.1f;
				else
					terrainProbabilities[k][3] = terrainProbabilities[k][3] / (float)adjacentAnalyzed;
			}

			// Use naive bayes for final analysis of probabilities
			naiveBayes();
			
			// assign terrain type
			assignType(terrain[i][j]);
			assignType(terrain[i][j+1]);
		}
	}
}