Пример #1
0
        private GeometryExtents <double> AddLayer(MRecipe recipe, MRecipeDeviceLayer layer)
        {
            var extents = GeometryExtents <double> .CreateDefaultDouble();

            // calculate layer's transform
            var transform = MRecipe.GetRelativeTransform(recipe, layer);

            // fetch geometries from pattern file
            var geometries = _fetchDxfFunc(layer.PatternFilePath);

            for (int i = 0; i < geometries?.Count; i++)
            {
                var clone = (IMarkGeometry)geometries[i].Clone();
                clone.Transform(transform);

                // render geometry
                AddDefault(
                    clone,
                    DefaultColor
                    );

                // update extents
                extents = GeometryExtents <double> .Combine(
                    extents,
                    clone.Extents
                    );
            }

            return(extents);
        }
Пример #2
0
        /// <summary>
        ///     Get geometries in DXF file.
        /// </summary>
        /// <param name="callback">An action to consume geometries as they are read from the file.</param>
        /// <param name="howmany">Howmany geometries to read</param>
        /// <returns>Returns a count and Extents of the geometries consumed.</returns>
        public (int Count, GeometryExtents <double> Extents) BeginGetGeometries(Action <string, IMarkGeometry> callback, int howmany = int.MaxValue)
        {
            _count  = 0;
            howmany = howmany < 0 ? int.MaxValue : howmany;
            var extents = GeometryExtents <double> .CreateDefaultDouble();

            using (var reader = new AdvancedLineStreamReader(_filePath))
            {
                string layerName;
                List <IMarkGeometry> geometries = null;

                while (
                    !reader.EndOfStream &&
                    _count < howmany
                    )
                {
                    (layerName, geometries) = ParseEntity(reader);

                    if (geometries != null)
                    {
                        foreach (var geometry in geometries)
                        {
                            _count += 1;
                            extents = GeometryExtents <double> .Combine(extents, geometry.Extents);

                            callback((layerName == null) ? "0" : layerName, geometry);
                        }
                    }
                }
            }

            return(_count, extents);
        }
Пример #3
0
        public virtual void AddRecipeNode(MRecipe recipe, MRecipeBaseNode recipeNode)
        {
            if (recipe == null || recipeNode == null)
            {
                return;
            }

            var extents = GeometryExtents <double> .CreateDefaultDouble();

            MRecipe.BeginGetAllLayers_Parallel(recipeNode, (layer) =>
            {
                extents = GeometryExtents <double> .Combine(
                    extents,
                    AddLayer(recipe, layer)
                    );
            });

            // calculate size of fiducial relative to the node
            var fiducialSize = 0.025 * extents.Hypotenuse;

            // generate fiducial pattern
            GenerateFiducialPattern(fiducialSize);

            // get node's transform
            var parentsTransform = (recipeNode.Parent as MRecipeBaseNode)?.TransformInfo.ToMatrix4x4() ?? GeometricArithmeticModule.GetDefaultTransformationMatrix();

            // render fiducials in parent's reference frame
            foreach (var fiducial in recipeNode.Fiducials)
            {
                var transform = GeometricArithmeticModule.CombineTransformations(
                    GeometricArithmeticModule.GetTranslationTransformationMatrix(
                        fiducial.X, fiducial.Y, fiducial.Z
                        ),
                    parentsTransform
                    );

                foreach (var geometry in _fiducialPattern)
                {
                    var clone = (IMarkGeometry)geometry.Clone();
                    clone.Transform(transform);
                    AddDefault(clone, FiducialColor);
                }
            }
        }
Пример #4
0
        public void Render()
        {
            _terminableTaskExecutor.CancelCurrentAndRun(
                (ctIn) =>
            {
                // reset shader
                MShader.Reset();

                if (_geometriesBuffer != null)
                {
                    int count   = 0;
                    var extents = GeometryExtents <double> .CreateDefaultDouble();
                    foreach (var layerName in _geometriesBuffer.Keys)
                    {
                        MShader.AddDefault(
                            _geometriesBuffer[layerName],
                            _colours[(count++) % _colours.Length]
                            );

                        extents = GeometryExtents <double> .Combine(
                            extents, GeometricArithmeticModule.CalculateExtents(_geometriesBuffer[layerName])
                            );
                    }

                    // overlay tiles
                    foreach (var tile in MTileSettings.ToTiles(TileSettings, extents))
                    {
                        MShader.AddDefault((MarkGeometryRectangle)tile, _tileColor);
                    }

                    // calculate size of fiducial relative to the node
                    var fiducialSize = 0.05 * extents.Hypotenuse;

                    // generate fiducial pattern
                    GenerateFiducialPattern(fiducialSize);

                    // get base transform
                    var baseTransform = GeometricArithmeticModule.GetTranslationTransformationMatrix(
                        extents.Centre.X, extents.Centre.Y
                        );

                    // render fiducials in parent's reference frame
                    foreach (var fiducial in Fiducials)
                    {
                        var transform = GeometricArithmeticModule.CombineTransformations(
                            baseTransform,
                            GeometricArithmeticModule.GetTranslationTransformationMatrix(
                                fiducial.X, fiducial.Y, fiducial.Z
                                )
                            );

                        foreach (var geometry in _fiducialPattern)
                        {
                            var clone = (IMarkGeometry)geometry.Clone();
                            clone.Transform(transform);
                            MShader.AddDefault(clone, _fiducialColor);
                        }
                    }
                }

                // stop if new render is requested
                ctIn.ThrowIfCancellationRequested();

                MShader.Render();

                DrawingExtentsX = MShader.Width;
                DrawingExtentsY = MShader.Height;
                DrawingCount    = MShader.Count;
            }
                );
        }