00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __VCGLIB_EXPORT_DXF
00029 #define __VCGLIB_EXPORT_DXF
00030
00031 namespace vcg {
00032 namespace tri {
00033 namespace io {
00034
00035 template <class SaveMeshType>
00039 class ExporterDXF
00040 {
00041 public:
00043 static int Save(SaveMeshType &m, const char * filename)
00044 {
00045
00046 FILE * o = fopen(filename,"w");
00047 if(o==NULL) return 1;
00048 fprintf(o,"0\n");
00049 fprintf(o,"SECTION\n");
00050 fprintf(o,"2\n");
00051 fprintf(o,"ENTITIES\n");
00052
00053 typename SaveMeshType::FaceIterator fi;
00054 for(fi=m.face.begin(); fi!=m.face.end(); ++fi)
00055 {
00056 if (!fi->IsD())
00057 {
00058 typename SaveMeshType::CoordType v0 = (*fi).V(0)->P();
00059 typename SaveMeshType::CoordType v1 = (*fi).V(1)->P();
00060 typename SaveMeshType::CoordType v2 = (*fi).V(2)->P();
00061 fprintf(o,"0\n"); fprintf(o,"3DFACE\n"); fprintf(o,"8\n"); fprintf(o,"0\n");
00062 fprintf(o,"10\n"); fprintf(o,"%f\n", v0[0]);
00063 fprintf(o,"20\n"); fprintf(o,"%f\n", v0[1]);
00064 fprintf(o,"30\n"); fprintf(o,"%f\n", v0[2]);
00065
00066 fprintf(o,"11\n"); fprintf(o,"%f\n", v1[0]);
00067 fprintf(o,"21\n"); fprintf(o,"%f\n", v1[1]);
00068 fprintf(o,"31\n"); fprintf(o,"%f\n", v1[2]);
00069
00070 fprintf(o,"12\n"); fprintf(o,"%f\n", v2[0]);
00071 fprintf(o,"22\n"); fprintf(o,"%f\n", v2[1]);
00072 fprintf(o,"32\n"); fprintf(o,"%f\n", v2[2]);
00073
00074 fprintf(o,"13\n"); fprintf(o,"%f\n", v2[0]);
00075 fprintf(o,"23\n"); fprintf(o,"%f\n", v2[1]);
00076 fprintf(o,"33\n"); fprintf(o,"%f\n", v2[2]);
00077 }
00078 }
00079
00080 fprintf(o,"0\n");
00081 fprintf(o,"ENDSEC\n");
00082 fprintf(o,"0\n");
00083 fprintf(o,"EOF\n");
00084 fclose(o);
00085 return 0;
00086 }
00088 static const char *ErrorMsg(int error)
00089 {
00090 static std::vector<std::string> dxf_error_msg;
00091 if(dxf_error_msg.empty())
00092 {
00093 dxf_error_msg.resize(2 );
00094 dxf_error_msg[0]="No errors";
00095 dxf_error_msg[1]="Can't open file";
00096 }
00097
00098 if(error>1 || error<0) return "Unknown error";
00099 else return dxf_error_msg[error].c_str();
00100 }
00101
00102
00103 };
00104
00105 }
00106 }
00107 }
00108
00109 #endif