Esempio n. 1
0
void 
Bbox::fromPointSet(std::vector<Vector> pointset)
{
	std::vector<Vector> sorted_pointset;
	sorted_pointset = sortedVectorArray(pointset,0);
	min.x = sorted_pointset.front().x;
	max.x = sorted_pointset.back().x;
	sorted_pointset = sortedVectorArray(pointset,1);
	min.y = sorted_pointset.front().y;
	max.y = sorted_pointset.back().y;
	sorted_pointset = sortedVectorArray(pointset,2);
	min.z = sorted_pointset.front().z;
	max.z = sorted_pointset.back().z;
	calcCenter();
}
IteratorPtr<LookupResult<T> > ParallelAdditionBasedElementComposer<T>::composeApproximations(const BuildingBlockBuckets<T>& buildingBlockBuckets,
		T target,
		DistanceCalculatorPtr<T> pDistanceCalculator,
		mreal_t epsilon,
		bool toSortResults) {

	SortedVectorArray<T> sortedVectorArray(m_wrapperComparator);
	sortedVectorArray.initByVectors(buildingBlockBuckets);

	SortedVectorArrayList<T> secondarySortedVectorArrays;
	initSecondarySortedVectorArrays(secondarySortedVectorArrays, buildingBlockBuckets);

	std::cout << "Finished pre-process\n";

	std::vector<T> partialTermElements;

	int lastVectorIndex = sortedVectorArray.getNbVectors() - 1;
	TaskFutureBuffer<T> taskFutureBuffer(m_pTaskExecutor, m_taskFutureBufferSize, 1);

	m_pTaskExecutor->start();
	findCompositionsInRange(sortedVectorArray,
			secondarySortedVectorArrays,
			lastVectorIndex,
			partialTermElements,
			target,
			target,
			pDistanceCalculator,
			epsilon,
			taskFutureBuffer);

	std::cout << "Number of combination submitted:" << m_combinationCounter << "\n";
	m_combinationCounter = 0;

	m_pTaskExecutor->executeAllRemaining();
	std::vector<LookupResult<T> > resultBuffer;
	taskFutureBuffer.collectResults(resultBuffer);
	m_pTaskExecutor->shutDown();

	//TODO Filter before/after sort results
	if(toSortResults) {
		std::sort(resultBuffer.begin(), resultBuffer.end(), DistanceComparator<T>());
	}

	releaseSecondarySortedVectorArrays(secondarySortedVectorArrays);

	return IteratorPtr<LookupResult<T> >(new VectorBasedReadOnlyIteratorImpl<LookupResult<T> >(resultBuffer));
}
IteratorPtr<LookupResult<T> > AdditionBasedElementComposer<T>::composeApproximations(const BuildingBlockBuckets<T>& buildingBlockBuckets,
		T target,
		DistanceCalculatorPtr<T> pDistanceCalculator,
		mreal_t epsilon,
		bool toSortResults) {

	SortedVectorArray<T> sortedVectorArray(m_wrapperComparator);
	sortedVectorArray.initByVectors(buildingBlockBuckets);

	SortedVectorArrayList<T> secondarySortedVectorArrays;
	initSecondarySortedVectorArrays(secondarySortedVectorArrays, buildingBlockBuckets);

	std::cout << "Finished pre-process\n";

	std::vector<LookupResult<T> > resultBuffer;
	std::vector<T> partialTermElements;

	int lastVectorIndex = sortedVectorArray.getNbVectors() - 1;
	try {
		findCompositionsInRange(sortedVectorArray,
				secondarySortedVectorArrays,
				lastVectorIndex,
				partialTermElements,
				target,
				target,
				pDistanceCalculator,
				epsilon,
				resultBuffer);
	}
	catch (int e) {
		std::cout << "Enough result\n";
	}

	releaseSecondarySortedVectorArrays(secondarySortedVectorArrays);

	std::cout << "Number of combination checked:" << m_combinationCounter << "\n";
	m_combinationCounter = 0;

	//TODO Filter before/after sort results
	if(toSortResults) {
		std::sort(resultBuffer.begin(), resultBuffer.end(), DistanceComparator<T>());
	}

	return IteratorPtr<LookupResult<T> >(new VectorBasedReadOnlyIteratorImpl<LookupResult<T> >(resultBuffer));
}