Beispiel #1
0
void moveBoid(const goalContainer * const goals, boidContainer * boidlist, int index){
	directionVector exitVec, cohVec, alignVec, averVec, acceleration;
	int i;

	acceleration.x = 0;
	acceleration.y = 0;


	//Could possibly make these all execute in parallel as well
	exitVec = moveToExit(goals, boidlist, index);
	cohVec = cohesion(boidlist, index);
	alignVec = alignment(boidlist, index);
	averVec = aversion(boidlist, index);


	//Add up vectors with weights
	addVector(&acceleration, &exitVec, 3);
	addVector(&acceleration, &cohVec, 1);
	addVector(&acceleration, &alignVec, 1);
	addVector(&acceleration, &averVec, 2);

	//Limit the vector to required speed
	limitVec(&acceleration);

	boidlist->boidArr[index].velocity = acceleration;
	boidlist->boidArr[index].xpos += acceleration.x;
	boidlist->boidArr[index].ypos += acceleration.y;

	for(i = 0; i < goals->size; i++){
		if(boidlist->boidArr[index].xpos == goals->pos[i][0] && boidlist->boidArr[index].ypos == goals->pos[i][1]){
			boidlist->boidArr[index].active = 0;
		}
	}
	
}
Beispiel #2
0
void
AuxiliarySystem::addDotVectors()
{
  if (_fe_problem.uDotRequested())
    _u_dot = &addVector("u_dot", true, GHOSTED);
  if (_fe_problem.uDotDotRequested())
    _u_dotdot = &addVector("u_dotdot", true, GHOSTED);
  if (_fe_problem.uDotOldRequested())
    _u_dot_old = &addVector("u_dot_old", true, GHOSTED);
  if (_fe_problem.uDotDotOldRequested())
    _u_dotdot_old = &addVector("u_dotdot_old", true, GHOSTED);
}
Beispiel #3
0
AuxiliarySystem::AuxiliarySystem(FEProblem & subproblem, const std::string & name) :
    SystemTempl<TransientExplicitSystem>(subproblem, name, Moose::VAR_AUXILIARY),
    _mproblem(subproblem),
    _serialized_solution(*NumericVector<Number>::build(_mproblem.comm()).release()),
    _time_integrator(NULL),
    _u_dot(addVector("u_dot", true, GHOSTED)),
    _du_dot_du(addVector("du_dot_du", true, GHOSTED)),
    _need_serialized_solution(false)
{
  _nodal_vars.resize(libMesh::n_threads());
  _elem_vars.resize(libMesh::n_threads());
}
Beispiel #4
0
void drawSurfaceRenderWithTexture(GLfloat a[3], GLfloat b[3], GLfloat c[3],
                                  GLfloat e[3], GLfloat l) {
  GLfloat Normal[3], pl_a[3], pl_b[3], pl_c[3];
  computeNormalwith3pointsOnPlane(a, b, c, Normal);
  draw2Refraction(Normal, a, e, a, pl_a, eta);
  draw2Refraction(Normal, a, e, b, pl_b, eta);
  draw2Refraction(Normal, a, e, c, pl_c, eta);
// printVector(pl_a);

  GLfloat np[3] = {0, 1, 0}, v0[3] = {np[0], l, np[2]};
  GLfloat pl2_a[3], pl2_b[3], pl2_c[3], p_intersect_a[3], p_intersect_b[3], p_intersect_c[3];

  addVector(pl_a, a, pl2_a);
  pointOnIntersectsPlane(np, v0, a, pl2_a, p_intersect_a);
  // printf("p_intersect_a is:");
  // printVector(p_intersect_a);

  addVector(pl_b, b, pl2_b);
  pointOnIntersectsPlane(np, v0, b, pl2_b, p_intersect_b);
  // printf("p_intersect_b is: ");
  // printVector(p_intersect_b);

  addVector(pl_c, c, pl2_c);
  pointOnIntersectsPlane(np, v0, c, pl2_c, p_intersect_c);
  // printf("p_intersect_c is: ");
  // printVector(p_intersect_c);

  GLfloat xa, xb, xc, za, zb, zc;
  translateCoodinatewith_floor_d(p_intersect_a[0], p_intersect_a[2], &xa, &za);
  translateCoodinatewith_floor_d(p_intersect_b[0], p_intersect_b[2], &xb, &zb);
  translateCoodinatewith_floor_d(p_intersect_c[0], p_intersect_c[2], &xc, &zc);

  // printf("xa is: %f ", xa);
  // printf("xb is: %f ", xb);
  // printf("xc is: %f\n", xc);
  if (xa > 0 && xa < 1 && xb > 0 && xb < 1 && xc > 0 && xc < 1
      && za > 0 && za < 1 && zb > 0 && zb < 1 && zc > 0 && zc < 1) {
    glBindTexture ( GL_TEXTURE_2D, texture_id[current_texture] );
    glBegin ( GL_TRIANGLES);
    glTexCoord2f(xa, za); glVertex3fv(a);
    glTexCoord2f(xb, zb); glVertex3fv(b);
    glTexCoord2f(xc, zc); glVertex3f(c[0], c[1], c[2]);
    glEnd();
    // printf("fit.\n");

  }
  else
    drawTriangleFlat(a, b, c);

}
Beispiel #5
0
/* This function code borrowed from:
http://geometryalgorithms.com/Archive/algorithm_0106/algorithm_0106.htm#dist3D_Line_to_Line()
*/
float dist_line_to_line( float* L1P0,float* L1P1,float* L2P0, float* L2P1)
{
	float    u[3] = {L1P1[0] - L1P0[0],
					L1P1[1] - L1P0[1],
					L1P1[2] - L1P0[2]	}; // Vector u
    float	 v[3] = {L2P1[0] - L2P0[0],
					L2P1[1] - L2P0[1],
					L2P1[2] - L2P0[2]	}; // Vector v
    float    w[3] = {L1P0[0] - L2P0[0],
					L1P0[1] - L2P0[1],
					L1P0[2] - L2P0[2]	}; // Vector w
	float dP[3],
		temp1[3],
		temp2[3],
		temp3[3];

    float    a = dot(u,u);        // always >= 0
    float    b = dot(u,v);
    float    c = dot(v,v);        // always >= 0
    float    d = dot(u,w);
    float    e = dot(v,w);
    float    D = a*c - b*b;       // always >= 0
    float    sc, tc;


    // compute the line parameters of the two closest points
    if (D < SMALL_NUM) {         // the lines are almost parallel
        sc = 0.0;
        tc = (b>c ? d/b : e/c);   // use the largest denominator
    }
    else {
        sc = (b*e - c*d) / D;
        tc = (a*e - b*d) / D;
    }

    // get the difference of the two closest points
    	// implements  w + (sc*u) - (tc*v)

	multiplyScalar(sc,u,temp1);
	multiplyScalar(-tc,v,temp2);
	addVector(temp1,temp2,temp3);
	addVector(temp3,w,dP);
	
    return sqrt(  pow(dP[0],2) 
                        + pow(dP[1],2) 
                        + pow(dP[2],2)
                        );   // return the closest distance
}
Beispiel #6
0
void addGCompound(GObject compound, GObject gobj) {
   if (compound->type != GCOMPOUND) {
      error("add: First argument is not a GCompound");
   }
   addVector(compound->u.compoundRep.contents, gobj);
   addOp(compound, gobj);
}
Beispiel #7
0
  void LitVector::init(const LitVector& other1, const LitVector& other2) {
    _size = other1._size;

    int newAlloc = other1._alloc;
    if (newAlloc < other2._alloc) newAlloc = other2._alloc;
    if (newAlloc < other1._size + other2._size) newAlloc <<= 1;
    if (newAlloc > _alloc) {
      _alloc = newAlloc;
      _lits = (Literal*) realloc(_lits, sizeof(Literal) * _alloc);
    }
    
#if MERGING > 0
    if (_size >= MERGING) {
      memcpy(_lits, other1._lits, sizeof(Literal) * _size);
      addVector_(other2._lits, other2._size);
    } else if (other2._size >= MERGING) {
      memcpy(_lits, other2._lits, sizeof(Literal) * other2._size);
      _size = other2._size;
      addVector_(other1._lits, other1._size);
    } else {
      memcpy(_lits + other2._size, other1._lits, sizeof(Literal) * _size);
      addVector(other2);
    }
#else
    memcpy(_lits, other1._lits, sizeof(Literal) * _size);
    memcpy(_lits + other1._size, other2._lits, sizeof(Literal) * other2._size);
    _size += other2._size;
#endif
  }
