Example usage for javax.media.j3d BoundingSphere getRadius

List of usage examples for javax.media.j3d BoundingSphere getRadius

Introduction

In this page you can find the example usage for javax.media.j3d BoundingSphere getRadius.

Prototype

public double getRadius() 

Source Link

Document

Returns the radius of this bounding sphere as a double.

Usage

From source file:Math3D.java

/**
 * Returns true if the parent bounds fully encloses the child 
 *///from w w w . j av  a2 s .  c om
public static boolean encloses(BoundingSphere parent, BoundingSphere child) {
    Point3d childCenter = new Point3d();
    Point3d parentCenter = new Point3d();
    child.getCenter(childCenter);
    parent.getCenter(parentCenter);
    double childR = child.getRadius();
    double parentR = parent.getRadius();

    if (childCenter.x + childR > parentCenter.x + parentR || childCenter.y + childR > parentCenter.y + parentR
            || childCenter.z + childR > parentCenter.z + parentR)
        return false;

    if (childCenter.x - childR < parentCenter.x - parentR || childCenter.y - childR < parentCenter.y - parentR
            || childCenter.z - childR < parentCenter.z - parentR)
        return false;

    return true;
}

From source file:Math3D.java

/**
 * Returns true if the parent bounds fully encloses the child 
 *//*ww w. j a  v a 2s . c  o  m*/
public static boolean encloses(BoundingBox parent, BoundingSphere child) {
    Point3d upper = new Point3d();
    Point3d lower = new Point3d();
    Point3d center = new Point3d();
    double radius;

    parent.getUpper(upper);
    parent.getLower(lower);
    child.getCenter(center);
    radius = child.getRadius();

    if (center.x + radius > upper.x || center.y + radius > upper.y || center.z + radius > upper.z)
        return false;

    if (center.x - radius < lower.x || center.y - radius < lower.y || center.z - radius < lower.z)
        return false;

    return true;
}

From source file:Math3D.java

/**
 * Returns true if the parent bounds fully encloses the child 
 *//*from  w  ww. ja v  a2s. c o  m*/
public static boolean encloses(BoundingSphere parent, BoundingBox child) {
    // if the distance from the center of the sphere to any corner of
    // the box is greater than the sphere radius return false

    Point3d lower = new Point3d();
    Point3d upper = new Point3d();

    Point3d parentCenter = new Point3d();

    child.getLower(lower);
    child.getUpper(upper);

    parent.getCenter(parentCenter);

    double xDim = upper.x - lower.x;
    double yDim = upper.y - lower.y;

    double radiusSquared = Math.pow(parent.getRadius(), 2);

    Vector3d tmp = new Vector3d();

    tmp.set(lower);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;
    tmp.set(lower.x + xDim, lower.y, lower.z);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;
    tmp.set(lower.x, lower.y + yDim, lower.z);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;
    tmp.set(lower.x + xDim, lower.y + yDim, lower.z);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;

    tmp.set(upper);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;
    tmp.set(upper.x - xDim, upper.y, upper.z);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;
    tmp.set(upper.x, upper.y - yDim, upper.z);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;
    tmp.set(upper.x - xDim, upper.y - yDim, upper.z);
    tmp.sub(parentCenter);
    if (tmp.lengthSquared() > radiusSquared)
        return false;

    return true;
}

From source file:edu.uci.ics.jung.algorithms.layout3d.AbstractLayout.java

private void adjustLocations(BoundingSphere oldSize, BoundingSphere size) {

    float oldWidth = 0;
    float oldHeight = 0;
    float oldDepth = 0;
    float width = 0;
    float height = 0;
    float depth = 0;

    oldWidth = oldHeight = oldDepth = (float) (2 * oldSize.getRadius());
    width = height = depth = (float) (2 * size.getRadius());

    float xOffset = (oldWidth - width) / 2;
    float yOffset = (oldHeight - height) / 2;
    float zOffset = (oldDepth - depth) / 2;

    // now, move each vertex to be at the new screen center
    while (true) {
        try {//w  w  w  .ja  v  a2  s . c  om
            for (V v : getGraph().getVertices()) {
                offsetVertex(v, xOffset, yOffset, zOffset);
            }
            break;
        } catch (ConcurrentModificationException cme) {
        }
    }
}

