示例#1
0
void BTreeBuilder::buildUnbalanced(
    ByteInputStream &sortedInputStream,
    RecordNum nEntriesTotal,
    double fillFactor)
{
    // TODO:  common fcn
    // calculate amount of space to reserve on each leaf from fillfactor
    uint cbReserved = getSegment()->getUsablePageSize() - sizeof(BTreeNode);
    cbReserved = uint(cbReserved*(1-fillFactor));

    // start with just a leaf level
    growTree();
    BTreeBuildLevel &level = getLevel(0);
    level.cbReserved = cbReserved;
    level.nEntriesTotal = nEntriesTotal;
    level.processInput(sortedInputStream);

    // NOTE:  It's important to realize that growTree() could be called inside
    // this loop, so it's necessary to recompute levels.size() after each
    // iteration.
    for (uint i = 0; i < levels.size(); ++i) {
        BTreeBuildLevel &level = getLevel(i);
        level.indexLastKey(true);
    }

    swapRoot();
}
示例#2
0
void BTreeBuilder::buildTwoPass(
    ByteInputStream &sortedInputStream,
    RecordNum nEntriesTotal,
    double fillFactor)
{
    // calculate amount of space to reserve on each leaf from fillfactor
    uint cbReserved = getSegment()->getUsablePageSize() - sizeof(BTreeNode);
    cbReserved = uint(cbReserved*(1-fillFactor));

    levels.resize(1);
    BTreeNodeAccessor &nodeAccessor = *pLeafNodeAccessor;
    assert(!nodeAccessor.hasFixedWidthEntries());
    VariableBuildLevel *pLeafLevel = new VariableBuildLevel(*this,nodeAccessor);
    levels[0].reset(pLeafLevel);

    BTreeBuildLevel &level = getLevel(0);
    level.nEntriesTotal = nEntriesTotal;
    level.cbReserved = cbReserved;

    level.allocatePage();

    // feed data into the leaf level; this will collect the entries for
    // level 1 (the parent of the leaf level) in a temp stream
    level.processInput(sortedInputStream);

    level.indexLastKey(true);

    // now we know how many entries to expect for level 1:  the number of
    // leaf nodes just filled
    RecordNum nEntriesParent = level.iNode + 1;

    if (nEntriesParent == 1) {
        // The leaf we just filled turns out to be the root.
        swapRoot();
        return;
    }

    // REVIEW:  distinguish leaf fillFactor from non-leaf fillFactor?

    SharedSegInputStream pParentInputStream =
        pLeafLevel->getParentKeyStream();
    assert(pParentInputStream);
    // feed buffered entries into level 1, and build up balanced from there
    buildBalanced(*pParentInputStream,1,nEntriesParent,fillFactor);
}
示例#3
0
void SQMAlgorithm::straightenSkeleton() {
	updateResetRoot();
	refreshIDs();
	if (LOG_COMPUTATION_TIME) {
		fb->open("logs/log.txt", ios::out);
		(*os) << "Skeleton straightening\n";
	}
	clock_t ts, te;
	if (skeleton) delete skeleton;
	SkinSkeleton *skeletonB = NULL;
	SkinSkeleton *skeletonR = NULL;
	totalClocks = 0;
	algorithmClocks = 0;

	ts = clock();
	root->breakCycles();
	te = clock();
	if (LOG_COMPUTATION_TIME)
		(*os) << "\tCycles preprocess took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";

	if (root->getNodes()->size() == 0) {
		//handle just root
		if (mesh) delete mesh;
		mesh = new MyMesh();
		ts = clock();
		root->createScaledIcosahderon(mesh);
		te = clock();
		sqmState = SQMFinalPlacement;
		if (LOG_COMPUTATION_TIME) {
			(*os) << "\tIt took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
			(*os) << "\n\nPreprocess time " << 0 << " clicks (" << 0 << " seconds)\n";
			(*os) << "Algorithm time " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
			(*os) << "Total time " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
		}
	} else if (root->getNodes()->size() <= 2) {
		SQMNode *node = findBNPInTree();
		if (node == NULL) {
			//handle worm
			ts = clock();
			//root->breakCycles();
			if (useCapsules) root->createCapsules();
			fixWorm();
			numOfNodes = countNodes();
			refreshIDs();
			te = clock();
			if (LOG_COMPUTATION_TIME)
				(*os) << "\tCapsule preprocess took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
			totalClocks += (te - ts);
			if (mesh) delete mesh;
			mesh = new MyMesh();
			skeletonR = root->exportToSkinSkeleton(NULL);
			ts = clock();
			root->wormCreate(mesh);
			te = clock();
			skeletonB = root->exportToSkinSkeleton(NULL);
			if (LOG_COMPUTATION_TIME)
				(*os) << "\tIt took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
			algorithmClocks += te - ts;
			sqmState = SQMJoinBNPs;
		} else {
			ts = clock();
			swapRoot(node);
			refreshIDs();
			te = clock();
			if (LOG_COMPUTATION_TIME)
				(*os) << "\tPreprocess took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
			totalClocks += te - ts;
		}
	}
	if (root->getNodes()->size() >= 3) {
		root->setIsCyclic(hasCycle);
		ts = clock();
		//root->breakCycles();
		if (useCapsules) root->createCapsules();
		numOfNodes = countNodes();
		refreshIDs();
		te = clock();
		if (LOG_COMPUTATION_TIME)
			(*os) << "\tCapsule preprocess took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
		totalClocks += te - ts;
		//root->straightenSkeleton(OpenMesh::Vec3f(0, 0, 0));
		skeletonR = root->exportToSkinSkeleton(NULL);
		ts = clock();
		//root->straightenSkeleton(NULL);
		root->straightenSkl();
		te = clock();
		skeletonB = root->exportToSkinSkeleton(NULL);
		(*os) << "\tIt took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
		algorithmClocks += te - ts;
		sqmState = SQMStraighten;
	}
	ts = clock();
	if (skeletonB != NULL) {
		skeletonR->CalculateCorrespondingDoF(skeletonB);
		skeletonR->ComputeSkinningMatrices();
		//skeletonR->ComputeCompoundRotation();
		skeleton = skeletonR;
	}
	te = clock();
	if (LOG_COMPUTATION_TIME)
		(*os) << "\tSkinning computation took " << te - ts << " clicks (" << (((float)(te - ts)) / CLOCKS_PER_SEC) << " seconds)\n";
	totalClocks += te - ts;

	if (LOG_COMPUTATION_TIME) {
		(*os) << "\n";
		fb->close();
	}
	delete skeletonB;
}