Пример #1
0
        public static object getInstance(BoundingBox3d box, View view)
        {
            AxeBox axe = new AxeBox(box);

            axe.View = view;
            return(axe);
        }
Пример #2
0
        public BoundingBox3d computeScaling()
        {
            //-- Scale the scene's view -------------------
            if (Squared)
            {
                _scaling = Squarify();
            }
            else
            {
                _scaling = (Coord3d)Coord3d.IDENTITY.Clone();
            }
            // Compute the bounds for computing cam distance, clipping planes, etc ...
            if ((_targetBox == null))
            {
                _targetBox = new BoundingBox3d(0, 1, 0, 1, 0, 1);
            }
            BoundingBox3d boundsScaled = new BoundingBox3d();

            boundsScaled.Add(_targetBox.scale(_scaling));
            if (MAINTAIN_ALL_OBJECTS_IN_VIEW)
            {
                boundsScaled.Add(Scene.Graph.Bounds.scale(_scaling));
            }
            return(boundsScaled);
        }
Пример #3
0
 public Scatter(Coord3d[] coordinates, Color[] colors, float width = 1)
 {
     _bbox  = new BoundingBox3d();
     Data   = coordinates;
     Width  = width;
     Colors = colors;
 }
Пример #4
0
 public ScatterMultiColor(Coord3d[] coordinates, ColorMapper mapper, float width = 1.0f)
 {
     _bbox       = new BoundingBox3d();
     Data        = coordinates;
     Width       = width;
     ColorMapper = mapper;
 }
Пример #5
0
 public GroupedLineScatter()
 {
     _bbox      = new BoundingBox3d();
     PointWidth = 1;
     LineWidth  = 1;
     Color      = Color.BLACK;
 }
Пример #6
0
 public void setData(BoundingBox3d box)
 {
     _bbox.reset();
     _bbox.Add(box);
     _quads = new List <Polygon>(6);
     // Add 6 polygons to list
     for (int i = 0; i <= 5; i++)
     {
         _quads.Add(new Polygon());
     }
     _quads[0].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymin, _bbox.zmax)));
     _quads[0].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymin, _bbox.zmin)));
     _quads[0].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymax, _bbox.zmin)));
     _quads[0].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymax, _bbox.zmax)));
     _quads[1].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymax, _bbox.zmax)));
     _quads[1].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymax, _bbox.zmin)));
     _quads[1].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymin, _bbox.zmin)));
     _quads[1].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymin, _bbox.zmax)));
     _quads[2].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymax, _bbox.zmax)));
     _quads[2].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymax, _bbox.zmin)));
     _quads[2].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymax, _bbox.zmin)));
     _quads[2].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymax, _bbox.zmax)));
     _quads[3].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymin, _bbox.zmax)));
     _quads[3].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymin, _bbox.zmin)));
     _quads[3].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymin, _bbox.zmin)));
     _quads[3].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymin, _bbox.zmax)));
     _quads[4].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymin, _bbox.zmax)));
     _quads[4].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymin, _bbox.zmax)));
     _quads[4].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymax, _bbox.zmax)));
     _quads[4].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymax, _bbox.zmax)));
     _quads[5].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymin, _bbox.zmin)));
     _quads[5].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymin, _bbox.zmin)));
     _quads[5].Add(new Point(new Coord3d(_bbox.xmin, _bbox.ymax, _bbox.zmin)));
     _quads[5].Add(new Point(new Coord3d(_bbox.xmax, _bbox.ymax, _bbox.zmin)));
 }
Пример #7
0
 /// <summary>
 /// Initialize a point at <paramref name="xyz"/> coordinate, with a <paramref name="rgb"/> color and a width of <paramref name="width"/>.
 /// </summary>
 /// <param name="xyz">Point coordinates</param>
 /// <param name="rgb">Point color</param>
 /// <param name="width">Point width</param>
 /// <remarks></remarks>
 public Point(Coord3d xyz, Color rgb, float width)
 {
     _bbox  = new BoundingBox3d();
     _xyz   = xyz;
     _width = width;
     _rgb   = rgb;
     UpdateBounds();
 }
