void KisCanvasResourceProvider::slotCanvasResourceChanged(int key, const QVariant & res) { if(key == KoCanvasResourceManager::ForegroundColor || key == KoCanvasResourceManager::BackgroundColor) { KoAbstractGradient* resource = KoResourceServerProvider::instance()->gradientServer()->resources()[0]; KoStopGradient* stopGradient = dynamic_cast<KoStopGradient*>(resource); if(stopGradient) { QList<KoGradientStop> stops; stops << KoGradientStop(0.0, fgColor()) << KoGradientStop(1.0, bgColor()); stopGradient->setStops(stops); KoResourceServerProvider::instance()->gradientServer()->updateResource(resource); } resource = KoResourceServerProvider::instance()->gradientServer()->resources()[1]; stopGradient = dynamic_cast<KoStopGradient*>(resource); if(stopGradient) { QList<KoGradientStop> stops; stops << KoGradientStop(0.0, fgColor()) << KoGradientStop(1.0, KoColor(QColor(0, 0, 0, 0), fgColor().colorSpace())); stopGradient->setStops(stops); KoResourceServerProvider::instance()->gradientServer()->updateResource(resource); } } switch (key) { case(KoCanvasResourceManager::ForegroundColor): m_fGChanged = true; emit sigFGColorChanged(res.value<KoColor>()); break; case(KoCanvasResourceManager::BackgroundColor): emit sigBGColorChanged(res.value<KoColor>()); break; case(CurrentPattern): emit sigPatternChanged(static_cast<KisPattern *>(res.value<void *>())); break; case(CurrentGeneratorConfiguration): emit sigGeneratorConfigurationChanged(static_cast<KisFilterConfiguration*>(res.value<void*>())); case(CurrentGradient): emit sigGradientChanged(static_cast<KoAbstractGradient *>(res.value<void *>())); break; case(CurrentPaintOpPreset): emit sigPaintOpPresetChanged(currentPreset()); break; case(CurrentKritaNode) : emit sigNodeChanged(currentNode()); break; case(CurrentCompositeOp) : emit sigCompositeOpChanged(currentCompositeOp()); break; case (Opacity): { emit sigOpacityChanged(res.toDouble()); } default: ; // Do nothing }; }
void KisToolDyna::timeoutPaint() { Q_ASSERT(currentPaintOpPreset()->settings()->isAirbrushing()); if (currentImage() && m_painter) { paintAt(m_previousPaintInformation); QRegion r = m_painter->takeDirtyRegion(); dbgPlugins << "Timeout paint dirty region:" << r; currentNode()->setDirty(r); } }
NodeImpl *TreeWalkerImpl::nextNode() { NodeImpl *result = 0; for (NodeImpl *node = currentNode()->traverseNextNode(); node; node = node->traverseNextNode()) { if (acceptNode(node) == NodeFilter::FILTER_ACCEPT && !ancestorRejected(node)) { setCurrentNode(node); result = node; break; } } return result; }
NodeImpl *TreeWalkerImpl::nextSibling() { NodeImpl *result = 0; for (NodeImpl *node = currentNode()->nextSibling(); node; node = node->nextSibling()) { if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) { setCurrentNode(node); result = node; break; } } return result; }
NodeImpl *TreeWalkerImpl::parentNode() { NodeImpl *result = 0; for (NodeImpl *node = currentNode()->parentNode(); node && node != root(); node = node->parentNode()) { if (acceptNode(node) == NodeFilter::FILTER_ACCEPT) { setCurrentNode(node); result = node; break; } } return result; }
//Function used to tie together whole program and allow us to use a single function to invoke an A Star search. void PathFind(bool &goalReached, deque <unique_ptr < SCoords > > &openList, deque <unique_ptr < SCoords > > &closedList, SCoords mapEnd, SCoords &north, SCoords &east, SCoords &south, SCoords &west , int mapArray[10][10], IModel* mapSquares[10][10], IMesh* squareMesh, int newCost, int existingCost, string visitedNodeSkin, string openListNodeSkin, bool &validNode) { unique_ptr<SCoords> currentNode(new SCoords); if (!goalReached || openList.empty()) { currentNode.reset(new SCoords);//Reset the current node every loop because we move current node onto closed list at the end of every loop. currentNode = move(openList.front());//We then set current node to the first value on open list and pop the value from open list. openList.pop_front(); mapSquares[currentNode->y][currentNode->x]->SetSkin(visitedNodeSkin); if (CheckFinish(currentNode.get(), mapEnd.x, mapEnd.y))//Check if the end goal has been reached. If it has then we exit the loop after dispalying an end message. { openList.push_back(move(currentNode));//We then push the final node back onto open list so we can move through it's parent chain. goalReached = true; return; } //If the current node isn't the end goal then we generate new nodes. else { GenerateNodes(north, east, south, west, currentNode.get()); //Then we check if the nodes have already been visited by checking openlist, if they haven't then we insert them. CalculatePath(currentNode.get(), mapArray, newCost, existingCost, north, mapEnd, openList, closedList, validNode); //If the node is a valid node,i.e. the node isn't a wall then a skin is applied to the square to indicate that it is a viable node. if (validNode) { mapSquares[north.y][north.x]->SetSkin(openListNodeSkin); } validNode = false; CalculatePath(currentNode.get(), mapArray, newCost, existingCost, east, mapEnd, openList, closedList, validNode); if (validNode) { mapSquares[east.y][east.x]->SetSkin(openListNodeSkin); } validNode = false; CalculatePath(currentNode.get(), mapArray, newCost, existingCost, south, mapEnd, openList, closedList, validNode); if (validNode) { mapSquares[south.y][south.x]->SetSkin(openListNodeSkin); } validNode = false; CalculatePath(currentNode.get(), mapArray, newCost, existingCost, west, mapEnd, openList, closedList, validNode); if (validNode) { mapSquares[west.y][west.x]->SetSkin(openListNodeSkin); } validNode = false; closedList.push_back(move(currentNode)); } //The list is then sorted based on score from lowest to highest. sort(openList.begin(), openList.end(), CompareCoords); } }
void WHtreeProcesser::collapseNode( const size_t thisNodeID, const dist_t coefficient, HTPROC_COLLAPSE collapseMode ) { if( thisNodeID > m_tree.getRoot().getID() ) { throw std::runtime_error( "ERROR @ collapseNode::flattenBranch(): nodeID is out of boundaries" ); } const WHnode& thisNode( m_tree.getNode( thisNodeID ) ); dist_t upperLevel( thisNode.getDistLevel() ); std::list< nodeID_t > worklist; worklist.push_back( thisNode.getFullID() ); while( !worklist.empty() ) { WHnode* currentNode( m_tree.fetchNode( worklist.front() ) ); worklist.pop_front(); std::vector< nodeID_t > currentKids( currentNode->getChildren() ); dist_t parentLevel( currentNode->getDistLevel() ); for( std::vector< nodeID_t >::iterator kidIter( currentKids.begin() ); kidIter != currentKids.end(); ++kidIter ) { if( m_tree.getNode( *kidIter ).isNode() ) { dist_t kidLevel( m_tree.getNode( *kidIter ).getDistLevel() ); bool doCollapse( false ); switch( collapseMode ) { case HTPR_C_CONSTANT: doCollapse = ( ( parentLevel - kidLevel ) < coefficient ); break; case HTPR_C_LINEAR: doCollapse = ( ( parentLevel - kidLevel ) < ( kidLevel * coefficient ) ); break; case HTPR_C_SQ: doCollapse = ( ( parentLevel - kidLevel ) < ( kidLevel * kidLevel * coefficient ) ); break; default: break; } if( doCollapse ) { worklist.push_back( *kidIter ); } } } currentNode->setDistLevel( upperLevel ); } return; } // end collapseNodeLinear() -------------------------------------------------------------------------------------
QString KGameSvgDocument::nodeToSvg() const { QString s, t, xml, defs, pattern; QTextStream str(&s); QTextStream str_t(&t); QStringList defsAdded; int result = 0; QRegExp rx; currentNode().save(str, 1); xml = *str.string(); // Find and add any required gradients or patterns pattern = QLatin1String( "url" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK + QLatin1String( "#(.*)" ) + WSP_ASTERISK + CLOSE_PARENS; rx.setPattern(pattern); if (rx.indexIn(xml, result) != -1) { QDomNode node, nodeBase; QString baseId; QDomNode n = def(); result = 0; while ((result = rx.indexIn(xml, result)) != -1) { // Find the pattern or gradient referenced result += rx.matchedLength(); if (!defsAdded.contains(rx.cap(1))) { node = d->findElementById(QLatin1String( "id" ), rx.cap(1), n); node.save(str_t, 1); defsAdded.append(rx.cap(1)); } // Find the gradient the above gradient is based on baseId = node.toElement().attribute(QLatin1String( "xlink:href" )).mid(1); if (!defsAdded.contains(baseId)) { nodeBase = d->findElementById(QLatin1String( "id" ), baseId, n); nodeBase.save(str_t, 1); defsAdded.append(baseId); } } defs = *str_t.string(); defs = QLatin1String( "<defs>" ) + defs + QLatin1String( "</defs>" ); } // Need to make node be a real svg document, so prepend and append required tags. xml = d->SVG_XML_PREPEND + defs + xml + d->SVG_XML_APPEND; return xml; }
void doWork() override { if (!hasWork()) return; NodeID nodeID = currentNode(); Node& node = _nodeTree->_nodes[nodeID]; _tracer.setNode(nodeID); _reader.setNode(nodeID, node.numInputSockets()); try { if(_withInit && node.flag(ENodeFlags::StateNode)) { // Try to restart node internal state if any if(!node.restart()) { throw ExecutionError{node.nodeName(), nodeTypeName(nodeID), "Error during node state restart"}; } } ExecutionStatus ret = node.execute(_reader, _writer); switch (ret.status) { case EStatus::Tag: // Tag for next execution tagNode(nodeID); break; case EStatus::Error: // If node reported an error tagNode(nodeID); throw ExecutionError{node.nodeName(), nodeTypeName(nodeID), ret.message}; break; case EStatus::Ok: default: break; } ++_pos; } catch (...) { _nodeTree->handleException(nodeID, _tracer); } }
void HTMLConstructionSite::insertTextNode(const String& string, WhitespaceMode whitespaceMode) { HTMLConstructionSiteTask dummyTask(HTMLConstructionSiteTask::Insert); dummyTask.parent = currentNode(); // FIXME: This probably doesn't need to be done both here and in insert(Task). if (isHTMLTemplateElement(*dummyTask.parent)) dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->content(); // Unclear when parent != case occurs. Somehow we insert text into two separate // nodes while processing the same Token. When it happens we have to flush the // pending text into the task queue before making more. if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent)) flushPendingText(); m_pendingText.append(dummyTask.parent, string, whitespaceMode); }
void Q3CList::insert(Q3CacheItem *ci) { Q3CacheItem *item = first(); while(item && item->skipPriority > ci->priority) { item->skipPriority--; item = next(); } if (item) Q3PtrList<Q3CacheItem>::insert(at(), ci); else append(ci); #if defined(QT_DEBUG) Q_ASSERT(ci->node == 0); #endif ci->node = currentNode(); }
QgsLayerTreeGroup* QgsLayerTreeView::currentGroupNode() const { QgsLayerTreeNode* node = currentNode(); if ( QgsLayerTree::isGroup( node ) ) return QgsLayerTree::toGroup( node ); else if ( QgsLayerTree::isLayer( node ) ) { QgsLayerTreeNode* parent = node->parent(); if ( QgsLayerTree::isGroup( parent ) ) return QgsLayerTree::toGroup( parent ); } if ( QgsLayerTreeModelLegendNode* legendNode = layerTreeModel()->index2legendNode( selectionModel()->currentIndex() ) ) { QgsLayerTreeLayer* parent = legendNode->layerNode(); if ( QgsLayerTree::isGroup( parent->parent() ) ) return QgsLayerTree::toGroup( parent->parent() ); } return 0; }
//========================================================================= void BubbleChartView::onCurrentNodeChanged(BaseTaxNode *node) { BaseTaxNode *curNode = currentNode(); if ( curNode == node ) return; BaseTaxNode *oldCurNode = curNode; taxDataProvider->current_tax_id = node->getId(); foreach(QGraphicsItem *item, scene()->items()) { if ( item->type() == GraphNode::Type ) { ChartGraphNode *n = (ChartGraphNode *)item; compareNodesAndUpdate(n, oldCurNode); compareNodesAndUpdate(n, node); } } if ( curNode != NULL && oldCurNode != NULL && node->getId() == oldCurNode->getId() ) return; setVerticalLegentColor(node, true); setVerticalLegentColor(oldCurNode, false); }
void AlignDialog::rebuildTree() { currentArc =0; gla=edit->gla; QList<MeshNode*> &meshList=meshTree->nodeList; ui.alignTreeWidget->clear(); M2T.clear(); A2Tf.clear(); A2Tb.clear(); for(int i=0;i<meshList.size();++i) { MeshTreeWidgetItem *item=new MeshTreeWidgetItem(meshList.value(i)); // if(meshList.value(i)==currentNode) item->setBackground(0,QBrush(QColor(Qt::lightGray))); M2T[meshList.value(i)]=item; ui.alignTreeWidget->insertTopLevelItem(i,item); } // Second part add the arcs to the tree vcg::AlignPair::Result *A; MeshTreeWidgetItem *parent; MeshTreeWidgetItem *item; for(int i=0;i< meshTree->resultList.size();++i) { A=&(meshTree->resultList[i]); // Forward arc parent=M2T[meshList.at((*A).FixName)]; item = new MeshTreeWidgetItem(meshTree, A, parent); A2Tf[A]=item; // Backward arc parent=M2T[meshList.at((*A).MovName)]; item = new MeshTreeWidgetItem(meshTree, A, parent); A2Tb[A]=item; } ui.alignTreeWidget->resizeColumnToContents(0); ui.alignTreeWidget->resizeColumnToContents(1); ui.alignTreeWidget->resizeColumnToContents(2); assert(currentNode()); updateCurrentNodeBackground(); updateButtons(); }
//for this problem g(n) will return the number of moves executed so far unless the user specifies '-cost' in the command line. //In the case where the user enters the -cost flag, g(n) will calculate the cost of an action as the number of spaces a tile moves during an action unsigned int Problem::g(const Node& n) { Node currentNode(n); if(hasCost == false) { /* returns the cumulative cost down to this node. Each move (equivalent to a level down the tree) has a cost of 1. */ unsigned int numMoves = 0; while(currentNode.parent != NULL) { currentNode = *currentNode.parent; numMoves++; } return numMoves; } else { /* returns the numbers of slots a tile will travel in the given move. Argument 1 is the node representing the initial puzzle state, argument 1 is the node representing the final puzzle state, the difference between the two states is used to calculate the cost of the move. */ unsigned int totalCost = 0; while(currentNode.parent != NULL) { currentNode = *currentNode.parent; totalCost += currentNode.cost; } return totalCost; } }
void NKView::IndexToNode(QModelIndex i) { emit currentNode(Mapregnode[i]); }
void AlignDialog::updateDialog() { assert(meshTree!=0); assert(currentNode() == meshTree->find(currentNode()->m)); updateButtons(); }
TreeWalkerImpl::TreeWalkerImpl(NodeImpl *rootNode, long whatToShow, NodeFilterImpl *filter, bool expandEntityReferences) : TraversalImpl(rootNode, whatToShow, filter, expandEntityReferences), m_current(rootNode) { if (currentNode()) currentNode()->ref(); }
bool GXLImporter::parseGraph( void ) { bool ok = true; bool edgeOrientedDefault = false; bool edgeOrientedDefaultForce = false; // current "graph" node if ( ok ) { QXmlStreamAttributes attrs = xml_->attributes(); QStringRef graphEdgeMode = attrs.value( "edgemode" ); if ( !graphEdgeMode.isEmpty() ) { if ( graphEdgeMode == "defaultdirected" ) { edgeOrientedDefault = true; edgeOrientedDefaultForce = false; } else if ( graphEdgeMode == "defaultundirected" ) { edgeOrientedDefault = false; edgeOrientedDefaultForce = false; } else if ( graphEdgeMode == "directed" ) { edgeOrientedDefault = true; edgeOrientedDefaultForce = true; } else if ( graphEdgeMode == "undirected" ) { edgeOrientedDefault = false; edgeOrientedDefaultForce = true; } else { ok = false; context_->getInfoHandler().reportError( "Invalid edgemode value." ); } } } osg::ref_ptr<Data::Node> currentNode( NULL ); osg::ref_ptr<Data::Edge> currentEdge( NULL ); osg::ref_ptr<Data::Node> hyperEdgeNode( NULL ); bool inHyperedge = false; while ( ok && !xml_->atEnd() ) { QXmlStreamReader::TokenType token; if ( ok ) { token = xml_->readNext(); } if ( ok ) { // vnoreny graf if ( ( token == QXmlStreamReader::StartElement ) && ( xml_->name() == "graph" ) ) { if ( ok ) { if ( static_cast<bool>( currentNode ) ) { context_->getGraph().createNestedGraph( currentNode ); } else if ( static_cast<bool>( currentEdge ) ) { // moznost pridania vnoreneho grafu do hrany } else { ok = false; context_->getInfoHandler().reportError( "Subgraph found, but it is not placed in node/edge." ); } } if ( ok ) { ok = parseGraph(); } if ( ok ) { context_->getGraph().closeNestedGraph(); } } // parsovanie uzla if ( ( token == QXmlStreamReader::StartElement ) && ( xml_->name() == "node" ) ) { if ( ok ) { ok = ( !currentNode ) && ( !currentEdge ) && ( !inHyperedge ); context_->getInfoHandler().reportError( ok, "Node in node/edge/hyperedge found." ); } QXmlStreamAttributes attrs = xml_->attributes(); QString nodeName; if ( ok ) { nodeName = attrs.value( "id" ).toString(); ok = !( nodeName.isEmpty() ); context_->getInfoHandler().reportError( ok, "Node ID can not be empty." ); } osg::ref_ptr<Data::Node> node( NULL ); if ( ok ) { node = context_->getGraph().addNode( nodeName, nodeType_ ); ok = node.valid(); context_->getInfoHandler().reportError( ok, "Unable to add new node." ); } if ( ok ) { readNodes_->addNode( nodeName, node ); } if ( ok ) { currentNode = node; } } if ( ( token == QXmlStreamReader::EndElement ) && ( xml_->name() == "node" ) ) { if ( ok ) { ok = currentNode; context_->getInfoHandler().reportError( ok, "Node end without matched node begin." ); } if ( ok ) { ( void )currentNode.release(); } } // parsovanie hrany if ( ( token == QXmlStreamReader::StartElement ) && ( xml_->name() == "edge" ) ) { if ( ok ) { ok = ( !currentNode ) && ( !currentEdge ) && ( !inHyperedge ); context_->getInfoHandler().reportError( ok, "Edge in node/edge/hyperedge found." ); } QXmlStreamAttributes attrs = xml_->attributes(); bool oriented = edgeOrientedDefault; if ( ok ) { QStringRef edgeIsDirected = attrs.value( "isdirected" ); if ( !edgeIsDirected.isEmpty() ) { if ( edgeIsDirected == "true" ) { if ( ( !edgeOrientedDefaultForce ) || ( edgeOrientedDefault ) ) { oriented = true; } else { ok = false; context_->getInfoHandler().reportError( "Can not replace global edge mode with edgeIsDirected=\"true\"." ); } } else if ( edgeIsDirected == "false" ) { if ( ( !edgeOrientedDefaultForce ) || ( !edgeOrientedDefault ) ) { oriented = false; } else { ok = false; context_->getInfoHandler().reportError( "Can not replace global edge mode with edgeIsDirected=\"false\"." ); } } else { context_->getInfoHandler().reportError( ok, "Invalid edgeIsDirected value." ); } } } //cielovy a zdrojovy uzol hrany QString nodeFromName; if ( ok ) { nodeFromName = attrs.value( "from" ).toString(); ok = !( nodeFromName.isEmpty() ); context_->getInfoHandler().reportError( ok, "Edge \"from\" attribute can not be empty." ); } QString nodeToName; if ( ok ) { nodeToName = attrs.value( "to" ).toString(); ok = !( nodeToName.isEmpty() ); context_->getInfoHandler().reportError( ok, "Edge \"to\" attribute can not be empty." ); } QString edgeName = nodeFromName + nodeToName; if ( ok ) { ok = readNodes_->contains( nodeFromName ); context_->getInfoHandler().reportError( ok, "Edge references invalid source node." ); } if ( ok ) { ok = readNodes_->contains( nodeToName ); context_->getInfoHandler().reportError( ok, "Edge references invalid destination node." ); } osg::ref_ptr<Data::Edge> edge( NULL ); if ( ok ) { edge = context_->getGraph().addEdge( edgeName, readNodes_->get( nodeFromName ), readNodes_->get( nodeToName ), edgeType_, oriented ); } if ( ok ) { currentEdge = edge; } } if ( ( token == QXmlStreamReader::EndElement ) && ( xml_->name() == "edge" ) ) { if ( ok ) { ok = currentEdge; context_->getInfoHandler().reportError( ok, "Edge end without matched edge begin." ); } if ( ok ) { ( void )currentEdge.release(); } } // hyperhrana if ( ( token == QXmlStreamReader::StartElement ) && ( xml_->name() == "rel" ) ) { if ( ok ) { ok = ( !currentNode ) && ( !currentEdge ) && ( !inHyperedge ); context_->getInfoHandler().reportError( ok, "Hyperedge in node/edge/hyperedge found." ); } QXmlStreamAttributes attrs = xml_->attributes(); QString hyperEdgeName; if ( ok ) { hyperEdgeName = attrs.value( "id" ).toString(); ok = !( hyperEdgeName.isEmpty() ); context_->getInfoHandler().reportError( ok, "Node ID can not be empty." ); } if ( ok ) { // zaciatok hyperhrany hyperEdgeNode = context_->getGraph().addHyperEdge( hyperEdgeName ); } if ( ok ) { inHyperedge = true; } } if ( ( token == QXmlStreamReader::EndElement ) && ( xml_->name() == "rel" ) ) { if ( ok ) { ok = inHyperedge; context_->getInfoHandler().reportError( ok, "Hyperedge end without matched hyperedge begin." ); } if ( ok ) { inHyperedge = false; } } // ukoncenie hyperhrany if ( ( token == QXmlStreamReader::StartElement ) && ( xml_->name() == "relend" ) ) { if ( ok ) { ok = inHyperedge; context_->getInfoHandler().reportError( ok, "Hyperedge endpoint without hyperedge." ); } QXmlStreamAttributes attrs = xml_->attributes(); QString targetName; if ( ok ) { targetName = attrs.value( "target" ).toString(); ok = !( targetName.isEmpty() ); context_->getInfoHandler().reportError( ok, "Hyperedge endpoint \"target\" attribute can not be empty." ); } if ( ok ) { ok = readNodes_->contains( targetName ); context_->getInfoHandler().reportError( ok, "Hyperedge endpoint references invalid target node." ); } osg::ref_ptr<Data::Node> target( NULL ); if ( ok ) { target = readNodes_->get( targetName ); } QString direction; if ( ok ) { direction = attrs.value( "direction" ).toString(); if ( direction == QString( "none" ) ) { direction = QString(); } ok = direction.isEmpty() || ( direction == QString( "in" ) ) || ( direction == QString( "out" ) ) ; context_->getInfoHandler().reportError( ok, "Hyperedge endpoint - invalid direction." ); } if ( ok ) { if ( direction.isEmpty() ) { direction = "none"; } } if ( ok ) { // TODO: add endpoint if ( direction==QString( "in" ) ) { context_->getGraph().addEdge( "", target, hyperEdgeNode, nodeType_, true ); } else if ( direction==QString( "out" ) ) { context_->getGraph().addEdge( "", hyperEdgeNode, target, nodeType_, true ); } else { context_->getGraph().addEdge( "", hyperEdgeNode, target, nodeType_, false ); } } } if ( ( token == QXmlStreamReader::EndElement ) && ( xml_->name() == "relend" ) ) { } // this graph end if ( ( token == QXmlStreamReader::EndElement ) && ( xml_->name() == "graph" ) ) { break; } } if ( ok ) { ok = !xml_->hasError(); context_->getInfoHandler().reportError( ok, "XML format error." ); } } // TODO: graf vnoreny v hyperhrane return ok; }
bool SnapToMovement::testSnapTo(const WFMath::Point<3>& position, const WFMath::Quaternion& orientation, WFMath::Vector<3>& adjustment, EmberEntity* snappedToEntity) { try { for (std::vector<Ogre::SceneNode*>::iterator I = mDebugNodes.begin(); I != mDebugNodes.end(); ++I) { Ogre::SceneNode* node = *I; node->setVisible(false); Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (node->getAttachedObject(0)); sphereEntity->setMaterialName("/global/authoring/point"); } } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting up debug nodes for snapping." << ex); } std::vector<Ogre::SceneNode*>::iterator nodeIterator = mDebugNodes.begin(); //Use an auto pointer to allow both for undefined values and automatic cleanup when exiting the method. std::auto_ptr<SnapPointCandidate> closestSnapping(0); WFMath::AxisBox<3> currentBbox = mEntity.getBBox(); //Translate the bbox into a rotbox WFMath::RotBox<3> currentRotbox; currentRotbox.size() = currentBbox.highCorner() - currentBbox.lowCorner(); currentRotbox.corner0() = currentBbox.lowCorner(); currentRotbox.orientation().identity(); currentRotbox.rotatePoint(orientation, WFMath::Point<3>(0, 0, 0)); currentRotbox.shift(WFMath::Vector<3>(position)); //See if we should visualize debug nodes for the moved entity for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); if (currentPoint.isValid() && nodeIterator != mDebugNodes.end()) { Ogre::SceneNode* node = *nodeIterator; node->setPosition(Convert::toOgre(currentPoint)); node->setVisible(true); nodeIterator++; } } //First find all entities which are close enough //Then try to do a snap movement based on the points of the eris bounding boxes. I.e. we only provide support for snapping one corner of a bounding box to another corner (for now). WFMath::Ball<3> boundingSphere = mEntity.getBBox().boundingSphere(); Ogre::Sphere sphere(mNode._getDerivedPosition(), boundingSphere.radius() * 2); Ogre::SphereSceneQuery* query = mSceneManager.createSphereQuery(sphere); Ogre::SceneQueryResult& result = query->execute(); for (Ogre::SceneQueryResultMovableList::const_iterator I = result.movables.begin(); I != result.movables.end(); ++I) { Ogre::MovableObject* movable = *I; if (movable->getUserAny().getType() == typeid(EmberEntityUserObject::SharedPtr)) { EmberEntityUserObject* anUserObject = Ogre::any_cast<EmberEntityUserObject::SharedPtr>(movable->getUserAny()).get(); EmberEntity& entity = anUserObject->getEmberEntity(); if (&entity != &mEntity && entity.hasBBox()) { //Ok, we have an entity which is close to our entity. Now check if any of the points of the bounding box is close. WFMath::AxisBox<3> bbox = entity.getBBox(); if (bbox.isValid()) { WFMath::RotBox<3> rotbox; rotbox.size() = bbox.highCorner() - bbox.lowCorner(); rotbox.corner0() = bbox.lowCorner(); rotbox.orientation().identity(); rotbox.rotatePoint(entity.getViewOrientation(), WFMath::Point<3>(0, 0, 0)); rotbox.shift(WFMath::Vector<3>(entity.getViewPosition())); for (size_t i = 0; i < rotbox.numCorners(); ++i) { WFMath::Point<3> point = rotbox.getCorner(i); Ogre::SceneNode* currentNode(0); //If there is any unclaimed debug node left we'll use it to visualize the corner if (nodeIterator != mDebugNodes.end()) { currentNode = *nodeIterator; currentNode->setPosition(Convert::toOgre(point)); currentNode->setVisible(true); nodeIterator++; } point.z() = 0; for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); currentPoint.z() = 0; WFMath::CoordType distance = WFMath::Distance(currentPoint, point); if (distance <= mSnapThreshold) { if (currentNode) { Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (currentNode->getAttachedObject(0)); if (sphereEntity) { try { sphereEntity->setMaterialName("/global/authoring/point/moved"); } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting material for point." << ex); } } } if (!closestSnapping.get()) { closestSnapping = std::auto_ptr<SnapPointCandidate>(new SnapPointCandidate()); closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } else if (distance < closestSnapping->distance) { closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } } } } } } } } mSceneManager.destroyQuery(query); if (closestSnapping.get()) { adjustment = closestSnapping->adjustment; snappedToEntity = closestSnapping->entity; return true; } return false; }
std::pair< size_t, size_t > WHtreeProcesser::pruneTree( float condition, size_t safeSize, const HTPROC_MODE pruneType ) { if( safeSize == 0 ) { safeSize = m_tree.getNumLeaves(); // any cluster no matter what size may be pruned if he meets the conditions } if( pruneType == HTPR_SIZERATIO ) { if( condition < 2 ) throw std::runtime_error( "ERROR @ WHtreeProcesser::pruneTree(): size pruning ratio must be equal or greater than 2" ); } else if( pruneType == HTPR_JOINSIZE ) { condition = std::floor( condition ); if( condition < safeSize ) throw std::runtime_error( "ERROR @ WHtreeProcesser::pruneTree(): size pruning lower boundary must be smaller than greater boundary" ); } else if( pruneType == HTPR_JOINLEVEL ) { if( condition <= 0 || condition >= 1 ) { throw std::runtime_error( "ERROR @ WHtreeProcesser::pruneTree(): condition is out of boundaries" ); } if( safeSize >= m_tree.getNumLeaves() ) { throw std::runtime_error( "ERROR @ WHtreeProcesser::pruneTree(): when pruning by distance level a safe size smaller than the roi size must be entered" ); } } size_t prunedLeaves( 0 ), prunedNodes( 0 ); // loop through all leaves and set them to prune if they match discardidng conditions for( std::vector< WHnode >::iterator leavesIter( m_tree.m_leaves.begin() ); leavesIter != m_tree.m_leaves.end(); ++leavesIter ) { size_t parentID( leavesIter->getParent().second ); size_t parentLevel( m_tree.getNode( parentID ).getDistLevel() ); if( ( pruneType == HTPR_JOINLEVEL ) && ( parentLevel > condition ) ) { leavesIter->setFlag( true ); } else if( ( pruneType == HTPR_SIZERATIO ) || ( pruneType == HTPR_JOINSIZE ) ) { size_t biggerSize( 0 ); std::vector< nodeID_t > kids( m_tree.getNode( parentID ).getChildren() ); for( size_t i = 0; i < kids.size(); ++i ) { size_t brotherSize( m_tree.getNode( kids[i] ).getSize() ); if( brotherSize > biggerSize ) { biggerSize = brotherSize; } } if( biggerSize > condition ) { leavesIter->setFlag( true ); } } } // loop through all nodes and set them to prune if they match discarding conditions for( std::vector< WHnode >::iterator nodesIter( m_tree.m_nodes.begin() ); nodesIter != m_tree.m_nodes.end() - 1; ++nodesIter ) { // dont check last node size_t parentID( nodesIter->getParent().second ); size_t nodeSize( nodesIter->getSize() ); size_t parentLevel( m_tree.getNode( parentID ).getDistLevel() ); bool pruneBranch( false ); if( nodeSize < safeSize ) { if( ( pruneType == HTPR_JOINLEVEL ) && ( parentLevel > condition ) ) { pruneBranch = true; } else if( ( pruneType == HTPR_SIZERATIO ) || ( pruneType == HTPR_JOINSIZE ) ) { size_t biggerSize( 0 ); std::vector< nodeID_t > kids( m_tree.getNode( parentID ).getChildren() ); for( size_t i = 0; i < kids.size(); ++i ) { if( kids[i] == nodesIter->getFullID() ) { continue; } size_t brotherSize( m_tree.getNode( kids[i] ).getSize() ); if( brotherSize > biggerSize ) { biggerSize = brotherSize; } } if( ( pruneType == HTPR_SIZERATIO ) && ( biggerSize > ( nodeSize * condition ) ) ) { pruneBranch = true; } if( ( pruneType == HTPR_JOINSIZE ) && ( biggerSize >= condition ) ) { pruneBranch = true; } } } if( pruneBranch ) { std::list< nodeID_t > worklist; worklist.push_back( nodesIter->getFullID() ); while( !worklist.empty() ) { WHnode* currentNode( m_tree.fetchNode( worklist.front() ) ); worklist.pop_front(); // if current node has already been pruned we continue with the next iteration if( currentNode->isFlagged() ) { continue; } currentNode->setFlag( true ); std::vector< nodeID_t > currentKids( currentNode->getChildren() ); worklist.insert( worklist.end(), currentKids.begin(), currentKids.end() ); } } } // count total pruned leaves for( std::vector< WHnode >::iterator leavesIter( m_tree.m_leaves.begin() ); leavesIter != m_tree.m_leaves.end(); ++leavesIter ) { if( leavesIter->isFlagged() ) { ++prunedLeaves; } } // count total pruned nodes for( std::vector< WHnode >::iterator nodesIter( m_tree.m_nodes.begin() ); nodesIter != m_tree.m_nodes.end() - 1; ++nodesIter ) { if( nodesIter->isFlagged() ) ++prunedNodes; } if( pruneType == HTPR_SIZERATIO ) { m_tree.m_treeName += ( "_prunedR" + string_utils::toString( safeSize ) + ":" + string_utils::toString( condition ) ); } else if( pruneType == HTPR_JOINSIZE ) { m_tree.m_treeName += ( "_prunedS" + string_utils::toString( condition ) + ":" + string_utils::toString( safeSize ) ); } else if( pruneType == HTPR_JOINLEVEL ) { m_tree.m_treeName += ( "_prunedL" + string_utils::toString( safeSize ) + ":" + string_utils::toString( condition ) ); } std::pair< size_t, size_t > pruned( m_tree.cleanup() ); pruned.second += m_tree.debinarize(); return pruned; } // end "pruneTree()" -----------------------------------------------------------------
TreeWalkerImpl::~TreeWalkerImpl() { if (currentNode()) currentNode()->deref(); }
void HTMLConstructionSite::insertHTMLElement(AtomicHTMLToken* token) { RefPtr<HTMLElement> element = createHTMLElement(token); attachLater(currentNode(), element); m_openElements.push(element.release()); }
inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode() { if (isHTMLTemplateElement(*currentNode())) return toHTMLTemplateElement(currentElement())->content()->document(); return currentNode()->document(); }