Go to the documentation of this file.
17 #include <assimp/cimport.h>
18 #include <assimp/scene.h>
19 #include <assimp/postprocess.h>
165 void ProcessSceneNode( unsigned int *oV, unsigned int *oF,
166 Tpolyhedron *p, const struct aiScene *sc, const struct aiNode *nd);
168 void ProcessSceneNode( unsigned int *oV, unsigned int *oF,
169 Tpolyhedron *p, const struct aiScene *sc, const struct aiNode *nd)
173 const struct aiMesh *mesh;
174 unsigned int ndxV,ndxF;
198 for(k=0;k<nd->mNumMeshes;k++)
200 mesh=sc->mMeshes[nd->mMeshes[k]];
202 for(i=0;i<mesh->mNumVertices;i++)
205 NEW(p-> v[ndxV],3, double);
206 p-> v[ndxV][0]=(double)mesh->mVertices[i].x;
207 p-> v[ndxV][1]=( double)mesh->mVertices[i].y;
208 p-> v[ndxV][2]=(double)mesh->mVertices[i].z;
213 for(i=0;i<mesh->mNumFaces;i++)
216 p-> nvf[ndxF]=mesh->mFaces[i].mNumIndices;
217 NEW(p-> fv[ndxF],p-> nvf[i], unsigned int);
218 for(j=0;j<p-> nvf[ndxF];j++)
219 p-> fv[ndxF][j]=((*oV)+mesh->mFaces[i].mIndices[j]);
221 (*oV)+=mesh->mNumVertices;
222 (*oF)+=mesh->mNumFaces;
226 for(i=0;i<nd->mNumChildren;i++)
227 ProcessSceneNode(oV,oF,p,sc,nd->mChildren[i]);
236 const struct aiScene *sc;
240 sc=aiImportFile(fn,aiProcess_Triangulate);
244 const struct aiMesh *mesh;
245 unsigned int k,oV,oF;
255 for(k=0;k<sc->mNumMeshes;k++)
259 p-> nv+=mesh->mNumVertices;
260 p-> nf+=mesh->mNumFaces;
269 NEW(p-> fv,p-> nf, unsigned int*);
274 ProcessSceneNode(&oV,&oF,p,sc,sc->mRootNode);
279 Error( "Error reading the geometry file");
281 Error( "The assimp library is missing");
293 unsigned int nt,i,j,k;
299 Error( "Can not open STL file");
303 fread(header, sizeof( char),5,f);
305 if (strcasecmp(header, "SOLID")==0)
306 Error( "Can not read ASCII STL files yet");
308 fread(header, sizeof( char),75,f);
311 fread(&nt, sizeof( int),1,f);
318 NEW(p-> v,nt, double*);
321 NEW(p-> nvf,nt, unsigned int);
322 NEW(p-> fv,nt, unsigned int*);
327 fread(v, sizeof( float),3,f);
330 NEW(p-> fv[i],p-> nvf[i], unsigned int);
335 fread(v, sizeof( float),3,f);
343 while((!found)&&(k<p-> nv))
351 NEW(p-> v[k],3, double);
361 fread(&u, sizeof( short),1,f);
373 fscanf(f, "%u",&(p-> nv));
374 fscanf(f, "%u",&(p-> nf));
375 fscanf(f, "%u",&(p-> ne));
376 if ((p-> nv==0)||(p-> nf==0))
382 NEW(p-> v[i],3, double);
383 fscanf(f, "%lf",&(p-> v[i][0]));
384 fscanf(f, "%lf",&(p-> v[i][1]));
385 fscanf(f, "%lf",&(p-> v[i][2]));
389 NEW(p-> fv,p-> nf, unsigned int*);
392 fscanf(f, "%u",&(p-> nvf[i]));
394 Error( "Empty face in OFF");
395 NEW(p-> fv[i],p-> nvf[i], unsigned int);
397 for(j=0;j<p-> nvf[i];j++)
398 fscanf(f, "%u",&(p-> fv[i][j]));
406 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
407 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
424 unsigned int i,j,k,n;
429 Error( "Using GenerateCylinderOFF in a non cylindric/line convex polyhedron");
438 NEW(p-> v[i],3, double);
439 NEW(p-> v[n+i],3, double);
444 a=((double)i/( double)n)* M_2PI;
445 p-> v[i][1]=p-> v[n+i][1]=cos(a);
446 p-> v[i][2]=p-> v[n+i][2]=sin(a);
462 NEW(p-> fv,p-> nf, unsigned int*);
469 NEW(p-> fv[i],4, unsigned int);
480 NEW(p-> fv[k],3, unsigned int);
489 NEW(p-> fv[k],3, unsigned int);
514 fscanf(f, "%lf",&(p-> p1[0]));
515 fscanf(f, "%lf",&(p-> p1[1]));
516 fscanf(f, "%lf",&(p-> p1[2]));
518 fscanf(f, "%lf",&(p-> p2[0]));
519 fscanf(f, "%lf",&(p-> p2[1]));
520 fscanf(f, "%lf",&(p-> p2[2]));
536 fscanf(f, "%u",&(p-> nv));
541 NEW(p-> v[i],3, double);
542 fscanf(f, "%lf",&(p-> v[i][0]));
543 fscanf(f, "%lf",&(p-> v[i][1]));
544 fscanf(f, "%lf",&(p-> v[i][2]));
563 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
564 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
576 fscanf(f, "%lf",&(p-> rad));
578 fscanf(f, "%lf",&(p-> p1[0]));
579 fscanf(f, "%lf",&(p-> p1[1]));
580 fscanf(f, "%lf",&(p-> p1[2]));
582 fscanf(f, "%lf",&(p-> p2[0]));
583 fscanf(f, "%lf",&(p-> p2[1]));
584 fscanf(f, "%lf",&(p-> p2[2]));
595 unsigned int i,j,k,in,r1,r2,n,m;
601 Error( "Using GenerateSphereOFF in a non spheric convex polyhedron");
607 offset= M_PI/((double)n-1);
610 NEW(meridian,n, double*);
613 NEW(meridian[i],3, double);
614 meridian[i][0]=p-> rad*cos(a);
616 meridian[i][2]=p-> rad*sin(a);
624 NEW(p-> v[i],3, double);
627 offset= M_2PI/(double)m;
652 NEW(p-> fv,p-> nf, unsigned int*);
667 NEW(p-> fv[k],3, unsigned int);
677 NEW(p-> fv[k],3, unsigned int);
685 NEW(p-> fv[k],4, unsigned int);
713 fscanf(f, "%lf",&(p-> rad));
715 fscanf(f, "%lf",&(p-> center[0]));
716 fscanf(f, "%lf",&(p-> center[1]));
717 fscanf(f, "%lf",&(p-> center[2]));
720 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
721 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
742 if ((ext==NULL)||(strcasecmp(ext, "OFF")==0))
750 boolean off, cylinder,sphere,line,segments;
756 Error( "Could not open Polyhedron file");
760 off=(strcasecmp(stmp, "OFF")==0);
761 cylinder=(strcasecmp(stmp, "CYLINDER")==0);
762 sphere=(strcasecmp(stmp, "SPHERE")==0);
763 line=(strcasecmp(stmp, "LINE")==0);
764 segments=(strcasecmp(stmp, "SEGMENTS")==0);
766 if ((!off)&&(!cylinder)&&(!sphere)&&(!line)&&(!segments))
767 Error( "Unknow type of shape");
791 Error( "Error reading geometry from file in InitPolyhedronFromFile");
793 if (strcasecmp(ext, "STL")==0)
796 Error( "Unknown file type in InitPolyhedronFromFile. Try compiling with the Assimp library");
802 unsigned int nt, unsigned int **t,
821 NEW(p-> v[i],3, double);
827 NEW(p-> fv,p-> nf, unsigned int*);
831 NEW(p-> fv[i],p-> nvf[i], unsigned int);
841 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
842 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
857 void NewBox( double xl, double yl, double zl,
858 double xu, double yu, double zu,
864 if ((xu<=xl)||(yu<=yl)||(zu<=zl))
865 Error( "Incorrect ranges in the box definition");
879 NEW(p-> v[i],3, double);
881 p-> v[0][0]=xl; p-> v[0][1]=yl; p-> v[0][2]=zl;
882 p-> v[1][0]=xl; p-> v[1][1]=yu; p-> v[1][2]=zl;
883 p-> v[2][0]=xu; p-> v[2][1]=yu; p-> v[2][2]=zl;
884 p-> v[3][0]=xu; p-> v[3][1]=yl; p-> v[3][2]=zl;
885 p-> v[4][0]=xl; p-> v[4][1]=yl; p-> v[4][2]=zu;
886 p-> v[5][0]=xl; p-> v[5][1]=yu; p-> v[5][2]=zu;
887 p-> v[6][0]=xu; p-> v[6][1]=yu; p-> v[6][2]=zu;
888 p-> v[7][0]=xu; p-> v[7][1]=yl; p-> v[7][2]=zu;
891 NEW(p-> fv,p-> nf, unsigned int*);
895 NEW(p-> fv[i],p-> nvf[i], unsigned int);
898 p-> fv[0][0]=0; p-> fv[0][1]=1; p-> fv[0][2]=2; p-> fv[0][3]=3;
899 p-> fv[1][0]=6; p-> fv[1][1]=5; p-> fv[1][2]=4; p-> fv[1][3]=7;
900 p-> fv[2][0]=3; p-> fv[2][1]=2; p-> fv[2][2]=6; p-> fv[2][3]=7;
901 p-> fv[3][0]=2; p-> fv[3][1]=1; p-> fv[3][2]=5; p-> fv[3][3]=6;
902 p-> fv[4][0]=4; p-> fv[4][1]=5; p-> fv[4][2]=1; p-> fv[4][3]=0;
903 p-> fv[5][0]=3; p-> fv[5][1]=0; p-> fv[5][2]=4; p-> fv[5][3]=7;
910 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
911 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
943 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
944 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
1018 NEW(p-> v,n, double*);
1021 NEW(p-> v[i],3, double);
1029 for(i=0;i<p-> nv;i++)
1033 av=fabs(p-> v[i][j]);
1042 p-> p1[0]=p-> p1[1]=p-> p1[2]=0.0;
1043 p-> p2[0]=p-> p2[1]=p-> p2[2]=0.0;
1064 p_dst-> nv=p_src-> nv;
1065 p_dst-> nf=p_src-> nf;
1066 p_dst-> ne=p_src-> ne;
1070 NEW(p_dst-> v,p_src-> nv, double*);
1071 for(i=0;i<p_dst-> nv;i++)
1073 NEW(p_dst-> v[i],3, double);
1074 p_dst-> v[i][0]=p_src-> v[i][0];
1075 p_dst-> v[i][1]=p_src-> v[i][1];
1076 p_dst-> v[i][2]=p_src-> v[i][2];
1084 NEW(p_dst-> nvf,p_dst-> nf, unsigned int);
1085 NEW(p_dst-> fv,p_dst-> nf, unsigned int*);
1086 for(i=0;i<p_dst-> nf;i++)
1088 p_dst-> nvf[i]=p_src-> nvf[i];
1089 NEW(p_dst-> fv[i],p_dst-> nvf[i], unsigned int);
1091 for(j=0;j<p_dst-> nvf[i];j++)
1092 p_dst-> fv[i][j]=p_src-> fv[i][j];
1106 p_dst-> p1[i]=p_src-> p1[i];
1107 p_dst-> p2[i]=p_src-> p2[i];
1125 for(i=0;i<p-> nv;i++)
1130 av=fabs(p-> v[i][j]);
1148 Error( "GetPolyhedronCenter is only defined for spheres");
1176 unsigned int **nvf, unsigned int ***fv, Tpolyhedron *p)
1199 Error( "Point counter out of range in GetPolyhedronDefiningPoint");
1215 Error( "Point counter out of range in GetPolyhedronDefiningPoint");
1227 Error( "Undefined Polyhedron type in GetPolyhedronDefiningPoint");
1235 Error( "Radius is not defined for OFFs,LINEs, or SEGMENTS");
1244 Error( "Vertex counter out of range");
1247 point[j]=p-> v[i][j];
1293 fprintf(f, "%.16f %.16f %.16f\n",v[0],v[1],v[2]);
1305 fprintf(f, "%.16f %.16f %.16f %.16f\n",v[0],v[1],v[2],p-> rad);
1320 f=fopen(fileName, "w");
1322 Error( "Could not open output file for a convex polyhedron");
1328 fprintf(f, "%u %u 1\n",p-> nv,p-> nf);
1329 for(i=0;i<p-> nv;i++)
1330 fprintf(f, "%f %f %f\n",p-> v[i][0],p-> v[i][1],p-> v[i][2]);
1332 for(i=0;i<p-> nf;i++)
1334 fprintf(f, "%u ",p-> nvf[i]);
1335 for(j=0;j<p-> nvf[i];j++)
1336 fprintf(f, " %u",p-> fv[i][j]);
1341 fprintf(f, "LINE\n");
1342 fprintf(f, "%.16f %.16f %.16f\n",p-> p1[0],p-> p1[1],p-> p1[2]);
1343 fprintf(f, "%.16f %.16f %.16f\n",p-> p2[0],p-> p2[1],p-> p2[2]);
1346 fprintf(f, "CYLINDER\n");
1347 fprintf(f, "%.16f\n",p-> rad);
1348 fprintf(f, "%.16f %.16f %.16f\n",p-> p1[0],p-> p1[1],p-> p1[2]);
1349 fprintf(f, "%.16f %.16f %.16f\n",p-> p2[0],p-> p2[1],p-> p2[2]);
1352 fprintf(f, "SPHERE\n");
1353 fprintf(f, "%.16f\n",p-> rad);
1357 fprintf(f, "SEGMENTS\n");
1358 fprintf(f, "%u\n",p-> nv);
1359 for(i=0;i<p-> nv;i++)
1360 fprintf(f, "%f %f %f\n",p-> v[i][0],p-> v[i][1],p-> v[i][2]);
1390 NEW(pname,l+30, char);
1391 sprintf(pname, "bodies/%s_%u",label,n);
1396 sprintf(pname, "bodies/_body_%u",n);
1409 fprintf(f, "line (");
1416 fprintf(f, "cylinder %g (",p-> rad);
1423 fprintf(f, "sphere %g (",p-> rad);
1443 fprintf(f, "segments (");
1450 if (((i-s)%2)==1) fprintf(f, "\n ");
1453 fprintf(f, ") color (%g,%g,%g)\n ",
1464 fprintf(f, " color (%g,%g,%g)",
1472 fprintf(f, " hidden");
1475 fprintf(f, " decoration");
1478 Error( "Unknown body disply status in PrintPolyhedron");
1490 for(i=0;i<p-> nv;i++)
1497 for(i=0;i<p-> nf;i++)
Definition of the boolean type.
void GetPolyhedronDefiningPoint(unsigned int i, double *point, Tpolyhedron *p) Gets a point defining a a object.
void PolyhedronPrintCenterAndCenter(FILE *f, THTransform *t, Tpolyhedron *p) Prints the center and the radius of a sphere to a file.
Definition of basic functions.
void PrintPolyhedron(FILE *f, char *path, char *label, unsigned int n, Tpolyhedron *p) Stores the polyhedron information into a file.
void GetOFFInfo(unsigned int *nv, double ***v, unsigned int *nf, unsigned int **nvf, unsigned int ***fv, Tpolyhedron *p) Gets the OFF information.
#define NEW(_var, _n, _type) Allocates memory space.
Data structure to hold the information about the name of a file.
void PolyhedronPrintCenter(FILE *f, THTransform *t, Tpolyhedron *p) Prints the center of a sphere to a file.
void ReadSphere(FILE *f, unsigned int g, Tpolyhedron *p) Constructor.
void GetPolyhedronColor(Tcolor *c, Tpolyhedron *p) Gets the color of a polyhedron.
void PlotSegments(unsigned int n, double **pt, Tplot3d *p) Adds a collecion of segments to the current object.
double GetGreen(Tcolor *c) Gets the green component of a color.
#define OFF_EXT File extension for geomview OFF files.
#define NORMAL_SHAPE One of the possible type of shapes.
void GetPolyhedronCenter(double *c, Tpolyhedron *p) Gets the center of the spheres.
double GetPolyhedronRadius(Tpolyhedron *p) Returns the radius used in the definition of the object.
#define CYLINDER One of the possible type of polyhedrons.
void Error(const char *s) General error function.
void CopyColor(Tcolor *c_dst, Tcolor *c_src) Copy constructor.
void PlotLine(double x0, double y0, double x1, double y1, Tplot *p) Plots a segment.
#define OFF One of the possible type of polyhedrons.
void PlotSphere(double r, double x, double y, double z, Tplot3d *p) Adds a sphere to the current object.
#define SEGMENTS One of the possible type of polyhedrons.
void CopyPolyhedron(Tpolyhedron *p_dst, Tpolyhedron *p_src) Copy constructor.
unsigned int GetPolyhedronNVertex(Tpolyhedron *p) Gets the number of vertexes of a polyhedron.
void ReadLine(FILE *f, Tpolyhedron *p) Constructor.
#define LINE One of the possible type of polyhedrons.
void Move3dObject(unsigned int nobj, THTransform *t, Tplot3d *p) Moves a 3d object.
Error and warning functions.
void DeleteFileName(Tfilename *fn) Destructor.
void ReadSTL(char *fn, Tpolyhedron *p) Constructor.
void ReadCylinder(FILE *f, unsigned int g, Tpolyhedron *p) Constructor.
void PlotPolyhedron(Tplot3d *pt, Tpolyhedron *p) Adds the polyhedron to a 3D geometry.
double Distance(unsigned int s, double *v1, double *v2) Computes the distance of two points.
unsigned int GetPolyhedronStatus(Tpolyhedron *p) Gets the status of a polyhedron (NORMAL, HIDDEN, DECOR).
boolean ReadGeneralMesh(char *fn, Tpolyhedron *p) Constructor.
void NewSphere(double r, double *center, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p) Constructor.
void ReadOFF(FILE *f, Tpolyhedron *p) Constructor.
void NewCylinder(double r, double *p1, double *p2, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p) Constructor.
void GenerateCylinderOFF(unsigned int g, Tpolyhedron *p) Generates an OFF that approximates a cylinder.
void MovePolyhedron(Tplot3d *pt, THTransform *t, Tpolyhedron *p) Moves an object previously added to a 3D scene.
void SavePolyhedron(char *fileName, Tpolyhedron *p) Stores the geometic information of a polyhedron into a file.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn) Constructor.
char * GetFileFullName(Tfilename *fn) Gets the file full name (paht+name+extension).
#define SPHERE One of the possible type of polyhedrons.
double GetRed(Tcolor *c) Gets the red component of a color.
Definition of the Tpolyhedron type and the associated functions.
#define NO_UINT Used to denote an identifier that has not been initialized.
double GetPolyhedronMaxCoordinate(Tpolyhedron *p) Returns the maximum coordinate value used in a polyhedron.
void InitPolyhedronFromFile(Tfilename *fname, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p) Constructor.
void GetPolyhedronVertex(unsigned int i, double *point, Tpolyhedron *p) Gets a vertex of a polyhedron.
void DeletePolyhedron(Tpolyhedron *p) Destructor.
unsigned int GetPolyhedronType(Tpolyhedron *p) Retrives the type of a polyhedron.
void NewSegments(unsigned int n, double *x, double *y, double *z, Tcolor *c, Tpolyhedron *p) Constructor.
void NewColor(double r, double g, double b, Tcolor *c) Constructor.
void Plot3dObject(unsigned int nv, unsigned int nf, unsigned int ne, double **v, unsigned int *nvf, unsigned int **fv, Tplot3d *p) Adds a polytope to the current object.
void NewLine(double *p1, double *p2, Tcolor *c, unsigned int bs, Tpolyhedron *p) Constructor.
char * GetFileExtension(Tfilename *fn) Gets the file extension.
void GenerateSphereOFF(unsigned int g, Tpolyhedron *p) Generates an OFF that approximates a sphere.
void SetPolyhedronColor(Tcolor *c, Tpolyhedron *p) Changes the color of a polyhedron.
void NewBox(double xl, double yl, double zl, double xu, double yu, double zu, Tcolor *c, unsigned int bs, Tpolyhedron *p) Constructor.
double GetBlue(Tcolor *c) Gets the blue component of a color.
unsigned int StartNew3dObject(Tcolor *c, Tplot3d *p) Start a composed object.
void Close3dObject(Tplot3d *p) Closes a composed object.
void InitPolyhedronFromTriangles(unsigned int nv, double **v, unsigned int nt, unsigned int **t, Tcolor *c, unsigned int bs, Tpolyhedron *p) Constructor.
void Print3Reals(FILE *f, double r1, double r2, double r3) Pretty print three real number.
void ReadSegments(FILE *f, Tpolyhedron *p) Constructor.
#define DECOR_SHAPE One of the possible type of shapes.
void TransformPolyhedron(THTransform *t, Tpolyhedron *p) Applies a homogenoeus transform to a polyhedron.
#define HIDDEN_SHAPE One of the possible type of shapes.
|
Follow us!