Пример #8
0
 /// <summary>
 /// Initializes a new GroupedLineScatter object
 /// </summary>
 /// <param name="coordinates">A list of coordinate arrays. Each list item is rendered as a separate series in a different color.</param>
 /// <param name="colors">A list of colors. The series are colored in order of this list with rollover if more series than colors are provided</param>
 /// <param name="pointwidth">The size of the scatter markers</param>
 /// <param name="linewidth">The width of the line</param>
 public GroupedLineScatter(List <Coord3d[]> coordinates, Color[] colors, float pointwidth = 8, float linewidth = 2)
 {
     _bbox           = new BoundingBox3d();
     Data            = coordinates;
     this.PointWidth = pointwidth;
     this.LineWidth  = linewidth;
     Colors          = colors;
 }
Пример #9
0
 public Polygon() : base()
 {
     _points = new List <Point>();
     _bbox   = new BoundingBox3d();
     _center = new Coord3d();
     _polygonOffsetFillEnable = true;
     _polygonMode             = PolygonMode.FRONT_AND_BACK;
 }
Пример #10
0
        public void setScale(nzy3D.Maths.Scale scale, bool notify)
        {
            BoundingBox3d bounds = this.Bounds;

            bounds.zmin      = scale.Min;
            bounds.zmax      = scale.Max;
            this.BoundManual = bounds;
            if (notify)
            {
                Shoot();
            }
        }
Пример #11
0
        public void drawAxisTickNumericLabel(AxeDirection direction, Camera cam, Color color, Halign hAlign, Valign vAlign, BoundingBox3d ticksTxtBounds, String tickLabel,
                                             Coord3d tickPosition)
        {
            GL.LoadIdentity();
            GL.Scale(_scale.x, _scale.y, _scale.z);

            BoundingBox3d tickBounds = _txt.drawText(cam, tickLabel, tickPosition, hAlign, vAlign, color);

            if (tickBounds != null)
            {
                ticksTxtBounds.Add(tickBounds);
            }
        }
Пример #12
0
 public AxeBox(BoundingBox3d bbox, IAxeLayout layout)
 {
     _layout = layout;
     if (bbox.valid())
     {
         setAxe(bbox);
     }
     else
     {
         setAxe(new BoundingBox3d(-1, 1, -1, 1, -1, 1));
     }
     _wholeBounds = new BoundingBox3d();
     Init();
 }
Пример #13
0
 public void drawAxisLabel(Camera cam, AxeDirection direction, Color color, BoundingBox3d ticksTxtBounds, double xlab, double ylab, double zlab, String axeLabel)
 {
     if ((direction == AxeDirection.AxeX && _layout.XAxeLabelDisplayed) ||
         (direction == AxeDirection.AxeY && _layout.YAxeLabelDisplayed) ||
         (direction == AxeDirection.AxeZ && _layout.ZAxeLabelDisplayed))
     {
         Coord3d       labelPosition = new Coord3d(xlab, ylab, zlab);
         BoundingBox3d labelBounds   = _txt.drawText(cam, axeLabel, labelPosition, Halign.CENTER, Valign.CENTER, color);
         if (labelBounds != null)
         {
             ticksTxtBounds.Add(labelBounds);
         }
     }
 }
Пример #14
0
        /// <summary>
        /// Return a 3d scaling factor that allows scaling the scene into a square
        /// box, according to the current ViewBoundMode.
        /// <p/>
        /// If the scene bounds are Infinite, NaN or zero, for a given dimension, the
        /// scaler will be set to 1 on the given dimension.
        ///
        /// @return a scaling factor for each dimension.
        /// </summary>
        internal Coord3d Squarify()
        {
            // Get the view bounds
            BoundingBox3d bounds = default(BoundingBox3d);

            switch (_boundmode)
            {
            case ViewBoundMode.AUTO_FIT:
                bounds = Scene.Graph.Bounds;
                break;

            case ViewBoundMode.MANUAL:
                bounds = _viewbounds;
                break;

            default:
                throw new Exception("Unsupported bound mode : " + _boundmode);
            }
            // Compute factors
            float xLen = (float)(bounds.xmax - bounds.xmin);
            float yLen = (float)(bounds.ymax - bounds.ymin);
            float zLen = (float)(bounds.zmax - bounds.zmin);
            float lmax = Math.Max(Math.Max(xLen, yLen), zLen);

            if (float.IsInfinity(xLen) | float.IsNaN(xLen) | xLen == 0)
            {
                xLen = 1;
                // throw new ArithmeticException("x scale is infinite, nan or 0");
            }
            if (float.IsInfinity(yLen) | float.IsNaN(yLen) | yLen == 0)
            {
                yLen = 1;
                // throw new ArithmeticException("y scale is infinite, nan or 0");
            }
            if (float.IsInfinity(zLen) | float.IsNaN(zLen) | zLen == 0)
            {
                zLen = 1;
                // throw new ArithmeticException("z scale is infinite, nan or 0");
            }
            if (float.IsInfinity(lmax) | float.IsNaN(lmax) | lmax == 0)
            {
                lmax = 1;
                // throw new ArithmeticException("lmax is infinite, nan or 0");
            }
            return(new Coord3d(lmax / xLen, lmax / yLen, lmax / zLen));
        }
