Пример #1
0
        /// <summary>
        /// set position of single vertex
        /// </summary>
        /// <param name="vertexID">index of vertex in vertex array</param>
        /// <param name="position">new position </param>
        public override void SetPosition(int vertexID, ILPoint3Df position)
        {
            VertexType vert = m_vertices[vertexID];

            vert.Position        = position;
            m_vertices[vertexID] = vert;
        }
Пример #2
0
        protected override void RunInternal(object parameter) {
            float x1 = m_MinCornerStart.X;
            float y1 = m_MinCornerStart.Y;
            float z1 = m_MinCornerStart.Z;
            float x2 = m_MaxCornerStart.X;
            float y2 = m_MaxCornerStart.Y;
            float z2 = m_MaxCornerStart.Z;
            float aMinX = m_MinCornerEnd.X - x1;
            float aMinY = m_MinCornerEnd.Y - y1;
            float aMinZ = m_MinCornerEnd.Z - z1;
            float aMaxX = m_MaxCornerEnd.X - x2;
            float aMaxY = m_MaxCornerEnd.Y - y2;
            float aMaxZ = m_MaxCornerEnd.Z - z2;
            foreach (ILActionRampElement elem in m_ramp) {
                if (m_canceled) return; 
                ILPoint3Df min = new ILPoint3Df(
                            x1 + aMinX * elem.Value,
                            y1 + aMinY * elem.Value,
                            z1 + aMinZ * elem.Value);
                ILPoint3Df max = new ILPoint3Df(
                            x2 + aMaxX * elem.Value,
                            y2 + aMaxY * elem.Value,
                            z2 + aMaxZ * elem.Value); 
                m_panel.Limits.Set(min,max);
                m_panel.Refresh(); 
                if (m_canceled) return; 
                Thread.Sleep((int)(elem.Duration * 1000)); 
            }


        }
Пример #3
0
        protected override void  ComputeLimits()
        {
            // only consider used(!) vertices (having indices in mapping)
            ILPoint3Df cent = new ILPoint3Df();

            if (m_shapeIndices.IsEmpty)
            {
                // fast exit
                m_positionCenter = cent;
                m_positionMin    = cent;
                m_positionMax    = cent;
                return;
            }
            ILPoint3Df max = ILPoint3Df.MinValue, min = ILPoint3Df.MaxValue, cur;

            foreach (int vertexID in m_shapeIndices.Values)
            {
                cur  = m_vertices[vertexID].Position;
                cent = cent + cur;
                max  = ILPoint3Df.Max(max, cur);
                min  = ILPoint3Df.Min(min, cur);
            }
            m_positionCenter = cent / m_vertices.Length;
            m_positionMax    = max;
            m_positionMin    = min;
            updateVertexPositions(Vertices, ref m_vertexPositions);
        }
Пример #4
0
        protected override void ComputeLimits()
        {
            ILPoint3Df cent = new ILPoint3Df();

            if (m_vertices.Length == 0)
            {
                // fast exit
                m_positionCenter = cent;
                m_positionMin    = cent;
                m_positionMax    = cent;
                return;
            }
            ILPoint3Df max = ILPoint3Df.MinValue, min = ILPoint3Df.MaxValue, cur;

            foreach (IILVertexDefinition vertex in m_vertices)
            {
                cur  = vertex.Position;
                cent = cent + cur;
                max  = ILPoint3Df.Max(max, cur);
                min  = ILPoint3Df.Min(min, cur);
            }
            m_positionCenter = cent / m_vertices.Length;
            m_positionMax    = max;
            m_positionMin    = min;
        }
Пример #5
0
        protected override void world2Screen(ILPoint3Df p1_3D, ILPoint3Df p2_3D, out Point p1_2D, out Point p2_2D)
        {
            Matrix mat = m_device.Transform.World;

            mat *= m_device.Transform.View;
            mat *= m_device.Transform.Projection;
            Vector3 s = new Vector3(p1_3D.X, p1_3D.Y, p1_3D.Z);
            Vector3 e = new Vector3(p2_3D.X, p2_3D.Y, p2_3D.Z);

            s.TransformCoordinate(mat);
            e.TransformCoordinate(mat);
            s.X = (s.X / 2.0f + 0.5f);
            e.X = (e.X / 2.0f + 0.5f);
            s.Y = -(s.Y / 2.0f - 0.5f);
            e.Y = -(e.Y / 2.0f - 0.5f);
            // variant with margin over viewport
            //float multMarg = (m_device.Viewport.Width / 100.0f);
            //startX = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.X + m_margin * multMarg);
            //endX =   (int)(multMarg * (100.0f - 0.0f * m_margin) * e.X + m_margin * multMarg);
            //multMarg = (m_device.Viewport.Height / 100.0f);
            //startY = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.Y + m_margin * multMarg);
            //endY =   (int)(multMarg * (100.0f - 0.0f * m_margin) * e.Y + m_margin * multMarg);
            float multMarg = (m_device.Viewport.Width);

            p1_2D = new Point((int)(multMarg * s.X), (int)(m_device.Viewport.Height * s.Y));
            p2_2D = new Point((int)(multMarg * e.X), (int)(m_device.Viewport.Height * e.Y));
        }
