Specify a bounding box that marks a model's edges.
Inheritance: IBoundingBox
示例#1
0
        /// <summary>
        /// move camera to focus on selected scene object again.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void adjustCameraToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = this.objectsTreeView.SelectedNode;
            if (node == null) { return; }
            SceneObject obj = node.Tag as SceneObject;
            if (obj == null) { return; }
            var transform = obj.Renderer as IModelSpace;
            if (transform == null) { return; }
            vec3 position = transform.WorldPosition;
            var max = transform.ModelSize / 2;
            var min = -max;
            IBoundingBox translatedBox = new BoundingBox(min + position, max + position);
            this.scientificCanvas.Scene.FirstCamera.ZoomCamera(translatedBox);

            this.scientificCanvas.Invalidate();
        }
        protected override BoundingBox InitSourceActiveBounds()
        {
            if (this.NodeNum <= 0)
            { throw new ArgumentException("No nodes found"); }

            vec3[] nodes = this.Nodes;
            var boundingBox = new BoundingBox(nodes[0], nodes[0]);
            for (int i = 1; i < nodes.Length; i++)
            {
                boundingBox = boundingBox.Union(nodes[i]);
            }
            return boundingBox;
        }
示例#3
0
        //public PointRadiusBuffer CreateRadiusBuffer(float[] radius)
        //{
        //    return (this.Factory as PointGridFactory).CreateRadiusBufferData(this, radius);
        //}
        //public PointRadiusBuffer CreateRadiusBuffer(float radius)
        //{
        //    return (this.Factory as PointGridFactory).CreateRadiusBufferData(this, radius);
        //}
        protected override BoundingBox InitSourceActiveBounds()
        {
            if (this.Positions == null || this.Positions.Length <= 0)
            { throw new ArgumentException("Points has No Value"); }

            vec3 v = this.Positions[0];
            var boundingBox = new BoundingBox(v, v);
            for (int i = 1; i < this.Positions.Length; i++)
            {
                boundingBox = boundingBox.Union(this.Positions[i]);
            }
            return boundingBox;
        }
