Beispiel #1
0
 protected void generateNormals(osg.Geometry geom)
 {
     if (geom != null)
     {
         osgUtil.SmoothingVisitor smoother;
         smoother.smooth(out geom);
     }
 }
Beispiel #2
0
        protected void applyOverlayTexturing(osg.Geometry geom, Feature input, FilterEnv env)
        {
            GeoExtent tex_extent;

            if (getRasterOverlayScript() != null)
            {
                // if there's a raster script for this filter, we're applying textures per-feature:
                tex_extent = new GeoExtent(
                    input.getExtent().getSouthwest().getAbsolute(),
                    input.getExtent().getNortheast().getAbsolute());
            }
            else
            {
                // otherwise prepare the geometry for an overlay texture covering the entire working extent:
                tex_extent = env.getExtent();
            }

            float width  = (float)tex_extent.getWidth();
            float height = (float)tex_extent.getHeight();

            // now visit the verts and calculate texture coordinates for each one.
            osg.Vec3Array verts = (osg.Vec3Array)(geom.getVertexArray());
            if (verts != null)
            {
                // if we are dealing with geocentric data, we will need to xform back to a real
                // projection in order to determine texture coords:
                GeoExtent tex_extent_geo;
                if (env.getInputSRS().isGeocentric())
                {
                    tex_extent_geo = new GeoExtent(
                        tex_extent.getSRS().getGeographicSRS().transform(tex_extent.getSouthwest()),
                        tex_extent.getSRS().getGeographicSRS().transform(tex_extent.getNortheast()));
                }

                osg.Vec2Array texcoords = new osg.Vec2Array(verts.size());
                for (int j = 0; j < verts.size(); j++)
                {
                    // xform back to raw SRS w.o. ref frame:
                    GeoPoint vert = new GeoPoint(verts[j], env.getInputSRS());
                    GeoPoint vert_map = vert.getAbsolute();
                    float    tu, tv;
                    if (env.getInputSRS().isGeocentric())
                    {
                        tex_extent_geo.getSRS().transformInPlace(vert_map);
                        tu = (vert_map.X - tex_extent_geo.getXMin()) / width;
                        tv = (vert_map.Y - tex_extent_geo.getYMin()) / height;
                    }
                    else
                    {
                        tu = (vert_map.X - tex_extent.getXMin()) / width;
                        tv = (vert_map.Y - tex_extent.getYMin()) / height;
                    }
                    (*texcoords)[j].set(tu, tv);
                }
                geom.setTexCoordArray(0, texcoords);
            }

            // if we are applying the raster per-feature, do so now.
            // TODO: deprecate? will we ever use this versus the BuildNodesFilter overlay? maybe
            if (getRasterOverlayScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getRasterOverlayScript(), input, env);
                if (r.isValid())
                {
                    RasterResource raster = env.getSession().getResources().getRaster(r.asString());
                    if (raster != null)
                    {
                        Image            image = null;
                        std.stringstream builder;
                        builder << "rtex_" << input.getOID() << ".jpg"; //TODO: dds with DXT1 compression

                        osg.StateSet raster_ss = new osg.StateSet();
                        if (raster.applyToStateSet(raster_ss.get(), tex_extent, getRasterOverlayMaxSize(), out image))
                        {
                            image.setFileName(builder.str());
                            geom.setStateSet(raster_ss.get());

                            // add this as a skin resource so the compiler can properly localize and deploy it.
                            env.getResourceCache().addSkin(raster_ss.get());
                        }
                    }
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }
        }
Beispiel #3
0
        public override FragmentList process(Feature input, FilterEnv env)
        {
            FragmentList output;

            // LIMITATION: this filter assumes all feature's shapes are the same
            // shape type! TODO: sort into bins of shape type and create a separate
            // geometry for each. Then merge the geometries.
            bool needs_tessellation = false;

            Fragment frag = new Fragment();

            GeoShapeList shapes = input.getShapes();

#if TODO
            // if we're in batch mode, the color was resolved in the other process() function.
            // otherwise we still need to resolve it.
            Vector4D color = getColorForFeature(input, env);
#endif
#if TODO
            foreach (GeoShape s in shapes)
            {
                GeoShape shape = s;

                if (shape.getShapeType() == GeoShape.ShapeType.TYPE_POLYGON)
                {
                    needs_tessellation = true;
                }


                osg.Geometry geom = new osg.Geometry();

                // TODO: pre-total points and pre-allocate these arrays:
                osg.Vec3Array verts = new osg.Vec3Array();
                geom.setVertexArray(verts);
                uint vert_ptr = 0;

                // per-vertex coloring takes more memory than per-primitive-set coloring,
                // but it renders faster.
                osg.Vec4Array colors = new osg.Vec4Array();
                geom.setColorArray(colors);
                geom.setColorBinding(osg.Geometry.BIND_PER_VERTEX);

                //osg.Vec3Array* normals = new osg.Vec3Array();
                //geom.setNormalArray( normals );
                //geom.setNormalBinding( osg.Geometry.BIND_OVERALL );
                //normals.push_back( osg.Vec3( 0, 0, 1 ) );


                Mogre.PixelFormat prim_type =
                    shape.getShapeType() == GeoShape.ShapeType.TYPE_POINT ? osg.PrimitiveSet.POINTS :
                    shape.getShapeType() == GeoShape.ShapeType.TYPE_LINE ? osg.PrimitiveSet.LINE_STRIP :
                    osg.PrimitiveSet.LINE_LOOP;
#endif
#if TODO
            for (int pi = 0; pi < shape.getPartCount(); pi++)
            {
                int          part_ptr = vert_ptr;
                GeoPointList points   = shape.getPart(pi);
                for (int vi = 0; vi < points.Count; vi++)
                {
                    verts.Add(points[vi]);
                    vert_ptr++;
                    colors.Add(color);
                }
                geom.addPrimitiveSet(new osg.DrawArrays(prim_type, part_ptr, vert_ptr - part_ptr));
            }

            // tessellate all polygon geometries. Tessellating each geometry separately
            // with TESS_TYPE_GEOMETRY is much faster than doing the whole bunch together
            // using TESS_TYPE_DRAWABLE.
            if (needs_tessellation)
            {
                osgUtil.Tessellator tess;
                tess.setTessellationType(osgUtil.Tessellator.TESS_TYPE_GEOMETRY);
                tess.setWindingType(osgUtil.Tessellator.TESS_WINDING_POSITIVE);
                tess.retessellatePolygons(*geom);

                applyOverlayTexturing(geom, input, env);
            }

            generateNormals(geom);

            frag.addDrawable(geom);
        }

        frag.addAttributes(input.getAttributes());
        applyFragmentName(frag, input, env);

        output.Add(frag);

        return(output);
#endif
            throw new NotImplementedException();
        }
        public override FragmentList process(Feature input, FilterEnv env)
        {
            FragmentList output;

            // LIMITATION: this filter assumes all feature's shapes are the same
            // shape type! TODO: sort into bins of shape type and create a separate
            // geometry for each. Then merge the geometries.
            bool needs_tessellation = false;

            Fragment frag = new Fragment();

            GeoShapeList shapes = input.getShapes();
            #if TODO
            // if we're in batch mode, the color was resolved in the other process() function.
            // otherwise we still need to resolve it.
            Vector4D color = getColorForFeature(input, env);
            #endif
            #if TODO
            foreach (GeoShape s in shapes)
            {
                GeoShape shape = s;

                if (shape.getShapeType() == GeoShape.ShapeType.TYPE_POLYGON)
                {
                    needs_tessellation = true;
                }

                osg.Geometry geom = new osg.Geometry();

                // TODO: pre-total points and pre-allocate these arrays:
                osg.Vec3Array verts = new osg.Vec3Array();
                geom.setVertexArray(verts);
                uint vert_ptr = 0;

                // per-vertex coloring takes more memory than per-primitive-set coloring,
                // but it renders faster.
                osg.Vec4Array colors = new osg.Vec4Array();
                geom.setColorArray(colors);
                geom.setColorBinding(osg.Geometry.BIND_PER_VERTEX);

                //osg.Vec3Array* normals = new osg.Vec3Array();
                //geom.setNormalArray( normals );
                //geom.setNormalBinding( osg.Geometry.BIND_OVERALL );
                //normals.push_back( osg.Vec3( 0, 0, 1 ) );

                Mogre.PixelFormat prim_type =
                    shape.getShapeType() == GeoShape.ShapeType.TYPE_POINT ? osg.PrimitiveSet.POINTS :
                    shape.getShapeType() == GeoShape.ShapeType.TYPE_LINE ? osg.PrimitiveSet.LINE_STRIP :
                    osg.PrimitiveSet.LINE_LOOP;
            #endif
            #if TODO
                for (int pi = 0; pi < shape.getPartCount(); pi++)
                {
                    int part_ptr = vert_ptr;
                    GeoPointList points = shape.getPart(pi);
                    for (int vi = 0; vi < points.Count; vi++)
                    {
                        verts.Add(points[vi]);
                        vert_ptr++;
                        colors.Add(color);
                    }
                    geom.addPrimitiveSet(new osg.DrawArrays(prim_type, part_ptr, vert_ptr - part_ptr));
                }

                // tessellate all polygon geometries. Tessellating each geometry separately
                // with TESS_TYPE_GEOMETRY is much faster than doing the whole bunch together
                // using TESS_TYPE_DRAWABLE.
                if (needs_tessellation)
                {
                    osgUtil.Tessellator tess;
                    tess.setTessellationType(osgUtil.Tessellator.TESS_TYPE_GEOMETRY);
                    tess.setWindingType(osgUtil.Tessellator.TESS_WINDING_POSITIVE);
                    tess.retessellatePolygons(*geom);

                    applyOverlayTexturing(geom, input, env);
                }

                generateNormals(geom);

                frag.addDrawable(geom);
            }

            frag.addAttributes(input.getAttributes());
            applyFragmentName(frag, input, env);

            output.Add(frag);

            return output;
            #endif
            throw new NotImplementedException();
        }