示例#1
0
void CUniformGrid::GetUnitsInRadius(NodeVector * dstVector, const Vector3 & point, float radius)
{
	const Vector3 radiusPoint(radius, radius, 0);

	int minX, minY;
	CellCoordFromMapPoint(&minX, &minY, point - radiusPoint);
	minX = math::max(0, math::min(minX, (m_Width - 1)));
	minY = math::max(0, math::min(minY, (m_Height - 1)));

	int maxX, maxY;
	CellCoordFromMapPoint(&maxX, &maxY, point + radiusPoint);
	maxX = math::max(0, math::min(maxX, (m_Width - 1)));
	maxY = math::max(0, math::min(maxY, (m_Height - 1)));

	dstVector->clear();

	for (int y = minY; y <= maxY; ++y)
	{
		for (int x = minX; x <= maxX; ++x)
		{
			// FIXME: non optimal - square, refactor me
			NodeVector *  gridVector = GetCell(x, y);
			dstVector->insert(dstVector->end(), gridVector->begin(), gridVector->end());
		}
	}
}
示例#2
0
void sortNodes(NodeVector& all){
	//	int count=0;
	int max=0;
	deque<Node*> sorted;
	for (int i=0; i<all.size(); i++) {
		Node* n=all[i];
		if(n->statementCount>max){
			sorted.push_front(n);
			max=n->statementCount;
		}
		else sorted.push_back(n);
	}
	for (int i=0; i<all.size(); i++) {
		all[i]=sorted[i];
	}
	std::sort(all.begin(), all.end(),sortNodePredicate);
	//	auto x=all.begin();
	//	auto y=all.end();
	//	std::sort(x, y, sortNodePredicate);// [] (Node* a, Node* b){ return a->statementCount > b->statementCount; });
	//	std::sort(all.begin(), all.end(), [] (Node* a, Node* b)->bool { return a->statementCount < b->statementCount; });
	//	showNodes(all,false,false,false);
	//	std::sort(all.begin(), all.end(), [] (Node* a, Node* b) { return a->statementCount < b->statementCount; });
	//	showNodes(all,false,false,false);
	//	std::sort(all.begin(),all.end(),);
	
}
示例#3
0
template<class NodeVector> void FileSystem::debugPrintNodes(NodeVector nodes) {
    if( debug) {
        unsigned int ix;
        NodeInfo* node;

        for (ix = 0; ix < nodes.size(); ++ix) {
            node = nodes.at(ix);

            cout << "Node: " << node->getName()
                << "\t\tSize: " << node->getSize()
                << "\tModify: " << node->getModifyTime()
                << "\tPath: " << node->getPath()
                << "\tSimilars: ";
        
            vector<NodeInfo*>::iterator it;
            vector<NodeInfo*> nodes = node->getSimilar();
            for(it=nodes.begin(); it != nodes.end(); ++it) {
                cout << (*it)->getPath() << ", ";
            }

            cout << endl;
        }
    }

}
示例#4
0
NodeVector SprFrontend::getDeclsFromNode(Node* n, Node*& baseExp) {
    NodeVector res;
    baseExp = nullptr;

    if (!Nest_computeType(n))
        return {};
    n = Nest_explanation(n);
    ASSERT(n);

    // Check if the node is a DeclExp, pointing to the actual references
    if (n->nodeKind == nkSparrowExpDeclExp) {
        baseExp = at(n->referredNodes, 0);
        res = NodeVector(n->referredNodes.beginPtr + 1, n->referredNodes.endPtr);
        return res;
    }

    // Check if this is a ModuleRef; if so, get the it's referred content (inner most package)
    if (n->nodeKind == nkSparrowExpModuleRef) {
        if (Nest_hasProperty(n, propResultingDecl))
            res = {Nest_getCheckPropertyNode(n, propResultingDecl)};
        return res;
    }

    // If the node represents a type, try to get the declaration associated with the type
    Type t = tryGetTypeValue(n);
    if (t && t.hasStorage()) {
        res.push_back(t.referredNode());
    }

    return res;
}
示例#5
0
 void AddFieldNode(CPLXMLNode* node, int iOrderPos)
 {
     if (iOrderPos >= (int)oFields.size())
         oFields.resize(iOrderPos+1);
     //CPLDebug( "OGR_ILI", "Register field with OrderPos %d to Class %s", iOrderPos, GetName());
     oFields[iOrderPos] = node;
 }
