Find children of given R-Tree node - c++

I need to know the hierarchy of my rtree. In particular, given a Node, I'd like to know its children.
I've seen that in this SO question there's a link to the following line in GitHub sources:
https://github.com/boostorg/geometry/blob/f92671b933e585ecba3c1b02c830f6e90e813da9/include/boost/geometry/index/detail/rtree/utilities/print.hpp#L160
where n is an InternalNode. From my understanding, it->first is the bounding box, while it->second is the indexable. However, I don't see how one can query the children of a specific node. Is there any way to find them?
I am completely stuck at the moment

Related

Getting the main list of nodes from xml document, using msxml lib in c++

I would like to go through the whole xml document that I have, without depending in the actual id value, node name or attributes.
I use the msxml3 lib.
I would like to get a list of the main nodes in the xml, that are descendants of the main node.
<mainNode>
<firstNodeInList></firstNodeInList>
<secondNodeInList></secondNodeInList>
<thirdNodeInList></thirdNodeInList>
</mainNode>
I would like to get a list of the inside nodes, i.e. :
firstNodeInList->secondNodeInList->thirdNodeInList.
Thank you
Since no one responded, I had to find out the answer, which apperently is very simple.
The first line will get the document element, or the root element. The second will get the list of children of the root.
MSXML2::IXMLDOMElementPtr docElem = m_newFileDoc->documentElement;
MSXML2::IXMLDOMNodeListPtr nodes = docElem->childNodes;

How to build a non-binary tree (with dependencies) incrementally

Short Description
I need to build a non-binary tree (language doesn't matter for now, but preferably in C++) from a list of items that do have dependencies to each other, but non-recurring and not cyclic.
The data for the nodes are read from a file and incrementally inserted into the tree.
The troubling part is how to handle those nodes which do not have parent-nodes yet that fulfill the dependency of the inserted node.
Detailed Description
Rough Outline
The assignment is easy: represent a bunch of Tasks and Subtasks in a non-binary tree.
This assignment would be quite easy to understand and implement, if not for a tiny condition: the list of Tasks has to be generated incrementally, so do the nodes in the tree.
Scenario
The Tasks are generated asynchronously and have to be added into the tree once the data to a certain Task is received.
This is "simulated" by reading a csv-file which has a certain Task in each line with some data, the most important ones being the PID and PPID attributes.
After a line is read and parsed, a Task is being created and inserted into the tree.
The tree should automatically resolve the dependencies following two simple rules:
Only show the node when the dependency is met (namely when a parent-node has been inserted before), but memorize the (now orphaned) node.
Whenever a Task(node) is added, check if it's a parentnode of one of the above meantioned orphaned ones and reconcile the nodes if rule #1 isn't infringed while doing so.
Please disregard the faulty logic behind this scenario: Normally, there can't be any SubTask without a ParentTask existing (at least in monolithic kernel designs).
And while the List of Tasks certainly do contain the ParentTasks needed to model the tree, it is unknown when the ParentNode-Data is read and inserted into the tree.
Desired outcome
Below is a figure showing the "raw data", a list of (unsorted) Tasks which has been created incrementally while adding one Task after another to the list.
The tree represents the subset of Tasks which has been inserted so far:
Please keep in mind that the tree is completely "naked" until the Tasks with the PIDs 1, 2 and 3 are inserted, because the other nodes are dependent of them.
What I did so far
I've written a Qt-C++ Code with three rough components:
TaskTree which holds a Root-Node (a node without any task-data)
TaskNode which has a field to hold the task-data and a QList<TaskNode> which is, in simple terms, a vector of TaskNodes to reference childnodes
Task has the related attributes (like pid and ppid)
It is no problem to insert a TaskNode if the parentnode already exists.
This only works though in a perfect world, in which the Tasks are sorted upon their respective dependencies AND there's a determined amount of Tasks to be added.
I don't have to tell you that such a scenario is highly unlikely though, so the tree creation has to memorize any orphaned node (which is a node that doesn't have a parent yet, duh).
I've tackled this "memorization" in different ways, but failed alltogether because I couldn't wrap my head around the algorithms behind it.
The two most promising thoughts I had were these:
Insert every orphaned node into a vector. Upon inserting a parentnode, check if it has children in the Orphan-Vector and reconcile. Do this recursively for the newly created subtree to match all possiblities.
Assign the PPID to the tree's RootNode, being 0 for the most top one. When an orphaned node appears, create a new TaskTree, assign the PPID of the orphan to the newly created tree and add the orphan to it.
This creates subtrees which can be quit intricate themselfs if several orphans match one of the trees. After each inserted Node, try to reconcile the subtrees to the root-tree.
Unfortunately I had to give up continuing those two concepts due to several spontaneous SIGSEGV's and other problems occuring because of the recursions etc.
So in the end I'm here trying to find a way to actually make this work without cutting down the complexicity of the problem through assumptions and other cheats...
Do you guys and gals have an idea which algorithm I could use for this problem or what category of problem this even is?
Approach 2 is the right one to take. The pieces that you are missing are that you need an unordered_map called node_needed that maps as yet unseen parent nodes to a vector of child trees that are waiting for it. You need a similar one mapping node_seen to the associated tree for nodes that have been seen.
Then when you see a node you perform the following:
Create TaskTree with only this node.
Add this TaskTree to the node_seen map
If this node's ID is in the parent_needed map:
Add each tree in the parent_needed map to this tree
Remove this node's ID from the parent_needed map
If this node has no parent:
Add this node's tree to the root tree
Else if this node's parent ID is in the node_seen map:
Add this node's tree to the parent tree
Else if this node's parent_ID is in the parent_needed map:
Append this node's tree to the parent_needed vector
Else:
Create a vector containing this node's tree
Add a mapping from this node's parent ID to that vector in the parent_needed map
Assuming no bugs (HAH! Bugs are part of life...), this should work.
After some deliberate design changes, I've come up with - what I think - the easiest way to implement this:
InsertTask(Task newTask)
{
Task parentTask = searchTreeForParent(newTask->ppid)
If (parentTask not found)
{
parentTask = treeRootNode;
}
If (treeRootNode has children)
{
For (every children in treeRootNode: child)
{
If (child->ppid != treeRootNode->pid AND child->ppid == newTask->pid)
{
newTask->addChild(child)
treeRootNode->remove(child)
}
}
}
parentTask->addChild(newTask)
}
The algorithm behind it is pretty easy: You add the new Tasks to the root node if there is no parent node yet and at the same time check if the newly added Task has potential children in the root node (because those orphaned ones were added to the root node before).
So if you actually insert all the Tasks to fulfill the dependencies, you end up with a complete and valid tree.
If you don't supply all the parent nodes, you end up with some of the branches being complete and valid and a bunch of orphaned ones in the root node.
But that's no problem because there is an easy trick to differenciate between a complete branch and orphans: just check if the ppid equals the root node's pid and voila, you output only those branches that are complete.

