Example #1
0
    private void populate() {
      // set up for a new population
      Vector oldPop = this.positions;
      this.positions = new Vector(50, 50);

      // first browse the old population and make changes
      for (int i = 0; i < oldPop.size(); i++) {
        Position a = (Position) oldPop.get(i);
        if (a.symPosNo < this.symPos.length) {
          Point3d sPos = this.symPos[a.symPosNo];
          if (sPos != null) {
            Point3d newPos = new Point3d(sPos);
            newPos.add(a.expandTranslation);
            if (this.isPosInBounds(newPos)
                && Model3d.this.getAtomHere(this.positions, newPos) == null) {
              a.changePos(newPos);
              this.positions.add(a);
              // System.out.println("move "+a);
              continue;
            }
          }
        }
        // invalid, duplicate or out of bounds, remove
        // System.out.println("del "+a);
        a.del();
      }

      // now add potentially new appeared atoms
      for (double i = -Math.ceil(Model3d.this.exm - 1);
          i <= Math.floor(Model3d.this.exp + 1) + 1;
          i++)
        for (double j = -Math.ceil(Model3d.this.eym - 1);
            j <= Math.floor(Model3d.this.eyp + 1) + 1;
            j++)
          for (double k = -Math.ceil(Model3d.this.ezm - 1);
              k <= Math.floor(Model3d.this.ezp + 1) + 1;
              k++) {
            Vector3d v = new Vector3d(i, j, k);
            for (int l = 0; l < this.symPos.length; l++) {
              if (this.symPos[l] == null) continue;
              Point3d p = new Point3d(this.symPos[l]);
              p.add(v);
              // TODO
              if (this.isPosInBounds(p) && Model3d.this.getAtomHere(this.positions, p) == null) {
                // if (isPosInBounds(round(p)) &&
                // getAtomHere(positions, p)==null) {
                Position a =
                    new Position(this.root, this, p, v, this.radius, this.color, l, !this.hidden);
                this.positions.add(a);
                // if (!isPosInBounds(p))System.out.println("xx
                // "+p);
              }
            }
          }
    }
  public Point3d calcCenterOfRotation() {
    List<Integer> line = getLongestLayerLine();

    // can't determine center of rotation if there are only 2 points
    // TODO does this ever happen??
    if (line.size() < 3) {
      return subunits.getCentroid();
    }

    Point3d centerOfRotation = new Point3d();
    List<Point3d> centers = subunits.getOriginalCenters();

    // calculate helix mid points for each set of 3 adjacent subunits
    for (int i = 0; i < line.size() - 2; i++) {
      Point3d p1 = new Point3d(centers.get(line.get(i)));
      Point3d p2 = new Point3d(centers.get(line.get(i + 1)));
      Point3d p3 = new Point3d(centers.get(line.get(i + 2)));
      transformationMatrix.transform(p1);
      transformationMatrix.transform(p2);
      transformationMatrix.transform(p3);
      centerOfRotation.add(getMidPoint(p1, p2, p3));
    }

    // average over all midpoints to find best center of rotation
    centerOfRotation.scale(1 / (line.size() - 2));
    // since helix is aligned along the y-axis, with an origin at y = 0, place the center of
    // rotation there
    centerOfRotation.y = 0;
    // transform center of rotation to the original coordinate frame
    reverseTransformationMatrix.transform(centerOfRotation);
    //		System.out.println("center of rotation: " + centerOfRotation);
    return centerOfRotation;
  }
  public Transform3D getTransform() {
    Transform3D transform = new Transform3D();
    Point3d target = new Point3d();

    target.add(direction, position);

    Point3d zoomedPosition = new Point3d();
    zoomedPosition.scaleAdd(-zoom / direction.length(), direction, target);

    transform.lookAt(zoomedPosition, target, up);
    transform.invert();
    return transform;
  }
 /**
  * Rescales Point2 so that length 1-2 is sum of covalent radii. if covalent radii cannot be found,
  * use bond length of 1.0
  *
  * @param atom1 stationary atom
  * @param atom2 moveable atom
  * @param point2 coordinates for atom 2
  * @return new coords for atom 2
  */
 public static Point3d rescaleBondLength(IAtom atom1, IAtom atom2, Point3d point2) {
   Point3d point1 = atom1.getPoint3d();
   double d1 = atom1.getCovalentRadius();
   double d2 = atom2.getCovalentRadius();
   // in case we have no covalent radii, set to 1.0
   double distance =
       (d1 < 0.1 || d2 < 0.1) ? 1.0 : atom1.getCovalentRadius() + atom2.getCovalentRadius();
   Vector3d vect = new Vector3d(point2);
   vect.sub(point1);
   vect.normalize();
   vect.scale(distance);
   Point3d newPoint = new Point3d(point1);
   newPoint.add(vect);
   return newPoint;
 }
 public void move() {
   Vector3d velocity = new Vector3d(cameraXP - cameraXN, 0, cameraZP - cameraZN);
   velocity.normalize();
   if (Double.isNaN(velocity.x)) {
     velocity = new Vector3d();
   }
   position.add(velocity);
   if (position.x < -maxX) {
     position.x = -maxX;
   } else if (position.x > maxX) {
     position.x = maxX;
   }
   if (position.z < -maxZ) {
     position.z = -maxZ;
   } else if (position.z > maxZ) {
     position.z = maxZ;
   }
 }