Пример #6
0
            /// <summary>
            /// create vertex data [unevenly distributed, depricated]
            /// </summary>
            /// <param name="center"></param>
            /// <param name="radius"></param>
            /// <param name="horRes"></param>
            /// <param name="vertRes"></param>
            /// <param name="indices"></param>
            /// <returns></returns>
            public static ILArray <float> CreateVertices(ILPoint3Df center, float radius, int horRes, int vertRes, out ILArray <int> indices)
            {
                ILArray <float> phi = repmat(tosingle(linspace(-pi, pi, horRes + 1)), vertRes + 1, 1);
                ILArray <float> rho = repmat(tosingle(linspace(0, pi, vertRes + 1)).T, 1, horRes + 1);
                bool            dummy;

                float[]         retArr = ILNumerics.Misc.ILMemoryPool.Pool.New <float>((horRes + 1) * (vertRes + 1), false, out dummy);
                ILArray <float> ret    = new ILArray <float>(retArr, vertRes + 1, horRes + 1);

                // create normals
                ret[":;:;3"] = sin(phi) * sin(rho);
                ret[":;:;4"] = cos(phi) * sin(rho);
                ret[":;:;5"] = cos(rho);
                // translate + scale vertices
                ret[":;:;0"] = (ILArray <float>)radius * ret[":;:;3"] + center.X;
                ret[":;:;1"] = (ILArray <float>)radius * ret[":;:;4"] + center.Y;
                ret[":;:;2"] = (ILArray <float>)radius * ret[":;:;5"] + center.Z;
                // create index mappings
                //horRes--; vertRes--;
                indices = new ILArray <int>(4, (horRes) * (vertRes));
                for (int r = 0, pos = 0; r < vertRes; r++)
                {
                    for (int c = 0; c < horRes; c++)
                    {
                        indices.SetValue(c + r * (horRes + 1), pos++);
                        indices.SetValue(c + (r + 1) * (horRes + 1), pos++);
                        indices.SetValue((c + 1) + (r + 1) * (horRes + 1), pos++);
                        indices.SetValue((c + 1) + r * (horRes + 1), pos++);
                    }
                }
                System.Diagnostics.Debug.Assert(maxall(indices) <= (double)ret[":;:;0"].Dimensions.NumberOfElements);
                System.Diagnostics.Debug.Assert(minall(indices) >= 0.0);
                return(ret);
            }
Пример #7
0
        /// <summary>
        /// add 'new' bar with new value and remove oldest bar
        /// </summary>
        /// <param name="value">height of new bar</param>
        /// <returns>discarded value</returns>
        public float Queue(float value)
        {
            // we move all shapes by 1 left
            ILPoint3Df offset = new ILPoint3Df(-1f, 0, 0);

            for (int i = 0; i < m_quads.Length; i++)
            {
                m_quads[i].Translate(offset);
                // FADE OUt old barsss ....
                m_quads[(i + m_oldestBarIndex) % (m_quads.Length - 1)].Opacity
                    = (byte)(m_oldestOpacity + i * (255 - m_oldestOpacity) / m_quads.Length);
                // tell the scene to update its size
                m_quads[i].Invalidate();
            }
            // configure oldest graph
            ILQuad newestQuad = m_quads[m_oldestBarIndex];

            offset.X = m_quads.Length;
            newestQuad.Translate(offset);
            float ret = newestQuad.Vertices[2].YPosition;

            newestQuad.Vertices[2].YPosition = value;
            newestQuad.Vertices[3].YPosition = value;
            newestQuad.Opacity = 255;

            if (++m_oldestBarIndex >= m_quads.Length)
            {
                m_oldestBarIndex = 0;
            }
            return(ret);
        }
Пример #8
0
 /// <summary>
 /// recompute the size spanned by this node, may fires Changed() event
 /// </summary>
 public override void Configure()
 {
     if (m_invalidated)
     {
         // configure childs (compute limits) first
         foreach (ILSceneGraphNode child in m_childs)
         {
             child.Configure();
         }
         bool       sizechanged = false;
         ILPoint3Df oldMin      = m_positionMin;
         ILPoint3Df oldMax      = m_positionMax;
         ComputeNodeLimits();
         if (oldMin != m_positionMin)
         {
             sizechanged = true;
         }
         if (oldMax != m_positionMax)
         {
             sizechanged = true;
         }
         m_invalidated = false;
         if (sizechanged)
         {
             OnSizeChanged();
         }
     }
 }
Пример #9
0
 private void createBoxes()
 {
     ILNumerics.Drawing.Misc.ILColormap cm = new ILNumerics.Drawing.Misc.ILColormap(Colormaps.Hsv);
     m_boxes = new List <ILLitBox3D>();
     float [] xPos = new float[] { 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 20, 20, 20 };
     float [] yPos = new float[] { 28, 29, 30, 28, 29, 30, 28, 29, 30, 28, 29, 30, 28, 29, 30, 28, 29, 30, 31, 28, 29, 30, 31, 29, 30, 31, 29, 30, 31 };
     float [] zVal = new float[] { 0.02f, 0.316f, 0.523f, 0.0223f, 0.283f, 0.471f, 0.0074f, 0.17f, 0.409f, 0.021f, 0.3f, 0.5f, 0.0191f, 0.187f, 0.337f, 0.02f, 0.07f, 0.52f, 0.64f, 0.06f, 0.22f, 0.3f, 0.48f, 0.17f, 0.21f, 0.63f, 0.1f, 0.17f, 0.3f };
     byte []  tran = new byte[] { 30, 30, 30, 70, 70, 70, 190, 190, 190 };
     for (int i = 0; i < xPos.Length; i++)
     {
         ILLitBox3D box;
         ILPoint3Df min = new ILPoint3Df(
             -m_max + xPos[i] + 0.05 + 4 + m_linesPositionOffset,
             -m_max + yPos[i] + 0.05 - 2 + m_linesPositionOffset,
             -zVal[i]);
         ILPoint3Df max = new ILPoint3Df(
             -m_max + xPos[i] + 0.9 + 4 + m_linesPositionOffset,
             -m_max + yPos[i] + 0.9 - 2 + m_linesPositionOffset,
             zVal[i]);
         box = new ILLitBox3D(m_panel, min, max, cm.Map((double)zVal[i] * cm.Length), cm.Map((double)zVal[i] * cm.Length));
         box.TopLabel.Text = "";
         box.GradientColor = box.TopColor;
         box.Edges.Color   = Color.DarkGray;
         if (tran.Length > i)
         {
             //box.Opacity = tran[i];
         }
         box.Quads[ILLitBox3D.QuadIndices.bottom].CustomCenter = new ILPoint3Df(0, 0, 3000);
         box.Quads[ILLitBox3D.QuadIndices.top].CustomCenter    = new ILPoint3Df(0, 0, 3000);
         m_boxes.Add(box);
         Add(box);
     }
 }
