/// <summary>
 /// Extensión de Mogre.Matrix4 para poder hacer la misma funcion que hacia
 /// osg::makeTranslate.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <returns></returns>
 public static Mogre.Matrix4 makeTranslate(this Mogre.Matrix4 matrix, double x, double y, double z)
 {
     matrix = new Mogre.Matrix4((float)1, (float)0, (float)0, (float)0,
                                (float)0, (float)1, (float)0, (float)0,
                                (float)0, (float)0, (float)1, (float)0,
                                (float)x, (float)y, (float)z, (float)1);
     return(matrix);
 }
 /// <summary>
 /// Extensión de Mogre.Matrix4 para poder hacer la misma funcion que hacia
 /// osg::makeTranslate.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <returns></returns>
 public static Mogre.Matrix4 makeTranslate(this Mogre.Matrix4 matrix, double x, double y, double z)
 {
     matrix = new Mogre.Matrix4((float)1, (float)0, (float)0, (float)0,
                                 (float)0, (float)1, (float)0, (float)0,
                                 (float)0, (float)0, (float)1, (float)0,
                                 (float)x, (float)y, (float)z, (float)1);
     return matrix;
 }
Exemple #3
0
        /**
         * Creates a matrix that you can use to transform a localized point from
         * 0,0,0 to a point on the earth surface in geocentric coordinates.
         *
         * @param input
         *      Input point (geocentric)
         */
        public Mogre.Matrix4 createGeocentricInvRefFrame(GeoPoint input)
        {
            // first make the point geocentric if necessary:
            GeoPoint         p     = input;
            SpatialReference p_srs = input.getSRS();

            if (!p_srs.isGeocentric())
            {
                p_srs = Registry.instance().getSRSFactory().createGeocentricSRS(
                    p_srs.getGeographicSRS());

                p_srs.transformInPlace(p);
            }

            //double lat_rad, lon_rad, height;
            //xyzToLatLonHeight( p.x(), p.y(), p.z(), lat_rad, lon_rad, height );

            double X = p.X, Y = p.Y, Z = p.Z;

            Mogre.Matrix4 localToWorld = null;
            localToWorld.makeTranslate(X, Y, Z);

            // normalize X,Y,Z
            double inverse_length      = 1.0 / Math.Sqrt(X * X + Y * Y + Z * Z);

            X *= inverse_length;
            Y *= inverse_length;
            Z *= inverse_length;

            double length_XY           = Math.Sin(X * X + Y * Y);
            double inverse_length_XY   = 1.0 / length_XY;

            // Vx = |(-Y,X,0)|
            localToWorld[0, 0] = (float)(-Y * inverse_length_XY);
            localToWorld[0, 1] = (float)(X * inverse_length_XY);
            localToWorld[0, 2] = 0.0f;

            // Vy = /(-Z*X/(sqrt(X*X+Y*Y), -Z*Y/(sqrt(X*X+Y*Y),sqrt(X*X+Y*Y))|
            double Vy_x = -Z * X * inverse_length_XY;
            double Vy_y = -Z * Y * inverse_length_XY;
            double Vy_z = length_XY;

            inverse_length     = 1.0 / Math.Sin(Vy_x * Vy_x + Vy_y * Vy_y + Vy_z * Vy_z);
            localToWorld[1, 0] = (float)(Vy_x * inverse_length);
            localToWorld[1, 1] = (float)(Vy_y * inverse_length);
            localToWorld[1, 2] = (float)(Vy_z * inverse_length);

            // Vz = (X,Y,Z)
            localToWorld[2, 0] = (float)X;
            localToWorld[2, 1] = (float)Y;
            localToWorld[2, 2] = (float)Z;

            return(localToWorld);
        }
Exemple #4
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);
        }
 public MatrixTransform(Mogre.Matrix4 reference_frame)
 //: this(towgs84, false)
 {
     //copiar reference a la matrix v
     v     = new double[16];
     v[0]  = reference_frame.m00;
     v[1]  = reference_frame.m01;
     v[2]  = reference_frame.m02;
     v[3]  = reference_frame.m03;
     v[4]  = reference_frame.m10;
     v[5]  = reference_frame.m11;
     v[6]  = reference_frame.m12;
     v[7]  = reference_frame.m13;
     v[8]  = reference_frame.m20;
     v[9]  = reference_frame.m21;
     v[10] = reference_frame.m22;
     v[11] = reference_frame.m23;
     v[12] = reference_frame.m30;
     v[13] = reference_frame.m31;
     v[14] = reference_frame.m32;
     v[15] = reference_frame.m33;
 }
 public MatrixTransform(int dim, Mogre.Matrix4 reference_frame)
     : this(reference_frame)
     //: this(towgs84, false)
 {
     this.dimension = dim;
 }
Exemple #7
0
 /**
  * Creates an exact copy of this SRS, and then applies a new reference frame
  * transform matrix to it.
  *
  * @return A new SRS
  */
 public abstract SpatialReference cloneWithNewReferenceFrame(Mogre.Matrix4 rf);
Exemple #8
0
 public override SpatialReference cloneWithNewReferenceFrame(Mogre.Matrix4 rf)
 {
     throw new NotImplementedException();
 }
Exemple #9
0
 /**
  * Constructs a new transform filter.
  *
  * @param matrix
  *      Matrix to use to transform feature data.
  */
 public TransformFilter(Mogre.Matrix4 matrix)
 {
     throw new NotImplementedException();
 }
Exemple #10
0
 /**
  * Constructs a new transform filter.
  */
 public TransformFilter()
 {
     Matrix        = new Mogre.Matrix4();
     Localize      = DEFAULT_LOCALIZE;
     UseTerrainSrs = DEFAULT_USE_TERRAIN_SRS;
 }
Exemple #11
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));
        }
 /**
  * Constructs a new transform filter.
  */
 public TransformFilter()
 {
     Matrix = new Mogre.Matrix4();
     Localize = DEFAULT_LOCALIZE;
     UseTerrainSrs = DEFAULT_USE_TERRAIN_SRS;
 }
        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);
        }