Initial commit
This commit is contained in:
parent
a34f7765b3
commit
b692bdb420
|
@ -0,0 +1,57 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/** Function to save to Smf format file.
|
||||
@param filename Name of the new Smf file
|
||||
*/
|
||||
void Save_Smf(const char * filename)
|
||||
{
|
||||
FILE *fp;
|
||||
fp = fopen(filename,"wb");
|
||||
fprintf(fp,"#SMF \n" );
|
||||
|
||||
face_iterator fi;
|
||||
vertex_iterator vi;
|
||||
map<vertex_pointer,int> index;
|
||||
int ind;
|
||||
|
||||
for(ind=1,vi=vert.begin(); vi!=vert.end(); ++vi,++ind)
|
||||
{
|
||||
fprintf(fp,"v " );
|
||||
fprintf(fp,"%f%s",(*vi).P()[0]," " );
|
||||
fprintf(fp,"%f%s",(*vi).P()[1]," " );
|
||||
fprintf(fp,"%f%s",(*vi).P()[2],"\n");
|
||||
index[&*vi] = ind;
|
||||
}
|
||||
|
||||
for (fi=face.begin(); fi!=face.end(); ++fi)
|
||||
{
|
||||
fprintf(fp,"%s","f ");
|
||||
for (int j = 0; j < 3; j++)
|
||||
fprintf(fp,"%i%s",index[(*fi).V(j)]," ");
|
||||
fprintf(fp,"%s","\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
bool Save_STL(const char * filename , bool binary =true, const char *objectname=0)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(filename,"wb");
|
||||
if(fp==0)
|
||||
return false;
|
||||
|
||||
if(binary)
|
||||
{
|
||||
// Write Header
|
||||
char *header="VCG ";
|
||||
if(objectname) strncpy(header,objectname,80);
|
||||
fwrite(header,80,1,fp);
|
||||
// write number of facets
|
||||
fwrite(&fn,1,sizeof(int),fp);
|
||||
face_iterator fi;
|
||||
Point3f p;
|
||||
unsigned short attributes=0;
|
||||
|
||||
for(fi=face.begin(); fi!=face.end(); ++fi) if( !(*fi).IsD() )
|
||||
{
|
||||
// For each triangle write the normal, the three coords and a short set to zero
|
||||
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P()));
|
||||
fwrite(p.V(),3,sizeof(float),fp);
|
||||
|
||||
for(int k=0;k<3;++k){
|
||||
p.Import((*fi).V(k)->P());
|
||||
fwrite(p.V(),3,sizeof(float),fp);
|
||||
}
|
||||
fwrite(&attributes,1,sizeof(short),fp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(objectname) fprintf(fp,"solid %s\n",objectname);
|
||||
else fprintf(fp,"solid vcg\n");
|
||||
|
||||
Point3f p;
|
||||
face_iterator fi;
|
||||
for(fi=face.begin(); fi!=face.end(); ++fi) if( !(*fi).IsD() )
|
||||
{
|
||||
// For each triangle write the normal, the three coords and a short set to zero
|
||||
p.Import(vcg::NormalizedNormal((*fi).V(0)->P(), (*fi).V(1)->P(), (*fi).V(2)->P()));
|
||||
fprintf(fp," facet normal %13e %13e %13e\n",p[0],p[1],p[2]);
|
||||
fprintf(fp," outer loop\n");
|
||||
for(int k=0;k<3;++k){
|
||||
p.Import((*fi).V(k)->P());
|
||||
fprintf(fp," vertex %13e %13e %13e\n",p[0],p[1],p[2]);
|
||||
}
|
||||
fprintf(fp," endloop\n");
|
||||
fprintf(fp," endfacet\n");
|
||||
}
|
||||
fprintf(fp,"endsolid vcg\n");
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
//@}
|
|
@ -0,0 +1,78 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/** Function to load a Smf file
|
||||
@param filename Name of Smf file
|
||||
*/
|
||||
int Load_Smf( const char * filename )
|
||||
{
|
||||
char buf[1024];
|
||||
FILE *fp;
|
||||
float x,y,z;
|
||||
bool one = true;
|
||||
map<int,vertex_pointer> mv;
|
||||
|
||||
fp = fopen(filename,"r");
|
||||
|
||||
if(!fp) return -1;
|
||||
|
||||
vertex_type v;
|
||||
v.Supervisor_Flags() = 0;
|
||||
face_type f;
|
||||
f.Supervisor_Flags() = 0;
|
||||
|
||||
while( fgets(buf,1024,fp) )
|
||||
{
|
||||
char *vf, *comm_pt;
|
||||
|
||||
if((comm_pt = strstr(buf,"#")) != NULL)
|
||||
*comm_pt = '\0';
|
||||
if( (vf = strstr(buf,"v")) != NULL )
|
||||
{
|
||||
sscanf(vf+1,"%f %f %f", &x, &y, &z);
|
||||
v.P()[0] = x;
|
||||
v.P()[1] = y;
|
||||
v.P()[2] = z;
|
||||
vert.push_back(v);
|
||||
}
|
||||
else if( (vf = strstr(buf,"f")) != NULL)
|
||||
{
|
||||
if(one)
|
||||
{
|
||||
vertex_iterator vi;
|
||||
int ind;
|
||||
for(ind=1,vi=vert.begin(); vi!=vert.end(); ++vi,++ind)
|
||||
mv[ind]=&*vi;
|
||||
one = false;
|
||||
}
|
||||
int v1,v2,v3;
|
||||
sscanf(vf+1,"%d %d %d", &v1, &v2, &v3);
|
||||
f.V(0) = mv[v1];
|
||||
f.V(1) = mv[v2];
|
||||
f.V(2) = mv[v3];
|
||||
face.push_back(f);
|
||||
}
|
||||
}
|
||||
vn = vert.size();
|
||||
fn = face.size();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* 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 *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
This folders contains most common FACE configuration files
|
||||
The name of the file specify the members that are added to the vertex class
|
||||
The name is a sequence of letters, in strict alphabetical order.
|
||||
The possible admitted letters pairs are
|
||||
|
||||
FA - face-face adjacency
|
||||
FC - Per-Face Color
|
||||
FN - Per-Face Normal
|
||||
FQ - Per-Face Quality
|
||||
VA - Vertex-face adjacency
|
||||
WC - Per-Wedge Color
|
||||
WN - Per-Wedge Normal
|
||||
WQ - Per-Wedge Quality
|
||||
WT - Per-Wedge Texture Coords
|
||||
SA - Shared Vertex-Face and Face-Face Adjacency
|
||||
RT - Data for Optimized Point-Face Distance and Ray-Tracing Stuff
|
||||
|
||||
E.g.
|
||||
|
||||
#include<vcg/simplex/vertex/with/fafnwc.h>
|
||||
|
||||
generate a type
|
||||
VertexFAFNWC<VertexType>
|
||||
|
||||
that can store F-F adjacency, Per face normal color and per wedge color.
|
||||
|
||||
|
Loading…
Reference in New Issue