Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JPolyline3D.hh
Go to the documentation of this file.
1#ifndef __JPOLYLINE3D__
2#define __JPOLYLINE3D__
3
4#include <istream>
5#include <ostream>
6#include <vector>
7
10
11/**
12 * \author mjongen
13 */
14
15namespace JGEOMETRY3D {}
16namespace JPP { using namespace JGEOMETRY3D; }
17
18namespace JGEOMETRY3D {
19
20 /**
21 Data structure for polyline in three dimensions.
22
23 A polyline is a series of connected line segments.
24 **/
25 class JPolyline3D : public std::vector<JGEOMETRY3D::JPosition3D> {
26 public:
27
28 /// default constructor
30
31
32 /// Constructor with given size
33 JPolyline3D( int size ) {
34 if(size>0) resize(size) ;
35 }
36
37
38 /**
39 * Get polyline.
40 *
41 * \return polyline
42 */
43 const JPolyline3D& getPolyline() const {
44 return static_cast<const JPolyline3D&>(*this);
45 }
46
47 /**
48 * Get polyline.
49 *
50 * \return polyline
51 */
53 {
54 return static_cast<JPolyline3D&>(*this);
55 }
56
57 /**
58 * Transform all vertices
59 *
60 * \param T matrix
61 */
63 for( iterator it=begin(); it!=end() ; ++it ) it->transform(T) ;
64 return *this;
65 }
66
67 /**
68 * Rotate all vertices
69 *
70 * \param R rotation matrix
71 */
73 {
74 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
75 return *this;
76 }
77
78 /**
79 * Rotate back all vertices.
80 *
81 * \param R rotation matrix
82 */
84 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
85 return *this;
86 }
87
88 /**
89 * Rotate all vertices around X-axis.
90 *
91 * \param R rotation matrix
92 */
94 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
95 return *this;
96 }
97
98 /**
99 * Rotate all vertices back around X-axis.
100 *
101 * \param R rotation matrix
102 */
104 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
105 return *this;
106 }
107
108
109 /**
110 * Rotate all vertices around Y-axis.
111 *
112 * \param R rotation matrix
113 */
115 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
116 return *this;
117 }
118
119
120 /**
121 * Rotate all vertices back around Y-axis.
122 *
123 * \param R rotation matrix
124 */
126 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
127 return *this;
128 }
129
130 /**
131 * Rotate all vertices around Z-axis.
132 *
133 * \param R rotation matrix
134 */
136 for( iterator it=begin(); it!=end() ; ++it ) it->rotate(R);
137 return *this;
138 }
139
140 /**
141 * Rotate all vertices back around Z-axis.
142 *
143 * \param R rotation matrix
144 */
146 for( iterator it=begin(); it!=end() ; ++it ) it->rotate_back(R) ;
147 return *this;
148 }
149
150 /**
151 * Transform all vertices of the polyline with a rotation and offset.
152 * See the corresponding function in JPosition3D for more information
153 *
154 * \param R rotation matrix
155 * \param pos position of origin (after rotation)
156 */
157 void transform(const JRotation3D& R, const JVector3D& pos) {
158 for( iterator it=begin(); it!=end() ; ++it ) it->transform(R,pos) ;
159 }
160
161 /**
162 * Transform back all vertices of the polyline.
163 *
164 * \param R rotation matrix
165 * \param pos polyline of origin (before rotation)
166 */
167 void transform_back(const JRotation3D& R, const JVector3D& pos) {
168 for( iterator it=begin(); it!=end() ; ++it ) it->transform_back(R,pos) ;
169 }
170
171
172 /**
173 * Read polyline from input.
174 *
175 * \param in input stream
176 * \param polyline polyline
177 * \return input stream
178 */
179 friend inline std::istream& operator>>(std::istream& in, JPolyline3D& polyline) {
180 int n = -1 ;
181 in >> n ;
182 polyline.resize(n) ;
183 for( iterator it=polyline.begin(); it!=polyline.end() ; ++it ) {
184 in >> *it ;
185 }
186 return in;
187 }
188
189 /**
190 * Write polyline to output.
191 *
192 * \param out output stream
193 * \param polyline polyline
194 * \return output stream
195 */
196 friend inline std::ostream& operator<<(std::ostream& out, const JPolyline3D& polyline)
197 {
198 out << polyline.size() ;
199 for( const_iterator it=polyline.begin(); it!=polyline.end() ; ++it ) {
200 out << *it ;
201 }
202 return out;
203 }
204 } ;
205
206
207
208}
209
210#endif
Data structure for polyline in three dimensions.
JPolyline3D & getPolyline()
Get polyline.
JPolyline3D(int size)
Constructor with given size.
JPolyline3D & rotate(const JRotation3D &R)
Rotate all vertices.
JPolyline3D & rotate(const JRotation3Y &R)
Rotate all vertices around Y-axis.
void transform_back(const JRotation3D &R, const JVector3D &pos)
Transform back all vertices of the polyline.
JPolyline3D & rotate_back(const JRotation3Y &R)
Rotate all vertices back around Y-axis.
JPolyline3D & rotate(const JRotation3X &R)
Rotate all vertices around X-axis.
JPolyline3D & rotate_back(const JRotation3X &R)
Rotate all vertices back around X-axis.
const JPolyline3D & getPolyline() const
Get polyline.
JPolyline3D & rotate(const JRotation3Z &R)
Rotate all vertices around Z-axis.
JPolyline3D()
default constructor
friend std::ostream & operator<<(std::ostream &out, const JPolyline3D &polyline)
Write polyline to output.
JPolyline3D & transform(const JMatrix3D &T)
Transform all vertices.
JPolyline3D & rotate_back(const JRotation3D &R)
Rotate back all vertices.
friend std::istream & operator>>(std::istream &in, JPolyline3D &polyline)
Read polyline from input.
JPolyline3D & rotate_back(const JRotation3Z &R)
Rotate all vertices back around Z-axis.
void transform(const JRotation3D &R, const JVector3D &pos)
Transform all vertices of the polyline with a rotation and offset.
Rotation around X-axis.
Rotation around Y-axis.
Rotation around Z-axis.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).