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/CRenderizable.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 MRPTDLLIMPEXP CSetOfLines;
00043
00044
00045 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CSetOfLines, CRenderizable )
00046
00047
00048
00049
00050 class MRPTDLLIMPEXP CSetOfLines : public CRenderizable
00051 {
00052 DEFINE_SERIALIZABLE( CSetOfLines )
00053 protected:
00054 std::vector<TSegment3D> mSegments;
00055 float mLineWidth;
00056
00057 public:
00058
00059
00060
00061 inline void clear() {
00062 mSegments.clear();
00063 }
00064
00065
00066
00067 inline void setLineWidth(float w) {
00068 mLineWidth=w;
00069 }
00070
00071
00072
00073 float getLineWidth() const {
00074 return mLineWidth;
00075 }
00076
00077
00078
00079 inline void appendLine(const mrpt::math::TSegment3D &sgm) {
00080 mSegments.push_back(sgm);
00081 }
00082
00083
00084
00085 inline void appendLine(float x0,float y0,float z0,float x1,float y1,float z1) {
00086 appendLine(TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
00087 }
00088
00089
00090
00091
00092 template<class T> inline void appendLines(const T &sgms) {
00093 mSegments.insert(mSegments.end(),sgms.begin(),sgms.end());
00094 }
00095
00096
00097
00098
00099 template<class T_it> inline void appendLines(const T_it &begin,const T_it &end) {
00100 mSegments.reserve(mSegments.size()+(end-begin));
00101 mSegments.insert(mSegments.end(),begin,end);
00102 }
00103
00104
00105
00106
00107 void resize(size_t nLines) {
00108 mSegments.resize(nLines);
00109 }
00110
00111
00112
00113
00114 void reserve(size_t r) {
00115 mSegments.reserve(r);
00116 }
00117
00118
00119
00120 template<class T,class U> inline void appendLine(T p0,U p1) {
00121 appendLine(p0.x,p0.y,p0.z,p1.x,p1.y,p1.z);
00122 }
00123
00124
00125
00126 inline size_t getLineCount() const {
00127 return mSegments.size();
00128 }
00129
00130
00131
00132
00133 void setLineByIndex(size_t index,const TSegment3D &segm);
00134
00135
00136
00137
00138 inline void setLineByIndex(size_t index,float x0,float y0,float z0,float x1,float y1,float z1) {
00139 setLineByIndex(index,TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
00140 }
00141
00142
00143
00144 inline static CSetOfLinesPtr Create(const std::vector<TSegment3D> &sgms) {
00145 return CSetOfLinesPtr(new CSetOfLines(sgms));
00146 }
00147
00148
00149 void render() const;
00150
00151
00152
00153
00154
00155 typedef std::vector<TSegment3D>::const_iterator const_iterator;
00156
00157
00158
00159 typedef std::vector<TSegment3D>::const_reverse_iterator const_reverse_iterator;
00160
00161
00162
00163
00164 inline const_iterator begin() const {
00165 return mSegments.begin();
00166 }
00167
00168
00169
00170
00171 inline const_iterator end() const {
00172 return mSegments.end();
00173 }
00174
00175
00176
00177
00178 inline const_reverse_iterator rbegin() const {
00179 return mSegments.rbegin();
00180 }
00181
00182
00183
00184
00185 inline const_reverse_iterator rend() const {
00186 return mSegments.rend();
00187 }
00188
00189 private:
00190
00191
00192 CSetOfLines():mSegments(),mLineWidth(1.0) {}
00193
00194
00195
00196 CSetOfLines(const std::vector<TSegment3D> &sgms):mSegments(sgms),mLineWidth(1.0) {}
00197
00198
00199
00200 virtual ~CSetOfLines() { }
00201 };
00202
00203
00204
00205 template<class T> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const T &s) {
00206 l->appendLines(s.begin(),s.end());
00207 return l;
00208 }
00209
00210
00211
00212 template<> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const mrpt::math::TSegment3D &s) {
00213 l->appendLine(s);
00214 return l;
00215 }
00216 }
00217
00218 }
00219
00220
00221 #endif