Example #1
0
// Mnozenie wektora przez skalar
Vect operator*(const Vect &p, double d)
{
    Vect z(p.getDimension());
    for(int i=0; i<p.getDimension(); i++)
        z.setCoordinate(i,d*p.getCoordinate(i));
    return z;
};
Example #2
0
bool Env::sendMsg(long idSrc, long idDest, char *msg) {
    logMsg("SEND MSG : " + std::to_string(idSrc) + " -> " + std::to_string(idDest));
    // if (this->phy->getNeighbours(idSrc).count(idDest)) {
        this->agents.at(idDest)->addMsg(msg);

        // Display the sending message with dataAgents
        Agent * agentSrc = this->agents.at(idSrc);
        Agent * agentDest = this->agents.at(idDest);
        Vect posSrc = PosToCell(agentSrc->getPos().x, agentSrc->getPos().y);
        Vect posDest = PosToCell(agentDest->getPos().x, agentDest->getPos().y);
        if (posSrc != posDest) {
            float dist = ((724-Vect(posSrc - posDest).Length()) / 724.0) / 6.0;
            for (float n = 0; n < 1; n += dist) {
                Vect base = posDest + n * (posSrc - posDest);
                Vect dirSommet = Vect(posSrc - posDest);
                dirSommet.Normalize();
                Vect vectBase = Vect(dirSommet.y, -dirSommet.x);
                for (int j = 0; j < 20; j++) {
                    for (int i = -j*0.5; i <= j*0.5; i++) {
                        Vect point = base + j / 2.0 * dirSommet + i / 2.0 * vectBase;
                        if (point.x >= 0 && point.x < 512 && point.y >= 0 && point.y < 512) {
                            agentSrc->getVision(point.x, point.y)->dataAgent = 10 * (1 - n);
                        }
                    }
                }
            }
        }
        return true;
    //}
    //return false;
}
Example #3
0
Bounds Bounds::GetTransformedBounds(const Matrix &m) const
{
    Bounds newBounds;
    BOOL bInitialized=0;
    for(int i=0; i<8; i++)
    {
        Vect p = GetPoint(i);
        p.TransformPoint(m);

        if(!bInitialized)
        {
            newBounds.Max = newBounds.Min = p;
            bInitialized = 1;
        }
        else
        {
            if(p.x < newBounds.Min.x)
                newBounds.Min.x = p.x;
            else if(p.x > newBounds.Max.x)
                newBounds.Max.x = p.x;

            if(p.y < newBounds.Min.y)
                newBounds.Min.y = p.y;
            else if(p.y > newBounds.Max.y)
                newBounds.Max.y = p.y;

            if(p.z < newBounds.Min.z)
                newBounds.Min.z = p.z;
            else if(p.z > newBounds.Max.z)
                newBounds.Max.z = p.z;
        }
    }

    return newBounds;
}
Example #4
0
JNIEXPORT void JNICALL Java_neuron_Neuron_vectorToHoc
  (JNIEnv *env, jclass, jlong jc, jdoubleArray ja, jint size) {
	Object* ho = (Object*)jc;
	Vect* vec = (Vect*)ho->u.this_pointer;
	vector_resize(vec, size);
	env->GetDoubleArrayRegion(ja, 0, size, &vec->elem(0));
}
Example #5
0
 void
 growVector()
   {
     CHECK (0 == Dummy::checksum());
     {
       typedef typename Table<HO>::Type Vect;
       
       Vect table;
       table.reserve(2);
       CHECK (0 == Dummy::checksum());
       
       cout << ".\n..install one element at index[0]\n";
       table.push_back(HO());
       CHECK (0 == Dummy::checksum());
       
       create_contained_object (table[0]); // switches into "managed" state
       CHECK (0 < Dummy::checksum());
       int theSum = Dummy::checksum();
       
       cout << ".\n..*** resize table to 16 elements\n";
       for (uint i=0; i<15; ++i)
         table.push_back(HO());
       
       CHECK (theSum == Dummy::checksum());
     }
     CHECK (0 == Dummy::checksum());
   }
