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 class OPENGL_IMPEXP CSetOfLines : public CRenderizableDisplayList
00058 {
00059 DEFINE_SERIALIZABLE( CSetOfLines )
00060 protected:
00061 std::vector<TSegment3D> mSegments;
00062 float mLineWidth;
00063
00064 public:
00065
00066
00067
00068 inline void clear() {
00069 mSegments.clear();
00070 CRenderizableDisplayList::notifyChange();
00071 }
00072
00073
00074
00075 inline void setLineWidth(float w) {
00076 mLineWidth=w;
00077 CRenderizableDisplayList::notifyChange();
00078 }
00079
00080
00081
00082 float getLineWidth() const {
00083 return mLineWidth;
00084 }
00085
00086
00087
00088 inline void appendLine(const mrpt::math::TSegment3D &sgm) {
00089 mSegments.push_back(sgm);
00090 CRenderizableDisplayList::notifyChange();
00091 }
00092
00093
00094
00095 inline void appendLine(float x0,float y0,float z0,float x1,float y1,float z1) {
00096 appendLine(TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
00097 CRenderizableDisplayList::notifyChange();
00098 }
00099
00100
00101
00102
00103 template<class T> inline void appendLines(const T &sgms) {
00104 mSegments.insert(mSegments.end(),sgms.begin(),sgms.end());
00105 CRenderizableDisplayList::notifyChange();
00106 }
00107
00108
00109
00110
00111 template<class T_it> inline void appendLines(const T_it &begin,const T_it &end) {
00112 mSegments.reserve(mSegments.size()+(end-begin));
00113 mSegments.insert(mSegments.end(),begin,end);
00114 CRenderizableDisplayList::notifyChange();
00115 }
00116
00117
00118
00119
00120 void resize(size_t nLines) {
00121 mSegments.resize(nLines);
00122 CRenderizableDisplayList::notifyChange();
00123 }
00124
00125
00126
00127
00128 void reserve(size_t r) {
00129 mSegments.reserve(r);
00130 CRenderizableDisplayList::notifyChange();
00131 }
00132
00133
00134
00135 template<class T,class U> inline void appendLine(T p0,U p1) {
00136 appendLine(p0.x,p0.y,p0.z,p1.x,p1.y,p1.z);
00137 CRenderizableDisplayList::notifyChange();
00138 }
00139
00140
00141
00142 inline size_t getLineCount() const {
00143 return mSegments.size();
00144 }
00145
00146
00147
00148
00149 void setLineByIndex(size_t index,const TSegment3D &segm);
00150
00151
00152
00153
00154 inline void setLineByIndex(size_t index,double x0,double y0,double z0,double x1,double y1,double z1) {
00155 setLineByIndex(index,TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
00156 CRenderizableDisplayList::notifyChange();
00157 }
00158
00159
00160
00161
00162 inline void getLineByIndex(size_t index,double &x0,double &y0,double &z0,double &x1,double &y1,double &z1) const {
00163 ASSERT_(index<mSegments.size())
00164 x0 = mSegments[index].point1.x;
00165 y0 = mSegments[index].point1.y;
00166 z0 = mSegments[index].point1.z;
00167 x1 = mSegments[index].point2.x;
00168 y1 = mSegments[index].point2.y;
00169 z1 = mSegments[index].point2.z;
00170 }
00171
00172
00173
00174 inline static CSetOfLinesPtr Create(const std::vector<TSegment3D> &sgms) {
00175 return CSetOfLinesPtr(new CSetOfLines(sgms));
00176 }
00177
00178
00179 void render_dl() const;
00180
00181
00182 typedef std::vector<TSegment3D>::iterator iterator;
00183 typedef std::vector<TSegment3D>::reverse_iterator reverse_iterator;
00184
00185
00186
00187
00188 typedef std::vector<TSegment3D>::const_iterator const_iterator;
00189
00190
00191
00192 typedef std::vector<TSegment3D>::const_reverse_iterator const_reverse_iterator;
00193
00194
00195
00196
00197 inline const_iterator begin() const {
00198 return mSegments.begin();
00199 }
00200 inline iterator begin() { CRenderizableDisplayList::notifyChange(); return mSegments.begin(); }
00201
00202
00203
00204
00205 inline const_iterator end() const {
00206 return mSegments.end();
00207 }
00208 inline iterator end() { CRenderizableDisplayList::notifyChange(); return mSegments.end(); }
00209
00210
00211
00212
00213 inline const_reverse_iterator rbegin() const {
00214 return mSegments.rbegin();
00215 }
00216
00217
00218
00219
00220 inline const_reverse_iterator rend() const {
00221 return mSegments.rend();
00222 }
00223
00224 private:
00225
00226
00227 CSetOfLines():mSegments(),mLineWidth(1.0) {}
00228
00229
00230
00231 CSetOfLines(const std::vector<TSegment3D> &sgms):mSegments(sgms),mLineWidth(1.0) {}
00232
00233
00234
00235 virtual ~CSetOfLines() { }
00236 };
00237
00238
00239
00240 template<class T> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const T &s) {
00241 l->appendLines(s.begin(),s.end());
00242 return l;
00243 }
00244
00245
00246
00247 template<> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const mrpt::math::TSegment3D &s) {
00248 l->appendLine(s);
00249 return l;
00250 }
00251 }
00252
00253 }
00254
00255
00256 #endif