00001 #include "SIGEL_Robot/SIG_Geometry.h"
00002 #include "SIGEL_Robot/SIG_Robot.h"
00003
00004 namespace SIGEL_Robot {
00005 void SIG_Geometry::addPolygon (SIG_Polygon *p)
00006 {
00007 if (polygons.count () >= polygons.size ()) {
00008 int newsize = polygons.size () * 2;
00009 if (newsize < 16) newsize = 16;
00010 polygons.resize (newsize);
00011 }
00012 polygons.insert( polygons.count(), p );
00013 }
00014
00015 SIG_Polygon const *SIG_Geometry::getPolygon (int i) const
00016 {
00017 return polygons [i];
00018 }
00019
00020 SIG_Geometry::SIG_Geometry (void)
00021 {
00022 }
00023
00024 SIG_Geometry::SIG_Geometry (const SIG_Geometry *geom)
00025 {
00026 vertices.resize (geom->vertices.count ());
00027 for (int i = 0; i < geom->vertices.count (); i++)
00028 vertices.insert (i, new DL_vector (geom->vertices.at (i)));
00029
00030 polygons.resize (geom->polygons.count ());
00031 for (int j = 0; j < geom->polygons.count (); j++)
00032 polygons.insert (j, new SIG_Polygon (this, geom->polygons.at (j)));
00033 }
00034
00035 SIG_Geometry::SIG_Geometry (QTextStream & tx)
00036 {
00037 QString tmpstr;
00038 int zahl;
00039
00040 tx >> tmpstr;
00041 if (tmpstr != "Geometry")
00042
00043 ;
00044
00045 tx >> zahl;
00046 vertices.resize (zahl);
00047 for (int i = 0; i < zahl; i++) {
00048 DL_vector d = SIG_Robot::streamToVector (tx);
00049 vertices.insert (i, new DL_vector (&d));
00050 }
00051
00052 tx >> zahl;
00053 polygons.resize (zahl);
00054 for (int i = 0; i < zahl; i++)
00055 polygons.insert (i, new SIG_Polygon (this, tx));
00056 }
00057
00058 SIG_Geometry::~SIG_Geometry (void)
00059 {
00060 polygons.setAutoDelete (TRUE);
00061 vertices.setAutoDelete (TRUE);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 }
00076
00077 int SIG_Geometry::getOrAddVertex (DL_vector vertex)
00078 {
00079 int appending_position = vertices.count ();
00080 for (int i = 0; i < appending_position; i++) {
00081 if (vertex.equal (vertices [i]))
00082 return i;
00083 }
00084 if (vertices.count () >= vertices.size ()) {
00085 int newsize = vertices.size () * 2;
00086 if (newsize < 16) newsize = 16;
00087 vertices.resize (newsize);
00088 }
00089 vertices.insert (appending_position, new DL_vector (&vertex));
00090 return appending_position;
00091 }
00092
00093 QVector<DL_vector> const & SIG_Geometry::getVertices (void) const
00094 {
00095 return vertices;
00096 }
00097
00098 int SIG_Geometry::getNumVertices (void) const
00099 {
00100 return vertices.count ();
00101 }
00102
00103 DL_vector SIG_Geometry::getVertex (int i) const
00104 {
00105 return *vertices.at (i);
00106 }
00107
00108 int SIG_Geometry::getNumPolygons (void) const
00109 {
00110 return polygons.count ();
00111 }
00112
00113 void SIG_Geometry::translate (DL_vector dir)
00114 {
00115 int nrofverts = vertices.count ();
00116 for (int i = 0; i < nrofverts; i++) {
00117 vertices [i]->plusis (&dir);
00118 }
00119 }
00120
00121 void SIG_Geometry::rotate (DL_matrix mat)
00122 {
00123 int nrofverts = vertices.count ();
00124 for (int i = 0; i < nrofverts; i++) {
00125 DL_vector d (vertices [i]);
00126 mat.times (&d, vertices [i]);
00127 }
00128 }
00129
00130 void SIG_Geometry::writeToFileTransfer (QTextStream & tx) const
00131 {
00132 int nrofverts = vertices.count ();
00133 tx << "Geometry "
00134 << vertices.count () << ' ';
00135 for (int i = 0; i < nrofverts; i++)
00136 SIG_Robot::vectorToStream (tx, *vertices [i]);
00137
00138 int nrofpolys = polygons.count ();
00139 tx << polygons.count () << '\n';
00140 for (int i = 0; i < nrofpolys; i++)
00141 polygons [i]->writeToFileTransfer (tx);
00142 }
00143 }