Exemplo n.º 1
0
        /// <summary>
        /// Event to sharpgl draw
        /// </summary>
        /// <param name="parameter">object parameter</param>
        private void OpenGLControl_OpenGLDraw(object parameter)
        {
            OpenGL gl = gl = ((OpenGLEventArgs)parameter).OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.Flush();

            if (!this.oldAnalysis && (this.vertices == null || this.vertices[this.Slider] == null))
            {
                return;
            }

            if (!this.oldAnalysis)
            {
                //// Clear the color and depth buffers.
                //gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

                //// Reset the modelview matrix.
                //gl.LoadIdentity();

                // Move the geometry into a fairly central position.
                gl.Translate(0.0f, 0.0f, -20.0f);

                gl.PointSize(1.0f);

                gl.Begin(OpenGL.GL_TRIANGLES);

                int id = this.displayInterp < this.Slider ? this.displayInterp : this.Slider;

                for (int i = 0; i < this.vertices[id].Count(); i++)
                {
                    Color asd = Interpolation.GetHeatMapColor(this.vertices[id][i].Z, -1, +1);
                    gl.Color(asd.R / (float)255, asd.G / (float)255, asd.B / (float)255);
                    gl.Vertex(this.vertices[id][i].X / 100, this.vertices[id][i].Y / 100, 0.0f);
                }

                gl.End();

                // Flush OpenGL.
                //gl.Flush();

                if (!this.savedVertices[id])
                {
                    this.TakeScreenshot(gl, id);
                    this.savedVertices[id] = true;
                }

                this.displayInterp++;
            }
            else
            {
                if (!this.changeImage && this.textureImages[this.Slider] != null)
                {
                    this.SelectTexture(gl, this.Slider);
                    this.changeImage = true;
                }

                //gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                //gl.LoadIdentity();

                gl.Translate(0.0f, 0.0f, -3.5f);

                gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.textures[0]);

                gl.Begin(OpenGL.GL_QUADS);

                // Front Face
                gl.TexCoord(0.0f, 0.0f);
                gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
                gl.TexCoord(1.0f, 0.0f);
                gl.Vertex(1.0f, -1.0f, 1.0f);  // Bottom Right Of The Texture and Quad
                gl.TexCoord(1.0f, 1.0f);
                gl.Vertex(1.0f, 1.0f, 1.0f);   // Top Right Of The Texture and Quad
                gl.TexCoord(0.0f, 1.0f);
                gl.Vertex(-1.0f, 1.0f, 1.0f);  // Top Left Of The Texture and Quad

                gl.End();

                //gl.Flush();
            }

            gl.Flush();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load sensors in model
        /// </summary>
        /// <param name="sensors">List of sensors</param>
        /// <param name="analysisName">Analysis name</param>
        public void LoadSensorsInModel2(IEnumerable <Sensor> sensors, string analysisName)
        {
            // this.ViewPort3d.Children.Remove(this.device3D);
            this.sensorGroupModel.Children.Clear();
            this.sensorGroupModel.Children.Add(this.stlModel);

            this.sensorModelArray[this.dataCounter] = new List <GeometryModel3D>();

            int pos = 0;

            foreach (Sensor sensor in sensors)
            {
                Color color = new Color()
                {
                    A = 255, R = 255, G = 255, B = 0
                };
                MeshBuilder meshBuilder;

                if (sensor.Values.Count != 0)
                {
                    // Get data from analysis
                    IEnumerable <SensorValue> svc = from values in sensor.Values where values.AnalysisName == analysisName select values;

                    if (svc.Count() > 0)
                    {
                        // Group by parameters
                        List <IGrouping <string, SensorValue> > grouped = svc.GroupBy(a => a.Parameter).ToList();

                        int[] indexs = grouped[0].Key == this.parameterString ? new int[] { 0, 1 } : new int[] { 1, 0 };

                        for (int i = 0; i < grouped[indexs[1]].Count(); i++)
                        {
                            if (this.sensorModelArray[i] == null)
                            {
                                this.sensorModelArray[i] = new List <GeometryModel3D>();
                            }

                            meshBuilder = new MeshBuilder();

                            color = Interpolation.GetHeatMapColor(grouped[indexs[1]].ElementAt(i).Value, -1, +1);
                            meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);

                            if (grouped.Count > 1)
                            {
                                double cte = grouped[indexs[0]].ElementAt(i).Value *Math.PI / 180;

                                Point3D newPoint = new Point3D(sensor.X + (4 * sensor.Size * Math.Cos(cte)), sensor.Y + (4 * sensor.Size * Math.Sin(cte)), sensor.Z);
                                meshBuilder.AddArrow(new Point3D(sensor.X, sensor.Y, sensor.Z), newPoint, this.arrowDiameterSize, this.arrowHeadSize);
                            }

                            GeometryModel3D sensorModel2 = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));

                            this.sensorModelArray[i].Add(sensorModel2);
                        }
                    }
                    else
                    {
                        meshBuilder = new MeshBuilder();

                        color = new Color()
                        {
                            A = 255, R = 255, G = 255, B = 0
                        };
                        meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);

                        GeometryModel3D sensorModel2 = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));

                        this.sensorModelArray[pos].Add(sensorModel2);
                    }
                }
            }

            // TODO
            // foreach (var model3d in this.sensorModelArray[this.sensorModelArray.Length - 1])
            foreach (var model3d in this.sensorModelArray[0])
            {
                this.sensorGroupModel.Children.Add(model3d);
            }

            this.GroupModel       = this.sensorGroupModel;
            this.device3D.Content = this.groupModel;

            if (!this.ViewPort3d.Children.Contains(this.device3D))
            {
                this.ViewPort3d.Children.Add(this.device3D);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load sensors in model
        /// </summary>
        /// <param name="sensors">List of sensors</param>
        public void LoadSensorsValuesInModel(IEnumerable <Sensor> sensors)
        {
            this.sensorGroupModel.Children.Clear();
            this.sensorGroupModel.Children.Add(this.stlModel);

            this.sensorModelArray[this.dataCounter] = new List <GeometryModel3D>();

            foreach (Sensor sensor in sensors)
            {
                MeshBuilder meshBuilder = new MeshBuilder();

                IEnumerable <IGrouping <string, SensorValue> > asd = sensor.Values.GroupBy(a => a.Parameter);

                double value = 0;

                foreach (IGrouping <string, SensorValue> gp in asd)
                {
                    if (gp.Key == this.parameterString)
                    {
                        double cte = gp.Last().Value *Math.PI / 180;

                        Point3D newPoint = new Point3D(sensor.X + (4 * sensor.Size * Math.Cos(cte)), sensor.Y + (4 * sensor.Size * Math.Sin(cte)), sensor.Z);
                        meshBuilder.AddArrow(new Point3D(sensor.X, sensor.Y, sensor.Z), newPoint, this.arrowDiameterSize, this.arrowHeadSize);
                    }
                    else
                    {
                        value = gp.Last().Value;
                        meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);
                    }
                }

                Color color;

                // If sensor does not receive any value, receives yellow as collor
                if (sensor.Values.Count != 0)
                {
                    color = Interpolation.GetHeatMapColor(value, -1, +1);
                }
                else
                {
                    color = new Color()
                    {
                        A = 255, R = 255, G = 255, B = 0
                    };
                }

                GeometryModel3D sensorModel = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));
                this.sensorModelArray[this.dataCounter].Add(sensorModel);
                this.sensorGroupModel.Children.Add(sensorModel);
            }

            if (this.modelMesh != null)
            {
                this.vertices[this.dataCounter++] = this.interpolation.Interpolate2(this.modelMesh, this.SensorsNotParameter(sensors));
                this.MaxSlider = this.dataCounter - 1;
                this.Slider    = this.MaxSlider;
            }

            this.GroupModel       = this.sensorGroupModel;
            this.device3D.Content = this.groupModel;

            if (!this.ViewPort3d.Children.Contains(this.device3D))
            {
                this.ViewPort3d.Children.Add(this.device3D);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load sensors in model
        /// </summary>
        /// <param name="sensors">List of sensors</param>
        /// <param name="analysisName">Analysis name</param>
        public void LoadSensorsInModel(IEnumerable <Sensor> sensors, string analysisName)
        {
            // this.ViewPort3d.Children.Remove(this.device3D);
            this.sensorGroupModel.Children.Clear();
            this.sensorGroupModel.Children.Add(this.stlModel);

            this.sensorModelArray[this.dataCounter] = new List <GeometryModel3D>();

            foreach (Sensor sensor in sensors)
            {
                MeshBuilder meshBuilder = new MeshBuilder();

                Color color = new Color()
                {
                    A = 255, R = 255, G = 255, B = 0
                };

                if (sensor.Values.Count != 0 && !string.IsNullOrEmpty(analysisName))
                {
                    // Get data from analysis
                    IEnumerable <SensorValue> svc = from values in sensor.Values where values.AnalysisName == analysisName select values;

                    if (svc.Count() > 0)
                    {
                        // Group by parameters
                        IEnumerable <IGrouping <string, SensorValue> > asd = svc.GroupBy(a => a.Parameter);
                        foreach (IGrouping <string, SensorValue> gp in asd)
                        {
                            // If parameter is direction then add arrow with the value
                            if (gp.Key == this.parameterString)
                            {
                                double cte = gp.Last().Value *Math.PI / 180;

                                Point3D newPoint = new Point3D(sensor.X + (4 * sensor.Size * Math.Cos(cte)), sensor.Y + (4 * sensor.Size * Math.Sin(cte)), sensor.Z);
                                meshBuilder.AddArrow(new Point3D(sensor.X, sensor.Y, sensor.Z), newPoint, this.arrowDiameterSize, this.arrowHeadSize);
                            }
                            else
                            {
                                // With the respective color
                                color = Interpolation.GetHeatMapColor(gp.Last().Value, -1, +1);
                            }
                        }
                    }
                    else
                    {
                        color = new Color()
                        {
                            A = 255, R = 255, G = 255, B = 0
                        };
                    }
                }

                meshBuilder.AddBox(new Point3D(sensor.X, sensor.Y, sensor.Z), sensor.Size, sensor.Size, this.sizeZ);

                GeometryModel3D sensorModel = new GeometryModel3D(meshBuilder.ToMesh(), MaterialHelper.CreateMaterial(color));

                this.sensorModelArray[this.dataCounter].Add(sensorModel);

                this.sensorGroupModel.Children.Add(sensorModel);
            }

            this.GroupModel       = this.sensorGroupModel;
            this.device3D.Content = this.groupModel;

            if (!this.ViewPort3d.Children.Contains(this.device3D))
            {
                this.ViewPort3d.Children.Add(this.device3D);
            }
        }