Beispiel #1
0
 protected void applyFragmentName(Fragment frag, Feature feature, FilterEnv env)
 {
     if (getFeatureNameScript() != null)
     {
         ScriptResult r = env.getScriptEngine().run(getFeatureNameScript(), feature, env);
         if (r.isValid())
         {
             frag.setName(r.asString());
         }
         else
         {
             env.getReport().error(r.asString());
         }
     }
 }
Beispiel #2
0
        public override FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            if (transform != null && !transform.Identity())
            {
                foreach (GeoShape shape in input.getShapes())
                {
                    XformVisitor visitor = new XformVisitor();
                    visitor.trans = transform;
                    shape.accept(visitor);
                }
            }

            output.Add(input);
            return(output);

#if TODO
            // resolve the xlate shortcut
            Matrix working_matrix = xform_matrix;

            // TODO: this can go into process(FeatureList) instead of running for every feature..
            if (getTranslateScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getTranslateScript(), input, env);
                if (r.isValid())
                {
                    working_matrix = Matrix.translate(r.asVec3());
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            if (working_srs != null || (working_matrix != null && !working_matrix.IsIdentity))
            {
                foreach (GeoShape shape in input.getShapes())
                {
                    if (working_matrix != null && !working_matrix.IsIdentity)
                    {
                        XformVisitor visitor;
                        visitor.mat = working_matrix;
                        shape.accept(visitor);
                    }

                    if (working_srs != null && !working_srs.equivalentTo(env.getInputSRS()))
                    {
                        working_srs.transformInPlace(shape);
                    }
                }
            }

            output.Add(input);
            return(output);
#endif
            throw new NotImplementedException();
        }
