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_hecolors_(0),
00123 refcount_ecolors_(0),
00124 refcount_fnormals_(0),
00125 refcount_fcolors_(0),
00126 refcount_ftextureIndex_(0)
00127 {
00128 add_property( points_, "v:points" );
00129
00130 if (VAttribs & Attributes::Normal)
00131 request_vertex_normals();
00132
00133 if (VAttribs & Attributes::Color)
00134 request_vertex_colors();
00135
00136 if (VAttribs & Attributes::TexCoord1D)
00137 request_vertex_texcoords1D();
00138
00139 if (VAttribs & Attributes::TexCoord2D)
00140 request_vertex_texcoords2D();
00141
00142 if (VAttribs & Attributes::TexCoord3D)
00143 request_vertex_texcoords3D();
00144
00145 if (HAttribs & Attributes::TexCoord1D)
00146 request_halfedge_texcoords1D();
00147
00148 if (HAttribs & Attributes::TexCoord2D)
00149 request_halfedge_texcoords2D();
00150
00151 if (HAttribs & Attributes::TexCoord3D)
00152 request_halfedge_texcoords3D();
00153
00154 if (HAttribs & Attributes::Color)
00155 request_halfedge_colors();
00156
00157 if (VAttribs & Attributes::Status)
00158 Connectivity::request_vertex_status();
00159
00160 if (HAttribs & Attributes::Status)
00161 Connectivity::request_halfedge_status();
00162
00163 if (EAttribs & Attributes::Status)
00164 Connectivity::request_edge_status();
00165
00166 if (EAttribs & Attributes::Color)
00167 request_edge_colors();
00168
00169 if (FAttribs & Attributes::Normal)
00170 request_face_normals();
00171
00172 if (FAttribs & Attributes::Color)
00173 request_face_colors();
00174
00175 if (FAttribs & Attributes::Status)
00176 Connectivity::request_face_status();
00177
00178 if (FAttribs & Attributes::TextureIndex)
00179 request_face_texture_index();
00180
00181
00182
00183 add_property(data_vpph_);
00184 add_property(data_fpph_);
00185 add_property(data_hpph_);
00186 add_property(data_epph_);
00187 }
00188
00189 virtual ~AttribKernelT()
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
00240
00241
00242
00243
00252 template <class _AttribKernel>
00253 void assign(const _AttribKernel& _other)
00254 {
00255 assign_connectivity(_other);
00256 for (typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
00257 v_it != Connectivity::vertices_end(); ++v_it)
00258 {
00259 set_point(v_it, (Point)_other.point(v_it));
00260 }
00261 }
00262
00263
00264
00265 const Point* points() const
00266 { return property(points_).data(); }
00267
00268 const Point& point(VertexHandle _vh) const
00269 { return property(points_, _vh); }
00270
00271 Point& point(VertexHandle _vh)
00272 { return property(points_, _vh); }
00273
00274 void set_point(VertexHandle _vh, const Point& _p)
00275 { property(points_, _vh) = _p; }
00276
00277
00278
00279
00280 const Normal* vertex_normals() const
00281 { return property(vertex_normals_).data(); }
00282
00283 const Normal& normal(VertexHandle _vh) const
00284 { return property(vertex_normals_, _vh); }
00285
00286 void set_normal(VertexHandle _vh, const Normal& _n)
00287 { property(vertex_normals_, _vh) = _n; }
00288
00289
00290
00291
00292 const Color* vertex_colors() const
00293 { return property(vertex_colors_).data(); }
00294
00295 const Color& color(VertexHandle _vh) const
00296 { return property(vertex_colors_, _vh); }
00297
00298 void set_color(VertexHandle _vh, const Color& _c)
00299 { property(vertex_colors_, _vh) = _c; }
00300
00301
00302
00303
00304 const TexCoord1D* texcoords1D() const {
00305 return property(vertex_texcoords1D_).data();
00306 }
00307
00308 const TexCoord1D& texcoord1D(VertexHandle _vh) const {
00309 return property(vertex_texcoords1D_, _vh);
00310 }
00311
00312 void set_texcoord1D(VertexHandle _vh, const TexCoord1D& _t) {
00313 property(vertex_texcoords1D_, _vh) = _t;
00314 }
00315
00316
00317
00318
00319 const TexCoord2D* texcoords2D() const {
00320 return property(vertex_texcoords2D_).data();
00321 }
00322
00323 const TexCoord2D& texcoord2D(VertexHandle _vh) const {
00324 return property(vertex_texcoords2D_, _vh);
00325 }
00326
00327 void set_texcoord2D(VertexHandle _vh, const TexCoord2D& _t) {
00328 property(vertex_texcoords2D_, _vh) = _t;
00329 }
00330
00331
00332
00333
00334 const TexCoord3D* texcoords3D() const {
00335 return property(vertex_texcoords3D_).data();
00336 }
00337
00338 const TexCoord3D& texcoord3D(VertexHandle _vh) const {
00339 return property(vertex_texcoords3D_, _vh);
00340 }
00341
00342 void set_texcoord3D(VertexHandle _vh, const TexCoord3D& _t) {
00343 property(vertex_texcoords3D_, _vh) = _t;
00344 }
00345
00346
00347
00348 const TexCoord1D* htexcoords1D() const {
00349 return property(halfedge_texcoords1D_).data();
00350 }
00351
00352 const TexCoord1D& texcoord1D(HalfedgeHandle _heh) const {
00353 return property(halfedge_texcoords1D_, _heh);
00354 }
00355
00356 void set_texcoord1D(HalfedgeHandle _heh, const TexCoord1D& _t) {
00357 property(halfedge_texcoords1D_, _heh) = _t;
00358 }
00359
00360
00361
00362
00363 const TexCoord2D* htexcoords2D() const {
00364 return property(halfedge_texcoords2D_).data();
00365 }
00366
00367 const TexCoord2D& texcoord2D(HalfedgeHandle _heh) const {
00368 return property(halfedge_texcoords2D_, _heh);
00369 }
00370
00371 void set_texcoord2D(HalfedgeHandle _heh, const TexCoord2D& _t) {
00372 property(halfedge_texcoords2D_, _heh) = _t;
00373 }
00374
00375
00376
00377
00378 const TexCoord3D* htexcoords3D() const {
00379 return property(halfedge_texcoords3D_).data();
00380 }
00381
00382 const TexCoord3D& texcoord3D(HalfedgeHandle _heh) const {
00383 return property(halfedge_texcoords3D_, _heh);
00384 }
00385
00386 void set_texcoord3D(HalfedgeHandle _heh, const TexCoord3D& _t) {
00387 property(halfedge_texcoords3D_, _heh) = _t;
00388 }
00389
00390
00391
00392 const Color* edge_colors() const
00393 { return property(edge_colors_).data(); }
00394
00395 const Color& color(EdgeHandle _eh) const
00396 { return property(edge_colors_, _eh); }
00397
00398 void set_color(EdgeHandle _eh, const Color& _c)
00399 { property(edge_colors_, _eh) = _c; }
00400
00401
00402
00403
00404 const Color* halfedge_colors() const
00405 { return property(halfedge_colors_).data(); }
00406
00407 const Color& color(HalfedgeHandle _heh) const
00408 { return property(halfedge_colors_, _heh); }
00409
00410 void set_color(HalfedgeHandle _heh, const Color& _c)
00411 { property(halfedge_colors_, _heh) = _c; }
00412
00413
00414
00415 const Normal& normal(FaceHandle _fh) const
00416 { return property(face_normals_, _fh); }
00417
00418 void set_normal(FaceHandle _fh, const Normal& _n)
00419 { property(face_normals_, _fh) = _n; }
00420
00421
00422
00423 const TextureIndex& texture_index(FaceHandle _fh) const
00424 { return property(face_texture_index_, _fh); }
00425
00426 void set_texture_index(FaceHandle _fh, const TextureIndex& _t)
00427 { property(face_texture_index_, _fh) = _t; }
00428
00429
00430
00431 const Color& color(FaceHandle _fh) const
00432 { return property(face_colors_, _fh); }
00433
00434 void set_color(FaceHandle _fh, const Color& _c)
00435 { property(face_colors_, _fh) = _c; }
00436
00437
00438
00439 void request_vertex_normals()
00440 {
00441 if (!refcount_vnormals_++)
00442 add_property( vertex_normals_, "v:normals" );
00443 }
00444
00445 void request_vertex_colors()
00446 {
00447 if (!refcount_vcolors_++)
00448 add_property( vertex_colors_, "v:colors" );
00449 }
00450
00451 void request_vertex_texcoords1D()
00452 {
00453 if (!refcount_vtexcoords1D_++)
00454 add_property( vertex_texcoords1D_, "v:texcoords1D" );
00455 }
00456
00457 void request_vertex_texcoords2D()
00458 {
00459 if (!refcount_vtexcoords2D_++)
00460 add_property( vertex_texcoords2D_, "v:texcoords2D" );
00461 }
00462
00463 void request_vertex_texcoords3D()
00464 {
00465 if (!refcount_vtexcoords3D_++)
00466 add_property( vertex_texcoords3D_, "v:texcoords3D" );
00467 }
00468
00469 void request_halfedge_texcoords1D()
00470 {
00471 if (!refcount_htexcoords1D_++)
00472 add_property( halfedge_texcoords1D_, "h:texcoords1D" );
00473 }
00474
00475 void request_halfedge_texcoords2D()
00476 {
00477 if (!refcount_htexcoords2D_++)
00478 add_property( halfedge_texcoords2D_, "h:texcoords2D" );
00479 }
00480
00481 void request_halfedge_texcoords3D()
00482 {
00483 if (!refcount_htexcoords3D_++)
00484 add_property( halfedge_texcoords3D_, "h:texcoords3D" );
00485 }
00486
00487 void request_edge_colors()
00488 {
00489 if (!refcount_ecolors_++)
00490 add_property( edge_colors_, "e:colors" );
00491 }
00492
00493 void request_halfedge_colors()
00494 {
00495 if (!refcount_hecolors_++)
00496 add_property( halfedge_colors_, "h:colors" );
00497 }
00498
00499 void request_face_normals()
00500 {
00501 if (!refcount_fnormals_++)
00502 add_property( face_normals_, "f:normals" );
00503 }
00504
00505 void request_face_colors()
00506 {
00507 if (!refcount_fcolors_++)
00508 add_property( face_colors_, "f:colors" );
00509 }
00510
00511 void request_face_texture_index()
00512 {
00513 if (!refcount_ftextureIndex_++)
00514 add_property( face_texture_index_, "f:textureindex" );
00515 }
00516
00517
00518
00519 void release_vertex_normals()
00520 {
00521 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
00522 remove_property(vertex_normals_);
00523 }
00524
00525 void release_vertex_colors()
00526 {
00527 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
00528 remove_property(vertex_colors_);
00529 }
00530
00531 void release_vertex_texcoords1D() {
00532 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
00533 remove_property(vertex_texcoords1D_);
00534 }
00535
00536 void release_vertex_texcoords2D() {
00537 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
00538 remove_property(vertex_texcoords2D_);
00539 }
00540
00541 void release_vertex_texcoords3D() {
00542 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
00543 remove_property(vertex_texcoords3D_);
00544 }
00545
00546 void release_halfedge_texcoords1D() {
00547 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
00548 remove_property(halfedge_texcoords1D_);
00549 }
00550
00551 void release_halfedge_texcoords2D() {
00552 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
00553 remove_property(halfedge_texcoords2D_);
00554 }
00555
00556 void release_halfedge_texcoords3D() {
00557 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
00558 remove_property(halfedge_texcoords3D_);
00559 }
00560
00561 void release_edge_colors()
00562 {
00563 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
00564 remove_property(edge_colors_);
00565 }
00566
00567 void release_halfedge_colors()
00568 {
00569 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
00570 remove_property(halfedge_colors_);
00571 }
00572
00573 void release_face_normals()
00574 {
00575 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
00576 remove_property(face_normals_);
00577 }
00578
00579 void release_face_colors()
00580 {
00581 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
00582 remove_property(face_colors_);
00583 }
00584
00585 void release_face_texture_index()
00586 {
00587 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
00588 remove_property(face_texture_index_);
00589 }
00590
00591
00592
00593 bool has_vertex_normals() const { return vertex_normals_.is_valid(); }
00594 bool has_vertex_colors() const { return vertex_colors_.is_valid(); }
00595 bool has_vertex_texcoords1D() const { return vertex_texcoords1D_.is_valid(); }
00596 bool has_vertex_texcoords2D() const { return vertex_texcoords2D_.is_valid(); }
00597 bool has_vertex_texcoords3D() const { return vertex_texcoords3D_.is_valid(); }
00598 bool has_halfedge_texcoords1D() const { return halfedge_texcoords1D_.is_valid();}
00599 bool has_halfedge_texcoords2D() const { return halfedge_texcoords2D_.is_valid();}
00600 bool has_halfedge_texcoords3D() const { return halfedge_texcoords3D_.is_valid();}
00601 bool has_edge_colors() const { return edge_colors_.is_valid(); }
00602 bool has_halfedge_colors() const { return halfedge_colors_.is_valid(); }
00603 bool has_face_normals() const { return face_normals_.is_valid(); }
00604 bool has_face_colors() const { return face_colors_.is_valid(); }
00605 bool has_face_texture_index() const { return face_texture_index_.is_valid(); }
00606
00607 public:
00608
00609 typedef VPropHandleT<Point> PointsPropertyHandle;
00610 typedef VPropHandleT<Normal> VertexNormalsPropertyHandle;
00611 typedef VPropHandleT<Color> VertexColorsPropertyHandle;
00612 typedef VPropHandleT<TexCoord1D> VertexTexCoords1DPropertyHandle;
00613 typedef VPropHandleT<TexCoord2D> VertexTexCoords2DPropertyHandle;
00614 typedef VPropHandleT<TexCoord3D> VertexTexCoords3DPropertyHandle;
00615 typedef HPropHandleT<TexCoord1D> HalfedgeTexCoords1DPropertyHandle;
00616 typedef HPropHandleT<TexCoord2D> HalfedgeTexCoords2DPropertyHandle;
00617 typedef HPropHandleT<TexCoord3D> HalfedgeTexCoords3DPropertyHandle;
00618 typedef EPropHandleT<Color> EdgeColorsPropertyHandle;
00619 typedef HPropHandleT<Color> HalfedgeColorsPropertyHandle;
00620 typedef FPropHandleT<Normal> FaceNormalsPropertyHandle;
00621 typedef FPropHandleT<Color> FaceColorsPropertyHandle;
00622 typedef FPropHandleT<TextureIndex> FaceTextureIndexPropertyHandle;
00623
00624 public:
00625
00626 PointsPropertyHandle points_pph() const
00627 { return points_; }
00628
00629 VertexNormalsPropertyHandle vertex_normals_pph() const
00630 { return vertex_normals_; }
00631
00632 VertexColorsPropertyHandle vertex_colors_pph() const
00633 { return vertex_colors_; }
00634
00635 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph() const
00636 { return vertex_texcoords1D_; }
00637
00638 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph() const
00639 { return vertex_texcoords2D_; }
00640
00641 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph() const
00642 { return vertex_texcoords3D_; }
00643
00644
00645 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph() const
00646 { return halfedge_texcoords1D_; }
00647
00648 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph() const
00649 { return halfedge_texcoords2D_; }
00650
00651 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph() const
00652 { return halfedge_texcoords3D_; }
00653
00654
00655 HalfedgeColorsPropertyHandle halfedge_colors_pph() const
00656 { return halfedge_colors_; }
00657
00658
00659 EdgeColorsPropertyHandle edge_colors_pph() const
00660 { return edge_colors_; }
00661
00662
00663 FaceNormalsPropertyHandle face_normals_pph() const
00664 { return face_normals_; }
00665
00666 FaceColorsPropertyHandle face_colors_pph() const
00667 { return face_colors_; }
00668
00669 FaceTextureIndexPropertyHandle face_texture_index_pph() const
00670 { return face_texture_index_; }
00671
00672 VertexData& data(VertexHandle _vh)
00673 { return property(data_vpph_, _vh); }
00674
00675 const VertexData& data(VertexHandle _vh) const
00676 { return property(data_vpph_, _vh); }
00677
00678 FaceData& data(FaceHandle _fh)
00679 { return property(data_fpph_, _fh); }
00680
00681 const FaceData& data(FaceHandle _fh) const
00682 { return property(data_fpph_, _fh); }
00683
00684 EdgeData& data(EdgeHandle _eh)
00685 { return property(data_epph_, _eh); }
00686
00687 const EdgeData& data(EdgeHandle _eh) const
00688 { return property(data_epph_, _eh); }
00689
00690 HalfedgeData& data(HalfedgeHandle _heh)
00691 { return property(data_hpph_, _heh); }
00692
00693 const HalfedgeData& data(HalfedgeHandle _heh) const
00694 { return property(data_hpph_, _heh); }
00695
00696 private:
00697
00698 PointsPropertyHandle points_;
00699 VertexNormalsPropertyHandle vertex_normals_;
00700 VertexColorsPropertyHandle vertex_colors_;
00701 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
00702 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
00703 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
00704
00705 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
00706 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
00707 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
00708 HalfedgeColorsPropertyHandle halfedge_colors_;
00709
00710 EdgeColorsPropertyHandle edge_colors_;
00711
00712 FaceNormalsPropertyHandle face_normals_;
00713 FaceColorsPropertyHandle face_colors_;
00714 FaceTextureIndexPropertyHandle face_texture_index_;
00715
00716 DataVPropHandle data_vpph_;
00717 DataHPropHandle data_hpph_;
00718 DataEPropHandle data_epph_;
00719 DataFPropHandle data_fpph_;
00720
00721 unsigned int refcount_vnormals_;
00722 unsigned int refcount_vcolors_;
00723 unsigned int refcount_vtexcoords1D_;
00724 unsigned int refcount_vtexcoords2D_;
00725 unsigned int refcount_vtexcoords3D_;
00726 unsigned int refcount_htexcoords1D_;
00727 unsigned int refcount_htexcoords2D_;
00728 unsigned int refcount_htexcoords3D_;
00729 unsigned int refcount_hecolors_;
00730 unsigned int refcount_ecolors_;
00731 unsigned int refcount_fnormals_;
00732 unsigned int refcount_fcolors_;
00733 unsigned int refcount_ftextureIndex_;
00734 };
00735
00736
00737 }
00738
00739 #endif // OPENMESH_ATTRIBKERNEL_HH defined
00740