Beispiel #8
0
/** input n -- normal, v0 -- a point on plane
    E -- eye, P -- object point
    output R -- refraction point
*/
void renderHalfRefraction(GLfloat n[3], GLfloat V0[3], GLfloat E[3], GLfloat P[3], GLfloat P3[3]) {
  GLfloat R[3];
  GLfloat P0[3];
  GLfloat v_temp[3];
  GLfloat v1_temp[3];
  GLfloat v2_temp[3];
  normalize(n);
  GLfloat r = pointOnIntersectsPlaneEllipsoid(n, V0, E, P, R);
  if (r < 0 || r > 1)
    return;
  projectionOnPlane(n, V0, P, P0);

  vector(v_temp, P0, R);
  productVectorScaler(v_temp, ita_r , v_temp);
  addVector(v_temp, R, P3);

  //glBegin(GL_POINTS);
  //glColor3f(1.0,1.0,0);
  // glVertex3fv(R);
  //glColor3f(1.0,1.0,0.0);
  //glVertex3fv(E);
  // glColor3f(0.0,1.0,1.0);
  // glVertex3fv(P0);
  // glColor3f(0.5,0.7,.9);
  // glVertex3fv(v_temp);
  //glEnd();

  // vector(v1_temp, v_temp, E);
  // normalize(v1_temp);
  // vector(v2_temp, P,R);
  // productVectorScaler(v1_temp, lenthOfVector(v2_temp), v1_temp);
  // addVector(v_temp, v1_temp, P1);

}
Beispiel #9
0
void
EigenSystem::saveOldSolutions()
{
  if (!_sys_sol_old)
    _sys_sol_old= &addVector("save_flux_old", false, PARALLEL);
  if (!_aux_sol_old)
    _aux_sol_old = &_fe_problem.getAuxiliarySystem().addVector("save_aux_old",  false, PARALLEL);
  if (!_sys_sol_older)
    _sys_sol_older = &addVector("save_flux_older", false, PARALLEL);
  if (!_aux_sol_older)
    _aux_sol_older = &_fe_problem.getAuxiliarySystem().addVector("save_aux_older",  false, PARALLEL);
  *_sys_sol_old   = solutionOld();
  *_sys_sol_older = solutionOlder();
  *_aux_sol_old   = _fe_problem.getAuxiliarySystem().solutionOld();
  *_aux_sol_older = _fe_problem.getAuxiliarySystem().solutionOlder();
}
Beispiel #10
0
int main()
{
	struct vector a = makeVector();
	struct vector b = makeVector();
	struct vector c = addVector(a,b);
	dispVector(c);
	return 0;
}
Beispiel #11
0
void addVertex(GPolygon poly, double x, double y) {
   GPoint *ppt;

   ppt = newBlock(GPoint *);
   poly->u.polygonRep.cx = ppt->x = x;
   poly->u.polygonRep.cy = ppt->y = y;
   addVector(poly->u.polygonRep.vertices, ppt);
   addVertexOp(poly, x, y);
}
Beispiel #12
0
	void start() {	
		cam.lookAt(eye, target, up);
		
		cout << "View:" << endl << cam.view << endl;
		cout << "Proj:" << endl << cam.projection << endl;
		cout << "Tran:" << endl << cam.transform << endl;
		
		cout << cam.view * Vector4f(0, 0, 0, 1) << endl;
		
		frustum.update(cam.transform);
		
		addVector(frustum.nearRect.tl, frustum.nearRect.tr);
		addVector(frustum.nearRect.tr, frustum.nearRect.br);
		addVector(frustum.nearRect.br, frustum.nearRect.bl);
		addVector(frustum.nearRect.bl, frustum.nearRect.tl);
		
		h_rays = thrust::host_vector<Ray>(width*height);
	}
