示例#1
0
void RpalParser::Bs()
{
  pushProc("Bs()");
  if (_nt == "not")
  {
    read_token("not");
    Bp();
    build("not", 1);
  }
  //else
  Bp();
  popProc("Bs()");
}
Expression* sintactico::Bp()
{
    if(CurrentToken->tipo == AND)
    {
        CurrentToken = Lexer->NexToken();
        Expression* izq = C();
        Expression* der = Bp();
        if(izq != NULL)
            return new exprAnd(izq, der,Lexer->linea);
        return izq;
    }
    return NULL;
}
示例#3
0
  /**
   * Oblicza wartość kombinacji liniowej przy użyciu algorytmu Clenshawa.
   *
   * @param x Punkt w którym wyliczana jest wartość wielomianu.
   * @param deriv Flaga mówiąca czy wyliczana jest pochodna kombinacji.
   */
  real eval_clenshaw(const real &x, const bool &deriv = false) {
 
    sequence B(P.n + 3);

    B[P.n + 2] = B[P.n + 1] = 0;
    for (int k = P.n; k >= 0; k--) {
      B[k] = w[k] + (P.a[k + 1] * x - P.b[k + 1]) * B[k + 1] - P.c[k + 2] * B[k + 2];
    }

    /* Jeżeli nie chcemy liczyć pochodnej to tutaj kończymy. */
    if (not deriv) {
      return P.a[0] * B[0];
    }

    sequence Bp(P.n + 3);

    Bp[P.n + 2] = Bp[P.n + 1] = 0;
    for (int k = P.n; k >= 1; k--) { 
      Bp[k] = (P.a[k] * B[k]) + (P.a[k] * x - P.b[k]) * Bp[k + 1] - P.c[k + 1] * Bp[k + 2];
    }

    return P.a[0] * Bp[1];
  }
