public AddRectangularMesh ( IList |
||
points | IList |
/// The one-dimensional array of points. The points are stored row-by-row. /// |
columns | int | /// The number of columns in the rectangular mesh. /// |
리턴 | void |
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, minY, minZ)}; for (int i = 0; i < rows; i++) { path.Add(BilinearInterpolation(Points, i, j)); } path.Add(new Point3D(x, maxY, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 9, 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, 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, 9, 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() { if (Points == null || Points.Length == 0) return 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 minColorValue = double.MaxValue; double maxColorValue = double.MinValue; minX = Points.OfType<Point3D>().Min(x => x.X); maxX = Points.OfType<Point3D>().Max(x => x.X); minY = Points.OfType<Point3D>().Min(x => x.Y); maxY = Points.OfType<Point3D>().Max(x => x.Y); minZ = Points.OfType<Point3D>().Min(x => x.Z); maxZ = Points.OfType<Point3D>().Max(x => x.Z); if (ColorValues != null) minColorValue = ColorValues.OfType<double>().Min(x => x); if (ColorValues != null) maxColorValue = ColorValues.OfType<double>().Max(x => x); if (Functions.Abs(minColorValue) < Functions.Abs(maxColorValue)) minColorValue = -maxColorValue; else maxColorValue = -minColorValue; BitmapPixelMaker bm_maker = new BitmapPixelMaker(columns, rows); for (int ix = 0; ix < columns; ix++) { for (int iy = 0; iy < rows; iy++) { try { byte red, green, blue; MapRainbowColor(Points[ix, iy].Z, minZ, maxZ, out red, out green, out blue); bm_maker.SetPixel(ix, iy, red, green, blue, 255); } catch { } } } var texcoords = new Point[rows, columns]; for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) { texcoords[i, j] = new Point(i, j); } var surfaceMeshBuilder = new MeshBuilder(); surfaceMeshBuilder.AddRectangularMesh(Points, texcoords); var surfaceModel = new GeometryModel3D(surfaceMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(new ImageBrush(bm_maker.MakeBitmap(128, 128)), 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, minY, minZ)}; for (int i = 0; i < rows; i++) { path.Add(BilinearInterpolation(Points, i, j)); } path.Add(new Point3D(x, maxY, minZ)); axesMeshBuilder.AddTube(path, LineThickness, 9, false); GeometryModel3D label = TextCreator.CreateTextLabelModel3D(x.ToString(), Brushes.Black, true, FontSize * 3, 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("Axe réel", Brushes.Black, true, FontSize * 10, new Point3D((minX + maxX) * 0.25, minY - FontSize * 6 - 0.5, 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, 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, 9, false); GeometryModel3D label = TextCreator.CreateTextLabelModel3D(y.ToString(), Brushes.Black, true, FontSize * 3, new Point3D(minX - FontSize * 3, y, minZ), new Vector3D(0, 1, 0), new Vector3D(1, 0, 0)); plotModel.Children.Add(label); } { GeometryModel3D label = TextCreator.CreateTextLabelModel3D("Axe imaginaire", Brushes.Black, true, FontSize * 10, 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 * 3, 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("Module", Brushes.Black, true, FontSize * 10, new Point3D(minX - FontSize * 10 - 1.5, maxY, (minZ + maxZ) * 0.5), new Vector3D(1, 0, 0), new Vector3D(0, 0, 1)); 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(surfaceModel); plotModel.Children.Add(axesModel); 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; }
private void CreateInitialMesh() { var pts = new Point3D[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { pts[i, j] = new Point3D(-Length * j / (m - 1), 0, PoleHeight - Height * i / (n - 1)); } var mb = new MeshBuilder(false, true); mb.AddRectangularMesh(pts, null, false, false); Mesh = mb.ToMesh(); }
/// <summary> /// This function contains all the "business logic" for constructing a SurfacePlot 3D. /// </summary> /// <returns>A Model3DGroup containing all the component models (mesh, surface definition, grid objects, etc).</returns> private Model3DGroup CreateModel() { var newModelGroup = new Model3DGroup(); double lineThickness = 0.01; double axesOffset = 0.05; // Get relevant constaints from the DataPoints object int numberOfRows = DataPoints.GetUpperBound(0) + 1; int numberOfColumns = DataPoints.GetUpperBound(1) + 1; // Determine the x, y, and z ranges of the DataPoints collection 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 < numberOfRows; i++) { for (int j = 0; j < numberOfColumns; j++) { double x = DataPoints[i, j].X; double y = DataPoints[i, j].Y; double z = DataPoints[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]); } } } /* TEMP */ int numberOfXAxisTicks = 10; int numberOfYAxisTicks = 10; int numberOfZAxisTicks = 5; double XAxisInterval = (maxX - minX) / numberOfXAxisTicks; double YAxisInterval = (maxY - minY) / numberOfYAxisTicks; double ZAxisInterval = (maxZ - minZ) / numberOfZAxisTicks; /* /TEMP */ // Set color value to 0 at texture coordinate 0.5, with an even spread in either direction if (Math.Abs(minColorValue) < Math.Abs(maxColorValue)) { minColorValue = -maxColorValue; } else { maxColorValue = -minColorValue; } // Set the texture coordinates by either z-value or ColorValue var textureCoordinates = new Point[numberOfRows, numberOfColumns]; for (int i = 0; i < numberOfRows; i++) { for (int j = 0; j < numberOfColumns; j++) { double tc; if (ColorValues != null) { tc = (ColorValues[i, j] - minColorValue) / (maxColorValue - minColorValue); } else { tc = (DataPoints[i, j].Z - minZ) / (maxZ - minZ); } textureCoordinates[i, j] = new Point(tc, tc); } } // Build the surface model (i.e. the coloured surface model) MeshBuilder surfaceModelBuilder = new MeshBuilder(); surfaceModelBuilder.AddRectangularMesh(DataPoints, textureCoordinates); GeometryModel3D surfaceModel = new GeometryModel3D(surfaceModelBuilder.ToMesh(), MaterialHelper.CreateMaterial(SurfaceBrush, null, null, 1, 0)); surfaceModel.BackMaterial = surfaceModel.Material; // Instantiate MeshBuilder objects for the Grid and SurfaceMeshLines meshes MeshBuilder surfaceMeshLinesBuilder = new MeshBuilder(); MeshBuilder surfaceContourLinesBuilder = new MeshBuilder(); MeshBuilder gridBuilder = new MeshBuilder(); // Build the axes labels model (i.e. the object that holds the axes labels and ticks) ModelVisual3D axesLabelsModel = new ModelVisual3D(); // Loop through x intervals - for the surface meshlines, the grid, and X axes ticks for (double x = minX; x <= maxX + 0.0001; x += XAxisInterval) { // Add surface mesh lines which denote intervals along the x-axis var surfacePath = new List<Point3D>(); double i = (x - minX) / (maxX - minX) * (numberOfColumns - 1); for (int j = 0; j < numberOfColumns; j++) { surfacePath.Add(DoBilinearInterpolation(DataPoints, i, j)); } surfaceMeshLinesBuilder.AddTube(surfacePath, lineThickness, 9, false); // Axes labels BillboardTextVisual3D label = new BillboardTextVisual3D(); label.Text = string.Format("{0:F2}", x); label.Position = new Point3D(x, minY - axesOffset, minZ - axesOffset); axesLabelsModel.Children.Add(label); // Grid lines var gridPath = new List<Point3D>(); gridPath.Add(new Point3D(x, minY, minZ)); gridPath.Add(new Point3D(x, maxY, minZ)); gridPath.Add(new Point3D(x, maxY, maxZ)); gridBuilder.AddTube(gridPath, lineThickness, 9, false); } // Loop through y intervals - for the surface meshlines, the grid, and Y axes ticks for (double y = minY; y <= maxY + 0.0001; y += YAxisInterval) { // Add surface mesh lines which denote intervals along the y-axis var path = new List<Point3D>(); double j = (y - minY) / (maxY - minY) * (numberOfRows - 1); for (int i = 0; i < numberOfRows; i++) { path.Add(DoBilinearInterpolation(DataPoints, i, j)); } surfaceMeshLinesBuilder.AddTube(path, lineThickness, 9, false); // Axes labels BillboardTextVisual3D label = new BillboardTextVisual3D(); label.Text = string.Format("{0:F2}", y); label.Position = new Point3D(minX - axesOffset, y, minZ - axesOffset); axesLabelsModel.Children.Add(label); // Grid lines var gridPath = new List<Point3D>(); gridPath.Add(new Point3D(minX, y, minZ)); gridPath.Add(new Point3D(maxX, y, minZ)); gridPath.Add(new Point3D(maxX, y, maxZ)); gridBuilder.AddTube(gridPath, lineThickness, 9, false); } // Loop through z intervals - for the grid, and Z axes ticks for (double z = minZ; z <= maxZ + 0.0001; z += ZAxisInterval) { // Grid lines var path = new List<Point3D>(); path.Add(new Point3D(minX, maxY, z)); path.Add(new Point3D(maxX, maxY, z)); path.Add(new Point3D(maxX, minY, z)); gridBuilder.AddTube(path, lineThickness, 9, false); // Axes labels BillboardTextVisual3D label = new BillboardTextVisual3D(); label.Text = string.Format("{0:F2}", z); label.Position = new Point3D(minX - axesOffset, maxY + axesOffset, z); axesLabelsModel.Children.Add(label); } // Add axes labels BillboardTextVisual3D xLabel = new BillboardTextVisual3D(); xLabel.Text = "X Axis"; xLabel.Position = new Point3D((maxX - minX) / 2, minY - 3 * axesOffset, minZ - 5 * axesOffset); axesLabelsModel.Children.Add(xLabel); BillboardTextVisual3D yLabel = new BillboardTextVisual3D(); yLabel.Text = "Y Axis"; yLabel.Position = new Point3D(minX - 3 * axesOffset, (maxY - minY) / 2, minZ - 5 * axesOffset); axesLabelsModel.Children.Add(yLabel); BillboardTextVisual3D zLabel = new BillboardTextVisual3D(); zLabel.Text = "Z Axis"; zLabel.Position = new Point3D(minX - 5 * axesOffset, maxY + 5 * axesOffset, 0); // Note: trying to find the midpoint of minZ, maxZ doesn't work when minZ = -0.5 and maxZ = 0.5... axesLabelsModel.Children.Add(zLabel); // Create models from MeshBuilders GeometryModel3D surfaceMeshLinesModel = new GeometryModel3D(surfaceMeshLinesBuilder.ToMesh(), Materials.Black); GeometryModel3D gridModel = new GeometryModel3D(gridBuilder.ToMesh(), Materials.Black); // Update model group //this.Children.Add(axesLabelsModel); newModelGroup.Children.Add(surfaceModel); newModelGroup.Children.Add(surfaceMeshLinesModel); newModelGroup.Children.Add(gridModel); //ScaleTransform3D surfaceTransform = new ScaleTransform3D(20, 20, 20, 0, 0, 0); //newModelGroup.Transform = surfaceTransform; return newModelGroup; }
/// <summary> /// Creates the 3D model of the terrain. /// </summary> /// <param name="lod"> /// The level of detail. /// </param> /// <returns> /// The Model3D. /// </returns> public GeometryModel3D CreateModel(int lod) { int ni = this.Height / lod; int nj = this.Width / lod; var pts = new List<Point3D>(ni * nj); double mx = (this.Left + this.Right) / 2; double my = (this.Top + this.Bottom) / 2; double mz = (this.MinimumZ + this.MaximumZ) / 2; this.Offset = new Point3D(mx, my, mz); for (int i = 0; i < ni; i++) { for (int j = 0; j < nj; j++) { double x = this.Left + (this.Right - this.Left) * j / (nj - 1); double y = this.Top + (this.Bottom - this.Top) * i / (ni - 1); double z = this.Data[i * lod * this.Width + j * lod]; x -= this.Offset.X; y -= this.Offset.Y; z -= this.Offset.Z; pts.Add(new Point3D(x, y, z)); } } var mb = new MeshBuilder(false, false); mb.AddRectangularMesh(pts, nj); var mesh = mb.ToMesh(); var material = Materials.Green; if (this.Texture != null) { this.Texture.Calculate(this, mesh); material = this.Texture.Material; mesh.TextureCoordinates = this.Texture.TextureCoordinates; } return new GeometryModel3D { Geometry = mesh, Material = material, BackMaterial = material }; }
/// <summary> /// Do the tessellation and return the <see cref="MeshGeometry3D"/>. /// </summary> /// <returns>A triangular mesh geometry.</returns> protected override MeshGeometry3D Tessellate() { Vector3D u = this.LengthDirection; Vector3D w = this.Normal; Vector3D v = Vector3D.CrossProduct(w, u); u = Vector3D.CrossProduct(v, w); u.Normalize(); v.Normalize(); w.Normalize(); double le = this.Length; double wi = this.Width; var pts = new List<Point3D>(); for (int i = 0; i < this.DivLength; i++) { double fi = -0.5 + ((double)i / (this.DivLength - 1)); for (int j = 0; j < this.DivWidth; j++) { double fj = -0.5 + ((double)j / (this.DivWidth - 1)); pts.Add(this.Origin + (u * le * fi) + (v * wi * fj)); } } var builder = new MeshBuilder(false, true); builder.AddRectangularMesh(pts, this.DivWidth); return builder.ToMesh(); }
/// <summary> /// Raw Left==Helix Front /// </summary> /// <param name="plotModel"></param> /// <param name="brush"></param> /// <param name="currentPosition"></param> private void CreateLeftSlice(Model3DGroup plotModel, sysMedia.Brush brush, double currentPosition) { var position = currentPosition * _realRect3D.SizeY; var sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, position, _realRect3D.SizeZ), new Point3D(_realRect3D.SizeX, position, _realRect3D.SizeZ), new Point3D(0, position, 0), new Point3D(_realRect3D.SizeX, position, 0) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(brush))); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(_realRect3D.SizeX, position, _realRect3D.SizeZ), new Point3D(0, position, _realRect3D.SizeZ), new Point3D(_realRect3D.SizeX, position, 0), new Point3D(0, position, 0) }, 2); var bgBrush = FilpAndRotateImageBrush(brush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); }
private void CreateFrontPartSlice(Model3DGroup plotModel, double currentPosition) { var position = (1 - currentPosition) * _realRect3D.SizeX; if (position < 0.0) return; #region Left var leftImageBrush = ClipImageBrush(LeftBrush, new Rect(0, 0, 1 - currentPosition, 1)); var sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, 0, _realRect3D.SizeZ), new Point3D(position, 0, _realRect3D.SizeZ), new Point3D(0, 0, 0), new Point3D(position, 0, 0) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(leftImageBrush))); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(position, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(0, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(position, _realRect3D.SizeY, 0), new Point3D(0, _realRect3D.SizeY, 0) }, 2); leftImageBrush = ClipImageBrush(RightBrush, new Rect(0, 0, 1 - currentPosition, 1)); var bgBrush = FilpAndRotateImageBrush(leftImageBrush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); #endregion Left #region Top var topImageBrush = ClipImageBrush(TopBrush, new Rect(0, 0, 1, 1 - currentPosition)); topImageBrush = RotateImageBrush(topImageBrush, 270); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(position, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(0, 0, _realRect3D.SizeZ), new Point3D(position, 0, _realRect3D.SizeZ) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(topImageBrush))); sectionMeshBuilder = new MeshBuilder(); //The sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(position, 0, 0), new Point3D(position, _realRect3D.SizeY, 0), new Point3D(0, 0, 0), new Point3D(0, _realRect3D.SizeY, 0) }, 2); topImageBrush = ClipImageBrush(BottomBrush, new Rect(0, 0, 1, 1 - currentPosition)); bgBrush = FilpImageBrush(topImageBrush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); #endregion Top }
private void CreateLeftPartSlice(Model3DGroup plotModel, double currentPosition) { #region Top var position = currentPosition * _realRect3D.SizeY; var topImageBrush = ClipImageBrush(TopBrush, new Rect(currentPosition, 0 , 1 - currentPosition, 1)); var sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, position, _realRect3D.SizeZ), new Point3D(0, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(_realRect3D.SizeX, position, _realRect3D.SizeZ), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, _realRect3D.SizeZ) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(topImageBrush))); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(_realRect3D.SizeX, position, 0), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, 0), new Point3D(0, position, 0), new Point3D(0, _realRect3D.SizeY, 0) }, 2); topImageBrush = ClipImageBrush(BottomBrush, new Rect(currentPosition, 0 , 1 - currentPosition, 1)); var bgBrush = topImageBrush; bgBrush = FilpImageBrush(bgBrush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); #endregion Top #region Front var frontImageBrush = ClipImageBrush(FrontBrush, new Rect(currentPosition, 0 , (1 - currentPosition), 1)); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(_realRect3D.SizeX, position, _realRect3D.SizeZ), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(_realRect3D.SizeX, position, 0), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, 0) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(frontImageBrush))); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, _realRect3D.SizeY, _realRect3D.SizeZ), new Point3D(0, position, _realRect3D.SizeZ), new Point3D(0, _realRect3D.SizeY, 0), new Point3D(0, position, 0) }, 2); frontImageBrush = ClipImageBrush(BackBrush, new Rect(currentPosition, 0 , 1 - currentPosition, 1)); bgBrush = FilpAndRotateImageBrush(frontImageBrush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); #endregion Front }
private void CreateTopPartSlice(Model3DGroup plotModel, double currentPosition) { var position = (1 - currentPosition) * _realRect3D.SizeZ; if (position < 0.0) return; #region Left var leftImageBrush = ClipImageBrush(LeftBrush, new Rect(0, currentPosition, 1, 1 - currentPosition)); var sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, 0, position), new Point3D(_realRect3D.SizeX, 0, position), new Point3D(0, 0, 0), new Point3D(_realRect3D.SizeX, 0, 0) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(leftImageBrush))); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, position), new Point3D(0, _realRect3D.SizeY, position), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, 0), new Point3D(0, _realRect3D.SizeY, 0) }, 2); leftImageBrush = ClipImageBrush(RightBrush, new Rect(0, currentPosition, 1, 1 - currentPosition)); var bgBrush = FilpAndRotateImageBrush(leftImageBrush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); #endregion Left #region Front var frontImageBrush = ClipImageBrush(FrontBrush, new Rect(0, currentPosition, 1, 1 - currentPosition)); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(_realRect3D.SizeX, 0, position), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, position), new Point3D(_realRect3D.SizeX, 0, 0), new Point3D(_realRect3D.SizeX, _realRect3D.SizeY, 0) }, 2); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(frontImageBrush))); sectionMeshBuilder = new MeshBuilder(); sectionMeshBuilder.AddRectangularMesh( new[] { new Point3D(0, _realRect3D.SizeY, position), new Point3D(0, 0, position), new Point3D(0, _realRect3D.SizeY, 0), new Point3D(0, 0, 0) }, 2); frontImageBrush = ClipImageBrush(BackBrush, new Rect(0, currentPosition, 1, 1 - currentPosition)); bgBrush = FilpAndRotateImageBrush(frontImageBrush); plotModel.Children.Add(new GeometryModel3D(sectionMeshBuilder.ToMesh(), MaterialHelper.CreateMaterial(bgBrush))); #endregion Front }
private Model3D CreateModel() { bool isCylindarMode = CylindarMode && ExpendedBrush != null && (SlideDirection == CooridinateDirection.ZN || SlideDirection == CooridinateDirection.ZP); bool isIntersectionmode = IntersectionMode && SectionBrush != null; bool isIntersectedCylindarMode = isCylindarMode && isIntersectionmode; var plotModel = new Model3DGroup(); var axesMeshBuilder = new MeshBuilder(); _realRect3D = GetSampleImageBox(); axesMeshBuilder.AddBoundingBox(_realRect3D, 0.01); plotModel.Children.Add(new GeometryModel3D(axesMeshBuilder.ToMesh(), Materials.Yellow)); var flipTransform = new ScaleTransform(1, -1, 0.5, 0.5); var znBrush = ZNBrush?.Clone(); var zpBrush = ZPBrush?.Clone(); if (zpBrush != null) { zpBrush.Transform = flipTransform; } var ynBrush = YNBrush?.Clone(); var ypBrush = YPBrush?.Clone(); if (ypBrush != null) { ypBrush.Transform = flipTransform; } var xnBrush = XNBrush?.Clone(); var xpBrush = XPBrush?.Clone(); if (xpBrush != null) { xpBrush.Transform = flipTransform; } var expBrush = ExpendedBrush?.Clone(); Rect3D rectDraw = _realRect3D; if (isIntersectionmode) { switch (SlideDirection) { case CooridinateDirection.XP: { rectDraw.SizeX = SectionPosition; xpBrush = SectionBrush.Clone(); xpBrush.Transform = flipTransform; double c = SectionPosition / _realRect3D.SizeX; ynBrush.Viewbox = new Rect(0, 0, 1, c); ypBrush.Viewbox = new Rect(0, 0, 1, c); znBrush.Viewbox = new Rect(0, 0, c, 1); zpBrush.Viewbox = new Rect(0, 0, c, 1); } break; case CooridinateDirection.XN: { rectDraw.X = SectionPosition; rectDraw.SizeX -= rectDraw.X; xnBrush = SectionBrush.Clone(); double c = SectionPosition / _realRect3D.SizeX; ynBrush.Viewbox = new Rect(0, c, 1, 1 - c); ypBrush.Viewbox = new Rect(0, c, 1, 1 - c); znBrush.Viewbox = new Rect(c, 0, 1 - c, 1); zpBrush.Viewbox = new Rect(c, 0, 1 - c, 1); } break; case CooridinateDirection.YP: { rectDraw.SizeY = SectionPosition; ypBrush = SectionBrush.Clone(); ypBrush.Transform = flipTransform; double c = SectionPosition / _realRect3D.SizeY; xnBrush.Viewbox = new Rect(0, 0, c, 1); xpBrush.Viewbox = new Rect(0, 0, c, 1); znBrush.Viewbox = new Rect(0, 0, 1, c); zpBrush.Viewbox = new Rect(0, 0, 1, c); } break; case CooridinateDirection.YN: { rectDraw.Y = SectionPosition; rectDraw.SizeY -= rectDraw.Y; ynBrush = SectionBrush.Clone(); double c = SectionPosition / _realRect3D.SizeY; xnBrush.Viewbox = new Rect(c, 0, 1 - c, 1); xpBrush.Viewbox = new Rect(c, 0, 1 - c, 1); znBrush.Viewbox = new Rect(0, c, 1, 1 - c); zpBrush.Viewbox = new Rect(0, c, 1, 1 - c); } break; case CooridinateDirection.ZP: { rectDraw.SizeZ = SectionPosition; zpBrush = SectionBrush.Clone(); zpBrush.Transform = flipTransform; double c = SectionPosition / _realRect3D.SizeZ; ynBrush.Viewbox = new Rect(0, 0, c, 1); ypBrush.Viewbox = new Rect(0, 0, c, 1); xnBrush.Viewbox = new Rect(0, 0, 1, c); xpBrush.Viewbox = new Rect(0, 0, 1, c); expBrush.Viewbox = new Rect(0, 0, 1, c); } break; case CooridinateDirection.ZN: { rectDraw.Z = SectionPosition; rectDraw.SizeZ -= rectDraw.Z; znBrush = SectionBrush.Clone(); double c = SectionPosition / _realRect3D.SizeZ; ynBrush.Viewbox = new Rect(c, 0, 1 - c, 1); ypBrush.Viewbox = new Rect(c, 0, 1 - c, 1); xnBrush.Viewbox = new Rect(0, c, 1, 1 - c); xpBrush.Viewbox = new Rect(0, c, 1, 1 - c); expBrush.Viewbox = new Rect(0, c, 1, 1 - c); } break; default: break; } } MeshBuilder mb = null; if (!isCylindarMode) { // draw faces in z directions mb = new MeshBuilder(); mb.AddRectangularMesh( new[] { new Point3D(rectDraw.X,rectDraw.Y,rectDraw.Z), //0,0,0 new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y,rectDraw.Z), //1,0,0 new Point3D(rectDraw.X,rectDraw.Y+rectDraw.SizeY,rectDraw.Z), //0,1,0 new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y+rectDraw.SizeY,rectDraw.Z) //1,1,0 }, 2); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(znBrush))); mb = new MeshBuilder(); mb.AddRectangularMesh( new[] { new Point3D(rectDraw.X,rectDraw.Y+rectDraw.SizeY,rectDraw.Z+rectDraw.SizeZ), // 0,1,1 new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y+rectDraw.SizeY,rectDraw.Z+rectDraw.SizeZ), // 1,1,1 new Point3D(rectDraw.X,rectDraw.Y,rectDraw.Z+rectDraw.SizeZ), // 0,0,1 new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y,rectDraw.Z+rectDraw.SizeZ) // 1,0,1 } , 2); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(zpBrush))); // draw faces in y directions mb = new MeshBuilder(); mb.AddRectangularMesh( new[] { new Point3D(rectDraw.X,rectDraw.Y,rectDraw.Z), new Point3D(rectDraw.X,rectDraw.Y,rectDraw.Z+rectDraw.SizeZ), new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y,rectDraw.Z), new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y,rectDraw.Z+rectDraw.SizeZ) }, 2); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(ynBrush))); mb = new MeshBuilder(); mb.AddRectangularMesh( new[] { new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y+rectDraw.SizeY,rectDraw.Z), new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y+rectDraw.SizeY,rectDraw.Z+rectDraw.SizeZ), new Point3D(rectDraw.X,rectDraw.Y+rectDraw.SizeY,rectDraw.Z), new Point3D(rectDraw.X,rectDraw.Y+rectDraw.SizeY,rectDraw.Z+rectDraw.SizeZ) }, 2); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(ypBrush))); // draw faces in x directions mb = new MeshBuilder(); mb.AddRectangularMesh( new[] { new Point3D(rectDraw.X,rectDraw.Y,rectDraw.Z), new Point3D(rectDraw.X,rectDraw.Y+rectDraw.SizeY,rectDraw.Z), new Point3D(rectDraw.X,rectDraw.Y,rectDraw.Z+rectDraw.SizeZ), new Point3D(rectDraw.X,rectDraw.Y+rectDraw.SizeY,rectDraw.Z+rectDraw.SizeZ) }, 2); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(xnBrush))); mb = new MeshBuilder(); mb.AddRectangularMesh( new[] { new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y,rectDraw.Z+rectDraw.SizeZ), new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y+rectDraw.SizeY,rectDraw.Z+rectDraw.SizeZ), new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y,rectDraw.Z), new Point3D(rectDraw.X+rectDraw.SizeX,rectDraw.Y+rectDraw.SizeY,rectDraw.Z) }, 2); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(xpBrush))); } if (isCylindarMode) { int div = 121; mb = new MeshBuilder(); double s = Math.Min(_realRect3D.SizeX, _realRect3D.SizeY); double shiftx = (_realRect3D.SizeX - s) / 2; double shifty = (_realRect3D.SizeY - s) / 2; var startCentre = new Point3D(Centre.X * s + shiftx, Centre.Y * s + shifty, rectDraw.Z); var endCentre = new Point3D(Centre.X * s + shiftx, Centre.Y * s + shifty, rectDraw.Z + rectDraw.SizeZ); double r = Radius * s; mb.AddCylindarZ(startCentre, r, rectDraw.SizeZ, div); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(expBrush))); mb = new MeshBuilder(); mb.AddCircleInZCross(startCentre, r, div, false); znBrush.Viewbox = new Rect((startCentre.X - r) / _realRect3D.SizeX, (startCentre.Y - r) / _realRect3D.SizeY, (2 * r) / _realRect3D.SizeX, (2 * r) / _realRect3D.SizeY); plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(znBrush))); mb = new MeshBuilder(); mb.AddCircleInZCross(endCentre, r, div, true); zpBrush.Viewbox = new Rect((startCentre.X - r) / _realRect3D.SizeX, (startCentre.Y - r) / _realRect3D.SizeY, (2 * r) / _realRect3D.SizeX, (2 * r) / _realRect3D.SizeY); zpBrush.Transform = null; plotModel.Children.Add(new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(zpBrush))); } return plotModel; }