Beispiel #13
0
/** to reduce calculation in Ecllipse sureface rendering example
    input: 3 points of triangle--v1,v2,v3
        a -- oringinal point on the line, pl -- direction
    output: Rr -- intersection point
    return 1 for intersected; 0 for not intersected with trianlge
*/
int lineIntersectTriangle(GLfloat v1[3], GLfloat v2[3], GLfloat v3[3],
                          GLfloat a[3], GLfloat pl[3], GLfloat Rr[3]) {
  GLfloat n[3], R[3];
  computeNormalwith3pointsOnPlane(v1, v2, v3, n);
  addVector(pl, a, R);
  GLfloat r = pointOnIntersectsPlaneEllipsoid(n, v1, a, R, Rr);
  if (r < 0 || r > 1)
    return 0;
  else return 1;
}
Beispiel #14
0
AuxiliarySystem::AuxiliarySystem(FEProblemBase & subproblem, const std::string & name) :
    SystemBase(subproblem, name, Moose::VAR_AUXILIARY),
    _fe_problem(subproblem),
    _sys(subproblem.es().add_system<TransientExplicitSystem>(name)),
    _serialized_solution(*NumericVector<Number>::build(_fe_problem.comm()).release()),
    _u_dot(addVector("u_dot", true, GHOSTED)),
    _need_serialized_solution(false)
{
  _nodal_vars.resize(libMesh::n_threads());
  _elem_vars.resize(libMesh::n_threads());
}
Beispiel #15
0
/** input n -- normal, v0 -- a point on plane
    E -- eye, P -- object point
    output P1 -- refraction point
*/
void renderRefraction(GLfloat n[3], GLfloat V0[3], GLfloat E[3], GLfloat P[3], GLfloat P1[3]) {
  GLfloat R[3];
  GLfloat P0[3];
  GLfloat v_temp[3];
  GLfloat v1_temp[3];
  GLfloat v2_temp[3];
  normalize(n);
  GLfloat r = pointOnIntersectsPlaneEllipsoid(n, V0, E, P, R);
  if (r < 0 || r > 1)
    return;
  projectionOnPlane(n, V0, P, P0);

  vector(v_temp, P0, R);
  productVectorScaler(v_temp, ita_r , v_temp);
  addVector(v_temp, R, v_temp);

  //glBegin(GL_POINTS);
  //glColor3f(1.0,1.0,0);
  // glVertex3fv(R);
  //glColor3f(1.0,1.0,0.0);
  //glVertex3fv(E);
  // glColor3f(0.0,1.0,1.0);
  // glVertex3fv(P0);
  // glColor3f(0.5,0.7,.9);
  // glVertex3fv(v_temp);
  //glEnd();

  vector(v1_temp, v_temp, E);
  normalize(v1_temp);
  vector(v2_temp, P, R);

  GLfloat constantd = ita_l * lenthOfVector(v2_temp);
  reverseVectorSign(v2_temp, v2_temp);
  constantd *= cosBetween2Vectors(n, v2_temp);
  productVectorScaler(v1_temp, constantd , v1_temp);
  addVector(v_temp, v1_temp, P1);

}
Beispiel #16
0
	void initRays() {
		int n = h_rays.size();
		int w = width, h = height;
		for (int i = 0; i < n; i++) {
			Ray &r = h_rays[i];
			r.done = false;
			r.color = Vector3(0, 0, 0);
			
			int ix = i%w;
			int iy = i/w;
			Number px = ((Number)ix + (Number)0.5)/w;
			Number py = ((Number)iy + (Number)0.5)/h;
			r.pos = frustum.pointOnNearPlane(px, py);
			r.dir = r.pos - eye;
			r.dir.normalize();
			addVector(eye, r.pos);
			addVectorDir(r.pos, r.dir);
		}
	}
