| 1 | /**************************************************************************** |
| 2 | * VCGLib o o * |
| 3 | * Visual and Computer Graphics Library o o * |
| 4 | * _ O _ * |
| 5 | * Copyright(C) 2004 \/)\/ * |
| 6 | * Visual Computing Lab /\/| * |
| 7 | * ISTI - Italian National Research Council | * |
| 8 | * \ * |
| 9 | * All rights reserved. * |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | * This program is distributed in the hope that it will be useful, * |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 19 | * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * |
| 20 | * for more details. * |
| 21 | * * |
| 22 | ****************************************************************************/ |
| 23 | /**************************************************************************** |
| 24 | History |
| 25 | |
| 26 | $Log: export_dxf.h,v $ |
| 27 | Revision 1.5 2005/02/04 15:04:29 spinelli |
| 28 | corretto nome costruttore.... |
| 29 | |
| 30 | Revision 1.4 2005/02/03 11:22:34 spinelli |
| 31 | ricorretti i metodi save per rendere compatibile il formato dxf con il formato di autocad specificato nel dxf reference 2005 |
| 32 | |
| 33 | Revision 1.3 2004/07/02 17:08:12 ganovelli |
| 34 | created |
| 35 | |
| 36 | Revision 1.2 2004/06/10 15:15:16 ganovelli |
| 37 | changes to comply dxf specs |
| 38 | |
| 39 | Revision 1.1 2004/05/27 13:24:08 ganovelli |
| 40 | export_dxf created |
| 41 | |
| 42 | ****************************************************************************/ |
| 43 | #ifndef __VCG_LIB_EXPORTER_DXF |
| 44 | #define __VCG_LIB_EXPORTER_DXF |
| 45 | |
| 46 | |
| 47 | namespace vcg { |
| 48 | namespace edge { |
| 49 | namespace io { |
| 50 | |
| 51 | |
| 52 | template <class EdgeMeshType> |
| 53 | class ExporterDXF |
| 54 | { |
| 55 | public: |
| 56 | |
| 57 | ExporterDXF(void){} |
| 58 | |
| 59 | |
| 60 | |
| 61 | static bool Save(EdgeMeshType *mp, const char * filename) |
| 62 | { |
| 63 | FILE * o = fopen(filename,"w"); |
| 64 | if(o==NULL) return false; |
| 65 | fprintf(o,"0\n"); |
| 66 | fprintf(o,"SECTION\n"); |
| 67 | fprintf(o,"2\n"); |
| 68 | fprintf(o,"ENTITIES\n"); |
| 69 | |
| 70 | Save(mp,o); |
| 71 | |
| 72 | fprintf(o,"0\n"); |
| 73 | fprintf(o,"ENDSEC\n"); |
| 74 | fprintf(o,"0\n"); |
| 75 | fprintf(o,"EOF\n"); |
| 76 | fclose(o); |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | |
| 82 | static void Save(EdgeMeshType *mp, FILE* o ) |
| 83 | { |
| 84 | EdgeMeshType::EdgeIterator i; |
| 85 | for(i=mp->edges.begin(); i!=mp->edges.end();++i) |
| 86 | { |
| 87 | Point3f p1 = (*i).V(0)->P(); |
| 88 | Point3f p2 = (*i).V(1)->P(); |
| 89 | |
| 90 | |
| 91 | fprintf(o,"0\n"); |
| 92 | fprintf(o,"LINE\n"); |
| 93 | fprintf(o,"8\n"); |
| 94 | fprintf(o,"0\n"); |
| 95 | fprintf(o,"10\n"); |
| 96 | |
| 97 | fprintf(o,"%f\n", p1[0]); //X |
| 98 | fprintf(o,"20\n"); |
| 99 | fprintf(o,"%f\n", p1[1]); //Y |
| 100 | fprintf(o,"30\n"); |
| 101 | fprintf(o,"%f\n", p1[2]); //Z |
| 102 | |
| 103 | fprintf(o,"11\n"); |
| 104 | fprintf(o,"%f\n", p2[0]); //X |
| 105 | fprintf(o,"21\n"); |
| 106 | fprintf(o,"%f\n", p2[1]); //Y |
| 107 | fprintf(o,"31\n"); |
| 108 | fprintf(o,"%f\n", p2[2]); //Z |
| 109 | |
| 110 | } |
| 111 | |
| 112 | |
| 113 | |
| 114 | } |
| 115 | |
| 116 | |
| 117 | }; |
| 118 | |
| 119 | }; |
| 120 | }; |
| 121 | }; |
| 122 | #endif |