complexplayground.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *    frankguettler@gmx.de                                                 *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  *   Playground that is loaded from xfig file with polylines               *
00024  *                                                                         *
00025  *   $Log: complexplayground.h,v $
00026  *   Revision 1.2  2010/04/27 14:42:18  martius
00027  *   some comments added
00028  *
00029  *   Revision 1.1  2007/08/28 09:23:14  martius
00030  *   initial
00031  *
00032  *                                                                 *
00033  ***************************************************************************/
00034 #ifndef __COMPLEXPLAYGROUND_H
00035 #define __COMPLEXPLAYGROUND_H
00036 
00037 #include "mathutils.h"
00038 #include "abstractground.h"
00039 #include "pos.h"
00040  
00041 namespace lpzrobots {
00042 
00043 // Taken from XFIG documentation
00044 // .....
00045 // (2) The first non-comment line consists of the following:
00046 
00047 //         string  orientation             ("Landscape" or "Portrait")
00048 //         string  justification           ("Center" or "Flush Left")
00049 //         string  units                   ("Metric" or "Inches")
00050 //         string  papersize               ("Letter", "Legal", "Ledger", "Tabloid",
00051 //                                          "A", "B", "C", "D", "E",
00052 //                                          "A4",   "A3", "A2", "A1", "A0" and "B5")
00053 //         float   magnification           (export and print magnification, %)
00054 //         string  multiple-page           ("Single" or "Multiple" pages)
00055 //         int     transparent color       (color number for transparent color for GIF
00056 //                                          export. -3=background, -2=None, -1=Default,
00057 //                                          0-31 for standard colors or 32- for user colors)
00058 //         # optional comment              (An optional set of comments may be here,
00059 //                                          which are associated with the whole figure)
00060 //         int     resolution coord_system (Fig units/inch and coordinate system:
00061 //                                            1: origin at lower left corner (NOT USED)
00062 //                                            2: upper left)
00063 
00064 //     Fig_resolution is the resolution of the figure in the file.
00065 //     Xfig will always write the file with a resolution of 1200ppi so it
00066 //     will scale the figure upon reading it in if its resolution is different
00067 //     from 1200ppi.  Pixels are assumed to be square.
00068 
00069 //     Xfig will read the orientation string and change the canvas to match
00070 //     either the Landscape or Portrait mode of the figure file.
00071 
00072 //     The units specification is self-explanatory.
00073 
00074 //     The coordinate_system variable is ignored - the origin is ALWAYS the
00075 //     upper-left corner.
00076 
00077 //     ** Coordinates are given in "fig_resolution" units.
00078 //     ** Line thicknesses are given in 1/80 inch (0.3175mm) or 1 screen pixel.
00079 //        When exporting to EPS, PostScript or any bitmap format (e.g. GIF),  the
00080 //        line thickness is reduced to 1/160 inch (0.159mm) to "lighten" the look.
00081 //     ** dash-lengths/dot-gaps are given in 80-ths of an inch.
00082 
00083 
00084 
00085 
00086 // (3) The rest of the file contains various objects.  An object can be one
00087 //     of six classes (or types).
00088 
00089 //         0)      Color pseudo-object.
00090 //         1)      Ellipse which is a generalization of circle.
00091 //         2)      Polyline which includes polygon and box.
00092 //         3)      Spline which includes
00093 //                 closed/open approximated/interpolated/x-spline spline.
00094 //         4)      Text.
00095 //         5)      Arc.
00096 //         6)      Compound object which is composed of one or more objects.
00097 // ........
00098 //    (3.5) POLYLINE
00099 
00100 //     First line:
00101 //         type    name                    (brief description)
00102 //         ----    ----                    -------------------
00103 //         int     object_code             (always 2)
00104 //         int     sub_type                (1: polyline
00105 //                                          2: box
00106 //                                          3: polygon
00107 //                                          4: arc-box)
00108 //                                          5: imported-picture bounding-box)
00109 //         int     line_style              (enumeration type)
00110 //         int     thickness               (1/80 inch)
00111 //         int     pen_color               (enumeration type, pen color)
00112 //         int     fill_color              (enumeration type, fill color)
00113 //         int     depth                   (enumeration type)
00114 //         int     pen_style               (pen style, not used)
00115 //         int     area_fill               (enumeration type, -1 = no fill)
00116 //         float   style_val               (1/80 inch)
00117 //         int     join_style              (enumeration type)
00118 //         int     cap_style               (enumeration type, only used for POLYLINE)
00119 //         int     radius                  (1/80 inch, radius of arc-boxes)
00120 //         int     forward_arrow           (0: off, 1: on)
00121 //         int     backward_arrow          (0: off, 1: on)
00122 //         int     npoints                 (number of points in line)
00123 
00124 //     Forward arrow line: same as ARC object
00125 
00126 //     Backward arrow line: same as ARC object
00127 
00128 //     For picture (type 5) the following line follows:
00129 //         type    name                    (brief description)
00130 //         ----    ----                    -------------------
00131 //         boolean flipped                 orientation = normal (0) or flipped (1)
00132 //         char    file[]                  name of picture file to import
00133 
00134 //     Points line(s).  The x,y coordinates follow, any number to a line, with
00135 //     as many lines as are necessary:
00136 //         type    name                    (brief description)
00137 //         ----    ----                    -------------------
00138 //         int     x1, y1                  (Fig units)
00139 //         int     x2, y2                  (Fig units)
00140 //           .
00141 //           .
00142 //         int     xnpoints ynpoints       (this will be the same as the 1st
00143 //                                         point for polygon and box)
00144 
00145   class PolyLine {
00146   public:
00147     PolyLine(){};
00148     /** try to parses a PolyLine at the start of the list of lines and returns the consumed lines
00149         1: no success; >=2 success
00150      */
00151     int parse(std::list<char*> lines);
00152     void print();
00153 
00154     int     object_code; //             (always 2)
00155     int     sub_type;    //             (we require 1: polyline)                                        
00156     int     line_style;  //             (0: normal wall, 1: border, rest ignored)
00157     int     thickness;   //             (1/80 inch means factor of .3175 )
00158     int     depth;       //             (multiple of height)
00159     std::list<Pos> points;
00160   };
00161 
00162   /** Playground that uses an xfig file with polylines
00163       linetype 0 is normal wall
00164       linetype 1 is border
00165       thickness is used as well, thickness is multiplied with wallthickness.
00166       depth is used as a height value and is multiplied with heightfactor.
00167       The entire size can be scaled with a global factor
00168   */
00169   class ComplexPlayground : public AbstractGround {
00170 
00171   protected:
00172 
00173     std::string filename;
00174     double length, factor, heightfactor;
00175     
00176     std::list<PolyLine> polylines;
00177    
00178   public:
00179     /**
00180        @param factor global factor for the entire playground
00181        @heightfactor factor for depth value of xfig line to determine wall height       
00182      */  
00183     ComplexPlayground(const OdeHandle& odeHandle, const OsgHandle& osgHandle , 
00184                       const std::string filename, 
00185                       double factor = 1, double heightfactor=0.02, bool createGround=true);
00186 
00187     void createPolyline(const PolyLine&);
00188 
00189   protected:
00190     virtual void create();   
00191     
00192   };
00193 
00194 }
00195 
00196 #endif
Generated on Fri Nov 4 10:59:38 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3