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; } ); }
public void Render() { _terminableTaskExecutor.CancelCurrentAndRun( (ctIn) => { // reset shader MShader.Reset(); if (_stlSlices != null) { // add geometries if (CurrentSlice >= 0 && CurrentSlice < _stlSlices.Count && _stlSlices[CurrentSlice] != null) { var stlSlice = _stlSlices[CurrentSlice]; // tiles for (int i = 0; i < stlSlice.Tiles?.Count; i++) { MShader.AddDefault(stlSlice.Tiles[i], _tileColor); } // contours for (int i = 0; i < stlSlice.ContourLines?.Count; i++) { MShader.AddDefault(stlSlice.ContourLines[i], MGLShader.Green); } // hatches for (int i = 0; i < stlSlice.HatchLines?.Count; i++) { MShader.AddDefault(stlSlice.HatchLines[i], MGLShader.White); } } // stop if new render is requested ctIn.ThrowIfCancellationRequested(); // get base transform var baseTransform = GeometricArithmeticModule.GetTranslationTransformationMatrix( StlModelReferencePoint.X, StlModelReferencePoint.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(); } ); }