Esempio n. 1
0
matrix<int> graph<V,E>::incidence_matrix()
{
    matrix<int> incidence(this->vertices.size(),this->edges.size());
    for(int i=0,a,b; i<this->edges.size(); i++)
    {
        for(a=0;this->vertices[a].ID!=this->edges[i].IDstart;a++);
        for(b=0;this->vertices[b].ID!=this->edges[i].IDend;b++);
        incidence(a,i) = -1;
        incidence(b,i) = +1;
    }
    return incidence;
}
Esempio n. 2
0
	bool LineSegment::isIncident(const cv::Point3d &vp, double ANGLE_EPSILON) const
	{
		cv::Point3d l = lineThroughPoints(middle, vp);
		normalizeZ(l);
		double d = incidence(l, from) / (norm12(l) * norm12(middle - from));
		return abs(asin(d)) <= ANGLE_EPSILON;
	}
Esempio n. 3
0
int NuTo::Structure::ElementsCreate(int rInterpolationTypeId, const Eigen::MatrixXi& rNodeNumbers)
{
    std::vector<int> newElementIds;
    // go through the elements
    for (int iNode = 0; iNode < rNodeNumbers.cols(); ++iNode)
    {
        auto column = rNodeNumbers.col(iNode);
        std::vector<int> incidence(column.data(), column.data() + column.size());
        int newElementId = ElementCreate(rInterpolationTypeId, incidence);
        newElementIds.push_back(newElementId);
    }

    bool showTime = mShowTime;
    mShowTime = false;

    // create element group containing the new elements
    int newElementGroup = GroupCreate(eGroupId::Elements);
    for (int newElementId : newElementIds)
        GroupAddElement(newElementGroup, newElementId);

    mShowTime = showTime;
    return newElementGroup;
}
Esempio n. 4
0
void Homology::findCompatibleBasisPair(int master, std::vector<int> dim)
{
  if(!this->isHomologyComputed(dim)) this->findHomologyBasis(dim);
  if(!this->isCohomologyComputed(dim)) this->findCohomologyBasis(dim);
  for(unsigned int idim = 0 ; idim < dim.size(); idim++) {
    int d = dim.at(idim);
    if(d < 1 || d > 2) continue;
    int n = this->betti(d);
    if(n < 2) continue;
    if((int)_chains[d].size() != n || (int)_cochains[d].size() != n) {
      Msg::Warning("Cannot produce compatible %d-(co)homology bases.", d);
      Msg::Debug("%d basis %d-chains and %d basis %d-cochains.",
                 (int)_chains[d].size(), d, (int)_cochains[d].size(), d);
      continue;
    }
    fullMatrix<double> m(n,n);
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(master==0) m(i,j) = incidence(*_cochains[d].at(i), *_chains[d].at(j));
        else m(i,j) = incidence(*_chains[d].at(i), *_cochains[d].at(j));
      }
    }

    int det = m.determinant();
    if(abs(det) != 1 || !m.invertInPlace()) {
      Msg::Warning("Cannot produce compatible %d-(co)homology bases.", d);
      Msg::Debug("Incidence matrix: ");
      for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
          Msg::Debug("(%d, %d) = %d", i, j, m(i,j));
      continue;
    }

    std::vector<Chain<int>*> newBasis(n);

    if(master==0) {
      for(int i = 0; i < n; i++) {
        newBasis.at(i) = new Chain<int>();
        for(int j = 0; j < n; j++) {
          *newBasis.at(i) += (int)m(i,j)*(*_cochains[d].at(j));
        }
      }
      for(int i = 0; i < n; i++) {
        newBasis.at(i)->setName(_cochains[d].at(i)->getName());
        delete _cochains[d].at(i);
        _cochains[d].at(i) = newBasis.at(i);
      }
    }
    else {
      for(int i = 0; i < n; i++) {
        newBasis.at(i) = new Chain<int>();
        for(int j = 0; j < n; j++) {
          *newBasis.at(i) += (int)m(i,j)*(*_chains[d].at(j));
        }
      }
      for(int i = 0; i < n; i++) {
        newBasis.at(i)->setName(_chains[d].at(i)->getName());
        delete _chains[d].at(i);
        _chains[d].at(i) = newBasis.at(i);
      }
    }
  }
}