⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxfentity.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                } else if (c == d) {                    vlist.push_back(a);                    vlist.push_back(b);                    vlist.push_back(c);                } else {                    qlist.push_back(a);                    qlist.push_back(b);                    qlist.push_back(c);                    qlist.push_back(d);                }                nlist.push_back(a);            }        }        if (_flag & 32) {            for (unsigned int m = 1; m < mcount; m++) {                // 0                a = _vertices[(m-1)*ncount+(ncount-1)].get()->getVertex();                // 1                b = _vertices[m*ncount+(ncount-1)].get()->getVertex();                // 3                c = _vertices[(m)*ncount].get()->getVertex();                // 2                d = _vertices[(m-1)*ncount].get()->getVertex();                if (a == b ) {                    vlist.push_back(a);                    vlist.push_back(c);                    vlist.push_back(d);                    b = c;                    c = d;                } else if (c == d) {                    vlist.push_back(a);                    vlist.push_back(b);                    vlist.push_back(c);                } else {                    qlist.push_back(a);                    qlist.push_back(b);                    qlist.push_back(c);                    qlist.push_back(d);                }                nlist.push_back(a);            }        }        // a naive attempt to determine vertex ordering        VList::iterator itr = nlist.begin();        Vec3d lastn = (*itr++);        double bad_c = 0;        double good_c = 0;        long bad=0,good=0;        for (; itr != nlist.end(); ) {            ++itr;            if ((*itr)== lastn) continue;            Vec3d diff = ((*itr)-lastn);            diff.normalize();            float dot = diff * nr;            if (dot > 0.0) {                bad_c += dot;                ++bad;            } else {                ++good;                good_c += dot;            }        }        if (bad > good) {            invert_order = true;        }        if (qlist.size())            sc->addQuads(getLayer(), _color, qlist, invert_order);        if (vlist.size())            sc->addTriangles(getLayer(), _color, vlist, invert_order);    } else if (_flag & 64) {         unsigned short _facetype = 3;        for (unsigned int i = 0; i < _indices.size(); i++) {            dxfVertex* vindice = _indices[i].get();            if (!vindice) continue;            if (vindice->getIndice4()) {                _facetype = 4;                d = _vertices[vindice->getIndice4()-1].get()->getVertex();            } else {                _facetype = 3;            }            if (vindice->getIndice3()) {                c = _vertices[vindice->getIndice3()-1].get()->getVertex();            } else {                c = vindice->getVertex(); // Vertex not indexed. Use as is            }            if (vindice->getIndice2()) {                b = _vertices[vindice->getIndice2()-1].get()->getVertex();            } else {                b = vindice->getVertex(); // Vertex not indexed. Use as is            }            if (vindice->getIndice1()) {                a = _vertices[vindice->getIndice1()-1].get()->getVertex();            } else {                a = vindice->getVertex(); // Vertex not indexed. Use as is            }            if (_facetype == 4) {                qlist.push_back(d);                qlist.push_back(c);                qlist.push_back(b);                qlist.push_back(a);            } else {                // 2005.12.13 pdr: vlist! not qlist!                vlist.push_back(c);                vlist.push_back(b);                vlist.push_back(a);            }        }        if (vlist.size())            sc->addTriangles(getLayer(), _color, vlist);        if (qlist.size())            sc->addQuads(getLayer(), _color, qlist);        // is there a flag 1 or 32 for 64?    } else {        // simple polyline?        for (short i = _vertices.size()-1; i >= 0; i--)            vlist.push_back(_vertices[i]->getVertex());        if (_flag & 1) {//            std::cout << "line loop " << _vertices.size() << std::endl;            sc->addLineLoop(getLayer(), _color, vlist);        } else {//            std::cout << "line strip " << _vertices.size() << std::endl;            sc->addLineStrip(getLayer(), _color, vlist);        }    }    sc->ocs_clear();}void dxfLWPolyline::assign(dxfFile* dxf, codeValue& cv){    string s = cv._string;    double d = cv._double;    switch (cv._groupCode) {        case 10:            _lastv.x() = d;            // x            break;        case 20:            _lastv.y() = d;            _lastv.z() = _elevation;            _vertices.push_back ( _lastv );            // y -> on shoot            break;        case 38:            _elevation = d; // what is elevation?            break;        case 70:            _flag = cv._int; // 2005.12.13 pdr: group codes [70,78] now signed int.            break;        case 90:            _vcount = cv._short;            break;        case 210:            _ocs.x() = d;            break;        case 220:            _ocs.y() = d;            break;        case 230:            _ocs.z() = d;            break;        default:            dxfBasicEntity::assign(dxf, cv);            break;    }}voiddxfLWPolyline::drawScene(scene* sc){//    if (getLayer() != "UDF2" && getLayer() != "ENGINES") return;//    if (!(_flag & 16)) return;    Matrixd m;    getOCSMatrix(_ocs, m);    sc->ocs(m);    if (_flag & 1) {//        std::cout << "lwpolyline line loop " << _vertices.size() << std::endl;        sc->addLineLoop(getLayer(), _color, _vertices);    } else {//        std::cout << "lwpolyline line strip " << _vertices.size() << std::endl;        sc->addLineStrip(getLayer(), _color, _vertices);    }    sc->ocs_clear();}voiddxfInsert::assign(dxfFile* dxf, codeValue& cv){    string s = cv._string;    if (_done || (cv._groupCode == 0 && s != "INSERT")) {        _done = true;        return;    }    if (cv._groupCode == 2 && !_block) {        _blockName = s;        _block = dxf->findBlock(s);    } else {        double d = cv._double;        switch (cv._groupCode) {            case 10:                _point.x() = d;                break;            case 20:                _point.y() = d;                break;            case 30:                _point.z() = d;                break;            case 41:                _scale.x() = d;                break;            case 42:                _scale.y() = d;                break;            case 43:                _scale.z() = d;                break;            case 50:                _rotation = d;                break;            case 210:                _ocs.x() = d;                break;            case 220:                _ocs.y() = d;                break;            case 230:                _ocs.z() = d;                break;            default:                dxfBasicEntity::assign(dxf, cv);                break;        }    }}/// hum. read the doc, then come back here. then try to figure.voiddxfInsert::drawScene(scene* sc){    // INSERTs can be nested. So pull the current matrix    // and push it back after we fill our context    // This is a snapshot in time. I will rewrite all this to be cleaner,    // but for now, it seems working fine     // (with the files I have, the results are equal to Voloview,    // and better than Deep Exploration and Lightwave).        // sanity check (useful when no block remains after all unsupported entities have been filtered out)    if (!_block)        return;    Matrixd back = sc->backMatrix();    Matrixd m;    m.makeIdentity();    sc->pushMatrix(m, true);    Vec3d trans = _block->getPosition();    sc->blockOffset(-trans);    if (_rotation) {        sc->pushMatrix(Matrixd::rotate(osg::DegreesToRadians(_rotation), 0,0,1));    }    sc->pushMatrix(Matrixd::scale(_scale.x(), _scale.y(), _scale.z()));    sc->pushMatrix(Matrixd::translate(_point.x(), _point.y(), _point.z()));    getOCSMatrix(_ocs, m);    sc->pushMatrix(m);    sc->pushMatrix(back);    EntityList& l = _block->getEntityList();    for (EntityList::iterator itr = l.begin(); itr != l.end(); ++itr) {        dxfBasicEntity* e = (*itr)->getEntity();        if (e) {            e->drawScene(sc);        }    }    sc->popMatrix(); // ocs    sc->popMatrix(); // translate    sc->popMatrix(); // scale    if (_rotation) {        sc->popMatrix(); // rotate    }    sc->popMatrix(); // identity    sc->popMatrix(); // back    sc->blockOffset(Vec3d(0,0,0));}void dxfText::assign(dxfFile* dxf, codeValue& cv){    switch (cv._groupCode) {        case 1:            _string = cv._string;            break;        case 10:            _point1.x() = cv._double;            break;        case 20:            _point1.y() = cv._double;            break;        case 30:            _point1.z() = cv._double;            break;        case 11:            _point2.x() = cv._double;            break;        case 21:            _point2.y() = cv._double;            break;        case 31:            _point2.z() = cv._double;            break;        case 40:            _height = cv._double;            break;        case 41:            _xscale = cv._double;            break;        case 50:            _rotation = cv._double;            break;        case 71:            _flags = cv._int;            break;        case 72:            _hjustify = cv._int;            break;        case 73:            _vjustify = cv._int;            break;        case 210:            _ocs.x() = cv._double;            break;        case 220:            _ocs.y() = cv._double;            break;        case 230:            _ocs.z() = cv._double;            break;        default:            dxfBasicEntity::assign(dxf, cv);            break;    }}voiddxfText::drawScene(scene* sc){    osgText::Text::AlignmentType align;    Matrixd m;    getOCSMatrix(_ocs, m);    sc->ocs(m);    ref_ptr<osgText::Text> _text = new osgText::Text;    _text->setText(_string);    _text->setCharacterSize( _height, 1.0/_xscale );    _text->setFont("arial.ttf");          Quat qr( DegreesToRadians(_rotation), Z_AXIS );        if ( _flags & 2 ) qr = Quat( PI, Y_AXIS ) * qr;    if ( _flags & 4 ) qr = Quat( PI, X_AXIS ) * qr;        _text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION);    _text->setRotation(qr);       if ( _hjustify != 0 || _vjustify !=0 ) _point1 = _point2;        switch (_vjustify) {    case 3:        switch (_hjustify) {        case 2:            align = osgText::Text::RIGHT_TOP;            break;        case 1:            align = osgText::Text::CENTER_TOP;            break;        default:            align = osgText::Text::LEFT_TOP;        }        break;    case 2:        switch (_hjustify) {        case 2:            align = osgText::Text::RIGHT_CENTER;            break;        case 1:            align = osgText::Text::CENTER_CENTER;            break;        default:            align = osgText::Text::LEFT_CENTER;        }        break;    case 1:        switch (_hjustify) {        case 2:            align = osgText::Text::RIGHT_BOTTOM;            break;        case 1:            align = osgText::Text::CENTER_BOTTOM;            break;        default:            align = osgText::Text::LEFT_BOTTOM;        }        break;    default:        switch (_hjustify) {        case 2:            align = osgText::Text::RIGHT_BOTTOM_BASE_LINE;            break;        case 1:            align = osgText::Text::CENTER_BOTTOM_BASE_LINE;            break;        default:            align = osgText::Text::LEFT_BOTTOM_BASE_LINE;        }        break;    }        _text->setAlignment(align);        sc->addText(getLayer(), _color, _point1, _text.get());    sc->ocs_clear();}// staticvoid dxfEntity::registerEntity(dxfBasicEntity* entity){    _registry[entity->name()] = entity;}// staticvoid dxfEntity::unregisterEntity(dxfBasicEntity* entity){    map<string, ref_ptr<dxfBasicEntity > >::iterator itr = _registry.find(entity->name());    if (itr != _registry.end()) {        _registry.erase(itr);    }}void dxfEntity::drawScene(scene* sc){    for (std::vector<ref_ptr<dxfBasicEntity > >::iterator itr = _entityList.begin();        itr != _entityList.end(); ++itr) {            (*itr)->drawScene(sc);    }}void dxfEntity::assign(dxfFile* dxf, codeValue& cv){    string s = cv._string;    if (cv._groupCode == 66 && !(_entity && string("TABLE") == _entity->name())) {        // The funny thing here. Group code 66 has been called 'obsoleted'        // for a POLYLINE. But not for an INSERT. Moreover, a TABLE        // can have a 66 for... an obscure bottom cell color value.         // I decided to rely on the presence of the 66 code for        // the POLYLINE. If you find a better alternative,        // contact me, or correct this code        // and post the correction to osg mailing list        _seqend = true;    } else if (_seqend && cv._groupCode == 0 && s == "SEQEND") {        _seqend = false;//        cout << "... off" << endl;    } else if (_entity) {        _entity->assign(dxf, cv);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -