Ejemplo n.º 1
0
void Octree::add(OcPoint p, void* data, int maxjump) {
    bool rOk = checkRecursion(this, p);
    if (!rOk) {
        cout << "\n Center "; center.print();
        cout << "\n Size " << size;
        cout << "\n Data size " << this->data.size();
        cout << "\n In Box: " << p.inBox(center, size) << endl;
        cout << "\n P Center "; parent->center.print();
        cout << "\n P Size " << parent->size;
        cout << "\n In Box: " << p.inBox(parent->center, parent->size) << endl;
        cout << "\n P OcPoint Octant " <<  parent->getOctant(p);
        cout << "\n P child at OcPoint Octant " <<  parent->children[ parent->getOctant(p) ];
        cout << "\n this " << this;
        return;
    }

    //cout << "\nAdd "; p.print();
    OcPoint rp = p.sub(center);

    if ( ! p.inBox(center, size) ) {
        if (parent == 0) {
            float s2 = size*0.5;
            parent = new Octree(resolution);
            //OcPoint c = center.add( OcPoint(copysign(s2,rp.x), copysign(s2,rp.y), copysign(s2,rp.z)) );
            OcPoint c = center.add( lvljumpCenter(s2, rp) );
            parent->center = c;
            float s = 2*size;
            parent->size = s;

            int o = parent->getOctant(center);
            parent->children[o] = this;
        }
        parent->add(p, data);
        return;
    }

    if (size > resolution && maxjump != 0) {
        int o = getOctant(p);
        if (children[o] == 0) {
            float s2 = size*0.25;
            children[o] = new Octree(resolution);
            float s = size*0.5;
            children[o]->size = s;
            //OcPoint c = center.add( OcPoint(copysign(s2,rp.x), copysign(s2,rp.y), copysign(s2,rp.z)) );
            OcPoint c = center.add( lvljumpCenter(s2, rp) );

            children[o]->center = c;
            children[o]->parent = this;
        }
        //OcPoint c = children[o]->center;
        children[o]->add(p, data, maxjump-1);
        return;
    }

    checkRecursion(0,p);
    this->data.push_back(data);
}
Ejemplo n.º 2
0
/**
 * Checks recursively, if the given block is allowed to contain
 * references to the potential child block.
 *
 * \return true if a recusrion has been found.
 */
bool RMemoryStorage::checkRecursion(
    RBlock::Id blockId, RBlock::Id potentialChildBlockId) {

    if (blockId==potentialChildBlockId) {
        return true;
    }

    // iterate through all entities inside potential child block and check
    // if anything refers back to the given block:
    QSet<REntity::Id> ids = queryBlockEntities(potentialChildBlockId);
    QSet<REntity::Id>::iterator it;
    for (it = ids.begin(); it != ids.end(); ++it) {
        QSharedPointer<REntity> e = queryEntityDirect(*it);
        QSharedPointer<RBlockReferenceEntity> blockRef = e.dynamicCast<
                RBlockReferenceEntity> ();
        if (blockRef.isNull()) {
            continue;
        }

        if (blockRef->getReferencedBlockId() == blockId) {
            return true;
        }
        if (checkRecursion(blockId, blockRef->getReferencedBlockId())) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 3
0
static void
initContext(ProfilerObject *pObj, ProfilerContext *self, ProfilerEntry *entry)
{
    long subcallRecursionLevel = 0;
    self->ctxEntry = entry;
    self->subt = self->paused = 0;
    self->previous = CURRENT_CONTEXT(pObj);
    CURRENT_CONTEXT(pObj) = self;
    ++entry->recursionLevel;
    if ((pObj->flags & POF_SUBCALLS) && self->previous) {
        /* find or create an entry for me in my caller's entry */
        ProfilerEntry *caller = self->previous->ctxEntry;
        ProfilerSubEntry *subentry = getSubEntry(pObj, caller, entry);
        if (subentry == NULL)
            subentry = newSubEntry(pObj, caller, entry);
        if (subentry)
            subcallRecursionLevel = ++subentry->recursionLevel;
    }
    checkRecursion(self, pObj->nProfilerStacks, entry->recursionLevel,
                   subcallRecursionLevel);
    self->t0 = pObj->currentTime;
}