Пример #1
0
        /// <summary>
        ///     Use method to invert an input transform matrix about a given origin.
        ///     Could help when combining transformation for stages with inverted axis.
        /// </summary>
        /// <param name="taskHandler">An implementation of the process configuration tasks</param>
        /// <param name="parentTransform">The parent transform in the chain of transformations</param>
        /// <param name="transform">The input transformation</param>
        /// <param name="ctIn">A cancellation token</param>
        /// <returns>The input matrix flip about it's parent's transform</returns>
        public async Task <Matrix4x4> InvertTransform(IProcessConfigurationTasksHandler taskHandler, Matrix4x4 parentTransform, Matrix4x4 transform, CancellationToken ctIn)
        {
            var origin = new MarkGeometryPoint();

            origin.Transform(parentTransform);

            var inverts = await taskHandler.GetStageInverts(ctIn);

            return(GeometricArithmeticModule.CombineTransformations(
                       // flip about the base transform's origin
                       GeometricArithmeticModule.GetTranslationTransformationMatrix(
                           -origin.X, -origin.Y, -origin.Z
                           ),

                       // apply the next transform
                       transform,

                       // flip the next transform on the requested x-axis
                       GeometricArithmeticModule.GetScalingTransformationMatrix(
                           inverts.InvertX ? -1 : 1,
                           inverts.InvertY ? -1 : 1
                           ),

                       // translate back to the base transform's origin
                       GeometricArithmeticModule.GetTranslationTransformationMatrix(
                           origin.X, origin.Y, origin.Z
                           )
                       ));
        }
Пример #2
0
        public Matrix4x4 ToMatrix4x4()
        {
            return(GeometricArithmeticModule.CombineTransformations(
                       // apply scale
                       GeometricArithmeticModule.GetScalingTransformationMatrix(
                           ScaleX, ScaleY, ScaleZ
                           ),

                       // apply rotation - don't forget to convert degrees to radians
                       GeometricArithmeticModule.GetRotationTransformationMatrix(
                           GeometricArithmeticModule.ToRadians(RotationDegX),
                           GeometricArithmeticModule.ToRadians(RotationDegY),
                           GeometricArithmeticModule.ToRadians(RotationDegZ)
                           ),

                       // apply offset
                       GeometricArithmeticModule.GetTranslationTransformationMatrix(
                           OffsetX, OffsetY, OffsetZ
                           )
                       ));
        }
Пример #3
0
        public bool SaveImage(string filePath)
        {
            var bitmap = new Bitmap(
                480, 480,
                PixelFormat.Format24bppRgb
                );

            var shader = new GeometryShader2D();

            shader.UpdateSettings(1, 1, Color.Red, Color.Green, Color.Transparent);

            shader.Reset(bitmap, Color.Black);

            var xScale = bitmap.Width / Boundary.Extents.Width;
            var yScale = bitmap.Height / Boundary.Extents.Height;

            // calculate transform
            var transformationMatrix = GeometricArithmeticModule.CombineTransformations(
                // centre geometries at origin before scaling
                GeometricArithmeticModule.GetTranslationTransformationMatrix(
                    -Boundary.Extents.Centre.X,
                    -Boundary.Extents.Centre.Y
                    ),
                // scale geometries to fit the target bitmap
                GeometricArithmeticModule.GetScalingTransformationMatrix(
                    xScale,
                    -yScale
                    ),
                // centre geometries in target bitmap
                GeometricArithmeticModule.GetTranslationTransformationMatrix(
                    0.5 * bitmap.Width,
                    0.5 * bitmap.Height
                    )
                );

            Draw(bitmap, shader, transformationMatrix);
            return(shader.WriteToFile(bitmap, filePath, PixelFormat.Format24bppRgb, 120, 120, GeometryShader2D.OptimisationSetting.Default));
        }