Esempio n. 1
0
        public virtual void DrawLine(PenX3D pen, IPolylineD3D path)
        {
            var asStraightLine = path as StraightLineAsPolylineD3D;

            if (null != asStraightLine)
            {
                DrawLine(pen, asStraightLine.GetPoint(0), asStraightLine.GetPoint(1));
                return;
            }
            else if (path.Count == 2)
            {
                DrawLine(pen, path.GetPoint(0), path.GetPoint(1));
                return;
            }

            //var line = new SolidPolyline(pen.CrossSection, asSweepPath.Points);
            var buffers = GetPositionNormalIndexedTriangleBuffer(pen.Material);
            var offset  = buffers.IndexedTriangleBuffer.VertexCount;

            if (null != buffers.PositionNormalIndexedTriangleBuffer)
            {
                var buf           = buffers.PositionNormalIndexedTriangleBuffer;
                var solidPolyline = new SolidPolyline();
                solidPolyline.AddWithNormals(
                    (position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z),
                    (i0, i1, i2, isLeftCos) => buf.AddTriangleIndices(i0, i1, i2, isLeftCos),
                    ref offset,
                    pen,
                    path.Points);
            }
            else if (null != buffers.PositionNormalColorIndexedTriangleBuffer)
            {
                var buf   = buffers.PositionNormalColorIndexedTriangleBuffer;
                var color = pen.Color.Color;
                var r     = color.ScR;
                var g     = color.ScG;
                var b     = color.ScB;
                var a     = color.ScA;

                var solidPolyline = new SolidPolyline();
                solidPolyline.AddWithNormals(
                    (position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z, r, g, b, a),
                    (i0, i1, i2, isLeftCos) => buf.AddTriangleIndices(i0, i1, i2, isLeftCos),
                    ref offset,
                    pen,
                    path.Points);
            }
            else if (null != buffers.PositionNormalUVIndexedTriangleBuffer)
            {
                throw new NotImplementedException("Texture on a line is not supported yet");
            }
            else
            {
                throw new NotImplementedException("Unexpected type of buffer: " + buffers.IndexedTriangleBuffer.GetType().ToString());
            }

            return;
        }
Esempio n. 2
0
 /// <summary>
 /// Get a line along the axis designated by the argument id from the logical values r0 to r1.
 /// </summary>
 /// <param name="path">Graphics path.</param>
 /// <param name="id">Axis to draw the isoline along.</param>
 /// <param name="r0">Start point of the isoline. The logical value of the other coordinate.</param>
 /// <param name="r1">End point of the isoline. The logical value of the other coordinate.</param>
 public virtual void GetIsolineFromTo(CSLineID id, double r0, double r1, out IPolylineD3D path)
 {
     if (id.ParallelAxisNumber == 0)
     {
         path = GetIsoline(new Logical3D(r0, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond), new Logical3D(r1, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond));
     }
     else if (id.ParallelAxisNumber == 1)
     {
         path = GetIsoline(new Logical3D(id.LogicalValueOtherFirst, r0, id.LogicalValueOtherSecond), new Logical3D(id.LogicalValueOtherFirst, r1, id.LogicalValueOtherSecond));
     }
     else
     {
         path = GetIsoline(new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r0), new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r1));
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Gets an isoline beginning from a given point to the axis.
 /// </summary>
 /// <param name="path">Graphics path to fill with the isoline.</param>
 /// <param name="r">Logical coordinate of the start point.</param>
 /// <param name="id">The logical plane to end the isoline.</param>
 public virtual void GetIsolineFromPointToPlane(Logical3D r, CSPlaneID id, out IPolylineD3D path)
 {
     if (id.PerpendicularAxisNumber == 0)
     {
         path = GetIsoline(r, new Logical3D(id.LogicalValue, r.RY, r.RZ));
     }
     else if (id.PerpendicularAxisNumber == 1)
     {
         path = GetIsoline(r, new Logical3D(r.RX, id.LogicalValue, r.RZ));
     }
     else
     {
         path = GetIsoline(r, new Logical3D(r.RX, r.RY, id.LogicalValue));
     }
 }
Esempio n. 4
0
		/// <summary>
		/// Get a line along the axis designated by the argument id from the logical values r0 to r1.
		/// </summary>
		/// <param name="path">Graphics path.</param>
		/// <param name="id">Axis to draw the isoline along.</param>
		/// <param name="r0">Start point of the isoline. The logical value of the other coordinate.</param>
		/// <param name="r1">End point of the isoline. The logical value of the other coordinate.</param>
		public virtual void GetIsolineFromTo(CSLineID id, double r0, double r1, out IPolylineD3D path)
		{
			if (id.ParallelAxisNumber == 0)
			{
				path = GetIsoline(new Logical3D(r0, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond), new Logical3D(r1, id.LogicalValueOtherFirst, id.LogicalValueOtherSecond));
			}
			else if (id.ParallelAxisNumber == 1)
			{
				path = GetIsoline(new Logical3D(id.LogicalValueOtherFirst, r0, id.LogicalValueOtherSecond), new Logical3D(id.LogicalValueOtherFirst, r1, id.LogicalValueOtherSecond));
			}
			else
			{
				path = GetIsoline(new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r0), new Logical3D(id.LogicalValueOtherFirst, id.LogicalValueOtherSecond, r1));
			}
		}
