示例#1
0
文件: MTnode.cpp 项目: jsc0218/MxTree
void
MTnode::InvalidateEntry (BOOL bNew)
{
	GiSTpath path = Path ();
	if (path.Level() > 1) {  // len>=3
		MTnode *parentNode = ((MT *)Tree())->ParentNode((MTnode *)this);
		for (int i=0; i<parentNode->NumEntries(); i++) {  // search the entry in the parent's node
			MTentry *entry = (MTentry *) (*parentNode)[i].Ptr();
			if (entry->Ptr() == path.Page()) {
				if (bNew) {
					entry->Key()->distance = -MaxDist();
				}
				entry->Key()->splitted = TRUE;
				break;
			}
		}
		path.MakeParent ();
		MTnode *grandNode = ((MT *)Tree())->ParentNode(parentNode);
		for (int i=0; i<grandNode->NumEntries(); i++) {  // search the entry in the grandparent's node
			MTentry *entry = (MTentry *) (*grandNode)[i].Ptr();
			if (entry->Ptr() == path.Page()) {
				entry->SetMaxRadius(-1);
				break;
			}
		}
		((MT *)Tree())->WriteNode(parentNode);  // write parent node (in inconsistent state)
		((MT *)Tree())->WriteNode(grandNode);  // write grandparent node (to invalidate the parent's entry)
		delete parentNode;
		delete grandNode;
	}
}
示例#2
0
 void Tree::SplitHelper(int local_dim, int global_dim, double split_value) {
     
     assert(local_dim >= 0);
     assert(global_dim >= 0);
     
     auto upper_min_corner = std::make_shared<std::vector<double>>(min_corner_->begin(),
                                                                   min_corner_->end());
     (*upper_min_corner)[local_dim] = split_value;
     
     auto lower_max_corner = std::make_shared<std::vector<double>>(max_corner_->begin(),
                                                                   max_corner_->end());
     (*lower_max_corner)[local_dim] = split_value;
     
     assert(children_.size() == 0);
     children_.reserve(2); // single-dim, single-value splits always produce 2 children
     
     // upper tree (child 0)
     children_.push_back(Tree(target_features_,
                              upper_min_corner,
                              max_corner_));
     
     // lower tree (child 1)
     children_.push_back(Tree(target_features_,
                              min_corner_,
                              lower_max_corner));
     
     // copy to member variables for future use
     split_dim_ = local_dim;
     split_val_ = split_value;
 }
示例#3
0
Tree Object::toTree() const
{
	if(isTree())
		return Tree(*this);
	else
		return Tree();
}
示例#4
0
    explicit StaticKDTree(std::vector<InputPoint> *points)
    {
        BOOST_ASSERT(k > 0);
        BOOST_ASSERT(points->size() > 0);
        size = points->size();
        kdtree = new InputPoint[size];
        for (Iterator i = 0; i != size; ++i)
        {
            kdtree[i] = points->at(i);
            for (unsigned dim = 0; dim < k; ++dim)
            {
                if (kdtree[i].coordinates[dim] < boundingBox.min[dim])
                    boundingBox.min[dim] = kdtree[i].coordinates[dim];
                if (kdtree[i].coordinates[dim] > boundingBox.max[dim])
                    boundingBox.max[dim] = kdtree[i].coordinates[dim];
            }
        }
        std::stack<Tree> s;
        s.push(Tree(0, size, 0));
        while (!s.empty())
        {
            Tree tree = s.top();
            s.pop();

            if (tree.right - tree.left < KDTREE_BASESIZE)
                continue;

            Iterator middle = tree.left + (tree.right - tree.left) / 2;
            std::nth_element(
                kdtree + tree.left, kdtree + middle, kdtree + tree.right, Less(tree.dimension));
            s.push(Tree(tree.left, middle, (tree.dimension + 1) % k));
            s.push(Tree(middle + 1, tree.right, (tree.dimension + 1) % k));
        }
    }
