コード例 #1
0
ファイル: SuffixTree.cpp プロジェクト: Tsuiwiki/infobright
void SuffixTree<Symb,NSymb>::SetCounts()
{
	std::vector<StackElem> stack;
	stack.reserve(STACK_INIT);
	stack.push_back(StackElem(ROOT,false));

	PNode n, ch;
	bool proc;
	while(!stack.empty()) {
		n = stack.back().n;
		proc = stack.back().proc;
		stack.pop_back();
		Node& node = GetNode(n);
		ch = node.child;
		if(ch == NIL) continue;

		if(proc) {		// children are already processed (their counts are correct)
			int& count = node.count;
			while(ch != NIL) {
				count += GetNode(ch).count;
				ch = NxtChild(ch);
			}
		}
		else {		// insert children onto the stack
			stack.push_back(StackElem(n,true));
			while(ch != NIL) {
				stack.push_back(StackElem(ch,false));
				ch = NxtChild(ch);
			}
		}
	}
}
コード例 #2
0
ファイル: traverse.cpp プロジェクト: nadult/Snail
void DBVH::TraverseShadow0(ShadowContext &c, int firstNode) const {
	const int size = c.Size();

	StackElem stack[maxDepth + 2]; int stackPos = 0;
	stack[stackPos++] = StackElem(firstNode, 0, size - 1);
	TreeStats stats;

	int sign[3] = { c.Dir(0).x[0] < 0.0f, c.Dir(0).y[0] < 0.0f, c.Dir(0).z[0] < 0.0f };
//	if(c.shadowCache[0] != ~0) {
//		const Triangle &tri = triCache[c.shadowCache[0]];
//		tri.CollideShadow(c, 0, size - 1);
//	}

	RayInterval interval(c.rays);
	
	while(stackPos) {
		int nNode = stack[--stackPos].node;
		int firstActive = stack[stackPos].firstActive;
		int lastActive = stack[stackPos].lastActive;

	CONTINUE:
		stats.LoopIteration();

		if(nodes[nNode].IsLeaf()) {
			int count = nodes[nNode].count, first = nodes[nNode].first & 0x7fffffff;

			const BBox &box = nodes[nNode].bbox;
			if(!box.TestInterval(interval))
				continue;

			if(box.Test(c, firstActive, lastActive))
				for(int n = 0; n < count; n++) {
					const ObjectInstance &obj = elements[first + n];
					obj.CollideShadow(c, firstActive, lastActive);
					stats.Intersection(lastActive - firstActive + 1);
				}
			continue;
		}
			
		bool test = 0; {
			const BBox &box = nodes[nNode].bbox;
			if(!box.TestInterval(interval))
				continue;
			test = box.Test(c, firstActive, lastActive);
		}

		if(test) {
			int firstNode = nodes[nNode].firstNode ^ sign[nodes[nNode].axis];
			int child = nodes[nNode].subNode;
			stack[stackPos++] = StackElem(child + (firstNode ^ 1), firstActive, lastActive);
			nNode = child + firstNode;
			goto CONTINUE;
		}
	}

	if(c.stats)
		(*c.stats) += stats;
}
コード例 #3
0
	void GUIResourceTreeView::updateFromProjectLibraryEntry(ResourceTreeElement* treeElement, const ProjectLibrary::LibraryEntry* libraryEntry)
	{
		struct StackElem
		{
			StackElem(const ProjectLibrary::LibraryEntry* entry, ResourceTreeElement* treeElem)
				:entry(entry), treeElem(treeElem)
			{ }

			const ProjectLibrary::LibraryEntry* entry;
			ResourceTreeElement* treeElem;
		};

		if(libraryEntry->type == ProjectLibrary::LibraryEntryType::Directory)
		{
			Stack<StackElem> todo;
			todo.push(StackElem(libraryEntry, treeElement));

			while(!todo.empty())
			{
				StackElem curElem = todo.top();
				todo.pop();

				const ProjectLibrary::DirectoryEntry* dirEntry = static_cast<const ProjectLibrary::DirectoryEntry*>(curElem.entry);

				for(auto& child : dirEntry->mChildren)
				{
					ResourceTreeElement* newChild = addTreeElement(curElem.treeElem, child->path);

					if(child->type == ProjectLibrary::LibraryEntryType::Directory)
						todo.push(StackElem(child, newChild));
				}

				sortTreeElement(curElem.treeElem);
			}
		}
	}
コード例 #4
0
ファイル: traverse.cpp プロジェクト: nadult/Snail
void DBVH::TraversePrimary0(Context<sharedOrigin, hasMask> &c, int firstNode) const {
	const int size = c.Size();

	StackElem stack[maxDepth + 2]; int stackPos = 0;
	stack[stackPos++] = StackElem(firstNode, 0, size - 1);
	TreeStats stats;

	int sign[3] = { c.Dir(0).x[0] < 0.0f, c.Dir(0).y[0] < 0.0f, c.Dir(0).z[0] < 0.0f };

	CornerRays crays(c.rays);
	RayInterval interval(c.rays);
	
	while(stackPos) {
		int nNode = stack[--stackPos].node;
		int firstActive = stack[stackPos].firstActive;
		int lastActive = stack[stackPos].lastActive;

	CONTINUE:
		stats.LoopIteration();

		if(nodes[nNode].IsLeaf()) {
			int count = nodes[nNode].count, first = nodes[nNode].first & 0x7fffffff;

			const BBox &box = nodes[nNode].bbox;
			if(!box.TestInterval(interval))
				continue;

			if(box.Test(c, firstActive, lastActive))
				for(int n = 0; n < count; n++) {
					const ObjectInstance &obj = elements[first + n];
					obj.CollidePrimary(c, first + n, firstActive, lastActive);
					stats.Intersection(lastActive - firstActive + 1);
				}

			continue;
		}
			
		int child = nodes[nNode].subNode;
#ifdef VECLIB_SSE_VER
		_mm_prefetch(&nodes[child + 0], _MM_HINT_T0);
		_mm_prefetch(&nodes[child + 1], _MM_HINT_T0);
#endif
			
		bool test = 1; {
			const BBox &box = nodes[nNode].bbox;
			if(!box.TestInterval(interval))
				continue;
			test = box.Test(c, firstActive, lastActive);
		}

		if(test) {
			int firstNode = nodes[nNode].firstNode ^ sign[nodes[nNode].axis];
			stack[stackPos++] = StackElem(child + (firstNode ^ 1), firstActive, lastActive);
			nNode = child + firstNode;
			goto CONTINUE;
		}
	}

	if(c.stats)
		(*c.stats) += stats;
}