From 84866a3b0d2f66a92e28baef560891b3b0a3a028 Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 14 Oct 2005 13:26:57 +0000 Subject: [PATCH] First Really Working version --- vcg/simplex/faceplus/base.h | 401 ++++++++++++++++++++++++------------ 1 file changed, 266 insertions(+), 135 deletions(-) diff --git a/vcg/simplex/faceplus/base.h b/vcg/simplex/faceplus/base.h index 277fe93d..af2fef5b 100644 --- a/vcg/simplex/faceplus/base.h +++ b/vcg/simplex/faceplus/base.h @@ -1,162 +1,293 @@ -#ifndef RECURSE_H -#define RECURSE_H +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ +Revision 1.2 2004/04/03 13:33:55 cignoni +Missing include + +Revision 1.1 2004/03/29 08:36:26 cignoni +First working version! + + +****************************************************************************/ +#ifndef __VCG_FACE_PLUS +#define __VCG_FACE_PLUS #include +#include +#include +#include - -class Empty{}; +namespace vcg { /*------------------------------------------------------------------*/ -template class EmptyCoord: public T { -public: - typedef vcg::Point3f CoordType; - CoordType &P() { static CoordType coord(0, 0, 0); return coord; } -}; -template class Coord: public T { -public: - typedef A CoordType; - CoordType &P() { return coord; } -private: - CoordType coord; -}; -template class Coord3f: public Coord {}; -template class Coord3d: public Coord {}; +/* +The base class of all the recusive definition chain. It is just a container of the typenames of the various simplexes. +These typenames must be known form all the derived classes. +*/ -/*------------------------------------------------------------------*/ - -template class EmptyNormal: public T { -public: - typedef vcg::Point3s NormalType; - NormalType &N() { static NormalType normal(0, 0, 0); return normal; } -}; -template class NormalX: public T { -public: - typedef A NormalType; - NormalType &N() { return norm; } -private: - NormalType norm; -}; -template class Normal3s: public NormalX {}; -template class Normal3f: public NormalX {}; -template class Normal3d: public NormalX {}; - -/*------------------------------------------------------------------*/ - -template class EmptyColor: public T { -public: - typedef vcg::Point3s ColorType; - ColorType &C() { static ColorType color(0, 0, 0); return color; } -}; -template class Color: public T { -public: - typedef A ColorType; - ColorType &C() { return color; } -private: - ColorType color; -}; -template class Color3c: public Color, T> {}; - - -/*------------------------------------------------------------------*/ - - -template class EmptyVFAdj: public T { -public: - //typedef vcg::Point3s ColorType; - typename T::FacePointer &Fp() { static typename T::FacePointer fp=0; return fp; } - int &Zp(){static int z=0; return z;}; +template +class FaceTypeHolder{ + public: + typedef BVT VertexType; + typedef typename VertexType::CoordType CoordType; + typedef typename VertexType::ScalarType ScalarType; + typedef BET EdgeType; + typedef BFT FaceType; + typedef BTT TetraType; + typedef BVT *VertPointer; + typedef BET *EdgePointer; + typedef BFT *FacePointer; + typedef BTT *TetraPointer; }; -template class VFAdj: public T { -public: - //typedef A ColorType; - typename T::FacePointer &Fp() {return fp; } - typename T::FacePointer &Zp() {return Zp; } -private: - typename T::FacePointer fp ; - int zp ; -}; +/* The base class form which we start to add our components. +it has the empty definition for all the standard members (coords, color flags) +Note: +in order to avoid both virtual classes and ambiguous definitions all +the subsequent overrides must be done in a sequence of derivation. + +In other words we cannot derive and add in a single derivation step +(with multiple ancestor), both the real (non-empty) normal and color but +we have to build the type a step a time (deriving from a single ancestor at a time). -/*------------------------------------------------------------------*/ -template -class FVEmpty{ -public: -typedef BVT *VertPointer; -typedef BFT *FacePointer; -}; - -template -class Vertex: public EmptyVFAdj > > > >{ -public: +*/ +template +class FaceBase: public face::EmptyVertexRef< + face::EmptyAdj< + face::EmptyColorQuality< + face::EmptyNormal< + face::EmptyFlag< + face::EmptyWedgeTexture< + FaceTypeHolder > > > > > >{ }; +// Metaprogramming Core -template class A> class Vertex1: public A > {}; +template class A> + class FaceArity1: public A > {}; -template class A, - template class B> class Vertex2: public B > {}; +template class A, template class B> + class FaceArity2: public B > {}; -template class A, - template class B, - template class C > class Vertex3: public C > {}; +template class A, template class B, + template class C > + class FaceArity3: public C > {}; -template class A, - template class B, - template class C, - template class D > class Vertex4: public D > {}; +template class A, template class B, + template class C, template class D> + class FaceArity4: public D > {}; +template class A, template class B, + template class C, template class D, + template class E > + class FaceArity5: public E > {}; -template < typename T> -class Default : public T {}; +template class A, template class B, + template class C, template class D, + template class E, template class F > + class FaceArity6: public F > {}; -template class A, - template class B = Default, - template class C = Default, - template class D = Default> class VertexK: public Default > {}; +/* The Real Big Face class; +The class __FaceArityMax__ is the one that is the Last to be derived, +and therefore is the only one to know the real members +(after the many overrides) so all the functions with common behaviour +using the members defined in the various Empty/nonEmpty component classes +MUST be defined here. -template < typename T=int> -class DefaultQ : public T {}; - -template class A, - template class B = DefaultQ, - template class C = DefaultQ, - template class D = DefaultQ > class VertexQ: public Vertex4 {}; - -template class A - > class VertexQ: public Vertex1 {}; - -template class A, - template class B - > class VertexQ: public Vertex2 {}; - -template class A, - template class B, - template class C - > class VertexQ: public Vertex3 {}; - -//template class A, -// template class B = Default, -// template class C = Default, -// template class D = Default > class VertexZ: public Default > {}; - -/* un vertice si definisce cosi': - -Vertex2 myvertex; +I.e. IsD() that uses the overridden Flags() member must be defined here. */ +template class A, template class B, + template class C, template class D, + template class E, template class F, + template class G> +class FaceArityMax: public G > { + +// ----- Flags stuff ----- +public: + enum { + // This bit indicate that the face is deleted from the mesh + DELETED = 0x00000001, // cancellato + // This bit indicate that the face of the mesh is not readable + NOTREAD = 0x00000002, // non leggibile (ma forse modificabile) + // This bit indicate that the face is not modifiable + NOTWRITE = 0x00000004, // non modificabile (ma forse leggibile) + // This bit indicate that the face is modified + SELECTED = 0x00000020, // Selection _flags + // Border _flags, it is assumed that BORDERi = BORDER0<>1; + return true; + } + assert(0); + return false; + } + /// This function checks if the given user bit is true + bool IsUserBit(int userBit){return (Flags() & userBit) != 0;} + /// This function set the given user bit + void SetUserBit(int userBit){Flags() |=userBit;} + /// This function clear the given user bit + void ClearUserBit(int userBit){Flags() &= (~userBit);} + + }; + + +template < typename T=int> +class FaceDefaultDeriver : public T {}; + +/* + +These are the three main classes that are used by the library user to define its own Facees. +The user MUST specify the names of all the type involved in a generic complex. +so for example when defining a Face of a trimesh you must know the name of the type of the edge and of the face. +Typical usage example: + +A Face with coords, flags and normal for use in a standard trimesh: + +class MyFaceNf : public FaceSimp2< VertProto, EdgeProto, MyFaceNf, face::Flag, face::Normal3f > {}; + + +A Face with coords, and normal for use in a tetrahedral mesh AND in a standard trimesh: + +class TetraFace : public FaceSimp3< VertProto, EdgeProto, TetraFace, TetraProto, face::Coord3d, face::Normal3f > {}; + +*/ + +template class A = FaceDefaultDeriver, template class B = FaceDefaultDeriver, + template class C = FaceDefaultDeriver, template class D = FaceDefaultDeriver, + template class E = FaceDefaultDeriver, template class F = FaceDefaultDeriver, + template class G = FaceDefaultDeriver > + class FaceSimp3: public FaceArityMax {}; + +template class A = FaceDefaultDeriver, template class B = FaceDefaultDeriver, + template class C = FaceDefaultDeriver, template class D = FaceDefaultDeriver, + template class E = FaceDefaultDeriver, template class F = FaceDefaultDeriver, + template class G = FaceDefaultDeriver > + class FaceSimp2: public FaceArityMax {}; + + +}// end namespace #endif