Example #1
0
  public static SphericalRegion getEnclosingSphere(RectangularBox box) {
    Point3f centre =
        new Point3f(
            (box.getHighestXValue() + box.getLowestXValue()) / 2,
            (box.getHighestYValue() + box.getLowestYValue()) / 2,
            (box.getHighestZValue() + box.getLowestZValue()) / 2);

    float radius =
        centre.distance(
            new Point3f(box.getLowestXValue(), box.getLowestYValue(), box.getLowestZValue()));

    SphericalRegion newSphere = new SphericalRegion(centre.x, centre.y, centre.z, radius);

    return newSphere;
  }
  protected Point3f generateNextPosition() throws CellPackingException {
    Point3f proposedPoint = null;

    logger.logComment(
        "----   Generating next position. positionsAlreadyTaken.size() = "
            + getNumPosAlreadyTaken());

    float minXLoc, minYLoc, minZLoc, maxXLoc, maxYLoc, maxZLoc;

    if (mustBeCompletelyInsideRegion()) {
      // limit the extent for possible location of soma centre to box which
      // will preclude soma wall impacting region boundary.

      minXLoc = myRegion.getLowestXValue() - CellTopologyHelper.getMinXExtent(myCell, true, false);
      minYLoc = myRegion.getLowestYValue() - CellTopologyHelper.getMinYExtent(myCell, true, false);
      minZLoc = myRegion.getLowestZValue() - CellTopologyHelper.getMinZExtent(myCell, true, false);

      maxXLoc = myRegion.getHighestXValue() - CellTopologyHelper.getMaxXExtent(myCell, true, false);
      maxYLoc = myRegion.getHighestYValue() - CellTopologyHelper.getMaxYExtent(myCell, true, false);
      maxZLoc = myRegion.getHighestZValue() - CellTopologyHelper.getMaxZExtent(myCell, true, false);
    } else {
      // in this case the soma centre can be anywhere inside the region..

      minXLoc = myRegion.getLowestXValue();
      minYLoc = myRegion.getLowestYValue();
      minZLoc = myRegion.getLowestZValue();

      maxXLoc = myRegion.getHighestXValue();
      maxYLoc = myRegion.getHighestYValue();
      maxZLoc = myRegion.getHighestZValue();
    }

    Point3f startPoint = new Point3f(minXLoc, minYLoc, minZLoc);

    logger.logComment("minXLoc: " + minXLoc + ", maxXLoc: " + maxXLoc);

    if (maxXLoc - minXLoc < 0 || maxYLoc - minYLoc < 0 || maxZLoc - minZLoc < 0) {
      throw new CellPackingException("Diameter of cell is smaller than region");
    }

    if (getNumPosAlreadyTaken() >= getNumberCells()) {
      throw new CellPackingException("All cells successfully placed");
    }

    if (getNumberCells() == 0) {
      throw new CellPackingException("Cell number set to zero!!");
    } else if (getNumberCells() == 1) {
      if (parameterList[DIMENSION_PARAM].value == DIMENSION_PARAM_X) {
        proposedPoint = new Point3f((minXLoc + maxXLoc) / 2, minYLoc, minZLoc);

      } else if (parameterList[DIMENSION_PARAM].value == DIMENSION_PARAM_Y) {
        proposedPoint = new Point3f(minXLoc, (minYLoc + maxYLoc) / 2, minZLoc);

      } else if (parameterList[DIMENSION_PARAM].value == DIMENSION_PARAM_Z) {

        proposedPoint = new Point3f(minXLoc, minYLoc, (minZLoc + maxZLoc) / 2);
      }

    } else {

      // Point3f lastPositionedPoint = getLastPosTaken();

      if (parameterList[DIMENSION_PARAM].value == DIMENSION_PARAM_X) {
        float distanceApart = (maxXLoc - minXLoc) / (getNumberCells() - 1);

        proposedPoint = new Point3f(startPoint);
        proposedPoint.add(new Point3f(distanceApart * numProposedPoints, 0, 0));

        logger.logComment(
            "Placing one of "
                + getNumberCells()
                + " cells in x dim..."
                + distanceApart
                + " apart, new: "
                + proposedPoint
                + ", already proposed: "
                + numProposedPoints);

        if (proposedPoint.x > maxXLoc) throw new CellPackingException("Reached end of x dimension");
      } else if (parameterList[DIMENSION_PARAM].value == DIMENSION_PARAM_Y) {
        logger.logComment("Placing cell in y dim...");
        float distanceApart = (maxYLoc - minYLoc) / (getNumberCells() - 1);
        proposedPoint = new Point3f(startPoint);
        proposedPoint.add(new Point3f(0, distanceApart * numProposedPoints, 0));

        if (proposedPoint.y > maxYLoc) throw new CellPackingException("Reached end of y dimension");
      } else if (parameterList[DIMENSION_PARAM].value == DIMENSION_PARAM_Z) {
        logger.logComment("Placing cell in z dim...");
        float distanceApart = (maxZLoc - minZLoc) / (getNumberCells() - 1);
        proposedPoint = new Point3f(startPoint);
        proposedPoint.add(new Point3f(0, 0, distanceApart * numProposedPoints));
        if (proposedPoint.z > maxZLoc) throw new CellPackingException("Reached end of z dimension");
      }

      if (proposedPoint == null) throw new CellPackingException("Cannot successfully place cell.");
    }
    // lastProposedPoint = new Point3d(proposedPoint);
    numProposedPoints++;

    return new Point3f(proposedPoint);
  }