char AdapterComputationalGeometry::SegTriInt(Vect* T,Vect q,Vect r){
    SegmentTriangleIntersection segmenttriangleintersection;
    tPointi Tpoints;
    tPointd qpoints;
    tPointd rpoints;
    tPointd ppoints;

	segmenttriangleintersection.Vertices[0][0]=T[0].getPunto().getX();
	segmenttriangleintersection.Vertices[0][1]=T[0].getPunto().getY();
	segmenttriangleintersection.Vertices[0][2]=T[0].getPunto().getZ();
	segmenttriangleintersection.Vertices[1][0]=T[1].getPunto().getX();
	segmenttriangleintersection.Vertices[1][1]=T[1].getPunto().getY();
	segmenttriangleintersection.Vertices[1][2]=T[1].getPunto().getZ();
	segmenttriangleintersection.Vertices[2][0]=T[2].getPunto().getX();
	segmenttriangleintersection.Vertices[2][1]=T[2].getPunto().getY();
	segmenttriangleintersection.Vertices[2][2]=T[2].getPunto().getZ();

	Tpoints[0]=0;
	Tpoints[1]=1;
	Tpoints[2]=2;

	qpoints[0]=q.getPunto().getX();
	qpoints[1]=q.getPunto().getY();
	qpoints[2]=q.getPunto().getZ();

	rpoints[0]=r.getPunto().getX();
	rpoints[1]=r.getPunto().getY();
	rpoints[2]=r.getPunto().getZ();

	return segmenttriangleintersection.SegTriInt(Tpoints,qpoints,rpoints,ppoints);
	}
bool VerificacionNodosVecinosColapsoRegion::corrigeInconsistencia (Malla *malla, int indNodo){
	assert(malla->getNodo(indNodo)!=NULL);

	Nodo* nodo=malla->getNodo(indNodo);
	Vect viejaNormal=nodo->getNormal();
	Vect nuevaNormal;
	vector<int> indArcosVecinos=nodo->getArcos();
	for (int indArco=0; indArco< (int)indArcosVecinos.size(); indArco++){
		Arco* arcoVecino=malla->getArco(indArcosVecinos[indArco]);
		int indPuntoA=arcoVecino->getNodoDistinto(indNodo);
		Nodo* NodoA=malla->getNodo(indPuntoA);
		Vect vectorVecino=NodoA->getNormal()*(val*NodoA->getConcentracion());
		nuevaNormal=nuevaNormal+vectorVecino;
		}
	//Normalizamos.
	nuevaNormal = nuevaNormal*(1/nuevaNormal.largo());
	nodo->setNormal(nuevaNormal);
	//Si la inconsistencia no se corrige, borramos el nodo central.
	if (checkInterseccionNodo(malla,indNodo)==true){
		nodo->setNormal(viejaNormal);
		colapsarRegion(malla,indNodo);
		return false;
	}
	else
		ntrayectoriasreparadas++;
	return true;
	}