Пример #10
0
        public override Point World2Screen(ILPoint3Df world, double[] modelview)
        {
            Vector3 w = new Vector3(world.X, world.Y, world.Z);
            Vector3 screen;

            Glu.Project(w, modelview, m_projMatrix, m_viewMatrix, out screen);
            return(new Point((int)screen.X, (int)(ClientSize.Height - screen.Y)));
        }
Пример #11
0
 public ILLight(int index)
 {
     m_enabled = index == 0;
     m_index   = index;
     Position  = new ILPoint3Df(100f, 100f, 100);
     Specular  = Color.FromArgb(255, 255, 255);
     Ambient   = Color.FromArgb(90, 90, 90);
     Diffuse   = Color.FromArgb(160, 160, 160);
 }
Пример #12
0
        /// <summary>
        /// (internally used) draws the plot
        /// </summary>
        /// <param name="props"></param>
        public override void Draw(ILRenderProperties props)
        {
            base.Draw(props);
            m_valLabel.Draw(props);
            ILPoint3Df labPos = m_quads[QuadIndices.top].Center;

            labPos.Z = Math.Max(m_quads[QuadIndices.top].Center.Z, m_quads[QuadIndices.bottom].Center.Z);
            m_topLabel.Draw(props, labPos);
        }
Пример #13
0
 /// <summary>
 /// translate all vertices of the shape
 /// </summary>
 /// <param name="offset">offset, all vertices will be moved by that amount</param>
 public override void Translate(ILPoint3Df offset)
 {
     for (int i = 0; i < m_vertCount; i++)
     {
         VertexType tmp = m_vertices[i];
         tmp.Position += offset;
         m_vertices[i] = tmp;
     }
 }
Пример #14
0
 /// <summary>
 /// set normal vector of single vertex
 /// </summary>
 /// <param name="vertexID">index of vertex in vertex array</param>
 /// <param name="normal">new normal vector</param>
 public override void SetNormal(int vertexID, ILPoint3Df normal)
 {
     if (VertexDefinition.StoresNormals)
     {
         VertexType vert = m_vertices[vertexID];
         vert.Normal          = normal;
         m_vertices[vertexID] = vert;
     }
 }
Пример #15
0
        /// <summary>
        /// set up viewport, projection and modelview matrices
        /// </summary>
        protected override void UpdateMatrices(float width2D, float height2D, float zDepth)
        {
            if (ClientSize.IsEmpty)
            {
                return;
            }
            if (m_plotBoxScreenRectF.Size.IsEmpty)
            {
                return;
            }

            float      worldSceneWidth;
            float      worldSceneHeight;
            ILPoint3Df camPos = m_camera.Position;
            ILPoint3Df top;
            ILPoint3Df moveOffset;

            helperUpdateMatrices(width2D, height2D, out worldSceneWidth, out worldSceneHeight, out top, out moveOffset);

            #region projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            float nearPlane = 0.2f; //Math.Max(0.0f, m_camera.Distance - m_clippingView.SphereRadius);
            float farPlane  = m_camera.Distance + m_clippingView.SphereRadius * 100;
            if (m_projection == Projection.Perspective)
            {
                float angle = (float)Math.Atan2(worldSceneHeight / 2.0f, m_camera.Distance - (zDepth / 2)) * 2.0f;
                Glu.Perspective(angle / Math.PI * 180, (double)worldSceneWidth / worldSceneHeight,
                                nearPlane, farPlane);
            }
            else
            {
                GL.Ortho(
                    -worldSceneWidth / 2.0, worldSceneWidth / 2.0
                    , -worldSceneHeight / 2.0, worldSceneHeight / 2.0
                    , nearPlane, farPlane);
            }
            GL.GetDouble(GetPName.ProjectionMatrix, m_projMatrix);
            // set viewport
            GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
            GL.GetInteger(GetPName.Viewport, m_viewMatrix);
            #endregion

            #region modelview
            MakeCurrent();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            //top = ILPoint3Df.normalize(top);
            Glu.LookAt(camPos.X, camPos.Y, camPos.Z
                       , m_camera.LookAt.X, m_camera.LookAt.Y, m_camera.LookAt.Z
                       , m_camera.Top.X, m_camera.Top.Y, m_camera.Top.Z);
            GL.Translate(moveOffset.X, moveOffset.Y, moveOffset.Z);
            GL.GetDouble(GetPName.ModelviewMatrix, m_modelViewMatrix);
            #endregion
        }
