Esempio n. 1
0
void output(){
  if (piles.size() > 1){
    printf("%lu piles remaining:", piles.size());
  }else{
    printf("%lu pile remaining:", piles.size());
  }
  for (IT it = piles.begin(); it != piles.end(); it++){
    printf(" %lu", it->size());
  }
  printf("\n");
}
Esempio n. 2
0
    RealTime ModelContainer::getIntersectionTime(const Ray& pRay, bool pExitAtFirst, float pMaxDist) const
    {
        #ifdef _DEBUG_VMAPS
        for(unsigned int i=0; i<getNSubModel(); i++)
        {
            SubModel model = getSubModel(i);
            bool insiteOk;
            Vector3 mynormal;
            Vector3 location;
            bool hitval = MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
                pRay.origin, pRay.direction,
                model.getAABoxBounds(),
                location,insiteOk, mynormal);
            if(hitval)
            {
                float len2 = (location - pRay.origin).squaredLength();
                int a = 0;                                  // just to be able to set a breakpoint
            }
        }
        TreeNode tn = getTreeNode(0);
        for(int i=0; i<tn.getNValues(); i++)
        {
            SubModel mysm = getSubModel(tn.getStartPosition() + i);
            AABox testbox = mysm.getAABoxBounds();
            gBoxArray.append(AABox(testbox.low(), testbox.high()));
        }
        #endif

        double  firstDistance = inf();
        Ray relativeRay = Ray::fromOriginAndDirection(pRay.origin - getBasePosition(), pRay.direction);
        const IT end = endRayIntersection();
        IT obj = beginRayIntersection(pRay, pMaxDist);
        for ( ;obj != end; ++obj)                           // (preincrement is *much* faster than postincrement!)
        {
            /*
            Call your accurate intersection test here.  It is guaranteed
            that the ray hits the bounding box of obj.  (*obj) has type T,
            so you can call methods directly using the "->" operator.
            */
            SubModel const *model =  &(*obj);

            RealTime t = model->getIntersectionTime(pRay, pExitAtFirst, pMaxDist);
            if(t > 0 && t < inf())
            {
                obj.markBreakNode();
                if(firstDistance > t && pMaxDist >= t)
                {
                    firstDistance = t;
                    if(pExitAtFirst) { break; }
                }
            }
        }
        return(firstDistance);
    }
void CDictionaryBasedTempPath::RepeatLookup()
{
    // optimization

    if (relPathElements.empty())
        return;

    // some preparation ...

    const CPathDictionary* dict = GetDictionary();
    index_t currentIndex = GetIndex();

    typedef std::vector<std::string>::iterator IT;
    IT begin = relPathElements.begin();

    // try to match the relative path elements with cached paths, step by step

    for (IT iter = begin, end = relPathElements.end(); iter != end; ++iter)
    {
        index_t nextIndex = dict->Find (currentIndex, iter->c_str());
        if (nextIndex == NO_INDEX)
        {
            // new dictionary-based path info ends here.
            // update internal data, if we made any progress

            if (iter != begin)
            {
                assert (currentIndex != nextIndex);

                relPathElements.erase (begin, iter);
                SetIndex (currentIndex);
            }
            return;
        }
        else
            currentIndex = nextIndex;
    }

    // cool. a full match

    if (GetIndex() != currentIndex)
    {
        relPathElements.clear();
        SetIndex (currentIndex);
    }
}
Esempio n. 4
0
void printImage(std::ostream& os, const IT& im,
                uint x0, uint y0, uint x1, uint y1)
{
    os << im.xsize() << "x" << im.ysize()
       << " (" << x1 - x0 << "x" << y1 - y0 << ")\n";
    for (uint y = y0; y < y1; ++y)
    {
        for (uint x = x0; x < x1; ++x)
        {
            if (x > x0)
            {
                os << " ";
            }
            os << im(x, y);
        }
        os << "\n";
    }
}
Esempio n. 5
0
bool check_and_move(IT it, int step){
  IT it2 = it;
  while (step--){
    if (it2 != piles.begin()){
      it2--;
    }else{
      return false;
    }
  }
  if (match(it->top(), it2->top())){
    it2->push(it->top());
    it->pop();
    if (it->empty()){
      piles.erase(it);
    }
    return true;
  }else{
    return false;
  }
}
Esempio n. 6
0
    float MapTree::getIntersectionTime(const Ray& pRay, float pMaxDist, bool pStopAtFirstHit)
    {
        double  firstDistance = inf();

        const IT end = iTree->endRayIntersection();
        IT obj = iTree->beginRayIntersection(pRay, pMaxDist);

        for ( ;obj != end; ++obj)                           // (preincrement is *much* faster than postincrement!)
        {
            /*
            Call your accurate intersection test here.  It is guaranteed
            that the ray hits the bounding box of obj.  (*obj) has type T,
            so you can call methods directly using the "->" operator.
            */
            ModelContainer *model = (ModelContainer *) (*obj);

            float t = model->getIntersectionTime(pRay, pStopAtFirstHit, pMaxDist);

            // just for visual debugging with an external debug class
            #ifdef _DEBUG_VMAPS
            if(gCount3 == gCount1)
            {
                AABox testBox;
                testBox = model->getAABoxBounds();
                gBoxArray.append(testBox);
            }
            ++gCount3;
            #endif
            if(t > 0 && t < inf())
            {
                obj.markBreakNode();
                if(firstDistance > t && pMaxDist >= t)
                {
                    firstDistance = t;
                    if(pStopAtFirstHit) break;
                }
            }
        }
        return firstDistance;
    }
