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