00001 //---------------------------------------------------------------------- 00002 // The Motion Strategy Library (MSL) 00003 //---------------------------------------------------------------------- 00004 // 00005 // Copyright (c) 1998-2000 Iowa State University and Steve LaValle. 00006 // All Rights Reserved. 00007 // 00008 // Permission to use, copy, and distribute this software and its 00009 // documentation is hereby granted free of charge, provided that 00010 // (1) it is not a component of a commercial product, and 00011 // (2) this notice appears in all copies of the software and 00012 // related documentation. 00013 // 00014 // Iowa State University and the author make no representations 00015 // about the suitability or fitness of this software for any purpose. 00016 // It is provided "as is" without express or implied warranty. 00017 //---------------------------------------------------------------------- 00018 00019 00020 #include "triangle.h" 00021 00022 00023 ostream& operator<<(ostream& out, const list<MSLTriangle>& L) 00024 { 00025 list<MSLTriangle>::iterator x; 00026 list<MSLTriangle> vl; 00027 vl = L; 00028 for (x = vl.begin(); x != vl.end(); x++) 00029 out << " " << *x; 00030 return out; 00031 } 00032 00033 00034 istream& operator>>(istream& in, list<MSLTriangle>& L) 00035 { 00036 L.clear(); 00037 MSLTriangle x; 00038 for(;;) 00039 { 00040 char c; 00041 while (in.get(c) && isspace(c)); 00042 if (!in) break; 00043 in.putback(c); 00044 x = MSLTriangle(); in >> x; L.push_back(x); 00045 } 00046 return in; 00047 } 00048 00049 00050 MSLTriangle::MSLTriangle(MSLPoint3d pt1, MSLPoint3d pt2, MSLPoint3d pt3){ 00051 p1 = pt1; 00052 p2 = pt2; 00053 p3 = pt3; 00054 } 00055 00056 00057 MSLTriangle::MSLTriangle(){ 00058 MSLPoint3d *p; 00059 p = new MSLPoint3d(0,0,0); 00060 p1 = *p; 00061 p2 = *p; 00062 p3 = *p; 00063 } 00064 00065 00066 MSLTriangle::MSLTriangle(const MSLTriangle& p){ 00067 p1 = p.p1; 00068 p2 = p.p2; 00069 p3 = p.p3; 00070 } 00071 00072 00073 list<MSLTriangle> PolygonsToTriangles(const list<MSLPolygon > &pl, 00074 double thickness) { 00075 00076 list<MSLPolygon>::const_iterator p; 00077 list<MSLPoint>::const_iterator pt; 00078 MSLPoint fpt; 00079 MSLPoint3d p1,p2,p3,p4,roof; 00080 list<MSLTriangle> tl; 00081 00082 tl.clear(); 00083 00084 for (p = pl.begin(); p != pl.end(); p++) { 00085 //cout << "Polygon: " << (*p) << "\n"; 00086 // Make the sides 00087 fpt = p->front(); 00088 roof = MSLPoint3d(fpt.xcoord(),fpt.ycoord(),thickness); 00089 pt = p->end(); 00090 pt--; // Moves to the last element 00091 p1 = MSLPoint3d(pt->xcoord(),pt->ycoord(),0.0); 00092 p4 = MSLPoint3d(pt->xcoord(),pt->ycoord(),thickness); 00093 pt = p->begin(); 00094 while (pt != p->end()) { 00095 p2 = MSLPoint3d(pt->xcoord(),pt->ycoord(),0.0); 00096 p3 = MSLPoint3d(pt->xcoord(),pt->ycoord(),thickness); 00097 00098 tl.push_back(MSLTriangle(p1,p2,p3)); 00099 tl.push_back(MSLTriangle(p4,p1,p3)); 00100 00101 if ((p3 != roof)&&(p4 != roof)) 00102 tl.push_back(MSLTriangle(roof,p4,p3)); 00103 00104 p1 = p2; p4 = p3; 00105 pt++; 00106 00107 } 00108 } 00109 00110 return tl; 00111 } 00112 00113