Ejemplo n.º 1
0
point triangle::calc_center( triangle* t )
{

	arma::vec Pa(3);
	Pa(0) = (t->m_vertex_list[0].x);
	Pa(1) = (t->m_vertex_list[0].y);
	Pa(2) = 0;

	arma::vec Pb(3);
	Pb(0) = (t->m_vertex_list[1].x);
	Pb(1) = (t->m_vertex_list[1].y);
	Pb(2) = 0;

	arma::vec Pc(3);
	Pc(0) = (t->m_vertex_list[2].x);
	Pc(1) = (t->m_vertex_list[2].y);
	Pc(2) = 0;

	arma::vec AB = Pb - Pa;
	arma::vec AC = Pc - Pa;
	arma::vec BC = Pc - Pb;

//circumcenter
// 	arma::vec N = arma::cross(AC,AB);
// 	arma::vec L1 = arma::cross(AB,N);
// 	arma::vec L2 = arma::cross(BC,N);
// 	arma::vec P21 = (Pc - Pa)/2;
// 	arma::vec P1 = (Pa + Pb)/2;

	
//incenter

	arma::vec uab  = AB / arma::norm(AB,1);
	arma::vec uac  = AC / arma::norm(AC,1);
	arma::vec ubc  = BC / arma::norm(BC,1);
	arma::vec uba = -uab;

	arma::vec L1 = uab + uac;
	arma::vec L2 = uba + ubc;
	arma::vec P21 = Pb-Pa;
	arma::vec P1 = Pa;
     
	arma::mat ML1(L1);
	arma::mat ML2(L2);

	arma::mat ML = arma::join_rows(ML1,-ML2);

	arma::vec lambda = arma::solve(ML,P21);

	arma::vec pos = P1+lambda(0)*L1;

	point p;
	p.x = pos(0);
	p.y = pos(1);
	return p;
}
Ejemplo n.º 2
0
int main()
{

    using SolverType      = invlib::ConjugateGradient<>;
    using MinimizerType   = invlib::GaussNewton<double, SolverType>;
    using PrecisionMatrix = invlib::PrecisionMatrix<MatrixType>;
    using MAPType         = invlib::MAP<LinearModel,
                                        MatrixType,
                                        PrecisionMatrix,
                                        PrecisionMatrix>;

    // Load data.
    MatrixType K     = invlib::read_matrix_arts("STR_VALUE(MATS_DATA)/K.xml");
    MatrixType SaInv = invlib::read_matrix_arts("STR_VALUE(MATS_DATA)/SaInv.xml");
    MatrixType SeInv = invlib::read_matrix_arts("STR_VALUE(MATS_DATA)/SeInv.xml");
    PrecisionMatrix Pa(SaInv);
    PrecisionMatrix Pe(SeInv);

    VectorType y     = invlib::read_vector_arts("STR_VALUE(MATS_DATA)/y.vec");
    VectorType xa    = invlib::read_vector_arts("STR_VALUE(MATS_DATA)/xa.vec");

    // Setup OEM.
    SolverType    cg(1e-6, 1);
    MinimizerType gn(1e-6, 1, cg);
    LinearModel   F(K, xa);
    MAPType       oem(F, xa, Pa, Pe);

    // Run OEM.
    VectorType x;
    oem.compute(x, y, gn, 0);

    invlib::write_vector_arts("x.xml", (invlib::VectorData<double>) x, invlib::Format::ASCII);

    return 0.0;
}
Ejemplo n.º 3
0
int Pa(int low,int high,int length,char *str) {
	if(length == 0 || length == 1)
		return 1;
	
	if(str[low] != str[high])
		return 0;
	
	Pa(low+1,high-1,length-2,str);
}
Ejemplo n.º 4
0
void x_PredictAGSites(const Seq& seq, CAntigenic::TLocVec& results,
                      int min_len)
{


    // First build vector giving local average of Pa (over 7 residues).
    // Along the way, calculate the average for the whole protein.
    
    vector<double> Pa(seq.size());
    double local_sum = 0, global_sum = 0;

    for (int i = 0;  i < 7;  i++) {
        local_sum += CAntigenic::sm_Pa_table[static_cast<unsigned>(seq[i])];
        global_sum += CAntigenic::sm_Pa_table[static_cast<unsigned>(seq[i])];
    }
    Pa[3] = local_sum / 7;
    
    for (unsigned int i = 4;  i < seq.size() - 3;  i++) {
        local_sum -= CAntigenic::sm_Pa_table[static_cast<unsigned>(seq[i-4])];
        local_sum += CAntigenic::sm_Pa_table[static_cast<unsigned>(seq[i+3])];
        global_sum += CAntigenic::sm_Pa_table[static_cast<unsigned>(seq[i+3])];
        Pa[i] = local_sum / 7;
    }

    double global_mean = global_sum / seq.size();
    double thresh = min(global_mean, 1.0);

    // now look for runs of Pa >= thresh of length >= min_len

    int count = 0;
    int begin = 0;  // initialize to avoid compiler warning

    // NOTE: we go one extra residue, in the knowledge that
    // its Pa entry will be zero, so it will end any run
    for (unsigned int i = 3;  i < seq.size() - 2;  i++) {
        if (Pa[i] >= thresh) {
            if (count == 0) {
                begin = i;  // the beginning of a run
            }
            count++;
        } else {
            // the end of a (possibly empty) run
            if (count >= min_len) {
                // an antigenic site
                int end = i - 1;
                
                CRef<objects::CSeq_loc> loc(new objects::CSeq_loc());
                loc->SetInt().SetFrom(begin);
                loc->SetInt().SetTo(end);
                results.push_back(loc);
            }
            count = 0;
        }
    }
}
Ejemplo n.º 5
0
int main(int argc,char *argv[]) {
	int Pa(int low,int high,int length,char *str);
	int iseven(int n);
	int isodd(int n);
	char str[]="aabaa";
	int len;

	len = strlen(str);

	if(Pa(0,len-1,len,str)) {
		printf("this string is a Pa string\n");
	}
	printf("3:%d 4:%d\n",iseven(0),iseven(4));
}
//----------------------------------------------------------------------
Mat & AccumulatorTransitionMatrix::add_to(Mat &P)const {
    int state_dim = transition_matrix_->nrow();
    if(P.nrow() != state_dim+2 || P.ncol() != state_dim+2) {
        report_error("wrong sizes in AccumulatorTransitionMatrix::add_to");
    }
    SubMatrix Pa(P, 0, state_dim-1, 0, state_dim-1);
    transition_matrix_->add_to_submatrix(Pa);
    Vec tmp = transition_matrix_->Tmult(observation_vector_.dense());
    VectorView(P.row(state_dim), 0, state_dim) += tmp;
    double a = 1 - fraction_in_initial_period_ * contains_end_;
    int b = !contains_end_;
    P(state_dim+1, state_dim) += a;
    P(state_dim+1, state_dim+1) += b;
    return P;
}
Ejemplo n.º 7
0
/**
 * @function setGlCamera
 * Set OpenGL camera parameters.
 * The off-axis projection is what gives
 * the feeling of augmented reality.
 */
