Example #1
0
        private void CreateGraphs()
        {
            int    FrameRateOffset       = -15;
            ColorF FrameRateControlColor = new ColorF(1, 1, 1, 1);

            potentialDrawsBudgetPosition            = new Vector2(10, (double)Height + FrameRateOffset);
            showPotentialDrawsBudgetGraph           = new MatterHackers.Agg.UI.CheckBox(potentialDrawsBudgetPosition.X, potentialDrawsBudgetPosition.Y, "D:000.000");
            showPotentialDrawsBudgetGraph.TextColor = FrameRateControlColor.ToColor();
            //showPotentialDrawsBudgetGraph.inactive_color(FrameRateControlColor);
            AddChild(showPotentialDrawsBudgetGraph);
            potentialDrawsBudgetGraph = new DataViewGraph(potentialDrawsBudgetPosition, 100, 100);

            potentialUpdatesBudgetPosition            = new Vector2(115, (double)Height + FrameRateOffset);
            showPotentialUpdatesBudgetGraph           = new MatterHackers.Agg.UI.CheckBox(potentialUpdatesBudgetPosition.X, potentialUpdatesBudgetPosition.Y, "U:000.000");
            showPotentialUpdatesBudgetGraph.TextColor = FrameRateControlColor.ToColor();
            //showPotentialUpdatesBudgetGraph.inactive_color(FrameRateControlColor);
            AddChild(showPotentialUpdatesBudgetGraph);
            potentialUpdatesBudgetGraph = new DataViewGraph(potentialUpdatesBudgetPosition, 100, 100);

            actualDrawsBudgetPosition            = new Vector2(220, (double)Height + FrameRateOffset);
            showActualDrawsBudgetGraph           = new MatterHackers.Agg.UI.CheckBox(actualDrawsBudgetPosition.X, actualDrawsBudgetPosition.Y, "A:000.000");
            showActualDrawsBudgetGraph.TextColor = FrameRateControlColor.ToColor();
            //showActualDrawsBudgetGraph.inactive_color(FrameRateControlColor);
            AddChild(showActualDrawsBudgetGraph);
            actualDrawsBudgetGraph = new DataViewGraph(actualDrawsBudgetPosition, 100, 100);
        }
Example #2
0
        public static IObject3D Load(Stream fileStream, CancellationToken cancellationToken, Action <double, string> reportProgress = null)
        {
            IObject3D root = new Object3D();

            IObject3D context = null;

            int       totalMeshes = 0;
            Stopwatch time        = Stopwatch.StartNew();

            Dictionary <string, ColorF>    materials = new Dictionary <string, ColorF>();
            Dictionary <IObject3D, string> objectMaterialDictionary = new Dictionary <IObject3D, string>();

            using (var decompressedStream = GetCompressedStreamIfRequired(fileStream))
            {
                using (var reader = XmlReader.Create(decompressedStream))
                {
                    List <Vector3> vertices = null;
                    Mesh           mesh     = null;

                    ProgressData progressData = new ProgressData(fileStream, reportProgress);

                    while (reader.Read())
                    {
                        if (!reader.IsStartElement())
                        {
                            continue;
                        }

                        switch (reader.Name)
                        {
                        case "object":
                            break;

                        case "mesh":
                            break;

                        case "vertices":
                            vertices = ReadAllVertices(reader, progressData);
                            break;

                        case "volume":
                            context = new Object3D();
                            root.Children.Add(context);
                            mesh = new Mesh();
                            context.SetMeshDirect(mesh);
                            totalMeshes += 1;

                            string materialId;
                            ReadVolume(reader, vertices, mesh, progressData, out materialId);
                            objectMaterialDictionary.Add(context, materialId);
                            break;

                        case "material":
                            ReadMaterial(reader, materials);
                            break;
                        }
                    }
                }

                fileStream.Dispose();
            }

            foreach (var keyValue in objectMaterialDictionary)
            {
                ColorF color = ColorF.White;
                if (keyValue.Value == null ||
                    !materials.TryGetValue(keyValue.Value, out color))
                {
                    color = ColorF.White;
                }
                keyValue.Key.Color = color.ToColor();
            }

            time.Stop();
            Debug.WriteLine(string.Format("AMF Load in {0:0.00}s", time.Elapsed.TotalSeconds));

            time.Restart();
            bool hasValidMesh = root.Children.Where(item => item.Mesh.Faces.Count > 0).Any();

            Debug.WriteLine("hasValidMesh: " + time.ElapsedMilliseconds);

            reportProgress?.Invoke(1, "");

            return((hasValidMesh) ? root : null);
        }