cgma
chaman.cc
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <assert.h>
00004 #include <string>
00005 #include <iostream>
00006 #include <fstream>
00007 #include <string.h>
00008 
00009 #include <vector>
00010 
00011 #include <iGeom.h>
00012 
00013 //#include "SimpleArray.h"
00014 template<typename T>
00015 class SimpleArray 
00016 {
00017 public:
00018   T *array;
00019   int array_alloc;
00020   int array_size;
00021   
00022   SimpleArray() : array(NULL), array_alloc(0), array_size(0){}
00023   ~SimpleArray() {reset();}
00024 
00025   T operator[](unsigned int lhs) {return array[lhs];}
00026         
00027   void reset() {
00028     if (0 != array) {
00029       free(array); array = NULL; array_alloc = array_size = 0;
00030     }
00031   }
00032   int size() {return array_size;}
00033   
00034 };
00035 #define SA_ARRAY_INOUT(a) &a.array, &a.array_alloc, &a.array_size
00036 #define SA_ARRAY_IN(a) a.array, a.array_size
00037 
00038 using namespace std;
00039 
00040 int main( int argc, char **argv)
00041 {
00042   assert( argc == 2 );
00043   string engine_opt = ";engine=OCC";
00044   string filename   = argv[1]; 
00045 
00046   int err;
00047   iGeom_Instance geom;
00048   iGeom_newGeom( engine_opt.c_str(), &geom, &err, engine_opt.length() );
00049 
00050   iGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 );
00051 
00052   iBase_EntitySetHandle root_set;
00053   iGeom_getRootSet( geom, &root_set, &err);
00054 
00055   cout << "Model Contents " << endl;
00056   const char *gtype[] = {"vertices: ", "edges: ", "faces: ", "regions: "};
00057   for (int i = 0; i <= 3; ++i) {
00058     int count;
00059     iGeom_getNumOfType( geom, root_set, i, &count, &err );
00060     std::cout << gtype[i] << count << std::endl;
00061   }
00062 
00063   iBase_TagHandle idtag;
00064   iGeom_getTagHandle( geom, "GLOBAL_ID", &idtag, &err, strlen("GLOBAL_ID") );
00065 
00066   SimpleArray<iBase_EntityHandle> vertices;
00067   iGeom_getEntities( geom, root_set, iBase_VERTEX, SA_ARRAY_INOUT(vertices), &err);
00068 
00069   SimpleArray<double> vCoords;
00070   iGeom_getVtxArrCoords(geom, SA_ARRAY_IN(vertices), iBase_INTERLEAVED, SA_ARRAY_INOUT(vCoords), &err);
00071 
00072   SimpleArray<iBase_EntityHandle> edges;
00073   iGeom_getEntities( geom, root_set, iBase_EDGE, SA_ARRAY_INOUT(edges), &err);
00074 
00075   SimpleArray<double> edgelength;
00076   iGeom_measure( geom, SA_ARRAY_IN(edges), SA_ARRAY_INOUT(edgelength), &err);
00077 
00078   double minlength = edgelength[0];
00079   for( int i = 0; i < edges.size(); i++) 
00080     minlength = std::min(minlength, edgelength[i]);
00081 
00082   double ustart, uend, delta;
00083   double x, y, z;
00084   int N = 10;
00085 
00086   int id;
00087   int numNodes = 0, numEdges = 0;
00088   vector<double> xCoord, yCoord, zCoord;
00089   for( int i = 0; i < edges.size(); i++) {
00090     iGeom_getEntURange( geom, edges[i], &ustart, &uend, &err);
00091     iGeom_getIntData( geom, edges[i], idtag, &id, &err);
00092     delta = (uend-ustart)/(double)N;
00093     for( int j = 0; j < N+1; j++) {
00094       double u = ustart + j*delta;
00095       iGeom_getEntUtoXYZ( geom, edges[i], u, &x, &y, &z, &err);
00096       xCoord.push_back(x);
00097       yCoord.push_back(y);
00098       zCoord.push_back(z);
00099       numNodes++;
00100     }
00101     numEdges += N;
00102   }
00103 
00104   SimpleArray<iBase_EntityHandle> faces;
00105   iGeom_getEntities( geom, root_set, iBase_FACE, SA_ARRAY_INOUT(faces), &err);
00106 
00107   int eid, vid1, vid2;
00108   SimpleArray<iBase_EntityHandle>  edgenodes;
00109   SimpleArray<iBase_EntityHandle>  faceedges;
00110   SimpleArray<iBase_EntityHandle>  facenodes;
00111 
00112   for( int i = 0; i < faces.size(); i++) 
00113   {
00114     iGeom_getIntData( geom, faces[i], idtag, &id, &err);
00115     iGeom_getEntAdj( geom, faces[i], iBase_EDGE,   SA_ARRAY_INOUT( faceedges ), &err);
00116     cout << "Face " << id << ": " << faceedges.size() << " edges." << endl;
00117     for(int j = 0; j < faceedges.size(); ++j) 
00118     {
00119       iGeom_getIntData( geom, faceedges[j], idtag, &eid, &err);
00120       iGeom_getEntAdj( geom, faceedges[j], iBase_VERTEX, SA_ARRAY_INOUT(edgenodes), &err);
00121       cout << "Edge " << eid << ", " << edgenodes.size() << " vertices: ";
00122       assert( edgenodes.size() == 2 );
00123       iGeom_getIntData( geom, edgenodes[0], idtag, &vid1, &err);
00124       iGeom_getIntData( geom, edgenodes[1], idtag, &vid2, &err);
00125       cout << vid1 << ", " << vid2 << endl;
00126     }
00127   }
00128 
00129 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines