LCOV - code coverage report
Current view: top level - disks2/fathom/slaves/sigma2/cgm-occ-cov/build/itaps - mergetest.cc (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 45 59 76.3 %
Date: 2020-06-30 00:58:45 Functions: 9 10 90.0 %
Branches: 61 178 34.3 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * \file mergetest.cpp
       3                 :            :  *
       4                 :            :  * \brief mergetest, utility to merge files
       5                 :            :  *
       6                 :            :  */
       7                 :            : #include "iGeom.h"
       8                 :            : #include <iostream>
       9                 :            : #include <set>
      10                 :            : #include <algorithm>
      11                 :            : #include <vector>
      12                 :            : #include <iomanip>
      13                 :            : #include <assert.h>
      14                 :            : #include <string.h>
      15                 :            : #include <math.h>
      16                 :            : 
      17                 :            : 
      18                 :            : #define CHECK( STR ) if (err != iBase_SUCCESS) return print_error( STR, err, geom, __FILE__, __LINE__ )
      19                 :            : 
      20                 :            : #define STRINGIFY(S) XSTRINGIFY(S)
      21                 :            : #define XSTRINGIFY(S) #S
      22                 :            : 
      23                 :          0 : static bool print_error( const char* desc,
      24                 :            :                          int err,
      25                 :            :                          iGeom_Instance geom,
      26                 :            :                          const char* file,
      27                 :            :                          int line )
      28                 :            : {
      29                 :            :   char buffer[1024];
      30         [ #  # ]:          0 :   iGeom_getDescription( geom, buffer, sizeof(buffer) );
      31                 :          0 :   buffer[sizeof(buffer)-1] = '\0';
      32                 :            : 
      33 [ #  # ][ #  # ]:          0 :   std::cerr << "ERROR: " << desc << std::endl
                 [ #  # ]
      34 [ #  # ][ #  # ]:          0 :             << "  Error code: " << err << std::endl
                 [ #  # ]
      35 [ #  # ][ #  # ]:          0 :             << "  Error desc: " << buffer << std::endl
                 [ #  # ]
      36 [ #  # ][ #  # ]:          0 :             << "  At        : " << file << ':' << line << std::endl
         [ #  # ][ #  # ]
      37         [ #  # ]:          0 :             ;
      38                 :            : 
      39                 :          0 :   return false; // must always return false or CHECK macro will break
      40                 :            : }
      41                 :            : 
      42                 :            : typedef iBase_TagHandle TagHandle;
      43                 :            : typedef iBase_EntityHandle GentityHandle;
      44                 :            : typedef iBase_EntitySetHandle GentitysetHandle;
      45                 :            : 
      46                 :            : /* Frees allocated arrays for us */
      47                 :            : template <typename T> class SimpleArray
      48                 :            : {
      49                 :            :   private:
      50                 :            :     T* arr;
      51                 :            :     int arrSize;
      52                 :            :     int arrAllocated;
      53                 :            : 
      54                 :            :   public:
      55                 :          1 :     SimpleArray() : arr(0) , arrSize(0), arrAllocated(0) {}
      56                 :            :     SimpleArray( unsigned s ) :arrSize(s), arrAllocated(s) {
      57                 :            :       arr = (T*)malloc(s*sizeof(T));
      58                 :            :       for (unsigned i = 0; i < s; ++i)
      59                 :            :         new (arr+i) T();
      60                 :            :     }
      61                 :            : 
      62                 :          1 :     ~SimpleArray() {
      63         [ +  + ]:          4 :       for (int i = 0; i < size(); ++i)
      64                 :          3 :         arr[i].~T();
      65                 :          1 :       free(arr);
      66                 :          1 :     }
      67                 :            : 
      68                 :          2 :     T**  ptr()            { return &arr; }
      69                 :         14 :     int& size()           { return arrSize; }
      70                 :            :     int  size()     const { return arrSize; }
      71                 :          2 :     int& capacity()       { return arrAllocated; }
      72                 :            :     int  capacity() const { return arrAllocated; }
      73                 :            : 
      74                 :            :     typedef T* iterator;
      75                 :            :     typedef const T* const_iterator;
      76                 :            :     iterator       begin()       { return arr; }
      77                 :            :     const_iterator begin() const { return arr; }
      78                 :            :     iterator         end()       { return arr + arrSize; }
      79                 :            :     const_iterator   end() const { return arr + arrSize; }
      80                 :            : 
      81                 :            : 
      82                 :          4 :     T& operator[]( unsigned idx )       { return arr[idx]; }
      83                 :            :     T  operator[]( unsigned idx ) const { return arr[idx]; }
      84                 :            : };
      85                 :            : 
      86                 :            : #define ARRAY_INOUT( A ) A.ptr(), &A.capacity(), &A.size()
      87                 :            : #define ARRAY_IN( A ) &A[0], A.size()
      88                 :            : 
      89                 :          1 : int main( int argc, char *argv[] )
      90                 :            : {
      91                 :            :     // Check command line arg
      92                 :            :   #ifdef FORCE_OCC
      93                 :            :     #ifndef HAVE_OCC
      94                 :            :       #error "Cannot force use of OCC w/out OCC support"
      95                 :            :     #endif
      96                 :            :   std::string filename = STRINGIFY(SRCDIR) "/voltest.stp";
      97                 :            :   std::string outfile = "merged.occ";
      98                 :            :     std::string engine_opt = ";engine=OCC";
      99                 :            :   #elif defined(HAVE_OCC)
     100         [ +  - ]:          1 :     std::string filename = STRINGIFY(SRCDIR) "/voltest.stp";
     101 [ +  - ][ +  - ]:          2 :     std::string outfile = "merged.occ";
     102 [ +  - ][ +  - ]:          2 :     std::string engine_opt = ";engine=OCC";
     103                 :            :   #else
     104                 :            :     std::cerr << "for facet engine merge is not supported\n";
     105                 :            :     return 1;
     106                 :            :   #endif
     107         [ +  - ]:          1 :   if (argc == 1) {
     108 [ +  - ][ +  - ]:          1 :     std::cout << "Using default input file: " << filename << std::endl;
                 [ +  - ]
     109 [ +  - ][ +  - ]:          1 :     std::cout << "Using default output file: " << outfile << std::endl;
                 [ +  - ]
     110                 :            :   }
     111         [ #  # ]:          0 :   else if (argc >= 3) {
     112         [ #  # ]:          0 :     filename = argv[1];
     113         [ #  # ]:          0 :     outfile = argv[2];
     114                 :            :   }
     115                 :            :   else {
     116 [ #  # ][ #  # ]:          0 :     std::cerr << "Usage: " << argv[0] << " [geom_filename] [out file]" << std::endl;
         [ #  # ][ #  # ]
     117                 :          0 :     return 1;
     118                 :            :   }
     119                 :            : 
     120                 :            :   // initialize  geom
     121                 :            :   int err;
     122                 :            :   iGeom_Instance geom;
     123 [ +  - ][ +  - ]:          1 :   iGeom_newGeom( engine_opt.c_str(), &geom, &err, engine_opt.length() );
                 [ +  - ]
     124                 :            : 
     125                 :            :     // Print out Header information
     126         [ +  - ]:          1 :   std::cout << "\n merge utility :\n\n";
     127                 :            : 
     128 [ +  - ][ +  - ]:          1 :   iGeom_load( geom, &filename[0], 0, &err, filename.length(), 0 );
                 [ +  - ]
     129 [ -  + ][ #  # ]:          1 :   CHECK( "ERROR : can not load a geometry" );
     130                 :            : 
     131                 :            :   iBase_EntitySetHandle root_set;
     132         [ +  - ]:          1 :   iGeom_getRootSet( geom, &root_set, &err );
     133 [ -  + ][ #  # ]:          1 :   CHECK( "ERROR : getRootSet failed!" );
     134                 :            : 
     135                 :            :     // print out the number of entities
     136 [ +  - ][ +  - ]:          1 :   std::cout << "Model contents: " << std::endl;
     137                 :          1 :   const char *gtype[] = {"vertices: ", "edges: ", "faces: ", "regions: "};
     138         [ +  + ]:          5 :   for (int i = 0; i <= 3; ++i) {
     139                 :            :     int count;
     140         [ +  - ]:          4 :     iGeom_getNumOfType( geom, root_set, i, &count, &err );
     141 [ -  + ][ #  # ]:          4 :     CHECK( "Error: problem getting entities after gLoad." );
     142 [ +  - ][ +  - ]:          4 :     std::cout << gtype[i] << count << std::endl;
                 [ +  - ]
     143                 :            :   }
     144                 :            : 
     145                 :            :   // get volumes, and call merge
     146                 :            :   int count;
     147         [ +  - ]:          1 :   iGeom_getNumOfType( geom, root_set, 3, &count, &err );
     148 [ -  + ][ #  # ]:          1 :   CHECK( "Error: problem getting volume numbers after gLoad." );
     149                 :            : 
     150 [ +  - ][ +  - ]:          2 :   SimpleArray<iBase_EntityHandle> vols;
     151                 :            : 
     152 [ +  - ][ +  - ]:          1 :   iGeom_getEntities( geom, root_set, 3, ARRAY_INOUT(vols), &err );
         [ +  - ][ +  - ]
     153 [ -  + ][ #  # ]:          1 :   CHECK( "Error: problem getting volumes." );
     154                 :            : 
     155                 :            :   //  now imprint
     156 [ +  - ][ +  - ]:          1 :   std::cout << "\n\nImprinting...." << std::endl;
     157 [ +  - ][ +  - ]:          1 :   iGeom_imprintEnts(geom, ARRAY_IN(vols),&err);
                 [ +  - ]
     158 [ -  + ][ #  # ]:          1 :   CHECK( "Error: problem imprinting volumes." );
     159                 :            :   ////CHECK("Imprint failed.");
     160                 :            : 
     161 [ +  - ][ +  - ]:          1 :   std::cout << "\n\nMerging...." << std::endl;
     162                 :          1 :   double dTol = 1e-4;
     163 [ +  - ][ +  - ]:          1 :   iGeom_mergeEnts(geom, ARRAY_IN(vols), dTol, &err);
                 [ +  - ]
     164                 :            :      ////CHECK("Merge failed.");
     165 [ -  + ][ #  # ]:          1 :   CHECK( "Error: problem merging volumes." );
     166                 :            : 
     167                 :            :   iGeom_save(geom, outfile.c_str(), NULL, &err,
     168 [ +  - ][ +  - ]:          1 :                 strlen(outfile.c_str()), 0);
                 [ +  - ]
     169 [ -  + ][ #  # ]:          1 :   CHECK( "Error: problem saving." );
     170                 :            : 
     171         [ +  - ]:          2 :   return 0;
     172 [ +  - ][ +  - ]:          4 : }
     173                 :            : 

Generated by: LCOV version 1.11