v8::Handle<v8::Value> JSFilterContext::ToLocalCallback(const v8::Arguments& args) { FilterContext* context = V8Util::UnwrapObject<FilterContext>(args.Holder()); if (context && args.Length() == 1 && args[0]->IsObject()) { v8::Local<v8::Object> obj( v8::Object::Cast(*args[0]) ); /*if (V8Util::CheckObjectType(obj, JSGeometry::GetObjectType())) // Geometry { osgEarth::Symbology::Geometry* geometry = V8Util::UnwrapObject<osgEarth::Symbology::Geometry>(obj); return }*/ if (V8Util::CheckObjectType(obj, JSVec3d::GetObjectType())) // Vec3d { osg::Vec3d* vec = V8Util::UnwrapObject<osg::Vec3d>(obj); osg::Vec3d* local = new osg::Vec3d(context->toLocal(*vec)); return JSVec3d::WrapVec3d(local, true); } } return v8::Undefined(); }
FilterContext ClampFilter::push( FeatureList& features, const FilterContext& cx ) { const Session* session = cx.getSession(); if ( !session ) { OE_WARN << LC << "No session - session is required for elevation clamping" << std::endl; return cx; } // the map against which we'll be doing elevation clamping MapFrame mapf = session->createMapFrame( Map::ELEVATION_LAYERS ); const SpatialReference* mapSRS = mapf.getProfile()->getSRS(); const SpatialReference* featureSRS = cx.profile()->getSRS(); bool isGeocentric = session->getMapInfo().isGeocentric(); // establish an elevation query interface based on the features' SRS. ElevationQuery eq( mapf ); for( FeatureList::iterator i = features.begin(); i != features.end(); ++i ) { Feature* feature = i->get(); GeometryIterator gi( feature->getGeometry() ); while( gi.hasMore() ) { Geometry* geom = gi.next(); if ( isGeocentric ) { // convert to map coords: cx.toWorld( geom ); mapSRS->transformFromECEF( geom ); // populate the elevations: eq.getElevations( geom, mapSRS ); // convert back to geocentric: mapSRS->transformToECEF( geom ); cx.toLocal( geom ); } else { // clamps the entire array to the highest available resolution. eq.getElevations( geom, featureSRS ); } } } return cx; }
FilterContext ScatterFilter::push(FeatureList& features, const FilterContext& context ) { if ( !isSupported() ) { OE_WARN << LC << "support for this filter is not enabled" << std::endl; return context; } // seed the random number generator so the randomness is the same each time // todo: control this seeding based on the feature source name, perhaps? ::srand( _randomSeed ); for( FeatureList::iterator i = features.begin(); i != features.end(); ++i ) { Feature* f = i->get(); Geometry* geom = f->getGeometry(); if ( !geom ) continue; const SpatialReference* geomSRS = context.profile()->getSRS(); // first, undo the localization frame if there is one. context.toWorld( geom ); // convert to geodetic if necessary, and compute the approximate area in sq km if ( context.isGeocentric() ) { GeometryIterator gi( geom ); while( gi.hasMore() ) geomSRS->getGeographicSRS()->transformFromECEF( gi.next(), true ); geomSRS = geomSRS->getGeographicSRS(); } PointSet* points = new PointSet(); if ( geom->getComponentType() == Geometry::TYPE_POLYGON ) { polyScatter( geom, geomSRS, context, points ); } else if ( geom->getComponentType() == Geometry::TYPE_LINESTRING || geom->getComponentType() == Geometry::TYPE_RING ) { lineScatter( geom, geomSRS, context, points ); } else { OE_WARN << LC << "Sorry, don't know how to scatter a PointSet yet" << std::endl; } // convert back to geocentric if necessary. if ( context.isGeocentric() ) context.profile()->getSRS()->getGeographicSRS()->transformToECEF( points, true ); // re-apply the localization frame. context.toLocal( points ); // replace the source geometry with the scattered points. f->setGeometry( points ); } return context; }