// -------------------------------------------------------------------- static void _copy_parents( const_pointer_type source, pointer_type target) { // // Do nothing if the source is the root. // const auto source_parent = source->_parent; if (source_parent == nullptr) return; // // Clone the source parent and assign it as a child of the target. // auto target_child = source_parent->_clone(); target->_children.push_back(target_child); target_child->_parent = target; // // Recursively process the children and parents. // _copy_children(source_parent, target_child, source); _copy_parents(source_parent, target_child); // // Reverse the direction of the length for the new child. // target_child->_length = source->_length; target_child->_has_length = source->_has_length; }
// copy constructor BaseExample & BaseExample::operator =(BaseExample & e) { if (this != &e) { clear (); for (int i = 0; i < e.l; i++) { inc_refcount_feature_node (e.x[i]); add (e.y[i], e.x[i]); } l = e.l; pack_d = e.pack_d; svindex_size = e.svindex_size; if (svindex_size) { _clone (alpha, e.alpha, svindex_size); _clone (G, e.G, svindex_size); } } return *this; }
EntityPrototype::EntityPrototype( Entity* ent) { _prototype = _clone( ent ); // Deactivate the prototype for( auto i=_prototype->mComponents.begin();i!=_prototype->mComponents.end();i++) { (*i)->deactivate(); } }
Entity* EntityPrototype::spawn(void) { Entity* ent = _clone( _prototype ); // Activate all components for( auto i=ent->mComponents.begin();i!=ent->mComponents.end();i++) { (*i)->activate(); } return ent; }
HSceneObject Prefab::instantiate() { if (mRoot == nullptr) return HSceneObject(); #if BS_IS_BANSHEE3D if (gCoreApplication().isEditor()) { // Update any child prefab instances in case their prefabs changed _updateChildInstances(); } #endif HSceneObject clone = _clone(); clone->_instantiate(); return clone; }
/// /// Creates a new tree based on the tree associated with this node; in /// the tree returned, a copy of this node is the root. /// /// \return A new Newick node, the root of an equivalent tree. /// pointer_type reroot() const { // // Reroot the structure of the tree. // auto root = _clone(); _copy_children(this, root, nullptr); _copy_parents(this, root); // // To preserve information, assign the length // to the old root to this new root. // auto old_root = find_root(); root->_length = old_root->_length; root->_has_length = old_root->_has_length; return root; }
static void _clone(LV2_OSC_Reader *reader, LV2_OSC_Writer *writer, size_t size) { if(lv2_osc_reader_is_bundle(reader)) { LV2_OSC_Item *itm = OSC_READER_BUNDLE_BEGIN(reader, size); assert(itm); LV2_OSC_Writer_Frame frame_bndl; assert(lv2_osc_writer_push_bundle(writer, &frame_bndl, itm->timetag)); OSC_READER_BUNDLE_ITERATE(reader, itm) { LV2_OSC_Reader reader2; lv2_osc_reader_initialize(&reader2, itm->body, itm->size); LV2_OSC_Writer_Frame frame_itm; assert(lv2_osc_writer_push_item(writer, &frame_itm)); _clone(&reader2, writer, itm->size); assert(lv2_osc_writer_pop_item(writer, &frame_itm)); } assert(lv2_osc_writer_pop_bundle(writer, &frame_bndl)); }
int QP_Solver::solve(const BaseExample &e, const Param &p, double *b_, double *alpha_, double *G_, double &rho, double &obj) { try { param = p; C = p.C; eps = p.eps; shrink_size = p.shrink_size; shrink_eps = p.shrink_eps; final_check = p.final_check; l = e.l; active_size = l; iter = 0; hit_old = 0; _clone (alpha, alpha_, l); _clone (G, G_, l); _clone (b, b_, l); _clone (y, e.y, l); _clone (x, e.x, l); q_matrix = new QMatrix (e, p); q_matrix->set (y, x); shrink_iter = new int [l]; status = new int [l]; active2index = new int [l]; for (int i = 0; i < l; i++) { status[i] = alpha2status(alpha[i]); shrink_iter[i] = 0; active2index[i] = i; } for (;;) { learn_sub(); if (final_check == 0 || check_inactive () == 0) break; q_matrix->rebuildCache (active_size); q_matrix->set (y, x); shrink_eps = p.shrink_eps; } // make result for (int i = 0; i < l; i++) { alpha_[active2index[i]] = alpha[i]; G_[active2index[i]] = G[i]; } // calculate objective value obj = 0; for (int i = 0; i < l; i++) obj += alpha[i] * (G[i] + b[i]); obj /= 2; // calculate threshold b rho = lambda_eq; delete [] status; delete [] alpha; delete [] x; delete [] y; delete [] b; delete [] G; delete [] active2index; delete [] shrink_iter; delete q_matrix; fprintf (stdout, "\nDone! %d iterations\n\n", iter); return 1; } catch (...) { fprintf (stderr, "QP_Solver::learn(): Out of memory\n"); exit (EXIT_FAILURE); return 0; } }
RobotNodePtr RobotNode::clone( RobotPtr newRobot, bool cloneChildren, RobotNodePtr initializeWithParent, CollisionCheckerPtr colChecker, float scaling ) { ReadLockPtr lock = getRobot()->getReadLock(); if (!newRobot) { VR_ERROR << "Attempting to clone RobotNode for invalid robot"; return RobotNodePtr(); } std::vector< std::string > clonedChildrenNames; VisualizationNodePtr clonedVisualizationNode; if (visualizationModel) clonedVisualizationNode = visualizationModel->clone(true,scaling); CollisionModelPtr clonedCollisionModel; if (collisionModel) clonedCollisionModel = collisionModel->clone(colChecker,scaling); RobotNodePtr result = _clone(newRobot, clonedVisualizationNode, clonedCollisionModel, colChecker, scaling); if (!result) { VR_ERROR << "Cloning failed.." << endl; return result; } if (cloneChildren) { std::vector< SceneObjectPtr > children = this->getChildren(); for (size_t i=0;i<children.size();i++) { RobotNodePtr n = dynamic_pointer_cast<RobotNode>(children[i]); if (n) { RobotNodePtr c = n->clone(newRobot,true,RobotNodePtr(),colChecker,scaling); if (c) result->attachChild(c); } else { SensorPtr s = dynamic_pointer_cast<Sensor>(children[i]); if (s) { // performs registering and initialization SensorPtr c = s->clone(result,scaling); } else { SceneObjectPtr so = children[i]->clone(children[i]->getName(),colChecker,scaling); if (so) result->attachChild(so); } } } } result->setMaxVelocity(maxVelocity); result->setMaxAcceleration(maxAcceleration); result->setMaxTorque(maxTorque); std::map< std::string, float>::iterator it = propagatedJointValues.begin(); while (it != propagatedJointValues.end()) { result->propagateJointValue(it->first,it->second); it++; } newRobot->registerRobotNode(result); if (initializeWithParent) result->initialize(initializeWithParent); return result; }
inline virtual CBaseType* clone(void) const { return _clone(); }