Ejemplo n.º 1
0
void DrawPath::renderCorr() const
{

    if (!_corrRoto)
        return;
    Vec2f a, b;
    glLineWidth(1);
    glBegin (GL_LINES);
    for (int i = 0; i < getNumElements(); i += 3)
    {
        a = getElement(i);
        glVertex2f(a.x(), a.y());
        b = _corrRoto->getSampleRoto(i)->getLoc(_corrRoto->getSampleRotoT(i));
        glVertex2f(b.x(), b.y());
    }
    glEnd();

    /*  if (!_corrRoto) return;
     glLineWidth(1);
     glBegin(GL_LINES);
     Vec2f a,b;
     for (int i=0; i<getNumElements(); i+=3) {
     a = _corrRoto->getElement(_corrs[i]);
     glVertex2f(a.x(),a.y());
     b= getElement(i);
     glVertex2f(b.x(),b.y());
     }
     glEnd();*/

    /*
     if (!(_corrs && _corrsPtr)) return;
     glLineWidth(1);
     glBegin(GL_LINES);
     Vec2f a,b;
     for (int i=0; i<getNumElements(); i+=1) {
     a = _corrsPtr[i]->getElement(_corrs[i]);
     glVertex2f(a.x(),a.y());
     b= getElement(i);
     glVertex2f(b.x(),b.y());

     }

     glEnd();
     */
}
Ejemplo n.º 2
0
   /** Equivalence.
       Two matrices are equivalent if they are both by rows or both by columns,
       they have the same dimensions, and each vector is equivalent. 
       In this method the FloatEqual function operator can be specified. 
   */
   template <class FloatEqual> bool 
   isEquivalent(const CoinPackedMatrix& rhs, const FloatEqual& eq) const
   {
      // Both must be column order or both row ordered and must be of same size
      if ((isColOrdered() ^ rhs.isColOrdered()) ||
	  (getNumCols() != rhs.getNumCols()) ||
	  (getNumRows() != rhs.getNumRows()) ||
	  (getNumElements() != rhs.getNumElements()))
	 return false;
     
      for (int i=getMajorDim()-1; i >= 0; --i) {
        CoinShallowPackedVector pv = getVector(i);
        CoinShallowPackedVector rhsPv = rhs.getVector(i);
        if ( !pv.isEquivalent(rhsPv,eq) )
          return false;
      }
      return true;
   }
