//------------------------------------------------------------------------------------- public override void Init3DModel(Model3DGroup model) { var builder = new MeshBuilder(); builder.AddBoundingBox(model.Bounds, 0.15); model.Children.Add(new GeometryModel3D(builder.ToMesh(), Materials.Black)); SceneViewModel.Model3D = model; SceneViewModel.CoordinatesBoundingBox = _model.GetCoordinatesForBoundingBox(builder.Positions); }
private Model3D CreateModel() { var plotModel = new Model3DGroup(); int rows = Points.GetUpperBound(0) + 1; int columns = Points.GetUpperBound(1) + 1; double minX = double.MaxValue; double maxX = double.MinValue; double minY = double.MaxValue; double maxY = double.MinValue; double minZ = double.MaxValue; double maxZ = double.MinValue; double minColorValue = double.MaxValue; double maxColorValue = double.MinValue; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double x = Points[i, j].X; double y = Points[i, j].Y; double z = Points[i, j].Z; maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); maxZ = Math.Max(maxZ, z); minX = Math.Min(minX, x); minY = Math.Min(minY, y); minZ = Math.Min(minZ, z); if (ColorValues != null) { maxColorValue = Math.Max(maxColorValue, ColorValues[i, j]); minColorValue = Math.Min(minColorValue, ColorValues[i, j]); } } } // make color value 0 at texture coordinate 0.5 if (Math.Abs(minColorValue) < Math.Abs(maxColorValue)) { minColorValue = -maxColorValue; } else { maxColorValue = -minColorValue; } // set the texture coordinates by z-value or ColorValue var texcoords = new Point[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double u = (Points[i, j].Z - minZ) / (maxZ - minZ); if (ColorValues != null) { u = (ColorValues[i, j] - minColorValue) / (maxColorValue - minColorValue); } texcoords[i, j] = new Point(u, u); } } var surfaceMeshBuilder = new MeshBuilder(); surfaceMeshBuilder.AddRectangularMesh(Points, texcoords); var surfaceModel = new GeometryModel3D(surfaceMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); surfaceModel.BackMaterial = surfaceModel.Material; var axesMeshBuilder = new MeshBuilder(); for (double x = minX; x <= maxX; x += IntervalX) { double j = (x - minX) / (maxX - minX) * (columns - 1); var path = new List <Point3D> { new Point3D(x + 0.00001, minY, minZ) }; // + 0.0001 to avoid ZoomExtens bug if any geometry has for (int i = 0; i < rows; i++) { path.Add(BilinearInterpolation(Points, i, j)); } path.Add(new Point3D(x, maxY, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 4, false); GeometryModel3D label = TextCreator.CreateTextLabelModel3D(x.ToString(), Brushes.Black, true, FontSize, new Point3D(x, minY - FontSize * 2.5, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("X-axis", Brushes.Black, true, FontSize, new Point3D((minX + maxX) * 0.5, minY - FontSize * 6, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } for (double y = minY; y <= maxY; y += IntervalY) { double i = (y - minY) / (maxY - minY) * (rows - 1); var path = new List <Point3D> { new Point3D(minX, y + 0.00001, minZ) }; for (int j = 0; j < columns; j++) { path.Add(BilinearInterpolation(Points, i, j)); } path.Add(new Point3D(maxX, y, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 4, false); GeometryModel3D label = TextCreator.CreateTextLabelModel3D(y.ToString(), Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 3, y, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Y-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, (minY + maxY) * 0.5, minZ), new Vector3D(0, 1, 0), new Vector3D(-1, 0, 0)); plotModel.Children.Add(label); } double z0 = (int)(minZ / IntervalZ) * IntervalZ; for (double z = z0; z <= maxZ + double.Epsilon; z += IntervalZ) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(z.ToString(), Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 3, maxY, z), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Z-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, maxY, (minZ + maxZ) * 0.5), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)); plotModel.Children.Add(label); } var bb = new Rect3D(minX, minY, minZ, maxX - minX, maxY - minY, 0 * (maxZ - minZ)); axesMeshBuilder.AddBoundingBox(bb, LineThickness); var axesModel = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Black); plotModel.Children.Add(surfaceModel); plotModel.Children.Add(axesModel); return(plotModel); }
private Model3D CreateModel() { var plotModel = new Model3DGroup(); if (Points == null || Values == null) return plotModel; double minX = Points.Min(p => p.X); double maxX = Points.Max(p => p.X); double minY = Points.Min(p => p.Y); double maxY = Points.Max(p => p.Y); double minZ = Points.Min(p => p.Z); double maxZ = Points.Max(p => p.Z); double minValue = Values.Min(); double maxValue = Values.Max(); var valueRange = maxValue - minValue; var scatterMeshBuilder = new MeshBuilder(true, true); var oldTCCount = 0; for (var i = 0; i < Points.Length; ++i) { scatterMeshBuilder.AddSphere(Points[i], SphereSize, 4, 4); var u = (Values[i] - minValue) / valueRange; var newTCCount = scatterMeshBuilder.TextureCoordinates.Count; for (var j = oldTCCount; j < newTCCount; ++j) { scatterMeshBuilder.TextureCoordinates[j] = new Point(u, u); } oldTCCount = newTCCount; } var scatterModel = new GeometryModel3D(scatterMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); scatterModel.BackMaterial = scatterModel.Material; // create bounding box with axes indications var axesMeshBuilder = new MeshBuilder(); for (double x = minX; x <= maxX; x += IntervalX) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(x.ToString(), Brushes.Black, true, FontSize, new Point3D(x, minY - FontSize*2.5, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("X-axis", Brushes.Black, true, FontSize, new Point3D((minX + maxX)*0.5, minY - FontSize*6, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } for (double y = minY; y <= maxY; y += IntervalY) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(y.ToString(), Brushes.Black, true, FontSize, new Point3D(minX - FontSize*3, y, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Y-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize*10, (minY + maxY)*0.5, minZ), new Vector3D(0, 1, 0), new Vector3D(-1, 0, 0)); plotModel.Children.Add(label); } double z0 = (int) (minZ/IntervalZ)*IntervalZ; for (double z = z0; z <= maxZ + double.Epsilon; z += IntervalZ) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(z.ToString(), Brushes.Black, true, FontSize, new Point3D(minX - FontSize*3, maxY, z), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Z-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize*10, maxY, (minZ + maxZ)*0.5), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)); plotModel.Children.Add(label); } var bb = new Rect3D(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ); axesMeshBuilder.AddBoundingBox(bb, LineThickness); var axesModel = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Black); plotModel.Children.Add(scatterModel); plotModel.Children.Add(axesModel); return plotModel; }
private Model3DGroup GetModel(GameObject newObject, String resourceName, String fileExt) { Transform3DGroup TransformGroup = new Transform3DGroup(); TranslateTransform3D TranslateTransform = new TranslateTransform3D(newObject.Position * ViewportScalingFactor); ModelVisual3D newModel = null; Model3DGroup newGroup = new Model3DGroup(); string assemblyLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string resourceBase = "pack://*****:*****@"\GameAssets\" + resourceName); break; case "3ds": ModelImporter importer = new ModelImporter(); newGroup = importer.Load(assemblyLocation + @"\GameAssets\" + resourceName); foreach (var material in newObject.Model.Materials) { MaterialGroup materialGroup = new MaterialGroup(); Brush materialBrush = new SolidColorBrush(material.DiffuseColor); materialBrush.Opacity = material.Opacity; materialGroup.Children.Add(MaterialHelper.CreateMaterial(materialBrush, material.SpecularPower)); if (!String.IsNullOrWhiteSpace(material.TextureFile)) { if (File.Exists(assemblyLocation + @"\GameAssets\" + material.TextureFile)) { var texture = MaterialHelper.CreateImageMaterial(new BitmapImage(new Uri(assemblyLocation + @"\GameAssets\" + material.TextureFile, UriKind.Relative)), material.Opacity); materialGroup.Children.Add(texture); } } var specular = new SpecularMaterial(); specular.SpecularPower = material.SpecularPower; specular.Color = material.SpecularColor; var emissive = new EmissiveMaterial(); emissive.Color = material.EmissiveColor; materialGroup.Children.Add(specular); materialGroup.Children.Add(emissive); ((GeometryModel3D)newGroup.Children[material.MeshIndex]).Material = materialGroup; } break; } #if DEBUG if (resourceName.IndexOf("Rink") < 0) { HelixToolkit.Wpf.MeshBuilder meshBuilder = new MeshBuilder(); var boundingRect = newGroup.Bounds; meshBuilder.AddBoundingBox(boundingRect, 3); } #endif double CenterX = newGroup.Bounds.SizeX / 2; double CenterY = newGroup.Bounds.SizeY / 2; double CenterZ = newGroup.Bounds.SizeZ / 2; ScaleTransform3D ScaleTransform = new ScaleTransform3D(newObject.Scale.X, newObject.Scale.Y, newObject.Scale.Z, CenterX, CenterY, CenterZ); TransformGroup.Children.Add(TranslateTransform); TransformGroup.Children.Add(ScaleTransform); newGroup.Transform = TransformGroup; if (newObject.ApplyPhysics) { var rinkBounds = _gameObjects.Where(x => x.Key.Model.IsGameWorld).First().Value.Content.Bounds; TranslateTransform.OffsetZ -= (newGroup.Bounds.Z - rinkBounds.Z); } newObject.Bounds = newGroup.Bounds; return(newGroup); }
private Model3D CreateModel() { var plotModel = new Model3DGroup(); if (Points == null || Values == null) { return(plotModel); } double minX = Points.Min(p => p.X); double maxX = Points.Max(p => p.X); double minY = Points.Min(p => p.Y); double maxY = Points.Max(p => p.Y); double minZ = Points.Min(p => p.Z); double maxZ = Points.Max(p => p.Z); double minValue = Values.Min(); double maxValue = Values.Max(); var valueRange = maxValue - minValue; var scatterMeshBuilder = new MeshBuilder(true, true); var oldTCCount = 0; for (var i = 0; i < Points.Length; ++i) { scatterMeshBuilder.AddSphere(Points[i], SphereSize, 4, 4); var u = (Values[i] - minValue) / valueRange; var newTCCount = scatterMeshBuilder.TextureCoordinates.Count; for (var j = oldTCCount; j < newTCCount; ++j) { scatterMeshBuilder.TextureCoordinates[j] = new Point(u, u); } oldTCCount = newTCCount; } var scatterModel = new GeometryModel3D(scatterMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); scatterModel.BackMaterial = scatterModel.Material; // create bounding box with axes indications var axesMeshBuilder = new MeshBuilder(); for (double x = minX; x <= maxX; x += IntervalX) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(x.ToString(), Brushes.Black, true, FontSize, new Point3D(x, minY - FontSize * 2.5, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("X-axis", Brushes.Black, true, FontSize, new Point3D((minX + maxX) * 0.5, minY - FontSize * 6, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } for (double y = minY; y <= maxY; y += IntervalY) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(y.ToString(), Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 3, y, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Y-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, (minY + maxY) * 0.5, minZ), new Vector3D(0, 1, 0), new Vector3D(-1, 0, 0)); plotModel.Children.Add(label); } double z0 = (int)(minZ / IntervalZ) * IntervalZ; for (double z = z0; z <= maxZ + double.Epsilon; z += IntervalZ) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(z.ToString(), Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 3, maxY, z), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Z-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, maxY, (minZ + maxZ) * 0.5), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)); plotModel.Children.Add(label); } var bb = new Rect3D(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ); axesMeshBuilder.AddBoundingBox(bb, LineThickness); var axesModel = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Black); plotModel.Children.Add(scatterModel); plotModel.Children.Add(axesModel); return(plotModel); }
private Model3D CreateModel() { var viewport = this.GetViewport3D(); var plotModel = new Model3DGroup(); var Children = plotModel.Children; plotModel.Children = null; int rows = Points.GetUpperBound(0) + 1; int columns = Points.GetUpperBound(1) + 1; double minX = double.MaxValue; double maxX = double.MinValue; double minY = double.MaxValue; double maxY = double.MinValue; double minZ = double.MaxValue; double maxZ = double.MinValue; double minColorValue = double.MaxValue; double maxColorValue = double.MinValue; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double x = Points[i, j].X; double y = Points[i, j].Y; double z = Points[i, j].Z; if (x == 0 && y == 0 && z == 0) { continue; } maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); maxZ = Math.Max(maxZ, z); minX = Math.Min(minX, x); minY = Math.Min(minY, y); minZ = Math.Min(minZ, z); if (ColorValues != null) { maxColorValue = Math.Max(maxColorValue, ColorValues[i, j]); minColorValue = Math.Min(minColorValue, ColorValues[i, j]); } } } IntervalX = (maxX - minX) / 6.0; IntervalY = (maxY - minY) / 6.0; IntervalZ = (maxZ - minZ) / 1.0; FontSize = 0.03; var FontScale = 1; LineThickness = 0.005; // make color value 0 at texture coordinate 0.5 if (Math.Abs(minColorValue) < Math.Abs(maxColorValue)) { minColorValue = -maxColorValue; } else { maxColorValue = -minColorValue; } // set the texture coordinates by z-value or ColorValue var texcoords = new Point[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double u = (Points[i, j].Z - minZ) / (maxZ - minZ); if (ColorValues != null) { u = (ColorValues[i, j] - minColorValue) / (maxColorValue - minColorValue); } texcoords[i, j] = new Point(u, u); } } if (rows == 1 || columns == 1) { var surfaceMeshBuilder = new MeshBuilder(); var pointList = new List <Point3D>(); var texturePoints = new List <double>(); var diameters = new List <double>(); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { pointList.Add(Points[i, j]); texturePoints.Add(texcoords[i, j].X); diameters.Add(LineThickness * 2.0); } } surfaceMeshBuilder.AddTube(pointList, texturePoints.ToArray(), diameters.ToArray(), 9, false, true, true); var mesh = surfaceMeshBuilder.ToMesh(); var surfaceModel = new GeometryModel3D(mesh, MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); surfaceModel.BackMaterial = surfaceModel.Material; Children.Add(surfaceModel); } else { var vertexZMapping = new Dictionary <Vertex, double>(); var vertices = new List <Vertex>(); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (Points[i, j].X == 0.0 && Points[i, j].Y == 0.0 && Points[i, j].Z == 0.0) { continue; } var vertex = new Vertex(Points[i, j].X, Points[i, j].Y); vertices.Add(vertex); vertexZMapping[vertex] = Points[i, j].Z; } } var mesh = DelaunayTriangulation <Vertex, Cell> .Create(vertices, 1e-10); foreach (var cell in mesh.Cells) { // 3D-ify it. var min = cell.Vertices.Min(vertex => vertexZMapping[vertex]); var max = cell.Vertices.Max(vertex => vertexZMapping[vertex]); var minPercentile = (min - minZ) / (maxZ - minZ); var maxPercentile = (max - minZ) / (maxZ - minZ); var minR = Math.Round(255.0 * (1 - 0.3 * minPercentile)); var minG = Math.Round(255.0 * (minPercentile)); var minB = Math.Round(255.0 * (Math.Abs(0.5 - minPercentile) * 2)); var maxR = Math.Round(255.0 * (1 - 0.3 * maxPercentile)); var maxG = Math.Round(255.0 * (maxPercentile)); var maxB = Math.Round(255.0 * (Math.Abs(0.5 - maxPercentile) * 2)); var minColor = Color.FromArgb((byte)255, (byte)minR, (byte)minG, (byte)minB); var maxColor = Color.FromArgb((byte)255, (byte)maxR, (byte)maxG, (byte)maxB); Children.Add(cell.Visual.CreateModel(new Point3DCollection(cell.Vertices.Select(vertex => { var vertexPoint = vertex.ToPoint(); return(new Point3D(vertexPoint.X, vertexPoint.Y, vertexZMapping[vertex])); })), minColor, maxColor)); } } //2 Stat //x=stat=x*total //y=stat2=y*total //3 Stat //x=stat1=x*total //y_1=stat2=(-x*total-y*total)/2 //y_2=stat3=y*total+(-x*total-y*total)/2 var axesMeshBuilder = new MeshBuilder(); for (double x = minX; x <= maxX; x += IntervalX) { double j = (x - minX) / (maxX - minX) * (columns - 1); var path = new List <Point3D> { new Point3D(x, minY, minZ) }; path.Add(new Point3D(x, maxY, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 9, false, true, true); var labelString = (x * ResultsData.ShrinkingFactor).ToString("F4"); if (StatCount == 2 || StatCount == 3) { labelString = (x * Total).ToString("F0"); } GeometryModel3D label = TextCreator.CreateTextLabelModel3D(labelString, Brushes.Black, true, FontSize, new Point3D(x, minY - FontSize * 6, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); label.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), -90.0), new Point3D(label.Bounds.SizeX / 2 + label.Bounds.Location.X, label.Bounds.SizeY / 2 + label.Bounds.Location.Y, 0.0)); Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(XAxisName, Brushes.Black, true, FontSize, new Point3D((minX + maxX) * 0.5, minY - FontSize * 12, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); Children.Add(label); } for (double y = minY; y <= maxY; y += IntervalY) { double i = (y - minY) / (maxY - minY) * (rows - 1); var path = new List <Point3D> { new Point3D(minX, y, minZ) }; path.Add(new Point3D(maxX, y, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 9, false, true, true); var labelString = (y * ResultsData.ShrinkingFactor).ToString("F4"); if (StatCount == 2) { labelString = (y * Total).ToString("F0"); } GeometryModel3D label = TextCreator.CreateTextLabelModel3D(labelString, Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 4, y, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(YAxisName, Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, (minY + maxY) * 0.5, minZ), new Vector3D(0, 1, 0), new Vector3D(-1, 0, 0)); label.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180.0), new Point3D(label.Bounds.SizeX / 2 + label.Bounds.Location.X, label.Bounds.SizeY / 2 + label.Bounds.Location.Y, 0.0)); Children.Add(label); } //double z0 = (int)(minZ / IntervalZ) * IntervalZ; var zTrans = IntervalZ / 3; for (double z = minZ; z <= maxZ + double.Epsilon; z += IntervalZ) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(z.ToString("F4"), Brushes.Black, true, FontSize / FontScale, new Point3D(minX - FontSize * 4, maxY + .015, z), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); label.Transform = new TranslateTransform3D(new Vector3D(0, 0, zTrans)); Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(ZAxisName, Brushes.Black, true, FontSize / FontScale, new Point3D(minX - FontSize * 10, maxY + .015, (minZ + maxZ) * 0.5), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)); label.Transform = new TranslateTransform3D(new Vector3D(0, 0, IntervalZ)); Children.Add(label); } var bb = new Rect3D(minX, minY, minZ, maxX - minX, maxY - minY, 0 * (maxZ - minZ)); axesMeshBuilder.AddBoundingBox(bb, LineThickness); var axesModel = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Black); Children.Add(axesModel); plotModel.Children = Children; return(plotModel); }
private Model3D CreateModel() { // if (Points ==null) var plotModel = new Model3DGroup(); int rows = Points.GetUpperBound(0) + 1; int columns = Points.GetUpperBound(1) + 1; double minX = double.MaxValue; double maxX = double.MinValue; double minY = double.MaxValue; double maxY = double.MinValue; double minZ = double.MaxValue; double maxZ = double.MinValue; //double RealminX = double.MaxValue; //double RealmaxX = double.MinValue; //double RealminY = double.MaxValue; //double RealmaxY = double.MinValue; //double RealminZ = double.MaxValue; //double RealmaxZ = double.MinValue; #region Color things double minColorValue = double.MaxValue; double maxColorValue = double.MinValue; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double x = Points[i, j].X; double y = Points[i, j].Y; double z = Points[i, j].Z; maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); maxZ = Math.Max(maxZ, z); minX = Math.Min(minX, x); minY = Math.Min(minY, y); minZ = Math.Min(minZ, z); if (ColorValues != null) { maxColorValue = Math.Max(maxColorValue, ColorValues[i, j]); minColorValue = Math.Min(minColorValue, ColorValues[i, j]); } } } // make color value 0 at texture coordinate 0.5 if (Math.Abs(minColorValue) < Math.Abs(maxColorValue)) { minColorValue = -maxColorValue; } else { maxColorValue = -minColorValue; } #endregion // set the texture coordinates by z-value or ColorValue var texcoords = new Point[rows, columns]; if (OriginalData == null || ColorCoding != ComplexPlainVisualizer.ColorCoding.Custom) { for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double u = (Points[i, j].Z - minZ) / (maxZ - minZ); //double v = if (ColorValues != null) { u = (ColorValues[i, j] - minColorValue) / (maxColorValue - minColorValue); } texcoords[i, j] = new Point(u, u); } } } else { for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double u = MathUtil.Scale(minZ, maxZ, Math.Log10(OriginalData[i, j].Z), 0.5); double v = OriginalData[i, j].W; double uu = 0.5 + u * Math.Cos(v); double vv = 0.5 + u * Math.Sin(v); texcoords[i, j] = new Point(uu, vv); } } } if (AutoScale) { ScaleX = 10 / Math.Abs(maxX - minX); ScaleY = 10 / Math.Abs(maxY - minY); ScaleZ = 5 / Math.Abs(maxZ - minZ); } var surfaceMeshBuilder = new MeshBuilder(); surfaceMeshBuilder.AddRectangularMesh(Points, texcoords); surfaceMeshBuilder.Scale(ScaleX, ScaleY, ScaleZ); var surfaceModel = new GeometryModel3D(surfaceMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); surfaceModel.BackMaterial = surfaceModel.Material; //RealmaxX = maxX; //RealminX = minX; //RealmaxY = maxY; //RealminY = minY; //RealmaxZ = maxZ; //RealminZ = minZ; maxX *= ScaleX; minX *= ScaleX; maxY *= ScaleY; minY *= ScaleY; maxZ *= ScaleZ; minZ *= ScaleZ; IntervalX = (maxX - minX) / SubAxisCount; IntervalY = (maxY - minY) / SubAxisCount; IntervalZ = (maxZ - minZ) / SubAxisCount; #region eje x var axesMeshBuilder = new MeshBuilder(); for (double x = minX; x <= maxX; x += IntervalX) { double j = (x - minX) / (maxX - minX) * (columns - 1); //var path = new List<Point3D> { new Point3D(x , minY , minZ) }; var path = new List <Point3D> { new Point3D(x, minY, minZ) }; for (int i = 0; i < rows; i++) { Point3D p = BilinearInterpolation(Points, i, j); p.X *= ScaleX; p.Y *= ScaleY; p.Z *= ScaleZ; path.Add(p); } path.Add(new Point3D(x, maxY, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 9, false); GeometryModel3D label = TextCreator.CreateTextLabelModel3D(StringUtils.CodeString(x / ScaleX), Brushes.Black, true, FontSize, new Point3D(x, minY - FontSize * 2.5, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("X-axis", Brushes.Black, true, FontSize, new Point3D((minX + maxX) * 0.5, minY - FontSize * 6, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } #endregion #region eje y for (double y = minY; y <= maxY; y += IntervalY) { double i = (y - minY) / (maxY - minY) * (rows - 1); var path = new List <Point3D> { new Point3D(minX, y, minZ) }; for (int j = 0; j < columns; j++) { Point3D p = BilinearInterpolation(Points, i, j); p.X *= ScaleX; p.Y *= ScaleY; p.Z *= ScaleZ; path.Add(p); } path.Add(new Point3D(maxX, y, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 9, false); GeometryModel3D label = TextCreator.CreateTextLabelModel3D(StringUtils.CodeString(y / ScaleY), Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 3, y, minZ), new Vector3D(1, 0, 0), new Vector3D(0, 1, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Y-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, (minY + maxY) * 0.5, minZ), new Vector3D(0, 1, 0), new Vector3D(-1, 0, 0)); plotModel.Children.Add(label); } #endregion #region eje z double z0 = (int)(minZ / IntervalZ) * IntervalZ; for (double z = z0; z <= maxZ + double.Epsilon; z += IntervalZ) { GeometryModel3D label = TextCreator.CreateTextLabelModel3D(StringUtils.CodeString(z / ScaleZ), Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 3, maxY, z), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Z-axis", Brushes.Black, true, FontSize, new Point3D(minX - FontSize * 10, maxY, (minZ + maxZ) * 0.5), new Vector3D(0, 0, 1), new Vector3D(1, 0, 0)); plotModel.Children.Add(label); } #endregion var bb = new Rect3D(minX, minY, minZ, maxX - minX, maxY - minY, 0 * (maxZ - minZ)); axesMeshBuilder.AddBoundingBox(bb, LineThickness); var axesModel = new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Black); plotModel.Children.Add(surfaceModel); plotModel.Children.Add(axesModel); return(plotModel); }