void setGlCamera()
{
    if(bProjectionMode)
    {
        /* SKEWED FRUSTRUM / OFF-AXIS PROJECTION
        ** My implementation is based on the following paper:
        ** Name:   Generalized Perspective Projection
        ** Author: Robert Kooima
        ** Date:   August 2008, revised June 2009
        */

        //-- space corners coordinates
        float pa[3]={-cx,-cy,0};
        float pb[3]={cx,-cy,0};
        float pc[3]={-cx,cy,0};
        float pe[3]={glCamX,glCamY,glCamZ};
        //-- space points
        cv::Vec3f Pa(pa);
        cv::Vec3f Pb(pb);
        cv::Vec3f Pc(pc);
        cv::Vec3f Pe(pe);
        //-- Compute an orthonormal basis for the screen.
        cv::Vec3f Vr = Pb-Pa;
        Vr /= cv::norm(Vr);
        cv::Vec3f Vu = Pc-Pa;
        Vu /= cv::norm(Vu);
        cv::Vec3f Vn = Vr.cross(Vu);
        Vn /= cv::norm(Vn);
        //-- Compute the screen corner vectors.
        cv::Vec3f Va = Pa-Pe;
        cv::Vec3f Vb = Pb-Pe;
        cv::Vec3f Vc = Pc-Pe;
        //-- Find the distance from the eye to screen plane.
        float d = -Va.dot(Vn);
        //-- Find the extent of the perpendicular projection.
        float l = Va.dot(Vr) * near / d;
        float r = Vr.dot(Vb) * near / d;
        float b = Vu.dot(Va) * near / d;
        float t = Vu.dot(Vc) * near / d;
        //-- Load the perpendicular projection.
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glFrustum(l, r, b, t, near, far+d);
        //-- Rotate the projection to be non-perpendicular.
        float M[16];
        memset(M, 0, 16 * sizeof (float));
        M[0] = Vr[0]; M[1] = Vu[0]; M[2] = Vn[0];
        M[4] = Vr[1]; M[5] = Vu[1]; M[6] = Vn[1];
        M[8] = Vr[2]; M[9] = Vu[2]; M[10] = Vn[2];
        M[15] = 1.0f;
        glMultMatrixf(M);
        //-- Move the apex of the frustum to the origin.
        glTranslatef(-pe[0], -pe[1], -pe[2]);
        //-- Reset modelview matrix
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    else
    {
        //-- intrinsic camera params
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60, (float)windowWidth/(float)windowHeight, 1, 250);
        //-- extrinsic camera params
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(glCamX, glCamY, glCamZ, 0, 0, 0, 0, 1, 0);
    }
}
Ejemplo n.º 8
0
void sha512_update(sha512_ctx_t *ctx, void *data, size_t dlen) {
  uint16_t avail; /* space available in the context message block */
  uint16_t pos;   /* position to write data into the message block */
  uint64_t x[80];
  
  while (dlen) {
    pos = CTX_POS(ctx);
    avail = CTX_AVAIL(ctx);
    if (avail > dlen)
      avail = dlen;
      
    /* Copy input data into the context's message block. */
    memcpy(ctx->block + pos, data, avail);
    data += avail;
    dlen -= avail;
    ctx->len += avail;
    
    if ((ctx->len % 128) == 0) {
      uint64_t a = ctx->hash[0];
      uint64_t b = ctx->hash[1];
      uint64_t c = ctx->hash[2];
      uint64_t d = ctx->hash[3];
      uint64_t e = ctx->hash[4];
      uint64_t f = ctx->hash[5];
      uint64_t g = ctx->hash[6];
      uint64_t h = ctx->hash[7];
      uint64_t t;
      
      Pa(t, a, b, c, d, e, f, g, h, x,  0, 0x428a2f98d728ae22);
      Pa(t, h, a, b, c, d, e, f, g, x,  1, 0x7137449123ef65cd);
      Pa(t, g, h, a, b, c, d, e, f, x,  2, 0xb5c0fbcfec4d3b2f);
      Pa(t, f, g, h, a, b, c, d, e, x,  3, 0xe9b5dba58189dbbc);
      Pa(t, e, f, g, h, a, b, c, d, x,  4, 0x3956c25bf348b538);
      Pa(t, d, e, f, g, h, a, b, c, x,  5, 0x59f111f1b605d019);
      Pa(t, c, d, e, f, g, h, a, b, x,  6, 0x923f82a4af194f9b);
      Pa(t, b, c, d, e, f, g, h, a, x,  7, 0xab1c5ed5da6d8118);
      Pa(t, a, b, c, d, e, f, g, h, x,  8, 0xd807aa98a3030242);
      Pa(t, h, a, b, c, d, e, f, g, x,  9, 0x12835b0145706fbe);
      Pa(t, g, h, a, b, c, d, e, f, x, 10, 0x243185be4ee4b28c);
      Pa(t, f, g, h, a, b, c, d, e, x, 11, 0x550c7dc3d5ffb4e2);
      Pa(t, e, f, g, h, a, b, c, d, x, 12, 0x72be5d74f27b896f);
      Pa(t, d, e, f, g, h, a, b, c, x, 13, 0x80deb1fe3b1696b1);
      Pa(t, c, d, e, f, g, h, a, b, x, 14, 0x9bdc06a725c71235);
      Pa(t, b, c, d, e, f, g, h, a, x, 15, 0xc19bf174cf692694);
      Pb(t, a, b, c, d, e, f, g, h, x, 16, 0xe49b69c19ef14ad2);
      Pb(t, h, a, b, c, d, e, f, g, x, 17, 0xefbe4786384f25e3);
      Pb(t, g, h, a, b, c, d, e, f, x, 18, 0x0fc19dc68b8cd5b5);
      Pb(t, f, g, h, a, b, c, d, e, x, 19, 0x240ca1cc77ac9c65);
      Pb(t, e, f, g, h, a, b, c, d, x, 20, 0x2de92c6f592b0275);
      Pb(t, d, e, f, g, h, a, b, c, x, 21, 0x4a7484aa6ea6e483);
      Pb(t, c, d, e, f, g, h, a, b, x, 22, 0x5cb0a9dcbd41fbd4);
      Pb(t, b, c, d, e, f, g, h, a, x, 23, 0x76f988da831153b5);
      Pb(t, a, b, c, d, e, f, g, h, x, 24, 0x983e5152ee66dfab);
      Pb(t, h, a, b, c, d, e, f, g, x, 25, 0xa831c66d2db43210);
      Pb(t, g, h, a, b, c, d, e, f, x, 26, 0xb00327c898fb213f);
      Pb(t, f, g, h, a, b, c, d, e, x, 27, 0xbf597fc7beef0ee4);
      Pb(t, e, f, g, h, a, b, c, d, x, 28, 0xc6e00bf33da88fc2);
      Pb(t, d, e, f, g, h, a, b, c, x, 29, 0xd5a79147930aa725);
      Pb(t, c, d, e, f, g, h, a, b, x, 30, 0x06ca6351e003826f);
      Pb(t, b, c, d, e, f, g, h, a, x, 31, 0x142929670a0e6e70);
      Pb(t, a, b, c, d, e, f, g, h, x, 32, 0x27b70a8546d22ffc);
      Pb(t, h, a, b, c, d, e, f, g, x, 33, 0x2e1b21385c26c926);
      Pb(t, g, h, a, b, c, d, e, f, x, 34, 0x4d2c6dfc5ac42aed);
      Pb(t, f, g, h, a, b, c, d, e, x, 35, 0x53380d139d95b3df);
      Pb(t, e, f, g, h, a, b, c, d, x, 36, 0x650a73548baf63de);
      Pb(t, d, e, f, g, h, a, b, c, x, 37, 0x766a0abb3c77b2a8);
      Pb(t, c, d, e, f, g, h, a, b, x, 38, 0x81c2c92e47edaee6);
      Pb(t, b, c, d, e, f, g, h, a, x, 39, 0x92722c851482353b);
      Pb(t, a, b, c, d, e, f, g, h, x, 40, 0xa2bfe8a14cf10364);
      Pb(t, h, a, b, c, d, e, f, g, x, 41, 0xa81a664bbc423001);
      Pb(t, g, h, a, b, c, d, e, f, x, 42, 0xc24b8b70d0f89791);
      Pb(t, f, g, h, a, b, c, d, e, x, 43, 0xc76c51a30654be30);
      Pb(t, e, f, g, h, a, b, c, d, x, 44, 0xd192e819d6ef5218);
      Pb(t, d, e, f, g, h, a, b, c, x, 45, 0xd69906245565a910);
      Pb(t, c, d, e, f, g, h, a, b, x, 46, 0xf40e35855771202a);
      Pb(t, b, c, d, e, f, g, h, a, x, 47, 0x106aa07032bbd1b8);
      Pb(t, a, b, c, d, e, f, g, h, x, 48, 0x19a4c116b8d2d0c8);
      Pb(t, h, a, b, c, d, e, f, g, x, 49, 0x1e376c085141ab53);
      Pb(t, g, h, a, b, c, d, e, f, x, 50, 0x2748774cdf8eeb99);
      Pb(t, f, g, h, a, b, c, d, e, x, 51, 0x34b0bcb5e19b48a8);
      Pb(t, e, f, g, h, a, b, c, d, x, 52, 0x391c0cb3c5c95a63);
      Pb(t, d, e, f, g, h, a, b, c, x, 53, 0x4ed8aa4ae3418acb);
      Pb(t, c, d, e, f, g, h, a, b, x, 54, 0x5b9cca4f7763e373);
      Pb(t, b, c, d, e, f, g, h, a, x, 55, 0x682e6ff3d6b2b8a3);
      Pb(t, a, b, c, d, e, f, g, h, x, 56, 0x748f82ee5defb2fc);
      Pb(t, h, a, b, c, d, e, f, g, x, 57, 0x78a5636f43172f60);
      Pb(t, g, h, a, b, c, d, e, f, x, 58, 0x84c87814a1f0ab72);
      Pb(t, f, g, h, a, b, c, d, e, x, 59, 0x8cc702081a6439ec);
      Pb(t, e, f, g, h, a, b, c, d, x, 60, 0x90befffa23631e28);
      Pb(t, d, e, f, g, h, a, b, c, x, 61, 0xa4506cebde82bde9);
      Pb(t, c, d, e, f, g, h, a, b, x, 62, 0xbef9a3f7b2c67915);
      Pb(t, b, c, d, e, f, g, h, a, x, 63, 0xc67178f2e372532b);
      Pb(t, a, b, c, d, e, f, g, h, x, 64, 0xca273eceea26619c);
      Pb(t, h, a, b, c, d, e, f, g, x, 65, 0xd186b8c721c0c207);
      Pb(t, g, h, a, b, c, d, e, f, x, 66, 0xeada7dd6cde0eb1e);
      Pb(t, f, g, h, a, b, c, d, e, x, 67, 0xf57d4f7fee6ed178);
      Pb(t, e, f, g, h, a, b, c, d, x, 68, 0x06f067aa72176fba);
      Pb(t, d, e, f, g, h, a, b, c, x, 69, 0x0a637dc5a2c898a6);
      Pb(t, c, d, e, f, g, h, a, b, x, 70, 0x113f9804bef90dae);
      Pb(t, b, c, d, e, f, g, h, a, x, 71, 0x1b710b35131c471b);
      Pb(t, a, b, c, d, e, f, g, h, x, 72, 0x28db77f523047d84);
      Pb(t, h, a, b, c, d, e, f, g, x, 73, 0x32caab7b40c72493);
      Pb(t, g, h, a, b, c, d, e, f, x, 74, 0x3c9ebe0a15c9bebc);
      Pb(t, f, g, h, a, b, c, d, e, x, 75, 0x431d67c49c100d4c);
      Pb(t, e, f, g, h, a, b, c, d, x, 76, 0x4cc5d4becb3e42b6);
      Pb(t, d, e, f, g, h, a, b, c, x, 77, 0x597f299cfc657e2a);
      Pb(t, c, d, e, f, g, h, a, b, x, 78, 0x5fcb6fab3ad6faec);
      Pb(t, b, c, d, e, f, g, h, a, x, 79, 0x6c44198c4a475817);
      
      ctx->hash[0] += a;
      ctx->hash[1] += b;
      ctx->hash[2] += c;
      ctx->hash[3] += d;
      ctx->hash[4] += e;
      ctx->hash[5] += f;
      ctx->hash[6] += g;
      ctx->hash[7] += h;
    }
  }
}