public override MeshBase CreateMesh(GridderSource source) { PointGridderSource src = (PointGridderSource)source; PointPositionBuffer positions = new PointPositionBuffer(); PointRadiusBuffer radiusBuffer = null; int dimSize = src.DimenSize; // setup positions unsafe { positions.AllocMem(dimSize); Vertex *cells = (Vertex *)positions.Data; for (int gridIndex = 0; gridIndex < dimSize; gridIndex++) { Vertex p = src.Transform * src.Positions[gridIndex]; cells[gridIndex] = p; } } radiusBuffer = this.CreateRadiusBufferData(src, src.Radius); PointMeshGeometry3D mesh = new PointMeshGeometry3D(positions, radiusBuffer, dimSize); mesh.Max = src.TransformedActiveBounds.Max; mesh.Min = src.TransformedActiveBounds.Min; return(mesh); }
public override MeshBase CreateMesh(GridderSource source) { PointGridderSource src = (PointGridderSource)source; vec3 minvec3 = new vec3(); vec3 maxvec3 = new vec3(); bool isSet = false; PointPositionBuffer positions = new PointPositionBuffer(); PointRadiusBuffer radiusBuffer = null; int dimSize = src.DimenSize; Random random = new Random(); // setup positions unsafe { positions.AllocMem(dimSize); var cells = (vec3 *)positions.Data; for (int gridIndex = 0; gridIndex < dimSize; gridIndex++) { vec3 p = src.TranslateMatrix * src.Positions[gridIndex]; cells[gridIndex] = p; } } radiusBuffer = this.CreateRadiusBufferData(src, src.Radius); PointMeshGeometry3D mesh = new PointMeshGeometry3D(positions, radiusBuffer, dimSize); mesh.Max = src.TransformedActiveBounds.Max; mesh.Min = src.TransformedActiveBounds.Min; return(mesh); }
public override TexCoordBuffer CreateTextureCoordinates(GridderSource source, int[] gridIndexes, float[] values, float minValue, float maxValue) { PointGridderSource src = (PointGridderSource)source; int[] visibles = src.BindResultsVisibles(gridIndexes); int dimenSize = src.DimenSize; float[] textures = src.GetInvisibleTextureCoords(); float distance = Math.Abs(maxValue - minValue); for (int i = 0; i < gridIndexes.Length; i++) { int gridIndex = gridIndexes[i]; if (visibles[gridIndex] > 0) { float value = values[i]; if (value < minValue) { value = minValue; } if (value > maxValue) { value = maxValue; } if (!(distance <= 0.0f)) { textures[gridIndex] = (value - minValue) / distance; if (textures[gridIndex] < 0.5f) { textures[gridIndex] = 0.5f - (0.5f - textures[gridIndex]) * 0.99f; } else { textures[gridIndex] = (textures[gridIndex] - 0.5f) * 0.99f + 0.5f; } } else { //最小值最大值相等时,显示最小值的颜色 textures[gridIndex] = 0.01f; //textures[gridIndex] = 0; } } } PointTexCoordBuffer coordBuffer = new PointTexCoordBuffer(); unsafe { coordBuffer.AllocMem(src.DimenSize); float *coords = (float *)coordBuffer.Data; for (int gridIndex = 0; gridIndex < dimenSize; gridIndex++) { coords[gridIndex] = textures[gridIndex]; } } return(coordBuffer); }
protected static PointGridderSource DoLoadPointSet(StreamReader reader, int nx, int ny, int nz) { int dimenSize = nx * ny * nz; PointGridderSource ps = new PointGridderSource(); ps.NX = nx; ps.NY = ny; ps.NZ = nz; vec3 minValue = new vec3(); vec3 maxValue = new vec3(); char[] delimeters = new char[] { ' ', '\t' }; string line; vec3[] positions = new vec3[dimenSize]; int positionCount = 0; bool isSet = false; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (String.IsNullOrEmpty(line)) { continue; } string[] fields = line.Split(delimeters, StringSplitOptions.RemoveEmptyEntries); if (fields.Length >= 3) { float x = System.Convert.ToSingle(fields[0]); float y = System.Convert.ToSingle(fields[1]); float z = Math.Abs(System.Convert.ToSingle(fields[2])); //全部Z按深度来处理, vec3 pt = new vec3(x, y, z); if (!isSet) { minValue = pt; maxValue = pt; isSet = true; } minValue = vec3Helper.Minvec3(minValue, pt); maxValue = vec3Helper.Maxvec3(maxValue, pt); positions[positionCount] = pt; positionCount++; if (positionCount == dimenSize) { break; } } } if (positionCount != dimenSize) { throw new ArgumentException(String.Format("file format error,points number:{0} not equals DIMENS", positionCount, dimenSize)); } ps.Max = maxValue; ps.Min = minValue; ps.Positions = positions; return(ps); }
protected static PointGridderSource DoLoadPointSet(StreamReader reader) { PointGridderSource ps = new PointGridderSource(); vec3 minValue = new vec3(); vec3 maxValue = new vec3(); char[] delimeters = new char[] { ' ', '\t' }; string line; List <vec3> positions = new List <vec3>(); int positionCount = 0; bool isSet = false; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (String.IsNullOrEmpty(line)) { continue; } string[] fields = line.Split(delimeters, StringSplitOptions.RemoveEmptyEntries); if (fields.Length >= 3) { float x = System.Convert.ToSingle(fields[0]); float y = System.Convert.ToSingle(fields[1]); float z = Math.Abs(System.Convert.ToSingle(fields[2])); //全部Z按深度来处理, vec3 pt = new vec3(x, y, z); if (!isSet) { minValue = pt; maxValue = pt; isSet = true; } minValue = vec3Helper.Minvec3(minValue, pt); maxValue = vec3Helper.Maxvec3(maxValue, pt); positions.Add(pt); positionCount++; } } ps.Max = maxValue; ps.Min = minValue; ps.Positions = positions.ToArray <vec3>(); ps.NX = ps.Positions.Length; ps.NY = 1; ps.NZ = 1; if (positions.Count <= 0) { return(null); } return(ps); }
public PointRadiusBuffer CreateRadiusBufferData(PointGridderSource src, float radius) { PointRadiusBuffer radiusBuffer = new PointRadiusBuffer(); unsafe { int dimenSize = src.DimenSize; radiusBuffer.AllocMem(dimenSize); float* radiues = (float*)radiusBuffer.Data; for (int gridIndex = 0; gridIndex < dimenSize; gridIndex++) { radiues[gridIndex] = radius; } } return radiusBuffer; }
public PointRadiusBuffer CreateRadiusBufferData(PointGridderSource src, float radius) { PointRadiusBuffer radiusBuffer = new PointRadiusBuffer(); unsafe { int dimenSize = src.DimenSize; radiusBuffer.AllocMem(dimenSize); float *radiues = (float *)radiusBuffer.Data; for (int gridIndex = 0; gridIndex < dimenSize; gridIndex++) { radiues[gridIndex] = radius; } } return(radiusBuffer); }
public override MeshBase CreateMesh(GridderSource source) { PointGridderSource src = (PointGridderSource)source; Vertex minVertex = new Vertex(); Vertex maxVertex = new Vertex(); bool isSet = false; PointPositionBuffer positions = new PointPositionBuffer(); PointRadiusBuffer radiusBuffer = null; int dimSize = src.DimenSize; Random random = new Random(); // setup positions unsafe { positions.AllocMem(dimSize); Vertex *cells = (Vertex *)positions.Data; for (int gridIndex = 0; gridIndex < dimSize; gridIndex++) { Vertex p = src.Positions[gridIndex]; cells[gridIndex] = p; if (!isSet) { minVertex = p; maxVertex = p; isSet = true; } if (src.IsActiveBlock(gridIndex)) { minVertex = SimLab.SimGrid.helper.VertexHelper.MinVertex(minVertex, p); maxVertex = SimLab.SimGrid.helper.VertexHelper.MaxVertex(maxVertex, p); } } } radiusBuffer = this.CreateRadiusBufferData(src, src.Radius); PointMeshGeometry3D mesh = new PointMeshGeometry3D(positions, radiusBuffer, dimSize); mesh.Max = maxVertex; mesh.Min = minVertex; return(mesh); }
public PointSetGridderWell3DHelper(PointGridderSource source, IScientificCamera camera) { this.gridderSource = source; this.camera = camera; }
private void CreateGridVisual3D(object sender, EventArgs e) { try { int nx = 236365; int ny = 1; int nz = 1; float step = System.Convert.ToSingle(tbColorIndicatorStep.Text); //float radius = System.Convert.ToSingle(this.tbRadius.Text); float propMin = System.Convert.ToSingle(this.tbxPropertyMinValue.Text, CultureInfo.InvariantCulture); float propMax = System.Convert.ToSingle(this.tbxPropertyMaxValue.Text, CultureInfo.InvariantCulture); int dimenSize = nx * ny * nz; float dx = System.Convert.ToSingle(this.tbDX.Text); float dy = System.Convert.ToSingle(this.gbDY.Text); float dz = System.Convert.ToSingle(this.tbDZ.Text); // use CatesianGridderSource to fill HexahedronGridderElement's content. string fileName = @"TET5_cvxyz.txt"; PointSetLoader loader = new PointSetLoader(); PointGridderSource source = loader.LoadFromFile(fileName, nx, ny, nz); source.Init(); InitPropertiesAndSelectDefault(dimenSize, propMin, propMax); ///模拟获得网格属性 ///获得当前选中的属性 float minValue = this.CurrentProperty.MinValue; float maxValue = this.CurrentProperty.MaxValue; step = (maxValue * 1.0f - minValue * 1.0f) / 10; int[] gridIndexes = this.CurrentProperty.GridIndexes; float[] gridValues = this.CurrentProperty.Values; //设置色标的范围 this.sim3D.SetColorIndicator(minValue, maxValue, step); // use HexahedronGridderElement DateTime t0 = DateTime.Now; PointMeshGeometry3D geometry = source.CreateMesh() as PointMeshGeometry3D; TexCoordBuffer textureCoodinates = source.CreateTextureCoordinates(gridIndexes, gridValues, minValue, maxValue); Bitmap texture = ColorPaletteHelper.GenBitmap(this.sim3D.uiColorIndicator.Data.ColorPalette); PointGrid gridder = new PointGrid(this.sim3D.OpenGL, this.sim3D.Scene.CurrentCamera); gridder.Init(geometry); gridder.RenderGrid = true; gridder.RenderGridWireframe = this.IsShowWireframe; gridder.SetTexture(texture); gridder.SetTextureCoods(textureCoodinates); DateTime t1 = DateTime.Now; TimeSpan ts1 = t1 - t0; DateTime t2 = DateTime.Now; //gridderElement.SetBoundingBox(mesh.Min, mesh.Max); this.sim3D.Tag = source; DateTime t3 = DateTime.Now; // update ModelContainer's BoundingBox. BoundingBox boundingBox = this.sim3D.ModelContainer.BoundingBox; boundingBox.SetBounds(geometry.Min, geometry.Max); // update ViewType to UserView. this.sim3D.ViewType = ViewTypes.UserView; this.sim3D.AddModelElement(gridder); //mesh.Dispose(); StringBuilder msgBuilder = new StringBuilder(); msgBuilder.AppendLine(String.Format("create mesh in {0} secs", (t1 - t0).TotalSeconds)); msgBuilder.AppendLine(String.Format("init SceneElement in {0} secs", (t2 - t1).TotalSeconds)); msgBuilder.AppendLine(String.Format("total load in {0} secs", (t2 - t0).TotalSeconds)); String msg = msgBuilder.ToString(); MessageBox.Show(msg, "Summary", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception error) { MessageBox.Show(error.ToString()); } }