Пример #16
0
        /// <summary>
        /// transform from screen space into world space using OpenGL
        /// </summary>
        /// <param name="x">screen X</param>
        /// <param name="y">screen Y</param>
        /// <returns>world coord</returns>
        public override void Screen2World(int x, int y, out ILPoint3Df nearClip, out ILPoint3Df farClip)
        {
            // TODO: check the Z coord values. 0.68 here was result of trial only!
            Vector3 far, near;

            Glu.UnProject(new Vector3(x, y, 0.0f), m_modelViewMatrix, m_projMatrix, m_viewMatrix, out near);
            Glu.UnProject(new Vector3(x, y, 1.0f), m_modelViewMatrix, m_projMatrix, m_viewMatrix, out far);
            // transform back from unit cube to clipping view
            farClip  = new ILPoint3Df(far.X, far.Y, far.Z);    //m_clippingView.Map(far.X, far.Y, far.Z);
            nearClip = new ILPoint3Df(near.X, near.Y, near.Z); //m_clippingView.Map(near.X, near.Y, near.Z);
        }
Пример #17
0
 protected override void IntDrawLabel(ILRenderProperties props)
 {
     if (m_vertCount == 0 || m_vertCount >= VerticesPerShape)
     {
         if (!String.IsNullOrEmpty(m_label.Text) && m_vertCount > 1)
         {
             ILPoint3Df cent = m_vertices[0].Position + m_vertices[1].Position;
             m_label.Draw(props, cent / 2);
         }
     }
 }
Пример #18
0
        ///// <summary>
        ///// signaled when one/some of the ILGraphs have changed
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //void Graph_Changed(object sender, ILGraphChangedEventArgs e) {
        //    OnGraphChanged(sender as ILGraph,e);
        //}
        /// <summary>
        /// called once the limits of a graph have changed
        /// </summary>
        /// <param name="sender">graph</param>
        /// <param name="e">event args, holding a reference to the clipping data</param>
        void Limits_Changed(object sender, ClippingChangedEventArgs e)
        {
            ILPoint3Df max = ILPoint3Df.MinValue;
            ILPoint3Df min = ILPoint3Df.MaxValue;

            foreach (ILGraph graph in this)
            {
                max = ILPoint3Df.Max(max, graph.Limits.Max);
                min = ILPoint3Df.Min(min, graph.Limits.Min);
            }
            m_clippingData.Set(min, max);
        }
Пример #19
0
        /// <summary>
        /// Transform 2 world coordinates into screen coords under current matrices
        /// </summary>
        /// <param name="p1_3D">world coord point 1</param>
        /// <param name="p2_3D">world coord point 2</param>
        /// <param name="p1_2D">(output) screen coord point 1</param>
        /// <param name="p2_2D">(output) screen coord point 2</param>
        public override void World2Screen(ILPoint3Df p1_3D, ILPoint3Df p2_3D, out Point p1_2D, out Point p2_2D)
        {
            Vector3 s = new Vector3();
            Vector3 e = new Vector3();

            Glu.Project(new Vector3(p1_3D.X, p1_3D.Y, p1_3D.Z),
                        m_modelViewMatrix, m_projMatrix, m_viewMatrix, out s);
            Glu.Project(new Vector3(p2_3D.X, p2_3D.Y, p2_3D.Z),
                        m_modelViewMatrix, m_projMatrix, m_viewMatrix, out e);
            p1_2D = new Point((int)s.X, (int)(ClientSize.Height - s.Y));
            p2_2D = new Point((int)e.X, (int)(ClientSize.Height - e.Y));
        }
Пример #20
0
 /// <summary>
 /// create new lit sphere for a scene graph
 /// </summary>
 /// <param name="panel">panel hosting the scene</param>
 /// <param name="center">center position</param>
 /// <param name="radius">radius of the sphere</param>
 /// <param name="color">color of the sphere</param>
 /// <param name="detail">number of triangularization iterations, typical: 0..4</param>
 public ILLitSphere(ILPanel panel, ILPoint3Df center, float radius, Color color, int detail)
     : base(panel, 3, 3)
 {
     m_fillColor        = color;
     m_center           = center;
     m_radius           = radius;
     m_detail           = detail;
     Material.Shininess = 60;
     AutoNormals        = true;
     m_shading          = ShadingStyles.Interpolate;
     createVertices(detail);
 }
