]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/save/PovExporter.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / save / PovExporter.java
index 3696dd10811986994943af9d7bdcc431a7f3eeb7..ee30841d6d779f7790b95006a58a75eda7759433 100644 (file)
@@ -9,57 +9,68 @@ import java.awt.event.ActionListener;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
 
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
 import javax.swing.JButton;
 import javax.swing.JDialog;
 import javax.swing.JFileChooser;
-import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JRadioButton;
 import javax.swing.JTextField;
 import javax.swing.SwingConstants;
-import javax.swing.filechooser.FileFilter;
 
+import tim.prune.App;
 import tim.prune.I18nManager;
+import tim.prune.UpdateMessageBroker;
+import tim.prune.config.Config;
+import tim.prune.data.NumberUtils;
 import tim.prune.data.Track;
+import tim.prune.function.Export3dFunction;
+import tim.prune.gui.DialogCloser;
+import tim.prune.load.GenericFileFilter;
 import tim.prune.threedee.LineDialog;
 import tim.prune.threedee.ThreeDModel;
 
 /**
- * Class to export track information
- * into a specified Pov file
+ * Class to export a 3d scene of the track to a specified Pov file
  */
-public class PovExporter
+public class PovExporter extends Export3dFunction
 {
-       private JFrame _parentFrame = null;
        private Track _track = null;
        private JDialog _dialog = null;
        private JFileChooser _fileChooser = null;
        private String _cameraX = null, _cameraY = null, _cameraZ = null;
        private JTextField _cameraXField = null, _cameraYField = null, _cameraZField = null;
-       private JTextField _fontName = null, _altitudeCapField = null;
-       private int _altitudeCap = ThreeDModel.MINIMUM_ALTITUDE_CAP;
+       private JTextField _fontName = null, _altitudeFactorField = null;
+       private JRadioButton _ballsAndSticksButton = null;
 
        // defaults
        private static final double DEFAULT_CAMERA_DISTANCE = 30.0;
        private static final String DEFAULT_FONT_FILE = "crystal.ttf";
-       // alternative font: DejaVuSans-Bold.ttf
 
 
        /**
-        * Constructor giving frame and track
-        * @param inParentFrame parent frame
-        * @param inTrack track object to save
+        * Constructor
+        * @param inApp App object
         */
-       public PovExporter(JFrame inParentFrame, Track inTrack)
+       public PovExporter(App inApp)
        {
-               _parentFrame = inParentFrame;
-               _track = inTrack;
+               super(inApp);
+               _track = inApp.getTrackInfo().getTrack();
                // Set default camera coordinates
                _cameraX = "17"; _cameraY = "13"; _cameraZ = "-20";
        }
 
+       /** Get the name key */
+       public String getNameKey() {
+               return "function.exportpov";
+       }
 
        /**
         * Set the coordinates for the camera (can be any scale)
@@ -73,23 +84,10 @@ public class PovExporter
                double cameraDist = Math.sqrt(inX*inX + inY*inY + inZ*inZ);
                if (cameraDist > 0.0)
                {
-                       _cameraX = "" + (inX / cameraDist * DEFAULT_CAMERA_DISTANCE);
-                       _cameraY = "" + (inY / cameraDist * DEFAULT_CAMERA_DISTANCE);
+                       _cameraX = NumberUtils.formatNumber(inX / cameraDist * DEFAULT_CAMERA_DISTANCE, 5);
+                       _cameraY = NumberUtils.formatNumber(inY / cameraDist * DEFAULT_CAMERA_DISTANCE, 5);
                        // Careful! Need to convert from java3d (right-handed) to povray (left-handed) coordinate system!
-                       _cameraZ = "" + (-inZ / cameraDist * DEFAULT_CAMERA_DISTANCE);
-               }
-       }
-
-
-       /**
-        * @param inAltitudeCap altitude cap to use
-        */
-       public void setAltitudeCap(int inAltitudeCap)
-       {
-               _altitudeCap = inAltitudeCap;
-               if (_altitudeCap < ThreeDModel.MINIMUM_ALTITUDE_CAP)
-               {
-                       _altitudeCap = ThreeDModel.MINIMUM_ALTITUDE_CAP;
+                       _cameraZ = NumberUtils.formatNumber(-inZ / cameraDist * DEFAULT_CAMERA_DISTANCE, 5);
                }
        }
 
@@ -97,12 +95,12 @@ public class PovExporter
        /**
         * Show the dialog to select options and export file
         */
-       public void showDialog()
+       public void begin()
        {
                // Make dialog window to select angles, colours etc
                if (_dialog == null)
                {
-                       _dialog = new JDialog(_parentFrame, I18nManager.getText("dialog.exportpov.title"), true);
+                       _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
                        _dialog.setLocationRelativeTo(_parentFrame);
                        _dialog.getContentPane().add(makeDialogComponents());
                }
@@ -111,11 +109,10 @@ public class PovExporter
                _cameraXField.setText(_cameraX);
                _cameraYField.setText(_cameraY);
                _cameraZField.setText(_cameraZ);
-               // Set vertical scale
-               _altitudeCapField.setText("" + _altitudeCap);
+               _altitudeFactorField.setText("" + _altFactor);
                // Show dialog
                _dialog.pack();
-               _dialog.show();
+               _dialog.setVisible(true);
        }
 
 
@@ -127,7 +124,9 @@ public class PovExporter
        {
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
-               panel.add(new JLabel(I18nManager.getText("dialog.exportpov.text")), BorderLayout.NORTH);
+               JLabel introLabel = new JLabel(I18nManager.getText("dialog.exportpov.text"));
+               introLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 6, 4));
+               panel.add(introLabel, BorderLayout.NORTH);
                // OK, Cancel buttons
                JPanel buttonPanel = new JPanel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