Esempio n. 7
0
static void test1()
{
    IT x;
    x.add_lc(11, RBBLACK, 2, RBRED);
    x.add_rc(11, RBBLACK, 14, RBBLACK);

    x.add_lc(2, RBRED, 1, RBBLACK);
    x.add_rc(2, RBRED, 7, RBBLACK);

    x.add_lc(7, RBBLACK, 5, RBRED);
    x.add_rc(7, RBBLACK, 8, RBRED);

    x.add_rc(14, RBBLACK, 15, RBRED);

    //x.add_lc(5, RBRED, 4, RBRED);
    x.insert(4);
    dump_rbt(x);
}
Esempio n. 8
0
static void test2()
{
    IT x;
    x.insert(1);
    x.insert(2);
    x.insert(11);
    x.insert(14);
    x.insert(15);
    x.insert(7);
    x.insert(5);
    x.insert(8);
    x.insert(4);
    x.insert(4);
    dump_rbt(x);

    //Test remove
    x.remove(7);
    x.remove(8);
    x.remove(4);
    x.remove(11);
    x.remove(14);
    x.remove(2);
    x.remove(5);
    x.remove(15);
    x.remove(1);

    //Test insert
    x.insert(1);
    x.insert(2);
    x.insert(11);
    x.insert(14);
    x.insert(15);
    x.insert(7);
    x.insert(5);
    x.insert(8);
    x.insert(4);
    x.insert(4);
    dump_rbt(x);
}
Esempio n. 9
0
    RealTime SubModel::getIntersectionTime(const Ray& pRay, bool pExitAtFirst, float pMaxDist) const
    {
        TriangleBox const *firstObject;
        double  firstDistance = inf();

        #ifdef _DEBUG_VMAPS
        int debugCount =0;
        #endif
        Ray relativeRay = Ray::fromOriginAndDirection(pRay.origin - getBasePosition(), pRay.direction);

        const IT end = endRayIntersection();
        IT obj = beginRayIntersection(relativeRay,pMaxDist,false);

        Triangle testT;
        for ( ;obj != end; ++obj)                           // (preincrement is *much* faster than postincrement!)
        {
            /*
            Call your accurate intersection test here.  It is guaranteed
            that the ray hits the bounding box of obj.  (*obj) has type T,
            so you can call methods directly using the "->" operator.
            */
            const TriangleBox *tri = &(*obj);

            testT = Triangle(tri->vertex(0).getVector3(),tri->vertex(1).getVector3(),tri->vertex(2).getVector3());
            double t = testIntersectionWithTriangle(obj,testT, relativeRay);
            #ifdef _DEBUG_VMAPS
            if(debugCount == 5)
            {
                firstObject = tri;
                firstDistance = 1;
            }
            ++debugCount;
            #endif
            if(t != inf())
            {
                /*
                Tell the iterator that we've found at least one
                intersection.  It will finish looking at all
                objects in this node and then terminate.
                */
                obj.markBreakNode();
                if(firstDistance > t && pMaxDist >= t)
                {
                    firstDistance = t;
                    firstObject   = tri;
                    if(pExitAtFirst) break;
                }
            }
            else
            {
                // This might the wrong side of the triangle... Turn it and test again
                testT = Triangle(tri->vertex(2).getVector3(),tri->vertex(1).getVector3(),tri->vertex(0).getVector3());
                t = testIntersectionWithTriangle(obj, testT,relativeRay);
                if(t != inf())
                {
                    obj.markBreakNode();
                    if(firstDistance > t && pMaxDist >= t)
                    {
                        firstDistance = t;
                        firstObject   = tri;
                        if(pExitAtFirst) break;
                    }
                }
            }
        }
        #ifdef _DEBUG_VMAPS
        if(firstDistance < inf())
        {
            myfound = true;
            p1 = firstObject->vertex(0).getVector3()+ getBasePosition();
            p2 = firstObject->vertex(1).getVector3()+ getBasePosition();
            p3 = firstObject->vertex(2).getVector3()+ getBasePosition();
            p4 = relativeRay.origin + getBasePosition();
            p5 =  relativeRay.intersection(testT.plane()) + getBasePosition();
            float dist1 = (p5-p4).magnitude();
            double dist2 = relativeRay.intersectionTime(testT);
            float dist3 = relativeRay.direction.magnitude();
            double dist4 = relativeRay.intersectionTime(testT);
        }
        #endif

        return(firstDistance);
    }