Example #6
0
  public synchronized void processCamera() {
    long dt = (System.nanoTime() - lastUpdateTime) / 1000000;
    float maxFractionForDT = TRAIL_MAX_FRACTION_DELTA_PER_SEC * (dt / 1000f);

    // set hit fraction
    float newHitFraction =
        trailorCamCollider.getCollisionFraction(currentAvartarHeadPoint, currentCameraMaxVector);

    // if it's bad just use previous hit fraction
    if (!Float.isNaN(newHitFraction)) {
      currentHitFraction = newHitFraction;
    }

    // come in a tiny bit so we see through wall to the side less
    if (currentHitFraction <= 1.0f) {
      float cameraVectorLen = currentHitFraction * TRAIL_MAX_DIST;
      cameraVectorLen -= TRAIL_DIST_MARGIN;
      currentHitFraction = cameraVectorLen / TRAIL_MAX_DIST;
    }

    float hitFractionDelta = currentHitFraction - lastSetHitFraction;

    // clamp the max out ward delta by time (inwards is instant)
    hitFractionDelta = hitFractionDelta > maxFractionForDT ? maxFractionForDT : hitFractionDelta;
    currentHitFraction = hitFractionDelta + lastSetHitFraction;

    // scale the camera vector
    tempCameraVector.set(currentCameraMaxVector);
    tempCameraVector.scale(currentHitFraction);

    // make a camerapoint
    tempCameraPoint.add(currentAvartarHeadPoint, tempCameraVector);

    // look at head from camera
    tempCamTrans.lookAt(tempCameraPoint, currentAvartarHeadPoint, Y_UP);
    tempCamTrans.invert(); // cos lookAt is not for view platforms?

    // set the actual view platform
    getViewPlatformTransform().setTransform(tempCamTrans);

    // remember state
    lastSetHitFraction = currentHitFraction;
    lastUpdateTime = System.nanoTime();
  }
  /* (non-Javadoc)
   * @see org.biojava.nbio.structure.quaternary.core.AxisAligner#getGeometricCenter()
   */
  @Override
  public Point3d getGeometricCenter() {
    run();

    Point3d geometricCenter = new Point3d();
    Vector3d translation = new Vector3d();
    //		reverseTransformationMatrix.get(translation);

    // TODO does this apply to the helic case?
    // calculate adjustment around z-axis and transform adjustment to
    //  original coordinate frame with the reverse transformation

    //		Vector3d corr = new Vector3d(0,minBoundary.y+getDimension().y, 0);
    //		reverseTransformationMatrix.transform(corr);
    //		geometricCenter.set(corr);

    reverseTransformationMatrix.transform(translation);
    geometricCenter.add(translation);
    return geometricCenter;
  }
 /**
  * Calculate new point X in a B-A(-D)-C system. It forms a B-A(-D)(-C)-X system.
  *
  * <p>(3) 3 ligands(B, C, D) of refAtom A (i) 1 points required; if A, B, C, D coplanar, no
  * points. else vector is resultant of BA, CA, DA
  *
  * @param aPoint to which substituents are added
  * @param bPoint first ligand of A
  * @param cPoint second ligand of A
  * @param dPoint third ligand of A
  * @param length A-X length
  * @return Point3d nwanted points (or null if failed (coplanar))
  */
 public static Point3d calculate3DCoordinates3(
     Point3d aPoint, Point3d bPoint, Point3d cPoint, Point3d dPoint, double length) {
   Vector3d v1 = new Vector3d(aPoint);
   v1.sub(bPoint);
   Vector3d v2 = new Vector3d(aPoint);
   v2.sub(cPoint);
   Vector3d v3 = new Vector3d(aPoint);
   v3.sub(dPoint);
   Vector3d v = new Vector3d(bPoint);
   v.add(cPoint);
   v.add(dPoint);
   if (v.length() < 0.00001) {
     return null;
   }
   v.normalize();
   v.scale(length);
   Point3d point = new Point3d(aPoint);
   point.add(v);
   return point;
 }