示例#4
0
void VanDerWaals::generateTriangle(Data::Mesh& mesh, Data::OMMesh::VertexHandle const& Av,
   Data::OMMesh::VertexHandle const& Bv, Data::OMMesh::VertexHandle const& Cv, int div)
{
   if (div <= 0) {
      mesh.addFace(Cv, Bv, Av);

   }else {

      Data::OMMesh::Point Ap(mesh.vertex(Av));
      Data::OMMesh::Point Bp(mesh.vertex(Bv));
      Data::OMMesh::Point Cp(mesh.vertex(Cv));

      // create 3 new vertices at the edge midpoints
      Data::OMMesh::Point ABp((Ap+Bp)*0.5);
      Data::OMMesh::Point BCp((Bp+Cp)*0.5);
      Data::OMMesh::Point CAp((Cp+Ap)*0.5);

      // Normalize the midpoints to keep them on the sphere
      ABp.normalize();
      BCp.normalize();
      CAp.normalize();

      Data::OMMesh::VertexHandle ABv(mesh.addVertex(ABp));
      Data::OMMesh::VertexHandle BCv(mesh.addVertex(BCp));
      Data::OMMesh::VertexHandle CAv(mesh.addVertex(CAp));

      mesh.setNormal(ABv, ABp);
      mesh.setNormal(BCv, BCp);
      mesh.setNormal(CAv, CAp);

      generateTriangle(mesh, Av,  ABv, CAv, div-1);
      generateTriangle(mesh, Bv,  BCv, ABv, div-1);
      generateTriangle(mesh, Cv,  CAv, BCv, div-1);
      generateTriangle(mesh, ABv, BCv, CAv, div-1);  //<-- Remove for serpinski
   }  
}
示例#5
0
ordinal_type
Stokhos::MonomialProjGramSchmidtPCEBasis<ordinal_type, value_type>::
buildReducedBasis(
  ordinal_type max_p, 
  value_type threshold,
  const Teuchos::SerialDenseMatrix<ordinal_type,value_type>& A, 
  const Teuchos::SerialDenseMatrix<ordinal_type,value_type>& F,
  const Teuchos::Array<value_type>& weights, 
  Teuchos::Array< Stokhos::MultiIndex<ordinal_type> >& terms_,
  Teuchos::Array<ordinal_type>& num_terms_,
  Teuchos::SerialDenseMatrix<ordinal_type,value_type>& Qp_, 
  Teuchos::SerialDenseMatrix<ordinal_type,value_type>& Q_)
{
  // Compute basis terms -- 2-D array giving powers for each linear index
  ordinal_type max_sz;
  CPBUtils::compute_terms(max_p, this->d, max_sz, terms_, num_terms_);

  // Compute B matrix -- monomials in F
  // for i=0,...,nqp-1
  //   for j=0,...,sz-1
  //      B(i,j) = F(i,1)^terms_[j][1] * ... * F(i,d)^terms_[j][d]
  // where sz is the total size of a basis up to order p and terms_[j] 
  // is an array of powers for each term in the total-order basis
  ordinal_type nqp = weights.size();
  SDM B(nqp, max_sz);
  for (ordinal_type i=0; i<nqp; i++) {
    for (ordinal_type j=0; j<max_sz; j++) {
      B(i,j) = 1.0;
      for (ordinal_type k=0; k<this->d; k++)
	B(i,j) *= std::pow(F(i,k), terms_[j][k]);
    }
  }

  // Project B into original basis -- should use SPAM for this
  SDM Bp(this->pce_sz, max_sz);
  const Teuchos::Array<value_type>& basis_norms = 
    this->pce_basis->norm_squared();
  for (ordinal_type i=0; i<this->pce_sz; i++) {
    for (ordinal_type j=0; j<max_sz; j++) {
      Bp(i,j) = 0.0;
      for (ordinal_type k=0; k<nqp; k++)
	Bp(i,j) += weights[k]*B(k,j)*A(k,i);
      Bp(i,j) /= basis_norms[i];
    }
  }

  // Rescale columns of Bp to have unit norm
  for (ordinal_type j=0; j<max_sz; j++) {
    value_type nrm = 0.0;
    for (ordinal_type i=0; i<this->pce_sz; i++)
      nrm += Bp(i,j)*Bp(i,j)*basis_norms[i];
    nrm = std::sqrt(nrm);
    for (ordinal_type i=0; i<this->pce_sz; i++)
      Bp(i,j) /= nrm;
  }

  // Compute our new basis -- each column of Qp is the coefficients of the
  // new basis in the original basis.  Constraint pivoting so first d+1
  // columns and included in Qp.
  Teuchos::Array<value_type> w(this->pce_sz, 1.0);
  SDM R;
  Teuchos::Array<ordinal_type> piv(max_sz);
  for (int i=0; i<this->d+1; i++)
    piv[i] = 1;
  typedef Stokhos::OrthogonalizationFactory<ordinal_type,value_type> SOF;
  ordinal_type sz_ = SOF::createOrthogonalBasis(
    this->orthogonalization_method, threshold, this->verbose, Bp, w, 
    Qp_, R, piv);

  // Evaluate new basis at original quadrature points
  Q_.reshape(nqp, sz_);
  ordinal_type ret = 
    Q_.multiply(Teuchos::NO_TRANS, Teuchos::NO_TRANS, 1.0, A, Qp_, 0.0);
  TEUCHOS_ASSERT(ret == 0);

  return sz_;
}
示例#6
0
TSIL_COMPLEX TSIL_Bp (TSIL_REAL X, TSIL_REAL Y, TSIL_COMPLEX S, TSIL_REAL QQ)
{  
  return Bp (X, Y, S, QQ);
}
示例#7
0
vector<Box3d*> TableObjectDetector::getHulls(const Mat P, const Mat L, const Mat plane) {
    double K;
    minMaxIdx(L, NULL, &K);
    vector<Box3d*> B;
    Mat Rp = determinePlaneRotation(-plane.col(0));
    // We found a rotation from a horizontal plane to our fitted plane
    // We want a translation from our fitted plane to a horizontal plane
    transpose(Rp, Rp);
    Mat Pt; transpose(P, Pt);
    Mat P_rot = Rp*Pt;
        
    for (int k=0; k<=K; k++) {
        double xmin = 1000; double ymin = 1000; double zmin = 1000;
        double xmax = -1000; double ymax = -1000; double zmax = -1000;        
        
        for (int i=0; i<P_rot.cols; i++) {
            if (L.at<int>(i)==k) {
                double x = P_rot.at<double>(0, i);
                double y = P_rot.at<double>(1, i);
                double z = P_rot.at<double>(2, i);
                if (x < xmin) {
                    xmin = x;
                }
                if (x>xmax) {
                    xmax = x;
                }
                if (y<ymin) {
                    ymin = y;
                }
                if (y>ymax) {
                    ymax = y;
                }
                if (z<zmin) {
                    zmin = z;
                }
                if (z>zmax) {
                    zmax = z;
                }
            }
        }
        
        zmax += 0.015; // Add the threshold so that the hull touches the plane
        
        Mat Bp(3, 8, CV_64F);
        Bp.at<double>(0, 0) = xmin; Bp.at<double>(1, 0) = ymin; Bp.at<double>(2, 0) = zmin;
        Bp.at<double>(0, 1) = xmax; Bp.at<double>(1, 1) = ymin; Bp.at<double>(2, 1) = zmin;
        Bp.at<double>(0, 2) = xmax; Bp.at<double>(1, 2) = ymax; Bp.at<double>(2, 2) = zmin;
        Bp.at<double>(0, 3) = xmin; Bp.at<double>(1, 3) = ymax; Bp.at<double>(2, 3) = zmin;
        Bp.at<double>(0, 4) = xmin; Bp.at<double>(1, 4) = ymin; Bp.at<double>(2, 4) = zmax;
        Bp.at<double>(0, 5) = xmax; Bp.at<double>(1, 5) = ymin; Bp.at<double>(2, 5) = zmax;
        Bp.at<double>(0, 6) = xmax; Bp.at<double>(1, 6) = ymax; Bp.at<double>(2, 6) = zmax;
        Bp.at<double>(0, 7) = xmin; Bp.at<double>(1, 7) = ymax; Bp.at<double>(2, 7) = zmax;
        Mat Rpp; transpose(Rp, Rpp);
        Bp = Rpp*Bp;
        transpose(Bp, Bp);
        
        Box3d* Bk = new Box3d(Bp);
        B.push_back(Bk);
    }

    this->objectHulls = B;
    
    return B;
}