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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef ACG_POLYLINET_HH
00054 #define ACG_POLYLINET_HH
00055
00056
00057
00058 #include <vector>
00059 #include <iostream>
00060 #include "../../Config/ACGDefines.hh"
00061
00062
00063
00064
00065
00066 namespace ACG {
00067
00068
00069
00070
00071
00072
00080 template <class PointT>
00081 class PolyLineT
00082 {
00083 public:
00084
00085
00086 typedef PointT Point;
00087 typedef typename Point::value_type Scalar;
00088
00090 PolyLineT(bool _closed = false );
00091
00093 PolyLineT(const PolyLineT& _line);
00094
00096 ~PolyLineT() {}
00097
00098
00099 bool is_closed() const { return closed_;}
00100 void set_closed(const bool _c) { closed_ = _c;}
00101
00102
00103 unsigned int n_vertices() const { return points_.size(); }
00104
00105
00106 unsigned int n_edges() const { if( n_vertices() == 0) return 0;
00107 else return points_.size()-1 + (unsigned int)closed_; }
00108
00109
00110 void clear();
00111
00112
00113 void resize( unsigned int _n);
00114
00115
00116
00117 void add_point(const Point& _p);
00118
00119
00120 void insert_point(int _idx, const Point& _p);
00121
00122
00123 void delete_point(int _idx);
00124
00125
00126
00127 Point& point(unsigned int _i) { return points_[_i];}
00128 const Point& point(unsigned int _i) const { return points_[_i];}
00129
00130
00131 std::vector<Point>& points() { return points_;}
00132 const std::vector<Point>& points() const { return points_;}
00133
00134
00135 Point& front() { return points_[0];}
00136 const Point& front() const { return points_[0];}
00137
00138 Point& back() { return points_[n_vertices()-1];}
00139 const Point& back() const { return points_[n_vertices()-1];}
00140
00141
00142
00143
00144
00145
00146
00147
00148 Scalar length() const;
00149
00150
00151
00152 void subdivide( Scalar _largest );
00153 void collapse ( Scalar _smallest );
00154
00155 void subdivide_old( Scalar _largest );
00156 void collapse_old ( Scalar _smallest );
00157
00158
00159 void invert();
00160
00161
00162 void append(const PolyLineT<PointT>& _pl);
00163
00164
00165 void prepend(const PolyLineT<PointT>& _pl);
00166
00167
00168 void split_closed( unsigned int _split_idx);
00169
00170
00171 void split( unsigned int _split_idx, PolyLineT<PointT>& _new_pl);
00172
00173
00174 void smooth_uniform_laplace();
00175 void smooth_uniform_laplace2();
00176 void smooth_uniform_laplace3();
00177
00178
00179 template <class MeshT, class SpatialSearchT>
00180 void project_to_mesh( const MeshT& _mesh, SpatialSearchT * _ssearch = 0);
00181
00182
00183 template <class MeshT, class SpatialSearchT>
00184 void project_to_mesh( const std::vector<MeshT*> _mesh,
00185 std::vector<SpatialSearchT*>* _ssearch = 0);
00186
00187
00188 template <class MeshT, class SpatialSearchT>
00189 void resample_on_mesh_edges( MeshT& _mesh, SpatialSearchT * _ssearch = 0);
00190
00191 #ifdef USE_PHYSIM
00192
00193 template <class MeshT, class SpatialSearchT>
00194 void integrate_into_mesh( MeshT& _mesh, SpatialSearchT * _ssearch = 0);
00195 #endif
00196
00197
00198
00199 template <class MeshT>
00200 void add_boundary_points( MeshT& _mesh);
00201
00202
00203 template <class LineNodeT>
00204 LineNodeT* get_line_node( LineNodeT*& _line_node, int _mode = 0);
00205
00206 template <class LineNodeT>
00207 void set_line_node( LineNodeT*& _line_node, int _mode = 0);
00208
00209
00210 void print() const;
00211
00212
00213 void load( const char* _filename);
00214 void save( const char* _filename) const;
00215
00216
00217
00218
00219 void request_vertex_normals() { request_prop( ref_count_vnormals_ , vnormals_);}
00220 void request_vertex_colors() { request_prop( ref_count_vcolors_ , vcolors_ );}
00221 void request_vertex_scalars() { request_prop( ref_count_vscalars_ , vscalars_);}
00222 void request_vertex_selections() { request_prop( ref_count_vselections_, vselections_);}
00223 void request_vertex_vhandles() { request_prop( ref_count_vvhandles_ , vvhandles_);}
00224 void request_vertex_ehandles() { request_prop( ref_count_vehandles_ , vehandles_);}
00225 void request_vertex_fhandles() { request_prop( ref_count_vfhandles_ , vfhandles_);}
00226
00227 void request_edge_normals() { request_prop( ref_count_enormals_ , enormals_);}
00228 void request_edge_colors() { request_prop( ref_count_ecolors_ , ecolors_ );}
00229 void request_edge_scalars() { request_prop( ref_count_escalars_ , escalars_);}
00230 void request_edge_selections() { request_prop( ref_count_eselections_, eselections_);}
00231
00232
00233 void release_vertex_normals() { release_prop( ref_count_vnormals_ , vnormals_);}
00234 void release_vertex_colors() { release_prop( ref_count_vcolors_ , vcolors_ );}
00235 void release_vertex_scalars() { release_prop( ref_count_vscalars_ , vscalars_);}
00236 void release_vertex_selections() { release_prop( ref_count_vselections_, vselections_);}
00237 void release_vertex_vhandles() { release_prop( ref_count_vvhandles_ , vvhandles_);}
00238 void release_vertex_ehandles() { release_prop( ref_count_vehandles_ , vehandles_);}
00239 void release_vertex_fhandles() { release_prop( ref_count_vfhandles_ , vfhandles_);}
00240
00241 void release_edge_normals() { release_prop( ref_count_enormals_ , enormals_);}
00242 void release_edge_colors() { release_prop( ref_count_ecolors_ , ecolors_ );}
00243 void release_edge_scalars() { release_prop( ref_count_escalars_ , escalars_);}
00244 void release_edge_selections() { release_prop( ref_count_eselections_, eselections_);}
00245
00246
00247 bool vertex_normals_available() const {return bool(ref_count_vnormals_);}
00248 bool vertex_colors_available() const {return bool(ref_count_vcolors_);}
00249 bool vertex_scalars_available() const {return bool(ref_count_vscalars_);}
00250 bool vertex_selections_available() const {return bool(ref_count_vselections_);}
00251 bool vertex_vhandles_available() const {return bool(ref_count_vvhandles_);}
00252 bool vertex_ehandles_available() const {return bool(ref_count_vehandles_);}
00253 bool vertex_fhandles_available() const {return bool(ref_count_vfhandles_);}
00254
00255 bool edge_normals_available() const {return bool(ref_count_enormals_);}
00256 bool edge_colors_available() const {return bool(ref_count_ecolors_);}
00257 bool edge_scalars_available() const {return bool(ref_count_escalars_);}
00258 bool edge_selections_available() const {return bool(ref_count_eselections_);}
00259
00260
00261 Point& vertex_normal(unsigned int _i) { return vnormals_[_i];}
00262 const Point& vertex_normal(unsigned int _i) const { return vnormals_[_i];}
00263
00264 Point & vertex_color(unsigned int _i) { return vcolors_[_i];}
00265 const Point & vertex_color(unsigned int _i) const { return vcolors_[_i];}
00266
00267 Scalar& vertex_scalar(unsigned int _i) { return vscalars_[_i];}
00268 const Scalar& vertex_scalar(unsigned int _i) const { return vscalars_[_i];}
00269
00270 unsigned char& vertex_selection(unsigned int _i) {return vselections_[_i];}
00271 const unsigned char& vertex_selection(unsigned int _i) const {return vselections_[_i];}
00272
00273 int& vertex_vhandle(unsigned int _i) {return vvhandles_[_i];}
00274 const int& vertex_vhandle(unsigned int _i) const {return vvhandles_[_i];}
00275
00276 int& vertex_ehandle(unsigned int _i) {return vehandles_[_i];}
00277 const int& vertex_ehandle(unsigned int _i) const {return vehandles_[_i];}
00278
00279 int& vertex_fhandle(unsigned int _i) {return vfhandles_[_i];}
00280 const int& vertex_fhandle(unsigned int _i) const {return vfhandles_[_i];}
00281
00282 Point& edge_normal(unsigned int _i) { return enormals_[_i];}
00283 const Point& edge_normal(unsigned int _i) const { return enormals_[_i];}
00284
00285 Point & edge_color(unsigned int _i) { return ecolors_[_i];}
00286 const Point & edge_color(unsigned int _i) const { return ecolors_[_i];}
00287
00288 Scalar& edge_scalar(unsigned int _i) { return escalars_[_i];}
00289 const Scalar& edge_scalar(unsigned int _i) const { return escalars_[_i];}
00290
00291 unsigned char& edge_selection(unsigned int _i) {return eselections_[_i];}
00292 const unsigned char& edge_selection(unsigned int _i) const {return eselections_[_i];}
00293
00294
00295
00296
00297
00298 void copy_vertex_complete(const PolyLineT<PointT>& _pl, unsigned int _i, unsigned int _j);
00299
00300
00301
00302 void copy_edge_complete(const PolyLineT<PointT>& _pl, unsigned int _i, unsigned int _j);
00303
00304 private:
00305
00306 template <class MeshT, class SpatialSearchT>
00307 Point find_nearest_point( const MeshT& _mesh,
00308 const Point& _point,
00309 typename MeshT::FaceHandle &_fh,
00310 SpatialSearchT * _ssearch = 0,
00311 double* _dbest = 0);
00312
00313
00314 template <class PropT>
00315 void request_prop( unsigned int& _ref_count, PropT& _prop);
00316 template <class PropT>
00317 void release_prop( unsigned int& _ref_count, PropT& _prop);
00318
00319 template <class IPoint>
00320 bool plane_line_intersection( const IPoint& _p_plane,
00321 const IPoint& _n_plane,
00322 const IPoint& _p0,
00323 const IPoint& _p1,
00324 IPoint& _p_int);
00325
00326 template<class MeshT>
00327 void edge_points_in_segment( const MeshT& _mesh,
00328 const Point& _p0,
00329 const Point& _p1,
00330 const typename MeshT::FaceHandle _fh0,
00331 const typename MeshT::FaceHandle _fh1,
00332 std::vector<Point> & _points,
00333 std::vector<typename MeshT::EdgeHandle>& _ehandles );
00334
00335
00336 private:
00337
00338
00339 std::vector<Point> points_;
00340
00341
00342 bool closed_;
00343
00344
00345
00346
00347 std::vector<Point> vnormals_;
00348 std::vector<Point> vcolors_;
00349 std::vector<Scalar> vscalars_;
00350 std::vector<unsigned char> vselections_;
00351 std::vector<int> vvhandles_;
00352 std::vector<int> vehandles_;
00353 std::vector<int> vfhandles_;
00354
00355 std::vector<Point> enormals_;
00356 std::vector<Point> ecolors_;
00357 std::vector<Scalar> escalars_;
00358 std::vector<unsigned char> eselections_;
00359
00360
00361
00362 unsigned int ref_count_vnormals_;
00363 unsigned int ref_count_vcolors_;
00364 unsigned int ref_count_vscalars_;
00365 unsigned int ref_count_vselections_;
00366 unsigned int ref_count_vvhandles_;
00367 unsigned int ref_count_vehandles_;
00368 unsigned int ref_count_vfhandles_;
00369
00370 unsigned int ref_count_enormals_;
00371 unsigned int ref_count_ecolors_;
00372 unsigned int ref_count_escalars_;
00373 unsigned int ref_count_eselections_;
00374 };
00375
00376
00377
00378 }
00379
00380 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_POLYLINET_C)
00381 #define ACG_POLYLINET_TEMPLATES
00382 #include "PolyLineT.cc"
00383 #endif
00384
00385 #endif // ACG_POLYLINET_HH defined
00386
00387