/**
   * Creates the meshes of one single phase and adds it to the ArrayList of 4D meshes.
   *
   * @param phase
   * @param parameters
   * @param info
   * @param splines
   */
  private void createPhantom(
      int phase, double[] parameters, CONRADCardiacModelConfig info, ArrayList<Mesh4D> splines) {
    String pcaFile = heartBase + "\\CardiacModel\\phase_" + phase + ".ccm";
    ActiveShapeModel asm = new ActiveShapeModel(pcaFile);
    Mesh allComp = asm.getModel(parameters);

    if (phase == 0) {
      for (int i = 0; i < info.numAnatComp; i++) {
        splines.add(new Mesh4D());
      }
    }

    int count = 0;
    for (heartComponents hc : heartComponents.values()) {
      Mesh comp = new Mesh();
      SimpleMatrix pts =
          allComp
              .getPoints()
              .getSubMatrix(info.vertexOffs[count], 0, hc.getNumVertices(), info.vertexDim);
      // rotate and translate points
      for (int i = 0; i < pts.getRows(); i++) {
        SimpleVector row = SimpleOperators.multiply(rot, pts.getRow(i));
        row.add(trans);
        pts.setRowValue(i, row);
      }
      comp.setPoints(pts);
      comp.setConnectivity(
          allComp
              .getConnectivity()
              .getSubMatrix(info.triangleOffs[count], 0, hc.getNumTriangles(), 3));
      splines.get(count).addMesh(comp);
      count++;
    }
  }
  private void followRay(
      SimpleVector pos,
      SimpleVector dir,
      double energyEV,
      FloatProcessor imp,
      int scatterCount,
      double totalDistance) {
    if (energyEV <= 1 || scatterCount > 20000) {
      System.out.println("energy low, times scattered: " + scatterCount);
      return;
    }
    // follow ray until next interaction point
    SimpleVector oldPos = pos.clone();
    double dist = sampler.getDistanceUntilNextInteractionCm(material, energyEV);
    pos.add(dir.multipliedBy(dist));
    pathlengths.add(dist);
    // draw the entire path
    // imp.drawLine((int)(scale*oldPos.getElement(0)), (int)(scale*oldPos.getElement(1)),
    // (int)(scale*pos.getElement(0)), (int)(scale*pos.getElement(1)));
    // draw interaction points only
    imp.drawDot((int) (scale * pos.getElement(0)), (int) (scale * pos.getElement(1)));

    // choose compton or photoelectric effect
    double photo =
        material.getAttenuation(energyEV / 1000, AttenuationType.PHOTOELECTRIC_ABSORPTION);
    double compton =
        material.getAttenuation(energyEV / 1000, AttenuationType.INCOHERENT_ATTENUATION);

    if (sampler.random() * (photo + compton) <= photo) {
      // photoelectric absorption
      energyEV = 0;
      // System.out.println("absorbed after " + scatterCount + " collisions");
      xs.add(pos.getElement(0));
      ys.add(pos.getElement(1));
      zs.add(pos.getElement(2));

      return;
    } else {
      // compton scattering

      energyEV = sampler.sampleComptonScattering(energyEV, dir);

      // send new ray
      followRay(pos, dir, energyEV, imp, scatterCount + 1, totalDistance + dist);
    }
  }