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); }
/// <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); }
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); } } }
public virtual void AddDefault(IList <IMarkGeometry> geometriesIn, double[] color) { if (geometriesIn == null || color == null || color.Length < 3) { AddDefault(geometriesIn); return; } if (geometriesIn.All(x => x is MarkGeometryPoint)) { var currentExtents = GeometryExtents <double> .Combine( new GeometryExtents <double>() { MinX = MinX, MaxX = MaxX, MinY = MinY, MaxY = MaxY }, GeometricArithmeticModule.CalculateExtents( geometriesIn ) ); // Update extents MinX = currentExtents.MinX; MaxX = currentExtents.MaxX; MinY = currentExtents.MinY; MaxY = currentExtents.MaxY; // Update Counter Count += geometriesIn.Count; var vtx = new VertexGroup() { Color = color }; for (int i = 0; i < geometriesIn.Count; i++) { vtx.Vertices.AddRange(ToDouble(geometriesIn[i] as MarkGeometryPoint)); } _points.Add(vtx); Update(); } else if (geometriesIn.All(x => x is MarkGeometryLine)) { var currentExtents = GeometryExtents <double> .Combine( new GeometryExtents <double>() { MinX = MinX, MaxX = MaxX, MinY = MinY, MaxY = MaxY }, GeometricArithmeticModule.CalculateExtents( geometriesIn ) ); // Update extents MinX = currentExtents.MinX; MaxX = currentExtents.MaxX; MinY = currentExtents.MinY; MaxY = currentExtents.MaxY; // Update Counter Count += geometriesIn.Count; var vtx = new VertexGroup() { Color = color }; for (int i = 0; i < geometriesIn.Count; i++) { vtx.Vertices.AddRange(ToDouble(geometriesIn[i] as MarkGeometryLine)); } _lines.Add(vtx); Update(); } else { for (int i = 0; i < geometriesIn.Count; i++) { AddDefault(geometriesIn[i], color); } } }
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; } ); }