Beispiel #17
0
  const LitVector& LitVector::operator+=(const LitVector& other) {
    int newSize = _size + other._size;

    int oldAlloc = _alloc;
    if (other._alloc > _alloc) _alloc = other._alloc;
    if (newSize > _alloc) _alloc <<= 1;
    assert(_alloc >= newSize);
    if (_alloc != oldAlloc) _lits = (Literal*) realloc(_lits, sizeof(Literal) * _alloc);
    
#if MERGING > 0
    if (_size >= MERGING) {
      addVector_(other._lits, other._size);
    } else {
      memmove(_lits + other._size, _lits, sizeof(Literal) * _size);
      addVector(other);
    }
#else
    memcpy(_lits + _size, other._lits, sizeof(Literal) * other._size);
    _size += other._size;
#endif
    return *this;
  }
GUIEquationEditor::GUIEquationEditor(QStringList SingelValues, QStringList Vectors ,QWidget *parent) :
        QDialog(parent),
        ui(new Ui::GUIEquationEditor)
{
    ui->setupUi(this);

    ui->listWidget_Values->addItems(SingelValues);
    ui->listWidget_Vectors->addItems(Vectors);

    QObject::connect(ui->pushButton_plus, SIGNAL(clicked()), this, SLOT(addPlus()));
    QObject::connect(ui->pushButton_minus, SIGNAL(clicked()), this, SLOT(addMinus()));
    QObject::connect(ui->pushButton_multi, SIGNAL(clicked()), this, SLOT(addMulti()));
    QObject::connect(ui->pushButton_cos, SIGNAL(clicked()), this, SLOT(addCos()));
    QObject::connect(ui->pushButton_sin, SIGNAL(clicked()), this, SLOT(addSin()));
    QObject::connect(ui->pushButton_tan, SIGNAL(clicked()), this, SLOT(addTan()));
    QObject::connect(ui->pushButton_nov, SIGNAL(clicked()), this, SLOT(addNov()));
    QObject::connect(ui->pushButton_random, SIGNAL(clicked()), this, SLOT(addRandom()));
    QObject::connect(ui->pushButton_if, SIGNAL(clicked()), this, SLOT(addIf()));
    QObject::connect(ui->pushButton_values, SIGNAL(clicked()), this, SLOT(addValue()));
    QObject::connect(ui->pushButton_vectors, SIGNAL(clicked()), this, SLOT(addVector()));


}
Beispiel #19
0
 /**
  * \f$U+=A*V\f$, add the product of a \p SparseMatrix \p A
  * and a \p Vector \p V to \p this, where \p this=U.
  */
 void addVector ( const boost::shared_ptr<Vector<T> >& V_in,
                  const boost::shared_ptr<MatrixSparse<T> >& A_in )
 {
     addVector( *V_in, *A_in );
 }
