Beispiel #1
0
Person::Person(bool healthy, int contactLow, int contactHigh,
									int immunityLow, int immunityHigh)
			 : strength(INITIAL_STRENGTH), is_Healthy(healthy), is_Dead(false),
			   successHealth(0)
{
	checkBoundary(contactLow, contactHigh);
	checkBoundary(immunityLow, immunityHigh);

	// Generate contact
	RandomNum rndContact(contactHigh, contactLow);
	rndContact.genRandNum();
	contact = rndContact.getRandNum();
	randContact = rndContact;

	// Generate immunity
	RandomNum rndImmunity(immunityHigh, immunityLow);
	rndImmunity.genRandNum();
	immunity = rndImmunity.getRandNum();
	randImmunity = rndImmunity;

	// Generate contact decrease when sick
	int sickLow = CONTACT_SICK_LOW;
	int sickHigh = CONTACT_SICK_HIGH;
	RandomNum rndContactSick(sickLow, sickHigh);
	rndContactSick.genRandNum();
	contactSickPct = rndContactSick.getRandNum() / 100;

	// Initialize random number gen. for randFor100Pct
	randFor100Pct.setMinMaxNum(0, 100);
}
Beispiel #2
0
void moveRight(CHARACTER *character,QUESTIONBLOCK blocks[],int numBlocks,ENEMY enemies[],int numEnemies) {
    character->mode = 0;
    character->direction = 0;
    character->oldCol = character->col;
    character->col++;
    checkBoundary(character,blocks,numBlocks,enemies,numEnemies);
}
Beispiel #3
0
void Person::setImmunityRangeLoHi(int immunityLow, int immunityHigh)
{
	checkBoundary(immunityLow, immunityHigh);
	randImmunity.setMinMaxNum(immunityLow, immunityHigh);
	randImmunity.genRandNum();
	contact = randImmunity.getRandNum();
}
Beispiel #4
0
// Set methods for contact and immunity ranges.
void Person::setContactRangeLoHi(int contactLow, int contactHigh)
{
	checkBoundary(contactLow, contactHigh);
	randContact.setMinMaxNum(contactLow, contactHigh);
	randContact.genRandNum();
	contact = randContact.getRandNum();
}
Beispiel #5
0
void Field::setPosition(int v, int h, Position pos)
{
    if (checkBoundary(v, h) == false){
        throw BadFieldBoundary(v, h);
    }
    this->field[v][h] = pos;
}
Beispiel #6
0
Position Field::getPosition(int v, int h) const
{
    if (checkBoundary(v, h) == false){
        throw BadFieldBoundary(v, h);
    }
    return this->field[v][h];
}
Beispiel #7
0
std::shared_ptr<PathNode> PathFinding::getNodebyPosFromWorld(int xPos, int yPos)
{
    if(checkBoundary(xPos,yPos))
        return _world[xPos+yPos*_cols];
    else
        return nullptr;
}
Beispiel #8
0
void readBlockAroundPoint (int xPos, int halfXapp, int* curXapp, int* leftShift) {

    int startX = xPos - halfXapp;
    int ix, id, ida, iz, ind, dataShift, tracesShift, pointsNumToRead;
    size_t startPos;
    float *ptrToTrace, *ptrToTraceSq, *ptrFrom, *ptrTo, *ptrSqFrom, *ptrSqTo;

    /* check if the apperture is adequate... if not - correct it and the start point */
    checkBoundary (&startX, curXapp);
    *leftShift = xPos - startX;
    pointsNumToRead = dagSize_ * (*curXapp);

    ptrToDags_   = sf_floatalloc (pointsNumToRead);
    ptrToDagsSq_ = sf_floatalloc (pointsNumToRead);
    memset (ptrToDags_,   0, pointsNumToRead * sizeof (float));
    memset (ptrToDagsSq_, 0, pointsNumToRead * sizeof (float));

    ptrToData_   = sf_floatalloc (pointsNumToRead);
    ptrToDataSq_ = sf_floatalloc (pointsNumToRead);
    memset (ptrToData_,   0, pointsNumToRead * sizeof (float));
    memset (ptrToDataSq_, 0, pointsNumToRead * sizeof (float));			

    startPos = (size_t) startX * dagSize_ * sizeof (float);

    sf_seek (inDags_,   startPos, SEEK_SET);
    sf_seek (inDagsSq_, startPos, SEEK_SET);

    sf_floatread (ptrToData_,   pointsNumToRead, inDags_);
    sf_floatread (ptrToDataSq_, pointsNumToRead, inDagsSq_);

    /* substacking in the x-dip direction */
		
    for (ix = 0; ix < *curXapp; ++ix) {
		for (id = 0; id < dipNum_; ++id) {
			
		    tracesShift = ix * dipNum_ + id;
		    ptrToTrace   = ptrToDags_ + tracesShift * zNum_;
		    ptrToTraceSq = ptrToDagsSq_ + tracesShift * zNum_;

		    for (ida = 0; ida < xdipapp_; ++ida) {		
				ind = id - xdipapp_ / 2 + ida;
				if (ind < 0 || ind >= dipNum_) continue;		
				
				dataShift = ix * dipNum_ + ind;
				ptrFrom   = ptrToData_   + dataShift * zNum_;
				ptrSqFrom = ptrToDataSq_ + dataShift * zNum_;

				ptrTo     = ptrToTrace;
				ptrSqTo   = ptrToTraceSq;

				for (iz = 0; iz < zNum_; ++iz, ++ptrTo, ++ptrSqTo, ++ptrFrom, ++ptrSqFrom) {
				    *ptrTo += *ptrFrom;
				    *ptrSqTo += *ptrSqFrom;
				}
	    	}
		}
    }

    return;
}
Beispiel #9
0
void Particle::updatePosition()
{
	x = x + v;
	checkBoundary();
	x_fitness = func(x);
	if (x_fitness < p_fitness)
	{
		p = x;
		p_fitness = x_fitness;
	}
}
Beispiel #10
0
Direction Field::whatIsEmpty(int v, int h) const
{
    if (checkBoundary(v, h) == false){
        throw BadFieldBoundary(v, h);
    }

    if (isEmpty(v - 1, h) == true) return Direction::UP;
    if (isEmpty(v, h + 1) == true) return Direction::RIGHT;
    if (isEmpty(v + 1, h) == true) return Direction::DOWN;
    if (isEmpty(v, h - 1) == true) return Direction::LEFT;
    return Direction::NO_DIRECTION;
}
Beispiel #11
0
bool Field::isEmpty(int v, int h) const
{
    if(checkBoundary(v, h) == false){
        return false;
    }

    if (this->field[v][h] != Position::EMPTY){
        return false;
    }

    return true;
}
void FaceComponent::generateColorImg()
{
    //get the non-horizontal bounding rectangle
	cv::RotatedRect rotatedRect = cv::minAreaRect(featurePoints_);
    //extend rectangle
	rotatedRect.size.height *= colorImgScale_;
	rotatedRect.size.width *= colorImgScale_;
	rotatedRect.points(vertices_);
    //rectangle vertexes cordinate
	std::vector<cv::Point2f> rotatedVertices;
	for (int i = 0; i < 4; i++)
	{
		//line(pFrame_->colorImg(), vertices_[i], vertices_[(i + 1) % 4], cv::Scalar(255));
		rotatedVertices.push_back(vertices_[i]);
	}
    //sort rectangle vertexes by cordinate x
	std::sort(rotatedVertices.begin(), rotatedVertices.end(),
		[](const cv::Point2f p0, const cv::Point2f p1)
		-> bool
	{
		return p0.x < p1.x;
	});
    //rotate image by rectangle angle
	cv::Rect rect;
	rect.width = rotatedRect.size.width;
	rect.height = rotatedRect.size.height;
	float rotatedAngle = rotatedRect.angle;
	if (abs(rotatedAngle)>45)
	{
		rotatedAngle += 90;
		rect.width = rotatedRect.size.height;
		rect.height = rotatedRect.size.width;
	}
	cv::Mat rotatedMat = cv::getRotationMatrix2D(rotatedRect.center, rotatedAngle, 1);
	cv::Mat cRotatedImg;
	cv::warpAffine(pFrame_->colorImg(), cRotatedImg, rotatedMat, pFrame_->colorImg().size());
	//cv::imshow("cRotatedImg", cRotatedImg);
	cv::Mat rotatedMatf;
	rotatedMat.convertTo(rotatedMatf, CV_64FC1);
    leftTopPoint_ = rotatedVertices[0].y < rotatedVertices[1].y ? rotatedVertices[0] : rotatedVertices[1];
    rect.x = rotatedMatf.at<double>(0, 0)* leftTopPoint_.x + rotatedMatf.at<double>(0, 1)* leftTopPoint_.y + rotatedMatf.at<double>(0, 2);
    rect.y = rotatedMatf.at<double>(1, 0)* leftTopPoint_.x + rotatedMatf.at<double>(1, 1)* leftTopPoint_.y + rotatedMatf.at<double>(1, 2);
    //check boundary to prevent boundary overstepping
    checkBoundary(rect,cv::Rect(0,0,cRotatedImg.size().width,cRotatedImg.size().height));
    /*rect.x = rect.x < 0 ? 0 : rect.x;
	rect.y = rect.y < 0 ? 0 : rect.y;
	rect.width = rect.x + rect.width > cRotatedImg.size().width ? cRotatedImg.size().width - rect.x-1:rect.width;
    rect.height = rect.y + rect.height > cRotatedImg.size().height ? cRotatedImg.size().height - rect.y - 1 : rect.height;*/
    //cut out image
	colorImg_ = cRotatedImg(rect).clone();
}
Beispiel #13
0
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue)
{
    if ((!strValue) || (!*strValue))
        ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);

    fRawData = XMLString::replicate(strValue, fMemoryManager);   // preserve the raw data form

    XMLCh* tmpStrValue = XMLString::replicate(strValue, fMemoryManager);
    ArrayJanitor<XMLCh> janTmpName(tmpStrValue, fMemoryManager);
    XMLString::trim(tmpStrValue);

    normalizeZero(tmpStrValue);

    if (XMLString::equals(tmpStrValue, XMLUni::fgNegINFString) )
    {
        fType = NegINF;
        fSign = -1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) )
    {
        fType = PosINF;
        fSign = 1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) )
    {
        fType = NaN;
        fSign = 1;
    }
    else
        //
        // Normal case
        //
    {
        checkBoundary(tmpStrValue);
    }

}
void XMLAbstractDoubleFloat::init(const XMLCh* const strValue)
{
    if ((!strValue) || (!*strValue))
        ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);

    fRawData = XMLString::replicate(strValue, fMemoryManager);   // preserve the raw data form

    XMLCh* tmpStrValue = XMLString::replicate(strValue, fMemoryManager);
    ArrayJanitor<XMLCh> janTmpName(tmpStrValue, fMemoryManager);
    XMLString::trim(tmpStrValue);

    if (!*tmpStrValue) 
        ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);

    normalizeZero(tmpStrValue);

    if (XMLString::equals(tmpStrValue, XMLUni::fgNegINFString) )
    {
        fType = NegINF;
        fSign = -1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgPosINFString) )
    {
        fType = PosINF;
        fSign = 1;
    }
    else if (XMLString::equals(tmpStrValue, XMLUni::fgNaNString) )
    {
        fType = NaN;
        fSign = 1;
    }
    else
        //
        // Normal case
        //
    {
        // Use a stack-based buffer when possible.  Since all
        // valid doubles or floats will only contain ASCII
        // digits, a decimal point,  or the exponent character,
        // they will all be single byte characters, and this will
        // work.
        static const unsigned int  maxStackSize = 100;

        const unsigned int  lenTempStrValue =
            XMLString::stringLen(tmpStrValue);

        if (lenTempStrValue < maxStackSize)
        {
            char    buffer[maxStackSize + 1];

            XMLString::transcode(
                tmpStrValue,
                buffer,
                sizeof(buffer) - 1,
                getMemoryManager());

            // Do this for safety, because we've
            // no guarantee we didn't overrun the
            // capacity of the buffer when transcoding
            // a bogus value.
            buffer[maxStackSize] = '\0';

            // If they aren't the same length, then some
            // non-ASCII multibyte character was present.
            // This will only happen in the case where the
            // string has a bogus character, and it's long
            // enough to overrun this buffer, but we need
            // to check, even if it's unlikely to happen.
            if (XMLString::stringLen(buffer) != lenTempStrValue)
            {
                ThrowXMLwithMemMgr(
                    NumberFormatException,
                    XMLExcepts::XMLNUM_Inv_chars,
                    getMemoryManager());
            }

            checkBoundary(buffer);
        }
        else
        {
            char *nptr = XMLString::transcode(tmpStrValue, getMemoryManager());
            const ArrayJanitor<char> janStr(nptr, fMemoryManager);

            checkBoundary(nptr);
        }
    }

}
Beispiel #15
0
void initialiseFields(double *collideField, double *streamField, int *flagField,
        const int * const sublength, int rank, int iproc, int jproc, int kproc)
{
    const int xl = sublength[0];
    const int yl = sublength[1];
    const int zl = sublength[2];

    /* Minor value and major value to set for a plane (i.e. FRONT and BACK or BOTTOM and TOP) */
    STATE minor, major;

    /* Set all values of flagField to 0, i.e. FLUID state. We will apply boundary conditions
     in the following */
    memset(flagField, FLUID, (xl + 2) * (yl + 2) * (zl + 2) * sizeof(*flagField));

    /* XY plane */
    if (checkBoundary(rank, iproc, jproc, kproc) & BOTTOM) {
        /* Subdomains in bottom part of domain */
        minor = NO_SLIP;
        major = PARALLEL_BOUNDARY;
    }
    if (checkBoundary(rank, iproc, jproc, kproc) & TOP) {
        minor = PARALLEL_BOUNDARY;
        major = MOVING_WALL;
    }
    else {
        /* Inner cells have parallel boundaries */
        minor = PARALLEL_BOUNDARY;
        major = PARALLEL_BOUNDARY;
    }
    for (int y = 0; y < yl + 2; ++y) {
        for (int x = 0; x < xl + 2; ++x) {
            flagField[fidx(sublength, x, y, 0)] = minor;
            flagField[fidx(sublength, x, y, zl + 1)] = major;
        }
    }

    /* XZ plane */
    if (checkBoundary(rank, iproc, jproc, kproc) & FRONT) {
        minor = NO_SLIP;
        major = PARALLEL_BOUNDARY;
    }
    else if (checkBoundary(rank, iproc, jproc, kproc) & BACK) {
        minor = PARALLEL_BOUNDARY;
        major = NO_SLIP;
    }
    else {
        minor = PARALLEL_BOUNDARY;
        major = PARALLEL_BOUNDARY;
    }
    for (int z = 0; z < zl + 2; ++z) {
        for (int x = 0; x < xl + 2; ++x) {
            flagField[fidx(sublength, x, 0, z)] = minor;
            flagField[fidx(sublength, x, yl + 1, z)] = major;
        }
    }

    /* YZ plane */
    if (checkBoundary(rank, iproc, jproc, kproc) & LEFT) {
        minor = NO_SLIP;
        major = PARALLEL_BOUNDARY;
    }
    else if (checkBoundary(rank, iproc, jproc, kproc) & RIGHT) {
        minor = PARALLEL_BOUNDARY;
        major = NO_SLIP;
    }
    else {
        minor = PARALLEL_BOUNDARY;
        major = PARALLEL_BOUNDARY;
    }
    for (int z = 0; z < zl + 2; ++z) {
        for (int y = 0; y < yl + 2; ++y) {
            flagField[fidx(sublength, 0, y, z)] = minor;
            flagField[fidx(sublength, xl + 1, y, z)] = major;
        }
    }

    /* Stream and Collide Fields are initialized to the respective lattice weights of the Cell */
    int index = 0;
    for (int z = 0; z < zl + 2; ++z) {
        for (int y = 0; y < yl + 2; ++y) {
            for (int x = 0; x < xl + 2; ++x) {
                for (int i = 0; i < Q; ++i) {
                    collideField[index] = LATTICEWEIGHTS[i];
                    streamField[index] = LATTICEWEIGHTS[i];
                    ++index;
                }
            }
        }
    }
}