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