void LMESH::set_parent(LMESH* parent) { assert(parent); _parent_mesh = parent; _subdiv_level = parent->subdiv_level() + 1; LMESHptr c = control_mesh(); assert(c != nullptr); if (c->has_name()) { char tmp[32]; sprintf(tmp, "%d", _subdiv_level); set_name(c->get_name() + "-sub" + tmp); } }
LMESHptr LMESH::get_lmesh(const string& exact_name) { // Return an LMESH with the given name. If one already exists, // return that one. Otherwise create a new LMESH with the desired // name. Fails (returns null) if the name is invalid (null string) // or the name is already taken by a BMESH that is not an LMESH. bool debug = NameLookup<BMESH>::_debug; // Make sure they're not asking for the null string: if (exact_name == "") { if (debug) cerr << "LMESH::get_lmesh: error: name is empty" << endl; return nullptr; } // Does a mesh with the requested name exist? BMESHptr mesh = dynamic_cast<BMESH*>(NameLookup<BMESH>::lookup(exact_name))->shared_from_this(); // If no mesh of that name exists, create a new one: if (!mesh) { LMESHptr ret = make_shared<LMESH>(); assert(ret && !ret->has_name()); ret->set_name(exact_name); return ret; } // A BMESH with the requested name already exists; // if it is not also an LMESH, this is an error: LMESHptr lm = dynamic_pointer_cast<LMESH>(mesh); if (debug && !lm) { cerr << "LMESH::get_lmesh: error: found requested name: " << exact_name << ", but it is not an LMESH" << endl; } return lm; }