Beispiel #3
0
        override public FeatureList process(Feature input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            //resolve the xlate shortcut
            Mogre.Matrix4 workingMatrix = Matrix;

            //TODO: this can go into process (FeatureList) instead of running for every feature..
            if (TranslateScript != null)
            {
                ScriptResult r = env.getScriptEngine().run(TranslateScript, input, env);
                if (r.isValid())
                {
                    workingMatrix.MakeTrans(new Mogre.Vector3((float)r.asVec3().x, (float)r.asVec3().y, (float)r.asVec3().z));
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }
            if (workingSrs != null || (workingMatrix != null && workingMatrix != Mogre.Matrix4.IDENTITY))
            {
                //TODO foreach (Geometry shape in input.getGeometry())
                //{
                //    if (workingMatrix != null && !workingMatrix.Equals(Mogre.Matrix4.IDENTITY))
                //    {

                //        XformVisitor visitor = new XformVisitor();
                //        visitor.mat = workingMatrix;
                //        shape.accept(visitor);
                //    }
                //    if (workingSrs != null && !(workingSrs.equivalentTo(env.getInputSRS())))
                //    {
                //        workingSrs.transformInPlace(shape);
                //    }
                //}
                if (workingSrs != null && !(workingSrs.equivalentTo(env.getInputSRS())))
                {
                    Geometry temp = GeometryTransform.TransformGeometry(input.getGeometry(), ((SharpMapSpatialReference)workingSrs).MathTransform);
                    input.setGeometry(temp);
                    //workingSrs.transformInPlace(input.getGeometry());
                }
            }
            output.Add(input);
            return(output);
        }
Beispiel #4
0
        protected virtual Vector4D getColorForFeature(Feature input, FilterEnv env)
        {
            Vector4D result = overall_color;

            if (is_batch)
            {
                result = batch_feature_color;
            }
            else if (getColorScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getColorScript(), input, env);
                if (r.isValid())
                {
                    result = r.asVec4();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            return(result);
        }
Beispiel #5
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 #6
0
        // FragmentFilter overrides
        public override FragmentList process(FeatureList input, FilterEnv env)
        {
            FragmentList output = new FragmentList();

            //cuidado con las entidades dentro del for

            int     i = 0;
            Vector3 scale;
            Vector3 distanceScale;
            Vector3 mScale = new Vector3(1, 1, 1);
            float   lWidth = 1;

            if (Scale != null)
            {
                scale = Registry.instance().GetEngine("Python").run(Scale).asVec3();
            }
            else
            {
                scale = new Vector3(1, 1, 1);
            }

            if (CoordScale != null)
            {
                distanceScale = Registry.instance().GetEngine("Python").run(CoordScale).asVec3();
            }
            else
            {
                distanceScale = new Vector3(1, 1, 1);
            }
            if (LineWidth != null)
            {
                lWidth = Registry.instance().GetEngine("Python").run(LineWidth).asFloat();
            }
            if (MaterialScale != null)
            {
                mScale = Registry.instance().GetEngine("Python").run(MaterialScale).asVec3();
            }

            SceneNode nodeIni = point3d(env.getName(), i, 0, 0, 0, null, env.getSceneMgr());

#if ESCALA_NODO_INICIAL
            if (Scale != null)
            {
                nodeIni.SetScale(Registry.instance().GetEngine("Python").run(Scale).asVec3());
            }
            if (coordScale != null)
            {
                Vector3 vec3 = Registry.instance().GetEngine("Python").run(Scale).asVec3();
                nodeIni.SetPosition(nodeIni.Position.x * vec3.x, nodeIni.Position.y * vec3.y, nodeIni.Position.z * vec3.z);
#if TRACE_BUILDGEOMFILTER
                System.Console.WriteLine("(" + n.Position.x + "," + n.Position.y + ")");
#endif
            }
#endif
            Fragment fIni = new Fragment(nodeIni);
            output.Add(fIni);

            foreach (Feature feature in input)
            {
                //if type of features is Point
                if (feature.row.Geometry is SharpMap.Geometries.Point)
                {
                    SharpMap.Geometries.Point p = (SharpMap.Geometries.Point)feature.row.Geometry;

                    i++;
                    SceneNode n = point3d(env.getName(), i, (float)p.X, (float)p.Y, 0, nodeIni, env.getSceneMgr());

                    n.SetScale(scale);
                    n.SetPosition(n.Position.x * distanceScale.x, n.Position.y * distanceScale.y, n.Position.z * distanceScale.z);

                    Fragment f = new Fragment(n);
                    output.Add(f);
                }

                //if type of features is Polygon
                else if (feature.row.Geometry is SharpMap.Geometries.Polygon)
                {
                    SharpMap.Geometries.Polygon polygon = (SharpMap.Geometries.Polygon)feature.row.Geometry;

                    ManualObject polygonNode = null;

                    if (polygonNode == null)
                    {
                        polygonNode = env.getSceneMgr().CreateManualObject(env.getName() + "Node_" + i);
                        MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourPolygon",
                                                                                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        material.GetTechnique(0).GetPass(0).VertexColourTracking =
                            (int)TrackVertexColourEnum.TVC_AMBIENT;

                        //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                        MogreTessellationCallbacks callback = new MogreTessellationCallbacks(polygonNode, Color, feature);

                        if (nameMaterial != null)
                        {
                            callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                            callback.MaterialScale = mScale;
                        }

                        GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                        Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                        Glu.gluTessBeginPolygon(null);
                        Glu.gluTessBeginContour();

                        int        numVertices = polygon.ExteriorRing.NumPoints /*/10+1*/;
                        int        numValores  = 3;
                        double[][] data        = new double[numVertices][];

                        for (int j = 0; j < numVertices; j++)
                        {
                            data[j] = new double[numValores];
                        }

                        int k = 0;
                        //1 polygon = N vertices
                        foreach (SharpMap.Geometries.Point point in polygon.ExteriorRing.Vertices)
                        {
                            //if (k % 10 == 0)
                            {
                                data[k /*/10*/][0] = point.X;
                                data[k /*/10*/][1] = point.Y;
                                data[k /*/10*/][2] = 0;
                            }
                            k++;

                            //SceneNode n = point3d(env.getName()+i+k, k + 10, (float)point.X * 10.0f, (float)point.Y * 10.0f, 0, nodeIni, env.getSceneMgr());
                        }
                        for (int j = 0; j < data.GetLength(0); j++)
                        {
                            Glu.gluTessVertex(data[j], 0, new Vector3((float)(data[j][1] * distanceScale.y), (float)(data[j][2] * distanceScale.z), (float)(data[j][0] * distanceScale.x)));
                        }

                        Glu.gluTessEndContour();
                        Glu.gluTessNormal(0, 0, 1);
                        Glu.gluTessEndPolygon();

                        nodeIni.AttachObject(polygonNode);
                    }
                    i++;
                }

                //if type of features is MultiPolygon
                else if (feature.row.Geometry is SharpMap.Geometries.MultiPolygon)
                {
                    SharpMap.Geometries.MultiPolygon mp = (SharpMap.Geometries.MultiPolygon)feature.row.Geometry;

                    // 1 MultiPolygon = N polygon
                    foreach (SharpMap.Geometries.Polygon polygon in mp.Polygons)
                    {
                        ManualObject polygonNode = null;

                        if (polygonNode == null)
                        {
                            polygonNode = env.getSceneMgr().CreateManualObject(env.getName() + "Node_" + i);
                            MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourPolygon",
                                                                                    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                            material.GetTechnique(0).GetPass(0).VertexColourTracking =
                                (int)TrackVertexColourEnum.TVC_AMBIENT;


                            //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                            MogreTessellationCallbacks callback = new MogreTessellationCallbacks(polygonNode, Color, feature);

                            if (nameMaterial != null)
                            {
                                callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                                callback.MaterialScale = mScale;
                            }

                            GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                            Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                            Glu.gluTessBeginPolygon(null);
                            Glu.gluTessBeginContour();

                            int        numVertices = polygon.ExteriorRing.NumPoints;
                            int        numValores  = 3;
                            double[][] data        = new double[numVertices][];

                            for (int j = 0; j < numVertices; j++)
                            {
                                data[j] = new double[numValores];
                            }

                            int k = 0;
                            //1 polygon = N vertices
                            foreach (SharpMap.Geometries.Point point in polygon.ExteriorRing.Vertices)
                            {
                                data[k][0] = point.X;
                                data[k][1] = point.Y;
                                data[k][2] = 0;

                                k++;

                                //SceneNode n = point3d(env.getName(), i, (float)point.X, (float)point.Y, 0, nodeIni, env.getSceneMgr());
                            }
                            for (int j = 0; j < data.GetLength(0); j++)
                            {
                                Glu.gluTessVertex(data[j], 0, new Vector3(((float)data[j][1]) * distanceScale.y, ((float)data[j][2]) * distanceScale.z, ((float)data[j][0]) * distanceScale.x));
                            }

                            Glu.gluTessEndContour();
                            Glu.gluTessNormal(0, 0, 1);
                            Glu.gluTessEndPolygon();

                            nodeIni.AttachObject(polygonNode);
                        }
                        i++;
                    }
                }

                //if type of features is Line
                else if (feature.row.Geometry is SharpMap.Geometries.ILineal /*SharpMap.Geometries.LineString*/)
                {
                    System.Collections.Generic.List <SharpMap.Geometries.ILineal> lineas = new System.Collections.Generic.List <SharpMap.Geometries.ILineal>();
                    if (feature.row.Geometry is SharpMap.Geometries.MultiLineString)
                    {
                        foreach (SharpMap.Geometries.LineString l in ((SharpMap.Geometries.MultiLineString)(feature.row.Geometry)).LineStrings)
                        {
                            lineas.Add(l);
                        }
                    }
                    else
                    {
                        lineas.Add((SharpMap.Geometries.ILineal)(feature.row.Geometry));
                    }
                    foreach (SharpMap.Geometries.ILineal line in lineas)
                    {
                        ManualObject lineNode = env.getSceneMgr().CreateManualObject("line" + i);

                        //MaterialPtr material = MaterialManager.Singleton.Create(nameMaterial,
                        //ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        //material.GetTechnique(0).GetPass(0).VertexColourTracking =
                        //               (int)TrackVertexColourEnum.TVC_AMBIENT;
                        //material.GetTechnique(0).GetPass(0).SetDepthBias(100);
                        //material.GetTechnique(0).GetPass(0).LightingEnabled = false;

                        int nSeg = 5; // Number of segments on the cap or join pieces
                        BufferParameters         param           = new BufferParameters(nSeg, BufferParameters.BufferEndCapStyle.CapRound, BufferParameters.BufferJoinStyle.JoinRound, 2);
                        IGeometryFactory <Coord> geometryFactory = new GeometryFactory <Coord>(new CoordSeqFac(new CoordFac(PrecisionModelType.DoubleFloating)));
                        //IWktGeometryReader<Coord> reader = geometryFactory.WktReader;
                        //string txt = feature.row.Geometry.AsText();
                        ILineString         line1       = (ILineString)GeometryConverter.ToNTSGeometry((SharpMap.Geometries.LineString)line, geometryFactory); // (ILineString<Coord>)reader.Read(txt);
                        IGeometry           coordBuffer = line1.Buffer(lWidth, param);
                        ICoordinateSequence coords      = coordBuffer.Coordinates;
                        //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                        MogreTessellationCallbacks callback = new MogreTessellationCallbacks(lineNode, Color, feature);
                        if (nameMaterial != null)
                        {
                            callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                            callback.MaterialScale = mScale;
                        }

                        GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                        Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                        Glu.gluTessBeginPolygon(null);
                        Glu.gluTessBeginContour();
                        foreach (Coord coord in coords)
                        {
                            double[] data = new double[] { coord.X *distanceScale.x, coord.Y *distanceScale.y, (double.IsNaN(coord.Z) ? 0 : coord.Z) * distanceScale.z };

                            Glu.gluTessVertex(data, 0, new Vector3((float)data[1], (float)data[2], (float)data[0]));
                        }
                        Glu.gluTessEndContour();
                        Glu.gluTessNormal(0, 0, 1);
                        Glu.gluTessEndPolygon();
                        i++;
                        nodeIni.AttachObject(lineNode);
                    }
                    if ((feature.row.Geometry is SharpMap.Geometries.Polygon) | (feature.row.Geometry is SharpMap.Geometries.MultiPolygon))
                    {
                        Fragment f = new Fragment(nodeIni);
                        output.Add(f);
                    }
                }
            }
            i = 0;//breakpoint

            /*foreach (Fragment fragment in output)
             * {
             *  fragment.Node.Scale(0,0,0);
             * }*/

#if TODO
            // if features are arriving in batch, resolve the color here.
            // otherwise we will resolve it later in process(feature,env).
            is_batch            = input.Count > 1;
            batch_feature_color = overall_color;
            if (is_batch && getColorScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getColorScript(), env);
                if (r.isValid())
                {
                    batch_feature_color = r.asVec4();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            return(base.process(input, env));
#endif
            //throw new NotImplementedException();

            if (successor != null)
            {
                if (successor is FeatureFilter)
                {
                    FeatureFilter filter = (FeatureFilter)successor;
                    FeatureList   l      = filter.process(input, env);
                    //FeatureList l = successor.process(input, env);
                }
                else if (successor is FragmentFilter)
                {
                    FragmentFilter filter = (FragmentFilter)successor;
                    FragmentList   l      = filter.process(output, env);
                }
            }

            return(output);
        }
        protected virtual FragmentList process(Feature input, FilterEnv env)
        {
            FragmentList output;

            // the text string:
            string text;

            if (getTextScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getTextScript(), input, env);
                if (r.isValid())
                {
                    text = r.asString();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            // resolve the size:
            double font_size = 16.0;

            if (getFontSizeScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getFontSizeScript(), input, env);
                if (r.isValid())
                {
                    font_size = r.asDouble(font_size);
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            // the text color:
            Vector4D color = getColorForFeature(input, env);

            // calculate the 3D centroid of the feature:
            // TODO: move this to the geoshapelist class
            Vector3D point = new Vector3D(input.getExtent().getCentroid());
            ZCalc    zc;

            input.getShapes().accept(zc);
            point.z() = zc.z_count > 0 ? zc.z_sum / (double)zc.z_count : 0.0;

            // build the drawable:
            osgText.Text t = new osgText.Text();
            t.setAutoRotateToScreen(true);
            t.setCharacterSizeMode(osgText.Text.SCREEN_COORDS);
            t.setAlignment(osgText.Text.CENTER_CENTER);
            t.setText(text.c_str());
            t.setColor(color);
            t.setCharacterSize((float)font_size);
            t.setPosition(point);
            t.setBackdropType(osgText.Text.OUTLINE);
            t.setBackdropColor(osg.Vec4(0, 0, 0, 1));

#if PENDING
            // testing the flat-label approach here:
            osg.Matrix cell2map       = env.getInputSRS().getInverseReferenceFrame();
            osg.Vec3d  feature_center = point * cell2map;
            feature_center.normalize();
            osg.Vec3d cell_center = osg.Vec3d(0, 0, 1) * cell2map;
            cell_center.normalize();
            osg.Quat q;
            q.makeRotate(cell_center, feature_center);
            t.setRotation(q);
            t.setAutoRotateToScreen(false);
            // end of flat label approach
#endif

            if (font.valid())
            {
                t.setFont(font.get());
            }

            if (getDisableDepthTest())
            {
                t.getOrCreateStateSet().setAttribute(new osg.Depth(osg.Depth.ALWAYS, 0, 1, false), osg.StateAttribute.ON);
            }

            output.Add(new Fragment(t));

            return(output);
        }
Beispiel #8
0
        override public FeatureList process(FeatureList input, FilterEnv env)
        {
            //first time through, establish a working SRS for output data.
            if (workingSrs == null)
            {
                //first try to use the terrain SRS if so directed:
                SpatialReference newOutSrs = UseTerrainSrs ? env.getTerrainSRS() : null;
                if (newOutSrs == null)
                {
                    //failing that, see if we have an SRS in a resource:
                    if (Srs == null && SrsScript != null)
                    {
                        //Console.WriteLine("Borrame" + SrsScript.getCode());
                        Srs = env.getSession().Resources.getSRS(SrsScript.getCode());
#if TODO_PH
                        ScriptResult r = env.getScriptEngine().run(SrsScript, env);
                        if (r.isValid())
                        {
                            Srs = (env.getSession().Resources.getSRS(r.asString()));

                            throw new NotImplementedException();
                        }
                        else
                        {
                            env.getReport().error(r.asString());
                        }
#endif
                    }
                    newOutSrs = Srs;
                }
                //set the "working" SRS that will be used for all features passing though this filter:
                workingSrs = newOutSrs != null ? newOutSrs : env.getInputSRS();

                //LOCALIZE points arround a local origin (the working extent's centroid)
                if (workingSrs != null && Localize)
                {
                    if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179)
                    {
                        //NOP - no localization for big geog extent ... needs more thought perhaps
                    }
                    else
                    {
                        GeoPoint centroid0 = newOutSrs == null?
                                             newOutSrs.transform(env.getCellExtent()).getCentroid()
                                                 : env.getCellExtent().getCentroid();

                        //we do want the localizer point on the surface if possible:
                        GeoPoint centroid = ClampToTerrain(centroid0, env);
                        if (centroid == null)
                        {
                            centroid = centroid0;
                        }

                        Mogre.Matrix4 localizer = new Mogre.Matrix4();
                        //For geocentric datasets, we need a special localizer matrix:
                        if (workingSrs.isGeocentric())
                        {
                            localizer = workingSrs.getEllipsoid().createGeocentricInvRefFrame(centroid);
                            localizer = localizer.Inverse();
                        }
                        //For projected datasets, just a simple translation
                        else
                        {
                            localizer.SetTrans(new Mogre.Vector3((float)centroid.X, (float)centroid.Y, (float)0.0));
                        }
                        workingSrs = workingSrs.cloneWithNewReferenceFrame(localizer);
                    }
                }
            }
            //we have to assing the output SRS on each pass
            if (workingSrs != null)
            {
                env.setOutputSRS(workingSrs);
            }
            return(base.process(input, env));
        }
Beispiel #9
0
        protected virtual AttributedNodeList process(AttributedNodeList input, FilterEnv env)
        {
            Node result;

            if (input.Count > 1)
            {
                result = new osg.Group();
                for (AttributedNodeList.iterator i = input.begin(); i != input.end(); i++)
                {
                    osg.Node node = i.get().getNode();
                    if (node != null)
                    {
                        if (getEmbedAttributes())
                        {
                            embedAttributes(node, i.get().getAttributes());
                        }

                        result.asGroup().addChild(node);
                    }
                }
            }
            else if (input.Count == 1)
            {
                result = input[0].getNode();

                if (getEmbedAttributes())
                {
                    embedAttributes(result.get(), input[0].getAttributes());
                }
            }
            else
            {
                return(new AttributedNodeList());
            }

            // if there are no drawables or external refs, toss it.
            if (!GeomUtils.hasDrawables(result.get()))
            {
                return(AttributedNodeList());
            }

            // NEXT create a XFORM if there's a localization matrix in the SRS. This will
            // prevent jittering due to loss of precision.
            SpatialReference input_srs = env.getInputSRS();

            if (env.getExtent().getArea() > 0 && !input_srs.getReferenceFrame().isIdentity())
            {
                Vector3D            centroid     = new Vector3D(0, 0, 0);
                osg.Matrixd         irf          = input_srs.getInverseReferenceFrame();
                osg.Vec3d           centroid_abs = centroid * irf;
                osg.MatrixTransform xform        = new osg.MatrixTransform(irf);

                xform.addChild(result);
                result = xform;

                if (getApplyClusterCulling() && input_srs.isGeocentric())
                {
                    Vector3D normal = centroid_abs;
                    normal.normalize();

                    //osg.BoundingSphere bs = result.computeBound(); // force it
                    // radius = distance from centroid inside which to disable CC altogether:
                    //float radius = bs.radius();
                    //osg.Vec3d control_point = bs.center();

                    Vector3D control_point = centroid_abs;
                    GeoPoint env_cen       = input_srs.transform(env.getCellExtent().getCentroid());
                    GeoPoint env_sw        = input_srs.transform(env.getCellExtent().getSouthwest());
                    float    radius        = (env_cen - env_sw).length();

                    // dot product: 0 = orthogonal to normal, -1 = equal to normal
                    float deviation = -radius / input_srs.getEllipsoid().getSemiMinorAxis();

                    osg.ClusterCullingCallback ccc = new osg.ClusterCullingCallback();
                    ccc.set(control_point, normal, deviation, radius);

                    osg.Group cull_group = new osg.Group();
                    cull_group.setCullCallback(ccc);
                    cull_group.addChild(xform);
                    result = cull_group;


                    //osgGIS.notify(osg.NOTICE) << "CCC: radius = " << radius << ", deviation = " << deviation << std.endl;


                    //if ( getDrawClusterCullingNormals() == true )
                    //{
                    //    //DRAW CLUSTER-CULLING NORMALS
                    //    osg.Geode* geode = new osg.Geode();
                    //    osg.Geometry* g = new osg.Geometry();
                    //    osg.Vec3Array* v = new osg.Vec3Array(2);
                    //    (*v)[0] = control_point; (*v)[1] = control_point + (normal*radius);
                    //    g.setVertexArray( v );
                    //    osg.Vec4Array* c = new osg.Vec4Array(1);
                    //    (*c)[0] = osg.Vec4f( 0,1,0,1 );
                    //    g.setColorArray( c );
                    //    g.setColorBinding( osg.Geometry.BIND_OVERALL );
                    //    g.addPrimitiveSet( new osg.DrawArrays( osg.PrimitiveSet.LINES, 0, 2 ) );
                    //    geode.addDrawable( g );
                    //    cull_group.addChild( geode );
                    //}
                }
            }

            if (getCullBackfaces())
            {
                result.getOrCreateStateSet().setAttributeAndModes(new osg.CullFace(), osg.StateAttribute.ON);
            }

            if (getDisableLighting())
            {
                result.getOrCreateStateSet().setMode(GL_LIGHTING, osg.StateAttribute.OFF);
            }

            if (getLineWidth() > 0.0f)
            {
                result.getOrCreateStateSet().setAttribute(new osg.LineWidth(line_width), osg.StateAttribute.ON);
            }

            if (getPointSize() > 0.0f)
            {
                osg.Point point = new osg.Point();
                point.setSize(point_size);
                result.getOrCreateStateSet().setAttribute(point, osg.StateAttribute.ON);
            }

            if (getAlphaBlending())
            {
                osg.BlendFunc blend_func = new osg.BlendFunc();
                //blend_func.setFunction( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
                result.getOrCreateStateSet().setAttributeAndModes(blend_func, osg.StateAttribute.ON);
                result.getOrCreateStateSet().setRenderingHint(osg.StateSet.TRANSPARENT_BIN);
            }

            if (getRasterOverlayScript())
            {
                ScriptResult r = env.getScriptEngine().run(getRasterOverlayScript(), env);
                if (r.isValid())
                {
                    RasterResource *raster = env.getSession().getResources().getRaster(r.asString());
                    if (raster)
                    {
                        osg.Image *image = NULL;

                        std.stringstream builder;

                        string cell_id = env.getProperties().getValue("compiler.cell_id", "");
                        if (cell_id.length() > 0)
                        {
                            builder << "r" << cell_id << ".jpg";
                        }
                        else
                        {
                            double x = env.getExtent().getCentroid().x();
                            double y = env.getExtent().getCentroid().y();
                            builder << std.setprecision(10) << "r" << x << "x" << y << ".jpg";
                        }

                        if (raster.applyToStateSet(result.getOrCreateStateSet(), env.getExtent(), getRasterOverlayMaxSize(), &image))
                        {
                            // Add this as a skin resource so the compiler can properly localize and deploy it.
                            image.setFileName(builder.str());

                            env.getResourceCache().addSkin(result.getOrCreateStateSet());
                        }
                    }
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            if (getOptimize())
            {
                //osgGIS.notice() << "[BuildNodes] Optimizing..." << std.endl;

                osgUtil.Optimizer opt;
                int opt_mask =
                    osgUtil.Optimizer.DEFAULT_OPTIMIZATIONS |
                    osgUtil.Optimizer.MERGE_GEODES |
                    osgUtil.Optimizer.TRISTRIP_GEOMETRY |
                    osgUtil.Optimizer.SPATIALIZE_GROUPS;

                // disable texture atlases, since they mess with our shared skin resources and
                // don't work correctly during multi-threaded building
                opt_mask &= ~osgUtil.Optimizer.TEXTURE_ATLAS_BUILDER;

                // I've seen this crash the app when dealing with certain ProxyNodes.
                // TODO: investigate this later.
                opt_mask &= ~osgUtil.Optimizer.REMOVE_REDUNDANT_NODES;

                // integrate the optimizer hints:
                opt_mask |= env.getOptimizerHints().getIncludedOptions();
                opt_mask &= ~(env.getOptimizerHints().getExcludedOptions());

                opt.optimize(result.get(), opt_mask);

                GeometryCleaner cleaner;
                cleaner.clean(result.get());
            }

            AttributedNodeList output;

            output.push_back(new AttributedNode(result.get()));

            return(output);
        }