示例#5
0
void
MTnode::InvalidateEntry(BOOL isNew)
{
	GiSTpath path=Path();
	if(path.Level()>1) {
		MTnode *parent=((MT *)Tree())->ParentNode((MTnode *)this), *gparent=((MT *)Tree())->ParentNode(parent);
		int i;

		for(i=0; i<parent->NumEntries(); i++) {	// search the entry between the parent's children
			MTentry *e=(MTentry *)((*parent)[i].Ptr());

			if(e->Ptr()==path.Page()) {
				if(isNew) e->Key()->distance=-maxDist();
//				else e->Key()->distance=-e->Key()->distance;
				e->Key()->splitted=TRUE;
				break;
			}
		}
		path.MakeParent();
		for(i=0; i<gparent->NumEntries(); i++) {	// search the parent entry between the grandparent's children
			MTentry *e=(MTentry *)((*gparent)[i].Ptr());

			if(e->Ptr()==path.Page()) {
				e->setmaxradius(-1);
				break;
			}
		}
		((MT *)Tree())->WriteNode(parent);	// write parent node (in inconsistent state)
		((MT *)Tree())->WriteNode(gparent);	// write gparent node (to invalidate the parent's entry)
		delete parent;
		delete gparent;
	}
}
T_tree insert(string key, T_tree t) {
  if (t==NULL) {
    return Tree(NULL, key, NULL);
  } else if (strcmp(key, t->key) < 0) {
    return Tree(insert(key, t->left), t->key, t->right);
  } else if (strcmp(key, t->key) > 0) {
    return Tree(t->left, t->key, insert(key, t->right));
  } else {
    return Tree(t->left, key, t->right);
  }
}
示例#7
0
TEST(TreeTests, TestCanJoinTwoTreesAtRoot) {
    std::unique_ptr<std::vector<std::array<int, 2>>> branches1 = std::make_unique<std::vector<std::array<int, 2>>>();
    branches1->push_back(std::array<int, 2>{1,2});
    branches1->push_back(std::array<int, 2>{1,3});
    Tree tree1 = Tree(branches1, 1);
    std::unique_ptr<std::vector<std::array<int, 2>>> branches2 = std::make_unique<std::vector<std::array<int, 2>>>();
    branches2->push_back(std::array<int, 2>{4,5});
    branches2->push_back(std::array<int, 2>{4,6});
    Tree tree2 = Tree(branches2, 4);
    Tree combined_tree = Tree(tree1, tree2, 1, 7);
    EXPECT_TRUE(combined_tree.checkValid());
    EXPECT_EQ(combined_tree.getNBranches(), 6);
    EXPECT_EQ(combined_tree.getNTips(), 4);
    EXPECT_EQ(combined_tree.getNNodes(), 7);
}
示例#8
0
TEST(TreeTests, CreateEmptyTree) {
    Tree testTree = Tree();
    EXPECT_EQ(testTree.getNTips(), 0);
    EXPECT_EQ(testTree.getNBranches(), 0);
    EXPECT_EQ(testTree.getNNodes(), 0);
    EXPECT_EQ(testTree.getRootID(), 0);
}
示例#9
0
void FileExplorerTab::ClearSelections()
{
    if(GetSelectionCount()) {
        // multiple selections
        Tree()->GetTreeCtrl()->UnselectAll();
    }
}
示例#10
0
int main()
{
  part_type& PartManager(part_type::instance());
  io_type& IOManager(io_type::instance());

  sleep(1);
  treeType& Tree(treeType::instance());
  sleep(1);

  IOManager.loadDump("test.h5part");

  dumpType dumper(&Tree);
  dumper.dotDump("test.dot");

  inserterType inserter(&Tree);
  
  gravworkerType worker(&Tree);
#pragma omp parallel for firstprivate(worker)
  for (int i = 0; i < 8; i++)
  {
    //const size_t tid = omp_get_thread_num();
    //std::cout << tid << ":" << i << ":" << &worker << "\n";
  }
  sleep(1);
  return 0;
}
示例#11
0
文件: ptree.hpp 项目: go4and/lib
inline Tree & checked_get(Tree & inp, const typename Tree::path_type & path)
{
    boost::optional<Tree &> child = inp.get_child_optional(path);
    if(child)
        return child.get();
    return inp.put_child(path, Tree());
}
示例#12
0
int main(int argc, char** argv) {
	char Data[MAX*MAX];
	char buf[MAX];
	int count = 0;
	int index = 0;
	int a = 0;
	while (scanf("%s",buf) && buf[0] != '#')
	{
		index = 0;
		while ( buf[0] != '*')
		{
			memcpy(Data+index,buf,strlen(buf)+1);
			index+=strlen(buf)+1;
			scanf("%s",buf);
		}
		count++;
		
		printf("DATA SET %d:\nROOT\n",count);
		
		a = 0;
		Tree(Data,a,0,index);
		printf("\n");
		
	}
	return 0;
}
示例#13
0
	// *******************************************************	
	// display(): called once per frame, whenever OpenGL decides it's time to redraw.
	virtual void display( float animation_delta_time, Vector2d &window_steering )
	{		
		if( animate ) animation_time += animation_delta_time;

		update_camera( animation_delta_time , window_steering );

		int basis_id = 0;

		float atime = animation_time * 10;
		Matrix4d model_transform = Matrix4d::Identity();
		Matrix4d std_model = model_transform;

		*m_tree = Tree(Matrix4d::Identity(), atime);
		// Start coding here!!!! 
		m_bee->timepassby(atime);

		// Plane
		model_transform = std_model * Affine3d(Translation3d(5, -5, -60)).matrix();				// Position
		glUniform4fv(g_addrs->color_loc, 1, Vector4f(.0f, .7f, .9f, 1).data());			// Color
		m_plane->draw ( projection_transform, camera_transform, model_transform, "" );

		// Tree
		model_transform = std_model * Affine3d(Translation3d(4, -5, -40)).matrix();				// Position
		glUniform4fv( g_addrs->color_loc, 1, Vector4f( .0f, .6f ,.2f ,1 ).data());			// Color
		m_tree->draw( basis_id++, projection_transform, camera_transform, model_transform, "");

		// Leg
		model_transform = std_model * Affine3d(Translation3d(4, 1+2*(abs(20.0 - ((int)atime % 41)))/10, -40)).matrix();				// Position
		model_transform *= Affine3d(AngleAxisd((-PI / 60 * atime), Vector3d(0, 1, 0))).matrix();
		model_transform *= Affine3d(Translation3d(20, 0, 0)).matrix();
		m_bee->draw(basis_id++, projection_transform, camera_transform, model_transform, "");
	}