Esempio n. 5
0
		/// <summary>
		/// Draws an isoline on a plane beginning from r0 to r1. For r0,r1 either ry0,ry1 is used (if it is an x-axis),
		/// otherwise rx0,rx1 is used. The other parameter pair is not used.
		/// </summary>
		/// <param name="path">Graphics path to fill with the isoline.</param>
		/// <param name="r0">Logical coordinate of the start point.</param>
		/// <param name="r1">Logical coordinate of the end point.</param>
		/// <param name="id">The axis to end the isoline.</param>
		public virtual void GetIsolineOnPlane(CSPlaneID id, Logical3D r0, Logical3D r1, IPolylineD3D path)
		{
			if (id.PerpendicularAxisNumber == 0)
			{
				path = GetIsoline(new Logical3D(id.LogicalValue, r0.RY, r0.RZ), new Logical3D(id.LogicalValue, r1.RY, r1.RZ));
			}
			else if (id.PerpendicularAxisNumber == 1)
			{
				path = GetIsoline(new Logical3D(r0.RX, id.LogicalValue, r0.RZ), new Logical3D(r1.RX, id.LogicalValue, r1.RZ));
			}
			else
			{
				path = GetIsoline(new Logical3D(r0.RX, r0.RY, id.LogicalValue), new Logical3D(r1.RX, r1.RY, id.LogicalValue));
			}
		}
Esempio n. 6
0
		/// <summary>
		/// Gets an isoline beginning from a given point to the axis.
		/// </summary>
		/// <param name="path">Graphics path to fill with the isoline.</param>
		/// <param name="r">Logical coordinate of the start point.</param>
		/// <param name="id">The logical plane to end the isoline.</param>
		public virtual void GetIsolineFromPointToPlane(Logical3D r, CSPlaneID id, out IPolylineD3D path)
		{
			if (id.PerpendicularAxisNumber == 0)
			{
				path = GetIsoline(r, new Logical3D(id.LogicalValue, r.RY, r.RZ));
			}
			else if (id.PerpendicularAxisNumber == 1)
			{
				path = GetIsoline(r, new Logical3D(r.RX, id.LogicalValue, r.RZ));
			}
			else
			{
				path = GetIsoline(r, new Logical3D(r.RX, r.RY, id.LogicalValue));
			}
		}
Esempio n. 7
0
 /// <summary>
 /// Draws an isoline on a plane beginning from r0 to r1. For r0,r1 either ry0,ry1 is used (if it is an x-axis),
 /// otherwise rx0,rx1 is used. The other parameter pair is not used.
 /// </summary>
 /// <param name="path">Graphics path to fill with the isoline.</param>
 /// <param name="r0">Logical coordinate of the start point.</param>
 /// <param name="r1">Logical coordinate of the end point.</param>
 /// <param name="id">The axis to end the isoline.</param>
 public virtual void GetIsolineOnPlane(CSPlaneID id, Logical3D r0, Logical3D r1, IPolylineD3D path)
 {
     if (id.PerpendicularAxisNumber == 0)
     {
         path = GetIsoline(new Logical3D(id.LogicalValue, r0.RY, r0.RZ), new Logical3D(id.LogicalValue, r1.RY, r1.RZ));
     }
     else if (id.PerpendicularAxisNumber == 1)
     {
         path = GetIsoline(new Logical3D(r0.RX, id.LogicalValue, r0.RZ), new Logical3D(r1.RX, id.LogicalValue, r1.RZ));
     }
     else
     {
         path = GetIsoline(new Logical3D(r0.RX, r0.RY, id.LogicalValue), new Logical3D(r1.RX, r1.RY, id.LogicalValue));
     }
 }
Esempio n. 8
0
		public virtual void DrawLine(PenX3D pen, IPolylineD3D path)
		{
			var asStraightLine = path as StraightLineAsPolylineD3D;

			if (null != asStraightLine)
			{
				DrawLine(pen, asStraightLine.GetPoint(0), asStraightLine.GetPoint(1));
				return;
			}
			else if (path.Count == 2)
			{
				DrawLine(pen, path.GetPoint(0), path.GetPoint(1));
				return;
			}

			//var line = new SolidPolyline(pen.CrossSection, asSweepPath.Points);
			var buffers = GetPositionNormalIndexedTriangleBuffer(pen.Material);
			var offset = buffers.IndexedTriangleBuffer.VertexCount;

			if (null != buffers.PositionNormalIndexedTriangleBuffer)
			{
				var buf = buffers.PositionNormalIndexedTriangleBuffer;
				var solidPolyline = new SolidPolyline();
				solidPolyline.AddWithNormals(
				(position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z),
				(i0, i1, i2, isLeftCos) => buf.AddTriangleIndices(i0, i1, i2, isLeftCos),
				ref offset,
				pen,
				path.Points);
			}
			else if (null != buffers.PositionNormalColorIndexedTriangleBuffer)
			{
				var buf = buffers.PositionNormalColorIndexedTriangleBuffer;
				var color = pen.Color.Color;
				var r = color.ScR;
				var g = color.ScG;
				var b = color.ScB;
				var a = color.ScA;

				var solidPolyline = new SolidPolyline();
				solidPolyline.AddWithNormals(
				(position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z, r, g, b, a),
				(i0, i1, i2, isLeftCos) => buf.AddTriangleIndices(i0, i1, i2, isLeftCos),
				ref offset,
				pen,
				path.Points);
			}
			else if (null != buffers.PositionNormalUVIndexedTriangleBuffer)
			{
				throw new NotImplementedException("Texture on a line is not supported yet");
			}
			else
			{
				throw new NotImplementedException("Unexpected type of buffer: " + buffers.IndexedTriangleBuffer.GetType().ToString());
			}

			return;
		}