@@ -157,8 +156,13 @@ public class PovExporter
                JLabel fontLabel = new JLabel(I18nManager.getText("dialog.exportpov.font"));
                fontLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                centralPanel.add(fontLabel);
-               _fontName = new JTextField(DEFAULT_FONT_FILE, 12);
+               String defaultFont = Config.getConfigString(Config.KEY_POVRAY_FONT);
+               if (defaultFont == null || defaultFont.equals("")) {
+                       defaultFont = DEFAULT_FONT_FILE;
+               }
+               _fontName = new JTextField(defaultFont, 12);
                _fontName.setAlignmentX(Component.LEFT_ALIGNMENT);
+               _fontName.addKeyListener(new DialogCloser(_dialog));
                centralPanel.add(_fontName);
                //coordinates of camera
                JLabel cameraXLabel = new JLabel(I18nManager.getText("dialog.exportpov.camerax"));
@@ -176,16 +180,40 @@ public class PovExporter
                centralPanel.add(cameraZLabel);
                _cameraZField = new JTextField("" + _cameraZ);
                centralPanel.add(_cameraZField);
-               // Altitude capping
-               JLabel altitudeCapLabel = new JLabel(I18nManager.getText("dialog.3d.altitudecap"));
+               // Altitude exaggeration
+               JLabel altitudeCapLabel = new JLabel(I18nManager.getText("dialog.3d.altitudefactor"));
                altitudeCapLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                centralPanel.add(altitudeCapLabel);
-               _altitudeCapField = new JTextField("" + _altitudeCap);
-               centralPanel.add(_altitudeCapField);
+               _altitudeFactorField = new JTextField("1.0");
+               centralPanel.add(_altitudeFactorField);
+
+               // Radio buttons for style - balls on sticks or tubes
+               JPanel stylePanel = new JPanel();
+               stylePanel.setLayout(new GridLayout(0, 2, 10, 4));
+               JLabel styleLabel = new JLabel(I18nManager.getText("dialog.exportpov.modelstyle"));
+               styleLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+               stylePanel.add(styleLabel);
+               JPanel radioPanel = new JPanel();
+               radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
+               _ballsAndSticksButton = new JRadioButton(I18nManager.getText("dialog.exportpov.ballsandsticks"));
+               _ballsAndSticksButton.setSelected(false);
+               radioPanel.add(_ballsAndSticksButton);
+               JRadioButton tubesButton = new JRadioButton(I18nManager.getText("dialog.exportpov.tubesandwalls"));
+               tubesButton.setSelected(true);
+               radioPanel.add(tubesButton);
+               ButtonGroup group = new ButtonGroup();
+               group.add(_ballsAndSticksButton); group.add(tubesButton);
+               stylePanel.add(radioPanel);
+
+               // add this grid to the holder panel
+               JPanel holderPanel = new JPanel();
+               holderPanel.setLayout(new BorderLayout(5, 5));
+               JPanel boxPanel = new JPanel();
+               boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.Y_AXIS));
+               boxPanel.add(centralPanel);
+               boxPanel.add(stylePanel);
+               holderPanel.add(boxPanel, BorderLayout.CENTER);
 