Ejemplo n.º 3
0
bool PViewData::toVector(std::vector<std::vector<double> > &vec)
{
  vec.resize(getNumTimeSteps());
  for(int step = 0; step < getNumTimeSteps(); step++){
    vec[step].clear();
    for(int ent = 0; ent < getNumEntities(step); ent++){
      for(int ele = 0; ele < getNumElements(step, ent); ele++){
        if(skipElement(step, ent, ele)) continue;
        for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){
          for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){
            double val;
            getValue(step, ent, ele, nod, comp, val);
            vec[step].push_back(val);
          }
        }
      }
    }
  }
  return true;
}
Ejemplo n.º 4
0
Bboxf2D DrawPath::calcBbox() const
{
    Bboxf2D bbox;
    for (int i = 0; i < getNumElements(); i++)
    {
        Bboxf2D currBox;
        Vec2f currLoc = getElement(i), extLoc, thick(_thick.getElement(i),
                _thick.getElement(i));

        Vec2f_Sub(extLoc, currLoc, thick);
        currBox.includePoint(extLoc);

        Vec2f_Add(extLoc, currLoc, thick);
        currBox.includePoint(extLoc);

        bbox.setToUnion(currBox);
    }

    return bbox;
}
Ejemplo n.º 5
0
long SerializeStreamImpl::findLabelInFile(const char * label) {

    assert(_fpLoad==NULL);
    assert(_fpSave!=NULL);

    long curPos;
    long nextPos = _lastNextEntry;
    
    while (true) {

        fseek(_fpLoad, nextPos, SEEK_SET);
        curPos = nextPos;
        fread(&nextPos, sizeof(nextPos), 1, _fpLoad);
        if (curPos==nextPos) {
            // we didn't find it
            throw ccor::Exception("core : label '%s' not found in a loading stream", label);
        }

        // load label string
        fseek(_fpLoad, nextPos, SEEK_SET);
        int n = getNumElements();
        std::string strLabel;
        strLabel.resize(n-1);
        serializeData((void*)strLabel.c_str(), 'L', sizeof(char), n);
        nextPos = ftell(_fpLoad);

        // compare it to what we want to find
        if (strLabel==label) {
            long _v;
            fread(&_v, sizeof(_v), 1, _fpLoad);
            // store label for future use
            long pos = ftell(_fpLoad);
            _labelMap.insert(LabelMap::value_type(label,pos));
            _lastNextEntry = nextPos;
            return pos;
        }
    }

    return 0;
}
Ejemplo n.º 6
0
double PViewDataList::getMax(int step, bool onlyVisible, int tensorRep,
                             int forceNumComponents, int componentMap[9])
{
  if(step >= (int)TimeStepMax.size()) return Max;

  if(forceNumComponents || tensorRep) {
    double vmax = -VAL_INF;
    for(int ent = 0; ent < getNumEntities(step); ent++) {
      for(int ele = 0; ele < getNumElements(step, ent); ele++) {
        for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++) {
          double val;
          getScalarValue(step, ent, ele, nod, val, tensorRep,
                         forceNumComponents, componentMap);
          vmax = std::max(vmax, val);
        }
      }
    }
    return vmax;
  }

  if(step < 0) return Max;
  return TimeStepMax[step];
}
Ejemplo n.º 7
0
bool PViewData::fromVector(const std::vector<std::vector<double> > &vec)
{
  if(empty() || !getNumTimeSteps()){
    Msg::Warning("Cannot import vector in an empty view; skipping");
    return false;
  }

  if((int)vec.size() != getNumTimeSteps()){
    Msg::Error("Incompatible number of steps in vector for view import (%d!=%d)",
               (int)vec.size(), getNumTimeSteps());
    return false;
  }

  for(int step = 0; step < getNumTimeSteps(); step++){
    int i = 0;
    for(int ent = 0; ent < getNumEntities(step); ent++){
      for(int ele = 0; ele < getNumElements(step, ent); ele++){
        if(skipElement(step, ent, ele)) continue;
        for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){
          double x, y, z;
          getNode(step, ent, ele, nod, x, y, z);
          for(int comp = 0; comp < getNumComponents(step, ent, ele); comp++){
            if(i < (int)vec[step].size()){
              setValue(step, ent, ele, nod, comp, vec[step][i++]);
            }
            else{
              Msg::Error("Bad index (%d) in vector (%d) for view import",
                         i, (int)vec[step].size());
              return false;
            }
          }
        }
      }
    }
  }
  return true;
}
Ejemplo n.º 8
0
void stressTests(){
    for(int i = 0 ; i <= 1000 ; i++){
        Node *list = makeRandListOfSizeN(i * 1000);
        delList(list);
        if(!(i%50)){
            printf("Made and deleted list of size %d...\n", i*1000);
        }
    }

    int hellListSize = 10000000;
    Node *list = makeRandListOfSizeN_bounded(hellListSize, 5000000);
    printList(list);

    for(int i = 0 ; i < 5000000 ; i++){
        Node *t = findElement(list, i);
        if(t){
            int pos = getNumElements(t->next);
            printf("Found %d in list at pos %d!\n", i, pos);
            break;
        }
    }
    for(int i = 0 ; i < 3000 ; i++){
        int op = arc4random() % 4;
        switch(op){
            case 0: list = insertAtN(list, arc4random(),
                              arc4random_uniform(hellListSize)); break;
            case 1: list = deleteAtN(list, arc4random_uniform(hellListSize)); break;
            case 2: list = changeValueAtN(list, arc4random(),
                                   arc4random_uniform(hellListSize)); break;
            case 3: list = addToTail(list, arc4random()); break;
        }
        if(!(i%50))
            printf("%d random operations completed...\n", i);
    }
    delList(list);
}
void RingBuffer<T>::popBack (int count)
{
	DE_ASSERT(de::inRange(count, 0, getNumElements()));
	m_back = (m_back + count) % m_size;
	m_numElements -= count;
}
Ejemplo n.º 10
0
double DrawPath::distToLast2(const Vec2f& loc) const
{
    return getPointerToElement(getNumElements() - 1)->distanceTo2(loc);
}
double
CoinPackedVectorBase::sum() const
{
   return std::accumulate(getElements(), getElements() + getNumElements(), 0.0);
}
Ejemplo n.º 12
0
void DrawPath::spliceIn(const DrawPath *other, const int i1, const int i2)
{

    printf("DrawPAth splicing %d %d\n", i1, i2);
    int oldSize = getNumElements();
    int newsize = i1 + other->getNumElements() + oldSize - i2 - 1, i, j, k;
    ensureCapacity(newsize);
    _thick.ensureCapacity(newsize);
    count = newsize;
    _thick.setCount(newsize);

    Vec2f* oldPts = new Vec2f[oldSize];
    float* oldThick = new float[oldSize];
    memcpy(oldPts, data, oldSize * sizeof(Vec2f));
    memcpy(oldThick, _thick.getData(), oldSize * sizeof(float));

    /*
     for (i=newsize-1,j=oldSize-1; j>i2; i--,j--) {
     setElement(i,oldPts[j]);
     _thick.setElement(i,oldThick[j]);
     }
     for (i=i1,j=0; j<other->getNumElements(); i++,j++) {
     setElement(i,other->getElement(j));
     _thick.setElement(i, other->_thick.getElement(j));
     }
     */
    float fac, blT;
    int spliceL = other->getNumElements();

    for (i = i1, j = 0; j < spliceL; i++, j++)
    {
        setElement(i, other->getElement(j));
        if (j < 9 && (k = i) < oldSize)
        {
            fac = float(j) / 8.f;
            blT = oldThick[k]
                    + fac * (other->_thick.getElement(j) - oldThick[k]);
            _thick.setElement(i, blT);
        }
        else if (j >= spliceL - 9 && (k = i2 - (spliceL - j - 1)) < oldSize)
        {
            fac = float(spliceL - j - 1) / 8.f;
            assert(fac >= 0);
            printf("end %f\n", fac);
            blT = oldThick[k]
                    + fac * (other->_thick.getElement(j) - oldThick[k]);
            _thick.setElement(i, blT);
        }
        else
            _thick.setElement(i, other->_thick.getElement(j));
    }

    for (k = i2 + 1; i < newsize; i++, k++)
    {
        setElement(i, oldPts[k]);
        _thick.setElement(i, oldThick[k]);
    }

    //i: new curve, j: spliceIn, k: old curve
    /*
     for (i=i1-lB,m=0,j=0, k=i1-lB; m<2*lB; m++,i++,j++,k++) {
     fac = float(m)/float(lB);
     Vec2f_LinInterp(blend, oldPts[k], other->getElement(j), fac);
     blT = oldThick[k] + fac*(other->_thick.getElement(j) - oldThick[k]);
     setElement(i,blend);
     _thick.setElement(i, blT);
     }
     */

    /*  for (m=0, k=i2+1-lB; m<hB; m++,i++,j++,k++) {
     fac = float(m)/float(lB);
     Vec2f_LinInterp(blend, oldPts[k], other->getElement(j), fac);
     setElement(i,blend);
     blT = oldThick[j] + fac*(other->_thick.getElement(j) - oldThick[k]);
     _thick.setElement(i, blT);
     }*/

    delete[] oldPts;
    delete[] oldThick;

    //for (i=0; i<newsize; i++)
    //printf("%f %f\n",getElement(i).x(), getElement(i).y());

    delete _corrRoto;
    _corrRoto = NULL;
    //delete[] _corrs; _corrs = NULL;
    //delete[] _corrsPtr; _corrsPtr = NULL;

    redoStroke();
    calculateStrokeDisplayList();
    calculateFillDisplayList();
}
Ejemplo n.º 13
0
double AbstractPath::distanceToEnd(const Vec2f pt) const {
  return getPointerToElement(getNumElements()-1)->distanceTo2(pt);
}
Ejemplo n.º 14
0
bool PViewData::empty()
{
  return (!getNumElements() && !getNumStrings2D() && !getNumStrings3D());
}
Ejemplo n.º 15
0
static bool nIsInRange(Node *l, int n){
    if(n < 0 || n > getNumElements(l))
        return false;
    return true;
}
double
CoinPackedVectorBase::normSquare() const
{
   return std::inner_product(getElements(), getElements() + getNumElements(),
			     getElements(), 0.0);
}
void RingBuffer<T>::peekBack (T* elemBuf, int count) const
{
	DE_ASSERT(de::inRange(count, 0, getNumElements()));
	for (int i = 0; i < count; i++)
		elemBuf[i] = m_buffer[(m_back + i) % m_size];
}
inline T RingBuffer<T>::peekBack (int offset) const
{
	DE_ASSERT(de::inBounds(offset, 0, getNumElements()));
	return m_buffer[(m_back + offset) % m_size];
}
Ejemplo n.º 19
0
bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed,
                         bool append)
{
  if(_adaptive){
    Msg::Warning("Writing adapted dataset (will only export current time step)");
    return _adaptive->getData()->writePOS(fileName, binary, parsed, append);
  }
  if(hasMultipleMeshes()){
    Msg::Error("Cannot export multi-mesh datasets in .pos format");
    return false;
  }
  if(haveInterpolationMatrices())
    Msg::Warning("Discarding interpolation matrices when saving in .pos format");
  if(binary || !parsed)
    Msg::Warning("Only parsed .pos files can be exported for this view type");

  FILE *fp = Fopen(fileName.c_str(), append ? "a" : "w");
  if(!fp){
    Msg::Error("Unable to open file '%s'", fileName.c_str());
    return false;
  }

  fprintf(fp, "View \"%s\" {\n", getName().c_str());

  int firstNonEmptyStep = getFirstNonEmptyTimeStep();
  for(int ent = 0; ent < getNumEntities(firstNonEmptyStep); ent++){
    for(int ele = 0; ele < getNumElements(firstNonEmptyStep, ent); ele++){
      if(skipElement(firstNonEmptyStep, ent, ele)) continue;
      int type = getType(firstNonEmptyStep, ent, ele);
      int numComp = getNumComponents(firstNonEmptyStep, ent, ele);
      const char *s = 0;
      switch(type){
      case TYPE_PNT: s = (numComp == 9) ? "TP" : (numComp == 3) ? "VP" : "SP"; break;
      case TYPE_LIN: s = (numComp == 9) ? "TL" : (numComp == 3) ? "VL" : "SL"; break;
      case TYPE_TRI: s = (numComp == 9) ? "TT" : (numComp == 3) ? "VT" : "ST"; break;
      case TYPE_QUA: s = (numComp == 9) ? "TQ" : (numComp == 3) ? "VQ" : "SQ"; break;
      case TYPE_TET: s = (numComp == 9) ? "TS" : (numComp == 3) ? "VS" : "SS"; break;
      case TYPE_HEX: s = (numComp == 9) ? "TH" : (numComp == 3) ? "VH" : "SH"; break;
      case TYPE_PRI: s = (numComp == 9) ? "TI" : (numComp == 3) ? "VI" : "SI"; break;
      case TYPE_PYR: s = (numComp == 9) ? "TY" : (numComp == 3) ? "VY" : "SY"; break;
      }
      if(s){
        fprintf(fp, "%s(", s);
        int numNod = getNumNodes(firstNonEmptyStep, ent, ele);
        for(int nod = 0; nod < numNod; nod++){
          double x, y, z;
          getNode(firstNonEmptyStep, ent, ele, nod, x, y, z);
          fprintf(fp, "%.16g,%.16g,%.16g", x, y, z);
          if(nod != numNod - 1) fprintf(fp, ",");
        }
        bool first = true;
        for(int step = 0; step < getNumTimeSteps(); step++){
          if(hasTimeStep(step)){
            for(int nod = 0; nod < numNod; nod++){
              for(int comp = 0; comp < numComp; comp++){
                double val;
                getValue(step, ent, ele, nod, comp, val);
                if(first){ fprintf(fp, "){%.16g", val); first = false; }
                else fprintf(fp, ",%.16g", val);
              }
            }
          }
        }
        fprintf(fp, "};\n");
      }
    }
  }

  fprintf(fp, "};\n");
  fclose(fp);

  return true;
}
Ejemplo n.º 20
0
int getNumElements(Node *l){
    return !l ? 0 : 1 + getNumElements(l->next);
}
Ejemplo n.º 21
0
size_t UniformAligner::getCurrentOffset() {
	return getOffset(getNumElements() - 1);
}