示例#1
0
  protected boolean gotAllPoints() {
    if (Double.isNaN(currentCoords.getX())) return false;
    if (Double.isNaN(currentCoords.getY())) return false;
    if (Double.isNaN(currentCoords.getZ())) return false;

    return true;
  }
示例#2
0
 // generic method for calculation of distance btw 2 atoms
 private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) {
   double distance;
   Point3d firstPoint = atom1.getPoint3d();
   Point3d secondPoint = atom2.getPoint3d();
   distance = firstPoint.distance(secondPoint);
   return distance;
 }
 /*
  * Bottom up hierarchical clustering
  */
 private static HashSet<Cluster> findClusters(Collection<Point3d> points, double threshold) {
   HashSet<Cluster> clusters = new HashSet<>(points.size() * 2);
   for (Point3d p : points) {
     Cluster candidate = new Cluster();
     candidate.add(p);
     for (Point3d p2 : points) {
       if (p != p2 && p.distance(p2) <= threshold) {
         candidate.add(p2);
       }
     }
     Iterator<Cluster> iter = clusters.iterator();
     while (iter.hasNext()) {
       Cluster c = iter.next();
       for (Point3d p2 : candidate) {
         if (c.contains(p2)) { // Se os clusters C e candidate se intersectam, fundi-los
           candidate.addAll(c);
           iter.remove();
           break;
         }
       }
     }
     clusters.add(candidate);
   }
   return clusters;
 }
  /**
   * Calculates the min and max boundaries of the structure after it has been transformed into its
   * canonical orientation.
   */
  private void calcBoundaries() {
    minBoundary.x = Double.MAX_VALUE;
    maxBoundary.x = Double.MIN_VALUE;
    minBoundary.y = Double.MAX_VALUE;
    maxBoundary.x = Double.MIN_VALUE;
    minBoundary.z = Double.MAX_VALUE;
    maxBoundary.z = Double.MIN_VALUE;
    xzRadiusMax = Double.MIN_VALUE;

    Point3d probe = new Point3d();

    for (Point3d[] list : subunits.getTraces()) {
      for (Point3d p : list) {
        probe.set(p);
        transformationMatrix.transform(probe);

        minBoundary.x = Math.min(minBoundary.x, probe.x);
        maxBoundary.x = Math.max(maxBoundary.x, probe.x);
        minBoundary.y = Math.min(minBoundary.y, probe.y);
        maxBoundary.y = Math.max(maxBoundary.y, probe.y);
        minBoundary.z = Math.min(minBoundary.z, probe.z);
        maxBoundary.z = Math.max(maxBoundary.z, probe.z);
        xzRadiusMax = Math.max(xzRadiusMax, Math.sqrt(probe.x * probe.x + probe.z * probe.z));
      }
    }
    //		System.out.println("MinBoundary: " + minBoundary);
    //		System.out.println("MaxBoundary: " + maxBoundary);
    //		System.out.println("zxRadius: " + xzRadiusMax);
  }
  private int findPointOfMinMov(int start_, int end_, int fileIndex) {
    //		logger.debug("Anfang: " + start_+ " Ende: " + end_);
    int start = start_;
    //		double sum = 	Math.pow(rawData.get(fileIndex).getDimension(0)[start],2) +
    //						Math.pow(rawData.get(fileIndex).getDimension(1)[start],2) +
    //						Math.pow(rawData.get(fileIndex).getDimension(2)[start],2);
    //		sum = Math.sqrt(sum);

    Point3d from =
        new Point3d(
            rawData.get(fileIndex).getDimension(0)[start],
            rawData.get(fileIndex).getDimension(1)[start],
            rawData.get(fileIndex).getDimension(2)[start]);
    int minMovIndex = start;

    while (start != end_) { // mean of difference of acceleration to fixed point
      Point3d tempPoint =
          new Point3d(
              rawData.get(fileIndex).getDimension(0)[start],
              rawData.get(fileIndex).getDimension(1)[start],
              rawData.get(fileIndex).getDimension(2)[start]);
      //			tempSum = Math.sqrt(tempSum);
      //			if ((sum - tempSum > 0)){
      //			sum = tempSum;
      if (from.distance(tempPoint) < 0.2) {
        minMovIndex = start;
        //			logger.debug("summe: " +minMovIndex);
      }
      start++;
    }
    return minMovIndex;
  }
  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 void closestIntersectionAndNormalAt(
      double x, double y, double z, Point3d intersection, Vector3d normal) {
    intersection.setX(x); // Go Straight Up for now...
    intersection.setY(y);
    intersection.setZ(heightAt(x, y, z));

    surfaceNormalAt(x, y, z, normal);
  }
 // This method is called whenever the "Reset Camera" action is triggered.  This should reset the
 // camera transform
 // to it's initial state.
 public void resetCamera() {
   // Point3d from = new Point3d(0., 0., 14.);
   Point3d from = new Point3d(0., 0., 18.);
   Point3d to = new Point3d(0., 0., 0.);
   Vector3d up = new Vector3d(0., 1., 0.);
   from.scale(0.05);
   to.scale(0.05);
   setLookAt(from, to, up);
 }
  public void applyTransform(RigidBodyTransform transform, boolean requireTransformInXYPlane) {
    temporaryTransformedPoint.set(this.getX(), this.getY(), 0.0);
    transform.transform(temporaryTransformedPoint);

    if (requireTransformInXYPlane)
      checkIsTransformationInPlane(transform, temporaryTransformedPoint);

    this.set(temporaryTransformedPoint.getX(), temporaryTransformedPoint.getY());
  }