Пример #21
0
            /// <summary>
            /// Calculates the normals.
            /// </summary>
            /// <param name="vertices">vertex array of the shape</param>
            /// <param name="shapeIndices">The shape mapping indices.</param>
            /// <param name="shapeIndicesIndex">Index of the shape indices.</param>
            public static void CalculateNormals(
                VertexType[] vertices
                , ILArray <int> shapeIndices
                , Dictionary <int, List <int> > shapeIndicesIndex)
            {
#if MEASURE_NORMAL_CALCULATION
                DateTime start = DateTime.Now;
#endif
                System.Diagnostics.Debug.Assert(vertices != null && vertices.Length > 0 && vertices[0].StoresNormals);
                // first calculate the normal for all vertices
                ILPoint3Df[] snormals = new ILPoint3Df[shapeIndices.Dimensions[1]];
                for (int shapeCol = 0; shapeCol < snormals.Length; shapeCol++)
                {
                    // crossproduct of vertex: (#1 - #0) x (#2 - #0)
                    int        vi0   = shapeIndices.GetValue(0, shapeCol);
                    int        vi1   = shapeIndices.GetValue(1, shapeCol);
                    int        vi2   = shapeIndices.GetValue(2, shapeCol);
                    ILPoint3Df cross = ILPoint3Df.crossN(
                        vertices[vi1].Position - vertices[vi0].Position,
                        vertices[vi1].Position - vertices[vi2].Position);
                    snormals[shapeCol] = cross;
                }
#if MEASURE_NORMAL_CALCULATION
                TimeSpan crossDone    = DateTime.Now - start;
                DateTime startSorting = DateTime.Now;
                System.Diagnostics.Debug.WriteLine("Normals Calculation: cross products in " + crossDone.TotalMilliseconds.ToString() + "ms");
#endif
                // find all facettes using this vertex
                for (int i = 0; i < vertices.Length; i++)
                {
                    if (!shapeIndicesIndex.ContainsKey(i))
                    {
                        continue;
                    }
                    ILPoint3Df normal = new ILPoint3Df();
                    foreach (int shapeIdx in shapeIndicesIndex[i])
                    {
                        normal += snormals[shapeIdx];
                    }
                    // or should we let OpenGL normalize the normals...?
                    vertices[i].Normal = ILPoint3Df.normalize(normal);

                    //System.Diagnostics.Debug.Assert(
                    //    Math.Abs(Math.Sqrt(
                    //    vertices[0].Normal.X * vertices[0].Normal.X +
                    //    vertices[0].Normal.Y * vertices[0].Normal.Y +
                    //    vertices[0].Normal.Z * vertices[0].Normal.Z) - 1.0) < (double)MachineParameterFloat.eps);
                }
#if MEASURE_NORMAL_CALCULATION
                TimeSpan sortDone = DateTime.Now - startSorting;
                System.Diagnostics.Debug.WriteLine("Normals Calculation: sorting done in " + sortDone.TotalMilliseconds.ToString() + "ms");
#endif
            }
Пример #22
0
        private void updateClipping()
        {
            ILPoint3Df max = ILPoint3Df.MinValue;
            ILPoint3Df min = ILPoint3Df.MaxValue;

            for (int i = 0; i < m_vertexCount; i++)
            {
                C4bV3f vert = m_vertices[i];
                max = ILPoint3Df.Max(vert.Position, max);
                min = ILPoint3Df.Min(vert.Position, min);
            }
            m_localClipping.Set(min, max);
        }
Пример #23
0
 /// <summary>
 /// (internal use)
 /// </summary>
 /// <param name="p">render properties</param>
 /// <param name="min">minimum coord for label area</param>
 /// <param name="max">maximum coord for label area</param>
 public void Draw(ILRenderProperties p, ILPoint3Df min, ILPoint3Df max)
 {
     if (!String.IsNullOrEmpty(Text))
     {
         if (m_expression != m_cachedExpression)
         {
             interprete(m_expression);
         }
         m_renderer.Begin(p);
         m_renderer.Draw(m_renderQueue, min.X, min.Y, min.Z, max.X, max.Y, max.Z, m_color);
         m_renderer.End(p);
     }
 }
Пример #24
0
 public ILZoomAction(ILPoint3Df MinCornerStart,
                     ILPoint3Df MinCornerEnd,
                     ILPoint3Df MaxCornerStart,
                     ILPoint3Df MaxCornerEnd, 
                     ILActionRamp ramp,
                     ILPanel panel) 
 : base () {
     m_MaxCornerEnd = ILPoint3Df.Max(MinCornerEnd,MaxCornerEnd);
     m_MaxCornerStart = ILPoint3Df.Max(MinCornerStart,MaxCornerStart); 
     m_MinCornerEnd = ILPoint3Df.Min(MinCornerEnd,MaxCornerEnd);
     m_MinCornerStart = ILPoint3Df.Min(MinCornerStart,MaxCornerStart);
     m_ramp = ramp; 
     m_panel = panel; 
 }
Пример #25
0
 public ILZoomAction(ILPoint3Df MinCornerStart,
                     ILPoint3Df MinCornerEnd,
                     ILPoint3Df MaxCornerStart,
                     ILPoint3Df MaxCornerEnd,
                     ILActionRamp ramp,
                     ILPanel panel)
     : base()
 {
     m_MaxCornerEnd   = ILPoint3Df.Max(MinCornerEnd, MaxCornerEnd);
     m_MaxCornerStart = ILPoint3Df.Max(MinCornerStart, MaxCornerStart);
     m_MinCornerEnd   = ILPoint3Df.Min(MinCornerEnd, MaxCornerEnd);
     m_MinCornerStart = ILPoint3Df.Min(MinCornerStart, MaxCornerStart);
     m_ramp           = ramp;
     m_panel          = panel;
 }
Пример #26
0
            /// <summary>
            /// compute distance to camera and return sorted indices for rendering
            /// </summary>
            /// <param name="centers">current primitive centers</param>
            /// <param name="position">current camera position</param>
            /// <returns>sorted indices of primitives in descending order</returns>
            internal static ILArray <int> GetSortedIndices(ILArray <float> centers,
                                                           ILPoint3Df position)
            {
                ILArray <float> pos = new float[] { -position.X, -position.Y, -position.Z };

                // move camera outside of centers
                pos *= maxall(abs(centers));
                pos  = repmat(pos, centers.Dimensions[0], 1);
                // compute distances
                ILArray <float>  dist = sum(pow(centers - pos, 2), 1);
                ILArray <double> ret;

                sort(dist, out ret, 0, false);
                return(toint32(ret));
            }
