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 #ifndef OPENMESH_ATTRIBKERNEL_HH
00043 #define OPENMESH_ATTRIBKERNEL_HH
00044
00045
00046
00047
00048 #include <OpenMesh/Core/Mesh/Attributes.hh>
00049 #include <OpenMesh/Core/Utils/GenProg.hh>
00050 #include <OpenMesh/Core/Utils/vector_traits.hh>
00051 #include <vector>
00052 #include <algorithm>
00053
00054
00055
00056 namespace OpenMesh {
00057
00058
00059
00060
00069 template <class MeshItems, class Connectivity>
00070 class AttribKernelT : public Connectivity
00071 {
00072 public:
00073
00074
00075
00076 typedef typename Connectivity::Vertex Vertex;
00077 typedef typename Connectivity::Halfedge Halfedge;
00078 typedef typename Connectivity::Edge Edge;
00079 typedef typename Connectivity::Face Face;
00080
00081 typedef typename MeshItems::Point Point;
00082 typedef typename MeshItems::Normal Normal;
00083 typedef typename MeshItems::Color Color;
00084 typedef typename MeshItems::TexCoord1D TexCoord1D;
00085 typedef typename MeshItems::TexCoord2D TexCoord2D;
00086 typedef typename MeshItems::TexCoord3D TexCoord3D;
00087 typedef typename MeshItems::Scalar Scalar;
00088 typedef typename MeshItems::TextureIndex TextureIndex;
00089
00090 typedef typename MeshItems::VertexData VertexData;
00091 typedef typename MeshItems::HalfedgeData HalfedgeData;
00092 typedef typename MeshItems::EdgeData EdgeData;
00093 typedef typename MeshItems::FaceData FaceData;
00094
00095 typedef AttribKernelT<MeshItems,Connectivity> AttribKernel;
00096
00097 enum Attribs {
00098 VAttribs = MeshItems::VAttribs,
00099 HAttribs = MeshItems::HAttribs,
00100 EAttribs = MeshItems::EAttribs,
00101 FAttribs = MeshItems::FAttribs
00102 };
00103
00104 typedef VPropHandleT<VertexData> DataVPropHandle;
00105 typedef HPropHandleT<HalfedgeData> DataHPropHandle;
00106 typedef EPropHandleT<EdgeData> DataEPropHandle;
00107 typedef FPropHandleT<FaceData> DataFPropHandle;
00108
00109 public:
00110
00111
00112
00113 AttribKernelT()
00114 : refcount_vnormals_(0),
00115 refcount_vcolors_(0),
00116 refcount_vtexcoords1D_(0),
00117 refcount_vtexcoords2D_(0),
00118 refcount_vtexcoords3D_(0),
00119 refcount_htexcoords1D_(0),
00120 refcount_htexcoords2D_(0),
00121 refcount_htexcoords3D_(0),
00122 refcount_ecolors_(0),
00123 refcount_fnormals_(0),
00124 refcount_fcolors_(0),
00125 refcount_ftextureIndex_(0)
00126 {
00127 add_property( points_, "v:points" );
00128
00129 if (VAttribs & Attributes::Normal)
00130 request_vertex_normals();
00131
00132 if (VAttribs & Attributes::Color)
00133 request_vertex_colors();
00134
00135 if (VAttribs & Attributes::TexCoord1D)
00136 request_vertex_texcoords1D();
00137
00138 if (VAttribs & Attributes::TexCoord2D)
00139 request_vertex_texcoords2D();
00140
00141 if (VAttribs & Attributes::TexCoord3D)
00142 request_vertex_texcoords3D();
00143
00144 if (HAttribs & Attributes::TexCoord1D)
00145 request_halfedge_texcoords1D();
00146
00147 if (HAttribs & Attributes::TexCoord2D)
00148 request_halfedge_texcoords2D();
00149
00150 if (HAttribs & Attributes::TexCoord3D)
00151 request_halfedge_texcoords3D();
00152
00153 if (VAttribs & Attributes::Status)
00154 Connectivity::request_vertex_status();
00155
00156 if (HAttribs & Attributes::Status)
00157 Connectivity::request_halfedge_status();
00158
00159 if (EAttribs & Attributes::Status)
00160 Connectivity::request_edge_status();
00161
00162 if (EAttribs & Attributes::Color)
00163 request_edge_colors();
00164
00165 if (FAttribs & Attributes::Normal)
00166 request_face_normals();
00167
00168 if (FAttribs & Attributes::Color)
00169 request_face_colors();
00170
00171 if (FAttribs & Attributes::Status)
00172 Connectivity::request_face_status();
00173
00174 if (FAttribs & Attributes::TextureIndex)
00175 request_face_texture_index();
00176
00177
00178
00179 add_property(data_vpph_);
00180 add_property(data_fpph_);
00181 add_property(data_hpph_);
00182 add_property(data_epph_);
00183 }
00184
00185 virtual ~AttribKernelT()
00186 {
00187
00188
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00248 template <class _AttribKernel>
00249 void assign(const _AttribKernel& _other)
00250 {
00251 assign_connectivity(_other);
00252 for (typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
00253 v_it != Connectivity::vertices_end(); ++v_it)
00254 {
00255 set_point(v_it, (Point)_other.point(v_it));
00256 }
00257 }
00258
00259
00260
00261 const Point* points() const
00262 { return property(points_).data(); }
00263
00264 const Point& point(VertexHandle _vh) const
00265 { return property(points_, _vh); }
00266
00267 Point& point(VertexHandle _vh)
00268 { return property(points_, _vh); }
00269
00270 void set_point(VertexHandle _vh, const Point& _p)
00271 { property(points_, _vh) = _p; }
00272
00273
00274
00275
00276 const Normal* vertex_normals() const
00277 { return property(vertex_normals_).data(); }
00278
00279 const Normal& normal(VertexHandle _vh) const
00280 { return property(vertex_normals_, _vh); }
00281
00282 void set_normal(VertexHandle _vh, const Normal& _n)
00283 { property(vertex_normals_, _vh) = _n; }
00284
00285
00286
00287
00288 const Color* vertex_colors() const
00289 { return property(vertex_colors_).data(); }
00290
00291 const Color& color(VertexHandle _vh) const
00292 { return property(vertex_colors_, _vh); }
00293
00294 void set_color(VertexHandle _vh, const Color& _c)
00295 { property(vertex_colors_, _vh) = _c; }
00296
00297
00298
00299
00300 const TexCoord1D* texcoords1D() const {
00301 return property(vertex_texcoords1D_).data();
00302 }
00303
00304 const TexCoord1D& texcoord1D(VertexHandle _vh) const {
00305 return property(vertex_texcoords1D_, _vh);
00306 }
00307
00308 void set_texcoord1D(VertexHandle _vh, const TexCoord1D& _t) {
00309 property(vertex_texcoords1D_, _vh) = _t;
00310 }
00311
00312
00313
00314
00315 const TexCoord2D* texcoords2D() const {
00316 return property(vertex_texcoords2D_).data();
00317 }
00318
00319 const TexCoord2D& texcoord2D(VertexHandle _vh) const {
00320 return property(vertex_texcoords2D_, _vh);
00321 }
00322
00323 void set_texcoord2D(VertexHandle _vh, const TexCoord2D& _t) {
00324 property(vertex_texcoords2D_, _vh) = _t;
00325 }
00326
00327
00328
00329
00330 const TexCoord3D* texcoords3D() const {
00331 return property(vertex_texcoords3D_).data();
00332 }
00333
00334 const TexCoord3D& texcoord3D(VertexHandle _vh) const {
00335 return property(vertex_texcoords3D_, _vh);
00336 }
00337
00338 void set_texcoord3D(VertexHandle _vh, const TexCoord3D& _t) {
00339 property(vertex_texcoords3D_, _vh) = _t;
00340 }
00341
00342
00343
00344 const TexCoord1D* htexcoords1D() const {
00345 return property(halfedge_texcoords1D_).data();
00346 }
00347
00348 const TexCoord1D& texcoord1D(HalfedgeHandle _heh) const {
00349 return property(halfedge_texcoords1D_, _heh);
00350 }
00351
00352 void set_texcoord1D(HalfedgeHandle _heh, const TexCoord1D& _t) {
00353 property(halfedge_texcoords1D_, _heh) = _t;
00354 }
00355
00356
00357
00358
00359 const TexCoord2D* htexcoords2D() const {
00360 return property(halfedge_texcoords2D_).data();
00361 }
00362
00363 const TexCoord2D& texcoord2D(HalfedgeHandle _heh) const {
00364 return property(halfedge_texcoords2D_, _heh);
00365 }
00366
00367 void set_texcoord2D(HalfedgeHandle _heh, const TexCoord2D& _t) {
00368 property(halfedge_texcoords2D_, _heh) = _t;
00369 }
00370
00371
00372
00373
00374 const TexCoord3D* htexcoords3D() const {
00375 return property(halfedge_texcoords3D_).data();
00376 }
00377
00378 const TexCoord3D& texcoord3D(HalfedgeHandle _heh) const {
00379 return property(halfedge_texcoords3D_, _heh);
00380 }
00381
00382 void set_texcoord3D(HalfedgeHandle _heh, const TexCoord3D& _t) {
00383 property(halfedge_texcoords3D_, _heh) = _t;
00384 }
00385
00386
00387
00388 const Color* edge_colors() const
00389 { return property(edge_colors_).data(); }
00390
00391 const Color& color(EdgeHandle _eh) const
00392 { return property(edge_colors_, _eh); }
00393
00394 void set_color(EdgeHandle _eh, const Color& _c)
00395 { property(edge_colors_, _eh) = _c; }
00396
00397
00398
00399 const Normal& normal(FaceHandle _fh) const
00400 { return property(face_normals_, _fh); }
00401
00402 void set_normal(FaceHandle _fh, const Normal& _n)
00403 { property(face_normals_, _fh) = _n; }
00404
00405
00406
00407 const TextureIndex& texture_index(FaceHandle _fh) const
00408 { return property(face_texture_index_, _fh); }
00409
00410 void set_texture_index(FaceHandle _fh, const TextureIndex& _t)
00411 { property(face_texture_index_, _fh) = _t; }
00412
00413
00414
00415 const Color& color(FaceHandle _fh) const
00416 { return property(face_colors_, _fh); }
00417
00418 void set_color(FaceHandle _fh, const Color& _c)
00419 { property(face_colors_, _fh) = _c; }
00420
00421
00422
00423 void request_vertex_normals()
00424 {
00425 if (!refcount_vnormals_++)
00426 add_property( vertex_normals_, "v:normals" );
00427 }
00428
00429 void request_vertex_colors()
00430 {
00431 if (!refcount_vcolors_++)
00432 add_property( vertex_colors_, "v:colors" );
00433 }
00434
00435 void request_vertex_texcoords1D()
00436 {
00437 if (!refcount_vtexcoords1D_++)
00438 add_property( vertex_texcoords1D_, "v:texcoords1D" );
00439 }
00440
00441 void request_vertex_texcoords2D()
00442 {
00443 if (!refcount_vtexcoords2D_++)
00444 add_property( vertex_texcoords2D_, "v:texcoords2D" );
00445 }
00446
00447 void request_vertex_texcoords3D()
00448 {
00449 if (!refcount_vtexcoords3D_++)
00450 add_property( vertex_texcoords3D_, "v:texcoords3D" );
00451 }
00452
00453 void request_halfedge_texcoords1D()
00454 {
00455 if (!refcount_htexcoords1D_++)
00456 add_property( halfedge_texcoords1D_, "h:texcoords1D" );
00457 }
00458
00459 void request_halfedge_texcoords2D()
00460 {
00461 if (!refcount_htexcoords2D_++)
00462 add_property( halfedge_texcoords2D_, "h:texcoords2D" );
00463 }
00464
00465 void request_halfedge_texcoords3D()
00466 {
00467 if (!refcount_htexcoords3D_++)
00468 add_property( halfedge_texcoords3D_, "h:texcoords3D" );
00469 }
00470
00471 void request_edge_colors()
00472 {
00473 if (!refcount_ecolors_++)
00474 add_property( edge_colors_, "e:colors" );
00475 }
00476
00477 void request_face_normals()
00478 {
00479 if (!refcount_fnormals_++)
00480 add_property( face_normals_, "f:normals" );
00481 }
00482
00483 void request_face_colors()
00484 {
00485 if (!refcount_fcolors_++)
00486 add_property( face_colors_, "f:colors" );
00487 }
00488
00489 void request_face_texture_index()
00490 {
00491 if (!refcount_ftextureIndex_++)
00492 add_property( face_texture_index_, "f:textureindex" );
00493 }
00494
00495
00496
00497 void release_vertex_normals()
00498 {
00499 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
00500 remove_property(vertex_normals_);
00501 }
00502
00503 void release_vertex_colors()
00504 {
00505 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
00506 remove_property(vertex_colors_);
00507 }
00508
00509 void release_vertex_texcoords1D() {
00510 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
00511 remove_property(vertex_texcoords1D_);
00512 }
00513
00514 void release_vertex_texcoords2D() {
00515 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
00516 remove_property(vertex_texcoords2D_);
00517 }
00518
00519 void release_vertex_texcoords3D() {
00520 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
00521 remove_property(vertex_texcoords3D_);
00522 }
00523
00524 void release_halfedge_texcoords1D() {
00525 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
00526 remove_property(halfedge_texcoords1D_);
00527 }
00528
00529 void release_halfedge_texcoords2D() {
00530 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
00531 remove_property(halfedge_texcoords2D_);
00532 }
00533
00534 void release_halfedge_texcoords3D() {
00535 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
00536 remove_property(halfedge_texcoords3D_);
00537 }
00538
00539 void release_edge_colors()
00540 {
00541 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
00542 remove_property(edge_colors_);
00543 }
00544
00545 void release_face_normals()
00546 {
00547 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
00548 remove_property(face_normals_);
00549 }
00550
00551 void release_face_colors()
00552 {
00553 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
00554 remove_property(face_colors_);
00555 }
00556
00557 void release_face_texture_index()
00558 {
00559 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
00560 remove_property(face_texture_index_);
00561 }
00562
00563
00564
00565 bool has_vertex_normals() const { return vertex_normals_.is_valid(); }
00566 bool has_vertex_colors() const { return vertex_colors_.is_valid(); }
00567 bool has_vertex_texcoords1D() const { return vertex_texcoords1D_.is_valid(); }
00568 bool has_vertex_texcoords2D() const { return vertex_texcoords2D_.is_valid(); }
00569 bool has_vertex_texcoords3D() const { return vertex_texcoords3D_.is_valid(); }
00570 bool has_halfedge_texcoords1D() const { return halfedge_texcoords1D_.is_valid();}
00571 bool has_halfedge_texcoords2D() const { return halfedge_texcoords2D_.is_valid();}
00572 bool has_halfedge_texcoords3D() const { return halfedge_texcoords3D_.is_valid();}
00573 bool has_edge_colors() const { return edge_colors_.is_valid(); }
00574 bool has_face_normals() const { return face_normals_.is_valid(); }
00575 bool has_face_colors() const { return face_colors_.is_valid(); }
00576 bool has_face_texture_index() const { return face_texture_index_.is_valid(); }
00577
00578 public:
00579
00580 typedef VPropHandleT<Point> PointsPropertyHandle;
00581 typedef VPropHandleT<Normal> VertexNormalsPropertyHandle;
00582 typedef VPropHandleT<Color> VertexColorsPropertyHandle;
00583 typedef VPropHandleT<TexCoord1D> VertexTexCoords1DPropertyHandle;
00584 typedef VPropHandleT<TexCoord2D> VertexTexCoords2DPropertyHandle;
00585 typedef VPropHandleT<TexCoord3D> VertexTexCoords3DPropertyHandle;
00586 typedef HPropHandleT<TexCoord1D> HalfedgeTexCoords1DPropertyHandle;
00587 typedef HPropHandleT<TexCoord2D> HalfedgeTexCoords2DPropertyHandle;
00588 typedef HPropHandleT<TexCoord3D> HalfedgeTexCoords3DPropertyHandle;
00589 typedef EPropHandleT<Color> EdgeColorsPropertyHandle;
00590 typedef FPropHandleT<Normal> FaceNormalsPropertyHandle;
00591 typedef FPropHandleT<Color> FaceColorsPropertyHandle;
00592 typedef FPropHandleT<TextureIndex> FaceTextureIndexPropertyHandle;
00593
00594 public:
00595
00596 PointsPropertyHandle points_pph() const
00597 { return points_; }
00598
00599 VertexNormalsPropertyHandle vertex_normals_pph() const
00600 { return vertex_normals_; }
00601
00602 VertexColorsPropertyHandle vertex_colors_pph() const
00603 { return vertex_colors_; }
00604
00605 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph() const
00606 { return vertex_texcoords1D_; }
00607
00608 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph() const
00609 { return vertex_texcoords2D_; }
00610
00611 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph() const
00612 { return vertex_texcoords3D_; }
00613
00614
00615 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph() const
00616 { return halfedge_texcoords1D_; }
00617
00618 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph() const
00619 { return halfedge_texcoords2D_; }
00620
00621 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph() const
00622 { return halfedge_texcoords3D_; }
00623
00624
00625 EdgeColorsPropertyHandle edge_colors_pph() const
00626 { return edge_colors_; }
00627
00628
00629 FaceNormalsPropertyHandle face_normals_pph() const
00630 { return face_normals_; }
00631
00632 FaceColorsPropertyHandle face_colors_pph() const
00633 { return face_colors_; }
00634
00635 FaceTextureIndexPropertyHandle face_texture_index_pph() const
00636 { return face_texture_index_; }
00637
00638 VertexData& data(VertexHandle _vh)
00639 { return property(data_vpph_, _vh); }
00640
00641 const VertexData& data(VertexHandle _vh) const
00642 { return property(data_vpph_, _vh); }
00643
00644 FaceData& data(FaceHandle _fh)
00645 { return property(data_fpph_, _fh); }
00646
00647 const FaceData& data(FaceHandle _fh) const
00648 { return property(data_fpph_, _fh); }
00649
00650 EdgeData& data(EdgeHandle _eh)
00651 { return property(data_epph_, _eh); }
00652
00653 const EdgeData& data(EdgeHandle _eh) const
00654 { return property(data_epph_, _eh); }
00655
00656 HalfedgeData& data(HalfedgeHandle _heh)
00657 { return property(data_hpph_, _heh); }
00658
00659 const HalfedgeData& data(HalfedgeHandle _heh) const
00660 { return property(data_hpph_, _heh); }
00661
00662 private:
00663
00664 PointsPropertyHandle points_;
00665 VertexNormalsPropertyHandle vertex_normals_;
00666 VertexColorsPropertyHandle vertex_colors_;
00667 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
00668 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
00669 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
00670
00671 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
00672 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
00673 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
00674
00675 EdgeColorsPropertyHandle edge_colors_;
00676
00677 FaceNormalsPropertyHandle face_normals_;
00678 FaceColorsPropertyHandle face_colors_;
00679 FaceTextureIndexPropertyHandle face_texture_index_;
00680
00681 DataVPropHandle data_vpph_;
00682 DataHPropHandle data_hpph_;
00683 DataEPropHandle data_epph_;
00684 DataFPropHandle data_fpph_;
00685
00686 unsigned int refcount_vnormals_;
00687 unsigned int refcount_vcolors_;
00688 unsigned int refcount_vtexcoords1D_;
00689 unsigned int refcount_vtexcoords2D_;
00690 unsigned int refcount_vtexcoords3D_;
00691 unsigned int refcount_htexcoords1D_;
00692 unsigned int refcount_htexcoords2D_;
00693 unsigned int refcount_htexcoords3D_;
00694 unsigned int refcount_ecolors_;
00695 unsigned int refcount_fnormals_;
00696 unsigned int refcount_fcolors_;
00697 unsigned int refcount_ftextureIndex_;
00698 };
00699
00700
00701 }
00702
00703 #endif // OPENMESH_ATTRIBKERNEL_HH defined
00704