void decimatePart( GeoPointList& input, double threshold, int min_points, GeoPartList& output ) { GeoPointList new_part; GeoPoint last_point; double t2 = threshold * threshold; if ( input.size() >= min_points ) { for( GeoPointList::iterator i = input.begin(); i != input.end(); i++ ) { if ( i == input.begin() )// || i == input.end()-1 ) { last_point = *i; new_part.push_back( *i ); } else { double d2 = (*i - last_point).length2(); if ( d2 > t2 ) { new_part.push_back( *i ); last_point = *i; } } } if ( new_part.size() >= min_points ) { output.push_back( new_part ); } } }
static void scrubPart( GeoPointList& part ) { while( part.size() >= 0 && part.front() == part.back() ) part.erase( part.end()-1 ); }
osg::Node* FeatureLabelLayer::createNode(const TerrainTile* tile, Feature* f) { // osg::MatrixTransform* mt = new osg::MatrixTransform; // GeoShapeList shapes = f->getShapes(); GeoPointList points = shapes[0].getPart(0); double lon,lat,h; osg::Vec3d start, end, pos; const SpatialReference* srs = getSP()->getSrs(); const SpatialReference* tile_srs = tile->getSP()->getSrs(); std::vector<osg::Vec3d> ins; ins.insert(ins.begin(), points.begin(), points.end()); if(!srs->isEquivalentTo(tile_srs)) { srs->transformPoints(tile_srs, &ins); } // lon = osg::DegreesToRadians(ins[0]._v[0]); lat = osg::DegreesToRadians(ins[0]._v[1]); h = ins[0]._v[2]; if(_on_ground) { srs->getEllipsoid()->convertLatLongHeightToXYZ(lat, lon, h+10000.0,start._v[0], start._v[1], start._v[2]); srs->getEllipsoid()->convertLatLongHeightToXYZ(lat, lon, h-10000.0,end._v[0], end._v[1], end._v[2]); tile->genIntersectPoint(start, end, pos); } else { srs->getEllipsoid()->convertLatLongHeightToXYZ(lat, lon, h+100,pos._v[0], pos._v[1], pos._v[2]); } mt->setMatrix(osg::Matrix::translate(pos)); osg::Geode* _geode= new osg::Geode; osgText::Text* text = new osgText::Text; std::string name= f->getAttribute(_key).asString(); wchar_t wtext[1024] = {0}; int charcount = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char*)(name.c_str()), name.length(), wtext, 1024); text->setFont(_font_name); text->setCharacterSize(_font_size); if (_size_mode == OBJECT_SIZE) { text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); } else { text->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); } text->setPosition(Vec3(0.0,0.0,0.0)); text->setAlignment(osgText::TextBase::LEFT_BOTTOM); text->setAxisAlignment(osgText::Text::SCREEN); text->setText(wtext); text->setName(name.c_str()); text->setColor(_color); _geode->addDrawable(text); mt->addChild(_geode); return mt; }