Пример #27
0
 /// <summary>
 /// invalidate geometry cache for this and all nodes up to root
 /// </summary>
 public virtual void Invalidate()
 {
     m_center      = ILPoint3Df.Empty;
     m_positionMin = ILPoint3Df.Empty;
     m_positionMax = ILPoint3Df.Empty;
     m_invalidated = true;
     if (Parent != null)
     {
         Parent.Invalidate();
     }
     else
     {
         OnInvalidated();
     }
 }
Пример #28
0
        protected void createQuads(ILBaseArray data)
        {
            if (data == null || data.Length == 0)
            {
                Clear();
                m_quads = new ILQuad[0];
            }
            else
            {
                Clear();
                m_quads = new ILQuad[data.Length];
                ILColorEnumerator colors = new ILColorEnumerator();
                ILArray <float>   fData  = null;
                if (data is ILArray <float> )
                {
                    fData = (ILArray <float>)data;
                }
                else
                {
                    fData = ILMath.tosingle(data);
                }
                for (int i = 0; i < m_quads.Length; i++)
                {
                    m_quads[i] = new ILQuad(m_panel);
                    m_quads[i].Border.Visible = true;
                    m_quads[i].FillColor      = colors.NextColor();
                    ILPoint3Df pos = new ILPoint3Df();
                    pos.X = i - m_barWidth / 2;
                    pos.Y = 0;
                    pos.Z = -0.5f;
                    m_quads[i].Vertices[0].Position = pos;
                    pos.X += m_barWidth;
                    m_quads[i].Vertices[1].Position = pos;
                    pos.Y += fData.GetValue(i);
                    m_quads[i].Vertices[2].Position = pos;
                    pos.X -= m_barWidth;
                    m_quads[i].Vertices[3].Position = pos;
                    // label the bar
                    m_quads[i].Label.Text   = i.ToString();
                    m_quads[i].Label.Anchor = new PointF(.5f, -1);

                    // bars will be transparent, oldest fading to OpacityOldest
                    m_quads[i].Opacity = (byte)(m_oldestOpacity + i * (255 - m_oldestOpacity) / m_quads.Length);
                    // add the bar to the scene graph node (base)
                    Add(m_quads[i]);
                }
            }
        }
Пример #29
0
            public static void CalculateNormals(VertexType[] vertices)
            {
                if (vertices.Length < 3)
                {
                    return;
                }
                // crossproduct of vertex: (#1 - #0) x (#2 - #0)
                ILPoint3Df cross = ILPoint3Df.crossN(
                    vertices[1].Position - vertices[0].Position,
                    vertices[1].Position - vertices[2].Position);

                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].Normal = cross;
                }
            }
Пример #30
0
 protected override void IntDrawLabel(ILRenderProperties props)
 {
     if (m_vertCount >= VerticesPerShape)
     {
         ILPoint3Df cent = m_vertices[m_shapeIndices.GetValue(0)].Position;
         // draw label at center of first shape
         if (!String.IsNullOrEmpty(m_label.Text))
         {
             for (int i = 1; i < VerticesPerShape; i++)
             {
                 cent += m_vertices[m_shapeIndices.GetValue(i)].Position;
             }
             m_label.Draw(props, cent / VerticesPerShape);
         }
     }
 }
Пример #31
0
        /// <summary>
        /// recalculate matrices based on current clipping data, -view
        /// </summary>
        protected override void UpdateMatrices()
        {
            // update projection
            float xSize, ySize;

            GetTransformedSize(out xSize, out ySize);
            // add label's size to increase margin
            Size labelsSize = m_axis.MaxTicLabelSize;

            xSize = (xSize * ClientSize.Width) / (ClientSize.Width - 2 * labelsSize.Width);
            ySize = (ySize * ClientSize.Height) / (ClientSize.Height - 2 * labelsSize.Height);
            if (m_projection == Projection.Perspective)
            {
                float angle = (float)Math.Atan2(xSize / 2.0f, m_camera.Distance) * 2.0f;
                m_projectionMat = Matrix.PerspectiveFovLH(angle, ySize / xSize, 0.0f, 12.0f);
                m_device.Transform.Projection = m_projectionMat;
            }
            else if (m_projection == Projection.Orthographic)
            {
                m_projectionMat = Matrix.OrthoLH(xSize, ySize, -10.0f, m_camera.Distance + 5.5f);
                m_device.Transform.Projection = m_projectionMat;
            }
            else
            {
                throw new ILInvalidOperationException("invalid projection: " + m_projection.ToString());
            }
            // update lookat
            m_view = Matrix.LookAtLH(new Vector3(0.0f,
                                                 -(float)Math.Sin(m_camera.Rho) * m_camera.Distance,
                                                 -(float)Math.Cos(m_camera.Rho) * m_camera.Distance),
                                     new Vector3(0.0f, 0.0f, 0.0f),
                                     new Vector3(0.0f, (m_camera.Rho < Math.PI / 2) ? 1.0f : -1.0f, 0.0f));
            m_device.Transform.View = m_view;
            //System.Diagnostics.Debug.Print("Phi: " + m_cameraPhi.ToString() + " Theta: " + m_cameraTheta.ToString());
            #region built world (scaling & rotation) matrix
            ILPoint3Df ab = m_clippingView.ScaleToUnitCube();
            m_world  = Matrix.Scaling(ab.X, ab.Y, ab.Z); //Identity; //RotationZ(m_cameraPhi);
            ab       = m_clippingView.CenterToUnitCube();
            m_world *= Matrix.Translation(ab.X, ab.Y, ab.Z);
            m_world *= Matrix.Scaling(1.0f, 1.0f, -1.0f);
            //if (m_camera.Phi > Math.PI) ;
            //m_camera.Phi -= (float)(2 * Math.PI);
            m_world *= Matrix.RotationZ((float)(m_camera.Phi));
            m_device.Transform.World = m_world;
            #endregion
        }