示例#10
0
 private void createArea() throws IOException {
   while (readThisLine() != null) {
     if (gotAllPoints() && currentCoords.getZ() < 0) {
       area.add(new Point2D.Double(currentCoords.getX(), currentCoords.getY()));
     }
   }
   gCodeFile.close();
   gCodeFile = new BufferedReader(new FileReader(rawFile));
   currentCoords = new Point3d(Double.NaN, Double.NaN, Double.NaN);
 }
示例#11
0
 // method which calculated distance btw an atom and the middle point of a bond
 // and returns distance and coordinates of middle point
 private double[] calculateDistanceBetweenAtomAndBond(IAtom proton, IBond theBond) {
   Point3d middlePoint = theBond.get3DCenter();
   Point3d protonPoint = proton.getPoint3d();
   double[] values = new double[4];
   values[0] = middlePoint.distance(protonPoint);
   values[1] = middlePoint.x;
   values[2] = middlePoint.y;
   values[3] = middlePoint.z;
   return values;
 }
  public boolean checkIfInside(
      double x, double y, double z, Point3d intersectionToPack, Vector3d normalToPack) {
    intersectionToPack.setX(x); // Go Straight Up for now...
    intersectionToPack.setY(y);
    intersectionToPack.setZ(heightAt(x, y, z));

    surfaceNormalAt(x, y, z, normalToPack);

    return (z < intersectionToPack.getZ());
  }
示例#13
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 void getDollyPosition(Point3d dollyPositionToPack) {
   if (dolly_x_var != null) {
     dollyPositionToPack.setX(dolly_x_var.getDoubleValue());
   }
   if (dolly_y_var != null) {
     dollyPositionToPack.setY(dolly_y_var.getDoubleValue());
   }
   if (dolly_z_var != null) {
     dollyPositionToPack.setZ(dolly_z_var.getDoubleValue());
   }
 }
示例#15
0
 /**
  * Tests if two positions are symmetrically equivalent under point group within a provided
  * tolerance.
  *
  * @param a First comparison Point3d.
  * @param b Second comparison Point3d
  * @param tolerance Tolerance distance
  * @return True if positions are equivalent, false otherwise.
  */
 public boolean isSymmetricallyEquivalent(Point3d a, Point3d b, double tolerance) {
   boolean isequivalent = false;
   for (SymmetryOperation key : operations) {
     Point3d testcoord = key.transformPoint(a);
     if (testcoord.distance(b) < tolerance) {
       isequivalent = true;
       break;
     }
   }
   return isequivalent;
 }
 public void getTrackingPosition(Point3d trackPositionToPack) {
   if (track_x_var != null) {
     trackPositionToPack.setX(track_x_var.getDoubleValue());
   }
   if (track_y_var != null) {
     trackPositionToPack.setY(track_y_var.getDoubleValue());
   }
   if (track_z_var != null) {
     trackPositionToPack.setZ(track_z_var.getDoubleValue());
   }
 }
示例#17
0
 public String toString() {
   return "t="
       + timestamp
       + ", x="
       + point3d.getX()
       + ", y="
       + point3d.getY()
       + ", z="
       + point3d.getZ()
       + " State is "
       + this.pointState.name();
 }
示例#18
0
 public boolean isValidList2Position(Vector3d position) {
   for (int i = 0; i < pcList2.size(); i++) {
     PointCharge pc = (PointCharge) pcList2.get(i);
     Point3d pcPosition = new Point3d(pc.getPosition());
     if (pcPosition.distance(new Point3d(position)) < pc_radius * 1.5) {
       return false;
     }
   }
   if (Math.abs(position.x - plate2_position.x) > plate_length / 2. - pc_radius) return false;
   if (Math.abs(position.y - plate2_position.y) > plate_height / 2. - pc_radius) return false;
   if (Math.abs(position.z - plate2_position.z) > plate_width / 2. - pc_radius) return false;
   return true;
 }
示例#19
0
  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;
  }
示例#20
0
  /**
   * Finds the position value in the image series map that is closest to the POI. This partially
   * populates an Image object but does NOT include the image id.
   *
   * @param imageSeries
   * @param poi
   * @return
   * @throws IOException
   */
  private void getClosestPosition(ImageSeries imageSeries, Point3d poi100, Image image)
      throws IOException {
    URL u = new URL(assembleAtlasMapURI(imageSeries.imageSeriesId));

    LOG.debug("Atlas map URI: {}", u.toString());

    BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
    String line = null;

    // discard first 2 lines
    in.readLine();
    in.readLine();
    double leastDistance = Double.POSITIVE_INFINITY;
    String[] bestLineSegs = null;
    int count = 2;
    while ((line = in.readLine()) != null) {
      String[] lineSegs = line.split(",");
      Point3d abaCoordinates =
          new Point3d(
              Double.parseDouble(lineSegs[0]),
              Double.parseDouble(lineSegs[1]),
              Double.parseDouble(lineSegs[2]));

      LOG.debug("lineSegs X: {}", lineSegs[0]);
      LOG.debug("lineSegs Y: {}", lineSegs[1]);
      LOG.debug("lineSegs Z: {}", lineSegs[2]);

      if (poi100.distanceSquared(abaCoordinates) < leastDistance) {
        leastDistance = poi100.distanceSquared(abaCoordinates);
        bestLineSegs = lineSegs;
      }

      // debug
      if ((++count % 1000) == 0) {
        System.out.printf("%d%n", count);
      }
    }
    in.close();

    image.imagesCheckedForProximity = count;
    image.abaCoordinates =
        new Point3d(
            Double.parseDouble(bestLineSegs[0]),
            Double.parseDouble(bestLineSegs[1]),
            Double.parseDouble(bestLineSegs[2]));
    image.abaXPixelPosition = Integer.parseInt(bestLineSegs[3]);
    image.abaYPixelPosition = Integer.parseInt(bestLineSegs[4]);
    image.abaImagePosition = bestLineSegs[5];

    LOG.debug("Points examined: {}", count);
  }
