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