From source file:edu.uci.ics.jung.algorithms.layout3d.FRLayout.java

private void doInit() {
    Graph<V, E> graph = getGraph();
    BoundingSphere d = getSize();
    if (graph != null) {//&& d != null) {
        currentIteration = 0;/*from  www .j a  v a  2 s .  co  m*/
        temperature = d.getRadius() / 10;

        forceConstant = Math.sqrt(d.getRadius() * d.getRadius() * d.getRadius() / graph.getVertexCount());

        attraction_constant = attraction_multiplier * forceConstant;
        repulsion_constant = repulsion_multiplier * forceConstant;
    }
}

From source file:edu.uci.ics.jung.algorithms.layout3d.SpringLayout.java

protected void moveNodes() {

    synchronized (getSize()) {
        try {/*from  ww  w  .j a v a 2 s  . co m*/
            for (V v : getGraph().getVertices()) {
                if (isLocked(v))
                    continue;
                SpringVertexData vd = getSpringData(v);
                if (vd == null)
                    continue;
                Point3f xyd = transform(v);

                vd.dx += vd.repulsiondx + vd.edgedx;
                vd.dy += vd.repulsiondy + vd.edgedy;
                vd.dz += vd.repulsiondz + vd.edgedz;

                // keeps nodes from moving any faster than 5 per time unit
                xyd.set((float) (xyd.getX() + Math.max(-5, Math.min(5, vd.dx))),
                        (float) (xyd.getY() + Math.max(-5, Math.min(5, vd.dy))),
                        (float) (xyd.getZ() + Math.max(-5, Math.min(5, vd.dz))));

                BoundingSphere d = getSize();
                float radius = (float) d.getRadius();

                if (xyd.getX() < -radius) {
                    xyd.set(-radius, xyd.getY(), xyd.getZ());//                     setX(0);
                } else if (xyd.getX() > radius) {
                    xyd.set(radius, xyd.getY(), xyd.getZ()); //setX(width);
                }

                if (xyd.getY() < -radius) {
                    xyd.set(xyd.getX(), -radius, xyd.getZ());//setY(0);
                } else if (xyd.getY() > radius) {
                    xyd.set(xyd.getX(), radius, xyd.getZ()); //setY(height);
                }

                if (xyd.getZ() < -radius) {
                    xyd.set(xyd.getX(), xyd.getY(), -radius);//setY(0);
                } else if (xyd.getZ() > radius) {
                    xyd.set(xyd.getX(), xyd.getY(), radius); //setY(height);
                }

                //                    System.err.println(v+" xyd = "+xyd);

            }
        } catch (ConcurrentModificationException cme) {
            moveNodes();
        }
    }
}

From source file:NodesTest.java

public void processStimulus(java.util.Enumeration criteria) {
    while (criteria.hasMoreElements()) {
        WakeupCriterion wakeUp = (WakeupCriterion) criteria.nextElement();

        // every N frames, check for a collision
        if (wakeUp instanceof WakeupOnElapsedFrames) {
            // create a PickBounds
            PickTool pickTool = new PickTool(pickRoot);
            pickTool.setMode(PickTool.BOUNDS);

            BoundingSphere bounds = (BoundingSphere) collisionObject.getBounds();
            pickBounds = new PickBounds(new BoundingSphere(
                    new Point3d(positionVector.x, positionVector.y, positionVector.z), bounds.getRadius()));
            pickTool.setShape(pickBounds, new Point3d(0, 0, 0));
            PickResult[] resultArray = pickTool.pickAll();

            if (isCollision(resultArray))
                onCollide();//from  ww  w  .  ja  v a2  s. c o  m
            else
                onMiss();

            moveCollisionObject();
        }
    }

    // assign the next WakeUpCondition, so we are notified again
    wakeupOn(m_WakeupCondition);
}

