Esempio n. 1
0
 public virtual InMemoryInt16Terrain LoadSouth()
 {
     IsNorth   = false;
     LonFactor = 1d;
     LatP      = -Math.PI / 2;
     Open(SouthDEM);
     Singleton = this;
     return(this);
 }
Esempio n. 2
0
        // Constants

        public virtual InMemoryInt16Terrain LoadNorth()
        {
            IsNorth   = true;
            LonFactor = -1d;
            LatP      = Math.PI / 2;
            Open(NorthDEM);
            Singleton = this;
            return(this);
        }
Esempio n. 3
0
        public static math.Vector3d LineSampleToMoonME(InMemoryInt16Terrain m, int line, int sample)
        {
            var relz   = m.LineSampleToTerrainOffset(line, sample);
            var radius = InMemoryInt16Terrain.MoonRadius + relz / 1000d;

            InMemoryInt16Terrain.GetLatLon(line, sample, out double lat, out double lon);
            var z = radius * Math.Sin(lat);
            var c = radius * Math.Cos(lat);
            var x = c * Math.Cos(lon);  // TODO: Not sure about these
            var y = c * Math.Sin(lon);

            return(new math.Vector3d(x, y, z));
        }
Esempio n. 4
0
        public void WritePlyFile(InMemoryInt16Terrain manager, string path, bool?writeASCII = null, bool?writeColorVertices = null)
        {
            if (Allocated == null)
            {
                return;
            }
            var ascii = writeASCII.HasValue ? writeASCII.Value : WriteASCII;
            var color = writeColorVertices.HasValue ? writeColorVertices.Value : WriteColorVertices;

            var vertex_count = EnumerateVertices().Count();
            var face_count   = EnumerateFaces().Count();

            var file = File.Open(path, FileMode.Create);
            var sw   = new StreamWriter(file);

            using (var bw = new BinaryWriter(file))
            {
                using (var ms = new MemoryStream(500))
                    using (var msw = new StreamWriter(ms))
                    {
                        msw.WriteLine("ply");
                        msw.WriteLine(ascii ? "format ascii 1.0" : "format binary_little_endian 1.0");

                        msw.WriteLine($"element vertex {vertex_count}");
                        msw.WriteLine("property double x");
                        msw.WriteLine("property double y");
                        msw.WriteLine("property double z");

                        if (color)
                        {
                            msw.WriteLine("property uchar red");
                            msw.WriteLine("property uchar green");
                            msw.WriteLine("property uchar blue");
                        }

                        msw.WriteLine($"element face {face_count}");
                        msw.WriteLine("property list uchar int vertex_index");

                        msw.WriteLine("end_header");
                        msw.Flush();
                        var bytes = ms.GetBuffer();
                        if (ascii)
                        {
                            for (var i = 0; i < ms.Length; i++)
                            {
                                sw.Write((char)bytes[i]);
                            }
                        }
                        else
                        {
                            bw.Write(bytes, 0, (int)ms.Length);
                        }
                    }

                sw.Flush();
                bw.Flush();

                var count_vertices = 0;

                // testing
                math.Vector3d offset;
                {
                    var vo  = Allocated.Values.First();
                    var off = vo.VertexOffsets[0];
                    offset = MeshGenerator.LineSampleToMoonME(manager, vo.Line + off.Y, vo.Sample + off.X);
                }

                // Write the vertices
                foreach (var m in Allocated.Values)
                {
                    var colorFromTile = m.Color;
                    foreach (var vertex_offset in m.VertexOffsets)
                    {
                        var sample = m.Sample + vertex_offset.X;
                        var line   = m.Line + vertex_offset.Y;
                        var pos    = MeshGenerator.LineSampleToMoonME(manager, line, sample);

                        // Testing
                        pos = pos - offset;

                        count_vertices++;
                        if (ascii)
                        {
                            sw.Write($"{pos.X} {pos.Y} {pos.Z}");
                            if (color)
                            {
                                sw.WriteLine($" {colorFromTile.R} {colorFromTile.G} {colorFromTile.B}");
                            }
                        }
                        else
                        {
                            bw.Write(pos.X);
                            bw.Write(pos.Y);
                            bw.Write(pos.Z);
                            if (color)
                            {
                                bw.Write(colorFromTile.R);
                                bw.Write(colorFromTile.G);
                                bw.Write(colorFromTile.B);
                            }
                        }
                    }
                }

                System.Diagnostics.Debug.Assert(count_vertices == vertex_count);

                // write the faces
                if (ascii)
                {
                    foreach (var face in EnumerateFaces())
                    {
                        sw.Write(face.Length);
                        for (var i = 0; i < face.Length; i++)
                        {
                            var idx = face[i];
                            System.Diagnostics.Debug.Assert(idx >= 0 && idx < vertex_count);
                            sw.Write(' ');
                            sw.Write(idx);
                        }
                        sw.WriteLine();
                    }
                }
                else
                {
                    foreach (var face in EnumerateFaces())
                    {
                        bw.Write((byte)face.Length);
                        for (var i = 0; i < face.Length; i++)
                        {
                            var idx = face[i];
                            System.Diagnostics.Debug.Assert(idx >= 0 && idx < vertex_count);
                            bw.Write(idx);
                        }
                    }
                }

                bw.Flush();
                sw.Flush();
            }
        }