Example #1
0
File: SPK_Line.cpp Project: 4ian/GD
	void Line::pushBound(const Vector3D& bound)
	{
		bounds[0] = tBounds[0] = bounds[1];
		bounds[1] = tBounds[1] = bound;
		computeDist();
		computePosition();
	}
Example #2
0
bool Exif2GPX::writeGPX(const QStringList& pictures, const QString& gpxOutput,
			bool interpolate, unsigned offset,
			const QString& prefix) {
  // initialize GPX DOM
  QDomDocument qdd;
  QDomElement gpxElt = qdd.createElement("gpx");
  qdd.appendChild(gpxElt);
  gpxElt.setAttribute("version", "1.0");
  
  // add the waypoints
  QStringList::const_iterator iter;
  for (iter = pictures.begin(); iter != pictures.end(); ++iter) {
    QDateTime timestamp = getTimeFromEXIF(*iter);
    QFile file(*iter);
    QFileInfo fi(file);
    addWaypoint(gpxElt, computePosition(timestamp.addSecs(-offset),
					interpolate), 
		timestamp.addSecs(-offset), prefix, fi.fileName());
  }
  
  // write the file
  QFile gpxOut(gpxOutput);
  if (!gpxOut.open(IO_WriteOnly)) {
    std::cerr<<"Could not open "<<gpxOutput<<std::endl;
    return false;
  }
  QTextStream str(&gpxOut);
  str<<qdd.toString();
  
  return true;
}
Example #3
0
File: SPK_Line.cpp Project: 4ian/GD
	void Line::setBounds(const Vector3D& p0,const Vector3D& p1)
	{
		bounds[0] = tBounds[0] = p0;
		bounds[1] = tBounds[1] = p1;
		computeDist();
		computePosition();
	}
	/**
	* 
	* @param logDriverParameters The parameter has to be in the form file:filename, for example file:/tmp/foo
	* If the specified file already exists or it cannot be created, this method will throw an exception and
	* the UnixFileLogDriver object will not work. If the file was already opened by another component of the same process,
	* logging will work properly.
	*/
	void  UnixFileLogDriver::setLogDriverParameters (const string& logDriverParameters)  throw (IOException, bad_exception) 
	{
		_isInitialized=false;
		// first find out, if parameter is correct
		if (logDriverParameters.find("file:",0,5))
			throw IOException("logDriverParameters have incorrect syntax for UnixFileLogger (does not begin with 'file:')!");
		string filename(logDriverParameters,5); // extract filename from parameters
		// second stat the file
		struct stat statbuf;
		int result=stat(filename.c_str(),&statbuf);
		if (result==-1) {
			switch (errno) {
				case ENOENT: { // file does not exist
					_fd=open(filename.c_str(),O_WRONLY|O_CREAT|O_EXCL,S_IRUSR|S_IWUSR);
					if (_fd==-1)
						throw IOException("UnixFileLogDriver got an error while trying to create file "+ filename+ ": "+strerror(errno));
					// register new file descriptor
					int result2=fstat(_fd,&statbuf);
					if (result2==-1) {
						close(_fd);
						throw IOException("UnixFileLogDriver got an error while trying to stat created file "+ filename+ ": "+strerror(errno));
					}
					try {
						(*_clonedFDMap)[computePosition(statbuf)]=_fd;
					}
					catch (...) {
						close(_fd);
						throw;
					}
					_isInitialized=true;
					return;
				}
				default: {
					throw IOException("UnixFileLogDriver got an error while trying to stat file "+ filename+ ": "+strerror(errno));
				}
			}
		}

		
		map < long long int, int >::const_iterator i=_clonedFDMap->find(computePosition(statbuf));
		if (i==_clonedFDMap->end())
			throw IOException("UnixFileLogDriver refused to write in already existing file "+ filename);
		_fd=i->second;
		_isInitialized=true;
	}