Пример #15
0
        public void Remove(AbstractDrawable drawable, bool updateViews)
        {
            bool output = false;

            lock (_components) {
                output = _components.Remove(drawable);
            }
            BoundingBox3d bbox = this.Bounds;

            foreach (View.View view in _scene.Views)
            {
                view.lookToBox(bbox);
                if (updateViews)
                {
                    view.Shoot();
                }
            }
        }
Пример #16
0
        public override Maths.BoundingBox3d drawText(Rendering.View.Camera cam, string s, Maths.Coord3d position, Align.Halign halign, Align.Valign valign, Colors.Color color, Maths.Coord2d screenOffset, Maths.Coord3d sceneOffset)
        {
            GL.Color3(color.r, color.g, color.b);
            GL.RasterPos3(position.x, position.y, position.z);
            BillBoardSize dims      = printString(s, halign, valign);
            Coord3d       posScreen = cam.ModelToScreen(position);
            Coord3d       botLeft   = new Coord3d();
            Coord3d       topRight  = new Coord3d();

            botLeft.x  = posScreen.x + dims.xoffset;
            botLeft.y  = posScreen.y + dims.yoffset;
            botLeft.z  = posScreen.z;
            topRight.x = botLeft.x + dims.xoffset;
            topRight.y = botLeft.y + dims.yoffset;
            topRight.z = botLeft.z;
            BoundingBox3d txtBounds = new BoundingBox3d();

            txtBounds.@add(cam.ScreenToModel(botLeft));
            txtBounds.@add(cam.ScreenToModel(topRight));
            return(txtBounds);
        }
Пример #17
0
        public void ZoomZ(float factor, bool updateView)
        {
            double range = this.Bounds.zmax - this.Bounds.zmin;

            if (range <= 0)
            {
                return;
            }
            double center = (this.Bounds.zmax + this.Bounds.zmin) / 2;
            double min    = center + (this.Bounds.zmin - center) * factor;
            double max    = center + (this.Bounds.zmax - center) * factor;

            // set min/max according to bounds
            nzy3D.Maths.Scale scale = null;
            if ((min < max))
            {
                scale = new nzy3D.Maths.Scale(min, max);
            }
            else
            {
                // forbid to have min = max if we zoom in
                if ((factor < 1))
                {
                    scale = new nzy3D.Maths.Scale(center, center);
                }
            }
            if ((scale != null))
            {
                BoundingBox3d bounds = this.Bounds;
                bounds.zmin      = scale.Min;
                bounds.zmax      = scale.Max;
                this.BoundManual = bounds;
                if (updateView)
                {
                    Shoot();
                }
                // fireControllerEvent(ControllerType.ZOOM, scale);
            }
        }
Пример #18
0
 public void RenderAxeBox()
 {
     if (_axeBoxDisplayed)
     {
         GL.MatrixMode(MatrixMode.Modelview);
         _scene.LightSet.Disable();
         _axe.setScale(_scaling);
         _axe.Draw(_cam);
         // for debug
         if (DISPLAY_AXE_WHOLE_BOUNDS)
         {
             AxeBox         abox = (AxeBox)_axe;
             BoundingBox3d  box  = abox.WholeBounds;
             Parallelepiped p    = new Parallelepiped(box);
             p.FaceDisplayed      = false;
             p.WireframeColor     = Color.MAGENTA;
             p.WireframeDisplayed = true;
             p.Draw(_cam);
         }
         _scene.LightSet.Enable();
     }
 }
