Ejemplo n.º 1
0
 public static void Done()
 {
     if (master != null)
     {
         if (master.Visible)
         {
             master.Close();
         }
         master = null;
     }
 }
Ejemplo n.º 2
0
 public static void Done()
 {
     if (master != null)
     {
         if (master.Visible)
         {
             master.Close();
         }
         master = null;
     }
 }
Ejemplo n.º 3
0
 public static void Show(Form owner, string titleText, string ProgressText)
 {
     canceled = false;
     if (master == null)
     {
         master = new ProgressPopup();
     }
     master.Owner = owner;
     master.Title = titleText;
     SetProgress(0, ProgressText);
     if (!master.Visible)
     {
         master.Show(owner);
     }
     Application.DoEvents();
 }
Ejemplo n.º 4
0
 public static void Show(Form owner, string titleText, string ProgressText)
 {
     canceled = false;
     if (master == null)
     {
         master = new ProgressPopup();
     }
     master.Owner = owner;
     master.Title = titleText;
     SetProgress(0, ProgressText);
     if (!master.Visible)
     {
         master.Show(owner);
     }
     Application.DoEvents();
 }
Ejemplo n.º 5
0
        private void Export_Click(object sender, EventArgs e)
        {
            string filename = "";

            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Filter           = "Standard Tessellation Language" + "|*.stl";
            saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            saveDialog.AddExtension     = true;
            saveDialog.DefaultExt       = ".stl";
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                filename = saveDialog.FileName;

                if (string.IsNullOrEmpty(filename))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            ProgressPopup.Show(this, "Export STL File", "Scanning Elevation Map");

            double baseOffset = double.Parse(baseHeight.Text);

            density = int.Parse(Density.Text);

            double xRate = Rect.West - Rect.East;
            double yRate = Rect.North - Rect.South;

            double latCenter = (Rect.North + Rect.South) / 2;

            double ratio = Math.Cos(latCenter / 180 * Math.PI);

            double sizeY = 100;
            double sizeX = Math.Abs(((xRate * ratio) / yRate) * sizeY);

            int stepsX = (int)(sizeX * density / 10);
            int stepsY = (int)(sizeY * density / 10);


            //Computer relative altitude to latitude scaling for this planet.
            double radius         = Earth3d.MainWindow.RenderContext11.NominalRadius;
            double altScaleFactor = ((radius * Math.PI * 2) / 360) * (yRate / sizeY);

            altScaleFactor = 1 / altScaleFactor;



            xRate /= stepsX;
            yRate /= stepsY;


            Vector3d[,] points = new Vector3d[stepsX, stepsY];
            double[,] altitude = new double[stepsX, stepsY];
            double maxAltitude = -10000000;
            double minAltitude = 100000000;
            double altScale    = double.Parse(AltitudeScale.Text) / 100;


            int estimatedTotal = stepsX * stepsY;
            int actualTotal    = 0;


            for (int y = 0; y < stepsY; y++)
            {
                for (int x = 0; x < stepsX; x++)
                {
                    double lat = Rect.North - (yRate * y);
                    double lng = Rect.East + (xRate * x);

                    double alt = Earth3d.MainWindow.GetAltitudeForLatLongNow(lat, lng);
                    altitude[x, y] = alt;
                    maxAltitude    = Math.Max(alt, maxAltitude);
                    minAltitude    = Math.Min(minAltitude, alt);
                    actualTotal++;
                }

                if (!ProgressPopup.SetProgress(((actualTotal * 100) / estimatedTotal), "Scanning Elevation Map"))
                {
                    ProgressPopup.Done();
                    return;
                }
            }

            double altRange = maxAltitude - minAltitude;

            // old altScaleFactor = (10 / altRange) * altScale;
            altScaleFactor *= altScale;

            double stepScaleX = sizeX / stepsX;
            double stepScaleY = sizeY / stepsY;

            // make the verticies
            for (int y = 0; y < stepsY; y++)
            {
                for (int x = 0; x < stepsX; x++)
                {
                    altitude[x, y] = ((altitude[x, y] - minAltitude) * altScaleFactor) + baseOffset;

                    points[x, y] = new Vector3d(x * stepScaleX, y * stepScaleY, altitude[x, y]);
                }
            }



            ProgressPopup.SetProgress(0, "Writing File");

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            FileStream   fs = File.OpenWrite(filename);
            BinaryWriter bw = new BinaryWriter(fs);

            // Write File Header
            bw.Write(new byte[80]);

            // x-1*y-1*2
            int count = ((stepsX - 1) * (stepsY - 1) + (stepsY - 1) + (stepsY - 1) + (stepsX - 1) + (stepsX - 1) + (stepsX - 1) * (stepsY - 1)) * 2;


            // Write Triangle Count
            bw.Write(count);


            // Loop thru and create triangles for all quads..

            int writeCount = 0;

            for (int y = 0; y < stepsY - 1; y++)
            {
                for (int x = 0; x < stepsX - 1; x++)
                {
                    // Write dummy Normal
                    bw.Write(0f);
                    bw.Write(0f);
                    bw.Write(0f);


                    // Vertexes - triangle 1
                    WriteVertex(bw, points[x, y]);
                    WriteVertex(bw, points[x + 1, y]);
                    WriteVertex(bw, points[x + 1, y + 1]);
                    bw.Write((UInt16)(0));
                    writeCount++;


                    // Write dummy Normal
                    bw.Write(0f);
                    bw.Write(0f);
                    bw.Write(0f);
                    // Vertexes - triangle 2
                    WriteVertex(bw, points[x, y]);
                    WriteVertex(bw, points[x + 1, y + 1]);
                    WriteVertex(bw, points[x, y + 1]);
                    bw.Write((UInt16)(0));
                    writeCount++;
                }
            }
            ProgressPopup.SetProgress(35, "Writing File");

            Vector3d pnt = new Vector3d();

            // Make side Skirts
            for (int y = 0; y < stepsY - 1; y++)
            {
                int x = 0;
                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);


                // Vertexes - triangle 1
                WriteVertex(bw, points[x, y]);
                WriteVertex(bw, points[x, y + 1]);
                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;


                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);
                // Vertexes - triangle 2
                WriteVertex(bw, points[x, y + 1]);

                pnt   = points[x, y + 1];
                pnt.Z = 0;
                WriteVertex(bw, pnt);

                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;
            }

            ProgressPopup.SetProgress(45, "Writing File");

            for (int y = 0; y < stepsY - 1; y++)
            {
                int x = stepsX - 1;
                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);


                // Vertexes - triangle 1
                WriteVertex(bw, points[x, y + 1]);
                WriteVertex(bw, points[x, y]);
                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;


                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);
                // Vertexes - triangle 2

                pnt   = points[x, y + 1];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                WriteVertex(bw, points[x, y + 1]);

                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;
            }

            ProgressPopup.SetProgress(50, "Writing File");

            for (int x = 0; x < stepsX - 1; x++)
            {
                int y = 0;
                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);


                // Vertexes - triangle 1
                WriteVertex(bw, points[x + 1, y]);
                WriteVertex(bw, points[x, y]);
                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;


                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);
                // Vertexes - triangle 2

                pnt   = points[x + 1, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                WriteVertex(bw, points[x + 1, y]);

                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;
            }

            ProgressPopup.SetProgress(55, "Writing File");

            for (int x = 0; x < stepsX - 1; x++)
            {
                int y = stepsY - 1;
                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);


                // Vertexes - triangle 1
                WriteVertex(bw, points[x, y]);
                WriteVertex(bw, points[x + 1, y]);
                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;


                // Write dummy Normal
                bw.Write(0f);
                bw.Write(0f);
                bw.Write(0f);
                // Vertexes - triangle 2
                WriteVertex(bw, points[x + 1, y]);

                pnt   = points[x + 1, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);

                pnt   = points[x, y];
                pnt.Z = 0;
                WriteVertex(bw, pnt);
                bw.Write((UInt16)(0));
                writeCount++;
            }

            ProgressPopup.SetProgress(65, "Writing File");


            ProgressPopup.SetProgress(75, "Writing File");

            for (int y = 0; y < stepsY - 1; y++)
            {
                for (int x = 0; x < stepsX - 1; x++)
                {
                    // Write dummy Normal
                    bw.Write(0f);
                    bw.Write(0f);
                    bw.Write(0f);


                    // Vertexes - triangle 1
                    pnt   = points[x, y];
                    pnt.Z = 0;
                    WriteVertex(bw, pnt);

                    pnt   = points[x + 1, y + 1];
                    pnt.Z = 0;
                    WriteVertex(bw, pnt);

                    pnt   = points[x + 1, y];
                    pnt.Z = 0;
                    WriteVertex(bw, pnt);



                    bw.Write((UInt16)(0));
                    writeCount++;


                    // Write dummy Normal
                    bw.Write(0f);
                    bw.Write(0f);
                    bw.Write(0f);

                    // Vertexes - triangle 2
                    pnt   = points[x, y];
                    pnt.Z = 0;
                    WriteVertex(bw, pnt);

                    pnt   = points[x, y + 1];
                    pnt.Z = 0;
                    WriteVertex(bw, pnt);

                    pnt   = points[x + 1, y + 1];
                    pnt.Z = 0;
                    WriteVertex(bw, pnt);

                    bw.Write((UInt16)(0));
                    writeCount++;
                }
            }



            // Make Bottom

            bw.Close();

            ProgressPopup.Done();
        }
Ejemplo n.º 6
0
 private void ProgressPopup_FormClosed(object sender, FormClosedEventArgs e)
 {
     master = null;
 }
Ejemplo n.º 7
0
 private void ProgressPopup_FormClosed(object sender, FormClosedEventArgs e)
 {
     master = null;
 }