示例#6
0
static void willRemoveChildren(ContainerNode* container)
{
    NodeVector children;
    getChildNodes(container, children);

    container->document()->nodeChildrenWillBeRemoved(container);

#if ENABLE(MUTATION_OBSERVERS)
    ChildListMutationScope mutation(container);
#endif

    for (NodeVector::const_iterator it = children.begin(); it != children.end(); it++) {
        Node* child = it->get();

#if ENABLE(MUTATION_OBSERVERS)
        mutation.willRemoveChild(child);
        child->notifyMutationObserversNodeWillDetach();
#endif
#if ENABLE(UNDO_MANAGER)
        if (UndoManager::isRecordingAutomaticTransaction(container))
            UndoManager::addTransactionStep(NodeRemovingDOMTransactionStep::create(container, child));
#endif

        // fire removed from document mutation events.
        dispatchChildRemovalEvents(child);
    }

    ChildFrameDisconnector(container, ChildFrameDisconnector::DoNotIncludeRoot).disconnect();
}
示例#7
0
sure::Scalar sure::keypoints::calculateEntropyWithCrossproducts(const Octree& octree, Node* node, Scalar normalSamplingrate, Scalar radius, Scalar influenceRadius)
{
  FixedPayload mainNormalIntegrate;
  octree.integratePayload(node->fixed().getMeanPosition(), radius, mainNormalIntegrate);
  Normal mainNormal = mainNormalIntegrate.calculateNormal();

  if( mainNormal.isStable() )
  {
    sure::normal::CrossProductHistogram histogram;
    histogram.setInfluenceRadius(influenceRadius);
    NodeVector nodes = octree.getNodes(node->fixed().getMeanPosition(), radius, normalSamplingrate);

    for(unsigned int i=0; i<nodes.size(); ++i)
    {
      Node* currNode = nodes[i];
      NormalPayload* currPayload = static_cast<CrossProductPayload*>(currNode->opt());
      if( currPayload->normal_.isStable())
      {
        histogram.insertCrossProduct(mainNormal.vector(), currPayload->normal_.vector());
      }
    }

    return histogram.calculateEntropy();
  }
  return 0.0;
}
示例#8
0
void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node* nextChild)
{
    ASSERT(newChild);
    ASSERT(nextChild);
    ASSERT(nextChild->parentNode() == this);

    NodeVector targets;
    collectTargetNodes(newChild.get(), targets);
    if (targets.isEmpty())
        return;

    if (nextChild->previousSibling() == newChild || nextChild == newChild) // nothing to do
        return;

    RefPtr<Node> next = nextChild;
    RefPtr<Node> nextChildPreviousSibling = nextChild->previousSibling();
    for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
        Node* child = it->get();

        insertBeforeCommon(next.get(), child);

        childrenChanged(true, nextChildPreviousSibling.get(), nextChild, 1);
        ChildNodeInsertionNotifier(this).notify(child);
    }
}
示例#9
0
sure::Scalar sure::keypoints::calculateEntropyWithCrossproductsPairwise(const Octree& octree, Node* node, Scalar normalSamplingrate, Scalar radius, Scalar influenceRadius)
{
  sure::normal::CrossProductHistogram histogram;
  histogram.setInfluenceRadius(influenceRadius);
  NodeVector nodes = octree.getNodes(node->fixed().getMeanPosition(), radius, normalSamplingrate);
  for(unsigned int i=0; i<nodes.size(); ++i)
  {
    Node* firstNode = nodes[i];
    NormalPayload* firstPayload = static_cast<NormalPayload*>(firstNode->opt());
    const Normal& firstNormal = firstPayload->normal_;

    if( !firstNormal.isStable() )
    {
      continue;
    }

    for(unsigned int j=i+1; j<nodes.size(); ++j)
    {
      Node* secondNode = nodes[j];
      CrossProductPayload* secondPayload = static_cast<CrossProductPayload*>(secondNode->opt());
      const Normal& secondNormal = secondPayload->normal_;
      if( secondNormal.isStable() )
      {
        histogram.insertCrossProduct(firstNormal.vector(), secondNormal.vector());
      }
    }

    return histogram.calculateEntropy();
  }
  return 0.0;
}
示例#10
0
int InsertTriFaceCentroidNode(
    int ix0,
    int ix1,
    int ix2,
    NodeVector & vecNodes
) {
    double dX = (vecNodes[ix0].x + vecNodes[ix1].x + vecNodes[ix2].x) / 3.0;
    double dY = (vecNodes[ix0].y + vecNodes[ix1].y + vecNodes[ix2].y) / 3.0;
    double dZ = (vecNodes[ix0].z + vecNodes[ix1].z + vecNodes[ix2].z) / 3.0;

    // Project to sphere
    double dRadius = sqrt(dX*dX + dY*dY + dZ*dZ);

    dX /= dRadius;
    dY /= dRadius;
    dZ /= dRadius;

    // Index
    int ix = vecNodes.size();

    // Insert node
    vecNodes.push_back(Node(dX, dY, dZ));

    return ix;
}
 boost::optional<ParentObject> SetpointManagerFollowOutdoorAirTemperature_Impl::parent() const {
   NodeVector nodes = getObject<ModelObject>().getModelObjectSources<Node>();
   if (nodes.size() == 1u) {
     return nodes[0];
   }
   return boost::none;
 }
