Пример #1
0
        public override void Do(IDemoChartControl chartControl)
        {
            // Load bitmap image.
            var colorTextureSource = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Demo.Features;component/Resources/bump01.bmp"));
            float ratio             = (float)colorTextureSource.PixelHeight / colorTextureSource.PixelWidth;

            // Create default reader for Wpf bitmap sources.
            var reader = new BitmapSourceRasterImage2DReader(colorTextureSource);

            // Create bump reader.
            var bumpReader = new BitmapSourceRasterImage2DReader(bumpTextureSource);

            // Create geometry for both raster data-s.
            var geometry = new RectTextureGeometry
            {
                Origin     = Vector3F.Zero,
                DirectionX = Vector3F.UnitX,
                DirectionY = Vector3F.UnitY,
                Size       = new Vector2F(1f, ratio)
            };

            // Create non-bump raster data object.
            var rasterData = new RasterData
            {
                // Set image interpolation type.
                InterpolationType = RasterDataInterpolationType.Linear,
                // Set image reader.
                Reader = reader,
                // Set name.
                Name = "Default",
                // Set geometry
                Geometry = geometry
            };

            // Create bump render data object.
            var bumpRasterData = new RasterData
            {
                // Set image interpolation type.
                InterpolationType = RasterDataInterpolationType.Linear,
                // Set image reader.
                Reader = reader,
                // Set bump image reader.
                BumpReader = bumpReader,
                // Set name.
                Name = "Bump",
                // Specify some material custom settings.
                Material = new RenderMaterial(0.25f, 0.6f, 0.6f, 0f, 0f),
                // Set geometry
                Geometry = geometry
            };

            // Setup bump raster data offset matrix.
            bumpRasterData.Transform = Matrix4F.Translation(1.25f, 0, 0);

            // Setup chart data source.
            chartControl.DataSource = new RenderData[] { rasterData, bumpRasterData };
        }
Пример #2
0
        public override void Do(IDemoChartControl chartControl)
        {
            const int   pointsCount = 1_000;
            const float amplitude   = 0.6f;

            // Calculate points on line.
            var points = new Vector3F[pointsCount];

            for (var i = 0; i < pointsCount; i++)
            {
                float scaledCoord = i / (float)pointsCount;
                points[i] = new Vector3F(
                    scaledCoord,
                    amplitude * (float)(Math.Cos(5 * 2 * Math.PI * scaledCoord) + 0.5f),
                    amplitude * (float)(Math.Sin(5 * Math.PI * scaledCoord) + 0.5f));
            }

            // Create line.
            var line = new Line
            {
                Points    = points,
                Strip     = true,
                Color     = Colors.Blue,
                Thickness = 3,
                Name      = "Main line"
            };

            // Add labels.
            const int labelStep  = 100;
            var       renderData = new List <RenderData> {
                line
            };
            int labelIndex = 0;

            for (var i = 0; i < pointsCount; i += labelStep)
            {
                renderData.Add(new Label
                {
                    Text       = (i / labelStep).ToString(),
                    FontFamily = "Arial",
                    FontSize   = 18,
                    Transform  = Matrix4F.Translation(points[i]),
                    Background = Colors.White,
                    Name       = $"Label {labelIndex++}"
                });
            }

            // Show axes.
            chartControl.Axes.IsAxes3DVisible = true;

            // Show result.
            chartControl.DataSource = renderData.ToArray();
        }
Пример #3
0
        public override void Do(IDemoChartControl chartControl)
        {
            // Create mesh for rendering. We need a cube.
            Mesh cubeMesh = CubeMeshFactory.GenerateCube();

            // Generates cube transformation matrixes and it's colors.
            Matrix4F[] transformations = new Matrix4F[TotalBarCount];
            Color4[]   colors          = new Color4[TotalBarCount];
            int        index           = 0;

            for (int x = 0; x < GridSize; x++)
            {
                for (int y = 0; y < GridSize; y++)
                {
                    // Randomize block height.
                    float height = (float)random.NextDouble() * MaxHeight;
                    // Compute current bar transformation matrix.
                    // Scaling matrix is used for size scaling. Translation matrix is used for positioning.
                    transformations[index] = Matrix4F.Scaling(BlockSize, BlockSize, height) *
                                             Matrix4F.Translation(GridStep * x, GridStep * y, height / 2);
                    // Randomize color.
                    colors[index] = DemoHelper.RandomizeColor();
                    index++;
                }
            }

            // Create presentation object.
            var primitiveCollection = new MultiColorPrimitiveCollection
            {
                // Set mesh.
                Mesh = cubeMesh,
                // Set name.
                Name = "Bars",
                // Set custom material.
                Material = new RenderMaterial(0.35f, 0.5f, 0.6f, 0.0f, 0.0f)
            };

            // Set transforms.
            primitiveCollection.SetTransformsAndColor(transformations, colors);

            // Set chart options.
            chartControl.Axes.IsAxes3DVisible = true;

            // Set data source.
            chartControl.DataSource = primitiveCollection;
        }