-               JPanel flowPanel = new JPanel();
-               flowPanel.add(centralPanel);
-               
                // show lines button
                JButton showLinesButton = new JButton(I18nManager.getText("button.showlines"));
                showLinesButton.addActionListener(new ActionListener() {
@@ -200,8 +228,11 @@ public class PovExporter
                                dialog.showDialog();
                        }
                });
+               JPanel flowPanel = new JPanel();
+               flowPanel.setLayout(new FlowLayout());
                flowPanel.add(showLinesButton);
-               panel.add(flowPanel, BorderLayout.CENTER);
+               holderPanel.add(flowPanel, BorderLayout.EAST);
+               panel.add(holderPanel, BorderLayout.CENTER);
                return panel;
        }
 
@@ -218,19 +249,15 @@ public class PovExporter
 
                // OK pressed, so choose output file
                if (_fileChooser == null)
+               {
                        _fileChooser = new JFileChooser();
-               _fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
-               _fileChooser.setFileFilter(new FileFilter() {
-                       public boolean accept(File f)
-                       {
-                               return (f != null && (f.isDirectory() || f.getName().toLowerCase().endsWith(".pov")));
-                       }
-                       public String getDescription()
-                       {
-                               return I18nManager.getText("dialog.exportpov.filetype");
-                       }
-               });
-               _fileChooser.setAcceptAllFileFilterUsed(false);
+                       _fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
+                       _fileChooser.setFileFilter(new GenericFileFilter("filetype.pov", new String[] {"pov"}));
+                       _fileChooser.setAcceptAllFileFilterUsed(false);
+                       // start from directory in config which should be set
+                       final String configDir = Config.getConfigString(Config.KEY_TRACK_DIR);
+                       if (configDir != null) {_fileChooser.setCurrentDirectory(new File(configDir));}
+               }
 
                // Allow choose again if an existing file is selected
                boolean chooseAgain = false;
@@ -257,6 +284,8 @@ public class PovExporter
                                        if (exportFile(file))
                                        {
                                                // file saved
+                                               // Store directory in config for later
+                                               Config.setConfigString(Config.KEY_TRACK_DIR, file.getParentFile().getAbsolutePath());
                                        }
                                        else
                                        {
@@ -283,7 +312,7 @@ public class PovExporter
        {
                FileWriter writer = null;
                // find out the line separator for this system
-               String lineSeparator = System.getProperty("line.separator");
+               final String lineSeparator = System.getProperty("line.separator");
                try
                {
                        // create and scale model
@@ -291,10 +320,12 @@ public class PovExporter
                        try
                        {
                                // try to use given altitude cap
-                               _altitudeCap = Integer.parseInt(_altitudeCapField.getText());
-                               model.setAltitudeCap(_altitudeCap);
+                               double altFactor = Double.parseDouble(_altitudeFactorField.getText());
+                               model.setAltitudeFactor(altFactor);
+                       }
+                       catch (NumberFormatException nfe) { // parse failed, reset
+                               _altitudeFactorField.setText("1.0");
                        }
-                       catch (NumberFormatException nfe) {}
                        model.scale();
 
                        // Create file and write basics
@@ -305,18 +336,22 @@ public class PovExporter
                        writeLatLongLines(writer, model, lineSeparator);
 
                        // write out points
-                       writeDataPoints(writer, model, lineSeparator);
+                       if (_ballsAndSticksButton.isSelected()) {
+                               writeDataPointsBallsAndSticks(writer, model, lineSeparator);
+                       }
+                       else {
+                               writeDataPointsTubesAndWalls(writer, model, lineSeparator);
+                       }
 
                        // everything worked
-                       JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.save.ok1")
-                                + " " + _track.getNumPoints() + " " + I18nManager.getText("dialog.save.ok2")
-                                + " " + inFile.getAbsolutePath(),
-                               I18nManager.getText("dialog.save.oktitle"), JOptionPane.INFORMATION_MESSAGE);
+                       UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.save.ok1")
+                                + " " + _track.getNumPoints() + " " + I18nManager.getText("confirm.save.ok2")
+                                + " " + inFile.getAbsolutePath());
                        return true;
                }
                catch (IOException ioe)
                {
-                       JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + ioe.getMessage(),
+                       JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + " : " + ioe.getMessage(),
                                I18nManager.getText("error.save.dialogtitle"), JOptionPane.ERROR_MESSAGE);
                }
                finally
