private void Expand(GeometryModel3D model, Transform3D transformation) { Transform3D ot; if (originalTransforms.ContainsKey(model)) ot = originalTransforms[model]; else { ot = model.Transform; originalTransforms.Add(model, ot); } Transform3D totalTransform = Transform3DHelper.CombineTransform(transformation, ot); var mesh = model.Geometry as MeshGeometry3D; if (mesh == null) return; var bounds = new Rect3D(); foreach (int i in mesh.TriangleIndices) bounds.Union(totalTransform.Transform(mesh.Positions[i])); Point3D p = bounds.Location; Vector3D d = p - actualExpandOrigin; d *= Expansion; Point3D p2 = actualExpandOrigin + d; var t = new TranslateTransform3D(p2 - p); model.Transform = Transform3DHelper.CombineTransform(ot, t); }
internal Rect3D ComputeSubgraphBounds3D() { Rect3D bboxChildrenSubgraph3D = Rect3D.Empty; for (int i = 0, count = _children.InternalCount; i < count; i++) { Visual3D child = _children.InternalGetItem(i); bboxChildrenSubgraph3D.Union(child.CalculateSubgraphBoundsOuterSpace()); } return(bboxChildrenSubgraph3D); }
public static Rect3D GetBounds(IDictionary dictionary) { var localToParent = GetLocalToParent(dictionary); var bounds = new Rect3D(localToParent.Transform(new Point3D(0, 0, 0)), new Size3D(0, 0, 0)); foreach(var key in dictionary.Keys) { var childDictionary = dictionary[key] as IDictionary; if(childDictionary != null) { var childBounds = GetBounds(childDictionary); bounds.Union(localToParent.Transform(childBounds.Location)); } } return bounds; }
internal override Rect3D CalculateSubgraphBoundsInnerSpace() { Model3DCollection children = Children; if (children == null) { return(Rect3D.Empty); } Rect3D bounds = Rect3D.Empty; for (int i = 0, count = children.Count; i < count; i++) { Model3D child = children.Internal_GetItem(i); // Calls CSBOS rather than Bounds to avoid ReadPreamble. bounds.Union(child.CalculateSubgraphBoundsOuterSpace()); } return(bounds); }
/// <summary> /// Return the result of the union of rect and point. /// </summary> /// <param name="rect">Rectangle.</param> /// <param name="point">Point.</param> /// <returns>The result of the union of rect and point.</returns> public static Rect3D Union(Rect3D rect, Point3D point) { rect.Union(new Rect3D(point, point)); return(rect); }
/// <summary> /// Return the result of the union of rect1 and rect2. /// </summary> /// <param name="rect1">First rectangle.</param> /// <param name="rect2">Second rectangle.</param> /// <returns>The result of the union of the two rectangles.</returns> public static Rect3D Union(Rect3D rect1, Rect3D rect2) { rect1.Union(rect2); return(rect1); }
/// <summary> /// Return the result of the union of rect and point. /// </summary> /// <param name="rect">Rectangle.</param> /// <param name="point">Point.</param> /// <returns>The result of the union of rect and point.</returns> public static Rect3D Union(Rect3D rect, Point3D point) { rect.Union(new Rect3D(point, point)); return rect; }
/// <summary> /// Return the result of the union of rect1 and rect2. /// </summary> /// <param name="rect1">First rectangle.</param> /// <param name="rect2">Second rectangle.</param> /// <returns>The result of the union of the two rectangles.</returns> public static Rect3D Union(Rect3D rect1, Rect3D rect2) { rect1.Union(rect2); return rect1; }
public void Calculate(List<Point> listCross, int pos, int len, double angle) { m_bounds = new Rect3D(); if (len <= 0) { return; } if (pos == 0) { m_Model3DGroup = GetNewGroup(); myModelVisual3D.Content = m_Model3DGroup; Transform3DGroup transGroup = new Transform3DGroup(); m_axB3d = new AxisAngleRotation3D(new Vector3D(0, 0, 1), sliderB.Value); RotateTransform3D myRotateTransform = new RotateTransform3D(m_axB3d); transGroup.Children.Add(myRotateTransform); m_axA3d = new AxisAngleRotation3D(new Vector3D(0, 1, 0), sliderA.Value); myRotateTransform = new RotateTransform3D(m_axA3d); transGroup.Children.Add(myRotateTransform); m_trans3d = new TranslateTransform3D(new Vector3D(0, 0, 0)); transGroup.Children.Add(m_trans3d); m_Model3DGroup.Transform = transGroup; m_Model3DGroup.Children.Add(meshCubeModel); } GeometryModel3D myGeometryModel = new GeometryModel3D(); m_Model3DGroup.Children.Add(myGeometryModel); MeshGeometry3D myMeshGeometry3D = new MeshGeometry3D(); Point3DCollection myPositionCollection = new Point3DCollection(); myGeometryModel.Geometry = myMeshGeometry3D; List<Point3DCollection> Discs = new List<Point3DCollection>(); double cur_angle = 0; double ZIncrement = 1; if (MathHelper.IsZero(angle) && (m_listCurve == null || m_listCurve.Count < 2) && (m_listLimits == null || m_listLimits.Count < 2)) { ZIncrement = len; } for (double Z = pos; Z <= pos + len; Z += ZIncrement) { Point3DCollection disc = new Point3DCollection(); cur_angle += angle; AxisAngleRotation3D myRotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), cur_angle); RotateTransform3D myRotateTransform = new RotateTransform3D(myRotation); TranslateTransform3D transTransform = new TranslateTransform3D(0, 0, Z); //ScaleTransform3D ScaleTrans = new ScaleTransform3D(new Vector3D(Zoom, Zoom, 0), new Point3D(0, 0, Z)); double RadLimit = GetRadiusLimit(Z); double RadIncrement = GetRadiusIncrement(Z); if (listCross.First() != listCross.Last()) {//make closed loop listCross.Add(listCross.First()); } for (int i = 0; i < listCross.Count; i++ ) { double x = listCross[i].X; double y = listCross[i].Y; Vector3D vec = new Vector3D(x, y, 0); if (!MathHelper.IsZero(RadIncrement)) { Vector3D vecNorm = new Vector3D(x, y, 0); double ZoomFactor = RadIncrement/10; vec *= ZoomFactor; } if (vec.Length > RadLimit) { Vector3D vecNorm = new Vector3D(x, y, 0); vecNorm.Normalize(); vec = vecNorm * RadLimit; } Point3D newPoint = (Point3D)myRotateTransform.Transform(vec); newPoint = transTransform.Transform(newPoint); disc.Add(newPoint); } if (Discs.Count == 0) { //крышки над примитивами Point3DCollection disc0 = new Point3DCollection(); for (int i = 0; i < disc.Count; i++) { Point3D pt = disc[i]; pt.X = 0; pt.Y = 0; disc0.Add(pt); } Discs.Add(disc0); } Discs.Add(disc); } SolidColorBrush mySolidBrush1 = new SolidColorBrush(); mySolidBrush1.Color = Color.FromRgb(200, 110, 110); DiffuseMaterial FrontMaterial = new DiffuseMaterial(mySolidBrush1); SolidColorBrush mySolidBrush = new SolidColorBrush(); mySolidBrush.Color = Color.FromRgb(110, 200, 110); DiffuseMaterial BackMaterial = new DiffuseMaterial(mySolidBrush); myGeometryModel.Material = FrontMaterial; myGeometryModel.BackMaterial = BackMaterial; for (int i = 1; i < Discs.Count; i++) { Point3DCollection disc1 = Discs[i - 1]; Point3DCollection disc2 = Discs[i]; for (int j = 1; j < disc1.Count; j++) { Point3D p1 = disc1[j - 1]; Point3D p2 = disc1[j]; Point3D p3 = disc2[j]; Point3D p4 = disc2[j - 1]; myPositionCollection.Add(p4); myPositionCollection.Add(p3); myPositionCollection.Add(p1); myPositionCollection.Add(p1); myPositionCollection.Add(p3); myPositionCollection.Add(p2); } } myMeshGeometry3D.Positions = myPositionCollection; m_bounds.Union(myMeshGeometry3D.Bounds); Size3D mySize = m_bounds.Size; string s = string.Format("X:{0},Y:{1},Z:{2}",(int)mySize.X,(int)mySize.Y,(int)mySize.Z); labelInfo.Content = s; }