[cgma-dev] r2772 - cgm/trunk/itaps

tautges at mcs.anl.gov tautges at mcs.anl.gov
Fri Mar 27 16:41:34 CDT 2009


Author: tautges
Date: 2009-03-27 16:41:32 -0500 (Fri, 27 Mar 2009)
New Revision: 2772

Added:
   cgm/trunk/itaps/chaman.cc
Modified:
   cgm/trunk/itaps/CATag.cpp
   cgm/trunk/itaps/Makefile.am
Log:
Adding small test from Chaman Verma.  Changing tag implementation
to disallow tag handle of 0.


Modified: cgm/trunk/itaps/CATag.cpp
===================================================================
--- cgm/trunk/itaps/CATag.cpp	2009-03-27 19:13:54 UTC (rev 2771)
+++ cgm/trunk/itaps/CATag.cpp	2009-03-27 21:41:32 UTC (rev 2772)
@@ -114,6 +114,7 @@
     : interfaceGroup(NULL)
 {
   pcTag = 0;
+  tagInfo.push_back(preset_tag_list[0]);
   
     // get the tag number for CATag
   DLIList<int> tag_types;
@@ -255,7 +256,7 @@
     
   TagInfo tmp_info = {tag_length, std::string(tag_name), tag_type, NULL, true};
   tagInfo.push_back(tmp_info);
-  *tag_handle = tagInfo.size()-1;
+  *tag_handle = tagInfo.size() - 1;
   if (default_value != NULL) {
     tagInfo[*tag_handle].defaultValue = (char *) malloc(tag_length);
     memcpy(tagInfo[*tag_handle].defaultValue, default_value, tag_length);
@@ -278,7 +279,7 @@
   }
   
     // if we got here, assume we can delete it
-  TagInfo *tinfo = (tag_handle >= 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
+  TagInfo *tinfo = (tag_handle > 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
   tinfo->isActive = false;
 
   RETURN(iBase_SUCCESS);
@@ -287,14 +288,14 @@
 const char *CGMTagManager::getTagName (/*in*/ const long tag_handle)
 {
   iGeom_clearLastError();
-  return (tag_handle >= 0 ? tagInfo[tag_handle].tagName.c_str() : 
+  return (tag_handle > 0 ? tagInfo[tag_handle].tagName.c_str() : 
           presetTagInfo[-tag_handle].tagName.c_str());
 }
 
 int CGMTagManager::getTagSize (/*in*/ const long tag_handle)
 {
   iGeom_clearLastError();
-  return (tag_handle >= 0 ? 
+  return (tag_handle > 0 ? 
           tagInfo[tag_handle].tagLength : 
           presetTagInfo[-tag_handle].tagLength);
 }
@@ -317,7 +318,7 @@
 int CGMTagManager::getTagType (/*in*/ const long tag_handle) 
 {
   iGeom_clearLastError();
-  return (tag_handle >= 0 ? 
+  return (tag_handle > 0 ? 
           tagInfo[tag_handle].tagType : 
           presetTagInfo[-tag_handle].tagType);
 }
@@ -326,7 +327,7 @@
                                            /*in*/ const long tag_handle,
                                            /*inout*/ ARRAY_INOUT_DECL(char, tag_value))
 {
-  TagInfo *tinfo = (tag_handle >= 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
+  TagInfo *tinfo = (tag_handle > 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
   int tag_size = tinfo->tagLength;
     // either way, we have to have that many bytes when we leave this function
   const bool allocated_data_arr = (*tag_value_allocated == 0);
@@ -391,7 +392,7 @@
                                            /*in*/ const long tag_handle,
                                            /*in*/ const char *tag_values, const int tag_values_size)
 {
-  TagInfo *tinfo = (tag_handle >= 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
+  TagInfo *tinfo = (tag_handle > 0 ? &tagInfo[tag_handle] : &presetTagInfo[-tag_handle]);
   int tag_size = tinfo->tagLength;
   
   const char *val_ptr = tag_values;
@@ -872,10 +873,10 @@
   std::cout << "This entity has " << tagData.size() << " tags.  Types are: " << std::endl;
   for (std::map<int,void*>::iterator mit = tagData.begin(); mit != tagData.end(); mit++) 
   {
-    if ((*mit).first < 0)
-      std::cout << myManager->tagInfo[-(*mit).first].tagName << std::endl;
+    if ((*mit).first > 0)
+      std::cout << myManager->tagInfo[(*mit).first].tagName << std::endl;
     else
-      std::cout << myManager->tagInfo[(*mit).first].tagName << std::endl;
+      std::cout << myManager->presetTagInfo[-(*mit).first].tagName << std::endl;
   }
 }
 
@@ -883,7 +884,7 @@
 {
   assert(NULL != tag_data);
 
-  CGMTagManager::TagInfo *tinfo = (tag_handle >= 0 ? 
+  CGMTagManager::TagInfo *tinfo = (tag_handle > 0 ? 
                                    &(myManager->tagInfo[tag_handle]) : 
                                    &(myManager->presetTagInfo[-tag_handle]));
   
@@ -908,7 +909,7 @@
 iBase_ErrorType CATag::set_tag_data(long tag_handle, const void *tag_data, 
                                      const bool can_shallow_copy)
 {
-  CGMTagManager::TagInfo *tinfo = (tag_handle >= 0 ? 
+  CGMTagManager::TagInfo *tinfo = (tag_handle > 0 ? 
                                    &(myManager->tagInfo[tag_handle]) : 
                                    &(myManager->presetTagInfo[-tag_handle]));
   

Modified: cgm/trunk/itaps/Makefile.am
===================================================================
--- cgm/trunk/itaps/Makefile.am	2009-03-27 19:13:54 UTC (rev 2771)
+++ cgm/trunk/itaps/Makefile.am	2009-03-27 21:41:32 UTC (rev 2772)
@@ -9,7 +9,7 @@
   SIDL_DIR = 
 endif 
 
-TESTS =
+TESTS = chaman
 if build_ACIS
   TESTS += testgeom
 else
@@ -62,6 +62,11 @@
 testgeom_occ_CPPFLAGS = $(testgeom_CPPFLAGS) -DFORCE_OCC
 testgeom_occ_LDFLAGS = $(testgeom_LDFLAGS)
 
+chaman_SOURCES = chaman.cc
+chaman_LDADD = libiGeom.la
+chaman_CPPFLAGS = $(CPPFLAGS) -DSRCDIR=$(srcdir)
+chaman_LDFLAGS = $(CGM_EXT_LTFLAGS) $(CGM_EXT_LDFLAGS)
+
 # Automake doesn't seem to have a directory defined for
 # platform-dependent data (or include) files. So put 
 # in $(libdir).  Define a $(cfgdir) to get around automake's

Added: cgm/trunk/itaps/chaman.cc
===================================================================
--- cgm/trunk/itaps/chaman.cc	                        (rev 0)
+++ cgm/trunk/itaps/chaman.cc	2009-03-27 21:41:32 UTC (rev 2772)
@@ -0,0 +1,129 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <string.h>
+
+#include <vector>
+
+#include <iGeom.h>
+
+//#include "SimpleArray.h"
+template<typename T>
+class SimpleArray 
+{
+public:
+  T *array;
+  int array_alloc;
+  int array_size;
+  
+  SimpleArray() : array(NULL), array_alloc(0), array_size(0){}
+  ~SimpleArray() {reset();}
+
+  T operator[](unsigned int lhs) {return array[lhs];}
+        
+  void reset() {
+    if (0 != array) {
+      free(array); array = NULL; array_alloc = array_size = 0;
+    }
+  }
+  int size() {return array_size;}
+  
+};
+#define SA_ARRAY_INOUT(a) &a.array, &a.array_alloc, &a.array_size
+#define SA_ARRAY_IN(a) a.array, a.array_size
+
+using namespace std;
+
+int main( int argc, char **argv)
+{
+  assert( argc == 2 );
+  string engine_opt = ";engine=OCC";
+  string filename   = argv[1]; 
+
+  int err;
+  iGeom_Instance geom;
+  iGeom_newGeom( engine_opt.c_str(), &geom, &err, engine_opt.length() );
+
+  iGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 );
+
+  iBase_EntitySetHandle root_set;
+  iGeom_getRootSet( geom, &root_set, &err);
+
+  cout << "Model Contents " << endl;
+  const char *gtype[] = {"vertices: ", "edges: ", "faces: ", "regions: "};
+  for (int i = 0; i <= 3; ++i) {
+    int count;
+    iGeom_getNumOfType( geom, root_set, i, &count, &err );
+    std::cout << gtype[i] << count << std::endl;
+  }
+
+  iBase_TagHandle idtag;
+  iGeom_getTagHandle( geom, "GLOBAL_ID", &idtag, &err, strlen("GLOBAL_ID") );
+
+  SimpleArray<iBase_EntityHandle> vertices;
+  iGeom_getEntities( geom, root_set, iBase_VERTEX, SA_ARRAY_INOUT(vertices), &err);
+
+  SimpleArray<double> vCoords;
+  iGeom_getVtxArrCoords(geom, SA_ARRAY_IN(vertices), iBase_INTERLEAVED, SA_ARRAY_INOUT(vCoords), &err);
+
+  SimpleArray<iBase_EntityHandle> edges;
+  iGeom_getEntities( geom, root_set, iBase_EDGE, SA_ARRAY_INOUT(edges), &err);
+
+  SimpleArray<double> edgelength;
+  iGeom_measure( geom, SA_ARRAY_IN(edges), SA_ARRAY_INOUT(edgelength), &err);
+
+  double minlength = edgelength[0];
+  for( int i = 0; i < edges.size(); i++) 
+    minlength = std::min(minlength, edgelength[i]);
+
+  double ustart, uend, delta;
+  double x, y, z;
+  int N = 10;
+
+  int id;
+  int numNodes = 0, numEdges = 0;
+  vector<double> xCoord, yCoord, zCoord;
+  for( int i = 0; i < edges.size(); i++) {
+    iGeom_getEntURange( geom, edges[i], &ustart, &uend, &err);
+    iGeom_getIntData( geom, edges[i], idtag, &id, &err);
+    delta = (uend-ustart)/(double)N;
+    for( int j = 0; j < N+1; j++) {
+      double u = ustart + j*delta;
+      iGeom_getEntUtoXYZ( geom, edges[i], u, &x, &y, &z, &err);
+      xCoord.push_back(x);
+      yCoord.push_back(y);
+      zCoord.push_back(z);
+      numNodes++;
+    }
+    numEdges += N;
+  }
+
+  SimpleArray<iBase_EntityHandle> faces;
+  iGeom_getEntities( geom, root_set, iBase_FACE, SA_ARRAY_INOUT(faces), &err);
+
+  int eid, vid1, vid2;
+  SimpleArray<iBase_EntityHandle>  edgenodes;
+  SimpleArray<iBase_EntityHandle>  faceedges;
+  SimpleArray<iBase_EntityHandle>  facenodes;
+
+  for( int i = 0; i < faces.size(); i++) 
+  {
+    iGeom_getIntData( geom, faces[i], idtag, &id, &err);
+    iGeom_getEntAdj( geom, faces[i], iBase_EDGE,   SA_ARRAY_INOUT( faceedges ), &err);
+    cout << "Face " << id << ": " << faceedges.size() << " edges." << endl;
+    for(int j = 0; j < faceedges.size(); ++j) 
+    {
+      iGeom_getIntData( geom, faceedges[j], idtag, &eid, &err);
+      iGeom_getEntAdj( geom, faceedges[j], iBase_VERTEX, SA_ARRAY_INOUT(edgenodes), &err);
+      cout << "Edge " << eid << ", " << edgenodes.size() << " vertices: ";
+      assert( edgenodes.size() == 2 );
+      iGeom_getIntData( geom, edgenodes[0], idtag, &vid1, &err);
+      iGeom_getIntData( geom, edgenodes[1], idtag, &vid2, &err);
+      cout << vid1 << ", " << vid2 << endl;
+    }
+  }
+
+}



More information about the cgma-dev mailing list