private static void LogInternal(Color headerColor, string header, Color msgColor, string format, params object[] args) { try { if (_rtbLog == null) { _rtbLog = (RichTextBox)Application.Current.MainWindow.FindName("rtbLog"); } System.Windows.Media.Color headerColorMedia = System.Windows.Media.Color.FromArgb(headerColor.A, headerColor.R, headerColor.G, headerColor.B); System.Windows.Media.Color msgColorMedia = System.Windows.Media.Color.FromArgb(msgColor.A, msgColor.R, msgColor.G, msgColor.B); var headerTR = new TextRange(_rtbLog.Document.ContentEnd, _rtbLog.Document.ContentEnd) { Text = header }; headerTR.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(headerColorMedia)); var messageTR = new TextRange(_rtbLog.Document.ContentEnd, _rtbLog.Document.ContentEnd); string msg = String.Format(format, args); messageTR.Text = msg + Environment.NewLine; messageTR.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(msgColorMedia)); Logging.WriteDebug(header + msg); } catch { Logging.Write("PB: " + format, args); } }
/// <summary> /// Handles drag and drop functionality for favourtie color rectangles. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FavoriteRect_Drop(object sender, DragEventArgs e) { if (_isEyedropperMode) { return; } System.Windows.Shapes.Rectangle rect = (System.Windows.Shapes.Rectangle)sender; if (rect != null) { // If the DataObject contains string data, extract it. if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string dataString = (string)e.Data.GetData(DataFormats.StringFormat); // If the string can be converted into a Color, // convert it and apply it to the rect. ColorConverter converter = new ColorConverter(); if (converter.IsValid(dataString)) { System.Windows.Media.Color mediaColor = (System.Windows.Media.Color)ColorConverter.ConvertFromString(dataString); Color color = GraphicsUtil.DrawingColorFromMediaColor(mediaColor); SetFavoriteColorRectangle((int)rect.Tag, color); } } } }
public static int ColorToInt(System.Windows.Media.Color color) { return((255 << 24) // A | (color.R << 16) // R | (color.G << 8) // G | (color.B << 0)); // B }
private void ColorBoard_MouseDown(object sender, MouseButtonEventArgs e) { ColorDialog loColorForm = new ColorDialog { FullOpen = true, }; Color color; ColorConverter.ConvertColor(((SolidColorBrush)ColorBoard.Background).Color, out color); loColorForm.Color = color; if (loColorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.Windows.Media.Color clr = new System.Windows.Media.Color() { R = loColorForm.Color.R, G = loColorForm.Color.G, B = loColorForm.Color.B, A = loColorForm.Color.A }; ColorBoard.Background = new SolidColorBrush(clr); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var col = (Color)value; System.Windows.Media.Color c = System.Windows.Media.Color.FromArgb(col.A, col.R, col.G, col.B); return(new SolidColorBrush(c)); }
/// <summary> /// Handles drag and drop functionality for favourtie color rectangles. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FavoriteRect_DragEnter(object sender, DragEventArgs e) { if (_isEyedropperMode) { return; } System.Windows.Shapes.Rectangle rect = (System.Windows.Shapes.Rectangle)sender; System.Windows.Media.Color prevMediaColor = ((SolidColorBrush)rect.Fill).Color; _previousFillColor = Color.FromArgb(prevMediaColor.A, prevMediaColor.R, prevMediaColor.G, prevMediaColor.B); if (rect != null) { // If the DataObject contains string data, extract it. if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string dataString = (string)e.Data.GetData(DataFormats.StringFormat); // If the string can be converted into a Color, // convert it and apply it to the rect. ColorConverter converter = new ColorConverter(); if (converter.IsValid(dataString)) { System.Windows.Media.Color mediaColor = (System.Windows.Media.Color)ColorConverter.ConvertFromString(dataString); Color color = Color.FromArgb(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B); SetThemeColorRectangle(rect.Name, color); } } } }
public static string ConvertWpfColorToString(this System.Windows.Media.Color color) { var colorString = string.Format("{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); return(colorString); }
private void buttonFarbe_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.ColorDialog newColorDialog = new ColorDialog(); if (newColorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.Windows.Media.Color farbeWPF = System.Windows.Media.Color.FromArgb(newColorDialog.Color.A, newColorDialog.Color.B, newColorDialog.Color.G, newColorDialog.Color.R); pinselBrush = new SolidColorBrush(farbeWPF); } }
public static void Log( System.Windows.Media.Color headerColor, string header, System.Windows.Media.Color msgColor, string format, params object[] args) { LogInvoker(LogLevel.Normal, headerColor, header, msgColor, string.Format(format, args)); }
/// <summary> /// write message to log window if Singular Debug Enabled setting true /// </summary> /// <param name="clr">color of message in window</param> /// <param name="message">message text with embedded parameters</param> /// <param name="args">replacement parameter values</param> public static void WriteDebug(Color clr, string message, params object[] args) { System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B); if (SadisticSettings.Instance.Debug) { Logging.Write(newColor, "(Sadistic) " + message, args); } }
public static void Log( System.Windows.Media.Color headerColor, string header, System.Windows.Media.Color msgColor, string format, params object[] args) { PBLog.Log(headerColor, header, msgColor, format, args); }
private async void SetPixel(System.Windows.Media.Color kekColor, int ix, int iy) { System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle(); Canvas.SetTop(rec, ix); Canvas.SetLeft(rec, iy); rec.Width = 1; rec.Height = 1; rec.Fill = new SolidColorBrush(kekColor); }
/// <summary> /// Change the selectedColor to the color of the matching color rect. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ColorRectangle_MouseUp(object sender, MouseButtonEventArgs e) { System.Windows.Shapes.Rectangle rect = (System.Windows.Shapes.Rectangle)sender; rect.MouseUp -= ColorRectangle_MouseUp; System.Windows.Media.Color color = ((SolidColorBrush)rect.Fill).Color; Color selectedColor = Color.FromArgb(color.A, color.R, color.G, color.B); dataSource.SelectedColor = new HSLColor(selectedColor); }
/// <summary> /// Change the selectedColor to the color of the matching color rect. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ColorRectangle_MouseUp(object sender, MouseButtonEventArgs e) { System.Windows.Shapes.Rectangle rect = (System.Windows.Shapes.Rectangle)sender; rect.MouseUp -= ColorRectangle_MouseUp; System.Windows.Media.Color color = ((SolidColorBrush)rect.Fill).Color; Color selectedColor = GraphicsUtil.DrawingColorFromMediaColor(color); dataSource.SelectedColor = new HSLColor(selectedColor); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { System.Windows.Media.Color c = (System.Windows.Media.Color)value; byte r = System.Convert.ToByte(c.R); byte g = System.Convert.ToByte(c.G); byte b = System.Convert.ToByte(c.B); byte a = System.Convert.ToByte(c.A); return(new SolidColorBrush(System.Windows.Media.Color.FromArgb(a, r, g, b))); }
private void ChangeLedLightColor() { Random randomGen = new Random(); KnownColor randomColorName = _knownColors[randomGen.Next(_knownColors.Length)]; Color color = Color.FromKnownColor(randomColorName); System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); LedLightColor = newColor; }
private static void Animate(DependencyObject target, Color c) { System.Windows.Media.Color targetColor; if (c.A < 10) { targetColor = new System.Windows.Media.Color { A = 60, R = 1, G = 115, B = 199 }; } else { targetColor = new System.Windows.Media.Color { A = Math.Min(c.A, (byte)60), R = c.R, G = c.G, B = c.B }; } if (!(((Border)target).Background is LinearGradientBrush linearBrush)) { linearBrush = new LinearGradientBrush(); linearBrush.StartPoint = new System.Windows.Point(0, 0); linearBrush.EndPoint = new System.Windows.Point(0, 1.0); var gs1 = new GradientStop(Colors.Transparent, 0.0); var gs2 = new GradientStop(System.Windows.Media.Color.FromRgb(239, 239, 239), 1.0); linearBrush.GradientStops.Add(gs1); linearBrush.GradientStops.Add(gs2); } var colorAnimation = new ColorAnimation( targetColor, new Duration(TimeSpan.FromMilliseconds(500))) { AccelerationRatio = 0.5, DecelerationRatio = 0.5 }; Storyboard.SetTarget(colorAnimation, linearBrush.GradientStops[0]); Storyboard.SetTargetProperty(colorAnimation, new PropertyPath(nameof(GradientStop.Color))); ((Border)target).Background = linearBrush; var storyboard = new Storyboard(); storyboard.Children.Add(colorAnimation); storyboard.Freeze(); storyboard.Begin(); }
/// <summary> /// write message to log window and file /// </summary> /// <param name="clr">color of message in window</param> /// <param name="message">message text with embedded parameters</param> /// <param name="args">replacement parameter values</param> public static void Write(Color clr, string message, params object[] args) { System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B); if (GlobalSettings.Instance.LogLevel >= LogLevel.Normal) { Logging.Write(newColor, "[Singular] " + message, args); } else if (GlobalSettings.Instance.LogLevel == LogLevel.Quiet) { Logging.WriteToFileSync(LogLevel.Normal, "[Singular] " + message, args); } }
/// <summary> /// Creates a solid color BitmapSource. /// </summary> /// <param name="color">The Background color.</param> /// <param name="width">The Width of the image.</param> /// <param name="height">The Height of the image.</param> /// <param name="dpi">The dpi of the image.</param> /// <param name="pixelFormat">The PixelFormat.</param> /// <returns>A BitmapSource of the given parameters.</returns> public static BitmapSource CreateEmtpyBitmapSource(System.Windows.Media.Color color, int width, int height, double dpi, PixelFormat pixelFormat) { var rawStride = (width * pixelFormat.BitsPerPixel + 7) / 8; var rawImage = new byte[rawStride * height]; var colors = new List <System.Windows.Media.Color> { color }; var myPalette = new BitmapPalette(colors); return(BitmapSource.Create(width, height, dpi, dpi, pixelFormat, myPalette, rawImage, rawStride)); }
/// <summary> /// output a diagnostic message. message is always written to log file, but is also written /// to log window if Debug enabled /// </summary> /// <param name="clr">color of message in window</param> /// <param name="message">message text with embedded parameters</param> /// <param name="args">replacement parameter values</param> public static void WriteTrace(Color clr, string message, params object[] args) { if (SingularSettings.Instance != null && SingularSettings.Instance.DebugOutput == DebugOutputDest.WindowAndFile) { System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B); Logging.Write(newColor, "|Singular| " + message, args); } else { WriteFile("|Singular| " + message, args); } }
/// <summary> /// write message to log window if Singular Debug Enabled setting true /// </summary> /// <param name="clr">color of message in window</param> /// <param name="message">message text with embedded parameters</param> /// <param name="args">replacement parameter values</param> public static void WriteDebug(Color clr, string message, params object[] args) { System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B); if (SingularSettings.Instance.EnableDebugLogging) { Logging.Write(newColor, "[Singular-DEBUG] " + message, args); } else { Logging.Write(LogLevel.Diagnostic, newColor, "[Singular-DEBUG] " + message, args); } }
public static void AnimateColor(SolidColorBrush from, System.Windows.Media.Color to, UIElement control, double duration) { SolidColorBrush myBrush = new SolidColorBrush(); myBrush = from; ColorAnimation myColorAnimation = new ColorAnimation(); myColorAnimation.From = from.Color; myColorAnimation.To = to; myColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation); control.GetType().GetProperty("Background").SetValue(control, myBrush); }
private void Set_Main_Color_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) { return; } System.Windows.Shapes.Rectangle rect = ((ContextMenu)(menuItem.Parent)).PlacementTarget as System.Windows.Shapes.Rectangle; System.Windows.Media.Color color = ((SolidColorBrush)rect.Fill).Color; Color selectedColor = Color.FromArgb(color.A, color.R, color.G, color.B); dataSource.SelectedColor = new HSLColor(selectedColor); }
/// <summary> /// write message to log window and file /// </summary> /// <param name="message">message text</param> public static void WriteNoSpam(string message) { var clr = Color.DeepSkyBlue; System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B); if (GlobalSettings.Instance.LogLevel >= LogLevel.Normal) { Logging.Write(newColor, "[Sadistic] " + message); } else if (GlobalSettings.Instance.LogLevel == LogLevel.Quiet) { Logging.WriteToFileSync(LogLevel.Normal, "[Sadistic] " + message); } }
/// <summary> /// write message to log window and file. overrides log windows duplicate /// line suppression by ensuring adjoining lines differ /// </summary> /// <param name="clr">color of message in window</param> /// <param name="message">message text with embedded parameters</param> /// <param name="args">replacement parameter values</param> public static void Write(Color clr, string message, params object[] args) { string sUniqueChar = (lineNo++ & 1) == 0 ? "" : " "; System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B); if (GlobalSettings.Instance.LogLevel >= LogLevel.Normal) { Logging.Write(newColor, "[Sadistic] " + message + sUniqueChar, args); } else if (GlobalSettings.Instance.LogLevel == LogLevel.Quiet) { Logging.WriteToFileSync(LogLevel.Normal, "[Sadistic] " + message + sUniqueChar, args); } }
private void Add_Favorite_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) { return; } System.Windows.Shapes.Rectangle rect = ((ContextMenu)(menuItem.Parent)).PlacementTarget as System.Windows.Shapes.Rectangle; System.Windows.Media.Color color = ((SolidColorBrush)rect.Fill).Color; HSLColor clickedColor = GraphicsUtil.DrawingColorFromMediaColor(color); dataSource.AddColorToFavorites(clickedColor); }
private static List <Color> GetDiamondTipColors(System.Windows.Media.Color hue) { List <Color> colors = new List <Color>() { hue.ConvertMediaColorToDrawingColor() }; double[] hslaValues = ColorHelper.ExpandDoublesToHSLAValues(ColorHelper.RgbaToHsla(hue)); // The order these are added matters. colors.Add(ColorHelper.HslaToRgba(hslaValues[0], hslaValues[1], 100, hslaValues[3]).ConvertMediaColorToDrawingColor()); // White colors.Add(ColorHelper.HslaToRgba(hslaValues[0], 0, hslaValues[2], hslaValues[3]).ConvertMediaColorToDrawingColor()); // Gray colors.Add(ColorHelper.HslaToRgba(hslaValues[0], hslaValues[1], 0, hslaValues[3]).ConvertMediaColorToDrawingColor()); // Black return(colors); }
private void Color_Information_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) { return; } System.Windows.Shapes.Rectangle rect = ((ContextMenu)(menuItem.Parent)).PlacementTarget as System.Windows.Shapes.Rectangle; System.Windows.Media.Color color = ((SolidColorBrush)rect.Fill).Color; Color selectedColor = GraphicsUtil.DrawingColorFromMediaColor(color); ColorInformationDialog dialog = new ColorInformationDialog(selectedColor); dialog.ShowThematicDialog(); }
private void Color_Information_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) { return; } System.Windows.Shapes.Rectangle rect = ((ContextMenu)(menuItem.Parent)).PlacementTarget as System.Windows.Shapes.Rectangle; System.Windows.Media.Color color = ((SolidColorBrush)rect.Fill).Color; Color selectedColor = Color.FromArgb(color.A, color.R, color.G, color.B); ColorInformationDialog dialog = new ColorInformationDialog(selectedColor); dialog.Show(); }
public static System.Windows.Media.Color FromHex(this System.Windows.Media.Color c, string hex) { if (hex == null) { return(new System.Windows.Media.Color()); } var convertFromString = ColorConverter.ConvertFromString(hex); if (convertFromString != null) { return((System.Windows.Media.Color)convertFromString); } throw new ArgumentException("Invalid hex color code"); }
public static void ApplyBlobMaskToOtherBitmaps(WriteableBitmap bitmap, WriteableBitmap gradientBitmapRef, WriteableBitmap realBitmapRef, System.Windows.Media.Color blobColor) { int stride = (bitmap.PixelWidth * bitmap.Format.BitsPerPixel + 7) / 8; byte[] pixelByteArray = new byte[bitmap.PixelHeight * stride]; byte[] gradientByteArray = new byte[gradientBitmapRef.PixelHeight * stride]; byte[] realByteArray = new byte[realBitmapRef.PixelHeight * stride]; bitmap.CopyPixels(pixelByteArray, stride, 0); gradientBitmapRef.CopyPixels(gradientByteArray, stride, 0); realBitmapRef.CopyPixels(realByteArray, stride, 0); for (int column = 0; column < bitmap.PixelWidth; column++) { for (int row = 0; row < bitmap.PixelHeight; row++) { int index = row * stride + 4 * column; var pixelColor = new System.Windows.Media.Color(); pixelColor = System.Windows.Media.Color.FromRgb(pixelByteArray[index + 2], pixelByteArray[index + 1], pixelByteArray[index]); if (pixelColor != blobColor) { gradientByteArray[index] = 0; gradientByteArray[index + 1] = 0; gradientByteArray[index + 2] = 0; realByteArray[index] = 0; realByteArray[index + 1] = 0; realByteArray[index + 2] = 0; } } } gradientBitmapRef.WritePixels(new Int32Rect(0, 0, gradientBitmapRef.PixelWidth, gradientBitmapRef.PixelHeight), gradientByteArray, stride, 0); realBitmapRef.WritePixels(new Int32Rect(0, 0, realBitmapRef.PixelWidth, realBitmapRef.PixelHeight), realByteArray, stride, 0); }
public Point3DColor(double x, double y, double z, System.Windows.Media.Color color) { Point3D = new Point3D(x, y, z); Color = color; }
public Point3DColor(Point3D point3D, System.Windows.Media.Color color) { Point3D = point3D; Color = color; }
public Point3DColor(double x, double y, double z) { Point3D = new Point3D(x, y, z); Color = System.Windows.Media.Colors.Black; }
public static bool shouldFlipThresholdedBitmap(WriteableBitmap bitmap, System.Windows.Media.Color blobColor) { int stride = (bitmap.PixelWidth * bitmap.Format.BitsPerPixel + 7) / 8; int topCount = 0; int bottomCount = 0; byte[] pixelByteArray = new byte[bitmap.PixelHeight * stride]; bitmap.CopyPixels(pixelByteArray, stride, 0); for (int column = 0; column < bitmap.PixelWidth; column++) { for (int row = 0; row < bitmap.PixelHeight; row++) { int index = row * stride + 4 * column; var pixelColor = new System.Windows.Media.Color(); pixelColor = System.Windows.Media.Color.FromRgb(pixelByteArray[index + 2], pixelByteArray[index + 1], pixelByteArray[index]); if (pixelColor == blobColor) { if (row < bitmap.PixelHeight/2.0) { topCount++; } else { bottomCount++; } } } } if (topCount > bottomCount) { return true; } else { return false; } }
public override void Start() { base.Start(); var baseLayer = ((dsBaseLayer)Model.Layer); if (OperatingMode == FieldOfViewOperatingMode.Image) { if (ImageLayer != null) return; var displayName = Model.Id + " FoV img"; ImageLayer = baseLayer.ChildLayers.OfType<ElementLayer>().FirstOrDefault(c => string.Equals(c.DisplayName, displayName, StringComparison.InvariantCultureIgnoreCase)); if (ImageLayer == null) { ImageLayer = new ElementLayer { ID = displayName, DisplayName = displayName }; ImageLayer.Initialize(); baseLayer.ChildLayers.Insert(0, ImageLayer); AppState.ViewDef.UpdateLayers(); } } else { if (GraphicsLayer != null) return; var displayName = Model.Id + " FoV"; GraphicsLayer = baseLayer.ChildLayers.OfType<GraphicsLayer>().FirstOrDefault(c => string.Equals(c.DisplayName, displayName, StringComparison.InvariantCultureIgnoreCase)); if (GraphicsLayer == null) { GraphicsLayer = new GraphicsLayer { ID = displayName, DisplayName = displayName }; GraphicsLayer.Initialize(); baseLayer.ChildLayers.Insert(0, GraphicsLayer); AppState.ViewDef.UpdateLayers(); } } color = Model.Model.GetColor("Color", Colors.Blue); strokeWidth = Model.Model.GetInt("StrokeWidth", 2); precision = Model.Model.GetInt("Precision", 2); ManagePoiVisibility(); //this.operatingMode = FieldOfViewOperatingMode.Polygon; switch (OperatingMode) { case FieldOfViewOperatingMode.Polygon: if (GraphicsLayer == null) return; remoteClient.ComputeFieldOfViewAsVectorCompleted += ClientOnComputeFieldOfViewAsVectorCompleted; localClient.ComputeFieldOfViewAsVectorCompleted += ClientOnComputeFieldOfViewAsVectorCompleted; break; default: if (ImageLayer == null) return; remoteClient.ComputeFieldOfViewAsImageCompleted += ClientOnComputeFieldOfViewAsImageCompleted; localClient.ComputeFieldOfViewAsImageCompleted += ClientOnComputeFieldOfViewAsImageCompleted; image = new Image { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Stretch = Stretch.Fill, StretchDirection = StretchDirection.Both }; ElementLayer.SetEnvelope(image, AppStateSettings.Instance.ViewDef.MapControl.Extent); ImageLayer.Children.Add(image); break; } var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => Poi.PositionChanged += ev, ev => Poi.PositionChanged -= ev); posChanged.Throttle(TimeSpan.FromMilliseconds(150)).Subscribe(k => Calculate()); var labelChanged = Observable.FromEventPattern<LabelChangedEventArgs>(ev => Poi.LabelChanged += ev, ev => Poi.LabelChanged -= ev); labelChanged.Throttle(TimeSpan.FromMilliseconds(150)).Subscribe(k => Calculate()); Calculate(); }
public List<MeshIdandGeometry> VisualizeBimPlusDataAsGenericElements(List<GenericElement> baseElements, object sender) { if (InputPorts[0].Data == null) return null; var max = baseElements.Count; var m_i = 1; // Init some lists and containers var container = new ContainerUIElement3D(); var geometry = new List<MeshIdandGeometry>(); // Init the MeshBuilde var meshBuilder = new MeshBuilder(false, false); // Loop the items of each list foreach (var item in baseElements) { // Get the geometric data from the AttributeGroups var points = item.AttributeGroups["geometry"].Attributes["threejspoints"] as IList<Point3D>; var triangleindices = item.AttributeGroups["geometry"].Attributes["geometryindices"]; var indices = (from index in triangleindices as IList<uint> select Convert.ToInt32(index)).ToList(); for (var i = 0; i < indices.Count; i++) { if (indices[i] == 0) { meshBuilder.AddTriangle(points[indices[i + 1]], points[indices[i + 2]], points[indices[i + 3]]); i = i + 3; } else if (indices[i] == 1) { meshBuilder.AddQuad(points[indices[i + 1]], points[indices[i + 2]], points[indices[i + 3]], points[indices[i + 4]]); i = i + 4; } } // Get the color of each representation group var color = Convert.ToInt64(item.AttributeGroups["geometry"].Attributes["color"]); var tempcolor = Color.FromArgb((int)color); var col = new System.Windows.Media.Color { A = tempcolor.A, G = tempcolor.G, R = tempcolor.R, B = tempcolor.B }; var myGeometryModel = new GeometryModel3D { Material = new DiffuseMaterial(new SolidColorBrush(col)), BackMaterial = new DiffuseMaterial(new SolidColorBrush(col)), Geometry = meshBuilder.ToMesh(true), Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)) }; myGeometryModel.Freeze(); var meshAndId = new MeshIdandGeometry { Id = item.Id, Model3D = myGeometryModel, Material = myGeometryModel.Material }; geometry.Add(meshAndId); // Save the parsed information in the elements attribute group item.AttributeGroups["geometry"].Attributes["parsedGeometry"] = meshAndId; // Refresh the builder so that we do not duplicate the meshes meshBuilder = new MeshBuilder(false, false); m_i++; var progressPercentage = Convert.ToInt32(((double)m_i / max) * 100); var backgroundWorker = sender as BackgroundWorker; backgroundWorker?.ReportProgress(progressPercentage, item.Id); } container.Children.Clear(); return geometry; }
public Point3DColor(Point3D point3D) { Point3D = point3D; Color = System.Windows.Media.Colors.Black; }
public static System.Windows.Media.Color PixelColorOfCentralBlob(WriteableBitmap bitmap) { int stride = (bitmap.PixelWidth * bitmap.Format.BitsPerPixel + 7) / 8; ConcurrentDictionary<System.Windows.Media.Color, int > colorDict = new ConcurrentDictionary<System.Windows.Media.Color, int>(); byte[] pixelByteArray = new byte[bitmap.PixelHeight * stride]; bitmap.CopyPixels(pixelByteArray, stride, 0); //Draw a Horizontal Line accross the middle for (int column = 0; column < bitmap.PixelWidth; column++) { var color = new System.Windows.Media.Color(); int row = (int)(bitmap.PixelHeight/2.0); int index = row * stride + 4 * column; int R = Convert.ToInt32(pixelByteArray[index+2]); int G = Convert.ToInt32(pixelByteArray[index+1]); int B = Convert.ToInt32(pixelByteArray[index]); color = System.Windows.Media.Color.FromRgb(pixelByteArray[index + 2], pixelByteArray[index + 1], pixelByteArray[index]); if (!(R == 255 && B == 255 && G == 255) && !(R== 0 && B == 0 && G == 0)) { colorDict.AddOrUpdate(color, 1, (id, count) => count + 1); } } int maxValue = 0; var colorKey = new System.Windows.Media.Color(); foreach (var item in colorDict) { if (item.Value > maxValue) { colorKey = item.Key; maxValue = item.Value; } } return colorKey; }