@@ -342,7 +377,7 @@ public class PovExporter
        private void writeStartOfFile(FileWriter inWriter, double inModelSize, String inLineSeparator)
        throws IOException
        {
-               inWriter.write("// Pov file produced by Prune - see http://activityworkshop.net/");
+               inWriter.write("// Pov file produced by GpsPrune - see http://activityworkshop.net/");
                inWriter.write(inLineSeparator);
                inWriter.write(inLineSeparator);
                // Select font based on user input
@@ -351,6 +386,9 @@ public class PovExporter
                {
                        fontPath = DEFAULT_FONT_FILE;
                }
+               else {
+                       Config.setConfigString(Config.KEY_POVRAY_FONT, fontPath);
+               }
                // Set up output
                String[] outputLines = {
                  "global_settings { ambient_light rgb <4, 4, 4> }", "",
@@ -385,7 +423,7 @@ public class PovExporter
                  "   open",
                  "   pigment { color rgb <0.5 0.5 0.5> }",
                  "  }", "",
-                 // TODO: Export rods to POV?  How to store in data?
+                 // MAYBE: Export rods to POV?  How to store in data?
                  "#declare waypoint_sphere =",
                  "  sphere {",
                  "   <0, 0, 0>, 0.4",
@@ -398,7 +436,7 @@ public class PovExporter
                  "  sphere {",
                  "   <0, 0, 0>, 0.3", // size should depend on model size
                  "   texture {",
-                 "      pigment {color rgb <0.2 1.0 0.2>}",
+                 "      pigment {color rgb <0.1 0.6 0.1>}", // dark green
                  "      finish { phong 1 }",
                  "   }",
                  " }",
@@ -406,7 +444,7 @@ public class PovExporter
                  "  sphere {",
                  "   <0, 0, 0>, 0.3", // size should depend on model size
                  "   texture {",
-                 "      pigment {color rgb <0.6 1.0 0.2>}",
+                 "      pigment {color rgb <0.4 0.9 0.2>}", // green
                  "      finish { phong 1 }",
                  "   }",
                  " }",
@@ -414,7 +452,7 @@ public class PovExporter
                  "  sphere {",
                  "   <0, 0, 0>, 0.3", // size should depend on model size
                  "   texture {",
-                 "      pigment {color rgb <1.0 1.0 0.1>}",
+                 "      pigment {color rgb <0.7 0.8 0.2>}", // yellow
                  "      finish { phong 1 }",
                  "   }",
                  " }",
@@ -422,7 +460,7 @@ public class PovExporter
                  "  sphere {",
                  "   <0, 0, 0>, 0.3", // size should depend on model size
                  "   texture {",
-                 "      pigment {color rgb <1.0 1.0 1.0>}",
+                 "      pigment {color rgb <0.5 0.8 0.6>}", // greeny
                  "      finish { phong 1 }",
                  "   }",
                  " }",
@@ -430,10 +468,27 @@ public class PovExporter
                  "  sphere {",
                  "   <0, 0, 0>, 0.3", // size should depend on model size
                  "   texture {",
-                 "      pigment {color rgb <0.1 1.0 1.0>}",
+                 "      pigment {color rgb <0.2 0.9 0.9>}", // cyan
                  "      finish { phong 1 }",
                  "   }",
-                 " }", "",
+                 " }",
+                 "#declare track_sphere5 =",
+                 "  sphere {",
+                 "   <0, 0, 0>, 0.3", // size should depend on model size
+                 "   texture {",
+                 "      pigment {color rgb <1.0 1.0 1.0>}", // white
+                 "      finish { phong 1 }",
+                 "   }",
+                 " }",
+                 "#declare track_sphere_t =",
+                 "  sphere {",
+                 "   <0, 0, 0>, 0.25", // size should depend on model size
+                 "   texture {",
+                 "      pigment {color rgb <0.6 1.0 0.2>}",
+                 "      finish { phong 1 }",
+                 "   } no_shadow",
+                 " }",
+                 "#declare wall_colour = rgbt <0.5, 0.5, 0.5, 0.3>;", "",
                  "// Base plane",
                  "box {",
                  "   <-" + inModelSize + ", -0.15, -" + inModelSize + ">,  // Near lower left corner",
@@ -462,7 +517,7 @@ public class PovExporter
                  "  pigment { color rgb <1 1 1> }",
                  "  translate <-" + (inModelSize * 1.03) + ", 0.2, 0>",
                  "}", "",
-                 // TODO: Light positions should relate to model size
+                 // MAYBE: Light positions should relate to model size
                  "// lights",
                  "light_source { <-1, 9, -4> color rgb <0.5 0.5 0.5>}",
                  "light_source { <1, 6, -14> color rgb <0.6 0.6 0.6>}",
@@ -486,7 +541,7 @@ public class PovExporter
         * @param inLineSeparator line separator to use
         * @throws IOException on file writing error
         */
-       private void writeLatLongLines(FileWriter inWriter, ThreeDModel inModel, String inLineSeparator)
+       private static void writeLatLongLines(FileWriter inWriter, ThreeDModel inModel, String inLineSeparator)
        throws IOException
        {
                inWriter.write("// Latitude and longitude lines:");
@@ -510,13 +565,13 @@ public class PovExporter
 
 
        /**
-        * Write out all the data points to the file
+        * Write out all the data points to the file in the balls-and-sticks style
         * @param inWriter Writer to use for writing file
         * @param inModel model object for getting data points
         * @param inLineSeparator line separator to use
         * @throws IOException on file writing error
         */
-       private void writeDataPoints(FileWriter inWriter, ThreeDModel inModel, String inLineSeparator)
+       private static void writeDataPointsBallsAndSticks(FileWriter inWriter, ThreeDModel inModel, String inLineSeparator)
        throws IOException
        {
                inWriter.write("// Data points:");
@@ -551,13 +606,166 @@ public class PovExporter
        }
 
 
+       /**
+        * Write out all the data points to the file in the tubes-and-walls style
+        * @param inWriter Writer to use for writing file
+        * @param inModel model object for getting data points
+        * @param inLineSeparator line separator to use
+        * @throws IOException on file writing error
+        */
+       private static void writeDataPointsTubesAndWalls(FileWriter inWriter, ThreeDModel inModel, String inLineSeparator)
+       throws IOException
+       {
+               inWriter.write("// Data points:");
+               inWriter.write(inLineSeparator);
+               int numPoints = inModel.getNumPoints();
+               int numTrackPoints = 0;
+               // Loop over all points and write out waypoints as balls
+               for (int i=0; i<numPoints; i++)
+               {
+                       if (inModel.getPointType(i) == ThreeDModel.POINT_TYPE_WAYPOINT)
+                       {
+                               // waypoint ball
+                               inWriter.write("object { waypoint_sphere translate <" + inModel.getScaledHorizValue(i)
+                                       + "," + inModel.getScaledAltValue(i) + "," + inModel.getScaledVertValue(i) + "> }");
+                               // vertical rod (if altitude positive)
+                               if (inModel.getScaledAltValue(i) > 0.0)
+                               {
+                                       inWriter.write(inLineSeparator);
+                                       inWriter.write("object { point_rod translate <" + inModel.getScaledHorizValue(i) + ",0,"
+                                               + inModel.getScaledVertValue(i) + "> scale <1," + inModel.getScaledAltValue(i) + ",1> }");
+                               }
+                               inWriter.write(inLineSeparator);
+                       }
+                       else {numTrackPoints++;}
+               }
+               inWriter.write(inLineSeparator);
+
+               // Loop over all the track segments
+               ArrayList<ModelSegment> segmentList = getSegmentList(inModel);
+               Iterator<ModelSegment> segmentIterator = segmentList.iterator();
+               while (segmentIterator.hasNext())
+               {
+                       ModelSegment segment = segmentIterator.next();
+                       int segLength = segment.getNumTrackPoints();
+
+                       // if the track segment is long enough, do a cubic spline sphere sweep
+                       if (segLength <= 1)
+                       {
+                               // single point in segment - just draw sphere
+                               int index = segment.getStartIndex();
+                               inWriter.write("object { track_sphere_t"
+                                       + " translate <" + inModel.getScaledHorizValue(index) + "," + inModel.getScaledAltValue(index)
+                                       + "," + inModel.getScaledVertValue(index) + "> }");
+                               // maybe draw some kind of polygon too or rod?
+                       }
+                       else
+                       {
+                               writeSphereSweep(inWriter, inModel, segment, inLineSeparator);
+                       }
+
+                       // Write wall underneath segment
+                       if (segLength > 1)
+                       {
+                               writePolygonWall(inWriter, inModel, segment, inLineSeparator);
+                       }
+               }
+       }
+
+
+       /**
+        * Write out a single sphere sweep using either cubic spline or linear spline
+        * @param inWriter Writer to use for writing file
+        * @param inModel model object for getting data points
+        * @param inSegment model segment to draw
+        * @param inLineSeparator line separator to use
+        * @throws IOException on file writing error
+        */
+       private static void writeSphereSweep(FileWriter inWriter, ThreeDModel inModel, ModelSegment inSegment, String inLineSeparator)
+       throws IOException
+       {
+               // 3d sphere sweep
+               inWriter.write("// Sphere sweep:");
+               inWriter.write(inLineSeparator);
+               String splineType = inSegment.getNumTrackPoints() < 5?"linear_spline":"cubic_spline";
+               inWriter.write("sphere_sweep { "); inWriter.write(splineType);
+               inWriter.write(" " + inSegment.getNumTrackPoints() + ",");
+               inWriter.write(inLineSeparator);
+               // Loop over all points in this segment and write out sphere sweep
+               for (int i=inSegment.getStartIndex(); i<=inSegment.getEndIndex(); i++)
+               {
+                       if (inModel.getPointType(i) != ThreeDModel.POINT_TYPE_WAYPOINT)
+                       {
+                               inWriter.write("  <" + inModel.getScaledHorizValue(i) + "," + inModel.getScaledAltValue(i)
+                                       + "," + inModel.getScaledVertValue(i) + ">, 0.25");
+                               inWriter.write(inLineSeparator);
+                       }
+               }
+               inWriter.write("  tolerance 0.1");
+               inWriter.write(inLineSeparator);
+               inWriter.write("  texture { pigment {color rgb <0.6 1.0 0.2>}  finish {phong 1} }");
+               inWriter.write(inLineSeparator);
+               inWriter.write("  no_shadow");
+               inWriter.write(inLineSeparator);
+               inWriter.write("}");
+               inWriter.write(inLineSeparator);
+       }
+
+
+       /**
+        * Write out a single polygon-based wall for the tubes-and-walls style
+        * @param inWriter Writer to use for writing file
+        * @param inModel model object for getting data points
+        * @param inSegment model segment to draw
+        * @param inLineSeparator line separator to use
+        * @throws IOException on file writing error
+        */
+       private static void writePolygonWall(FileWriter inWriter, ThreeDModel inModel, ModelSegment inSegment, String inLineSeparator)
+       throws IOException
+       {
+               // wall
+               inWriter.write(inLineSeparator);
+               inWriter.write("// wall between sweep and floor:");
+               inWriter.write(inLineSeparator);
+               // Loop over all points in this segment again and write out polygons
+               int prevIndex = -1;
+               for (int i=inSegment.getStartIndex(); i<=inSegment.getEndIndex(); i++)
+               {
+                       if (inModel.getPointType(i) != ThreeDModel.POINT_TYPE_WAYPOINT)
+                       {
+                               if (prevIndex >= 0)
+                               {
+                                       double xDiff = inModel.getScaledHorizValue(i) - inModel.getScaledHorizValue(prevIndex);
+                                       double yDiff = inModel.getScaledVertValue(i) - inModel.getScaledVertValue(prevIndex);
+                                       double dist = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
+                                       if (dist > 0)
+                                       {
+                                               inWriter.write("polygon {");
+                                               inWriter.write("  5, <" + inModel.getScaledHorizValue(prevIndex) + ", 0.0, " + inModel.getScaledVertValue(prevIndex) + ">,");
+                                               inWriter.write(" <" + inModel.getScaledHorizValue(prevIndex) + ", " + inModel.getScaledAltValue(prevIndex) + ", "
+                                                       + inModel.getScaledVertValue(prevIndex) + ">,");
+                                               inWriter.write(" <" + inModel.getScaledHorizValue(i) + ", " + inModel.getScaledAltValue(i) + ", "
+                                                       + inModel.getScaledVertValue(i) + ">,");
+                                               inWriter.write(" <" + inModel.getScaledHorizValue(i) + ", 0.0, " + inModel.getScaledVertValue(i) + ">,");
+                                               inWriter.write(" <" + inModel.getScaledHorizValue(prevIndex) + ", 0.0, " + inModel.getScaledVertValue(prevIndex) + ">");
+                                               inWriter.write("  pigment { color wall_colour } no_shadow");
+                                               inWriter.write("}");
+                                               inWriter.write(inLineSeparator);
+                                       }
+                               }
+                               prevIndex = i;
+                       }
+               }
+       }
+
+
        /**
         * @param inCode height code to check
         * @return validated height code within range 0 to max
         */
        private static byte checkHeightCode(byte inCode)
        {
-               final byte maxHeightCode = 4;
+               final byte maxHeightCode = 5;
                if (inCode < 0) return 0;
                if (inCode > maxHeightCode) return maxHeightCode;
                return inCode;
@@ -579,4 +787,46 @@ public class PovExporter
                catch (Exception e) {} // ignore parse failures
                return "" + value;
        }
+
+       /**
+        * Go through the points making a list of the segment starts and the number of track points in each segment
+        * @param inModel model containing data
+        * @return list of ModelSegment objects
+        */
+       private static ArrayList<ModelSegment> getSegmentList(ThreeDModel inModel)
+       {
+               ArrayList<ModelSegment> segmentList = new ArrayList<ModelSegment>();
+               if (inModel != null && inModel.getNumPoints() > 0)
+               {
+                       ModelSegment currSegment = null;
+                       int numTrackPoints = 0;
+                       for (int i=0; i<inModel.getNumPoints(); i++)
+                       {
+                               if (inModel.getPointType(i) != ThreeDModel.POINT_TYPE_WAYPOINT)
+                               {
+                                       if (inModel.getPointType(i) == ThreeDModel.POINT_TYPE_SEGMENT_START || currSegment == null)
+                                       {
+                                               // start of segment
+                                               if (currSegment != null)
+                                               {
+                                                       currSegment.setEndIndex(i-1);
+                                                       currSegment.setNumTrackPoints(numTrackPoints);
+                                                       segmentList.add(currSegment);
+                                                       numTrackPoints = 0;
+                                               }
+                                               currSegment = new ModelSegment(i);
+                                       }
+                                       numTrackPoints++;
+                               }
+                       }
+                       // Add last segment to list
+                       if (currSegment != null && numTrackPoints > 0)
+                       {
+                               currSegment.setEndIndex(inModel.getNumPoints()-1);
+                               currSegment.setNumTrackPoints(numTrackPoints);
+                               segmentList.add(currSegment);
+                       }
+               }
+               return segmentList;
+       }
 }