//will add points along exsisting edges and make new faces from them void geo_sphere::subdivide_geosphere(int res){ int e = n_tri(res); if(gs_sphere_start[res]+e>(int)gstris.size())return; for(int i = 0; i<e; i++){ int p1 = gstris[gs_sphere_start[res] + i].point[0]; int p2 = gstris[gs_sphere_start[res] + i].point[1]; int p3= gstris[gs_sphere_start[res] + i].point[2]; vector3d v1 = gspoints[p1]; vector3d v2 = gspoints[p2]; vector3d v3 = gspoints[p3]; //adding two vectors makes a scalar multiple of of there average //normaliseing them will project them onto the unit sphere int p12 = add_if_not_present(MakeUnitVector(v1+v2)); int p23 = add_if_not_present(MakeUnitVector(v2+v3)); int p31 = add_if_not_present(MakeUnitVector(v3+v1)); gstris.push_back(stri(p1,p12,p31)); gstris.push_back(stri(p2,p23,p12)); gstris.push_back(stri(p3,p31,p23)); gstris.push_back(stri(p12,p23,p31)); } }
int mod_main (flux_t h, int argc, char **argv) { optparse_t *p = optparse_create ("pymod"); if (optparse_add_option_table (p, opts) != OPTPARSE_SUCCESS) msg_exit ("optparse_add_option_table"); if (optparse_set (p, OPTPARSE_USAGE, usage_msg) != OPTPARSE_SUCCESS) msg_exit ("optparse_set usage"); int option_index = optparse_parse_args (p, argc, argv); if (option_index <= 0 || optparse_hasopt(p, "help") || option_index >= argc){ optparse_print_usage(p); return (option_index < 0); } const char * module_name = argv[option_index]; Py_SetProgramName("pymod"); Py_Initialize(); PyObject *search_path = PySys_GetObject("path"); // Add installation search paths add_if_not_present(search_path, optparse_get_str(p, "path", "")); add_if_not_present(search_path, FLUX_PYTHON_PATH); PySys_SetObject("path", search_path); if(optparse_hasopt(p, "verbose")){ PyObject_Print(search_path, stderr, 0); } flux_log(h, LOG_INFO, "loading python module named: %s", module_name); PyObject *module = PyImport_ImportModule("flux.core"); if(!module){ PyErr_Print(); return EINVAL; } PyObject *mod_main = PyObject_GetAttrString(module, "mod_main_trampoline"); if(mod_main && PyCallable_Check(mod_main)){ //maybe unpack args directly? probably easier to use a dict PyObject *py_args = PyTuple_New(3); PyTuple_SetItem(py_args, 0, PyString_FromString(module_name)); PyTuple_SetItem(py_args, 1, PyLong_FromVoidPtr(h)); //Convert zhash to native python dict, should preserve mods //through switch to argc-style arguments PyObject *arg_list = PyList_New(0); char ** it = argv + option_index; int i; for (i=0; *it; i++, it++){ PyList_Append(arg_list, PyString_FromString(*it)); } PyTuple_SetItem(py_args, 2, arg_list); // Call into trampoline PyObject_CallObject(mod_main, py_args); if(PyErr_Occurred()){ PyErr_Print(); } Py_DECREF(py_args); Py_DECREF(arg_list); } Py_Finalize(); return 0; }