Exemple #1
0
  public void prepare() throws ParamError {
    if (debug) {
      verbose = false;
    }

    // read in parameter values from ParamDB
    fromDB();

    if (ignoreVParams) {
      ScaleV = 0;
      for (int i = 1; i < 4; i++) {
        LevelParams lp = levelParams[i];
        lp.nCurveV = 0;
        lp.nLengthV = 0;
        lp.nSplitAngleV = 0;
        lp.nRotateV = 0;
        // lp.nBranchDistV = 0;
        if (lp.nDownAngle > 0) {
          lp.nDownAngle = 0;
        }
      }
    }

    // additional params checks
    for (int l = 0; l < Math.min(Levels, 4); l++) {
      LevelParams lp = levelParams[l];
      if (lp.nSegSplits > 0 && lp.nSplitAngle == 0) {
        throw new ParamError("nSplitAngle may not be 0.");
      }
    }

    // create one random generator for every level
    // so you can develop a tree level by level without
    // influences between the levels
    long l = levelParams[0].initRandom(Seed);
    for (int i = 1; i < 4; i++) {
      l = levelParams[i].initRandom(l);
    }

    // create a random generator for myself (used in stem_radius)
    random = new Random(Seed);

    // mesh settings
    if (Smooth <= 0.2) {
      smooth_mesh_level = -1;
    } else {
      smooth_mesh_level = (int) (Levels * Smooth);
    }
    mesh_quality = Smooth;

    // mesh points per cross-section for the levels
    // minima
    levelParams[0].mesh_points = 4;
    levelParams[1].mesh_points = 3;
    levelParams[2].mesh_points = 2;
    levelParams[3].mesh_points = 1;
    // set meshpoints with respect to mesh_quality and Lobes
    if (Lobes > 0) {
      levelParams[0].mesh_points = (int) (Lobes * (Math.pow(2, (int) (1 + 2.5 * mesh_quality))));
      levelParams[0].mesh_points =
          Math.max(levelParams[0].mesh_points, (int) (4 * (1 + 2 * mesh_quality)));
    }
    for (int i = 1; i < 4; i++) {
      levelParams[i].mesh_points =
          Math.max(3, (int) (levelParams[i].mesh_points * (1 + 1.5 * mesh_quality)));
    }

    // stop generation at some level?
    if (stopLevel >= 0 && stopLevel <= Levels) {
      Levels = stopLevel;
      Leaves = 0;
    }

    if (scale_tree == 0) {
      scale_tree = Scale + levelParams[0].random.uniform(-ScaleV, ScaleV);
    }
  }