Example #9
0
  /**
   * Create a core Java 3D View instance and a utility Viewer instance using the attributes gathered
   * by this object.
   */
  protected Viewer createViewer(boolean setVisible) {
    Point3d leftEyeCoe, rightEyeCoe;

    j3dView = new View();
    j3dView.setViewPolicy(viewPolicy);

    if (configBody == null) physicalBody = new PhysicalBody();
    else physicalBody = configBody.j3dPhysicalBody;

    if (configEnv == null) physicalEnvironment = new PhysicalEnvironment();
    else physicalEnvironment = configEnv.j3dPhysicalEnvironment;

    j3dView.setPhysicalBody(physicalBody);
    j3dView.setPhysicalEnvironment(physicalEnvironment);

    boolean standardDefaults = true;
    if (coeCenteringEnableSet && !coeCenteringEnable) {
      standardDefaults = false;
    }
    if (configEnv != null && configEnv.coexistenceToTrackerBase != null) {
      standardDefaults = false;
    } else {
      Iterator i = screens.iterator();
      while (i.hasNext()) {
        ConfigScreen s = (ConfigScreen) i.next();
        if (s.trackerBaseToImagePlate != null) {
          standardDefaults = false;
          break;
        }
      }
    }

    if (standardDefaults) {
      // Coexistence centering has not been explicitly set false, and
      // the tracker base to image plate and coexistence to tracker base
      // transforms are unset, so use the standard Java 3D defaults.
      if (windowEyepointPolicy == -1) windowEyepointPolicy = View.RELATIVE_TO_FIELD_OF_VIEW;
      if (windowMovementPolicy == -1) windowMovementPolicy = View.PHYSICAL_WORLD;
      if (windowResizePolicy == -1) windowResizePolicy = View.PHYSICAL_WORLD;
      if (!coeCenteringEnableSet) coeCenteringEnable = true;
    } else {
      // Use multi-screen or calibrated coexistence defaults.
      if (windowEyepointPolicy == -1) windowEyepointPolicy = View.RELATIVE_TO_COEXISTENCE;
      if (windowMovementPolicy == -1) windowMovementPolicy = View.VIRTUAL_WORLD;
      if (windowResizePolicy == -1) windowResizePolicy = View.VIRTUAL_WORLD;
      if (!coeCenteringEnableSet) coeCenteringEnable = false;
    }

    j3dView.setWindowEyepointPolicy(windowEyepointPolicy);
    j3dView.setWindowMovementPolicy(windowMovementPolicy);
    j3dView.setWindowResizePolicy(windowResizePolicy);
    j3dView.setCoexistenceCenteringEnable(coeCenteringEnable);

    if (centerEyeInCoexistence == null) {
      centerEyeInCoexistence = new Point3d(0.0, 0.0, 0.4572);
    }

    leftEyeCoe = new Point3d(centerEyeInCoexistence);
    rightEyeCoe = new Point3d(centerEyeInCoexistence);

    if (stereoEnable) {
      Point3d leftEyeBody = new Point3d();
      Point3d rightEyeBody = new Point3d();

      physicalBody.getLeftEyePosition(leftEyeBody);
      physicalBody.getRightEyePosition(rightEyeBody);

      leftEyeCoe.add(leftEyeBody);
      rightEyeCoe.add(rightEyeBody);
    }

    j3dView.setLeftManualEyeInCoexistence(leftEyeCoe);
    j3dView.setRightManualEyeInCoexistence(rightEyeCoe);

    j3dView.setBackClipPolicy(backClipPolicy);
    j3dView.setFrontClipPolicy(frontClipPolicy);
    j3dView.setBackClipDistance(backClipDistance);
    j3dView.setFrontClipDistance(frontClipDistance);

    j3dView.setScreenScalePolicy(screenScalePolicy);
    j3dView.setScreenScale(screenScale);

    j3dView.setFieldOfView(fieldOfView);
    j3dView.setTrackingEnable(trackingEnable);
    j3dView.setSceneAntialiasingEnable(antialiasingEnable);

    if (screens.size() == 0) {
      throw new IllegalStateException(
          errorMessage(
              creatingCommand, "View \"" + instanceName + "\" has no canvases or screens"));
    }

    ConfigScreen[] cs = new ConfigScreen[screens.size()];
    screens.toArray(cs);

    j3dViewer = new Viewer(cs, this, setVisible);
    return j3dViewer;
  }