示例#4
0
        /// <summary>
        /// 初始化
        /// </summary>
        public virtual void Init()
        {
            if (this.gridIndexer == null)
            {
                this.gridIndexer = new GridIndexer(this.NX, this.NY, this.NZ);
            }

            if (this.ActiveBlocks == null)
            {
                this.ActiveBlocks = ArrayHelper.NewIntArray(this.DimenSize, 1);
            }
            if (this.zeroVisibles == null)
            {
                this.zeroVisibles = ArrayHelper.NewIntArray(this.DimenSize, 0);
            }
            if (this.invisibleTextures == null)
            {
                //初始化不可视
                this.invisibleTextures = ArrayHelper.NewFloatArray(this.DimenSize, 2);
            }

            this.InitGridCoordinates();

            this.SourceActiveBounds = this.InitSourceActiveBounds();
            //初始化
            mat4 identityMat = mat4.identity();
            vec3 center = this.SourceActiveBounds.GetCenter();
            //矩形三角形移动到中心点
            this.Position = -center;

            vec3 newcenter = this.Position * center;
            //System.Console.WriteLine(center);
            vec3 destMin = this.Position * this.SourceActiveBounds.MinPosition;
            vec3 destMax = this.Position * this.SourceActiveBounds.MaxPosition;

            //变换后的三维矩形六面体
            this.TransformedActiveBounds = new BoundingBox(destMin, destMax);
        }
        protected override CSharpGL.Tuple<WellRenderer, LabelRenderer> Convert(vec3 originalWorldPosition, TracyEnergy.Simba.Data.Keywords.impl.WellSpecs wellspec, TracyEnergy.Simba.Data.Keywords.impl.WellCompatCollection wellCompatList)
        {
            int locI = wellspec.Li;
            int locJ = wellspec.Lj;

            //if compat has position ,use compat
            List<WellCompat> segments = null;
            if (wellCompatList != null)
                segments = wellCompatList.GetWellSegments(wellspec.WellName);
            if (segments != null && segments.Count > 0)
            {
                locI = segments[0].PosI;
                locJ = segments[0].PosJ;
            }

            if (!this.grid.DataSource.IsSliceBlock(locI, locJ))
            {
                return null;
            }

            vec3 h1 = this.grid.DataSource.PointFLT(locI, locJ, 1);
            vec3 h2 = this.grid.DataSource.PointBRT(locI, locJ, 1);
            vec3 d0 = h2 - h1;
            float L = (float)d0.length();
            d0 = d0.normalize();
            vec3 vec = d0 * (L * 0.5f);
            vec3 comp1 = CenterOfLine(h1, h2); ; //地层完井段的起始点

            //vec3 minCord = this.grid.FlipTransform * this.grid.SourceActiveBounds.Min;
            vec3 minCord = this.grid.DataSource.SourceActiveBounds.MinPosition;
            vec3 maxCord = this.grid.DataSource.SourceActiveBounds.MaxPosition;
            var rectSrc = new BoundingBox(minCord, maxCord);
            vec3 modelTop = new vec3(comp1.x, comp1.y, rectSrc.MaxPosition.z);

            float mdx = (rectSrc.MaxPosition - rectSrc.MinPosition).x;
            float mdy = (rectSrc.MaxPosition - rectSrc.MinPosition).y;
            float mdz = (rectSrc.MaxPosition - rectSrc.MinPosition).z;

            float xyextend = System.Math.Max(mdx, mdy); //XY平面的最大边长
            float extHeight; //延长线段
            if (mdz < 0.1f * xyextend) //z很小
            {
                extHeight = 0.1f * xyextend;
            }
            else if (mdz < 0.2f * xyextend)
            {
                extHeight = mdz * 0.5f;
            }
            else if (mdz < 0.3f * xyextend)
            {
                extHeight = mdz * 0.25f;
            }
            else if (mdz < 0.4f * xyextend)
            {
                extHeight = mdz * 0.2f;
            }
            else
            {
                extHeight = 0.2f * mdz;
            }

            //地表坐标

            vec3 direction = new vec3(0, 0, 1.0f);
            vec3 head = modelTop + direction * extHeight;

            //确定井的半径
            float wellRadius;

            #region decide the well radius

            if (mdx < mdy)
            {
                if (mdy * 0.5f >= mdx) //长方形的模型
                {
                    int n = this.grid.DataSource.NX;
                    if (n >= 10)
                    {
                        wellRadius = (mdx / n) * 0.5f;
                    }
                    else
                    {
                        wellRadius = (mdx / n) * 0.35f;
                    }
                }
                else
                {
                    int n = this.grid.DataSource.NX;
                    if (n >= 10)
                    {
                        n = 10;
                        wellRadius = (mdx / n) * 0.5f;
                    }
                    else
                    {
                        wellRadius = (mdx / n) * 0.35f;
                    }
                }
            }
            else if (mdx == mdy)
            {
                int n = Math.Min(this.grid.DataSource.NX, this.grid.DataSource.NY);
                if (n >= 10)
                {
                    n = 10;
                    wellRadius = (mdx / n) * 0.85f;
                }
                else
                {
                    wellRadius = (mdx / n) * 0.5f;
                }
            }
            else
            {
                if (mdx * 0.5f >= mdy)
                {
                    int n = this.grid.DataSource.NY;
                    if (n > 10)
                    {
                        n = 10;
                        wellRadius = (mdy / n) * 0.5f;
                    }
                    else
                    {
                        wellRadius = (mdy / n) * 0.35f;
                    }
                }
                else
                {
                    int n = this.grid.DataSource.NY;
                    if (n > 10)
                    {
                        n = 10;
                        wellRadius = (mdx / n) * 0.5f;
                    }
                    else
                    {
                        wellRadius = (mdx / n) * 0.35f;
                    }
                }
            }

            #endregion decide the well radius

            Fluid fluid = FluidConverter.Convert(wellspec.Fluid);
            Color pipeColor = MapFluidToColor(fluid);
            Color textColor = Color.White;

            List<vec3> wellPath = new List<vec3>();
            wellPath.Add(head);
            wellPath.Add(modelTop);

            #region start decide the trajery of the well

            {
                int lastI = locI;
                int lastJ = locJ;
                int lastK = -1;
                vec3 lastvec3 = comp1;
                int segCount = segments.Count;
                for (int i = 0; i < segCount; i++)
                {
                    WellCompat compseg = segments[i];
                    int compI = compseg.PosI;
                    int compJ = compseg.PosJ;
                    int compK1 = compseg.K1;
                    int compK2 = compseg.K2;
                    if (compK1 == compK2)//同一网格上
                    {
                        if ((lastI != compI) || (lastJ != compJ) || (lastK != compK1))
                        {
                            vec3 s1 = this.grid.DataSource.PointFLT(compI, compJ, compK1);
                            vec3 s2 = this.grid.DataSource.PointBRT(compI, compJ, compK1);
                            vec3 point = CenterOfLine(s1, s2);
                            wellPath.Add(point);
                            lastI = compI;
                            lastJ = compJ;
                            lastK = compK1;
                        }
                    }
                    else //compK1 != compK2
                    {
                        //k1 coord
                        if ((lastI != compI) || (lastJ != compJ) || (lastK != compK1))
                        {
                            vec3 s1 = this.grid.DataSource.PointFLT(compI, compJ, compK1);
                            vec3 s2 = this.grid.DataSource.PointBRT(compI, compJ, compK1);
                            vec3 point = CenterOfLine(s1, s2);
                            wellPath.Add(point);
                        }
                        lastI = compI;
                        lastJ = compJ;
                        lastK = compK1;

                        if ((lastI != compI) || (lastJ != compJ) || (lastK != compK2))
                        {
                            vec3 s1 = this.grid.DataSource.PointFLT(compI, compJ, compK2);
                            vec3 s2 = this.grid.DataSource.PointBRT(compI, compJ, compK2);
                            vec3 point = CenterOfLine(s1, s2);
                            wellPath.Add(point);
                        }
                        lastI = compI;
                        lastJ = compJ;
                        lastK = compK2;
                    }
                }//end for

                var model = new WellModel(wellPath, wellRadius);
                //NamedWellRenderer renderer = NamedWellRenderer.Create(model, pipeColor, wellspec.WellName, 12);
                WellRenderer wellRenderer = WellRenderer.Create(model);
                wellRenderer.WellColor = pipeColor;
                LabelRenderer labelRenderer = LabelRenderer.Create(64, 64);
                labelRenderer.Text = wellspec.WellName;
                var result = new CSharpGL.Tuple<WellRenderer, LabelRenderer>(wellRenderer, labelRenderer);
                return result;
            }

            #endregion start decide the trajery of the well
        }