Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

AttribKernelT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 
00026 #ifndef OPENMESH_ATTRIBKERNEL_HH
00027 #define OPENMESH_ATTRIBKERNEL_HH
00028 
00029 
00030 //== INCLUDES =================================================================
00031 
00032 #include <OpenMesh/Core/Attributes/Attributes.hh>
00033 #include <OpenMesh/Core/Mesh/Kernels/Common/BaseKernel.hh>
00034 #include <OpenMesh/Core/Utils/GenProg.hh>
00035 #include <OpenMesh/Core/Utils/vector_traits.hh>
00036 #include <vector>
00037 #include <algorithm>
00038 
00039 //== NAMESPACES ===============================================================
00040 
00041 namespace OpenMesh {
00042 
00043 
00044 //== CLASS DEFINITION =========================================================
00045 
00053 template <class MeshItems>
00054 class AttribKernelT : public BaseKernel
00055 {
00056 public:
00057 
00058   //---------------------------------------------------------------- item types
00059 
00060   typedef typename MeshItems::Vertex             Vertex;
00061   typedef typename MeshItems::Halfedge           Halfedge;
00062   typedef typename MeshItems::Edge               Edge;
00063   typedef typename MeshItems::Face               Face;
00064 
00065   typedef typename MeshItems::Point              Point;
00066   typedef typename MeshItems::Normal             Normal;
00067   typedef typename MeshItems::Color              Color;
00068   typedef typename MeshItems::TexCoord1D         TexCoord1D;
00069   typedef typename MeshItems::TexCoord2D         TexCoord2D;
00070   typedef typename MeshItems::TexCoord3D         TexCoord3D;
00071 
00072   typedef typename MeshItems::Scalar             Scalar;
00073 
00074   typedef Attributes::StatusInfo                 StatusInfo;
00075 
00076   typedef AttribKernelT<MeshItems>               AttribKernel;
00077 
00078   enum Attribs {
00079     VAttribs = MeshItems::VAttribs,
00080     HAttribs = MeshItems::HAttribs,
00081     EAttribs = MeshItems::EAttribs,
00082     FAttribs = MeshItems::FAttribs,
00083   };
00084 
00085   typedef GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
00086     HasPrevHalfedge;
00087 
00088 public:
00089 
00090   //-------------------------------------------------- constructor / destructor
00091 
00092   AttribKernelT() :
00093 
00094     refcount_vnormals_(0),
00095     refcount_vcolors_(0),
00096     refcount_vtexcoords1D_(0),
00097     refcount_vtexcoords2D_(0),
00098     refcount_vtexcoords3D_(0),
00099     refcount_vstatus_(0),
00100     refcount_hstatus_(0),
00101     refcount_estatus_(0),
00102     refcount_fnormals_(0),
00103     refcount_fcolors_(0),
00104     refcount_fstatus_(0)
00105 
00106   {
00107 
00108     add_property( points_, "v:points" );
00109 
00110     if (VAttribs & Attributes::Normal)
00111       request_vertex_normals();
00112 
00113     if (VAttribs & Attributes::Color)
00114       request_vertex_colors();
00115 
00116     if (VAttribs & Attributes::TexCoord1D)
00117       request_vertex_texcoords1D();
00118 
00119     if (VAttribs & Attributes::TexCoord2D)
00120       request_vertex_texcoords2D();
00121 
00122     if (VAttribs & Attributes::TexCoord3D)
00123       request_vertex_texcoords3D();
00124 
00125     if (VAttribs & Attributes::Status)
00126       request_vertex_status();
00127 
00128     if (HAttribs & Attributes::Status)
00129       request_halfedge_status();
00130 
00131     if (EAttribs & Attributes::Status)
00132       request_edge_status();
00133 
00134     if (FAttribs & Attributes::Normal)
00135       request_face_normals();
00136 
00137     if (FAttribs & Attributes::Color)
00138       request_face_colors();
00139 
00140     if (FAttribs & Attributes::Status)
00141       request_face_status();
00142   }
00143 
00144 
00145   ~AttribKernelT()
00146   {
00147     // should remove properties, but this will be done in
00148     // BaseKernel's destructor anyway...
00149   }
00150 
00151 
00152 
00153   // -------------------------------------------------------- copy & assignment
00154 
00155   AttribKernelT(const AttribKernelT& _rhs)
00156     : BaseKernel(_rhs)
00157   { operator=(_rhs); }
00158 
00159   AttribKernelT& operator=(const AttribKernelT& _rhs)
00160   {
00161     if (this!=&_rhs)
00162     {
00163       // remove old properties
00164       remove_property(points_);
00165       remove_property(vertex_normals_);
00166       remove_property(vertex_colors_);
00167       remove_property(vertex_texcoords1D_);
00168       remove_property(vertex_texcoords2D_);
00169       remove_property(vertex_texcoords3D_);
00170       remove_property(vertex_status_);
00171       remove_property(halfedge_status_);
00172       remove_property(edge_status_);
00173       remove_property(face_normals_);
00174       remove_property(face_colors_);
00175       remove_property(face_status_);
00176 
00177       // parent deep-copies properties
00178       BaseKernel::operator=(_rhs);
00179 
00180       // copy property handles
00181       points_              = _rhs.points_;
00182       vertex_normals_      = _rhs.vertex_normals_;
00183       vertex_colors_       = _rhs.vertex_colors_;
00184       vertex_texcoords1D_  = _rhs.vertex_texcoords1D_;
00185       vertex_texcoords2D_  = _rhs.vertex_texcoords2D_;
00186       vertex_texcoords3D_  = _rhs.vertex_texcoords3D_;
00187       vertex_status_       = _rhs.vertex_status_;
00188       halfedge_status_     = _rhs.halfedge_status_;
00189       edge_status_         = _rhs.edge_status_;
00190       face_normals_        = _rhs.face_normals_;
00191       face_colors_         = _rhs.face_colors_;
00192       face_status_         = _rhs.face_status_;
00193 
00194       // copy ref-counts
00195       refcount_vnormals_     = _rhs.refcount_vnormals_;
00196       refcount_vcolors_      = _rhs.refcount_vcolors_;
00197       refcount_vtexcoords1D_ = _rhs.refcount_vtexcoords1D_;
00198       refcount_vtexcoords2D_ = _rhs.refcount_vtexcoords2D_;
00199       refcount_vtexcoords3D_ = _rhs.refcount_vtexcoords3D_;
00200       refcount_vstatus_      = _rhs.refcount_vstatus_;
00201       refcount_hstatus_      = _rhs.refcount_hstatus_;
00202       refcount_estatus_      = _rhs.refcount_estatus_;
00203       refcount_fnormals_     = _rhs.refcount_fnormals_;
00204       refcount_fcolors_      = _rhs.refcount_fcolors_;
00205       refcount_fstatus_      = _rhs.refcount_fstatus_;
00206     }
00207 
00208     return *this;
00209   }
00210 
00211 
00212   //-------------------------------------------------------------------- points
00213 
00214   const Point* points() const {
00215     return property(points_).data();
00216   }
00217 
00218   const Point& point(VertexHandle _vh) const {
00219     return property(points_, _vh);
00220   }
00221 
00222   Point& point(VertexHandle _vh) {
00223     return property(points_, _vh);
00224   }
00225 
00226   void set_point(VertexHandle _vh, const Point& _p) {
00227     property(points_, _vh) = _p;
00228   }
00229 
00230 
00231   //------------------------------------------------------------ vertex normals
00232 
00233   const Normal* vertex_normals() const {
00234     return property(vertex_normals_).data();
00235   }
00236 
00237   const Normal& normal(VertexHandle _vh) const {
00238     return property(vertex_normals_, _vh);
00239   }
00240 
00241   void set_normal(VertexHandle _vh, const Normal& _n) {
00242     property(vertex_normals_, _vh) = _n;
00243   }
00244 
00245 
00246   //------------------------------------------------------------- vertex colors
00247 
00248   const Color* vertex_colors() const {
00249     return property(vertex_colors_).data();
00250   }
00251 
00252   const Color& color(VertexHandle _vh) const {
00253     return property(vertex_colors_, _vh);
00254   }
00255 
00256   void set_color(VertexHandle _vh, const Color& _c) {
00257     property(vertex_colors_, _vh) = _c;
00258   }
00259 
00260 
00261   //------------------------------------------------------- vertex 1D texcoords
00262 
00263   const TexCoord1D* texcoords1D() const {
00264     return property(vertex_texcoords1D_).data();
00265   }
00266 
00267   const TexCoord1D& texcoord1D(VertexHandle _vh) const {
00268     return property(vertex_texcoords1D_, _vh);
00269   }
00270 
00271   void set_texcoord1D(VertexHandle _vh, const TexCoord1D& _t) {
00272     property(vertex_texcoords1D_, _vh) = _t;
00273   }
00274 
00275 
00276   //------------------------------------------------------- vertex 2D texcoords
00277 
00278   const TexCoord2D* texcoords2D() const {
00279     return property(vertex_texcoords2D_).data();
00280   }
00281 
00282   const TexCoord2D& texcoord2D(VertexHandle _vh) const {
00283     return property(vertex_texcoords2D_, _vh);
00284   }
00285 
00286   void set_texcoord2D(VertexHandle _vh, const TexCoord2D& _t) {
00287     property(vertex_texcoords2D_, _vh) = _t;
00288   }
00289 
00290 
00291   //------------------------------------------------------- vertex 3D texcoords
00292 
00293   const TexCoord3D* texcoords3D() const {
00294     return property(vertex_texcoords3D_).data();
00295   }
00296 
00297   const TexCoord3D& texcoord3D(VertexHandle _vh) const {
00298     return property(vertex_texcoords3D_, _vh);
00299   }
00300 
00301   void set_texcoord3D(VertexHandle _vh, const TexCoord3D& _t) {
00302     property(vertex_texcoords3D_, _vh) = _t;
00303   }
00304 
00305 
00306   //------------------------------------------------------------ vertex status
00307 
00308   const StatusInfo& status(VertexHandle _vh) const {
00309     return property(vertex_status_, _vh);
00310   }
00311 
00312   StatusInfo& status(VertexHandle _vh) {
00313     return property(vertex_status_, _vh);
00314   }
00315 
00316 
00317   //----------------------------------------------------------- halfedge status
00318 
00319   const StatusInfo& status(HalfedgeHandle _hh) const {
00320     return property(halfedge_status_, _hh);
00321   }
00322 
00323   StatusInfo& status(HalfedgeHandle _hh) {
00324     return property(halfedge_status_, _hh);
00325   }
00326 
00327 
00328 
00329   //--------------------------------------------------------------- edge status
00330 
00331   const StatusInfo& status(EdgeHandle _eh) const {
00332     return property(edge_status_, _eh);
00333   }
00334 
00335   StatusInfo& status(EdgeHandle _eh) {
00336     return property(edge_status_, _eh);
00337   }
00338 
00339 
00340 
00341   //--------------------------------------------------------------- face status
00342 
00343   const StatusInfo& status(FaceHandle _fh) const {
00344     return property(face_status_, _fh);
00345   }
00346 
00347   StatusInfo& status(FaceHandle _fh) {
00348     return property(face_status_, _fh);
00349   }
00350 
00351 
00352 
00353   //-------------------------------------------------------------- face normals
00354 
00355   const Normal& normal(FaceHandle _fh) const {
00356     return property(face_normals_, _fh);
00357   }
00358 
00359   void set_normal(FaceHandle _fh, const Normal& _n) {
00360     property(face_normals_, _fh) = _n;
00361   }
00362 
00363 
00364 
00365   //--------------------------------------------------------------- face colors
00366 
00367   const Color& color(FaceHandle _fh) const {
00368     return property(face_colors_, _fh);
00369   }
00370 
00371   void set_color(FaceHandle _fh, const Color& _c) {
00372     property(face_colors_, _fh) = _c;
00373   }
00374 
00375 
00376 
00377   //------------------------------------------------ request / alloc properties
00378 
00379   void request_vertex_normals() {
00380     if (!refcount_vnormals_++)
00381       add_property( vertex_normals_, "v:normals" );
00382   }
00383 
00384   void request_vertex_colors() {
00385     if (!refcount_vcolors_++)
00386       add_property( vertex_colors_, "v:colors" );
00387   }
00388 
00389   void request_vertex_texcoords1D() {
00390     if (!refcount_vtexcoords1D_++)
00391       add_property( vertex_texcoords1D_, "v:texcoords1D" );
00392   }
00393 
00394   void request_vertex_texcoords2D() {
00395     if (!refcount_vtexcoords2D_++)
00396       add_property( vertex_texcoords2D_, "v:texcoords2D" );
00397   }
00398 
00399   void request_vertex_texcoords3D() {
00400     if (!refcount_vtexcoords3D_++)
00401       add_property( vertex_texcoords3D_, "v:texcoords3D" );
00402   }
00403 
00404   void request_vertex_status() {
00405     if (!refcount_vstatus_++)
00406       add_property( vertex_status_, "v:status" );
00407   }
00408 
00409   void request_halfedge_status() {
00410     if (!refcount_hstatus_++)
00411       add_property( halfedge_status_, "h:status" );
00412   }
00413 
00414   void request_edge_status() {
00415     if (!refcount_estatus_++)
00416       add_property( edge_status_, "e:status" );
00417   }
00418 
00419   void request_face_normals() {
00420     if (!refcount_fnormals_++)
00421       add_property( face_normals_, "f:normals" );
00422   }
00423 
00424   void request_face_colors() {
00425     if (!refcount_fcolors_++)
00426       add_property( face_colors_, "f:colors" );
00427   }
00428 
00429   void request_face_status() {
00430     if (!refcount_fstatus_++)
00431       add_property( face_status_, "f:status" );
00432   }
00433 
00434 
00435 
00436   //------------------------------------------------- release / free properties
00437 
00438   void release_vertex_normals() {
00439     if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
00440       remove_property(vertex_normals_);
00441   }
00442 
00443   void release_vertex_colors() {
00444     if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
00445       remove_property(vertex_colors_);
00446   }
00447 
00448   void release_vertex_texcoords1D() {
00449     if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
00450       remove_property(vertex_texcoords1D_);
00451   }
00452 
00453   void release_vertex_texcoords2D() {
00454     if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
00455       remove_property(vertex_texcoords2D_);
00456   }
00457 
00458   void release_vertex_texcoords3D() {
00459     if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
00460       remove_property(vertex_texcoords3D_);
00461   }
00462 
00463   void release_vertex_status() {
00464     if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
00465       remove_property(vertex_status_);
00466   }
00467 
00468   void release_halfedge_status() {
00469     if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
00470       remove_property(halfedge_status_);
00471   }
00472 
00473   void release_edge_status() {
00474     if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
00475       remove_property(edge_status_);
00476   }
00477 
00478   void release_face_normals() {
00479     if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
00480       remove_property(face_normals_);
00481   }
00482 
00483   void release_face_colors() {
00484     if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
00485       remove_property(face_colors_);
00486   }
00487 
00488   void release_face_status() {
00489     if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
00490       remove_property(face_status_);
00491   }
00492 
00493 
00494 
00495   //---------------------------------------------- dynamic check for properties
00496 
00497   bool has_vertex_normals()     const { return vertex_normals_.is_valid();   }
00498   bool has_vertex_colors()      const { return vertex_colors_.is_valid();    }
00499   bool has_vertex_texcoords1D() const { return vertex_texcoords1D_.is_valid();}
00500   bool has_vertex_texcoords2D() const { return vertex_texcoords2D_.is_valid();}
00501   bool has_vertex_texcoords3D() const { return vertex_texcoords3D_.is_valid();}
00502   bool has_vertex_status()      const { return vertex_status_.is_valid();    }
00503   bool has_halfedge_status()    const { return halfedge_status_.is_valid();  }
00504   bool has_edge_status()        const { return edge_status_.is_valid();      }
00505   bool has_face_normals()       const { return face_normals_.is_valid();     }
00506   bool has_face_colors()        const { return face_colors_.is_valid();      }
00507   bool has_face_status()        const { return face_status_.is_valid();      }
00508 
00509   static bool has_prev_halfedge() {
00510     return (HAttribs & Attributes::PrevHalfedge);
00511   }
00512 
00513 
00514 public:
00515 
00516   typedef VPropHandleT<Point>               PointsPropertyHandle;
00517   typedef VPropHandleT<Normal>              VertexNormalsPropertyHandle;
00518   typedef VPropHandleT<Color>               VertexColorsPropertyHandle;
00519   typedef VPropHandleT<TexCoord1D>          VertexTexCoords1DPropertyHandle;
00520   typedef VPropHandleT<TexCoord2D>          VertexTexCoords2DPropertyHandle;
00521   typedef VPropHandleT<TexCoord3D>          VertexTexCoords3DPropertyHandle;
00522   typedef VPropHandleT<StatusInfo>          VertexStatusPropertyHandle;
00523   typedef HPropHandleT<StatusInfo>          HalfedgeStatusPropertyHandle;
00524   typedef EPropHandleT<StatusInfo>          EdgeStatusPropertyHandle;
00525   typedef FPropHandleT<Normal>              FaceNormalsPropertyHandle;
00526   typedef FPropHandleT<Color>               FaceColorsPropertyHandle;
00527   typedef FPropHandleT<StatusInfo>          FaceStatusPropertyHandle;
00528 
00529 public:
00530   //standard vertex properties
00531   PointsPropertyHandle                      points_pph() const
00532   {
00533     return points_;
00534   }
00535 
00536   VertexNormalsPropertyHandle               vertex_normals_pph() const
00537   {
00538     return vertex_normals_;
00539   }
00540 
00541   VertexColorsPropertyHandle                vertex_colors_pph() const
00542   {
00543     return vertex_colors_;
00544   }
00545 
00546   VertexTexCoords1DPropertyHandle           vertex_texcoords1D_pph() const
00547   {
00548     return AttribKernel::vertex_tex_coords_;
00549   }
00550 
00551   VertexTexCoords2DPropertyHandle           vertex_texcoords2D_pph() const
00552   {
00553     return AttribKernel::vertex_tex_coords_;
00554   }
00555 
00556   VertexTexCoords3DPropertyHandle           vertex_texcoords3D_pph() const
00557   {
00558     return AttribKernel::vertex_tex_coords_;
00559   }
00560 
00561   VertexStatusPropertyHandle                vertex_status_pph() const
00562   {
00563     return vertex_status_;
00564   }
00565 
00566   //standard halfedge properties
00567   HalfedgeStatusPropertyHandle              halfedge_status_pph() const
00568   {
00569     return halfedge_status_;
00570   }
00571 
00572   //standard edge properties
00573   EdgeStatusPropertyHandle                  edge_status_pph() const
00574   {
00575     return edge_status_;
00576   }
00577 
00578   //standard face properties
00579   FaceNormalsPropertyHandle                 face_normals_pph() const
00580   {
00581     return face_normals_;
00582   }
00583 
00584   FaceColorsPropertyHandle                  face_colors_pph() const
00585   {
00586     return face_colors_;
00587   }
00588 
00589   FaceStatusPropertyHandle                  face_status_pph() const
00590   {
00591     return face_status_;
00592   }
00593 
00594 private:
00595 
00596   //standard vertex properties
00597   PointsPropertyHandle                      points_;
00598   VertexNormalsPropertyHandle               vertex_normals_;
00599   VertexColorsPropertyHandle                vertex_colors_;
00600   VertexTexCoords1DPropertyHandle           vertex_texcoords1D_;
00601   VertexTexCoords2DPropertyHandle           vertex_texcoords2D_;
00602   VertexTexCoords3DPropertyHandle           vertex_texcoords3D_;
00603   VertexStatusPropertyHandle                vertex_status_;
00604 
00605   //standard halfedge properties
00606   HalfedgeStatusPropertyHandle              halfedge_status_;
00607 
00608   //standard edge properties
00609   EdgeStatusPropertyHandle                  edge_status_;
00610 
00611   //standard face properties
00612   FaceNormalsPropertyHandle                 face_normals_;
00613   FaceColorsPropertyHandle                  face_colors_;
00614   FaceStatusPropertyHandle                  face_status_;
00615 
00616   unsigned int  refcount_vnormals_;
00617   unsigned int  refcount_vcolors_;
00618   unsigned int  refcount_vtexcoords1D_;
00619   unsigned int  refcount_vtexcoords2D_;
00620   unsigned int  refcount_vtexcoords3D_;
00621   unsigned int  refcount_vstatus_;
00622   unsigned int  refcount_hstatus_;
00623   unsigned int  refcount_estatus_;
00624   unsigned int  refcount_fnormals_;
00625   unsigned int  refcount_fcolors_;
00626   unsigned int  refcount_fstatus_;
00627 };
00628 
00629 
00630 //=============================================================================
00631 } // namespace OpenMesh
00632 //=============================================================================
00633 #endif // OPENMESH_ATTRIBKERNEL_HH defined
00634 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .