1 #ifndef CELL_ATTRIBUTES_H
2 #define CELL_ATTRIBUTES_H
3 
4 #include "cell.h"
5 
6 
7 
8 /* the correspondences between names of the chains in Cell::perVertex_attributes and Cell::perFace_attributes
9    with the access memebers of BertexType and FaceType are fixed and determined in this file
10    */
11 
12 template <class VertexType>
ExportVertexAttribute(std::string attr_name,const unsigned int & i,VertexType & v)13     void Cell::ExportVertexAttribute(std::string attr_name, const unsigned int & i, VertexType & v ){
14     if( attr_name == std::string("Normal3f"))   {  GetVertexAttribute(std::string("Normal3f"),i,&v.N());   return;}
15     if( attr_name == std::string("Color4b"))    {  GetVertexAttribute(std::string("Color4b"),i,&v.C());    return;}
16     sprintf(lgn->Buf(),"Vertex Attribute %s not implemented\n",attr_name.c_str());
17     lgn->Push();
18 }
19 
20 template <class FaceType>
ExportFaceAttribute(std::string attr_name,const unsigned int & i,FaceType & f)21     void Cell::ExportFaceAttribute(std::string attr_name, const unsigned int & i, FaceType & f ){
22     if( attr_name == std::string("Normal3f"))   { GetFaceAttribute(std::string("Normal3f"),i,&f.N());   return;}
23     if( attr_name == std::string("Color4b"))    { GetFaceAttribute(std::string("Color4b"),i,&f.C());    return;}
24     sprintf(lgn->Buf(),"Face Attribute %s not implemented\n",attr_name.c_str());
25     lgn->Push();
26 }
27 
28 
29 template <class VertexType>
ImportVertexAttribute(std::string attr_name,const unsigned int & i,VertexType & v)30     void Cell::ImportVertexAttribute(std::string attr_name, const unsigned int & i, VertexType & v ){
31     if( attr_name == std::string("Normal3f"))   {SetVertexAttribute(std::string("Normal3f"),i,&v.N()); return;}
32     if( attr_name == std::string("Color4b"))    {SetVertexAttribute(std::string("Color4b"),i,&v.C()); return;}
33     sprintf(lgn->Buf(),"Vertex Attribute %s not implemented\n",attr_name.c_str());
34     lgn->Push();
35 }
36 
37 template <class FaceType>
ImportFaceAttribute(std::string attr_name,const unsigned int & i,FaceType & f)38     void Cell::ImportFaceAttribute(std::string attr_name, const unsigned int & i, FaceType & f ){
39     if( attr_name == std::string("Normal3f"))   { SetFaceAttribute(std::string("Normal3f"),i,&f.N());  return;}
40     if( attr_name == std::string("Color4b"))    { SetFaceAttribute(std::string("Color4b") ,i,&f.C());  return;}
41     sprintf(lgn->Buf(),"Face Attribute %s not implemented\n",attr_name.c_str());
42     lgn->Push();
43 }
44 
45 
46 /*
47 
48   */
49 
50 struct AttributeMapper{
51 
52     std::vector<std::string> vert_attrs;
53     std::vector<std::string> face_attrs;
54 
55 
56     /* Import / Export functions */
57     template <class VertexType>
ImportVertexAttributeMapper58     void ImportVertex(Cell*c,VertexType & v, const unsigned int & pos){
59         std::vector<std::string>::iterator ai;
60         for(ai = vert_attrs.begin(); ai != vert_attrs.end(); ++ai)
61             c->ImportVertexAttribute((*ai),pos,v);
62     }
63 
64     template <class FaceType>
ImportFaceAttributeMapper65     void ImportFace(Cell*c,FaceType & v, const unsigned int & pos){
66         std::vector<std::string>::iterator ai;
67         for(ai = face_attrs.begin(); ai != face_attrs.end(); ++ai)
68             c->ImportFaceAttribute((*ai),pos,v);
69     }
70 
71     template <class VertexType>
ExportVertexAttributeMapper72     void ExportVertex(Cell*c,VertexType & v, const unsigned int & pos){
73         std::vector<std::string>::iterator ai;
74         for(ai = vert_attrs.begin(); ai != vert_attrs.end(); ++ai)
75             c->ExportVertexAttribute((*ai),pos,v);
76     }
77 
78     template <class FaceType>
ExportFaceAttributeMapper79     void ExportFace(Cell*c,FaceType & v, const unsigned int & pos){
80         std::vector<std::string>::iterator ai;
81         for(ai = face_attrs.begin(); ai != face_attrs.end(); ++ai)
82             c->ExportFaceAttribute((*ai),pos,v);
83     }
84 
85 
86 };
87 
88 
89 #endif // CELL_ATTRIBUTES_H
90