コード例 #1
0
        private void OnGridPropertyChanged(object sender, EventArgs e)
        {
            GridderSource source = this.sim3D.Tag as GridderSource;

            if (source == null)
            {
                return;
            }

            List <SimLabGrid> gridders = this.sim3D.Scene.SceneContainer.Traverse <SimLabGrid>().ToList <SimLabGrid>();

            if (gridders.Count <= 0)
            {
                return;
            }

            SimLabGrid grid = gridders[0];

            GridProperty prop = this.CurrentProperty;

            if (prop == null)
            {
                return;
            }
            float minValue = prop.MinValue;
            float maxValue = prop.MaxValue;
            float step     = (maxValue - minValue) / 10.0f;

            if (step <= 0.0f)
            {
                step = 1.0f;
            }

            this.sim3D.SetColorIndicator(minValue, maxValue, step);
            TexCoordBuffer textureCoordinates = source.CreateTextureCoordinates(prop.GridIndexes, prop.Values, minValue, maxValue);

            grid.SetTextureCoods(textureCoordinates);

            DynamicUnstructureGrid           dynamicUnstructureGrid          = gridders[0] as DynamicUnstructureGrid;
            DynamicUnstructuredGridderSource dynamicUnstructureGridderSource = source as DynamicUnstructuredGridderSource;

            if (dynamicUnstructureGrid != null && dynamicUnstructureGridderSource != null)
            {
                TexCoordBuffer anotherTextureCoordinates = dynamicUnstructureGridderSource.CreateFractureTextureCoordinates(prop.GridIndexes, prop.Values, minValue, maxValue);
                dynamicUnstructureGrid.SetFractionTextureCoords(anotherTextureCoordinates);
            }

            this.sim3D.Invalidate();
        }
コード例 #2
0
        private void CreateCatesianGridVisual3D(object sender, EventArgs e)
        {
            try
            {
                string fileName = @"geometry.txt";
                DynamicUnstructureGeometryLoader loader = new DynamicUnstructureGeometryLoader();
                // use CatesianGridderSource to fill HexahedronGridderElement's content.
                DynamicUnstructuredGridderSource source = loader.LoadSource(fileName);
                source.Init();

                int nx        = source.NX;
                int ny        = source.NY;
                int nz        = source.NZ;
                int dimenSize = nx * ny * nz;

                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);

                float   dx      = System.Convert.ToSingle(this.tbDX.Text);
                float   dy      = System.Convert.ToSingle(this.gbDY.Text);
                float   dz      = System.Convert.ToSingle(this.tbDZ.Text);
                float[] dxArray = initArray(dimenSize, dx);
                float[] dyArray = initArray(dimenSize, dy);
                float[] dzArray = initArray(dimenSize, dz);



                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;
                DynamicUnstructureGeometry geometry = source.CreateMesh() as DynamicUnstructureGeometry;
                TexCoordBuffer             matrixTextureCoordinates    = source.CreateTextureCoordinates(gridIndexes, gridValues, minValue, maxValue);
                TexCoordBuffer             fractureTextureCoordindates = source.CreateFractureTextureCoordinates(gridIndexes, gridValues, minValue, maxValue);
                Bitmap texture = ColorPaletteHelper.GenBitmap(this.sim3D.uiColorIndicator.Data.ColorPalette);
                //geometry.Positions.Dump();
                //geometry.TriangleIndices.Dump();
                //MeshGeometry mesh = HexahedronGridderHelper.CreateMesh(source);
                DynamicUnstructureGrid gridder = new DynamicUnstructureGrid(this.sim3D.OpenGL, this.sim3D.Scene.CurrentCamera);
                gridder.Init(geometry);
                gridder.RenderGrid          = true;
                gridder.RenderGridWireframe = this.IsShowWireframe;
                gridder.SetTexture(texture);
                gridder.SetMatrixTextureCoords(matrixTextureCoordinates);
                gridder.SetFractionTextureCoords(fractureTextureCoordindates);

                this.element = gridder;

                //textureCoodinates.Dump();


                DateTime t1  = DateTime.Now;
                TimeSpan ts1 = t1 - t0;

                //mesh.VertexColors = HexahedronGridderHelper.FromColors(source, gridIndexes, colors, mesh.Visibles);
                //this.DebugMesh(mesh);

                //HexahedronGridderElement gridderElement = new HexahedronGridderElement(source, this.scientificVisual3DControl.Scene.CurrentCamera);
                //gridderElement.renderWireframe = false;
                //method1
                //gridderElement.Initialize(this.scientificVisual3DControl.OpenGL);

                //method2
                //gridderElement.Initialize(this.scientificVisual3DControl.OpenGL, mesh);
                DateTime t2 = DateTime.Now;

                //gridderElement.SetBoundingBox(mesh.Min, mesh.Max);
                this.sim3D.Tag = source;


                //gridderElement.Name = string.Format("element {0}", elementCounter++);
                //this.scientificVisual3DControl.AddModelElement(gridderElement);

                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());
            }
        }