This commit is contained in:
ganovelli 2004-07-02 17:08:12 +00:00
parent 5e3a9f5460
commit d29f584547
1 changed files with 65 additions and 61 deletions

View File

@ -1,4 +1,4 @@
/**************************************************************************** /****************************************************************************
* VCGLib o o * * VCGLib o o *
* Visual and Computer Graphics Library o o * * Visual and Computer Graphics Library o o *
* _ O _ * * _ O _ *
@ -8,7 +8,7 @@
* \ * * \ *
* All rights reserved. * * All rights reserved. *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/06/10 15:15:16 ganovelli
changes to comply dxf specs
Revision 1.1 2004/05/27 13:24:08 ganovelli Revision 1.1 2004/05/27 13:24:08 ganovelli
export_dxf created export_dxf created
@ -32,7 +35,7 @@ export_dxf created
#define __VCG_LIB_EXPORTER_DXF #define __VCG_LIB_EXPORTER_DXF
#include <stdio.h> #include <stdio.h>
/** /**
This class encapsulate a filter for saving edge meshes ad polyline in DXF format. This class encapsulate a filter for saving edge meshes ad polyline in DXF format.
*/ */
namespace vcg { namespace vcg {
@ -41,72 +44,73 @@ namespace io {
template <class EdgeMeshType> template <class EdgeMeshType>
class ExporterDXF{ class ExporterDXF{
public: public:
typedef typename EdgeMeshType::VertexPointer VertexPointer; typedef typename EdgeMeshType::VertexPointer VertexPointer;
static bool Save( EdgeMeshType &em, const char * filename){ static bool Save( EdgeMeshType &em, const char * filename){
FILE * o = fopen(filename,"w"); FILE * o = fopen(filename,"w");
if(o==NULL) if(o==NULL)
return false; return false;
// print header // print header
fprintf(o,"999\nVCGLibraryDXF\n0\nSECTION\n2\nTABLES\n0\nTABLE\n2\nLAYER\n70\n153\n0\nLAYER\n2\nthelayer\n70\n0\n62\n15\n0\nENDTAB\n0\nENDSEC\n0\nSECTION\n2\nENTITIES\n"); fprintf(o,"999\nVCGLibraryDXF\n0\nSECTION\n2\nTABLES\n0\nTABLE\n2\nLAYER\n70\n153\n0\nLAYER\n2\nthelayer\n70\n0\n62\n15\n0\nENDTAB\n0\nENDSEC\n0\nSECTION\n2\nENTITIES\n");
vcg::edge::Pos<typename EdgeMeshType::EdgeType> et; vcg::edge::Pos<typename EdgeMeshType::EdgeType> et;
typename typename EdgeMeshType::EdgePointer ep = &*em.edges.begin(),start;
typename typename EdgeMeshType::EdgeIterator ei;
int i=0,maxc=0,n_=0; typename EdgeMeshType::EdgePointer ep = &*em.edges.begin(),start;
typename EdgeMeshType::EdgeIterator ei;
for(ei = em.edges.begin(); ei != em.edges.end();++ei){(*ei).ClearS();}
for(ei = em.edges.begin(); ei != em.edges.end();++ei) int i=0,maxc=0,n_=0;
{i=1;
for(ei = em.edges.begin(); ei != em.edges.end();++ei){(*ei).ClearS();}
start = &*ei;
et.Set(&*ei,(*ei).V(0)); for(ei = em.edges.begin(); ei != em.edges.end();++ei)
if(!et.e->IsS()) {i=1;
{// nuovo contorno: trova il bordo se c'e' e posiziona li' l'hal edge
n_++; start = &*ei;
do{ et.Set(&*ei,(*ei).V(0));
ep = et.e; if(!et.e->IsS())
if(et.e->EEp(et.Z()) == et.e) {// nuovo contorno: trova il bordo se c'e' e posiziona li' l'hal edge
break; n_++;
et.NextE(); do{
}while (et.e != start); ep = et.e;
fprintf(o,"0\nPOLYLINE\n10\n0\n70\n0\n8\nthelayer\n"); if(et.e->EEp(et.Z()) == et.e)
start = et.e; break;
i=0; et.NextE();
do{ }while (et.e != start);
if(i++>maxc) fprintf(o,"0\nPOLYLINE\n10\n0\n70\n0\n8\nthelayer\n");
maxc=i; start = et.e;
et.e->SetS(); i=0;
ep = et.e; do{
OutVertex(et.e->V(et.Z()), o); if(i++>maxc)
et.NextE(); maxc=i;
}while((et.e != ep)&&(et.e !=start)&&(i<em.en)); et.e->SetS();
fprintf(o,"0\nSEQEND\n"); ep = et.e;
} OutVertex(et.e->V(et.Z()), o);
} et.NextE();
}while((et.e != ep)&&(et.e !=start)&&(i<em.en));
fprintf(o,"0\nENDSEC\n0\nEOF\n"); fprintf(o,"0\nSEQEND\n");
fclose(o); }
return 0; }
}
fprintf(o,"0\nENDSEC\n0\nEOF\n");
fclose(o);
return 0;
}
private: private:
static void OutVertex(const VertexPointer & v, FILE* o){ static void OutVertex(const VertexPointer & v, FILE* o){
fprintf(o,"0\nVERTEX\n100\nAcDb3dPolylineVertex\n70\n32\n"); fprintf(o,"0\nVERTEX\n100\nAcDb3dPolylineVertex\n70\n32\n");
int i; int i;
for(i = 0 ; i < 3; ++i) for(i = 0 ; i < 3; ++i)
fprintf(o,"%d\n%f\n",(i+1)*10,v->P()[i]); fprintf(o,"%d\n%f\n",(i+1)*10,v->P()[i]);
} }
}; };
};//vcg };//vcg
};//edge };//edge
};//io };//io
#endif #endif