Doctrine Extensions - Tree - Multiple roots

We heavily use the tree doctrine extension in our zf2 project - with some big tree data structures. We know that inserts and updates in a nested set are expensive. We also know that the tree plugin uses the "root" column to find out which tree shall be updated.
Yesterday I read the tree documentation again and found:
"Support for multiple roots in nested-set"
What does it mean and how does it work? I couldn't find any documentation for this feature.
Our hope would be that we could define a second root item of a lower branch of a big tree so that inserts and updates into this lower branch will not affect the whole tree but only this branch. Is it possible?
yes it is possible, tree root branches will be separated by level 0 nodes, see mapping example of TreeRoot column there should be examples for all mapping types to map treeRoot column. The column must be of the same type as ID, it does not support a ManyToOne relation for now, but there is a plan someday to support it.
root1
child
root2
child
child2
When updating or inserting any child on root2 or root1 branch, it will affect only that certain branch. Also note that, tree is still not concurrently safe, you have to manage locking yourself, see documentation reference here.
The doc directory contains most of the information given here.

How do I rotate/translate existing OpenSceneGraph (OSG) nodes from a loaded .ive model tree?

I have a given model in .ive and the problem is that I'm trying to rotate a single node out of the whole tree model (existing in the .ive file). Is that possible? How can I do that?
Sure, it can be done.
You first have to find the nodes that you want to manipulate. You should be able to do this by creating a subclass of osg::NodeVisitor, and using it to traverse the graph until you find the node you want to manipulate. If you've given the node a name, it can be simple to find the one you are looking for. If not, you'll have to figure out some other unique characteristics of the node, or just pull all nodes of a certain type and try them one at a time.
Then, once you have that, you can just save a pointer and manipulate it directly.
See tutorials:
https://www.movesinstitute.org/Sullivan/OSGTutorials/osgDOF.html
and
https://www.movesinstitute.org/Sullivan/OSGTutorials/osgUpdate.htm
You will have to find the node that corresponds with that subsection of the model. To do this you will need to identify something that is unique about that node (hopefully it has a name or something).
Once you have that node, you may need to break it off of the main tree, add a Transform of some kind (a PositionAttitudeTransform, probably) and then re-add your node as a child of the PAT.
Then you can modify the rotations in the PAT.
You might use a visitor like the find named node(s) visitor to locate the node you want.
Consider converting the .ive file to .osgt or .osg in order to see the structure (and hopefully node names) in the file.

XSLT - How can I save a node from one document in another temp document and later retrieve it?

This isn't exactly what I want to do, but it's a simple case of the functionality I need. I want to alternate between processing nodes in one document and processing nodes in a temp document that was created during the processing of the original document. To do this, I want to "save" a node from the original document into the temp document so I can go back to it. I can easily "save" the node itself into the temp document, but being part of the temp document I can no longer do things like test if another node is an ancestor of that node in the original document.
I could imagine using generate-id to do this. I wouldn't save the node per se, but an id to it and then use the id to get back to the node within the original document. The problem with this approach is that I can't ask for the node whose generate-id is such and such. I could go through the tree and find it, but I'm looking for a simpler, faster access method.
Does one exist?
Thanks in advance.
Index every node of interest by its generate-id():
<xsl:key name="kNodeById" match="node()"
use="generate-id()"/>
and to get to the node by its id $vId:
key('kNodeById', $vId)