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

AttribKernelT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2003 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 
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::TexCoord           TexCoord;
00069 
00070   typedef typename MeshItems::Scalar             Scalar;
00071 
00072   typedef Attributes::StatusInfo                 StatusInfo;
00073 
00074 
00075   enum Attribs {
00076     VAttribs = MeshItems::VAttribs,
00077     HAttribs = MeshItems::HAttribs,
00078     EAttribs = MeshItems::EAttribs,
00079     FAttribs = MeshItems::FAttribs,
00080   };
00081 
00082   typedef GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)> 
00083     HasPrevHalfedge;
00084 
00085 
00086 
00087   //-------------------------------------------------- constructor / destructor
00088 
00089   AttribKernelT() :
00090 
00091     refcount_vnormals_(0),
00092     refcount_vcolors_(0),
00093     refcount_vtexcoords_(0),
00094     refcount_vstatus_(0),
00095     refcount_hstatus_(0),
00096     refcount_estatus_(0),
00097     refcount_fnormals_(0),
00098     refcount_fcolors_(0),
00099     refcount_fstatus_(0)
00100 
00101   {
00102 
00103     add_property( points_, "v:points" );
00104 
00105     if (VAttribs & Attributes::Normal)
00106       request_vertex_normals();
00107 
00108     if (VAttribs & Attributes::Color)
00109       request_vertex_colors();
00110 
00111     if (VAttribs & Attributes::TexCoord)
00112       request_vertex_texcoords();
00113 
00114     if (VAttribs & Attributes::Status)
00115       request_vertex_status();
00116 
00117     if (HAttribs & Attributes::Status)
00118       request_halfedge_status();
00119 
00120     if (EAttribs & Attributes::Status)
00121       request_edge_status();
00122 
00123     if (FAttribs & Attributes::Normal)
00124       request_face_normals();
00125 
00126     if (FAttribs & Attributes::Color)
00127       request_face_colors();
00128 
00129     if (FAttribs & Attributes::Status)
00130       request_face_status();
00131   }
00132 
00133    
00134   ~AttribKernelT() 
00135   {
00136     // should remove properties, but this will be done in
00137     // BaseKernel's destructor anyway...
00138   }
00139 
00140 
00141 
00142   // -------------------------------------------------------- copy & assignment
00143 
00144   AttribKernelT(const AttribKernelT& _rhs) 
00145     : BaseKernel(_rhs)
00146   { operator=(_rhs); }
00147 
00148   AttribKernelT& operator=(const AttribKernelT& _rhs)
00149   {
00150     // remove old properties
00151     remove_property(points_);
00152     remove_property(vertex_normals_);
00153     remove_property(vertex_colors_);
00154     remove_property(vertex_texcoords_);
00155     remove_property(vertex_status_);
00156     remove_property(halfedge_status_);
00157     remove_property(edge_status_);
00158     remove_property(face_normals_);
00159     remove_property(face_colors_);
00160     remove_property(face_status_);
00161 
00162     // parent deep-copies properties
00163     BaseKernel::operator=(_rhs);
00164 
00165     // copy property handles
00166     points_            = _rhs.points_;
00167     vertex_normals_    = _rhs.vertex_normals_;
00168     vertex_colors_     = _rhs.vertex_colors_;
00169     vertex_texcoords_  = _rhs.vertex_texcoords_;
00170     vertex_status_     = _rhs.vertex_status_;
00171     halfedge_status_   = _rhs.halfedge_status_;
00172     edge_status_       = _rhs.edge_status_;
00173     face_normals_      = _rhs.face_normals_;
00174     face_colors_       = _rhs.face_colors_;
00175     face_status_       = _rhs.face_status_;
00176     
00177     // copy ref-counts
00178     refcount_vnormals_   = _rhs.refcount_vnormals_;
00179     refcount_vcolors_    = _rhs.refcount_vcolors_;
00180     refcount_vtexcoords_ = _rhs.refcount_vtexcoords_;
00181     refcount_vstatus_    = _rhs.refcount_vstatus_;
00182     refcount_hstatus_    = _rhs.refcount_hstatus_;
00183     refcount_estatus_    = _rhs.refcount_estatus_;
00184     refcount_fnormals_   = _rhs.refcount_fnormals_;
00185     refcount_fcolors_    = _rhs.refcount_fcolors_;
00186     refcount_fstatus_    = _rhs.refcount_fstatus_;
00187 
00188     return *this;
00189   }
00190 
00191 
00192   //-------------------------------------------------------------------- points
00193  
00194   const Point* points() const { 
00195     return property(points_).data(); 
00196   }
00197 
00198   const Point& point(VertexHandle _vh) const {
00199     return property(points_, _vh);
00200   }
00201 
00202   Point& point(VertexHandle _vh) {
00203     return property(points_, _vh);
00204   }
00205 
00206   void set_point(VertexHandle _vh, const Point& _p) {
00207     property(points_, _vh) = _p;
00208   }
00209 
00210 
00211   //------------------------------------------------------------ vertex normals
00212 
00213   const Normal* vertex_normals() const {
00214     return property(vertex_normals_).data(); 
00215   }
00216 
00217   const Normal& normal(VertexHandle _vh) const {
00218     return property(vertex_normals_, _vh);
00219   }
00220 
00221   void set_normal(VertexHandle _vh, const Normal& _n) {
00222     property(vertex_normals_, _vh) = _n;
00223   }
00224 
00225 
00226   //------------------------------------------------------------- vertex colors
00227 
00228   const Color* vertex_colors() const {
00229     return property(vertex_colors_).data(); 
00230   }
00231 
00232   const Color& color(VertexHandle _vh) const {
00233     return property(vertex_colors_, _vh);
00234   }
00235 
00236   void set_color(VertexHandle _vh, const Color& _c) {
00237     property(vertex_colors_, _vh) = _c;
00238   }
00239 
00240 
00241   //---------------------------------------------------------- vertex texcoords
00242 
00243   const TexCoord* texcoords() const {
00244     return property(vertex_texcoords_).data(); 
00245   }
00246 
00247   const TexCoord& texcoord(VertexHandle _vh) const {
00248     return property(vertex_texcoords_, _vh);
00249   }
00250 
00251   void set_texcoord(VertexHandle _vh, const TexCoord& _t) {
00252     property(vertex_texcoords_, _vh) = _t;
00253   }
00254 
00255 
00256   //------------------------------------------------------------ vertex status
00257 
00258   const StatusInfo& status(VertexHandle _vh) const {
00259     return property(vertex_status_, _vh);
00260   }
00261 
00262   StatusInfo& status(VertexHandle _vh) {
00263     return property(vertex_status_, _vh);
00264   }
00265 
00266 
00267   //----------------------------------------------------------- halfedge status
00268 
00269   const StatusInfo& status(HalfedgeHandle _hh) const {
00270     return property(halfedge_status_, _hh);
00271   }
00272 
00273   StatusInfo& status(HalfedgeHandle _hh) {
00274     return property(halfedge_status_, _hh);
00275   }
00276 
00277 
00278 
00279   //--------------------------------------------------------------- edge status
00280 
00281   const StatusInfo& status(EdgeHandle _eh) const {
00282     return property(edge_status_, _eh);
00283   }
00284 
00285   StatusInfo& status(EdgeHandle _eh) {
00286     return property(edge_status_, _eh);
00287   }
00288 
00289 
00290 
00291   //--------------------------------------------------------------- face status
00292 
00293   const StatusInfo& status(FaceHandle _fh) const {
00294     return property(face_status_, _fh);
00295   }
00296 
00297   StatusInfo& status(FaceHandle _fh) {
00298     return property(face_status_, _fh);
00299   }
00300 
00301 
00302 
00303   //-------------------------------------------------------------- face normals
00304 
00305   const Normal& normal(FaceHandle _fh) const {
00306     return property(face_normals_, _fh);
00307   }
00308 
00309   void set_normal(FaceHandle _fh, const Normal& _n) {
00310     property(face_normals_, _fh) = _n;
00311   }
00312 
00313 
00314 
00315   //--------------------------------------------------------------- face colors
00316 
00317   const Color& color(FaceHandle _fh) const {
00318     return property(face_colors_, _fh);
00319   }
00320 
00321   void set_color(FaceHandle _fh, const Color& _c) {
00322     property(face_colors_, _fh) = _c;
00323   }
00324 
00325 
00326 
00327   //------------------------------------------------ request / alloc properties
00328 
00329   void request_vertex_normals() {
00330     if (!refcount_vnormals_++)  
00331       add_property( vertex_normals_, "v:normals" );
00332   }
00333 
00334   void request_vertex_colors() {
00335     if (!refcount_vcolors_++)
00336       add_property( vertex_colors_, "v:colors" );
00337   }
00338 
00339   void request_vertex_texcoords() {
00340     if (!refcount_vtexcoords_++)
00341       add_property( vertex_texcoords_, "v:texcoords" );
00342   }
00343 
00344   void request_vertex_status() {
00345     if (!refcount_vstatus_++)
00346       add_property( vertex_status_, "v:status" );
00347   }
00348 
00349   void request_halfedge_status() {
00350     if (!refcount_hstatus_++)
00351       add_property( halfedge_status_, "h:status" );
00352   }
00353 
00354   void request_edge_status() {
00355     if (!refcount_estatus_++)
00356       add_property( edge_status_, "e:status" );
00357   }
00358 
00359   void request_face_normals() {
00360     if (!refcount_fnormals_++)
00361       add_property( face_normals_, "f:normals" );
00362   }
00363 
00364   void request_face_colors() {
00365     if (!refcount_fcolors_++)      
00366       add_property( face_colors_, "f:colors" );
00367   }
00368 
00369   void request_face_status() {
00370     if (!refcount_fstatus_++)
00371       add_property( face_status_, "f:status" );
00372   }
00373 
00374 
00375 
00376   //------------------------------------------------- release / free properties
00377 
00378   void release_vertex_normals() {
00379     if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
00380       remove_property(vertex_normals_);
00381   }
00382 
00383   void release_vertex_colors() {
00384     if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
00385       remove_property(vertex_colors_);
00386   }
00387 
00388   void release_vertex_texcoords() {
00389     if ((refcount_vtexcoords_ > 0) && (! --refcount_vtexcoords_))
00390       remove_property(vertex_texcoords_);
00391   }
00392 
00393   void release_vertex_status() {
00394     if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
00395       remove_property(vertex_status_);
00396   }
00397 
00398   void release_halfedge_status() {
00399     if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
00400       remove_property(halfedge_status_);
00401   }
00402 
00403   void release_edge_status() {
00404     if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
00405       remove_property(edge_status_);
00406   }
00407 
00408   void release_face_normals() {
00409     if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
00410       remove_property(face_normals_);
00411   }
00412 
00413   void release_face_colors() {
00414     if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
00415       remove_property(face_colors_);
00416   }
00417 
00418   void release_face_status() {
00419     if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
00420       remove_property(face_status_);
00421   }
00422 
00423 
00424 
00425   //---------------------------------------------- dynamic check for properties
00426 
00427   bool has_vertex_normals()   const { return vertex_normals_.is_valid();   }
00428   bool has_vertex_colors()    const { return vertex_colors_.is_valid();    }
00429   bool has_vertex_texcoords() const { return vertex_texcoords_.is_valid(); }
00430   bool has_vertex_status()    const { return vertex_status_.is_valid();    }
00431   bool has_halfedge_status()  const { return halfedge_status_.is_valid();  }
00432   bool has_edge_status()      const { return edge_status_.is_valid();      }
00433   bool has_face_normals()     const { return face_normals_.is_valid();     }
00434   bool has_face_colors()      const { return face_colors_.is_valid();      }
00435   bool has_face_status()      const { return face_status_.is_valid();      }
00436 
00437   static bool has_prev_halfedge() {
00438     return (HAttribs & Attributes::PrevHalfedge); 
00439   }
00440 
00441 
00442   
00443 protected:
00444   
00445   VPropHandleT<Point>         points_;
00446   VPropHandleT<Normal>        vertex_normals_;
00447   VPropHandleT<Color>         vertex_colors_;
00448   VPropHandleT<TexCoord>      vertex_texcoords_;
00449   VPropHandleT<StatusInfo>    vertex_status_;
00450   HPropHandleT<StatusInfo>    halfedge_status_;
00451   EPropHandleT<StatusInfo>    edge_status_;
00452   FPropHandleT<Normal>        face_normals_;
00453   FPropHandleT<Color>         face_colors_;
00454   FPropHandleT<StatusInfo>    face_status_;
00455 
00456   unsigned int  refcount_vnormals_;
00457   unsigned int  refcount_vcolors_;
00458   unsigned int  refcount_vtexcoords_;
00459   unsigned int  refcount_vstatus_;
00460   unsigned int  refcount_hstatus_;
00461   unsigned int  refcount_estatus_;
00462   unsigned int  refcount_fnormals_;
00463   unsigned int  refcount_fcolors_;
00464   unsigned int  refcount_fstatus_;
00465 };
00466 
00467 
00468 //=============================================================================
00469 } // namespace OpenMesh
00470 //=============================================================================
00471 #endif // OPENMESH_ATTRIBKERNEL_HH defined
00472 //=============================================================================

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