40 return "Builds a tree spanning every vertex of a mesh";
45 return "Plugin(SpanningTree) builds a tree spanning every vertex of a mesh "
46 "and stores it directly in the model.\n"
47 "The tree is constructed by starting first on the curves, "
48 "then on the surfaces and finally on the volumes.\n"
51 "- PhysicalVolumes: list of the physical volumes "
52 "upon which the tree must be built.\n"
53 "- PhysicalSurfaces: list of the physical surfaces "
54 "upon which the tree must be built.\n"
55 "- PhysicalCurves: list of the physical curves "
56 "upon which the tree must be built.\n"
57 "- OutputPhysical: physical tag of the generated tree "
58 "(-1 will select a new tag automatically).\n"
60 "Note - Lists must be comma separated integers "
61 "and spaces are ignored.\n"
62 "Remark - This plugin does not overwrite a physical group."
63 "Therefore, if an existing physical tag is used in OutputPhysical, "
64 "the edges of the tree will be /added/ to the specified group.";
99 vector<list<int> > physical(3);
100 curve =
parse(curve, physical[0]);
101 surface =
parse(surface, physical[1]);
102 volume =
parse(volume, physical[2]);
105 int dim[3] = {1, 2, 3};
112 for(
int i = 0; i < 3; i++)
113 for(
auto j = physical[i].begin(); j != physical[i].end(); j++)
114 getAllMElement(*model, *j, dim[i],
element[i]);
118 Msg::Warning(
"No elements found in the given physcials: abording!");
123 Msg::Info(
"--> PhysicalVolumes: %s", volume.c_str());
124 Msg::Info(
"--> PhysicalSurfaces: %s", surface.c_str());
125 Msg::Info(
"--> PhysicalCurves: %s", curve.c_str());
129 vector<EdgeSet> edge(3);
130 for(
int i = 0; i < 3; i++) getAllMEdge(
element[i], edge[i]);
135 for(
int i = 0; i < 3; i++) spanningTree(edge[i], vertex, tree);
137 addToModel(*model, tree,
output);
151 for(
auto it = edge.begin(); it != edge.end(); it++) {
152 if(vertex.
find(it->first) != vertex.
find(it->second)) {
154 vertex.
join(it->first, it->second);
163 str.erase(remove(str.begin(), str.end(),
' '), str.end());
166 replace(str.begin(), str.end(),
',',
' ');
175 while(!stream.eof()) {
177 if(sscanf(tmp.c_str(),
"%d", &tag) > 0) physical.push_back(tag);
187 std::map<int, std::vector<GEntity *> > group;
193 auto entity = group.find(physical);
194 if(entity == group.end())
return;
196 for(
size_t i = 0; i < entity->second.size(); i++)
197 for(
size_t j = 0; j < entity->second[i]->getNumMeshElements(); j++)
198 element.insert(entity->second[i]->getMeshElement(j));
206 for(; it != end; it++)
207 for(
int i = 0; i < (*it)->getNumEdges(); i++)
209 std::pair<int, int>((*it)->getEdge(i).getVertex(0)->getNum() - 1,
210 (*it)->getEdge(i).getVertex(1)->getNum() - 1));
218 std::vector<MElement *>
line(tree.size());
221 auto end = tree.end();
222 auto it = tree.begin();
224 for(
int i = 0; it != end; i++, it++)
230 std::string name =
"";
237 entityNum = *std::max_element(max, max + 4) + 1;
242 physicalNum = *std::max_element(max, max + 4) + 1;
249 std::map<int, std::vector<MElement *> > entityMap;
250 entityMap[entityNum] =
line;
253 std::map<int, std::string> physicalInfo;
254 physicalInfo[physicalNum] = name;
257 std::map<int, std::map<int, std::string> > physicalMap;
258 physicalMap[entityNum] = physicalInfo;
268 if(p.first < p.second)
269 return std::pair<int, int>(p.first, p.second);
271 return std::pair<int, int>(p.second, p.first);
280 for(
size_t i = 0; i < n; i++) parent[i] = i;
292 if(parent[a] != a) parent[a] = find(parent[a]);
307 if(rank[aRoot] < rank[bRoot])
309 parent[bRoot] = aRoot;
310 if(rank[aRoot] == rank[bRoot])
319 for(
size_t i = 0; i < parent.size(); i++)
320 str <<
"(" << i + 1 <<
", " << parent[i] + 1 <<
")" << endl;
326 const std::pair<int, int> &a,
const std::pair<int, int> &b)
const
328 std::pair<int, int> as =
minmax(a);
329 std::pair<int, int> bs =
minmax(b);