Пример #32
0
        //protected void sortPrimitives() {
        //    m_oldCameraPosition = m_panel.Camera.Position;
        //    Computation.SortIndices(
        //                m_vertices, m_shapeIndices, m_vertCount, m_panel.Camera.Position,
        //                VerticesPerShape).ExportValues(ref m_renderIndices);
        //}

        private void sortPrimitives()
        {
            m_oldCameraPosition = m_panel.Camera.Position;
            if (m_renderIndices == null || m_renderIndices.Length < m_shapeIndices.Dimensions.NumberOfElements)
            {
                m_renderIndices = new int[m_shapeIndices.Dimensions.NumberOfElements];
            }
            float camScale = (ILPoint3Df.Max(m_positionMax, m_positionMin) - m_positionCenter).GetLength();

            Computation.SortIndices(
                m_vertexPositions
                , m_shapeIndices
                , m_vertCount
                , m_panel.Camera.LookAt + ((m_panel.Camera.LookAt - m_panel.Camera.Position) * camScale)
                , VerticesPerShape
                , m_renderIndices);
        }
Пример #33
0
 protected override void world2Screen(ILPoint3Df p1_3D, ILPoint3Df p2_3D, out Point p1_2D, out Point p2_2D ) {
     Matrix mat = m_device.Transform.World;
     mat *= m_device.Transform.View;
     mat *= m_device.Transform.Projection;
     Vector3 s = new Vector3(p1_3D.X, p1_3D.Y, p1_3D.Z);
     Vector3 e = new Vector3(p2_3D.X, p2_3D.Y, p2_3D.Z);
     s.TransformCoordinate(mat);
     e.TransformCoordinate(mat);
     s.X = (s.X / 2.0f + 0.5f);
     e.X = (e.X / 2.0f + 0.5f);
     s.Y = -(s.Y / 2.0f - 0.5f);
     e.Y = -(e.Y / 2.0f - 0.5f);
     // variant with margin over viewport
     //float multMarg = (m_device.Viewport.Width / 100.0f); 
     //startX = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.X + m_margin * multMarg); 
     //endX =   (int)(multMarg * (100.0f - 0.0f * m_margin) * e.X + m_margin * multMarg); 
     //multMarg = (m_device.Viewport.Height / 100.0f); 
     //startY = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.Y + m_margin * multMarg); 
     //endY =   (int)(multMarg * (100.0f - 0.0f * m_margin) * e.Y + m_margin * multMarg); 
     float multMarg = (m_device.Viewport.Width);
     p1_2D = new Point ((int)(multMarg * s.X),(int)(m_device.Viewport.Height * s.Y));
     p2_2D = new Point ((int)(multMarg * e.X),(int)(m_device.Viewport.Height * e.Y));
 }
Пример #34
0
 public ILLight (int index) {
     m_enabled = index == 0; 
     m_index = index; 
     Position = new ILPoint3Df(100f,100f,100);
     Specular = Color.FromArgb(255,255,255);
     Ambient = Color.FromArgb(90,90,90); 
     Diffuse = Color.FromArgb(160,160,160);  
 }
Пример #35
0
 public override Point Transform(ILPoint3Df worldPoint) {
     throw new NotImplementedException(); 
 }
Пример #36
0
 /// <summary>
 /// (internal use)
 /// </summary>
 /// <param name="p">render properties</param>
 /// <param name="min">minimum coord for label area</param>
 /// <param name="max">maximum coord for label area</param>
 public void Draw(ILRenderProperties p, ILPoint3Df min, ILPoint3Df max) {
     if (!String.IsNullOrEmpty(Text)) {
         if (m_expression != m_cachedExpression) 
             interprete(m_expression);
         m_renderer.Begin(p);
         m_renderer.Draw(m_renderQueue,min.X,min.Y,min.Z,max.X,max.Y,max.Z, m_color);
         m_renderer.End(p);
     }
 }
Пример #37
0
        protected void createQuads(ILBaseArray data) {
            if (data == null || data.Length == 0) {
                Clear(); 
                m_quads = new ILQuad[0];
            } else {
                Clear(); 
                m_quads = new ILQuad[data.Length]; 
                ILColorEnumerator colors = new ILColorEnumerator(); 
                ILArray<float> fData = null; 
                if (data is ILArray<float>) {
                    fData = (ILArray<float>)data; 
                } else {
                    fData = ILMath.tosingle(data);
                }
                for (int i = 0; i < m_quads.Length; i++) {
                    m_quads[i] = new ILQuad(m_panel); 
                    m_quads[i].Border.Visible = true; 
                    m_quads[i].FillColor = colors.NextColor(); 
                    ILPoint3Df pos = new ILPoint3Df(); 
                    pos.X = i - m_barWidth / 2; 
                    pos.Y = 0; 
                    pos.Z = -0.5f; 
                    m_quads[i].Vertices[0].Position = pos; 
                    pos.X += m_barWidth; 
                    m_quads[i].Vertices[1].Position = pos; 
                    pos.Y += fData.GetValue(i); 
                    m_quads[i].Vertices[2].Position = pos; 
                    pos.X -= m_barWidth; 
                    m_quads[i].Vertices[3].Position = pos; 
                    // label the bar
                    m_quads[i].Label.Text = i.ToString(); 
                    m_quads[i].Label.Anchor = new PointF(.5f,-1);   

                    // bars will be transparent, oldest fading to OpacityOldest
                    m_quads[i].Opacity = (byte)(m_oldestOpacity + i * (255 - m_oldestOpacity) / m_quads.Length); 
                    // add the bar to the scene graph node (base)
                    Add(m_quads[i]); 
                }
            }
        }