Example #5
0
const vgm::Vec3i IImage::computePositionFromOffset( const uint32 offset ) const
{
    assert( isOffsetValid(offset) );

    const uint32 index = computeIndexFromOffset(offset);

    const vgm::Vec3i retVal = computePosition( index );

    assert( isValid(retVal) );

    return retVal;
}
	Ptr<ISubtitlesItem> CPangoCairoRenderer::render(Ptr<ISubtitlesItem> i_item)
	{
		Ptr<CSubtitlesTextItem> text = i_item;

		if (text.isNull() || i_item->getType() != SUBTITLES_TYPE_TEXT)
		{
			return Ptr<ISubtitlesItem>();
		}

		Ptr<CCairoSurface> surface = new CCairoSurface(m_displaySize.Height, m_displaySize.Width, SURFACE_FORMAT_ARGB32);

		cairo_t * cairo = cairo_create(surface->getSurface());
		
		cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0);
		cairo_paint(cairo);
		
		PangoLayout * layout = pango_cairo_create_layout(cairo);

		pango_layout_set_width(layout, m_displaySize.Width*PANGO_SCALE);
		pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
		pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
		pango_layout_set_text(layout, text->getText().c_str(), -1);

		PangoFontDescription * font = pango_font_description_from_string(m_font.c_str());
		pango_layout_set_font_description(layout, font);
		pango_font_description_free(font);

		cairo_set_source_rgb(cairo, 1.0, 1.0, 1.0);

		pango_cairo_update_layout(cairo, layout);
		pango_cairo_show_layout(cairo, layout);

		CValue<CRectangle> rect = getPixelRectangle(layout);
		
		cairo_destroy(cairo);

		g_object_unref(layout);

		if (rect.isValid())
		{

			Ptr<CCairoSurface> textSurface = new CCairoSurface(*surface, rect.getValue()); 
			
			CSize size = rect.getValue().Size;
			CPoint position = computePosition(size);
			CRectangle newRect(position, size);
			
			return new CSubtitlesGraphicsItem(textSurface, newRect, text->getBeginTime(), text->getEndTime());
		}

		return Ptr<ISubtitlesItem>();
	}
