00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef opengl_CSetOfLines_H
00030 #define opengl_CSetOfLines_H
00031
00032 #include <mrpt/opengl/CRenderizableDisplayList.h>
00033 #include <mrpt/math/lightweight_geom_data.h>
00034 #include <mrpt/utils/stl_extensions.h>
00035
00036 namespace mrpt
00037 {
00038 namespace opengl
00039 {
00040 using mrpt::math::TPoint3D;
00041 using mrpt::math::TSegment3D;
00042 class OPENGL_IMPEXP CSetOfLines;
00043
00044
00045 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfLines, CRenderizableDisplayList, OPENGL_IMPEXP )
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class OPENGL_IMPEXP CSetOfLines : public CRenderizableDisplayList
00059 {
00060 DEFINE_SERIALIZABLE( CSetOfLines )
00061 protected:
00062 std::vector<TSegment3D> mSegments;
00063 float mLineWidth;
00064
00065 public:
00066
00067
00068
00069 inline void clear() {
00070 mSegments.clear();
00071 CRenderizableDisplayList::notifyChange();
00072 }
00073
00074
00075
00076 inline void setLineWidth(float w) {
00077 mLineWidth=w;
00078 CRenderizableDisplayList::notifyChange();
00079 }
00080
00081
00082
00083 float getLineWidth() const {
00084 return mLineWidth;
00085 }
00086
00087
00088
00089 inline void appendLine(const mrpt::math::TSegment3D &sgm) {
00090 mSegments.push_back(sgm);
00091 CRenderizableDisplayList::notifyChange();
00092 }
00093
00094
00095
00096 inline void appendLine(float x0,float y0,float z0,float x1,float y1,float z1) {
00097 appendLine(TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
00098 CRenderizableDisplayList::notifyChange();
00099 }
00100
00101
00102
00103
00104 template<class T> inline void appendLines(const T &sgms) {
00105 mSegments.insert(mSegments.end(),sgms.begin(),sgms.end());
00106 CRenderizableDisplayList::notifyChange();
00107 }
00108
00109
00110
00111
00112 template<class T_it> inline void appendLines(const T_it &begin,const T_it &end) {
00113 mSegments.reserve(mSegments.size()+(end-begin));
00114 mSegments.insert(mSegments.end(),begin,end);
00115 CRenderizableDisplayList::notifyChange();
00116 }
00117
00118
00119
00120
00121 void resize(size_t nLines) {
00122 mSegments.resize(nLines);
00123 CRenderizableDisplayList::notifyChange();
00124 }
00125
00126
00127
00128
00129 void reserve(size_t r) {
00130 mSegments.reserve(r);
00131 CRenderizableDisplayList::notifyChange();
00132 }
00133
00134
00135
00136 template<class T,class U> inline void appendLine(T p0,U p1) {
00137 appendLine(p0.x,p0.y,p0.z,p1.x,p1.y,p1.z);
00138 CRenderizableDisplayList::notifyChange();
00139 }
00140
00141
00142
00143 inline size_t getLineCount() const {
00144 return mSegments.size();
00145 }
00146
00147
00148
00149
00150 void setLineByIndex(size_t index,const TSegment3D &segm);
00151
00152
00153
00154
00155 inline void setLineByIndex(size_t index,double x0,double y0,double z0,double x1,double y1,double z1) {
00156 setLineByIndex(index,TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
00157 CRenderizableDisplayList::notifyChange();
00158 }
00159
00160
00161
00162
00163 inline void getLineByIndex(size_t index,double &x0,double &y0,double &z0,double &x1,double &y1,double &z1) const {
00164 ASSERT_(index<mSegments.size())
00165 x0 = mSegments[index].point1.x;
00166 y0 = mSegments[index].point1.y;
00167 z0 = mSegments[index].point1.z;
00168 x1 = mSegments[index].point2.x;
00169 y1 = mSegments[index].point2.y;
00170 z1 = mSegments[index].point2.z;
00171 }
00172
00173
00174
00175 inline static CSetOfLinesPtr Create(const std::vector<TSegment3D> &sgms) {
00176 return CSetOfLinesPtr(new CSetOfLines(sgms));
00177 }
00178
00179
00180 void render_dl() const;
00181
00182
00183 typedef std::vector<TSegment3D>::iterator iterator;
00184 typedef std::vector<TSegment3D>::reverse_iterator reverse_iterator;
00185
00186
00187
00188
00189 typedef std::vector<TSegment3D>::const_iterator const_iterator;
00190
00191
00192
00193 typedef std::vector<TSegment3D>::const_reverse_iterator const_reverse_iterator;
00194
00195
00196
00197
00198 inline const_iterator begin() const {
00199 return mSegments.begin();
00200 }
00201 inline iterator begin() { CRenderizableDisplayList::notifyChange(); return mSegments.begin(); }
00202
00203
00204
00205
00206 inline const_iterator end() const {
00207 return mSegments.end();
00208 }
00209 inline iterator end() { CRenderizableDisplayList::notifyChange(); return mSegments.end(); }
00210
00211
00212
00213
00214 inline const_reverse_iterator rbegin() const {
00215 return mSegments.rbegin();
00216 }
00217
00218
00219
00220
00221 inline const_reverse_iterator rend() const {
00222 return mSegments.rend();
00223 }
00224
00225 private:
00226
00227
00228 CSetOfLines():mSegments(),mLineWidth(1.0) {}
00229
00230
00231
00232 CSetOfLines(const std::vector<TSegment3D> &sgms):mSegments(sgms),mLineWidth(1.0) {}
00233
00234
00235
00236 virtual ~CSetOfLines() { }
00237 };
00238
00239
00240
00241 template<class T> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const T &s) {
00242 l->appendLines(s.begin(),s.end());
00243 return l;
00244 }
00245
00246
00247
00248 template<> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const mrpt::math::TSegment3D &s) {
00249 l->appendLine(s);
00250 return l;
00251 }
00252 }
00253
00254 }
00255
00256
00257 #endif