Пример #38
0
 /// <summary>
 /// (internal use)
 /// </summary>
 /// <param name="p">render properties</param>
 /// <param name="center">center position for the label</param>
 public void Draw(ILRenderProperties p, ILPoint3Df center ) {
     if (!String.IsNullOrEmpty(Text)) {
         if (m_expression != m_cachedExpression) 
             interprete(m_expression);
         double[] modelview = null;
         m_renderer.Begin(p, ref modelview);
         Point dest = m_panel.World2Screen(center, modelview);
         offsetAlignment(m_size, ref dest);
         if (m_fringeColor.IsEmpty) {
             m_renderer.Draw(m_renderQueue, dest, TextOrientation.Horizontal, m_color);
         } else {
             drawFringed(m_renderer, m_renderQueue, dest, TextOrientation.Horizontal, m_color); 
         }
         m_renderer.End(p); 
     }
 }
Пример #39
0
        /// <summary>
        /// add 'new' bar with new value and remove oldest bar
        /// </summary>
        /// <param name="value">height of new bar</param>
        /// <returns>discarded value</returns>
        public float Queue(float value) {
            // we move all shapes by 1 left
            ILPoint3Df offset = new ILPoint3Df(-1f,0,0);
            for (int i = 0; i < m_quads.Length; i++) {
                m_quads[i].Translate(offset);
                // FADE OUt old barsss .... 
                m_quads[(i + m_oldestBarIndex) % (m_quads.Length - 1)].Opacity
                    = (byte)(m_oldestOpacity + i * (255 - m_oldestOpacity) / m_quads.Length);
                // tell the scene to update its size
                m_quads[i].Invalidate();
            }
            // configure oldest graph
            ILQuad newestQuad = m_quads[m_oldestBarIndex];
            offset.X = m_quads.Length; 
            newestQuad.Translate(offset);
            float ret = newestQuad.Vertices[2].YPosition; 
            newestQuad.Vertices[2].YPosition = value;
            newestQuad.Vertices[3].YPosition = value;
            newestQuad.Opacity = 255; 

            if (++m_oldestBarIndex >= m_quads.Length) 
                m_oldestBarIndex = 0; 
            return ret;        
        }
Пример #40
0
 public override Point World2Screen(ILPoint3Df world, double[] modelview) {
     Vector3 w = new Vector3(world.X, world.Y, world.Z);
     Vector3 screen;
     Glu.Project(w,modelview, m_projMatrix, m_viewMatrix, out screen);
     return new Point((int)screen.X,(int)(ClientSize.Height - screen.Y));
 }
Пример #41
0
 /// <summary>
 /// Transform 2 world coordinates into screen coords under current matrices
 /// </summary>
 /// <param name="p1_3D">world coord point 1</param>
 /// <param name="p2_3D">world coord point 2</param>
 /// <param name="p1_2D">(output) screen coord point 1</param>
 /// <param name="p2_2D">(output) screen coord point 2</param>
 public override void World2Screen(ILPoint3Df p1_3D, ILPoint3Df p2_3D, out Point p1_2D, out Point p2_2D) {
     Vector3 s = new Vector3();
     Vector3 e = new Vector3();
     Glu.Project(new Vector3(p1_3D.X, p1_3D.Y, p1_3D.Z),
                 m_modelViewMatrix, m_projMatrix, m_viewMatrix, out s);
     Glu.Project(new Vector3(p2_3D.X, p2_3D.Y, p2_3D.Z),
                 m_modelViewMatrix, m_projMatrix, m_viewMatrix, out e);
     p1_2D = new Point((int)s.X,(int)(ClientSize.Height - s.Y));
     p2_2D = new Point((int)e.X,(int)(ClientSize.Height - e.Y));
 }
Пример #42
0
 /// <summary>
 /// transform from screen space into world space using OpenGL
 /// </summary>
 /// <param name="x">screen X</param>
 /// <param name="y">screen Y</param>
 /// <returns>world coord</returns>
 public override void Screen2World(int x, int y, out ILPoint3Df nearClip, out ILPoint3Df farClip) {
     // TODO: check the Z coord values. 0.68 here was result of trial only! 
     Vector3 far,near; 
     Glu.UnProject(new Vector3(x, y, 0.0f),m_modelViewMatrix, m_projMatrix, m_viewMatrix, out near);
     Glu.UnProject(new Vector3(x, y, 1.0f),m_modelViewMatrix, m_projMatrix, m_viewMatrix, out far);
     // transform back from unit cube to clipping view
     farClip = new ILPoint3Df(far.X,far.Y,far.Z);  //m_clippingView.Map(far.X, far.Y, far.Z);
     nearClip = new ILPoint3Df(near.X, near.Y, near.Z); //m_clippingView.Map(near.X, near.Y, near.Z);
 }