00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 LpzRobots development team * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00005 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00006 * Ralf Der <ralfder at mis dot mpg dot 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 ***************************************************************************/ 00024 #ifndef __COMPLEXPLAYGROUND_H 00025 #define __COMPLEXPLAYGROUND_H 00026 00027 #include "mathutils.h" 00028 #include "abstractground.h" 00029 #include "pos.h" 00030 00031 namespace lpzrobots { 00032 00033 // Taken from XFIG documentation 00034 // ..... 00035 // (2) The first non-comment line consists of the following: 00036 00037 // string orientation ("Landscape" or "Portrait") 00038 // string justification ("Center" or "Flush Left") 00039 // string units ("Metric" or "Inches") 00040 // string papersize ("Letter", "Legal", "Ledger", "Tabloid", 00041 // "A", "B", "C", "D", "E", 00042 // "A4", "A3", "A2", "A1", "A0" and "B5") 00043 // float magnification (export and print magnification, %) 00044 // string multiple-page ("Single" or "Multiple" pages) 00045 // int transparent color (color number for transparent color for GIF 00046 // export. -3=background, -2=None, -1=Default, 00047 // 0-31 for standard colors or 32- for user colors) 00048 // # optional comment (An optional set of comments may be here, 00049 // which are associated with the whole figure) 00050 // int resolution coord_system (Fig units/inch and coordinate system: 00051 // 1: origin at lower left corner (NOT USED) 00052 // 2: upper left) 00053 00054 // Fig_resolution is the resolution of the figure in the file. 00055 // Xfig will always write the file with a resolution of 1200ppi so it 00056 // will scale the figure upon reading it in if its resolution is different 00057 // from 1200ppi. Pixels are assumed to be square. 00058 00059 // Xfig will read the orientation string and change the canvas to match 00060 // either the Landscape or Portrait mode of the figure file. 00061 00062 // The units specification is self-explanatory. 00063 00064 // The coordinate_system variable is ignored - the origin is ALWAYS the 00065 // upper-left corner. 00066 00067 // ** Coordinates are given in "fig_resolution" units. 00068 // ** Line thicknesses are given in 1/80 inch (0.3175mm) or 1 screen pixel. 00069 // When exporting to EPS, PostScript or any bitmap format (e.g. GIF), the 00070 // line thickness is reduced to 1/160 inch (0.159mm) to "lighten" the look. 00071 // ** dash-lengths/dot-gaps are given in 80-ths of an inch. 00072 00073 00074 00075 00076 // (3) The rest of the file contains various objects. An object can be one 00077 // of six classes (or types). 00078 00079 // 0) Color pseudo-object. 00080 // 1) Ellipse which is a generalization of circle. 00081 // 2) Polyline which includes polygon and box. 00082 // 3) Spline which includes 00083 // closed/open approximated/interpolated/x-spline spline. 00084 // 4) Text. 00085 // 5) Arc. 00086 // 6) Compound object which is composed of one or more objects. 00087 // ........ 00088 // (3.5) POLYLINE 00089 00090 // First line: 00091 // type name (brief description) 00092 // ---- ---- ------------------- 00093 // int object_code (always 2) 00094 // int sub_type (1: polyline 00095 // 2: box 00096 // 3: polygon 00097 // 4: arc-box) 00098 // 5: imported-picture bounding-box) 00099 // int line_style (enumeration type) 00100 // int thickness (1/80 inch) 00101 // int pen_color (enumeration type, pen color) 00102 // int fill_color (enumeration type, fill color) 00103 // int depth (enumeration type) 00104 // int pen_style (pen style, not used) 00105 // int area_fill (enumeration type, -1 = no fill) 00106 // float style_val (1/80 inch) 00107 // int join_style (enumeration type) 00108 // int cap_style (enumeration type, only used for POLYLINE) 00109 // int radius (1/80 inch, radius of arc-boxes) 00110 // int forward_arrow (0: off, 1: on) 00111 // int backward_arrow (0: off, 1: on) 00112 // int npoints (number of points in line) 00113 00114 // Forward arrow line: same as ARC object 00115 00116 // Backward arrow line: same as ARC object 00117 00118 // For picture (type 5) the following line follows: 00119 // type name (brief description) 00120 // ---- ---- ------------------- 00121 // boolean flipped orientation = normal (0) or flipped (1) 00122 // char file[] name of picture file to import 00123 00124 // Points line(s). The x,y coordinates follow, any number to a line, with 00125 // as many lines as are necessary: 00126 // type name (brief description) 00127 // ---- ---- ------------------- 00128 // int x1, y1 (Fig units) 00129 // int x2, y2 (Fig units) 00130 // . 00131 // . 00132 // int xnpoints ynpoints (this will be the same as the 1st 00133 // point for polygon and box) 00134 00135 class PolyLine { 00136 public: 00137 PolyLine(){}; 00138 /** try to parses a PolyLine at the start of the list of lines and returns the consumed lines 00139 1: no success; >=2 success 00140 */ 00141 int parse(std::list<char*> lines); 00142 void print(); 00143 00144 int object_code; // (always 2) 00145 int sub_type; // (we require 1: polyline) 00146 int line_style; // (0: normal wall, 1: border, rest ignored) 00147 int thickness; // (1/80 inch means factor of .3175 ) 00148 int depth; // (multiple of height) 00149 std::list<Pos> points; 00150 }; 00151 00152 /** Playground that uses an xfig file with polylines 00153 linetype 0 is normal wall 00154 linetype 1 is border 00155 thickness is used as well, thickness is multiplied with wallthickness. 00156 depth is used as a height value and is multiplied with heightfactor. 00157 The entire size can be scaled with a global factor 00158 */ 00159 class ComplexPlayground : public AbstractGround { 00160 00161 protected: 00162 00163 std::string filename; 00164 double length, factor, heightfactor; 00165 00166 std::list<PolyLine> polylines; 00167 00168 public: 00169 /** 00170 @param factor global factor for the entire playground 00171 @heightfactor factor for depth value of xfig line to determine wall height 00172 */ 00173 ComplexPlayground(const OdeHandle& odeHandle, const OsgHandle& osgHandle , 00174 const std::string filename, 00175 double factor = 1, double heightfactor=0.02, bool createGround=true); 00176 00177 void createPolyline(const PolyLine&); 00178 00179 protected: 00180 virtual void create(); 00181 00182 }; 00183 00184 } 00185 00186 #endif