IPickedGeometry IColorCodedPicking.Pick(uint stageVertexID)
        {
            IColorCodedPicking    element        = this as IColorCodedPicking;
            PickedGeometryIndexed pickedGeometry = element.TryPick <PickedGeometryIndexed>(
                PrimitiveModes.TriangleStrip, stageVertexID);

            if (pickedGeometry == null)
            {
                return(null);
            }

            // Fill primitive's positions and colors. This maybe changes much more than lines above in second dev.
            uint lastVertexID;

            if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
            {
                pickedGeometry.CubeIndex = lastVertexID / 8;
                var vertexIndex = lastVertexID % 8;
                pickedGeometry.positions = new vec3[1] {
                    unitCubePos[vertexIndex]
                };
            }

            return(pickedGeometry);
        }
Esempio n. 2
0
        public override string ToString()
        {
            var positions = this.positions;

            if (positions == null)
            {
                positions = new vec3[0];
            }

            string strPositions = positions.PrintArray();

            uint stageVertexID         = this.StageVertexID;
            IColorCodedPicking picking = this.From;

            string lastVertexID = "?";

            if (picking != null)
            {
                uint tmp;
                if (picking.GetLastVertexIDOfPickedGeometry(stageVertexID, out tmp))
                {
                    lastVertexID = string.Format("{0}", tmp);
                }
            }

            string result = string.Format("{0}: P: {1} vertex ID:{2}/{3} ∈{4}",
                                          GeometryType, strPositions, lastVertexID, stageVertexID, From);

            return(result);
            //return base.ToString();
        }
Esempio n. 3
0
        /// <summary>
        /// Get the primitive of <paramref name="element"/> according to vertex's id.
        /// <para>Returns <code>null</code> if <paramref name="element"/> is null or <paramref name="stageVertexID"/> does not belong to any of this <paramref name="element"/>'s vertices.</para>
        /// <para>Note: the <paramref name="stageVertexID"/> refers to the last vertex that constructs the primitive. And it's unique in scene's all elements.</para>
        /// </summary>
        /// <typeparam name="T">Subclass of <see cref="IPickedGeometry"/></typeparam>
        /// <param name="element">the scene's element that contains the primitive.</param>
        /// <param name="mode">specifies what type of primitive it is.</param>
        /// <param name="stageVertexID">Refers to the last vertex that constructs the primitive. And it's unique in scene's all elements.</param>
        /// <param name="positions">element's vertices' position array.</param>
        /// <returns></returns>
        public static T TryPick <T>(
            this IColorCodedPicking element, PrimitiveModes mode, uint stageVertexID, float[] positions)
            where T : IPickedGeometry, new()
        {
            if (positions == null)
            {
                throw new ArgumentNullException("positions");
            }

            T pickedGeometry = element.TryPick <T>(mode, stageVertexID);

            // Fill primitive's positions and colors. This maybe changes much more than lines above in second dev.
            if (pickedGeometry != null)
            {
                uint lastVertexID;
                if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
                {
                    int vertexCount = pickedGeometry.GeometryType.GetVertexCount();
                    if (vertexCount == -1)
                    {
                        vertexCount = positions.Length / 3;
                    }
                    float[] geometryPositions = new float[vertexCount * 3];
                    uint    i = lastVertexID * 3 + 2;
                    for (int j = (geometryPositions.Length - 1); j >= 0; i--, j--)
                    {
                        if (i == uint.MaxValue)// This is when mode is GL_LINE_LOOP.
                        {
                            i = (uint)positions.Length - 1;
                        }
                        geometryPositions[j] = positions[i];
                    }

                    var poss = new vec3[vertexCount];
                    for (int t = 0; t < vertexCount; t++)
                    {
                        poss[t] = new vec3(geometryPositions[t * 3 + 0], geometryPositions[t * 3 + 1], geometryPositions[t * 3 + 2]);
                    }
                    pickedGeometry.positions = poss;
                }
            }

            return(pickedGeometry);
        }
        IPickedGeometry IColorCodedPicking.Pick(uint stageVertexID)
        {
            IColorCodedPicking    element        = this as IColorCodedPicking;
            PickedGeometryColored pickedGeometry = element.TryPick <PickedGeometryColored>(
                this.Model.Mode, stageVertexID, this.Model.Positions);

            if (pickedGeometry == null)
            {
                return(null);
            }

            // Fill primitive's positions and colors. This maybe changes much more than lines above in second dev.
            uint lastVertexID;

            if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
            {
                ScientificModel model = this.Model;

                int vertexCount = pickedGeometry.GeometryType.GetVertexCount();
                if (vertexCount == -1)
                {
                    vertexCount = model.VertexCount;
                }

                float[] geometryColors = new float[vertexCount * 3];

                float[] modelColors = model.Colors;

                uint i = lastVertexID * 3 + 2;
                for (int j = (geometryColors.Length - 1); j >= 0; i--, j--)
                {
                    if (i == uint.MaxValue)// This is when mode is GL_LINE_LOOP.
                    {
                        i = (uint)modelColors.Length - 1;
                    }
                    geometryColors[j] = modelColors[i];
                }

                pickedGeometry.colors = geometryColors;
            }

            return(pickedGeometry);
        }
Esempio n. 5
0
        /// <summary>
        /// Get the primitive of <paramref name="element"/> according to vertex's id.
        /// <para>Returns <code>null</code> if <paramref name="element"/> is null or <paramref name="stageVertexID"/> is not in the range of this <paramref name="element"/>.</para>
        /// <para>Note: the <paramref name="stageVertexID"/> Refers to the last vertex that constructs the primitive. And it's unique in scene's all elements.</para>
        /// <para>Note: The result's positions property is not set up as there will be different kinds of storage mode for positions(float[], IntPtr, etc). You have to initialize the positions property and fill correct position information afterwards.</para>
        /// </summary>
        /// <typeparam name="T">Sub type of <see cref="IPickedGeometry"/></typeparam>
        /// <param name="element">the scene's element that contains the primitive.</param>
        /// <param name="mode">specifies what type of primitive it is.</param>
        /// <param name="stageVertexID">Refers to the last vertex that constructs the primitive. And it's unique in scene's all elements.</param>
        /// <returns></returns>
        public static T TryPick <T>(
            this IColorCodedPicking element, PrimitiveModes mode, uint stageVertexID)
            where T : IPickedGeometry, new()
        {
            T pickedGeometry = default(T);

            if (element != null)
            {
                uint lastVertexID;
                if (element.GetLastVertexIDOfPickedGeometry(stageVertexID, out lastVertexID))
                {
                    pickedGeometry = new T();

                    pickedGeometry.GeometryType  = mode.ToGeometryType();
                    pickedGeometry.StageVertexID = stageVertexID;
                    pickedGeometry.From          = element;
                }
            }

            return(pickedGeometry);
        }