当前位置: 首页>>代码示例>>C++>>正文


C++ Tree类代码示例

本文整理汇总了C++中Tree的典型用法代码示例。如果您正苦于以下问题:C++ Tree类的具体用法?C++ Tree怎么用?C++ Tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setProperty

void setProperty (Tree t, Tree key, Tree val)
{
	CTree* pl = t->attribut();
	if (pl) t->attribut(updateKey(pl, key, val)); 
	else 	t->attribut(updateKey(nil, key, val));
}
开发者ID:gauravchawla03,项目名称:Stanford,代码行数:6,代码来源:list.cpp

示例2: calc_node_statistics_tree

node_statistics calc_node_statistics_tree( Tree const& tree )
{
    node_statistics stat;
    detail::update_statistics( tree.root() , stat );
    return stat;
}
开发者ID:Ambrosys,项目名称:gpcxx,代码行数:6,代码来源:node_statistics.hpp

示例3: vector

	bool TestBTree::testErase()
	{
		status << "Running Test Insert\n";

		Map map;
		Tree tree;
		Vector vector( elements );
		_init( vector );
		
		for( unsigned int i = 0; i < iterations; ++i )
		{
			switch( random() % 2 )
			{
				case 0:
				{
					size_t index = random() % vector.size();
					map.insert( std::make_pair( vector[ index ], i ) );
					Tree::iterator fi = 
						tree.lower_bound( vector[ index ] );
					fi = tree.insert( fi, 
						std::make_pair( vector[ index ], i ) );
					if( fi->first != vector[ index ] )
					{
						status << "Insert failed, returned iterator with key " 
						<< fi->first << " does not match inserted value " 
						<< vector[ index ] << "\n";
						dumpTree( tree, path );
						return false;
					}		
					break;
				}
								
				case 1:
				{
					size_t index = random() % vector.size();
					size_t index1 = random() % vector.size();
					Map::iterator mi = map.find( vector[ index ] );
					Map::iterator mi1 = map.find( vector[ index1 ] );
					Tree::iterator ti = tree.find( vector[ index ] );
					Tree::iterator ti1 = tree.find( vector[ index1 ] );
					
					if( mi == map.end() && mi1 == map.end() )
					{
						break;
					}
					
					if( mi == map.end() && mi1 != map.end() )
					{
						std::swap( mi, mi1 );
						std::swap( ti, ti1 );
					}
					else if( mi != map.end() && mi1 != map.end() )
					{
						if( mi1->first < mi->first )
						{
							std::swap( mi, mi1 );
							std::swap( ti, ti1 );
						}
					}
					
					map.erase( mi, mi1 );
					tree.erase( ti, ti1 );
					break;
				}
			}
		}
			
		{
			Map::iterator mi = map.begin();
			Tree::iterator ti = tree.begin();

			for( ; mi != map.end() && ti != tree.end(); ++mi, ++ti )
			{
				if( mi->first != ti->first )
				{
					status << "Erase failed, map key " << mi->first
						<< " does not match tree key " << ti->first 
						<< "\n";
					dumpTree( tree, path );
					return false;
				}
				if( mi->second != ti->second )
				{
					status << "Erase failed, map value " 
						<< mi->second
						<< " does not match tree value " << ti->second 
						<< "\n";
					dumpTree( tree, path );
					return false;
				}
			}
		}
		
		status << "  Test Erase Passed.\n";
		return true;
	}
开发者ID:3upperm2n,项目名称:hydrazine,代码行数:96,代码来源:TestBTree.cpp

示例4: main

// Begin the main program.
int main (int argc, char** argv)
{

LibMeshInit init (argc, argv);
Mesh mesh(3);
EquationSystems equation_systems (mesh);
read_parameters(equation_systems,argc,argv);
std::string result_file_name (equation_systems.parameters.get<std::string>("result_file_name"));

unsigned int n_timesteps = equation_systems.parameters.get<Real>("n_timesteps");
unsigned int N_eles=equation_systems.parameters.get<Real>("N_eles");
 
Real time = 0;
Real end_time = equation_systems.parameters.get<Real>("end_time");
const unsigned int n_nonlinear_steps = 6;
const Real nonlinear_tolerance = 1.e-3;
const Real initial_linear_solver_tol = 1.e-18;

if(!equation_systems.parameters.get<std::string>("problem").compare("cube")){

MeshTools::Generation::build_cube (
mesh,
                                       1,1,2,
                                       0.0, 1.0,
                                       0.0, 1.0,
																			 0.0, 1.0,
                                       HEX8);
                                      

}	


if((!equation_systems.parameters.get<std::string>("problem").compare("lung")) || (!equation_systems.parameters.get<std::string>("problem").compare("cylinder"))){
  
std::string mesh_file_name (equation_systems.parameters.get<std::string>("mesh_input"));
GmshIO(mesh).read(mesh_file_name);

}
 
//Create tree
Tree tree;
tree.read_tree(equation_systems);

mesh.prepare_for_use();

setup_equationsystem(equation_systems);
TransientLinearImplicitSystem& newton_update = equation_systems.get_system<TransientLinearImplicitSystem>("Newton-update");
TransientLinearImplicitSystem& reference = equation_systems.get_system<TransientLinearImplicitSystem>("Reference-Configuration");
TransientLinearImplicitSystem& last_non_linear_soln = equation_systems.get_system<TransientLinearImplicitSystem>("Last-non-linear-soln");
TransientLinearImplicitSystem& postvars = equation_systems.get_system<TransientLinearImplicitSystem>("postvars");




equation_systems.init ();
equation_systems.print_info();
 
/*
const MeshBase::const_node_iterator nd_end_tlc =
      equation_systems.get_mesh().local_nodes_end();
for (MeshBase::const_node_iterator nd = equation_systems.get_mesh().local_nodes_begin();
      nd != nd_end_tlc; ++nd) {
  const Node *node = *nd;

//Copy initial mesh into reference.solution
  for (unsigned int d = 0; d < 3; ++d) {
		//Save the TLC reference
    unsigned int dest_dof = node->dof_number(reference.number(), d+4, 0);
    Real value = (*node)(d);
    reference.current_local_solution->set(dest_dof, value);
    reference.solution->set(dest_dof, value);

	}
}
 */

//Move mesh and tree from inspiration to registered expiration
  
 const Point Aexp = equation_systems.parameters.get<Point>("A");
const Point bexp = equation_systems.parameters.get<Point>("b");

Real facexp=1.4;
//Update the position of the airway tree
std::cout<<"Moving tree to expiratory FRC " <<std::endl;
    for (double j=0; j <tree.number_nodes ; j++) {
			for (unsigned int d = 0; d < 3; ++d) {
				tree.nodes(j)(d)=tree.nodes(j)(d)-facexp*( tree.nodes(j)(d)*Aexp(d)+bexp(d) );
			}
				
				
				//Move mesh a bit more to ecncompass tree on;y do this for N48
				//	if((!equation_systems.parameters.get<std::string>("mesh_input").compare("meshes/lung/N048r_fine2881.msh")) || (!equation_systems.parameters.get<std::string>("mesh_input").compare("meshes/lung/N048_node5036.msh"))){
					  	if( (!equation_systems.parameters.get<std::string>("mesh_input").compare("meshes/lung/N048_node5036.msh"))){
						
						//tree.nodes(j)(0)= tree.nodes(j)(0)*0.98+2; //-paper don't know why ??
						//tree.nodes(j)(1)= tree.nodes(j)(1)*0.98+4; //-paper don't know why ??
						//tree.nodes(j)(2)= tree.nodes(j)(2)*0.98+2; //-paper don't know why ??
											
						tree.nodes_deformed(j)(0)=tree.nodes(j)(0);
//.........这里部分代码省略.........
开发者ID:loztop,项目名称:large_deformation_lung,代码行数:101,代码来源:poro_main.C

示例5: switch

void World::touchMove(int id, int x, int y) {
	if(id>1)
		return;

 	touchCurrentX[id] = x;
	touchCurrentY[id] = y;

#if !USE_MOUSE
	if(id == 1) {
		touched[1] = true;
		touchStartX[1] = touchCurrentX[1];
		touchStartY[1] = touchCurrentY[1];

		touchEvent = TE_ZOOM;
		touchStartX[0] = touchCurrentX[0];
		touchStartY[0] = touchCurrentY[0];
		panStart = pos;
		scaleStart = scale;
		return;
	}
#endif

	switch(touchEvent) {
		case TE_ZOOM: 
			setScale(scaleStart * (vec2((float)touchCurrentX[0] - touchCurrentX[1], (float)touchCurrentY[0] - touchCurrentY[1]).length() /
				vec2((float)touchStartX[0] - touchStartX[1], (float)touchStartY[0] - touchStartY[1]).length() ) );
			move(panStart + pointToPos((touchStartX[0] + touchStartX[1]) / 2, (touchStartY[0] + touchStartY[1]) / 2)
				-	pointToPos((touchCurrentX[0] + touchCurrentX[1]) / 2, (touchCurrentY[0] + touchCurrentY[1]) / 2) );
			break;
		case TE_PAN:
			move(panStart + pointToPos(touchStartX[id], touchStartY[id]) - pointToPos(touchCurrentX[id], touchCurrentY[id]));
			break;
		case TE_TRY:
		case TE_CAN_LINK:
		case TE_CAN_UNLINK:
			if(id>0)
				break;
			{
			Planet* targetPlanet = getPlanet( pointToPos(x, y) );
			if(!targetPlanet || targetPlanet == sourcePlanet) {
				touchEvent = TE_TRY;
				break;
			}
			Tree *targetTree = targetPlanet->getTree(currentRace);
			if(targetTree) {
				if(targetTree->isLinked(sourcePlanet)) {
					touchEvent = TE_CAN_UNLINK;
					break;
				}
			}
			Tree *sourceTree = sourcePlanet->getTree(currentRace);
			if(sourceTree) {
				if(sourceTree->isLinked(targetPlanet)) {
					touchEvent = TE_TRY;
					break;
				}
				touchEvent = TE_CAN_LINK;
			}
			}
			break;
	}

}
开发者ID:alexsaen,项目名称:Roots,代码行数:63,代码来源:World.cpp

示例6: defined

EstOutput Parsimony::createProcesses(Tree* t, vector< vector<string> > namesOfGroupCombos, CountTable* ct) {
	try {
        int process = 1;
		vector<int> processIDS;
		
		EstOutput results;

#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
				
		//loop through and create all the processes you want
		while (process != processors) {
			int pid = fork();
			
			if (pid > 0) {
				processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
				process++;
			}else if (pid == 0){
				EstOutput myresults;
				myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct);
				
				if (m->control_pressed) { exit(0); }
				
				//pass numSeqs to parent
				ofstream out;
				string tempFile = outputDir + toString(getpid()) + ".pars.results.temp";
				m->openOutputFile(tempFile, out);
				out << myresults.size() << endl;
				for (int i = 0; i < myresults.size(); i++) {  out << myresults[i] << '\t';  } out << endl;
				out.close();
				
				exit(0);
			}else { 
				m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
				for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
				exit(0); 
			}
		}
		
		results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, ct);
		
		//force parent to wait until all the processes are done
		for (int i=0;i<processIDS.size();i++) { 
			int temp = processIDS[i];
			wait(&temp);
		}
		
		if (m->control_pressed) { return results; }
			
		//get data created by processes
		for (int i=0;i<processIDS.size();i++) { 
			ifstream in;
			string s = outputDir + toString(processIDS[i]) + ".pars.results.temp";
			m->openInputFile(s, in);
			
			//get scores
			if (!in.eof()) {
				int num;
				in >> num; m->gobble(in);
				
				if (m->control_pressed) { break; }
				
				double w; 
				for (int j = 0; j < num; j++) {
					in >> w;
					results.push_back(w);
				}
				m->gobble(in);
			}
			in.close();
			m->mothurRemove(s);
		}
#else
        //fill in functions
        vector<parsData*> pDataArray;
		DWORD   dwThreadIdArray[processors-1];
		HANDLE  hThreadArray[processors-1];
        vector<CountTable*> cts;
        vector<Tree*> trees;
		
		//Create processor worker threads.
		for( int i=1; i<processors; i++ ){
            CountTable* copyCount = new CountTable();
            copyCount->copy(ct);
            Tree* copyTree = new Tree(copyCount);
            copyTree->getCopy(t);
            
            cts.push_back(copyCount);
            trees.push_back(copyTree);
            
            parsData* temppars = new parsData(m, lines[i].start, lines[i].num, namesOfGroupCombos, copyTree, copyCount);
			pDataArray.push_back(temppars);
			processIDS.push_back(i);
            
			hThreadArray[i-1] = CreateThread(NULL, 0, MyParsimonyThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]);
		}
		
		results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, ct);
		
		//Wait until all threads have terminated.
		WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
//.........这里部分代码省略.........
开发者ID:jonls,项目名称:mothur,代码行数:101,代码来源:parsimony.cpp

示例7: addTree

bool Tree::addTree(const Tree& tree, const std::string& tree_name,
        const std::string& hook_name) {
    return this->addTreeRecursive(tree.getSegment("root"), tree_name, hook_name);
}
开发者ID:Eibriel,项目名称:blender-dfelinto,代码行数:4,代码来源:tree.cpp

示例8: getLnTreeProb

double Treescale::updateTreeScale(double &oldLnL) {
	
	Tree *t = modelPtr->getActiveTree();
	Node *rt = t->getRoot();

	double oldtreeprob = getLnTreeProb(t);
	
	if(retune && tuning > scaleVal)
		tuning = scaleVal * 0.5;
		
	double limO = scaleVal + tuning;
	double limY = scaleVal - tuning;
	double rtLB = t->getNodeLowerBoundTime(rt) * scaleVal;
	double lowBound = rtLB;
	
	double hiBound = limO;
	if(treeTimePrior == 4){
		if(hiBound > treeOriginTime)
			hiBound = treeOriginTime;
	}
	
	if(isBounded){
		if(lowBound < yngBound)
			lowBound = yngBound;
		if(hiBound > oldBound)
			hiBound = oldBound;
	}
	
	double oldRH, newRH;
	oldRH = scaleVal;
		
	double u = ranPtr->uniformRv(-0.5,0.5) * (limO - limY);
	newRH = oldRH + u;
	while(newRH < lowBound || newRH > hiBound){
		if(newRH < lowBound)
			newRH = (2 * lowBound) - newRH;
		if(newRH > hiBound)
			newRH = (2 * hiBound) - newRH;
	}
		
	double scaleRatio = oldRH / newRH;
	int numNodes = t->getNumNodes();
	for(int i=0; i<numNodes; i++){
		Node *p = t->getNodeByIndex(i);
		if(p != rt){
			if(p->getIsLeaf() && p->getIsCalibratedDepth() == false){
				p->setNodeDepth(0.0);
			}
			else{
				double oldP = p->getNodeDepth();
				double newP = oldP * scaleRatio;
				p->setNodeDepth(newP);
				p->setFossAttchTime(0.0);
				if(false){
					double oldPhi = p->getFossAttchTime();
					double fA = p->getNodeYngTime();
					double newPhi = oldPhi * scaleRatio;
					if(newPhi*newRH < fA){
						cout << i << " op = " << oldPhi*oldRH << "  np = " << newPhi*newRH << " oRH = " << oldRH << "  nRH = " 
							<< newRH << "  fA = " << fA << endl;
					}
					int x = t->countDecLinsTimeIntersect(p, newPhi, newP);
					p->setFossAttchTime(newPhi);
					p->setNumFossAttchLins(x); 
				}
			}
		}
	}
	scaleVal = newRH;
	t->setTreeScale(scaleVal);
	t->treeScaleUpdateFossilAttchTimes(scaleRatio, oldRH, newRH);
	t->treeUpdateNodeOldestBoundsAttchTimes();
	t->setAllNodeBranchTimes();
		
	double lnPriorRatio = 0.0; 
	double newtreeprob = getLnTreeProb(t);
	lnPriorRatio += (newtreeprob - oldtreeprob);
	if(tsPriorD == 2){
		if(exponHPCalib)
			expoRate = t->getRootCalibExpRate();
		lnPriorRatio += lnExponentialTSPriorRatio(newRH, oldRH);
	}
	double lnProposalRatio = 0.0;
	
	double jacobian = 0.0;
	if(treeTimePrior < 2)
		jacobian = (log(oldRH) - log(newRH)) * (t->getNumTaxa() - 2);


	t->flipAllCls();
	t->flipAllTis();
	t->upDateAllCls();
	t->upDateAllTis();
	modelPtr->setTiProb();
	
	
	return lnPriorRatio + lnProposalRatio + jacobian;
}
开发者ID:lheins,项目名称:FDPPDIV,代码行数:98,代码来源:Parameter_treescale.cpp

示例9: tmap

Tree tmap (Tree key, tfun f, Tree t)
{	
	//printf("start tmap\n");
	Tree p; 
	
	if (getProperty(t, key, p)) {
		
		return (isNil(p)) ? t : p;	// truc pour eviter les boucles
		
	} else {
		
		Tree r1=nil;
		switch (t->arity()) {
			
			case 0 : 
				r1 = t; 
				break;
			case 1 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0))); 
				break;
			case 2 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1))); 
				break;
			case 3 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1)),
										   tmap(key,f,t->branch(2))); 
				break;
			case 4 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1)),
										   tmap(key,f,t->branch(2)), tmap(key,f,t->branch(3))); 
				break;
		}
		Tree r2 = f(r1);
		if (r2 == t) {
			setProperty(t, key, nil);
		} else {
			setProperty(t, key, r2);
		}
		return r2;
	}
}
开发者ID:gauravchawla03,项目名称:Stanford,代码行数:41,代码来源:list.cpp

示例10: subst

static Tree subst (Tree t, Tree propkey, Tree id, Tree val)
{
	Tree p;
	
	if (t==id) {
		return val;
		
	} else if (t->arity() == 0) {
		return t;
	} else if (getProperty(t, propkey, p)) {
		return (isNil(p)) ?  t : p;
	} else {
		Tree r=nil;
		switch (t->arity()) {
			
			case 1 : 
				r = tree(t->node(), 
							subst(t->branch(0), propkey, id, val)); 
				break;
				
			case 2 : 
				r = tree(t->node(), 
							subst(t->branch(0), propkey, id, val), 
							subst(t->branch(1), propkey, id, val)); 
				break;
				
			case 3 : 
				r = tree(t->node(), 
							subst(t->branch(0), propkey, id, val), 
							subst(t->branch(1), propkey, id, val), 
							subst(t->branch(2), propkey, id, val)); 
				break;
				
			case 4 : 
				r = tree(t->node(), 
							subst(t->branch(0), propkey, id, val), 
							subst(t->branch(1), propkey, id, val), 
							subst(t->branch(2), propkey, id, val), 
							subst(t->branch(3), propkey, id, val)); 
				break;
			
		}
		if (r == t) {
			setProperty(t, propkey, nil);
		} else {
			setProperty(t, propkey, r);
		}
		return r;
	}
		
}
开发者ID:gauravchawla03,项目名称:Stanford,代码行数:51,代码来源:list.cpp

