public POVConeLeafWriter(AbstractExporter exporter /*, Params params*/, Tree tree) {
   super();
   this.exporter = exporter;
   this.w = exporter.getWriter();
   this.tree = tree;
   this.povrayDeclarationPrefix = tree.getSpecies() + "_" + tree.getSeed() + "_";
 }
 public POVConeStemWriter(AbstractExporter exporter, /*Params params,*/ int level) {
   super();
   this.exporter = exporter;
   this.w = exporter.getWriter();
   //		this.params = params;
   this.level = level;
 }
  /* (non-Javadoc)
   * @see net.sourceforge.arbaro.tree.TreeTraversal#visitLeaf(net.sourceforge.arbaro.tree.Leaf)
   */
  public boolean visitLeaf(Leaf leaf) {
    // prints povray code for the leaf
    String indent = "    ";

    w.println(
        indent
            + "object { "
            + povrayDeclarationPrefix
            + "leaf "
            + transformationStr(leaf.getTransformation())
            + "}");

    //		increment progress count
    exporter.incProgressCount(AbstractExporter.LEAF_PROGRESS_STEP);

    return true;
  }
Exemple #4
0
  /**
   * Output the World Model to the specified stream.
   *
   * @param model The world model to export
   * @param fw The stream to write to
   */
  public void export(WorldModel model, Writer fw) {

    super.export(model, fw);

    Entity[] entities = ((BaseWorldModel) model).getModelData();

    int len = entities.length;

    try {

      fw.write(header);

      for (int i = 0; i < len; i++) {
        Entity entity = entities[i];

        if (entity == null) {
          // Its expected we will have gaps
          continue;
        }

        if (entity.isController()) {
          continue;
        }

        fw.write("<!-- Begin entity: " + entity.getEntityID() + "-->\n");

        // if the entity has a position then place it
        if (entity instanceof PositionableEntity) {

          double[] position = new double[3];
          float[] rotation = new float[4];
          float[] scale = new float[3];

          ((PositionableEntity) entity).getPosition(position);
          ((PositionableEntity) entity).getRotation(rotation);
          ((PositionableEntity) entity).getScale(scale);

          fw.write(
              "    <Transform "
                  + "translation='"
                  + position[0]
                  + " "
                  + position[1]
                  + " "
                  + position[2]
                  + "' "
                  + "rotation='"
                  + rotation[0]
                  + " "
                  + rotation[1]
                  + " "
                  + rotation[2]
                  + " "
                  + rotation[3]
                  + "' "
                  + "scale='"
                  + scale[0]
                  + " "
                  + scale[1]
                  + " "
                  + scale[2]
                  + "' >\n");
        }

        // inline the model
        String url = entity.getModelURL();
        fw.write("        <Inline url='" + url + "' />\n");

        // if the entity has a position then place it
        if (entity instanceof PositionableEntity) {
          fw.write("    </Transform>\n");
        }

        fw.write("<!-- End entity: " + entity.getEntityID() + "-->\n");
      }

      fw.write("</Scene>\n");
      fw.write("</X3D>\n");
      fw.close();

    } catch (IOException ioe) {
      errorReporter.errorReport("IO Error.", ioe);
    }
  }
Exemple #5
0
  /**
   * Output a specific entity to the specified stream.
   *
   * @param model The world model to export
   * @param entityID The entity to export
   * @param fw The stream to write to
   */
  public void export(WorldModel model, int entityID, Writer fw, String worldURL) {

    super.export(model, entityID, fw);

    Entity[] toolValues = ((BaseWorldModel) model).getModelData();

    Entity entity = toolValues[entityID];

    if (entity == null) {
      // errorReporter.messageReport("Cannot find model to export: " + entityID);
      return;
    }

    if (entity.isController()) {
      return;
    }

    try {
      fw.write(header);

      fw.write("<!-- Begin entity: " + entity.getEntityID() + "-->\n");

      // if the entity has a position then place it
      if (entity instanceof PositionableEntity) {

        double[] position = new double[3];
        float[] rotation = new float[4];
        float[] scale = new float[3];

        ((PositionableEntity) entity).getPosition(position);
        ((PositionableEntity) entity).getRotation(rotation);
        ((PositionableEntity) entity).getScale(scale);

        fw.write(
            "    <Transform "
                + "translation='"
                + position[0]
                + " "
                + position[1]
                + " "
                + position[2]
                + "' "
                + "rotation='"
                + rotation[0]
                + " "
                + rotation[1]
                + " "
                + rotation[2]
                + " "
                + rotation[3]
                + "' "
                + "scale='"
                + scale[0]
                + " "
                + scale[1]
                + " "
                + scale[2]
                + "' >\n");
      }

      // inline the model
      String url = entity.getModelURL();

      fw.write("        <Inline url='" + worldURL + url + "' />\n");

      // if the entity has a position then place it
      if (entity instanceof PositionableEntity) {
        fw.write("    </Transform>\n");
      }

      fw.write("<!-- End entity: " + entity.getEntityID() + "-->\n");

      fw.write("</Scene>\n");
      fw.write("</X3D>\n");

      fw.close();
    } catch (IOException ioe) {
      errorReporter.errorReport("IO Error.", ioe);
    }
  }
  @Override
  public void doExecute() {

    super.copySrcconfig();
    super.copyWeb();
  }
  /* (non-Javadoc)
   * @see net.sourceforge.arbaro.tree.TreeTraversal#enterStem(net.sourceforge.arbaro.tree.Stem)
   */
  public boolean enterStem(Stem stem) {
    if (level >= 0 && stem.getLevel() < level) {
      return true; // look further for stems

    } else if (level >= 0 && stem.getLevel() > level) {
      return false; // go back to higher level

    } else {

      String indent = whitespace(stem.getLevel() * 2 + 4);
      NumberFormat fmt = FloatFormat.getInstance();
      Enumeration sections = stem.sections();

      if (sections.hasMoreElements()) {
        StemSection from = (StemSection) sections.nextElement();
        StemSection to = null;

        while (sections.hasMoreElements()) {
          to = (StemSection) sections.nextElement();

          w.println(
              indent
                  + "cone   { "
                  + vectorStr(from.getPosition())
                  + ", "
                  + fmt.format(from.getRadius())
                  + ", "
                  + vectorStr(to.getPosition())
                  + ", "
                  + fmt.format(to.getRadius())
                  + " }");

          // put spheres where z-directions changes
          if (!from.getZ().equals(to.getPosition().sub(from.getPosition()).normalize())) {

            w.println(
                indent
                    + "sphere { "
                    + vectorStr(from.getPosition())
                    + ", "
                    + fmt.format(from.getRadius() - 0.0001)
                    + " }");
          }

          from = to;
        }

        // put sphere at stem end
        /* FIXME? now using sections instead of segments, the spherical stem end
        *       will be made from several cones instead of one shpere ...

        			if ((to.getRadius() > 0.0001) ||
        					(lpar.nTaper>1 && lpar.nTaper<=2))
        			{
        				w.println(indent + "sphere { " + vectorStr(to.getPosition()) + ", "
        						+ fmt.format(to.getRadius()-0.0001) + " }");
        			}
        		*/
      }

      exporter.incProgressCount(AbstractExporter.STEM_PROGRESS_STEP);

      return true;
    }
  }