Exemplo n.º 1
0
std::deque<const Coords*> LcpFinder::leastCostPath(int algorithm) {
    if (this->startPoint == 0) {
        std::cout << "No startpoint set in finder. Is the startpoint inside any polygon?\n" << std::endl;
        exit(1);
    }
    for (int i = 0; i<this->polygons.size(); i++) {
        this->triangulate(i);
    }

    int targetsFound = 0;
    this->startPoint->setToStart(0);
    /*
    bool (*compareFunction)(const Coords*, const Coords*);
    

    if (algorithm == 0) {
        compareFunction = &compDijkstra;
    } else if (algorithm == 1) {
        compareFunction = &compAstar;
    }
    cmpr comparator{compareFunction};
     */
    //MinHeap<const Coords*, cmpr> minheap(comparator);
    //MinHeap<const Coords*, cmpr> minheap(comparator);
    boost::heap::fibonacci_heap<const Coords*, boost::heap::compare < Coords::cmpr>> minheap;

    this->startPoint->handle = minheap.push(this->startPoint);

    int handled = 0;
    int old = 0;
    int total = this->coordmap.size();
    int percent = total / 100;

    while (!minheap.empty()) {
        if (handled - old > percent) {
            int percentage = handled * 100 / total;
            old = handled;
            std::cout << "\rSearching..." << percentage << "% done";
            fflush(stdout);
        }
        handled++;

        const Coords* node = minheap.top();
        //std::cout<<node->toString()<<std::endl;
        if (node == 0) {
            std::cout << "current node = 0\n";
            exit(2);
        }
        if (node->flag == 1) {
            targetsFound++;
            if (targetsFound == this->numOfTargets) {
                std::cout << "break\n";
                break;
            }
        }


        minheap.pop();
        nSet neighbours = findNeighbours(node);

        for (std::pair<const Coords*, double> p : neighbours) {
            const Coords* n = p.first;
            if (n == 0) {
                std::cout << "neighbour is 0\n";
                exit(2);
            }
            double d = p.second;

            if (n->getToStart() < 0) { // node has not yet been inserted into minheap
                n->setToStart(d);
                //n->setToEnd(this->toClosestEnd(n));
                n->setPred(node);
                n->handle = minheap.push(n);
            } else if (n->getToStart() > d) {
                n->setToStart(d);
                n->setPred(node);
                minheap.increase(n->handle);

                //minheap.decrease(n); //reorders minheap after changing priority of n
            }
        }
    }

    std::deque<const Coords*> res{};
    for (std::pair<int, std::forward_list < const Coords*>> polygon : this->targetPoints) {

        for (const Coords* ep : polygon.second) {
            if (ep == 0) {
                std::cout << "EP == 0\n";
                continue;
            }

            if (ep == this->startPoint) {
                continue;
            }
            res.push_back(ep);

        }
    }
    return res;
}
Exemplo n.º 2
0
MStatus BCIViz::compute( const MPlug& plug, MDataBlock& block )
{
	if( plug == outValue ) {
		MStatus status;
		
		MDagPath path;
		MDagPath::getAPathTo(thisMObject(), path);
		
		MMatrix worldInverseSpace = path.inclusiveMatrixInverse();
		
		MDataHandle inputdata = block.inputValue(ainput, &status);
        if(status) {
			const MMatrix drvSpace = inputdata.asMatrix();
			fDriverPos.x = drvSpace(3, 0);
			fDriverPos.y = drvSpace(3, 1);
			fDriverPos.z = drvSpace(3, 2);
			
			fDriverPos *= worldInverseSpace;
		}
		
		fTargetPositions.clear();
		
		MArrayDataHandle htarget = block.inputArrayValue( atargets );
		unsigned numTarget = htarget.elementCount();
		
		fTargetPositions.setLength(numTarget);
		
		for(unsigned i = 0; i<numTarget; i++) {
			MDataHandle tgtdata = htarget.inputValue(&status);
			if(status) {
				const MMatrix tgtSpace = tgtdata.asMatrix();
				MPoint tgtPos(tgtSpace(3,0), tgtSpace(3,1), tgtSpace(3,2));
				tgtPos *= worldInverseSpace;
				MVector disp = tgtPos;
				disp.normalize();
				tgtPos = disp;
				fTargetPositions[i] = tgtPos;
			}
			htarget.next();
		}
		
		m_hitTriangle = 0;
		neighbourId[0] = 0;
		neighbourId[1] = 1;
		neighbourId[2] = 2;
		
		if(!checkTarget())
		{
			MGlobal::displayWarning("convex hull must have no less than 4 targes.");
			return MS::kSuccess;
		}
		
		if(!checkFirstFour(fTargetPositions))
		{
			MGlobal::displayWarning("first 4 targes cannot sit on the same plane.");
			return MS::kSuccess;
		}
		
		if(!constructHull())
		{
			MGlobal::displayWarning("convex hull failed on construction.");
			return MS::kSuccess;
		}

		findNeighbours();
		
		calculateWeight();

        MArrayDataHandle outputHandle = block.outputArrayValue( outValue );
		
		int numWeight = fTargetPositions.length();

		m_resultWeights.setLength(numWeight);
		
		for(int i=0; i < numWeight; i++) 
			m_resultWeights[i] = 0.0;
			
		m_resultWeights[neighbourId[0]] = fAlpha;
		m_resultWeights[neighbourId[1]] = fBeta;
		m_resultWeights[neighbourId[2]] = fGamma;
		
		MArrayDataBuilder builder(outValue, numWeight, &status);
		
		for(int i=0; i < numWeight; i++) {
			MDataHandle outWeightHandle = builder.addElement(i);
			outWeightHandle.set( m_resultWeights[i] );
			//MGlobal::displayInfo(MString("wei ") + i + " " + weights[i]);
		}
		
		outputHandle.set(builder);
		outputHandle.setAllClean();
    }

	return MS::kSuccess;
}
/*-----------------------------------------------------------*/
int haloExchange(int benchmarkType){
	int dataSizeIter;

	/* find the ranks of the left and right neighbour */
	findNeighbours();

	/* initialise repsToDo to defaultReps */
	repsToDo = defaultReps;

	/* Start loop over data sizes */
	dataSizeIter = minDataSize; /* Initialise dataSizeIter */

    MPI_Barrier(comm);
	while (dataSizeIter <= maxDataSize){
		/* set sizeofBuffer */
		sizeofBuffer = dataSizeIter * numThreads;

		/*Allocate space for the main data arrays */
		allocateHaloexchangeData(sizeofBuffer);

		/* perform benchmark warm-up */
		if (benchmarkType == MASTERONLY){
			masteronlyHaloexchange(warmUpIters, dataSizeIter);
		}
		else if (benchmarkType == FUNNELLED){
			funnelledHaloexchange(warmUpIters, dataSizeIter);
		}
		else if (benchmarkType == MULTIPLE){
			multipleHaloexchange(warmUpIters, dataSizeIter);
		}

        GASPI(barrier(GASPI_GROUP_ALL, GASPI_BLOCK));
        /* Each process performs a verification test */
		testHaloexchange(sizeofBuffer, dataSizeIter);
        MPI_Barrier(comm);

		/*Initialise the benchmark */
		benchComplete = FALSE;

		/*Execute benchmark until target time is reached */
		while (benchComplete != TRUE){
			/*Start timer */
			GASPI(barrier(GASPI_GROUP_ALL, GASPI_BLOCK));
			startTime = MPI_Wtime();

			/*Execute benchmarkType for repsToDo repetitions*/
			if (benchmarkType == MASTERONLY){
				masteronlyHaloexchange(repsToDo, dataSizeIter);
			}
			else if (benchmarkType == FUNNELLED){
				funnelledHaloexchange(repsToDo, dataSizeIter);
			}
			else if (benchmarkType == MULTIPLE){
				multipleHaloexchange(repsToDo, dataSizeIter);
			}

			/*Stop timer */
			GASPI(barrier(GASPI_GROUP_ALL, GASPI_BLOCK));
			finishTime = MPI_Wtime();
			totalTime = finishTime - startTime;

            MPI_Barrier(comm);
            /* Test if target time is reached with the number of reps */
			if (myMPIRank==0){
			  benchComplete = repTimeCheck(totalTime, repsToDo);
			}
			/* Ensure all procs have the same value of benchComplete */
			/* and repsToDo */
			MPI_Bcast(&benchComplete, 1, MPI_INT, 0, comm);
			MPI_Bcast(&repsToDo, 1, MPI_INT, 0, comm);
		}

		/* Master process sets benchmark results */
		if (myMPIRank == 0 ){
			setReportParams(dataSizeIter, repsToDo, totalTime);
			printReport();
		}

		/* Free allocated data */
		freeHaloexchangeData();

		/* Double dataSize and loop again */
		dataSizeIter = dataSizeIter * 2;
	}

	return 0;
}
Exemplo n.º 4
0
void RegionGrowingHSV::findPointNeighbours ()
{
    // convert point cloud type to vtkPolyData
    vtkPolyData* m_polydata = vtkPolyData::New();
    int convertnum = mesh2vtk(m_polymesh,m_polydata);
    if( num_pts!=convertnum )
        return;

    pcl::search::Search <pcl::PointXYZRGB>::Ptr tree =
            boost::shared_ptr<pcl::search::Search<pcl::PointXYZRGB> > (new pcl::search::KdTree<pcl::PointXYZRGB>);
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
    pcl::fromROSMsg(m_polymesh.cloud,*cloud);
    tree->setInputCloud(cloud);
    std::vector<float> nearestDis;

    std::vector<int> neighbours;
    point_neighbours_.clear();
    neighbours_for_possi_.clear();
    point_neighbours_.resize (num_pts, neighbours);
    neighbours_for_possi_.resize(num_pts,neighbours);

    for (int i_point = 0; i_point < num_pts; i_point++)
    {
        std::vector<bool> is_neighbour(num_pts,false);
        std::vector<int> seed_initial;
        std::vector<int> seed;
        seed_initial.push_back(i_point);

        int time = 0;
        neighbours.clear ();

        while( !seed_initial.empty() && time<searchDis_ )
        {
            while( !seed_initial.empty() )      // 将seed_initial中的种子点copy到seed中
            {
                seed.swap(seed_initial);
                seed_initial.clear();
            }
            while(!seed.empty())
            {
                int current_seed = seed[0];
                seed.erase(seed.begin());
                is_neighbour[current_seed] = true;
                findNeighbours(current_seed,seed_initial,neighbours,is_neighbour,m_polydata);
            }
            time++;
            if(time==1)
            {
                if(neighbours.size()<3)
                {
                    neighbours.clear();
                    nearestDis.clear();
                    tree->nearestKSearch(cloud->points[i_point],10,neighbours,nearestDis);
                }
                point_neighbours_[i_point] = neighbours;
            }
        }
        //std::cout<<"size neighbours of the "<<i_point<<"'s point is "<<neighbours.size()<<std::endl;
        if(neighbours.size()<3)
        {
            neighbours.clear();
            nearestDis.clear();
            tree->nearestKSearch(cloud->points[i_point],10,neighbours,nearestDis);
        }
        neighbours_for_possi_[i_point].swap (neighbours);
    }
    std::cout<<"find point neighbours end..."<<std::endl;
}