示例11: getProperty

bool getProperty (Tree t, Tree key, Tree& val)
{
	CTree* pl = t->attribut();
	if (pl) return findKey(pl, key, val);
	else 	return false;
}
开发者ID:gauravchawla03,项目名称:Stanford,代码行数:6,代码来源:list.cpp

示例12: remProperty

void remProperty (Tree t, Tree key)
{
	CTree* pl = t->attribut();
	if (pl) t->attribut(removeKey(pl, key));
}
开发者ID:gauravchawla03,项目名称:Stanford,代码行数:5,代码来源:list.cpp

示例13: main

int main()
{
	Tree tree;
	tree.insert("yiyuan",new HosPartNode(1,"yiyuan"));

	tree.insert("yiyuan",new HosPartNode(10,"louceng"));

	tree.insert("louceng",new HosPartNode(1,"zhongyangdating"));
	tree.insert("louceng",new HosPartNode(4,"peilou"));

	tree.insert("zhongyangdating",new HosPartNode(1,"TV"));
	tree.insert("zhongyangdating",new HosPartNode(2,"sofa"));

	tree.insert("peilou",new HosPartNode(2,"changzoulang"));
	tree.insert("peilou",new HosPartNode(1,"zoulanglianjie"));

	tree.insert("changzoulang",new HosPartNode(21,"bingfang"));

	tree.insert("zoulanglianjie",new HosPartNode(5,"kufang"));

	tree.insert("bingfang",new HosPartNode(1,"washroom"));
	tree.insert("bingfang",new HosPartNode(4,"chazuo"));
	tree.insert("bingfang",new HosPartNode(2,"bingchuang"));

	tree.insert("washroom",new HosPartNode(1,"ximianpen"));
	tree.insert("washroom",new HosPartNode(1,"zuobianqi"));

	tree.insert("chazuo",new HosPartNode(2,"chakou"));
	tree.insert("chazuo",new HosPartNode(1,"mianban"));

//	tree.getParent(tree.Find("bingfang"))->print();
//	tree.Find("bingfang")->print();
//	cout<<endl;
	tree.WithTraverse(tree.getRoot());
	cout<<endl;
	cout<<"每个楼层中病房的数量为 : "<<tree.count("louceng","bingfang")<<endl;
	return 0;
}
开发者ID:cxy229,项目名称:dshomework,代码行数:38,代码来源:dshw3_4_2.cpp

