Пример #1
0
        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);
        }
Пример #2
0
 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 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;
            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);
        }
Пример #5
0
        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());
            }
        }