2 #ifndef vgl_pointset_3d_h_ 3 #define vgl_pointset_3d_h_ 21 # include <vcl_msvc_warnings.h> 87 std::vector< Type >
const&
scalars)
92 std::vector< Type >
const&
scalars)
100 for(
unsigned i = 0; i<
npts; ++i){
101 if(!this->has_normals_&& !this->has_scalars_)
103 else if(!this->has_scalars_)
105 else if(!this->has_normals_)
113 if(i>=static_cast<unsigned>(
points_.size()))
return false;
114 points_[i].set(
p.x(),
p.y(),
p.z());
return true;
133 template <
class Type>
135 unsigned n = pointset.
npts();
136 if(n != this->npts())
138 std::vector<vgl_point_3d<Type> > pts = pointset.
points();
139 for(
unsigned i =0; i<n; ++i)
140 if(pts[i] != points_[i])
145 if(static_cast<unsigned>(normals_.size()) != n)
147 std::vector<vgl_vector_3d<Type> > normals = pointset.
normals();
148 for(
unsigned i =0; i<n; ++i)
149 if(normals[i] != normals_[i])
155 if(static_cast<unsigned>(scalars_.size()) != n)
157 std::vector< Type > scalars = pointset.
scalars();
158 for(
unsigned i =0; i<n; ++i)
159 if(scalars[i] != scalars_[i])
165 template <
class Type>
168 std::cout <<
"Bad ostream in write vgl_pointset_3d to stream\n";
171 std::vector<vgl_point_3d<Type> > pts = ptset.
points();
173 for(
unsigned i =0; i<static_cast<unsigned>(pts.size()); i++){
175 ostr << p.
x() <<
',' << p.
y() <<
',' << p.
z() <<
'\n';
178 std::vector< Type > scalars = ptset.
scalars();
179 for(
unsigned i =0; i<static_cast<unsigned>(pts.size()); i++){
181 Type sc = scalars[i];
182 ostr << p.
x() <<
',' << p.
y() <<
',' << p.
z()<<
',' << sc <<
'\n';
185 std::vector<vgl_vector_3d<Type> > normals = ptset.
normals();
186 for(
unsigned i =0; i<static_cast<unsigned>(pts.size()); i++){
189 ostr << p.
x() <<
',' << p.
y() <<
',' << p.
z()<<
',' << n.
x() <<
',' << n.
y() <<
',' << n.
z() <<
'\n';
192 std::vector< Type > scalars = ptset.
scalars();
193 std::vector<vgl_vector_3d<Type> > normals = ptset.
normals();
194 for(
unsigned i =0; i<static_cast<unsigned>(pts.size()); i++){
197 Type sc = scalars[i];
198 ostr << p.
x() <<
',' << p.
y() <<
',' << p.
z()<<
',' << n.
x() <<
',' << n.
y() <<
',' << n.
z() <<
',' << sc <<
'\n';
204 template <
class Type>
207 std::cout <<
"Bad istream in read vgl_pointset_3d from stream\n";
210 std::vector<vgl_point_3d<Type> > pts;
211 std::vector<vgl_vector_3d<Type> > normals;
212 std::vector<Type > scalars;
214 bool has_normals =
false;
215 bool has_scalars =
false;
221 bool first_line =
true;
222 while(istr.getline(buf,100)){
226 unsigned comma_count = 0;
227 for(
unsigned i =0; i<100&&!done; ++i){
229 if(c ==
'\0'||c ==
'\n'){
233 buf_str.push_back(c);
238 has_scalars = (comma_count == 3 || comma_count == 6) ;
239 has_normals = (comma_count == 5 || comma_count == 6) ;
244 for(
unsigned i =0; i<100&&!done; ++i){
246 if(c ==
'\0'||c ==
'\n'){
250 buf_str.push_back(c);
254 std::stringstream isstr(buf_str);
255 isstr >>std::noskipws;
257 Type x, y, z, nx, ny, nz, sc;
260 if(!(c==
','||c==
' ')){
261 std::cout <<
"stream parse error\n";
265 if(!(c==
','||c==
' ')){
266 std::cout <<
"stream parse error\n";
269 if(!has_normals&&!has_scalars)
271 else if(has_normals || has_scalars){
273 if(!(c==
','||c==
' ')){
274 std::cout <<
"stream parse error\n";
278 if(has_normals&&!has_scalars){
280 if(!(c==
','||c==
' ')){
281 std::cout <<
"stream parse error\n";
285 if(!(c==
','||c==
' ')){
286 std::cout <<
"stream parse error\n";
290 }
else if(has_scalars&& !has_normals)
292 else if( has_scalars && has_normals){
294 if(!(c==
','||c==
' ')){
295 std::cout <<
"stream parse error\n";
299 if(!(c==
','||c==
' ')){
300 std::cout <<
"stream parse error\n";
304 if(!(c==
','||c==
' ')){
305 std::cout <<
"stream parse error\n";
314 normals.push_back(n);
317 scalars.push_back(sc);
319 if(!has_normals&&has_scalars){
322 }
else if(has_normals&&!has_scalars){
325 }
else if(has_scalars&&has_normals){
333 #endif // vgl_pointset_3d_h_ std::vector< vgl_vector_3d< Type > > normals() const
vgl_point_3d< Type > p(unsigned i) const
void add_point_with_normal(vgl_point_3d< Type > const &p, vgl_vector_3d< Type > const &normal)
incrementally grow points and normals duplicate pairs are allowed.
void append_pointset(vgl_pointset_3d< Type > const &ptset)
bool set_normal(unsigned i, vgl_vector_3d< Type > const &n)
Represents a cartesian 3D point.
std::vector< vgl_vector_3d< Type > > normals_
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
bool set_scalar(unsigned i, Type sc)
vgl_pointset_3d(std::vector< vgl_point_3d< Type > > points, std::vector< vgl_vector_3d< Type > > normals)
vgl_pointset_3d(std::vector< vgl_point_3d< Type > > points)
Construct from a list.
bool operator==(const vgl_pointset_3d< Type > &spl) const
Equality operator.
vgl_pointset_3d(std::vector< vgl_point_3d< Type > > points, std::vector< Type > scalars)
a point in 3D nonhomogeneous space
bool has_normals() const
accessors.
Type sc(unsigned i) const
bool has_normals_
members.
std::vector< vgl_point_3d< Type > > points_
void add_point(vgl_point_3d< Type > const &p)
incrementally grow points, duplicate points are allowed.
void add_point_with_normal_and_scalar(vgl_point_3d< Type > const &p, vgl_vector_3d< Type > const &normal, Type sc)
std::vector< Type > scalars_
void set_points(std::vector< vgl_point_3d< Type > > const &points)
void set_points_with_normals_and_scalars(std::vector< vgl_point_3d< Type > > const &points, std::vector< vgl_vector_3d< Type > > const &normals, std::vector< Type > const &scalars)
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
std::vector< Type > scalars() const
std::vector< vgl_point_3d< Type > > points() const
void set_points_with_normals(std::vector< vgl_point_3d< Type > > const &points, std::vector< vgl_vector_3d< Type > > const &normals)
void set_points_with_scalars(std::vector< vgl_point_3d< Type > > const &points, std::vector< Type > const &scalars)
bool set_point(unsigned i, vgl_point_3d< Type > const &p)
void add_point_with_scalar(vgl_point_3d< Type > const &p, Type sc)
vgl_pointset_3d()
Default constructor.
bool operator!=(vgl_pointset_3d< Type >const &spl) const
vgl_vector_3d< Type > n(unsigned i) const
vgl_pointset_3d(std::vector< vgl_point_3d< Type > > points, std::vector< vgl_vector_3d< Type > > normals, std::vector< Type > scalars)