示例14: tagsOpen

QString Parse::getTypeOfToken(const QString &ident, const QString &className,
                              Scope * scope, bool token_is_function)
{
	/* if we have a variable and already found a local definition, just return it after duplicating */
	if (!token_is_function && scope->localdef.length())
		return scope->localdef;

	/* if the identifier is this-> return the current class */
	if (ident == "this")
		return scope->scope;

	Tree *tree = NULL;
	if (className.length())
	{
		tree = Tree::buildInheritanceTree(className);
		if (!tree)
			return NULL;
	}

	tagFileInfo info;
	tagEntry entry;
	tagFile *tfile = tagsOpen(tagsFilePath.toAscii(), &info);
	if (tfile && info.status.opened)
	{
		if (tagsFind(tfile, &entry, ident.toAscii(), TAG_OBSERVECASE | TAG_FULLMATCH) ==
		        TagSuccess)
		{
			do
			{
				if (tree && !tree->isMemberOfScope(&entry, scope))
					continue;

				const char *kind = tagsField(&entry, "kind");
				if (token_is_function)	/* only list if tag is a function */
				{
					if (!kind
					        || (strcmp(kind, "function") && strcmp(kind, "prototype")))
						continue;
				}
				else		/* or a variable */
				{
					//brc: add externvar for extern variables like cout
					if (!kind
					        || (strcmp(kind, "variable") && strcmp(kind, "externvar")
					            //brc: namespace workarround: add namespace
					            && strcmp(kind, "namespace") && strcmp(kind, "member")))
						continue;
				}

				/* need to duplicate the pattern, don't ask me why */
				QString type = extractTypeQualifier(entry.address.pattern, ident);
				if(tree)
					tree->freeTree();
				tagsClose(tfile);
				return type;
			}
			while (tagsFindNext(tfile, &entry) == TagSuccess);
		}
		tagsClose(tfile);
	}
	return NULL;
}
开发者ID:pasnox,项目名称:monkeystudio1,代码行数:62,代码来源:parse.cpp