SplineVector3D LoopingCubicHermiteSpline::getPosition(double x) const
{
    //use modular arithmetic to bring x into an acceptable range
    x = fmod(x, numSegments);
    if(x < 0)
        x += numSegments;

    //find the interpolation data for this t value
    InterpolationData segment = segmentData.at(getSegmentIndex(x));
    double t = (x - segment.t0) * segment.tDistanceInverse;

    return computePosition(t, segment);
}
Spline::InterpolatedPTCW LoopingCubicHermiteSpline::getWiggle(double x) const
{
    //use modular arithmetic to bring x into an acceptable range
    x = fmod(x, numSegments);
    if(x < 0)
        x += numSegments;

    InterpolationData segment = segmentData.at(getSegmentIndex(x));
    double t = (x - segment.t0) * segment.tDistanceInverse;

    return InterpolatedPTCW(
                computePosition(t, segment),
                computeTangent(t, segment),
                computeCurvature(t, segment),
                computeWiggle(segment)
                );
}
Example #9
0
void Ball::update(float delta){
    if (isMoving()){
        //air resistance
        auto velocity = body -> getVelocity();
        auto length = velocity.length();
        if (length < VELOCITY_DUMP){
            body -> setVelocity( Vec2::ZERO );
        }else{
            auto dir = Vec2(velocity);
            dir.normalize();
            body -> setVelocity( velocity - (length * delta * AIR_RESISTANCE) * dir );
        }
    }
    //floating
    floatingPos = sin(ScreenUtil::getTime() * 3.0f + randomSeed * 3.14f) * Vec2(0 , 3);
    
    computePosition();
}
Example #10
0
void ParametricObject::generateGrid(){
	ofBackground(0);
    glEnable(GL_DEPTH_TEST);
    float steps_w = w;
    float steps_h = h;
    float step_w = 1.0/steps_w;
    float step_h = 1.0/steps_h;

	float xx,yy,zz;
	float i,j;

	int contador=0;
	int contadorIndices=0;
	std::vector<ofPoint>::iterator it_p;
	std::vector<ofPoint>::iterator it_n;
	std::vector<int>::iterator it_i;

	it_p = points.begin();
	it_n = normals.begin();
	it_i = indices.begin();
	float i_sub, j_sub;

	for (j=0;j<h;j++){
		for (i=0;i<w;i++){
			i_sub = i/(w-1);
			j_sub = j/(h-1);
			it_p = points.insert(it_p, computePosition(ofPoint(i_sub, j_sub, 0)));
			it_n = normals.insert(it_n, computePosition(ofPoint(i_sub, j_sub, 0)));
			contador++;

			//ofLogNotice()<<"Punto: "<<i<<" "<<j<<" "<<0<<" -> "<<computePosition(ofPoint(i_sub, j_sub, 0));

		}
	}
	for (j=0;j<h-1;j++){
		for (i=0;i<w-1;i++){

			xx = j*w+i;
			yy = (j+1)*w+i;
			zz = (j+1)*w+(i+1);
			//mesh.addTriangle(xx,yy,zz);
			it_i = indices.insert(it_i, xx);
			it_i = indices.insert(it_i, yy);
			it_i = indices.insert(it_i, zz);
			//ofLogNotice()<<"Agregando: "<<xx<<" "<<yy<<" "<<zz;

			xx = j*w+i;
			yy = j*w+(i+1);
			zz = (j+1)*w+(i+1);
			//mesh.addTriangle(xx,yy,zz);
			it_i = indices.insert(it_i, xx);
			it_i = indices.insert(it_i, yy);
			it_i = indices.insert(it_i, zz);
			//ofLogNotice()<<"Agregando: "<<xx<<" "<<yy<<" "<<zz;

			//mesh.addVertex(computePosition(ofPoint(i, j, 0)));
			//mesh.addNormal(computeNormal(ofPoint(i, j, 0)));
        }
    }
	/*
	ofLogNotice()<<"La cantidad de puntos es: "<<points.size();
	for(int i=0;i<points.size();i++){
		ofLogNotice()<<"Los puntos son: "<<ofToString(points.at(i));
	}*/
	
	
	/*
	for (j=0;j<h-1;j++){
		for (i=0;i<w-1;i++){
			xx = j*w+i;
			yy = (j+1)*w+i;
			zz = (j+1)*w+i+1;
			//mesh.addTriangle(xx,yy,zz);
			indices.push_back(xx);
			indices.push_back(yy);
			indices.push_back(zz);
			xx = j*w+i;
			yy = j*w+i+1;
			zz = (j+1)*w+i+1;
			//mesh.addTriangle(xx,yy,zz);
			indices.push_back(xx);
			indices.push_back(yy);
			indices.push_back(zz);
		}
    }*/
	
	/*
	ofLogNotice()<<"Laterales";
	for (j=0;j<h-1;j++){
			xx = j*w;
			yy = (j+1)*w;
			zz = (j+1)*w-1;
			//ofLogNotice() <<xx<<","<<yy<<","<<zz;
			//mesh.addTriangle(xx,yy,zz);
			it_i = indices.insert(it_i, xx);
			it_i = indices.insert(it_i, yy);
			it_i = indices.insert(it_i, zz);
			ofLogNotice()<<"Agregando borde: "<<xx<<" "<<yy<<" "<<zz;
			xx = (j+1)*w;
			yy = (j+1)*w-1;
			zz = (j+2)*w-1;
			//mesh.addTriangle(xx,yy,zz);
			it_i = indices.insert(it_i, xx);
			it_i = indices.insert(it_i, yy);
			it_i = indices.insert(it_i, zz);
			ofLogNotice()<<"Agregando borde: "<<xx<<" "<<yy<<" "<<zz;
			//ofLogNotice() <<xx<<","<<yy<<","<<zz;
	}
	ofLogNotice()<<"Superior";
	for (i=0;i<w-1;i++){
			xx = i;
			yy = i+1;
			zz = i+w*(h-1);
			//mesh.addTriangle(xx,yy,zz);
			it_i = indices.insert(it_i, xx);
			it_i = indices.insert(it_i, yy);
			it_i = indices.insert(it_i, zz);
			ofLogNotice()<<"Agregando borde: "<<xx<<" "<<yy<<" "<<zz;
			xx = (i+1)+w*(h-1);
			yy = i+1;
			zz = i+w*(h-1);
			//mesh.addTriangle(xx,yy,zz);
			it_i = indices.insert(it_i, xx);
			it_i = indices.insert(it_i, yy);
			it_i = indices.insert(it_i, zz);
			ofLogNotice()<<"Agregando borde: "<<xx<<" "<<yy<<" "<<zz;
			//ofLogNotice() <<xx<<","<<yy<<","<<zz;
	}*/

	/*
	ofLogNotice()<<"+++++++++++++"<<indices.size();
	
	int iiii=0;
	for (it_i=indices.begin(); it_i<indices.end(); it_i++){
		xx = *it_i;
		ofLogNotice()<<xx;
		if (iiii%3==2){
			ofLogNotice()<<"-----------";
		}
		iiii++;
	}
	*/

	/*
	mesh.addNormal( ofVec3f( normals[id].x, normals[id].y, normals[id].z ));
	mesh.addIndex(indices[id]);
*/
}
Example #11
0
void CSulManipulatorCamera::home( double t )
{
    computePosition( _homeEye, _homeCenter, _homeUp );
}
double BH2009SoccerSymbols::computeAngleNextBall()
{
  return toDegrees(Geometry::angleTo(theInstance->robotPose,computePosition()));
}
Example #13
0
int main(int argc, char* argv[]) {
    // Initialize shared memory
    if (ipc.init(false))
        exit(1);

    // Initialize nominal beaconContainer
    parseWaypoints();
    
    // Create camera semaphore/ mutex
    sem_init(&semCam, 0, 0);
    if (pthread_mutex_init(&mutexImageData, NULL) != 0) {
        printf("\n Camera mutex init failed\n");
        exit(1);
    }
    
    // Start camera thread
    pthread_t tid;
    int err = pthread_create(&tid, NULL, &camThread, NULL);
    if (err != 0) {
        printf("\nCan't create camera thread :[%s]", strerror(err));
        exit(1);
    }
    
    lastPhotogramMicros = getMicroSec();
    
    // Main loop
    for(;;photogram++) {        
        TRACE(DEBUG, "\nPHOTOGRAM %d, milliseconds: %ld\n", photogram, getMillisSinceStart());
        
        // Update time variables
        photogramMicros = getMicroSec();
        lastPhotogramSpentTime = getSpent(photogramMicros - lastPhotogramMicros);
        microsSinceStart += lastPhotogramSpentTime;
        lastPhotogramMicros = photogramMicros;
        
        // Get drone roll, pitch and yaw
        attitudeT attitude, delayedAttitude;
        ipc.getAttitude(attitude);
        
        attitudeSignal.push(attitude, lastPhotogramSpentTime);
        delayedAttitude = attitudeSignal.getSignal();
        
        droneRoll = delayedAttitude.roll * 0.01;
        dronePitch = delayedAttitude.pitch * 0.01;
        droneYaw = delayedAttitude.yaw * 0.01;
        
        // Update estimated servo values
        rollStatusServo.update(lastPhotogramSpentTime);
        pitchStatusServo.update(lastPhotogramSpentTime);
        
        if (rollStatusServo.inBigStep() || pitchStatusServo.inBigStep()) {
            sem_wait(&semCam);
            continue;
        }
       
        // Update estimated camera roll and pitch
        roll = droneRoll + rollStatusServo.getEstimatedAngle();
        pitch = dronePitch + pitchStatusServo.getEstimatedAngle();
        
        // Switch beacon containers to preserve one history record
        if (beaconContainer == &beaconContainerA) {
            beaconContainer = &beaconContainerB;
            oldBeaconContainer = &beaconContainerA;
        }
        else {
            beaconContainer = &beaconContainerA;
            oldBeaconContainer = &beaconContainerB;
        }
        beaconContainer->clean();
  
        // Wait until new frame is received
        sem_wait(&semCam);
        
        // Where the magic happens
        findBeacons();
        groupBeacons();
        findWaypoints();
        computePosition();
    }
    StopCamera();
    printf("Finished.\n");
    
    return 0;
}
void CameraManipulator::home(double /*currentTime*/)
{
    if (getAutoComputeHomePosition()) computeHomePosition();
    computePosition(_homeEye, _homeCenter, _homeUp);
    _thrown = false;
}
void initialiseFields( double *collideField, double *streamField, int *flagField, int * xlength, int *local_xlength, char *problem, char* pgmInput, int rank, int iProc, int jProc, int kProc )
{
    int iCoord, jCoord, kCoord, x, y, z, i;
#ifdef _ARBITRARYGEOMETRIES_
    int** pgmImage;
#endif // _ARBITRARYGEOMETRY_
    computePosition(iProc, jProc, kProc, &iCoord, &jCoord, &kCoord);
#ifdef _ARBITRARYGEOMETRIES_
    #pragma omp parallel private(x, y, z, i) shared(iCoord, jCoord, kCoord, collideField, flagField, streamField, xlength, problem, pgmInput, pgmImage, local_xlength, iProc, jProc, kProc)
#else
    #pragma omp parallel private(x, y, z, i) shared(iCoord, jCoord, kCoord, collideField, flagField, streamField, xlength, local_xlength, iProc, jProc, kProc)
#endif // _ARBITRARYGEOMETRY_
    {
        #pragma omp for schedule(static)
        for(x = 0; x < (local_xlength[0] + 2) * (local_xlength[1] + 2) * (local_xlength[2] + 2); x++)
        {
            flagField[x] = FLUID;
            for(i = 0; i < PARAMQ; i++)
                collideField[PARAMQ * x + i] = streamField[PARAMQ * x + i] = LATTICEWEIGHTS[i];
        }

        // independend of the problem first initialize all ghost cells as PARALLEL_BOUNDARY
        /* top boundary */
        #pragma omp for nowait schedule(static)
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = PARALLEL_BOUNDARY;

        /* back boundary */
        #pragma omp for nowait schedule(static)
        for (y = 0; y <= local_xlength[1] + 1; y++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                flagField[y * (local_xlength[0] + 2) + x] = PARALLEL_BOUNDARY;

        /* bottom boundary */
        #pragma omp for nowait schedule(static)
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = PARALLEL_BOUNDARY;

        /* left boundary */
        #pragma omp for nowait schedule(static)
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (y = 0; y <= local_xlength[1] + 1; y++)
                flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = PARALLEL_BOUNDARY;

        /* right boundary */
        #pragma omp for nowait schedule(static)
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (y = 0; y <= local_xlength[1] + 1; y++)
                flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = PARALLEL_BOUNDARY;

        /* front boundary, i.e. z = local_xlength + 1 */
        #pragma omp for schedule(static)
        for (y = 0; y <= local_xlength[1] + 1; y++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                flagField[(local_xlength[2] + 1) * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = PARALLEL_BOUNDARY;

        /** initialization of different scenarios */
#ifdef _ARBITRARYGEOMETRIES_
        if (!strcmp(problem, "drivenCavity"))
        {
#endif // _ARBITRARYGEOMETRY_
            /* front boundary, i.e. z = local_xlength + 1 */
            if (kCoord == kProc - 1)
            {
                #pragma omp for nowait schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[(local_xlength[2] + 1) * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = NO_SLIP;
            }

            /* back boundary */
            if (kCoord == 0)
            {
                #pragma omp for schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[y * (local_xlength[0] + 2) + x] = NO_SLIP;
            }

            /* left boundary */
            if (iCoord == 0)
            {
                #pragma omp for nowait schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = NO_SLIP;
            }
            /* right boundary */
            if (iCoord == iProc - 1)
            {
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = NO_SLIP;
            }
            /* bottom boundary */
            if (jCoord == 0)
            {
                #pragma omp for nowait schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)

                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = NO_SLIP;
            }

            /* top boundary */
            if (jCoord == jProc - 1)
            {
                #pragma omp for nowait schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = MOVING_WALL;
            }
#ifdef _ARBITRARYGEOMETRIES_
        }
        if (!strcmp(problem, "tiltedPlate"))
        {
            #pragma omp single
            {
                pgmImage = read_pgm(pgmInput);
            }
            #pragma omp for nowait schedule(static)
            for (z = 1; z <= local_xlength[2]; z++)
                for (y = 1; y <= local_xlength[1]; y++)
                    for (x = 1; x <= local_xlength[0]; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = !!pgmImage[(xlength[0] / iProc) * iCoord + x][(xlength[1] / jProc) * jCoord + y];


            /* front boundary, i.e. z = local_xlength + 1 */
            if (kCoord == kProc - 1)
                #pragma omp for nowait schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                    {
                        // check for obstacle in the cell in the inner part of the domain adjacent to the boundary (i.e. NO_SLIP)
                        // if there is an obstacle, make the boundary NO_SLIP instead of FREE_SLIP as well
                        if (pgmImage[(xlength[0] / iProc) * iCoord + x][(xlength[1] / jProc) * jCoord + y])
                            flagField[(local_xlength[2] + 1) * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = NO_SLIP;
                        else
                            flagField[(local_xlength[2] + 1) * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = FREE_SLIP;
                    }

            /* back boundary */
            if (kCoord == 0)
                #pragma omp for schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                    {
                        // check for obstacle in the cell in the inner part of the domain adjacent to the boundary
                        // if there is an obstacle, make the boundary NO_SLIP instead of FREE_SLIP as well
                        if (pgmImage[(xlength[0] / iProc) * iCoord + x][(xlength[1] / jProc) * jCoord + y])
                            flagField[y * (local_xlength[0] + 2) + x] = NO_SLIP;
                        else
                            flagField[y * (local_xlength[0] + 2) + x] = FREE_SLIP;
                    }


            /* left boundary */
            if (iCoord == 0)
                #pragma omp for nowait schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = INFLOW;

            /* right boundary */
            if (iCoord == iProc - 1)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = OUTFLOW;


            /* top boundary */
            if (jCoord == jProc - 1)
                #pragma omp for nowait schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = NO_SLIP;

            /* bottom boundary */
            if (jCoord == 0)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = NO_SLIP;


            // Adjust PARALLEL_BOUNDARY if the "adjacent" cell in the domain of the neighbouring process is an obstacle cell
            /* top boundary */
            #pragma omp for nowait schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (x = 0; x <= local_xlength[0] + 1; x++)
                    if (flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] == PARALLEL_BOUNDARY && pgmImage[(xlength[0] / iProc) * iCoord + x][(xlength[1] / jProc) * (jCoord + 1) +  1])
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = NO_SLIP;

            /* bottom boundary */
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (x = 0; x <= local_xlength[0] + 1; x++)
                    if (flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] == PARALLEL_BOUNDARY && pgmImage[(xlength[0] / iProc) * iCoord + x][(xlength[1] / jProc) * jCoord])
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = NO_SLIP;

            /* left boundary */
            #pragma omp for nowait schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    if (flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] == PARALLEL_BOUNDARY && pgmImage[(xlength[0] / iProc) * iCoord][(xlength[1] / jProc) * jCoord + y])
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = NO_SLIP;

            /* right boundary */
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    if (flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] == PARALLEL_BOUNDARY && pgmImage[(xlength[0] / iProc) * (iCoord + 1) + 1][(xlength[1] / jProc) * jCoord + y])
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = NO_SLIP;
            #pragma omp single
            {
                free_imatrix(pgmImage, 0, xlength[0] + 2, 0, xlength[1] + 2);
            }
        }
        if (!strcmp(problem, "flowStep"))
        {
            /* front boundary, i.e. z = local_xlength + 1 */
            if (kCoord == kProc - 1)
                #pragma omp for schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[(local_xlength[2] + 1) * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = NO_SLIP;

            /* back boundary */
            if (kCoord == 0)
                #pragma omp for schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[y * (local_xlength[0] + 2) + x] = NO_SLIP;

            /* left boundary */
            if (iCoord == 0)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = INFLOW;

            /* right boundary */
            if (iCoord == iProc - 1)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = OUTFLOW;

            /* top boundary */
            if (jCoord == jProc - 1)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = NO_SLIP;

            /* bottom boundary */
            if (jCoord == 0)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = NO_SLIP;


            /* step */
            // step height & width: jProc * local_xlength[1] / 2
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (y = 1; y <= min(xlength[1] / 2 - jCoord * (xlength[1] / jProc), local_xlength[1] ) ; y++) /* integer division on purpose, half of the channel is blocked by step */
                    for (x = 1; x <= min(xlength[1] / 2 - iCoord * (xlength[0] / iProc), local_xlength[0] ); x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = NO_SLIP;

            // adjust the PARALLEL_BOUNDARY where "adjacent" cells in the neighbouring domain are NO_SLIP
            /* top boundary */
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (x = 0; x <= local_xlength[0] + 1; x++)
                    if (x <= xlength[1] / 2 - iCoord * (xlength[0] / iProc) && xlength[1] / 2 - (jCoord + 1) * (xlength[1] / jProc) >= 1 && flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] == PARALLEL_BOUNDARY)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = NO_SLIP;


            /* bottom boundary */
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (x = 0; x <= local_xlength[0] + 1; x++)
                    if( x <= xlength[1] / 2 - iCoord * (xlength[0] / iProc) && 0 <= xlength[1] / 2 - jCoord * (xlength[1] / jProc) && flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] == PARALLEL_BOUNDARY)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = NO_SLIP;

            /* left boundary */
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    if( 0 <= xlength[1] / 2 - iCoord * (xlength[0] / iProc) && y <= xlength[1] / 2 - jCoord * (xlength[1] / jProc)  && flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] == PARALLEL_BOUNDARY)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = NO_SLIP;

            /* right boundary */
            #pragma omp for schedule(static)
            for (z = 0; z <= local_xlength[2] + 1; z++)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    if( 1 <= xlength[1] / 2 - (iCoord + 1) * (xlength[0] / iProc) && y <= xlength[1] / 2 - jCoord * (xlength[1] / jProc)  && flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] == PARALLEL_BOUNDARY)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = NO_SLIP;
        }
        if (!strcmp(problem, "planeShearFlow"))
        {

            /* front boundary, i.e. z = xlength + 1 */
            if (kCoord == kProc - 1)
                #pragma omp for schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[(local_xlength[2] + 1) * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x] = FREE_SLIP;

            /* back boundary */
            if (kCoord == 0)
                #pragma omp for schedule(static)
                for (y = 0; y <= local_xlength[1] + 1; y++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[y * (local_xlength[0] + 2) + x] = FREE_SLIP;

            /* left boundary */
            if (iCoord == 0)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2)] = PRESSURE_IN;

            /* right boundary */
            if (iCoord == iProc - 1)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (y = 0; y <= local_xlength[1] + 1; y++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + local_xlength[0] + 1] = OUTFLOW;

            /* top boundary */
            if (jCoord == jProc - 1)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + (local_xlength[1] + 1) * (local_xlength[0] + 2) + x] = NO_SLIP;

            /* bottom boundary */
            if (jCoord == 0)
                #pragma omp for schedule(static)
                for (z = 0; z <= local_xlength[2] + 1; z++)
                    for (x = 0; x <= local_xlength[0] + 1; x++)
                        flagField[z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + x] = NO_SLIP;
        }
#endif // _ARBITRARYGEOMETRY_
    } // end of parallel region

    /** debugging code: checking the flagField */
#ifdef DEBUG
    int * exactFlagField;
    exactFlagField = (int *) malloc( (size_t) sizeof( int ) * (xlength[0] + 2) *  (xlength[1] + 2) * (xlength[2] + 2));
    FILE *fp2 = NULL;
    unsigned int line2 = 0;
    int noOfReadEntries;
    int error2 = 0;
    char szFileName2[80];
    computePosition(iProc, jProc, kProc, &iCoord, &jCoord, &kCoord);
    sprintf( szFileName2, "Testdata/%s/flagField.dat", problem );
    fp2 = fopen(szFileName2,"r");
    if (fp2 != NULL)
    {
        for (line2 = 0; line2 < (xlength[0] + 2) *  (xlength[1] + 2) * (xlength[2] + 2); line2++)
        {
            noOfReadEntries = fscanf(fp2,"%d",&exactFlagField[line2]);
            if (noOfReadEntries != 1)
                continue;
        }

    }
    fclose(fp2);
    for (z = 1; z <= local_xlength[2]; z++)
        for (y = 1; y <= local_xlength[1]; y++)
            for(x = 1; x <= local_xlength[0]; x++)
                for (i = 0; i < PARAMQ; i++)
                    if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                        error2 = 1;
    if (error2)
        printf("ERROR: Process %d has a different flagField at inner nodes.\n",rank);

    error2 = 0;
    // Check global boundaries as well
    if (iCoord == 0)
    {
        // Left boundary
        x = 0;
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (y = 0; y <= local_xlength[1] + 1; y++)
                if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                    error2 = 1;

    }
    if (iCoord == iProc - 1)
    {
        // Right boundary
        x = local_xlength[0] + 1;
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (y = 0; y <= local_xlength[1] + 1; y++)
                if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                    error2 = 1;
    }
    if (jCoord == 0)
    {
        // Bottom boundary
        y = 0;
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                    error2 = 1;

    }
    if (jCoord == jProc - 1)
    {
        // Top boundary
        y = local_xlength[1] + 1;
        for (z = 0; z <= local_xlength[2] + 1; z++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                    error2 = 1;
    }
    if (kCoord == 0)
    {
        // back boundary
        z = 0;
        for (y = 0; y <= local_xlength[1] + 1; y++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                    error2 = 1;

    }
    if (kCoord == kProc - 1)
    {
        // front boundary
        z = local_xlength[2] + 1;
        for (y = 0; y <= local_xlength[1] + 1; y++)
            for (x = 0; x <= local_xlength[0] + 1; x++)
                if (flagField[(z * (local_xlength[0] + 2) * (local_xlength[1] + 2) + y * (local_xlength[0] + 2) + x)] != exactFlagField[((z + kCoord * (xlength[2] / kProc)) * (xlength[0] + 2) * (xlength[1] + 2) + (y + jCoord * (xlength[1] / jProc)) * (xlength[0] + 2) + (x + iCoord * (xlength[0] / iProc)))])
                    error2 = 1;
    }

    if (error2)
        printf("ERROR: Process %d has a different flagField at global boundary.\n",rank);
    free(exactFlagField);
#endif
    /** debugging code end */
}
Example #16
0
void FPSManipulator::home(double /*currentTime*/)
{

	computePosition( osg::Vec3(-10,0,60),  osg::Vec3(0,0,60), osg::Z_AXIS);

}
double BH2009SoccerSymbols::computePositionNextBallY()
{
  return computePosition().y;
}