Example #10
0
  /**
   * Draws the five sides of the hemicube into the provided drawable
   *
   * @param drawable
   * @param which
   * @param near
   * @param far
   * @param bCollect
   */
  public void drawHemiCube(
      GLAutoDrawable drawable, int which, double near, double far, boolean bCollect) {

    // TODO - PART 1 - DRAW HEMICUBE!

    GL gl = drawable.getGL();
    GLU glu = new GLU();

    /* Return the face based on which parameter */
    int[] vertices = scene.getObject().getFace(which);

    /* Find the center of the face */
    /* Center of the face is the average of the three vertices */

    /* Using returned list of vertex indices, find the vertices
     * corresponding to a particular face */
    Vertex v1 = scene.getObject().vertexList.get(vertices[0]);
    Vertex v2 = scene.getObject().vertexList.get(vertices[1]);
    Vertex v3 = scene.getObject().vertexList.get(vertices[2]);

    /* Locate center of face */
    /* Average of three vertices */
    Point3d centerPoint = new Point3d();
    centerPoint = new Point3d(v1.p);
    centerPoint.add(v2.p);
    centerPoint.add(v3.p);
    centerPoint.scale(0.33333);

    /* Set up camera frame */

    /* --- Surface normal --- */
    /* Declare points of vertex for face */
    Point3d p1 = new Point3d(v1.p);
    Point3d p2 = new Point3d(v2.p);
    Point3d p3 = new Point3d(v3.p);

    /* Declare vector u as p2-p1 */
    Point3d uVec = new Point3d(p2);
    uVec.sub(p1);
    Vector3d u = new Vector3d(uVec);

    /* Declare vector v as p3-p1 */
    Point3d vVec = new Point3d(p3);
    vVec.sub(p1);
    Vector3d v = new Vector3d(vVec);

    /* Make normal vector */
    Vector3d norm = new Vector3d();
    norm.cross(u, v);

    /* --- Vectors Orthonormal to Normal --- */
    Point3d vec1pt = new Point3d(p1);
    vec1pt.sub(p2);
    Vector3d vec1 = new Vector3d(vec1pt);
    vec1.cross(vec1, norm); // Cross surface normal with vec1 to get orthogonal vector

    Vector3d vec2 = new Vector3d();
    vec2.cross(
        norm,
        vec1); // Cross product of surface normal with new vector vec1 to get 2nd orthogonal vector

    /* Make unit vectors */
    norm.normalize();
    vec1.normalize();
    vec2.normalize();

    /* Set up the five different frustums, and stitch together using viewPort */
    /* Viewport to set up the view of the scene */

    /* ----- FRONT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight() / 3);

    /* Set up frustums for this face */

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + norm.x,
        centerPoint.y + norm.y,
        centerPoint.z + norm.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- BOTTOM FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(0, drawable.getHeight() / 3, drawable.getWidth(), drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, 0, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + (-vec1.x),
        centerPoint.y + (-vec1.y),
        centerPoint.z + (-vec1.z),
        centerPoint.x + norm.x,
        centerPoint.y + norm.y,
        centerPoint.z + norm.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- TOP FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, -near, 0, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z,
        centerPoint.x - norm.x,
        centerPoint.y - norm.y,
        centerPoint.z - norm.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- LEFT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + 2 * (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(0, near, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + vec2.x,
        centerPoint.y + vec2.y,
        centerPoint.z + vec2.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- RIGHT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + 3 * (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(near, 0, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + (-vec2.x),
        centerPoint.y + (-vec2.y),
        centerPoint.z + (-vec2.z),
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ---- End Frustums ---- */

    // if collecting the form factors, then read back and process the data
    if (bCollect) {
      gl.glFlush();
      gl.glFinish();
      gl.glReadPixels(
          0, 0, divisions * 2, divisions * 6, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelDataBuffer);
      collectData(which);
    }
  }
Example #11
0
    private void init(final Content c, final int x, final int y) {
      xLast = x;
      yLast = y;

      content = c;

      // some transforms
      c.getLocalToVworld(localToVWorld);
      localToVWorldInverse.invert(localToVWorld);
      canvas.getImagePlateToVworld(ipToVWorld);
      ipToVWorldInverse.invert(ipToVWorld);

      // calculate the canvas position in world coords
      c.getContent().getCenter(centerInVWorld);
      localToVWorld.transform(centerInVWorld);
      ipToVWorldInverse.transform(centerInVWorld, centerInIp);

      // get the eye point in world coordinates
      canvas.getCenterEyeInImagePlate(eyePtInVWorld);
      ipToVWorld.transform(eyePtInVWorld);

      // use picking to infer the radius of the virtual sphere which is rotated
      final Point3d p = univ.getPicker().getPickPointGeometry(c, x, y);
      float r = 0, dD = 0;
      if (p != null) {
        pickPtInVWorld.set(p);
        localToVWorld.transform(pickPtInVWorld);
        r = (float) pickPtInVWorld.distance(centerInVWorld);
      } else {
        c.getContent().getMin(p1);
        localToVWorld.transform(p1);
        r = (float) p1.distance(centerInVWorld);
        vec.sub(centerInVWorld, eyePtInVWorld);
        vec.normalize();
        vec.scale(-r);
        pickPtInVWorld.add(centerInVWorld, vec);
      }
      dD = (float) pickPtInVWorld.distance(eyePtInVWorld);

      // calculate distance between eye and canvas point
      canvas.getPixelLocationInImagePlate(x, y, p1);
      ipToVWorld.transform(p1);
      final float dd = (float) p1.distance(eyePtInVWorld);

      // calculate the virtual distance between two neighboring pixels
      canvas.getPixelLocationInImagePlate(x + 1, y, p2);
      ipToVWorld.transform(p2);
      final float dx = (float) p1.distance(p2);

      // calculate the virtual distance between two neighboring pixels
      canvas.getPixelLocationInImagePlate(x, y + 1, p3);
      ipToVWorld.transform(p3);
      final float dy = (float) p1.distance(p3);

      final float dX = dD / dd * dx;
      final float dY = dD / dd * dy;

      anglePerPix = Math.atan2(dX, r);

      univ.getViewPlatformTransformer().getYDir(axisPerDx, ipToVWorld);
      univ.getViewPlatformTransformer().getXDir(axisPerDy, ipToVWorld);

      translationPerDx.set(axisPerDy);
      translationPerDx.scale(dX);

      translationPerDy.set(axisPerDx);
      translationPerDy.scale(dY);

      rotateTG = c.getLocalRotate();
      translateTG = c.getLocalTranslate();
      c.getContent().getCenter(vec);
      transl_inv.set(vec);
      vec.set(-vec.x, -vec.y, -vec.z);
      transl.set(vec);
    }