Exemplo n.º 1
0
char HAdaptiveField::load(AdaptiveField * fld)
{
    int nc = 1;
    readIntAttr(".ncells", &nc);

    float originSpan[4];
    readFloatAttr(".origin_span", originSpan);

    int ml = 7;
    readIntAttr(".max_level", &ml);

    fld->setBounding(originSpan);
    fld->setMaxLevel(ml);

    BaseBuffer dhash;
    dhash.create(nc * 16);
    readCharData(".cellHash", nc*16, dhash.data());

    IOCellHash * src = (IOCellHash *)dhash.data();
    std::cout<<"\n hadaptive field add n cells "<<nc;
    unsigned i = 0;
    for(; i<nc; i++) {
        fld->addCell(src->code, src->level, src->visited, src->index);
        src++;
    }
    std::cout<<"\n hadaptive field done load";
    return HField::load(fld);
}
Exemplo n.º 2
0
char HAdaptiveField::save(AdaptiveField * fld)
{
    int nc = fld->numCells();
    std::cout<<"\n hadaptivefield save n cells "<<nc;

    if(!hasNamedAttr(".ncells"))
        addIntAttr(".ncells");

    writeIntAttr(".ncells", &nc);

    if(!hasNamedAttr(".origin_span"))
        addFloatAttr(".origin_span", 4);

    float originSpan[4];
    originSpan[0] = fld->origin().x;
    originSpan[1] = fld->origin().y;
    originSpan[2] = fld->origin().z;
    originSpan[3] = fld->span();
    writeFloatAttr(".origin_span", originSpan);

    if(!hasNamedAttr(".max_level"))
        addIntAttr(".max_level");

    int ml = fld->maxLevel();
    writeIntAttr(".max_level", &ml);

    BaseBuffer dhash;
    dhash.create(nc * 16);
    IOCellHash * dst = (IOCellHash *)dhash.data();

    sdb::CellHash * c = fld->cells();
    c->begin();
    while(!c->end()) {
        dst->code = c->key();
        dst->level = c->value()->level;
        dst->visited = c->value()->visited;
        dst->index = c->value()->index;
        dst++;
        c->next();
    }

    if(!hasNamedData(".cellHash"))
        addCharData(".cellHash", nc*16);

    writeCharData(".cellHash", nc*16, dhash.data());

    return HField::save(fld);
}