示例15: TreeCtrlEntry

/*************************************************************************
    Sample specific initialisation goes here.
*************************************************************************/
bool TreeDemoSample::initialiseSample()
   {
   using namespace CEGUI;
   Tree *      theTree;
   TreeItem *  newTreeCtrlEntryLvl1;  // Level 1 TreeCtrlEntry (branch)
   TreeItem *  newTreeCtrlEntryLvl2;  // Level 2 TreeCtrlEntry (branch)
   TreeItem *  newTreeCtrlEntryLvl3;  // Level 3 TreeCtrlEntry (branch)
   TreeItem *  newTreeCtrlEntryParent;
   Image *     iconArray[9];

#if defined( __WIN32__ ) || defined( _WIN32 )
   // Windows specific code.
   srand(time(NULL));
#endif

   // Get window manager which we will use for a few jobs here.
   WindowManager& winMgr = WindowManager::getSingleton();

//   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Standard);
//   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Insane);

   // Load the scheme to initialise the skin which we use in this sample
   SchemeManager::getSingleton().create(SCHEME_FILE_NAME);

   // set default mouse image
   System::getSingleton().setDefaultMouseCursor(IMAGES_FILE_NAME, "MouseArrow");

   // load an image to use as a background
   ImagesetManager::getSingleton().createFromImageFile("BackgroundImage", "GPN-2000-001437.tga");

   // Load some icon images for our test tree
  // Imageset *iconImages = ImagesetManager::getSingleton().create("TreeIcons.imageset");
   Imageset& drives = ImagesetManager::getSingleton().create("DriveIcons.imageset");

   // here we will use a StaticImage as the root, then we can use it to place a background image
   Window* background = winMgr.createWindow(STATICIMAGE_NAME);

   // set area rectangle
   background->setArea(URect(cegui_reldim(0), cegui_reldim(0), cegui_reldim(1), cegui_reldim(1)));
   // disable frame and standard background
   background->setProperty("FrameEnabled", "false");
   background->setProperty("BackgroundEnabled", "false");
   // set the background image
   background->setProperty("Image", "set:BackgroundImage image:full_image");
   // install this as the root GUI sheet
   System::getSingleton().setGUISheet(background);

//   CEGUI::System::getSingleton().setTooltip(TOOLTIP_NAME);

    FontManager::getSingleton().create("DejaVuSans-10.font");
//	if(!FontManager::getSingleton().isFontPresent("Commonwealth-10"))
//		FontManager::getSingleton().createFont("Commonwealth-10.font");


   TreeDemoWindow = winMgr.loadWindowLayout(LAYOUT_FILE_NAME);

   background->addChildWindow(TreeDemoWindow);

   // listen for key presses on the root window.
   background->subscribeEvent(Window::EventKeyDown, Event::Subscriber(&TreeDemoSample::handleRootKeyDown, this));

   theTree = (Tree *)TreeDemoWindow->getChild(TreeID);
   theTree->initialise();
   theTree->subscribeEvent(Tree::EventSelectionChanged, Event::Subscriber(&TreeDemoSample::handleEventSelectionChanged, this));
   theTree->subscribeEvent(Tree::EventBranchOpened, Event::Subscriber(&TreeDemoSample::handleEventBranchOpened, this));
   theTree->subscribeEvent(Tree::EventBranchClosed, Event::Subscriber(&TreeDemoSample::handleEventBranchClosed, this));

   // activate the background window
   background->activate();

   Imageset& iconImages = drives;
   iconArray[0] = (Image *)&iconImages.getImage("Artic");
   iconArray[1] = (Image *)&iconImages.getImage("Black");
   iconArray[2] = (Image *)&iconImages.getImage("Sunset");
   iconArray[3] = (Image *)&iconImages.getImage("DriveStack");
   iconArray[4] = (Image *)&iconImages.getImage("GlobalDrive");
   iconArray[5] = (Image *)&iconImages.getImage("Blue");
   iconArray[6] = (Image *)&iconImages.getImage("Lime");
   iconArray[7] = (Image *)&iconImages.getImage("Silver");
   iconArray[8] = (Image *)&iconImages.getImage("GreenCandy");

   // Create a top-most TreeCtrlEntry
   newTreeCtrlEntryLvl1 = new TreeItem("Tree Item Level 1a");
   newTreeCtrlEntryLvl1->setIcon(drives.getImage("Black"));
   newTreeCtrlEntryLvl1->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
//   newTreeCtrlEntryLvl1->setUserData((void *)someData);
   theTree->addItem(newTreeCtrlEntryLvl1);
   // Create a second-level TreeCtrlEntry and attach it to the top-most TreeCtrlEntry
   newTreeCtrlEntryLvl2 = new TreeItem("Tree Item Level 2a (1a)");
   newTreeCtrlEntryLvl2->setIcon(drives.getImage("Artic"));
   newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->addItem(newTreeCtrlEntryLvl2);
   // Create a third-level TreeCtrlEntry and attach it to the above TreeCtrlEntry
   newTreeCtrlEntryLvl3 = new TreeItem("Tree Item Level 3a (2a)");
   newTreeCtrlEntryLvl3->setIcon(drives.getImage("Blue"));
   newTreeCtrlEntryLvl3->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
//.........这里部分代码省略.........
开发者ID:CharlesSadler,项目名称:CharlesSadlerRTSGame,代码行数:101,代码来源:Sample_TreeDemo.cpp


注:本文中的Tree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。