Пример #19
0
        public View(Scene scene, ICanvas canvas, Quality quality)
        {
            BoundingBox3d sceneBounds = scene.Graph.Bounds;

            _viewpoint  = (Coord3d)DEFAULT_VIEW.Clone();
            _center     = (Coord3d)sceneBounds.getCenter();
            _scaling    = (Coord3d)Coord3d.IDENTITY.Clone();
            _viewmode   = ViewPositionMode.FREE;
            _boundmode  = ViewBoundMode.AUTO_FIT;
            _cameraMode = CameraMode.ORTHOGONAL;
            _axe        = (IAxe)AxeFactory.getInstance(sceneBounds, this);
            _cam        = CameraFactory.getInstance(_center);
            _scene      = scene;
            _canvas     = canvas;
            _quality    = quality;
            _renderers  = new List <IRenderer2D>();
            //_tooltips = New List(Of ITooltipRenderer)
            _bgViewport                = new ImageViewport();
            _viewOnTopListeners        = new List <IViewIsVerticalEventListener>();
            _viewPointChangedListeners = new List <IViewPointChangedListener>();
            _wasOnTopAtLastRendering   = false;
            //_overlay = New Overlay
            View.Current = this;
        }
Пример #20
0
        internal void correctCameraPositionForIncludingTextLabels(ViewPort viewport)
        {
            _cam.SetViewPort(viewport);
            _cam.shoot(_cameraMode);
            _axe.Draw(_cam);
            Clear();
            AxeBox        abox      = (AxeBox)_axe;
            BoundingBox3d newBounds = abox.WholeBounds.scale(_scaling);

            if (_viewmode == Modes.ViewPositionMode.TOP)
            {
                float radius = (float)Math.Max(newBounds.xmax - newBounds.xmin, newBounds.ymax - newBounds.ymin);
                radius += radius * STRETCH_RATIO;
                _cam.RenderingSphereRadius = radius;
            }
            else
            {
                _cam.RenderingSphereRadius = (float)newBounds.getRadius();
                Coord3d target = newBounds.getCenter();
                Coord3d eye    = _viewpoint.cartesian().@add(target);
                _cam.Target = target;
                _cam.Eye    = eye;
            }
        }
Пример #21
0
 public void setAxe(Maths.BoundingBox3d box)
 {
     _bbox = box;
 }
Пример #22
0
 /// <summary>
 /// Create a simple axe centered on (box.xmin, box.ymin, box.zmin)
 /// </summary>
 public AxeBase(BoundingBox3d box)
 {
     setAxe(box);
     setScale(new Coord3d(1, 1, 1));
 }
Пример #23
0
        public void drawAxisTicks(Camera cam, AxeDirection direction, Color color, Halign hal, Valign val, float tickLength, BoundingBox3d ticksTxtBounds, float xpos,
                                  float ypos, float zpos, float xdir, float ydir, float zdir, float[] ticks)
        {
            double xlab;
            double ylab;
            double zlab;
            String tickLabel = "";

            for (int t = 0; t < ticks.Length; t++)
            {
                // Shift the tick vector along the selected axis
                // and set the tick length
                switch (direction)
                {
                case AxeDirection.AxeX:
                    xpos      = ticks[t];
                    xlab      = xpos;
                    ylab      = (_yrange / tickLength) * ydir + ypos;
                    zlab      = (_zrange / tickLength) * zdir + zpos;
                    tickLabel = _layout.XTickRenderer.Format(xpos);
                    break;

                case AxeDirection.AxeY:
                    ypos      = ticks[t];
                    xlab      = (_xrange / tickLength) * xdir + xpos;
                    ylab      = ypos;
                    zlab      = (_zrange / tickLength) * zdir + zpos;
                    tickLabel = _layout.YTickRenderer.Format(ypos);
                    break;

                case AxeDirection.AxeZ:
                    zpos      = ticks[t];
                    xlab      = (_xrange / tickLength) * xdir + xpos;
                    ylab      = (_yrange / tickLength) * ydir + ypos;
                    zlab      = zpos;
                    tickLabel = _layout.ZTickRenderer.Format(zpos);
                    break;

                default:
                    throw new Exception("Unsupported axe direction");
                }
                Coord3d tickPosition = new Coord3d(xlab, ylab, zlab);

                if (_layout.TickLineDisplayed)
                {
                    drawTickLine(color, xpos, ypos, zpos, xlab, ylab, zlab);
                }

                // Select the alignement of the tick label
                Halign hAlign = layoutHorizontal(direction, cam, hal, tickPosition);
                Valign vAlign = layoutVertical(direction, val, zdir);

                // Draw the text label of the current tick
                drawAxisTickNumericLabel(direction, cam, color, hAlign, vAlign, ticksTxtBounds, tickLabel, tickPosition);
            }
        }
