MeshKit  1.0
test_camaltriadvance.cpp
Go to the documentation of this file.
00001 
00007 #include "meshkit/MKCore.hpp"
00008 #include "meshkit/CAMALTriAdvance.hpp"
00009 #include "meshkit/SizingFunction.hpp"
00010 #include "meshkit/SizingFunctionVar.hpp"
00011 #include "meshkit/ModelEnt.hpp"
00012 
00013 using namespace MeshKit;
00014 
00015 #include "TestUtil.hpp"
00016 
00017 MKCore *mk = NULL;
00018 bool save_mesh = false;
00019 
00020 void holysurf_test();
00021 void singleholesurf_test();
00022 void singleholesurfimprinted_test();
00023 void square_test();
00024 void mesh_test(std::string filebase);
00025 void var_size_test();
00026 
00027 #ifdef HAVE_ACIS
00028 std::string extension = ".sat";
00029 #elif HAVE_OCC
00030 std::string extension = ".stp";
00031 #endif
00032 
00033 int main(int argc, char **argv) 
00034 {
00035   
00036     // start up MK and load the geometry
00037   mk = new MKCore;
00038   int num_fail = 0;
00039   
00040   if (argc == 2) save_mesh = true;
00041   
00042 
00043   num_fail += RUN_TEST(holysurf_test);
00044   num_fail += RUN_TEST(singleholesurf_test);
00045   num_fail += RUN_TEST(singleholesurfimprinted_test);
00046   num_fail += RUN_TEST(square_test);
00047   num_fail += RUN_TEST(var_size_test);
00048   return num_fail;
00049 }
00050 
00051 void holysurf_test() 
00052 {
00053   mesh_test("holysurf");
00054 }
00055 
00056 void singleholesurf_test() 
00057 {
00058   mesh_test("singleholesurf");
00059 }
00060 
00061 void singleholesurfimprinted_test()
00062 {
00063   mesh_test("singleholesurfimprinted");
00064 }
00065 
00066 void square_test()
00067 {
00068   mesh_test("squaresurf");
00069 }
00070 void mesh_test(std::string filebase)
00071 {
00072   std::string file_name = TestDir + "/" + filebase + extension;
00073   mk->load_geometry(file_name.c_str());
00074 
00075     // get the surface
00076   MEntVector dum, surfs;
00077   mk->get_entities_by_dimension(2, dum);
00078   surfs.push_back(*dum.rbegin());
00079   mk->construct_meshop("CAMALTriAdvance", surfs);
00080 
00081     // make a sizing function and set it on the surface
00082   SizingFunction esize(mk, -1, 0.25);
00083   surfs[0]->sizing_function_index(esize.core_index());
00084   
00085     // mesh the surface, by calling execute
00086   mk->setup_and_execute();
00087 
00088     // report the number of tris
00089   moab::Range tris;
00090   moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension(0, 2, tris);
00091   CHECK_EQUAL(moab::MB_SUCCESS, rval);
00092   std::cout << tris.size() << " tris generated." << std::endl;
00093 
00094   if (save_mesh) {
00095         // output mesh
00096     std::string outfile = filebase + std::string(".vtk");
00097     moab::EntityHandle out_set = surfs[0]->mesh_handle();
00098     rval = mk->moab_instance()->write_file(outfile.c_str(), NULL, NULL, &out_set, 1);
00099     MBERRCHK(rval, mk->moab_instance());
00100   }
00101 
00102   mk->clear_graph();
00103 }
00104 
00105 void var_size_test()
00106 {
00107   std::string file_name = TestDir + "/" + std::string("squaresurf") + extension;
00108   mk->load_geometry(file_name.c_str());
00109 
00110     // get the surface
00111   MEntVector dum, surfs;
00112   mk->get_entities_by_dimension(2, dum);
00113   surfs.push_back(*dum.rbegin());
00114   mk->construct_meshop("CAMALTriAdvance", surfs);
00115 
00116     // make a sizing function and set it on the surface
00117   // make a sizing function and set it on the surface
00118   SizingFunctionVar * svar = new SizingFunctionVar(mk, -1, 0.1);
00119 
00120   // these could be read from a file, or something
00121   double point0[3] = {0, 0, 0};
00122   double coeffs[4] = {0.05, 0.05, 0.05, 0.1};
00123   svar->set_linear_coeff(point0, coeffs);
00124 
00125   ModelEnt *this_surf = (*surfs.rbegin());
00126   this_surf->sizing_function_index(svar->core_index());
00127   // how to know if we use a var size during setup of the Edge Mesher?
00128 
00129     // mesh the surface, by calling execute
00130   mk->setup_and_execute();
00131 
00132     // report the number of tris
00133   moab::Range tris;
00134   moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension(0, 2, tris);
00135   CHECK_EQUAL(moab::MB_SUCCESS, rval);
00136   std::cout << tris.size() << " tris generated." << std::endl;
00137 
00138   if (save_mesh) {
00139         // output mesh
00140     std::string outfile = std::string("squaresurf") + std::string(".vtk");
00141     moab::EntityHandle out_set = surfs[0]->mesh_handle();
00142     rval = mk->moab_instance()->write_file(outfile.c_str(), NULL, NULL, &out_set, 1);
00143     MBERRCHK(rval, mk->moab_instance());
00144   }
00145 
00146   mk->clear_graph();
00147 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines