#ifndef __JPOLYLINE3D__ #define __JPOLYLINE3D__ #include #include #include #include "JGeometry3D/JRotation3D.hh" #include "JGeometry3D/JPosition3D.hh" /** * \author mjongen */ namespace JGEOMETRY3D {} namespace JPP { using namespace JGEOMETRY3D; } namespace JGEOMETRY3D { /** Data structure for polyline in three dimensions. A polyline is a series of connected line segments. **/ class JPolyline3D : public std::vector { public: /// default constructor JPolyline3D() {} /// Constructor with given size JPolyline3D( int size ) { if(size>0) resize(size) ; } /** * Get polyline. * * \return polyline */ const JPolyline3D& getPolyline() const { return static_cast(*this); } /** * Get polyline. * * \return polyline */ JPolyline3D& getPolyline() { return static_cast(*this); } /** * Transform all vertices * * \param T matrix */ JPolyline3D& transform(const JMatrix3D& T) { for( iterator it=begin(); it!=end() ; ++it ) it->transform(T) ; return *this; } /** * Rotate all vertices * * \param R rotation matrix */ JPolyline3D& rotate(const JRotation3D& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R); return *this; } /** * Rotate back all vertices. * * \param R rotation matrix */ JPolyline3D& rotate_back(const JRotation3D& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ; return *this; } /** * Rotate all vertices around X-axis. * * \param R rotation matrix */ JPolyline3D& rotate(const JRotation3X& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R); return *this; } /** * Rotate all vertices back around X-axis. * * \param R rotation matrix */ JPolyline3D& rotate_back(const JRotation3X& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ; return *this; } /** * Rotate all vertices around Y-axis. * * \param R rotation matrix */ JPolyline3D& rotate(const JRotation3Y& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R); return *this; } /** * Rotate all vertices back around Y-axis. * * \param R rotation matrix */ JPolyline3D& rotate_back(const JRotation3Y& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ; return *this; } /** * Rotate all vertices around Z-axis. * * \param R rotation matrix */ JPolyline3D& rotate(const JRotation3Z& R){ for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R); return *this; } /** * Rotate all vertices back around Z-axis. * * \param R rotation matrix */ JPolyline3D& rotate_back(const JRotation3Z& R) { for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ; return *this; } /** * Transform all vertices of the polyline with a rotation and offset. * See the corresponding function in JPosition3D for more information * * \param R rotation matrix * \param pos position of origin (after rotation) */ void transform(const JRotation3D& R, const JVector3D& pos) { for( iterator it=begin(); it!=end() ; ++it ) it->transform(R,pos) ; } /** * Transform back all vertices of the polyline. * * \param R rotation matrix * \param pos polyline of origin (before rotation) */ void transform_back(const JRotation3D& R, const JVector3D& pos) { for( iterator it=begin(); it!=end() ; ++it ) it->transform_back(R,pos) ; } /** * Read polyline from input. * * \param in input stream * \param polyline polyline * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JPolyline3D& polyline) { int n = -1 ; in >> n ; polyline.resize(n) ; for( iterator it=polyline.begin(); it!=polyline.end() ; ++it ) { in >> *it ; } return in; } /** * Write polyline to output. * * \param out output stream * \param polyline polyline * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JPolyline3D& polyline) { out << polyline.size() ; for( const_iterator it=polyline.begin(); it!=polyline.end() ; ++it ) { out << *it ; } return out; } } ; } #endif