示例#12
0
void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent)
{
    NodeVector children;
    getChildNodes(oldParent, children);

    if (oldParent->document()->hasMutationObserversOfType(MutationObserver::ChildList)) {
        ChildListMutationScope mutation(oldParent);
        for (unsigned i = 0; i < children.size(); ++i)
            mutation.willRemoveChild(children[i].get());
    }

    // FIXME: We need to do notifyMutationObserversNodeWillDetach() for each child,
    // probably inside removeDetachedChildrenInContainer.

    oldParent->removeDetachedChildren();

    for (unsigned i = 0; i < children.size(); ++i) {
        if (children[i]->attached())
            children[i]->detach();
        // FIXME: We need a no mutation event version of adoptNode.
        RefPtr<Node> child = document()->adoptNode(children[i].release(), ASSERT_NO_EXCEPTION);
        parserAppendChild(child.get());
        // FIXME: Together with adoptNode above, the tree scope might get updated recursively twice
        // (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree).
        // Can we do better?
        treeScope()->adoptIfNeeded(child.get());
        if (attached() && !child->attached())
            child->attach();
    }
}
示例#13
0
文件: min.cpp 项目: okhat/ngraph
shared_ptr<Node> op::Min::copy_with_new_args(const NodeVector& new_args) const
{
    if (new_args.size() != 1)
    {
        throw ngraph_error("Incorrect number of new arguments");
    }
    return make_shared<Min>(new_args.at(0), m_reduction_axes);
}
示例#14
0
shared_ptr<Node> op::GetOutputElement::copy_with_new_args(const NodeVector& new_args) const
{
    if (new_args.size() != 1)
    {
        throw ngraph_error("Incorrect number of new arguments");
    }
    return make_shared<GetOutputElement>(new_args.at(0), m_n);
}
示例#15
0
文件: one_hot.cpp 项目: okhat/ngraph
shared_ptr<Node> op::OneHot::copy_with_new_args(const NodeVector& new_args) const
{
    if (new_args.size() != 1)
    {
        throw ngraph_error("Incorrect number of new arguments");
    }
    return make_shared<OneHot>(new_args.at(0), m_shape, m_one_hot_axis);
}
示例#16
0
文件: cos.cpp 项目: okhat/ngraph
shared_ptr<Node> op::Cos::copy_with_new_args(const NodeVector& new_args) const
{
    if (new_args.size() != 1)
    {
        throw ngraph_error("Incorrect number of new arguments");
    }
    return make_shared<Cos>(new_args.at(0));
}
示例#17
0
bool ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, AttachBehavior attachBehavior)
{
    RefPtr<ContainerNode> protect(this);

    // Check that this node is not "floating".
    // If it is, it can be deleted as a side effect of sending mutation events.
    ASSERT(refCount() || parentOrShadowHostNode());

    ec = 0;

    // Make sure adding the new child is ok
    if (!checkAddChild(this, newChild.get(), ec))
        return false;

    if (newChild == m_lastChild) // nothing to do
        return newChild;

    NodeVector targets;
    collectChildrenAndRemoveFromOldParent(newChild.get(), targets, ec);
    if (ec)
        return false;

    if (targets.isEmpty())
        return true;

    // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events.
    if (!checkAcceptChildGuaranteedNodeTypes(this, newChild.get(), ec))
        return false;

    InspectorInstrumentation::willInsertDOMNode(document(), this);

    // Now actually add the child(ren)
    ChildListMutationScope mutation(this);
    for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
        Node* child = it->get();

        // If the child has a parent again, just stop what we're doing, because
        // that means someone is doing something with DOM mutation -- can't re-parent
        // a child that already has a parent.
        if (child->parentNode())
            break;

        treeScope()->adoptIfNeeded(child);

        // Append child to the end of the list
        {
            NoEventDispatchAssertion assertNoEventDispatch;
            appendChildToContainer(child, this);
        }

        updateTreeAfterInsertion(this, child, attachBehavior);
    }

    dispatchSubtreeModifiedEvent();
    return true;
}
示例#18
0
void InitRootTypes::wrapFuncArgs(NodeVector& args, const NodeVector& funcArgs)
{
	for (NodeVector::const_iterator it = funcArgs.begin(); it != funcArgs.end(); it++) {
		const FuncArg::Ptr& funcArg = FuncArg::from(*it);
		TupleTypeArg::Ptr arg(new TupleTypeArg);
		arg->setName(funcArg->getName());
		arg->setType(funcArg->getPossibleType());
		args.push_back(arg);
	}
}
示例#19
0
vector<Algorithm*> Network::innerVisibleAlgorithms(Algorithm* algo) {
  NetworkNode* visibleNetworkRoot = visibleNetwork<NetworkNode>(algo);

  vector<Algorithm*> algos = depthFirstMap(visibleNetworkRoot, returnAlgorithm);

  NodeVector nodes = depthFirstSearch(visibleNetworkRoot);
  for (int i=0; i<(int)nodes.size(); i++) delete nodes[i];

  return algos;
}
示例#20
0
void Class::addFields(const NodeVector& fields)
{
    // Make sure all the nodes given as parameters have the right kind
    for ( Node* field: fields )
    {
        if ( field->nodeKind() != nkFeatherDeclVar )
            REP_INTERNAL(field->location(), "Node %1% must be a field") % field;
    }
    
    children_.insert(children_.end(), fields.begin(), fields.end());
}
示例#21
0
 bool isEmbedded()
 {
     if (isAssocClass)
         for (NodeVector::const_iterator it = oFields.begin(); it != oFields.end(); ++it)
         {
             if (*it == NULL) continue;
             if (CSLTestBoolean(CPLGetXMLValue( *it, "EmbeddedTransfer", "FALSE" )))
                 return true;
         }
     return false;
 }