Пример #24
0
        public void UpdateCamera(ViewPort viewport, BoundingBox3d boundsScaled, float sceneRadiusScaled)
        {
            Coord3d target = _center.multiply(_scaling);
            Coord3d eye    = default(Coord3d);

            _viewpoint.z = sceneRadiusScaled * 2;
            // maintain a reasonnable distance to the scene for viewing it
            switch (_viewmode)
            {
            case Modes.ViewPositionMode.FREE:
                eye = _viewpoint.cartesian().@add(target);
                break;

            case Modes.ViewPositionMode.TOP:
                eye   = _viewpoint;
                eye.x = -PI_div2;
                // on x
                eye.y = PI_div2;
                // on top
                eye = eye.cartesian().@add(target);
                break;

            case Modes.ViewPositionMode.PROFILE:
                eye   = _viewpoint;
                eye.y = 0;
                eye   = eye.cartesian().@add(target);
                break;

            default:
                throw new Exception("Unsupported viewmode : " + _viewmode);
            }
            Coord3d up = default(Coord3d);

            if (Math.Abs(_viewpoint.y) == PI_div2)
            {
                // handle up vector
                Coord2d direction = new Coord2d(_viewpoint.x, _viewpoint.y).cartesian();
                if (_viewpoint.y > 0)
                {
                    // on top
                    up = new Coord3d(-direction.x, -direction.y, 0);
                }
                else
                {
                    up = new Coord3d(direction.x, direction.y, 0);
                }
                // handle "on-top" events
                if (!_wasOnTopAtLastRendering)
                {
                    _wasOnTopAtLastRendering = true;
                    fireViewOnTopEvent(true);
                }
            }
            else
            {
                // handle up vector
                up = new Coord3d(0, 0, 1);
                // handle "on-top" events
                if (_wasOnTopAtLastRendering)
                {
                    _wasOnTopAtLastRendering = false;
                    fireViewOnTopEvent(false);
                }
            }
            // Apply camera settings
            _cam.Target = target;
            _cam.Up     = up;
            _cam.Eye    = eye;
            // Set rendering volume
            if (_viewmode == Modes.ViewPositionMode.TOP)
            {
                _cam.RenderingSphereRadius = (float)(Math.Max(boundsScaled.xmax - boundsScaled.xmin, boundsScaled.ymax - boundsScaled.ymin) / 2);
                // correctCameraPositionForIncludingTextLabels(viewport) ' quite experimental !
            }
            else
            {
                _cam.RenderingSphereRadius = sceneRadiusScaled;
            }
            // Setup camera (i.e. projection matrix)
            //cam.setViewPort(canvas.getRendererWidth(),
            // canvas.getRendererHeight(), left, right);
            _cam.SetViewPort(viewport);
            _cam.shoot(_cameraMode);
        }