Esempio n. 9
0
        /// <summary>
        /// Template to make a line draw.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="pdata">The plot data. Don't use the Range property of the pdata, since it is overriden by the next argument.</param>
        /// <param name="range">The plot range to use.</param>
        /// <param name="layer">Graphics layer.</param>
        /// <param name="pen">The pen to draw the line.</param>
        /// <param name="symbolGap">The size of the symbol gap. Argument is the original index of the data. The return value is the absolute symbol gap at this index. This function is null if no symbol gap is required.</param>
        /// <param name="skipFrequency">Skip frequency. Normally 1, thus all gaps are taken into account. If 2, only every 2nd gap is taken into account, and so on.</param>
        /// <param name="connectCircular">If true, the end of the line is connected with the start of the line.</param>
        public override void Paint(
            IGraphicsContext3D g,
            Processed3DPlotData pdata,
            PlotRange range,
            IPlotArea layer,
            PenX3D pen,
            Func <int, double> symbolGap,
            int skipFrequency,
            bool connectCircular)
        {
            var linePoints = pdata.PlotPointsInAbsoluteLayerCoordinates;
            var linepts    = new PointD3D[range.Length + (connectCircular ? 1 : 0)];

            Array.Copy(linePoints, range.LowerBound, linepts, 0, range.Length); // Extract
            if (connectCircular)
            {
                linepts[linepts.Length - 1] = linepts[0];
            }
            int lastIdx   = range.Length - 1 + (connectCircular ? 1 : 0);
            var layerSize = layer.Size;

            if (symbolGap != null)
            {
                if (skipFrequency <= 1) // skip all scatter symbol gaps -> thus skipOffset can be ignored
                {
                    for (int i = 0; i < lastIdx; i++)
                    {
                        int    originalIndex = range.OffsetToOriginal + i;
                        var    diff          = linepts[i + 1] - linepts[i];
                        double gapAtStart    = symbolGap(originalIndex);
                        double gapAtEnd      = i != (range.Length - 1) ? symbolGap(originalIndex + 1) : symbolGap(range.OffsetToOriginal);
                        var    relAtStart    = 0.5 * gapAtStart / diff.Length; // 0.5 because symbolGap is the full gap between two lines, thus between the symbol center and the beginning of the line it is only 1/2
                        var    relAtEnd      = 0.5 * gapAtEnd / diff.Length;   // 0.5 because symbolGap is the full gap between two lines, thus between the symbol center and the beginning of the line it is only 1/2
                        if ((relAtStart + relAtEnd) < 1)                       // a line only appears if sum of the gaps  is smaller than 1
                        {
                            var start = linepts[i] + relAtStart * diff;
                            var stop  = linepts[i + 1] - relAtEnd * diff;

                            g.DrawLine(pen, start, stop);
                        }
                    } // end for
                }     // skipFrequency was 1
                else  // skipFrequency is > 1
                {
                    for (int i = 0; i < lastIdx; i += skipFrequency)
                    {
                        int originalRowIndex = range.OriginalFirstPoint + i;

                        double gapAtStart = symbolGap(originalRowIndex);
                        double gapAtEnd   = i != range.Length ? symbolGap(originalRowIndex + skipFrequency) : symbolGap(range.OffsetToOriginal);

                        IPolylineD3D polyline = SharpPolylineD3D.FromPointsWithPossibleDublettes(linepts.Skip(i).Take(1 + skipFrequency));
                        polyline = polyline.ShortenedBy(RADouble.NewAbs(gapAtStart / 2), RADouble.NewAbs(gapAtEnd / 2));

                        if (null != polyline)
                        {
                            g.DrawLine(pen, polyline);
                        }
                    } // end for.
                }
            }
            else // no line symbol gap required, so we can use DrawLines to draw the lines
            {
                if (linepts.Length > 1) // we don't want to have a drawing exception if number of points is only one
                {
                    g.DrawLine(pen, SharpPolylineD3D.FromPointsWithPossibleDublettes(linepts));
                }
            }
        }