示例#22
0
文件: node.cpp 项目: okhat/ngraph
NodeVector Node::get_arguments()
{
    NodeVector result;
    for (auto& i : get_inputs())
    {
        {
            result.push_back(i.get_output().get_node());
        }
    }
    return result;
}
示例#23
0
文件: Dijkstra.cpp 项目: trew/TDP005
void Dijkstra::clear_saved_paths() {
	for (std::map<NodePair, NodePath*>::iterator it = saved_paths.begin();
			it != saved_paths.end(); it++) {
		delete (*it).second;
		(*it).second = NULL;
	}
	saved_paths.clear();
	NodeVector nodes = grid->get_nodes();
	for (NodeVector::iterator node = nodes.begin(); node != nodes.end(); node++) {
		(*node)->set_cost_from_start(max_cost);
	}
}
示例#24
0
void Network::topologicalSortExecutionNetwork() {
  // Note: we don't need to do a full-fledged topological sort here, as we do not
  // have any DAG, we actually have a dependency tree. This way we can just do a
  // depth-first search, with ref-counting to account for diamond shapes in the tree.
  // this is similar to the wavefront design pattern used in parallelization

  // Using DFS here also has the advantage that it makes as much as possible use
  // of cache locality

  // 1- get all the nodes and count the number of refs they have
  NodeVector nodes = depthFirstSearch(_executionNetworkRoot);
  map<NetworkNode*, int> refs;

  // this initialization should be useless, but let's do it anyway for clarity
  for (int i=0; i<(int)nodes.size(); i++) refs[nodes[i]] = 0;

  // count the number of refs for each node
  for (int i=0; i<(int)nodes.size(); i++) {
    const NodeVector& children = nodes[i]->children();
    for (int j=0; j<(int)children.size(); j++) {
      refs[children[j]] += 1;
    }
  }

  // 2- do DFS again, manually this time and only visit node which have no refs anymore
  _toposortedNetwork.clear();

  NodeStack toVisit;
  toVisit.push(_executionNetworkRoot);
  refs[_executionNetworkRoot] = 1;

  while (!toVisit.empty()) {
    NetworkNode* currentNode = toVisit.top();
    toVisit.pop();

    if (--refs[currentNode] == 0) {
      _toposortedNetwork.push_back(currentNode->algorithm()); // keep this node, it is good

      const NodeVector& children = currentNode->children();
      for (int i=0; i<(int)children.size(); i++) {
        toVisit.push(children[i]);
      }
    }
  }

  E_DEBUG(ENetwork, "-------------------------------------------------------------------------------------------");
  for (int i=0; i<(int)_toposortedNetwork.size(); i++) {
    E_DEBUG_NONL(ENetwork, " → " << _toposortedNetwork[i]->name());
  }
  E_DEBUG(ENetwork, ""); // for adding a newline
  E_DEBUG(ENetwork, "-------------------------------------------------------------------------------------------");
}
示例#25
0
void ContainerNode::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
    Node::reportMemoryUsage(memoryObjectInfo);
    info.ignoreMember(m_firstChild);
    info.ignoreMember(m_lastChild);

    // Report child nodes as direct members to make them look like a tree in the snapshot.
    NodeVector children;
    getChildNodes(const_cast<ContainerNode*>(this), children);
    for (size_t i = 0; i < children.size(); ++i)
        info.addMember(children[i], "child");
}
示例#26
0
Node* XPathResult::singleNodeValue(ExceptionCode& ec) const
{
    if (resultType() != ANY_UNORDERED_NODE_TYPE && resultType() != FIRST_ORDERED_NODE_TYPE) {
        ec = TYPE_ERR;
        return 0;
    }
  
    NodeVector nodes = m_value.toNodeVector();
    if (nodes.size () == 0)
        return 0;

    return nodes[0].get();
}
示例#27
0
Node* XPathResult::snapshotItem(unsigned long index, ExceptionCode& ec)
{
    if (resultType() != UNORDERED_NODE_SNAPSHOT_TYPE && resultType() != ORDERED_NODE_SNAPSHOT_TYPE) {
        ec = TYPE_ERR;
        return 0;
    }
    
    NodeVector nodes = m_value.toNodeVector();
    if (index >= nodes.size())
        return 0;
    
    return nodes[index].get();
}
示例#28
0
// todo: presorted jumplists
NodeVector intersect(NodeVector a, NodeVector b) {
	NodeVector c;
	NodeVector::iterator it;
	for(it = a.begin(); it != a.end(); ++it)
		if (contains(b, *it))
//			c.insert(*it);
			c.push_back(*it);
//	for (int i=0; i < a.size(); i++) {
//		Node* n=a[0];
//		if (contains(b, n)) c.push_back(n);
//	}
    return c;
}
示例#29
0
// this differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
void ContainerNode::removeChildren()
{
    if (!m_firstChild)
        return;

    // The container node can be removed from event handlers.
    RefPtr<ContainerNode> protect(this);

    // Exclude this node when looking for the focused or full screen Node since
    // only children will be removed.
    // FIXME: We should call these inside the loop below. Right now you can focus
    // a node with mutation events and it'll never get blured.
    document()->removeFocusedNodeOfSubtree(this, true);
    document()->removeFullScreenElementOfSubtree(this, true);

    ChildListMutationScope mutation(this);
    NodeVector removedChildren;
    {
        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;

        while (RefPtr<Node> child = m_firstChild) {
            // Dispatch synchronous events like mutation and unload events.
            dispatchChildRemovalEvents(child.get());
            ChildFrameDisconnector(child.get()).disconnect();

            // FIXME: In theory this can fire focus events when the selection
            // changes, but there's no obvious way to test it.
            document()->nodeWillBeRemoved(child.get());

            // If an event moved the child start over.
            if (child != m_firstChild)
                continue;

            mutation.willRemoveChild(child.get());
            child->notifyMutationObserversNodeWillDetach();
            removeBetween(0, child->nextSibling(), child.get());
            removedChildren.append(child.release());
        }

        // FIXME: We could avoid walking all the children twice by calling
        // notify inside the loop and childrenChanged after but that would mean
        // calling childrenChanged in a different order than all other methods.
        // Figure out if this is safe.
        childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size()));
        for (size_t i = 0; i < removedChildren.size(); ++i)
            ChildNodeRemovalNotifier(this).notify(removedChildren[i].get());
    }

    dispatchSubtreeModifiedEvent();
}
示例#30
0
Algorithm* Network::findAlgorithm(const std::string& name) {
  NodeVector nodes = depthFirstSearch(_visibleNetworkRoot);
  for (NodeVector::iterator node = nodes.begin(); node != nodes.end(); ++node) {
    if ((*node)->algorithm()->name() == name) return (*node)->algorithm();
  }

  ostringstream msg;
  msg << "Could not find algorithm with name '" << name << "'. Known algorithms are: ";
  if (!nodes.empty()) msg << '\'' << nodes[0]->algorithm()->name() << '\'';
  for (int i=1; i<(int)nodes.size(); i++) {
    msg << ", '" << nodes[i]->algorithm()->name() << '\'';
  }
  throw EssentiaException(msg);
}