Пример #25
0
        internal BoundingBox3d drawTicks(Camera cam, int axis, AxeDirection direction, Color color, Halign hal, Valign val)
        {
            int           quad_0         = 0;
            int           quad_1         = 0;
            float         tickLength     = 20.0f; // with respect to range
            float         axeLabelDist   = 2.5f;
            BoundingBox3d ticksTxtBounds = new BoundingBox3d();

            // Retrieve the quads that intersect and create the selected axe
            switch (direction)
            {
            case AxeDirection.AxeX:
                quad_0 = _axeXquads[axis, 0];
                quad_1 = _axeXquads[axis, 1];
                break;

            case AxeDirection.AxeY:
                quad_0 = _axeYquads[axis, 0];
                quad_1 = _axeYquads[axis, 1];
                break;

            case AxeDirection.AxeZ:
                quad_0 = _axeZquads[axis, 0];
                quad_1 = _axeZquads[axis, 1];
                break;

            default:
                throw new Exception("Unsupported axe direction");
            }

            // Computes PoSition of ticks lying on the selected axe
            // (i.e. 1st point of the tick line)
            float xpos = _normx[quad_0] + _normx[quad_1];
            float ypos = _normy[quad_0] + _normy[quad_1];
            float zpos = _normz[quad_0] + _normz[quad_1];

            // Computes the DIRection of the ticks
            // assuming initial vector point is the center
            float xdir = (float)((_normx[quad_0] + _normx[quad_1]) - _center.x);
            float ydir = (float)((_normy[quad_0] + _normy[quad_1]) - _center.y);
            float zdir = (float)((_normz[quad_0] + _normz[quad_1]) - _center.z);

            xdir = (xdir == 0 ? 0 : xdir / Math.Abs(xdir));             // so that direction as length 1
            ydir = (ydir == 0 ? 0 : ydir / Math.Abs(ydir));
            zdir = (zdir == 0 ? 0 : zdir / Math.Abs(zdir));


            // Variables for storing the position of the Label position
            // (2nd point on the tick line)
            float xlab = 0;
            float ylab = 0;
            float zlab = 0;

            // Draw the label for axis
            string axeLabel = null;
            int    dist     = 1;

            switch (direction)
            {
            case AxeDirection.AxeX:
                xlab     = (float)_center.x;
                ylab     = axeLabelDist * (_yrange / tickLength) * dist * ydir + ypos;
                zlab     = axeLabelDist * (_zrange / tickLength) * dist * zdir + zpos;
                axeLabel = _layout.XAxeLabel;
                break;

            case AxeDirection.AxeY:
                xlab     = axeLabelDist * (_xrange / tickLength) * dist * xdir + xpos;
                ylab     = (float)_center.y;
                zlab     = axeLabelDist * (_zrange / tickLength) * dist * zdir + zpos;
                axeLabel = _layout.YAxeLabel;
                break;

            case AxeDirection.AxeZ:
                xlab     = axeLabelDist * (_xrange / tickLength) * dist * xdir + xpos;
                ylab     = axeLabelDist * (_yrange / tickLength) * dist * ydir + ypos;
                zlab     = (float)_center.z;
                axeLabel = _layout.ZAxeLabel;
                break;

            default:
                throw new Exception("Unsupported axe direction");
            }

            drawAxisLabel(cam, direction, color, ticksTxtBounds, xlab, ylab, zlab, axeLabel);
            drawAxisTicks(cam, direction, color, hal, val, tickLength, ticksTxtBounds, xpos, ypos, zpos, xdir, ydir, zdir, getAxisTicks(direction));
            return(ticksTxtBounds);
        }
Пример #26
0
 public AxeBox(BoundingBox3d bbox) : this(bbox, new AxeBoxLayout())
 {
 }
Пример #27
0
 public void setAxe(Maths.BoundingBox3d box)
 {
     _boxBounds = box;
     setAxeBox((float)box.xmin, (float)box.xmax, (float)box.ymin, (float)box.ymax, (float)box.zmin, (float)box.zmax);
 }
