00001 
00002 #ifndef  __JBXL_CPP_MESHOBJECTDATA_H_
00003 #define  __JBXL_CPP_MESHOBJECTDATA_H_
00004 
00005 
00006 #include  "tools++.h"
00007 #include  "txml.h"
00008 
00009 #include  "TriBrep.h"
00010 #include  "Rotation.h"
00011 #include  "FacetBaseData.h"
00012 #include  "MaterialParam.h"
00013 
00014 
00015 #define   MOBJN_MTERIALID_RAND_LEN   6
00016 
00017 
00018 
00019 namespace jbxl {
00020 
00021 
00022 
00023 class  MeshObjectNode;
00024 class  MeshObjectData;
00025 
00026 
00027 
00029 
00030 
00031 
00037 class  MeshObjectNode
00038 {
00039 public:
00040     Buffer  material_id;            
00041     bool    same_material;          
00042 
00043     int     facet_no;               
00044     MaterialParam material_param;   
00045 
00046     int     num_index;              
00047     int     num_polygon;            
00048     int     num_vertex;             
00049     int     num_texcrd;             
00050 
00051     int*    data_index;             
00052 
00053     Vector<double>* vertex_value;   
00054     Vector<double>* normal_value;   
00055     UVMap<double>*  texcrd_value;   
00056 
00057     MeshObjectNode* next;
00058     MeshObjectNode* prev;
00059 
00060 public:
00061     MeshObjectNode(void) { init();}
00062     virtual ~MeshObjectNode(void) {}
00063 
00064     void    init(void);
00065     void    free(void);
00066     void    free_value(void);
00067     void    clear(void);
00068 
00069     void    set (int vertex,   int polygon,   int vcount=3);
00070     bool    getm(int vertex=0, int polygon=0, int vcount=0);
00071 
00072     
00073     void    setFacetNo(int no) { if (no>=0) facet_no = no;}
00074     void    setMaterialParam(MaterialParam param);
00075     void    delMaterialParam(void) { material_param.clear();}
00076 
00077     void    setMaterialID(const char* str);
00078     void*   getMaterialID(void) { return _tochar(material_id.buf);}
00079 
00080     void    execAffineTrans(UVMap<double>* uvmap=NULL, int num=-1);
00081     UVMap<double>*  generatePlanarUVMap(Vector<double> scale, UVMap<double>* uvmap=NULL);
00082 
00083 public:
00084     bool    computeVertexDirect(FacetBaseData* facetdata);
00085     bool    computeVertexDirect(Vector<double>* vtx, Vector<double>* nml, UVMap<double>* map, int num, int vcount=3);
00086     bool    computeVertexByBREP(Vector<double>* vtx, Vector<double>* nml, UVMap<double>* map, int num, int vcount=3);
00087 };
00088 
00089 
00090 inline void  freeMeshObjectNode(MeshObjectNode*& node) { if(node!=NULL) { node->free(); delete node; node=NULL;} }
00091 void  freeMeshObjectList(MeshObjectNode*& node);
00092 
00093 MeshObjectNode*  DelMeshObjectNode(MeshObjectNode* node);
00094 MeshObjectNode*  AddMeshObjectNode(MeshObjectNode* list, MeshObjectNode* node);
00095 
00096 
00097 
00098 
00100 
00101 
00102 
00106 class  MeshObjectData
00107 {
00108 public:
00109     Buffer  data_name;                  
00110 
00111     int     ttl_index;                  
00112     int     ttl_vertex;                 
00113     int     ttl_texcrd;                 
00114     int     num_node;                   
00115     int     num_vcount;                 
00116 
00117     MeshObjectNode* nodelist;           
00118     MeshObjectNode* endplist;           
00119 
00120     AffineTrans<double>* affine_trans;  
00121 
00122 private: 
00123     int     num_import;                 
00124 
00125     Vector<double>* impvtx_value;       
00126     Vector<double>* impnrm_value;       
00127     UVMap<double>*  impmap_value;       
00128 
00129 public:
00130     MeshObjectData(const char* name=NULL) { init(name);}
00131     virtual ~MeshObjectData(void)   {}
00132 
00133     void    init(const char* name=NULL);
00134     void    free(void);
00135     void    free_value(void);
00136     void    clear(void);
00137 
00138     
00139     void    setName(const char* str) { free_Buffer(&data_name); data_name=make_Buffer_str(str);}
00140     char*   getName(void) { return _tochar(data_name.buf);}
00141     
00142     void    setAffineTrans(AffineTrans<double> a) { delAffineTrans(); affine_trans=new AffineTrans<double>(); affine_trans->dup(a);}
00143     void    delAffineTrans(void) { freeAffineTrans(affine_trans);}
00144 
00145 public:
00146     bool    addData(FacetBaseData* facetdata, MaterialParam* param);
00147     bool    addData(Vector<double>* vct, Vector<double>* nrm, UVMap<double>* map, int vnum, MaterialParam* param, bool useBrep);
00148     bool    addData(TriPolyData* tridata, int tnum, int fnum, MaterialParam* param, bool useBrep);  
00149 
00150     void    joinData(MeshObjectData*& data);    
00151     void    setMaterialParam(MaterialParam param, int num=-1);
00152     
00153     bool    importTriData(TriPolyData* tridata, int tnum, int fnum=-1);
00154     bool    importTriData(Vector<double>* vct, Vector<double>* nrm, UVMap<double>* map, int vnum);
00155     bool    addNode(FacetBaseData* facetdata, const char* name);
00156     bool    addNode(const char* name, bool useBrep);
00157 };
00158 
00159 
00160 inline void  freeMeshObjectData(MeshObjectData*& data) { if(data!=NULL) { data->free(); delete data; data=NULL;} }
00161 
00162 
00163 
00164 }       
00165 
00166 #endif
00167