Beispiel #20
0
/*
 * Initialize the GUI interface for the plugin
 */
void QgsGrassPlugin::initGui()
{
  toolBarPointer = 0;
  mTools = 0;
  mNewMapset = 0;
  mRegion = 0;

  QSettings settings;
  QgsGrass::init();
  mCanvas = qGisInterface->mapCanvas();
  QWidget* qgis = qGisInterface->mainWindow();

  connect( mCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setTransform() ) );

  // Connect project
  connect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
  connect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );

  // Create region rubber band
  mRegionBand = new QgsRubberBand( mCanvas, QGis::Polygon );
  mRegionBand->setZValue( 20 );

  // Create the action for tool (the icons are set later by calling setCurrentTheme)
  mOpenMapsetAction = new QAction( QIcon(), tr( "Open mapset" ), this );
  mNewMapsetAction = new QAction( QIcon(), tr( "New mapset" ), this );
  mCloseMapsetAction = new QAction( QIcon(), tr( "Close mapset" ), this );

  mAddVectorAction = new QAction( QIcon(), tr( "Add GRASS vector layer" ), this );
  mAddRasterAction = new QAction( QIcon(), tr( "Add GRASS raster layer" ), this );
  mOpenToolsAction = new QAction( QIcon(), tr( "Open GRASS tools" ), this );

  mRegionAction = new QAction( QIcon(), tr( "Display Current Grass Region" ), this );
  mRegionAction->setCheckable( true );

  mEditRegionAction = new QAction( QIcon(), tr( "Edit Current Grass Region" ), this );
  mEditAction = new QAction( QIcon(), tr( "Edit Grass Vector layer" ), this );
  mNewVectorAction = new QAction( QIcon(), tr( "Create new Grass Vector" ), this );

  mAddVectorAction->setWhatsThis( tr( "Adds a GRASS vector layer to the map canvas" ) );
  mAddRasterAction->setWhatsThis( tr( "Adds a GRASS raster layer to the map canvas" ) );
  mOpenToolsAction->setWhatsThis( tr( "Open GRASS tools" ) );
  mRegionAction->setWhatsThis( tr( "Displays the current GRASS region as a rectangle on the map canvas" ) );
  mEditRegionAction->setWhatsThis( tr( "Edit the current GRASS region" ) );
  mEditAction->setWhatsThis( tr( "Edit the currently selected GRASS vector layer." ) );

  // Connect the action
  connect( mAddVectorAction, SIGNAL( triggered() ), this, SLOT( addVector() ) );
  connect( mAddRasterAction, SIGNAL( triggered() ), this, SLOT( addRaster() ) );
  connect( mOpenToolsAction, SIGNAL( triggered() ), this, SLOT( openTools() ) );
  connect( mEditAction, SIGNAL( triggered() ), this, SLOT( edit() ) );
  connect( mNewVectorAction, SIGNAL( triggered() ), this, SLOT( newVector() ) );
  connect( mRegionAction, SIGNAL( toggled( bool ) ), this, SLOT( switchRegion( bool ) ) );
  connect( mEditRegionAction, SIGNAL( triggered() ), this, SLOT( changeRegion() ) );
  connect( mOpenMapsetAction, SIGNAL( triggered() ), this, SLOT( openMapset() ) );
  connect( mNewMapsetAction, SIGNAL( triggered() ), this, SLOT( newMapset() ) );
  connect( mCloseMapsetAction, SIGNAL( triggered() ), this, SLOT( closeMapset() ) );

  // Add actions to a GRASS plugin menu
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenMapsetAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewMapsetAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mCloseMapsetAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mAddVectorAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mAddRasterAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mNewVectorAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mEditAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mOpenToolsAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mRegionAction );
  qGisInterface->addPluginToMenu( tr( "&GRASS" ), mEditRegionAction );

  // Add the toolbar to the main window
  toolBarPointer = qGisInterface->addToolBar( tr( "GRASS" ) );
  toolBarPointer->setObjectName( "GRASS" );

  // Add to the toolbar
  toolBarPointer->addAction( mOpenMapsetAction );
  toolBarPointer->addAction( mNewMapsetAction );
  toolBarPointer->addAction( mCloseMapsetAction );
  toolBarPointer->addSeparator();
  toolBarPointer->addAction( mAddVectorAction );
  toolBarPointer->addAction( mAddRasterAction );
  toolBarPointer->addAction( mNewVectorAction );
  toolBarPointer->addAction( mEditAction );
  toolBarPointer->addAction( mOpenToolsAction );
  toolBarPointer->addAction( mRegionAction );
  toolBarPointer->addAction( mEditRegionAction );

  // Set icons to current theme
  setCurrentTheme( "" );
  // Connect theme change signal
  connect( qGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );

  // Connect display region
  connect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );

  setEditAction();
  connect( qGisInterface, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
           this, SLOT( setEditAction() ) );

  // Init Region symbology
  mRegionPen.setColor( QColor( settings.value( "/GRASS/region/color", "#ff0000" ).toString() ) );
  mRegionPen.setWidth( settings.value( "/GRASS/region/width", 0 ).toInt() );
  mRegionBand->setColor( mRegionPen.color() );
  mRegionBand->setWidth( mRegionPen.width() );

  mapsetChanged();
}
// Assumes symbol-spaced sampling!!!
// Based upon paper by Al-Dhahir and Cioffi
bool designDFE(signalVector &channelResponse,
	       float SNRestimate,
	       int Nf,
	       signalVector **feedForwardFilter,
	       signalVector **feedbackFilter)
{
  
  signalVector G0(Nf);
  signalVector G1(Nf);
  signalVector::iterator G0ptr = G0.begin();
  signalVector::iterator G1ptr = G1.begin();
  signalVector::iterator chanPtr = channelResponse.begin();

  int nu = channelResponse.size()-1;

  *G0ptr = 1.0/sqrtf(SNRestimate);
  for(int j = 0; j <= nu; j++) {
    *G1ptr = chanPtr->conj();
    G1ptr++; chanPtr++;
  }

  signalVector *L[Nf];
  signalVector::iterator Lptr;
  float d;
  for(int i = 0; i < Nf; i++) {
    d = G0.begin()->norm2() + G1.begin()->norm2();
    L[i] = new signalVector(Nf+nu);
    Lptr = L[i]->begin()+i;
    G0ptr = G0.begin(); G1ptr = G1.begin();
    while ((G0ptr < G0.end()) &&  (Lptr < L[i]->end())) {
      *Lptr = (*G0ptr*(G0.begin()->conj()) + *G1ptr*(G1.begin()->conj()) )/d;
      Lptr++;
      G0ptr++;
      G1ptr++;
    }
    complex k = (*G1.begin())/(*G0.begin());

    if (i != Nf-1) {
      signalVector G0new = G1;
      scaleVector(G0new,k.conj());
      addVector(G0new,G0);

      signalVector G1new = G0;
      scaleVector(G1new,k*(-1.0));
      addVector(G1new,G1);
      delayVector(G1new,-1.0);

      scaleVector(G0new,1.0/sqrtf(1.0+k.norm2()));
      scaleVector(G1new,1.0/sqrtf(1.0+k.norm2()));
      G0 = G0new;
      G1 = G1new;
    }
  }

  *feedbackFilter = new signalVector(nu);
  L[Nf-1]->segmentCopyTo(**feedbackFilter,Nf,nu);
  scaleVector(**feedbackFilter,(complex) -1.0);
  conjugateVector(**feedbackFilter);

  signalVector v(Nf);
  signalVector::iterator vStart = v.begin();
  signalVector::iterator vPtr;
  *(vStart+Nf-1) = (complex) 1.0;
  for(int k = Nf-2; k >= 0; k--) {
    Lptr = L[k]->begin()+k+1;
    vPtr = vStart + k+1;
    complex v_k = 0.0;
    for (int j = k+1; j < Nf; j++) {
      v_k -= (*vPtr)*(*Lptr);
      vPtr++; Lptr++;
    }
     *(vStart + k) = v_k;
  }

  *feedForwardFilter = new signalVector(Nf);
  signalVector::iterator w = (*feedForwardFilter)->begin();
  for (int i = 0; i < Nf; i++) {
    delete L[i];
    complex w_i = 0.0;
    int endPt = ( nu < (Nf-1-i) ) ? nu : (Nf-1-i);
    vPtr = vStart+i;
    chanPtr = channelResponse.begin();
    for (int k = 0; k < endPt+1; k++) {
      w_i += (*vPtr)*(chanPtr->conj());
      vPtr++; chanPtr++;
    }
    *w = w_i/d;
    w++;
  }


  return true;
  
}
Beispiel #22
0
void
AuxiliarySystem::addExtraVectors()
{
  if (_fe_problem.needsPreviousNewtonIteration())
    _solution_previous_nl = &addVector("u_previous_newton", true, GHOSTED);
}
Beispiel #23
0
int main()
{
	struct Vector a={5,5,5,5,5,"test1"};
	struct Vector b={6,6,6,6,6,"test2"};
	addVector(&a,&b);
}