Пример #28
0
        public void Draw(Rendering.View.Camera camera)
        {
            // Set scaling
            GL.LoadIdentity();
            GL.Scale(_scale.x, _scale.y, _scale.z);
            // Set culling
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Front);
            // Draw cube in feedback buffer for computing hidden quads
            _quadIsHidden = getHiddenQuads(camera);
            // Plain part of quad making the surrounding box
            if (_layout.FaceDisplayed)
            {
                Color quadcolor = _layout.QuadColor;
                GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill);
                GL.Color4(quadcolor.r, quadcolor.g, quadcolor.b, quadcolor.a);
                GL.LineWidth(1);
                GL.Enable(EnableCap.PolygonOffsetFill);
                GL.PolygonOffset(1, 1);
                // handle stippling
                drawCube(OpenTK.Graphics.RenderingMode.Render);
                GL.Disable(EnableCap.PolygonOffsetFill);
            }
            // Edge part of quads making the surrounding box
            Color gridcolor = _layout.GridColor;

            GL.PolygonMode(MaterialFace.Back, PolygonMode.Line);
            GL.Color4(gridcolor.r, gridcolor.g, gridcolor.b, gridcolor.a);
            GL.LineWidth(1);
            drawCube(OpenTK.Graphics.RenderingMode.Render);
            // Draw grids on non hidden quads
            GL.PolygonMode(MaterialFace.Back, PolygonMode.Line);
            GL.Color4(gridcolor.r, gridcolor.g, gridcolor.b, gridcolor.a);
            GL.LineWidth(1);
            GL.LineStipple(1, 0xaaaa);
            GL.Enable(EnableCap.LineStipple);
            for (int quad = 0; quad <= 5; quad++)
            {
                if ((!_quadIsHidden[quad]))
                {
                    drawGridOnQuad(quad);
                }
            }
            GL.Disable(EnableCap.LineStipple);
            // Draw ticks on the closest axes
            _wholeBounds.reset();
            _wholeBounds.Add(_boxBounds);
            //gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
            // Display x axis ticks
            if ((_xrange > 0 & _layout.XTickLabelDisplayed))
            {
                // If we are on top, we make direct axe placement
                if ((((_view != null) && _view.ViewMode == nzy3D.Plot3D.Rendering.View.Modes.ViewPositionMode.TOP)))
                {
                    BoundingBox3d bbox = drawTicks(camera, 1, AxeDirection.AxeX, _layout.XTickColor, Halign.LEFT, Valign.TOP);
                    // setup tick labels for X on the bottom
                    _wholeBounds.Add(bbox);
                }
                else
                {
                    // otherwise computed placement
                    int xselect = findClosestXaxe(camera);
                    if ((xselect >= 0))
                    {
                        BoundingBox3d bbox = drawTicks(camera, xselect, AxeDirection.AxeX, _layout.XTickColor);
                        _wholeBounds.Add(bbox);
                    }
                    else
                    {
                        //System.err.println("no x axe selected: " + Arrays.toString(quadIsHidden));
                        // HACK: handles "on top" view, when all face of cube are drawn, which forbid to select an axe automatically
                        BoundingBox3d bbox = drawTicks(camera, 2, AxeDirection.AxeX, _layout.XTickColor, Halign.CENTER, Valign.TOP);
                        _wholeBounds.Add(bbox);
                    }
                }
            }
            // Display y axis ticks
            if ((_yrange > 0 & _layout.YTickLabelDisplayed))
            {
                if ((((_view != null)) && _view.ViewMode == nzy3D.Plot3D.Rendering.View.Modes.ViewPositionMode.TOP))
                {
                    BoundingBox3d bbox = drawTicks(camera, 2, AxeDirection.AxeY, _layout.YTickColor, Halign.LEFT, Valign.GROUND);
                    // setup tick labels for Y on the left
                    _wholeBounds.Add(bbox);
                }
                else
                {
                    int yselect = findClosestYaxe(camera);
                    if ((yselect >= 0))
                    {
                        BoundingBox3d bbox = drawTicks(camera, yselect, AxeDirection.AxeY, _layout.YTickColor);
                        _wholeBounds.Add(bbox);
                    }
                    else
                    {
                        //System.err.println("no y axe selected: " + Arrays.toString(quadIsHidden));
                        // HACK: handles "on top" view, when all face of cube are drawn, which forbid to select an axe automatically
                        BoundingBox3d bbox = drawTicks(camera, 1, AxeDirection.AxeY, _layout.YTickColor, Halign.RIGHT, Valign.GROUND);
                        _wholeBounds.Add(bbox);
                    }
                }
            }
            // Display z axis ticks
            if ((_zrange > 0 & _layout.ZTickLabelDisplayed))
            {
                if ((((_view != null)) && _view.ViewMode == nzy3D.Plot3D.Rendering.View.Modes.ViewPositionMode.TOP))
                {
                }
                else
                {
                    int zselect = findClosestZaxe(camera);
                    if ((zselect >= 0))
                    {
                        BoundingBox3d bbox = drawTicks(camera, zselect, AxeDirection.AxeZ, _layout.ZTickColor);
                        _wholeBounds.Add(bbox);
                    }
                }
            }
            // Unset culling
            GL.Disable(EnableCap.CullFace);
        }
Пример #29
0
 public Scatter()
 {
     _bbox = new BoundingBox3d();
     Width = 1;
     Color = Color.BLACK;
 }
Пример #30
0
 public static Box ToBox(this BoundingBox3d cub)
 {
     return(new Box(cub.Origin.ToVec3f(), (float)cub.DX, (float)cub.DY, (float)cub.DZ));
 }