From source file:VrmlPickingTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Transform3D viewTrans = new Transform3D();
    Transform3D eyeTrans = new Transform3D();

    BoundingSphere sceneBounds = (BoundingSphere) m_SceneBranchGroup.getBounds();

    // point the view at the center of the object
    Point3d center = new Point3d();
    sceneBounds.getCenter(center);/*from   ww w .ja v  a 2  s .co m*/
    double radius = sceneBounds.getRadius();
    Vector3d temp = new Vector3d(center);
    viewTrans.set(temp);

    // pull the eye back far enough to see the whole object
    double eyeDist = 1.4 * radius / Math.tan(Math.toRadians(40) / 2.0);
    temp.x = 0.0;
    temp.y = 0.0;
    temp.z = eyeDist;
    eyeTrans.set(temp);
    viewTrans.mul(eyeTrans);

    // set the view transform
    tgArray[0].setTransform(viewTrans);

    return tgArray;
}

From source file:ExDepthCue.java

public Group buildScene() {
    // Get the current color
    Color3f color = (Color3f) colors[currentColor].value;

    // Turn off the example headlight
    setHeadlightEnable(false);//w  ww  . ja va 2 s.c  o m

    // Create the scene group
    Group scene = new Group();

    // Create a switch group to hold the fog node. This enables
    // us to turn the fog node on and off via the GUI.
    fogSwitch = new Switch();
    fogSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Create influencing bounds
    Bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Set the fog color, density, and its influencing bounds
    fog = new LinearFog();
    fog.setColor(color);
    // front and back distances set below
    fog.setCapability(Fog.ALLOW_COLOR_WRITE);
    fog.setCapability(Fog.ALLOW_INFLUENCING_BOUNDS_WRITE);
    fog.setInfluencingBounds(worldBounds);
    fogSwitch.addChild(fog);
    scene.addChild(fogSwitch);
    if (depthCueOnOff)
        fogSwitch.setWhichChild(0); // on
    else
        fogSwitch.setWhichChild(Switch.CHILD_NONE); // off

    // Set the background color and its application bounds
    //   Usually, the background color should match the fog color
    //   or the results look odd.
    background = new Background();
    background.setColor(color);
    background.setApplicationBounds(worldBounds);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    scene.addChild(background);

    // Build foreground geometry
    Group content = buildIsoline();
    scene.addChild(content);

    // Automatically compute good front and back distances for
    // fog to get good depth-cueing. To do this, first get the
    // dimensions of the bounds around the content. Then,
    // set the front distance to be at the center of the content
    // (or closer by a tad) and the back distance at the front
    // distance PLUS half the depth of the content's bounding box
    BoundingSphere sampleSphere = new BoundingSphere();
    BoundingBox sampleBox = new BoundingBox();
    Bounds bounds = content.getBounds();
    double deltaDistance = 0.0;
    double centerZ = 0.0;

    if (bounds == null) {
        // No bounds available. Estimate the values knowing
        // that the above content is what it is.
        centerZ = 0.5; // 0.5 closer than true center
        deltaDistance = 2.0;
    } else if (bounds.getClass() == sampleSphere.getClass()) {
        BoundingSphere sphereBounds = (BoundingSphere) bounds;
        deltaDistance = Math.abs(sphereBounds.getRadius());
        Point3d center = new Point3d();
        sphereBounds.getCenter(center);
        centerZ = center.z + 0.5; // 0.5 closer than true center
    } else if (bounds.getClass() == sampleBox.getClass()) {
        BoundingBox boxBounds = (BoundingBox) bounds;
        Point3d p1 = new Point3d();
        Point3d p2 = new Point3d();
        boxBounds.getLower(p1);
        boxBounds.getUpper(p2);
        deltaDistance = p2.z - p1.z;
        if (deltaDistance < 0.0)
            deltaDistance *= -1.0;
        if (p1.z > p2.z)
            centerZ = p1.z - deltaDistance / 2.0;
        else
            centerZ = p2.z - deltaDistance / 2.0;
        centerZ += 0.5; // 0.5 closer than true center
    } else {
        System.err.println("Unknown bounds type");
    }

    // Set front distance to the distance from the default
    // viewing position (0,0,10) to the center of the bounds.
    fog.setFrontDistance(10.0f - (float) centerZ);

    // Set back distance to the distance from the default
    // viewing position (0,0,10) to the back of the bounds.
    fog.setBackDistance(10.0f - (float) centerZ + (float) deltaDistance);

    return scene;
}