示例#21
0
  private double[] getSubunitZDepth() {
    int n = subunits.getSubunitCount();
    double[] depth = new double[n];
    Point3d probe = new Point3d();

    // transform subunit centers into z-aligned position and calculate
    // z-coordinates (depth) along the z-axis.
    for (int i = 0; i < n; i++) {
      Point3d p = subunits.getCenters().get(i);
      probe.set(p);
      transformationMatrix.transform(probe);
      depth[i] = probe.z;
    }
    return depth;
  }
 /**
  * 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;
 }
 @Override
 public void selected(
     Graphics3DNode graphics3dNode,
     ModifierKeyInterface modifierKeyHolder,
     Point3d location,
     Point3d cameraLocation,
     Quat4d cameraRotation) {
   if (shouldAcceptDeviceInput()) {
     if (modifierKeyHolder.isKeyPressed(Key.SHIFT)) {
       if (!isTracking() || !isTrackingX()) setFixX(location.getX());
       if (!isTracking() || !isTrackingY()) setFixY(location.getY());
       if (!isTracking() || !isTrackingZ()) setFixZ(location.getZ());
     }
   }
 }
示例#24
0
  @Override
  void update() {
    int newEditId;
    if ((newEditId = volume.update()) != volumeEditId) {
      for (int i = 0; i < 6; i++) {
        boxLine[i].setCoordinates(0, volume.facePoints[i], 0, 4);
        boxLine[i].setCoordinate(4, volume.facePoints[i][0]);
        imageQuad[i].setCoordinates(0, volume.facePoints[i], 0, 4);
      }

      faceCenter[PLUS_X].set(volume.maxCoord.x, 0.0, 0.0);
      faceCenter[PLUS_Y].set(0.0, volume.maxCoord.y, 0.0);
      faceCenter[PLUS_Z].set(0.0, 0.0, volume.maxCoord.z);
      faceCenter[MINUS_X].set(volume.minCoord.x, 0.0, 0.0);
      faceCenter[MINUS_Y].set(0.0, volume.minCoord.y, 0.0);
      faceCenter[MINUS_Z].set(0.0, 0.0, volume.minCoord.z);
      volCenter.x = (volume.maxCoord.x + volume.minCoord.x) / 2;
      volCenter.y = (volume.maxCoord.y + volume.minCoord.y) / 2;
      volCenter.z = (volume.maxCoord.z + volume.minCoord.z) / 2;
      volumeEditId = newEditId;
    }
    eyePtChanged();
    for (int i = 0; i < 6; i++) {
      if (boxAttr[i].getValue() == true) {
        boxSwitch[i].setWhichChild(Switch.CHILD_ALL);
      } else {
        boxSwitch[i].setWhichChild(Switch.CHILD_NONE);
      }
      String curImageFile = imageAttr[i].getValue();
      if (curImageFile != imageFile[i]) {
        imageFile[i] = curImageFile;
        if (imageFile[i].length() > 0) {
          try {
            URL imageURL = new URL(context.getCodeBase().toString() + imageFile[i]);
            imageTexture[i] = new TextureLoader(imageURL, null).getTexture();
          } catch (Exception e) {
            System.err.println("Error " + e + " loading image:" + imageFile[i] + ".");
          }
        }
        imageAppearance[i].setTexture(imageTexture[i]);
        if (imageTexture[i] != null) {
          imageSwitch[i].setWhichChild(Switch.CHILD_ALL);
        } else {
          imageSwitch[i].setWhichChild(Switch.CHILD_NONE);
        }
      }
    }
  }
 private void checkIsTransformationInPlane(
     RigidBodyTransform transformToNewFrame, Point3d transformedPoint) {
   transformToNewFrame.getTranslation(temporaryTranslation);
   if (Math.abs(temporaryTranslation.getZ() - transformedPoint.getZ()) > epsilon)
     throw new RuntimeException(
         "Cannot transform FramePoint2d to a plane with a different surface normal");
 }
示例#26
0
  public Point3d getEye(Point3d eye) {
    if (eye == null) eye = new Point3d();
    if (globe != null) globe.getEllipsoid().toCartesian(lat, lon, hEllps, eye);
    else eye.set(0, 0, 0);

    return eye;
  }
示例#27
0
  public void getPropertyComponents(List comps, final ObjectListener listener) {
    visibleCbx = new JCheckBox(getName(), visible);
    float[] rgb = color.get().getRGBComponents(null);
    slider = new JSlider(0, 100, (int) (rgb[0] * 100));

    float[] xyz = new float[3];
    direction.get(xyz);
    directionXFld = makeField("" + xyz[0], listener, "X Direction");
    directionYFld = makeField("" + xyz[1], listener, "Y Direction");
    directionZFld = makeField("" + xyz[2], listener, "Z Direction");

    double[] pxyz = new double[3];
    location.get(pxyz);
    locationXFld = makeField("" + pxyz[0], listener, "");
    locationYFld = makeField("" + pxyz[1], listener, "");
    locationZFld = makeField("" + pxyz[2], listener, "");

    List fldComps =
        Misc.newList(GuiUtils.rLabel("Direction:"), directionXFld, directionYFld, directionZFld);
    //
    // fldComps.addAll(Misc.newList(GuiUtils.rLabel("Location:"),locationXFld,locationYFld,locationZFld));

    comps.add(visibleCbx);
    GuiUtils.tmpInsets = new Insets(0, 2, 0, 0);
    comps.add(
        GuiUtils.vbox(
            slider, GuiUtils.left(GuiUtils.doLayout(fldComps, 4, GuiUtils.WT_N, GuiUtils.WT_N))));

    if (listener != null) {
      visibleCbx.addActionListener(listener);
      slider.addChangeListener(listener);
    }
  }
示例#28
0
  void translate(final int xNew, final int yNew) {
    if (content == null || content.isLocked()) return;
    final int dx = xNew - xLast;
    final int dy = yNew - yLast;
    translateTG.getTransform(translateOld);
    v1.scale(dx, translationPerDx);
    v2.scale(-dy, translationPerDy);
    translation.add(v1, v2);
    translateNew.set(translation);
    translateNew.mul(translateOld);

    translateTG.setTransform(translateNew);
    transformChanged(BehaviorCallback.TRANSLATE, translateNew);

    xLast = xNew;
    yLast = yNew;
  }
示例#29
0
  public void updateStateFromString(String upperLine) {
    lineNumber++;
    // add all variables
    // addVarsFromLine(upperLine);
    // strip comments to avoid confusion when a comment exists at the end of
    // a non-comment line
    stripComments(upperLine);
    // get machine states
    recordState(upperLine);

    double xValue = getDoubleFromChar(upperLine, 'X');
    double yValue = getDoubleFromChar(upperLine, 'Y');
    double zValue = getDoubleFromChar(upperLine, 'Z');
    if (!Double.isNaN(xValue)) currentCoords.setX(xValue);
    if (!Double.isNaN(yValue)) currentCoords.setY(yValue);
    if (!Double.isNaN(zValue)) currentCoords.setZ(zValue);
  }
示例#30
0
  public static void transformMesh(final TopLoc_Location loc, double[] src, float[] dst) {
    double[] matrix = new double[16];
    loc.transformation().getValues(matrix);

    Matrix4d m4d = new Matrix4d(matrix);
    Point3d p3d = new Point3d();

    for (int i = 0; i < src.length; i += 3) {
      p3d.x = src[i + 0];
      p3d.y = src[i + 1];
      p3d.z = src[i + 2];
      m4d.transform(p3d);
      dst[i + 0] = (float) p3d.x;
      dst[i + 1] = (float) p3d.y;
      dst[i + 2] = (float) p3d.z;
    }
  }