示例#14
0
 bool TreeInertialParameters::changeInertialParameters(const Eigen::VectorXd & new_chain_param,  Tree& new_tree)
 {
     SegmentMap::const_iterator root;
     ref_tree.getRootSegment(root);
     new_tree = Tree(root->first);
     return changeInertialParametersRecursive(new_chain_param,new_tree,root,root->first);
 }
示例#15
0
TEST(TreeTests, CreateTwoTipTreeFromTwoBranchList){
    std::unique_ptr<std::vector<std::array<int, 2>>> branches = std::make_unique<std::vector<std::array<int, 2>>>();
    branches->push_back(std::array<int, 2>{1,2});
    branches->push_back(std::array<int, 2>{1,3});
    Tree tree = Tree(branches, 1);
    EXPECT_EQ(tree.getNTips(), 2);
    EXPECT_EQ(tree.checkValid(), true);
}
示例#16
0
Wt::WWidget *TreesTables::trees()
{
  Wt::WTemplate *result = new TopicTemplate("treestables-Trees");

  result->bindWidget("Tree", Tree());

  return result;
}
示例#17
0
void createTrees () {
	for (int i = 0; i < treeCount; i++) {
		int angle = randBetween(0, 359);
		int offset = randBetween(500, 2500);
		int x = std::cos(angle * (M_PI / 180)) * offset;
		int z = std::sin(angle * (M_PI / 180)) * offset;
		trees.push_back(Tree(Vector3(x, 0, z)));
	}
}
T_tree insert(string key, void *value, T_tree t) {
  if (t==NULL) {

    return Tree(NULL, Binding(key, value), NULL);

  } else if (strcmp(key, t->binding->key) < 0) {

    return Tree(insert(key, value, t->left), t->binding, t->right);

  } else if (strcmp(key, t->binding->key) > 0) {

    return Tree(t->left, t->binding, insert(key, value, t->right));

  } else {

    return Tree(t->left, Binding(key, value), t->right);
  }
}
示例#19
0
TEST(TreeTests, AddRootToEmptyTree) {
    Tree testTree = Tree();
    int tip_id = testTree.addTipRandomly();
    EXPECT_EQ(testTree.getNTips(), 1);
    EXPECT_EQ(testTree.getNBranches(), 0);
    EXPECT_EQ(testTree.getNNodes(), 1);
    EXPECT_EQ(tip_id, 1);
    EXPECT_EQ(testTree.getRootID(), 1);
}
示例#20
0
TEST(TreeTests, CreateTwoTipTree) {
    Tree testTree = Tree();
    testTree.addTipRandomly();
    int tip_id = testTree.addTipRandomly();
    EXPECT_EQ(tip_id, 3);
    EXPECT_EQ(testTree.getNTips(), 2);
    EXPECT_EQ(testTree.getNBranches(), 2);
    EXPECT_EQ(testTree.getNNodes(), 3);
    EXPECT_EQ(testTree.getRootID(), 2);
}
示例#21
0
bool treeFromUrdfModel(const urdf::ModelInterface& robot_model, Tree& tree, const bool consider_root_link_inertia)
{
  if (consider_root_link_inertia) {
    //For giving a name to the root of KDL using the robot name,
    //as it is not used elsewhere in the KDL tree
    std::string fake_root_name = "__kdl_import__" + robot_model.getName()+"__fake_root__";
    std::string fake_root_fixed_joint_name = "__kdl_import__" + robot_model.getName()+"__fake_root_fixed_joint__";

    tree = Tree(fake_root_name);

   const urdf::ConstLinkPtr root = robot_model.getRoot();

    // constructs the optional inertia
    RigidBodyInertia inert(0);
    if (root->inertial)
      inert = toKdl(root->inertial);

    // constructs the kdl joint
    Joint jnt = Joint(fake_root_fixed_joint_name, Joint::None);

    // construct the kdl segment
    Segment sgm(root->name, jnt, Frame::Identity(), inert);

    // add segment to tree
    tree.addSegment(sgm, fake_root_name);

  } else {
    tree = Tree(robot_model.getRoot()->name);

    // warn if root link has inertia. KDL does not support this
    if (robot_model.getRoot()->inertial)
      std::cerr << "The root link " << robot_model.getRoot()->name <<
                   " has an inertia specified in the URDF, but KDL does not support a root link with an inertia.  As a workaround, you can add an extra dummy link to your URDF." << std::endl;
  }

  //  add all children
  for (size_t i=0; i<robot_model.getRoot()->child_links.size(); i++)
    if (!addChildrenToTree(robot_model.getRoot()->child_links[i], tree))
      return false;

  return true;
}
示例#22
0
void
MTnode::Print(ostream& os) const
{
	if(obj!=NULL) os << *obj << " ";
//	else cout << "obj NULL...\n";
	os << ((MTnode *)this)->Path() << " #Entries: " << NumEntries() << ", Level " << Level();
	if(IsLeaf()) os << "(Leaf)";
	else os << "(Internal)";
	os << ", Sibling: " << Sibling() << ", Size: " << Size() << "/" << Tree()->Store()->PageSize() << endl;
	for(int i=0; i<NumEntries(); i++) (*this)[i]->Print(os);
}
示例#23
0
MTentry *
MTnode::Entry() const
{
	GiSTpath path=((MTnode *)this)->Path();
	MTnode *parent=((MT *)Tree())->ParentNode((MTnode *)this);
	MTentry *returnEntry=NULL;

	for(int i=0; (i<parent->NumEntries())&&(returnEntry==NULL); i++)
		if((*parent)[i].Ptr()->Ptr()==path.Page()) returnEntry=(MTentry *)(*parent)[i].Ptr()->Copy();
	delete parent;
	return returnEntry;
}
示例#24
0
int main(){
	 int arr[]={25,20,6,10,21,8,1,30,1,2,3,4,5,6,7,8,9};
         std::vector<int> val(arr,arr+16);
	tree Tree(val);// Create from vector
//	Tree.delete_elem(3);//delete element 3
//	Tree.delete_node(Tree.find(25));//delete subtree with root=25
//	Tree.replace(Tree.find(3),Tree.find(25));//Replace elements with children
	Tree.Print();// make full tree
//	Tree.Print(Tree.find(20));//make subtree with root=20
//	std::cout<<Tree.find(5)->parrent->key;//Parrent 5 
	return 0;
}
示例#25
0
文件: MTnode.cpp 项目: jsc0218/MxTree
void
MTnode::Print (ostream& os) const
{
	if (obj) {
		os << *obj << " ";
	}
	os << ((MTnode *)this)->Path() << " #Entries: " << NumEntries() << ", Level " << Level();
	IsLeaf () ? os << "(Leaf)" : os << "(Internal)";
	os << ", Sibling: " << Sibling() << ", Size: " << Size() << "/" << Tree()->Store()->PageSize() << endl;
	for (int i=0; i<NumEntries(); i++) {
		(*this)[i]->Print(os);
	}
}
示例#26
0
TEST(TreeTests, TwoBranchListFromTree){
    Tree testTree = Tree();
    testTree.addTipRandomly();
    testTree.addTipRandomly();
    std::unique_ptr<std::vector<std::array<int, 2>>> branchList = testTree.getBranchList();
    EXPECT_EQ(branchList->size(), 2);
    // Check that branches are correct:
    std::array<int, 2> branch1 = (*branchList)[0];
    EXPECT_EQ(branch1[0], 2);
    EXPECT_EQ(branch1[1], 1);
    std::array<int, 2> branch2 = (*branchList)[1];
    EXPECT_EQ(branch2[0], 2);
    EXPECT_EQ(branch2[1], 3);
}
示例#27
0
文件: MTnode.cpp 项目: jsc0218/MxTree
MTentry *
MTnode::ParentEntry () const
{
	MTnode *parentNode = ((MT *)Tree())->ParentNode((MTnode *)this);
	MTentry *parentEntry = NULL;

	for (int i=0; i < parentNode->NumEntries() && !parentEntry; i++) {
		if ((*parentNode)[i].Ptr()->Ptr() == ((MTnode *)this)->Path().Page()) {
			parentEntry = (MTentry *) (*parentNode)[i].Ptr()->Copy();
		}
	}
	delete parentNode;
	return parentEntry;
}
示例#28
0
    void loadRevision(const std::string& revName) {
	Git::ObjectId treeRoot = git_.getCommitTree(revName);

	layoutAboutToBeChanged().emit(); // Invalidates model indexes

	treeData_.clear();
	childPointer_.clear();

	/*
	 * This stores the tree root as treeData_[0]
	 */
	treeData_.push_back(Tree(-1, -1, treeRoot, git_.treeSize(treeRoot)));

	layoutChanged().emit();
    }