Example #8
0
BOOL Plane::GetIntersection(const Vect &p1, const Vect &p2, float &fT) const
{
    float P1Dist = p1.DistFromPlane(*this);
    float P2Dist = p2.DistFromPlane(*this);

    if(CloseFloat(P1Dist, 0.0f, EPSILON))
    {
        if(P2Dist == 0.0f)
            return 0;

        fT = 0.0f;
        return 1;
    }
    else if(CloseFloat(P2Dist, 0.0f, EPSILON))
    {
        fT = 1.0f;
        return 1;
    }

    BOOL bP1Over = (P1Dist > 0.0f);
    BOOL bP2Over = (P2Dist > 0.0f);

    if(bP1Over == bP2Over)
        return FALSE;

    float P1AbsDist = fabs(P1Dist);
    float dist2 = (P1AbsDist+fabs(P2Dist));
    if(dist2 < EPSILON)
        return FALSE;
    fT = P1AbsDist/dist2;

    return TRUE;
}
Example #9
0
void can_project_and_scale_points() {
    FrameBuffer fb(500, 500);
    Vect v = Vect(0, 0, 100);
    fb.projectAndScalePoint(v);
    ASSERT_EQUAL_FLOAT(v.getX(), 250, 0.1);
    ASSERT_EQUAL_FLOAT(v.getY(), 250, 0.1);
}
Example #10
0
const Vect Vect::getNorm()const
{
	Vect norming = Vect(this->m);
	norming.norm();

	return norming;
};
void AnimController::setBonePose( PyramidObject *node )
{
	PyramidObject *childNode = (PyramidObject *)node;
	PyramidObject *parentNode = (PyramidObject *)node->getParent();

	if( parentNode == GraphicsObjMan::getMainTree()->getRoot() )
		return;

	if (parentNode != 0 && childNode != 0)	{
		// Now get the world matrices
		Vect start(0.0f,0.0f,0.0f);

		parentNode->transform();
		Vect ptA = start * parentNode->getWorld();

		childNode->transform();
		Vect ptB = start * childNode->getWorld();

		// direction between the anchor points of the respective bones
		Vect dir = -(ptB - ptA);

		// length of the bone 0
		float mag = dir.mag();

		// Set the orientation and length for bone 0
		Matrix S( SCALE, BONE_WIDTH, BONE_WIDTH, mag);
		Quat Q( ROT_ORIENT, dir.getNorm(), Vect( 0.0f, 1.0f, 0.0f) );
		Matrix T( TRANS, ptB );

		Matrix BoneOrient = S * Q * T;

		childNode->setBoneOrientation( BoneOrient );
	}
}
Example #12
0
// Konstruktor kopiujacy
Vect::Vect(const Vect &w)
{
    dim = w.getDimension();
    v = new double[w.getDimension()];
    for (int i = 0; i < w.getDimension(); i++)
        setCoordinate(i, w.getCoordinate(i));
}
Example #13
0
TEST(RayTracer, ray_inits) {
    Ray r(Vect(0, 0, -1), Vect(-1, 0, 0));
    Vect o = r.getOrigin();
    Vect d = r.getDirection();
    CHECK_EQUAL(-1, o.getZ());
    CHECK_EQUAL(-1, d.getX());
}
Example #14
0
Vect operator*(const Vect &w, double d)
{
    Vect r(w.getDimension());
    r = w;
    for (int i = 0; i < w.getDimension(); i++)
        r.setCoordinate(i, d * w.getCoordinate(i));
    return r;
}
Example #15
0
double operator*(const Vect &w1, const Vect &w2)
{
    assert (w1.getDimension() == w2.getDimension());
    double d = 0;
    for (int i = 0; i < w1.getDimension(); i++)
        d = d + w1.getCoordinate(i) * w2.getCoordinate(i);
    return d;
}
Example #16
0
Vect operator-(const Vect &w1, const Vect &w2)
{
    assert (w1.getDimension() == w2.getDimension());
    Vect w(w1.getDimension());
    w = w1;
    w -= w2;
    return w;
}
Example #17
0
TEST(RayTracer, has_normalized_vectors) {
    RayTracer rt(10, 10);
    rt.setViewDirection(Vect(3, 4, 5));
    Vect viewDir = rt.getViewDirection();
    DOUBLES_EQUAL(0.424264, viewDir.getX(), 0.0001);
    DOUBLES_EQUAL(0.565685, viewDir.getY(), 0.0001);
    DOUBLES_EQUAL(0.707106, viewDir.getZ(), 0.0001);
}
Example #18
0
Vect operator*(const Vect &p, double d){

    Vect k(p.getDimension());
    for(int i = 1; i <= k.getDimension(); i++){
        k.setCoordinate(i,p.getCoordinate(i)*d);
    }

return k;
}
Example #19
0
void Rand::behaviour(AgentControl *agent) {
    if (t>10) {
        Vect force = Vect((rand() % 100) - 50, (rand() % 100) - 50);
        force.Normalize();
        agent->getPhy()->applyForce(100*force);
        t = 0;
    }
    t++;
}
Example #20
0
void LinearMechanism::create()
{
	int i;
	lmfree();
	i = 0;
	Object* o = *hoc_objgetarg(++i);
	
	if (strcmp(o->ctemplate->sym->name, "PythonObject") == 0) {
	    f_callable_ = o;
    	hoc_obj_ref(o);
	    c_ = matrix_arg(++i);
    } else {
        f_callable_ = NULL;
        c_ = matrix_arg(1);
    }
	g_ = matrix_arg(++i);
	y_ = vector_arg(++i);

	if (ifarg(i + 2) && hoc_is_object_arg(i + 2) && is_vector_arg(i + 2)) {
		y0_ = vector_arg(++i);
	}
	b_ = vector_arg(++i);
    if (ifarg(++i)) {
#if HAVE_IV
	Oc oc;
#endif

	if (hoc_is_double_arg(i)) {
		nnode_ = 1;
		nodes_ = new Node*[1];
		double x = chkarg(i, 0., 1.);
		Section* sec = chk_access();
		nodes_[0] = node_exact(sec, x);
		nrn_notify_when_double_freed(&NODEV(nodes_[0]), this);
	}else{
		Object* o = *hoc_objgetarg(i);
		check_obj_type(o, "SectionList");
		SectionList* sl = new SectionList(o);
		sl->ref();
		Vect* x = vector_arg(i+1);
		Section* sec;
		nnode_ = 0;
		nodes_ = new Node*[x->capacity()];
		for (sec = sl->begin(); sec; sec = sl->next()) {
			nodes_[nnode_] = node_exact(sec, x->elem(nnode_));
			nrn_notify_when_double_freed(&NODEV(nodes_[nnode_]), this);
			++nnode_;
		}
		if (ifarg(i+2)) {
			elayer_ = vector_arg(i+2);
		}
		sl->unref();
	}
    }
 	model_ = new LinearModelAddition(c_, g_, y_, y0_, b_,
		nnode_, nodes_, elayer_, f_callable_);
}
Example #21
0
JNIEXPORT jdoubleArray JNICALL Java_neuron_Neuron_vectorFromHoc
  (JNIEnv *env, jclass, jlong jc) {
	Object* ho = (Object*)jc;
	Vect* vec = (Vect*)ho->u.this_pointer;
	jint size = vec->capacity();
	jdoubleArray ja = env->NewDoubleArray(size);
	env->SetDoubleArrayRegion(ja, 0, size, &vec->elem(0));
	return ja;
}
Example #22
0
// Iloczyn skalarny
double operator*(const Vect &p1, const Vect &p2)
{
    assert (p1.getDimension() == p2.getDimension());

    double wynik = 0;
    for(int i=0; i<p1.getDimension(); i++)
        wynik += (p1.getCoordinate(i) * p2.getCoordinate(i));
    return wynik;
};
Example #23
0
Vect operator-(const Vect &p1, const Vect &p2)
{
assert(p1.getDimension() == p2.getDimension());

     Vect p4(p1.getDimension());
     p4 = p1;
     p4 -= p2;
     return p4;
}
Example #24
0
// Mno¿enie wektora przez skalar
Vect operator*(const Vect &p, double d)
{
    Vect g(p.getDimension());

    for (int i=0; i<p.getDimension(); i++)
        g.setCoordinate(i,p.getCoordinate(i)*d);

    return g;
}
Example #25
0
BOOL Bounds::LineIntersection(const Vect &v1, const Vect &v2, float &fT) const
{
    float tMax = M_INFINITE;
    float tMin = -M_INFINITE;

    Vect rayVect = (v2-v1);
    float rayLength = rayVect.Len();
    Vect rayDir = rayVect*(1.0f/rayLength);

    Vect center = GetCenter();
    Vect E = Max-center;
    Vect T = center-v1;

    for(int i=0; i<3; i++)
    {
        float e = T.ptr[i];
        float f = rayDir.ptr[i];
        float fI = 1.0f/f;

        if(fabs(f) > 0.0f)
        {
            float t1 = (e+E.ptr[i])*fI;
            float t2 = (e-E.ptr[i])*fI;
            if(t1 > t2)
            {
                if(t2 > tMin) tMin = t2;
                if(t1 < tMax) tMax = t1;
            }
            else
            {
                if(t1 > tMin) tMin = t1;
                if(t2 < tMax) tMax = t2;
            }
            if(tMin > tMax) return FALSE;
            if(tMax < 0.0f) return FALSE;
        }
        else if( ((-e - E.ptr[i]) > 0.0f) ||
                 ((-e + E.ptr[i]) < 0.0f) )
        {
            return FALSE;
        }

        if(tMin > rayLength) return FALSE;
    }

    if(tMin > 0.0f)
    {
        fT = (tMin/rayLength);
        return TRUE;
    }
    else
    {
        fT = (tMax/rayLength);
        return TRUE; 
    }
}
Example #26
0
void Shape::axisRotate(float deg){
	Vertex centTemp(center.x, center.y, center.z);
	translate(-center.x, -center.y, -center.z);//Translate to origin
	Vertex origin(0,0,0);
	bool para = false;
	//Build movement matrix
	axis = chooseAxis();
	Vect * ax = new Vect(origin, axis);
	Vect y(0,1.0, 0);
	Vect * v = Vect::unitVector(*ax);
	if(v->isParallel(y)){
		v->x += .0000000001;
	}	
	Vect * u = Vect::unitVector(*(Vect::crossProduct(*v, y)));
	Vect * n = Vect::unitVector(*(Vect::crossProduct(*u, *v)));
	//Align the global axis to the local axis:
	for(int i = 0; i < rs; i++){
		for(int j = 0; j < vs; j++){
			GLfloat x = verts[i][j].x;
			GLfloat y = verts[i][j].y;
			GLfloat z = verts[i][j].z;
			verts[i][j].x = u->x*x + u->y*y + u->z*z;
			verts[i][j].y = v->x*x + v->y*y + v->z*z;
			verts[i][j].z = n->x*x + n->y*y + n->z*z;
			x = vertsNorm[i][j].x;
			y = vertsNorm[i][j].y;
			z = vertsNorm[i][j].z;
			vertsNorm[i][j].x = u->x*x + u->y*y + u->z*z;
			vertsNorm[i][j].y = v->x*x + v->y*y + v->z*z;
			vertsNorm[i][j].z = n->x*x + n->y*y + n->z*z;
		}
	}
	//Rotate the amount needed.
	
	rotate(deg, 0, 1, 0);
	if(!para){
	for(int i = 0; i < rs; i++){
		for(int j = 0; j < vs; j++){
			GLfloat x = verts[i][j].x;
			GLfloat y = verts[i][j].y;
			GLfloat z = verts[i][j].z;
			verts[i][j].x = u->x*x + v->x*y + n->x*z;
			verts[i][j].y = u->y*x + v->y*y + n->y*z;
			verts[i][j].z = u->z*x + v->z*y + n->z*z;
			x = vertsNorm[i][j].x;
			y = vertsNorm[i][j].y;
			z = vertsNorm[i][j].z;
			vertsNorm[i][j].x = u->x*x + v->x*y + n->x*z;
			vertsNorm[i][j].y = u->y*x + v->y*y + n->y*z;
			vertsNorm[i][j].z = u->z*x + v->z*y + n->z*z;

		}
	}
	}
	translate(centTemp.x, centTemp.y, centTemp.z);
}
Example #27
0
Vect operator-(const Vect &p1, const Vect &p2){

    assert(p1.getDimension()==p2.getDimension());
    Vect k(p1.getDimension());
    for(int i = 1; i <= k.getDimension(); i++){
        k.setCoordinate(i,p1.getCoordinate(i)-p2.getCoordinate(i));
    }

return k;
}
Example #28
0
Vect::Vect(const Vect &w){

    dim = w.getDimension();
    v = new double[w.getDimension()];

    for(int i = 1; i <= dim; i++){
    v[i-1]=w.getCoordinate(i);
    }

}
Example #29
0
double operator*(const Vect &p1, const Vect &p2){

    assert(p1.getDimension()==p2.getDimension());
    double output = 0;
    for(int i = 1; i <= p1.getDimension(); i++){
        output += p1.getCoordinate(i)*p2.getCoordinate(i);
    }

return output;
}
Example #30
0
BOOL Bounds::OutsidePlane(const Plane &p) const
{
    Vect vmin;

    vmin.x = (*(DWORD*)&p.Dir.x & 0x80000000) ? Max.x : Min.x;
    vmin.y = (*(DWORD*)&p.Dir.y & 0x80000000) ? Max.y : Min.y;
    vmin.z = (*(DWORD*)&p.Dir.z & 0x80000000) ? Max.z : Min.z;

    return (vmin.Dot(p.Dir) > p.Dist);
}