public static Cuboid Union(Cuboid bounds3D1, Cuboid bounds3D2) { if (!bounds3D1.IsPhysical) return bounds3D2; if (!bounds3D2.IsPhysical) return bounds3D1; Point3D minimum1 = bounds3D1.minimum; Point3D minimum2 = bounds3D2.minimum; Point3D maximum1 = bounds3D1.maximum; Point3D maximum2 = bounds3D2.maximum; return new Cuboid(Math.Min(minimum1.X, minimum2.X), Math.Min(minimum1.Y, minimum2.Y), Math.Min(minimum1.Z, minimum2.Z), Math.Max(maximum1.X, maximum2.X), Math.Max(maximum1.Y, maximum2.Y), Math.Max(maximum1.Z, maximum2.Z)); }
/// <summary> /// Fired when model added or removed /// </summary> protected void Models_Changed(Object sender, ItemEventArgs e) { // Find new bounds that gives the world max and min Cuboid bounds = new Cuboid(new Point3D(0, 0, 0), new Point3D(0, 0, 0)); foreach (Model3D model in (Model3DCollection)sender) { bounds = Cuboid.Union(model.Bounds, bounds); } if (!bounds.IsPhysical) { bounds = new Cuboid(new Point3D(-1, -1, -1), new Point3D(1, 1, 1)); } GraphMin = bounds.Minimum; GraphMax = bounds.Maximum; }
/// <summary> /// Provides transform that will map one set of bounds to another /// </summary> public static MatrixTransform3D BoundsMapping(Cuboid sourceBounds, Cuboid destinationBounds) { Point3D graphMin = sourceBounds.minimum; Point3D graphMax = sourceBounds.maximum; Point3D modelMin = destinationBounds.minimum; Point3D modelMax = destinationBounds.maximum; double scaleX = (modelMax.X - modelMin.X) / (graphMax.X - graphMin.X); double scaleY = (modelMax.Y - modelMin.Y) / (graphMax.Y - graphMin.Y); double scaleZ = (modelMax.Z - modelMin.Z) / (graphMax.Z - graphMin.Z); double offX = -graphMin.X * scaleX + modelMin.X; double offY = -graphMin.Y * scaleY + modelMin.Y; double offZ = -graphMin.Z * scaleZ + modelMin.Z; Matrix3D transform = new Matrix3D(scaleX, 0, 0, 0, 0, scaleY, 0, 0, 0, 0, scaleZ, 0, offX, offY, offZ, 1); MatrixTransform3D matrixTransform = new MatrixTransform3D(transform); return matrixTransform; }
/// <summary> /// Provides transform that will map one set of bounds to another /// </summary> public static MatrixTransform3D BoundsMapping(Cuboid sourceBounds, Cuboid destinationBounds) { Point3D graphMin = sourceBounds.minimum; Point3D graphMax = sourceBounds.maximum; Point3D modelMin = destinationBounds.minimum; Point3D modelMax = destinationBounds.maximum; double scaleX = (modelMax.X - modelMin.X) / (graphMax.X - graphMin.X); double scaleY = (modelMax.Y - modelMin.Y) / (graphMax.Y - graphMin.Y); double scaleZ = (modelMax.Z - modelMin.Z) / (graphMax.Z - graphMin.Z); double offX = -graphMin.X * scaleX + modelMin.X; double offY = -graphMin.Y * scaleY + modelMin.Y; double offZ = -graphMin.Z * scaleZ + modelMin.Z; Matrix3D transform = new Matrix3D(scaleX, 0, 0, 0, 0, scaleY, 0, 0, 0, 0, scaleZ, 0, offX, offY, offZ, 1); MatrixTransform3D matrixTransform = new MatrixTransform3D(transform); return(matrixTransform); }
public static Cuboid Union(Cuboid bounds3D1, Cuboid bounds3D2) { if (!bounds3D1.IsPhysical) { return(bounds3D2); } if (!bounds3D2.IsPhysical) { return(bounds3D1); } Point3D minimum1 = bounds3D1.minimum; Point3D minimum2 = bounds3D2.minimum; Point3D maximum1 = bounds3D1.maximum; Point3D maximum2 = bounds3D2.maximum; return(new Cuboid(Math.Min(minimum1.X, minimum2.X), Math.Min(minimum1.Y, minimum2.Y), Math.Min(minimum1.Z, minimum2.Z), Math.Max(maximum1.X, maximum2.X), Math.Max(maximum1.Y, maximum2.Y), Math.Max(maximum1.Z, maximum2.Z))); }
protected void CreateMesh(IEnumerable <double> x, IEnumerable <double> y, IEnumerable <double> z, int xLength, int yLength) { lengthU = xLength; lengthV = yLength; bounds = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max()); Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(x, y, z, xLength, yLength); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.HSV, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256); SetColorFromIndices(); colourMapUpdateTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) }; colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick); lights = new List <SharpDX.Direct3D9.Light>(); SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(0.3f, 0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(-0.3f, -0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); material = new SharpDX.Direct3D9.Material(); material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Diffuse = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Ambient = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Power = 10; }
protected void CreateMeshILArray(ILArray <double> x, ILArray <double> y, ILArray <double> z) { bounds = new Cuboid(x.MinValue, y.MinValue, z.MinValue, x.MaxValue, y.MaxValue, z.MaxValue); lengthU = x.Dimensions[0]; lengthV = x.Dimensions[1]; ILArray <double> xs, ys, zs; if (x.IsReference) { xs = x.Clone() as ILArray <double>; } else { xs = x; } if (y.IsReference) { ys = y.Clone() as ILArray <double>; } else { ys = y; } if (z.IsReference) { zs = z.Clone() as ILArray <double>; } else { zs = z; } //if (x.IsReference || y.IsReference || z.IsReference) throw new Exception("x, y and z must be solid arrays"); double[] xa = xs.InternalArray4Experts; double[] ya = ys.InternalArray4Experts; double[] za = zs.InternalArray4Experts; Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(xa, ya, za, lengthU, lengthV); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.Jet, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(za, lengthU, lengthV, 256); SetColorFromIndices(); }
protected void CreateMesh(IEnumerable<double> x, IEnumerable<double> y, IEnumerable<double> z, int xLength, int yLength) { lengthU = xLength; lengthV = yLength; bounds = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max()); Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(x, y, z, xLength, yLength); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.HSV, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256); SetColorFromIndices(); colourMapUpdateTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) }; colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick); lights = new List<SharpDX.Direct3D9.Light>(); SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(0.3f, 0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(-0.3f, -0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); material = new SharpDX.Direct3D9.Material(); material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Diffuse = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Ambient = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Power = 10; }
protected void CreateMeshILArray(ILArray<double> x, ILArray<double> y, ILArray<double> z) { bounds = new Cuboid(x.MinValue, y.MinValue, z.MinValue, x.MaxValue, y.MaxValue, z.MaxValue); lengthU = x.Dimensions[0]; lengthV = x.Dimensions[1]; ILArray<double> xs, ys, zs; if (x.IsReference) xs = x.Clone() as ILArray<double>; else xs = x; if (y.IsReference) ys = y.Clone() as ILArray<double>; else ys = y; if (z.IsReference) zs = z.Clone() as ILArray<double>; else zs = z; //if (x.IsReference || y.IsReference || z.IsReference) throw new Exception("x, y and z must be solid arrays"); double[] xa = xs.InternalArray4Experts; double[] ya = ys.InternalArray4Experts; double[] za = zs.InternalArray4Experts; Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(xa, ya, za, lengthU, lengthV); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.Jet, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(za, lengthU, lengthV, 256); SetColorFromIndices(); }