示例#29
0
TEST(TreeTests, TestCanSplitAlongTipBranch){
    std::unique_ptr<std::vector<std::array<int, 2>>> branches = std::make_unique<std::vector<std::array<int, 2>>>();
    branches->push_back(std::array<int, 2>{1,2});
    branches->push_back(std::array<int, 2>{1,3});
    branches->push_back(std::array<int, 2>{3,4});
    branches->push_back(std::array<int, 2>{3,5});
    Tree tree = Tree(branches, 1);
    auto subtrees = std::array<std::unique_ptr<Tree>, 2>();
    tree.splitTree(3, 4, subtrees);
    std::cout << "Checking tree 1, with " << subtrees[0]->getNTips() << " tips\n";
    EXPECT_TRUE(subtrees[0]->checkValid());
    std::cout << "Checking tree 2, with " << subtrees[1]->getNTips() << " tips\n";
    EXPECT_TRUE(subtrees[1]->checkValid());
    EXPECT_EQ(subtrees[0]->getNTips() + subtrees[1]->getNTips(), tree.getNTips());
}
示例#30
0
TEST(TreeTests, FailTreeCreationFromWrongRootNode){
    std::unique_ptr<std::vector<std::array<int, 2>>> branches = std::make_unique<std::vector<std::array<int, 2>>>();
    branches->push_back(std::array<int, 2>{1,2});
    branches->push_back(std::array<int, 2>{1,3});
    branches->push_back(std::array<int, 2>{3,4});
    branches->push_back(std::array<int, 2>{3,5});
    bool exceptionRaised = false;
    try {
        Tree tree = Tree(branches, 2);
    }
    catch (std::logic_error) {
        exceptionRaised = true;
    }
    EXPECT_TRUE(exceptionRaised);
}