Пример #4
0
            public DistanceWidget()
            {
                Marker CreateMarker(Vector3F position, Color4 color, int pixelSize, string name)
                {
                    // Create marker internal data.
                    var markerData = new Sphere
                    {
                        Color = color,
                        // Assign interactor to the render data.
                        Interactor = new MarkerInteractor(),
                    };

                    // Create marker object.
                    var marker = new Marker(markerData)
                    {
                        // Set it's pixel size.
                        PixelSize = pixelSize,
                        // Set it's translation.
                        Transform = Matrix4F.Translation(position),
                        // Set it's name.
                        Name = name
                    };

                    // Set render data parent as tag because we'll use it in it's interactor.
                    markerData.Tag = marker;

                    return(marker);
                }

                // Create markers.
                Marker firstMarker  = CreateMarker(new Vector3F(0.2f), Colors.Blue, 50, "Marker 1");
                Marker secondMarker = CreateMarker(new Vector3F(0.8f), Colors.Green, 50, "Marker 2");

                // Create distance line.
                var line = new Line
                {
                    Color     = Colors.Black,
                    Thickness = 3.0f,
                    Name      = "Line",
                };

                Line CreateLabelOffsetLine() =>
                new Line
                {
                    Color           = Colors.DarkRed,
                    Thickness       = 1.0f,
                    IsLegendVisible = false
                };

                Label CreateInfoLabel() =>
                new Label
                {
                    IsLegendVisible = false,
                    FontColor       = Colors.Black,
                    Background      = Colors.White,
                    BorderColor     = Colors.Black,
                    MarkerColor     = Colors.DarkRed,
                    MarkerRadius    = 5,
                    BorderThickness = 1,
                    FontFamily      = "Tahoma",
                    FontSize        = 12
                };

                string ToString(Vector3F position) => $"{position.X:G3}; {position.Y:G3}; {position.Z:G3}";

                // Create label offset lines.
                Line distanceLabelOffsetLine = CreateLabelOffsetLine();
                Line firstLabelOffsetLine    = CreateLabelOffsetLine();
                Line secondLabelOffsetLine   = CreateLabelOffsetLine();

                // Create info labels.
                Label distanceLabel = CreateInfoLabel();
                Label firstLabel    = CreateInfoLabel();
                Label secondLabel   = CreateInfoLabel();

                void ResetLinePoints()
                {
                    const float labelOffsetLength = 0.4f;

                    // Reset line points according to markers positions.
                    line.Points = new[] { firstMarker.Transform.GetTranslation(), secondMarker.Transform.GetTranslation() };

                    // Reset label position as center of distance line.
                    Vector3F lineCenter          = (line.Points[0] + line.Points[1]) / 2;
                    Vector3F lineDirectionVector = (line.Points[0] - line.Points[1]).GetNormalized();
                    Vector3F labelOffsetVector   = lineDirectionVector.Cross(Vector3F.UnitZ);
                    Vector3F totalOffset         = labelOffsetLength * labelOffsetVector;

                    distanceLabel.Position         = lineCenter + labelOffsetLength * labelOffsetVector;
                    firstLabel.Position            = firstMarker.Transform.GetTranslation() + totalOffset;
                    secondLabel.Position           = secondMarker.Transform.GetTranslation() + totalOffset;
                    distanceLabelOffsetLine.Points = new[] { lineCenter, lineCenter + totalOffset };
                    firstLabelOffsetLine.Points    = new[] { line.Points[0], line.Points[0] + totalOffset };
                    secondLabelOffsetLine.Points   = new[] { line.Points[1], line.Points[1] + totalOffset };

                    // Reset label text as distance.
                    distanceLabel.Text = (line.Points[0] - line.Points[1]).GetLength().ToString("G4");
                    firstLabel.Text    = ToString(line.Points[0]);
                    secondLabel.Text   = ToString(line.Points[1]);
                }

                // Attach property handlers.
                firstMarker.PropertyChanged += (sender, e) =>
                {
                    if (e.PropertyName == nameof(RenderData.Transform))
                    {
                        ResetLinePoints();
                    }
                    ;
                };
                secondMarker.PropertyChanged += (sender, e) =>
                {
                    if (e.PropertyName == nameof(RenderData.Transform))
                    {
                        ResetLinePoints();
                    }
                };
                ResetLinePoints();

                // Add elements to the container collection.
                Collection.Add(firstMarker);
                Collection.Add(secondMarker);
                Collection.Add(line);
                Collection.Add(firstLabelOffsetLine);
                Collection.Add(secondLabelOffsetLine);
                Collection.Add(distanceLabelOffsetLine);
                Collection.Add(firstLabel);
                Collection.Add(secondLabel);
                Collection.Add(distanceLabel);
            }