void FindContourSurface::compute( const unsigned& current, MultiValue& myvals ) const {
  std::vector<unsigned> neighbours; unsigned num_neighbours; unsigned nfound=0; double minp=0;
  std::vector<unsigned> bins_n( ingrid->getNbin() ); unsigned shiftn=current;
  std::vector<unsigned> ind( ingrid->getDimension() ); std::vector<double> point( ingrid->getDimension() );
#ifndef DNDEBUG
  std::vector<unsigned> oind( mygrid->getDimension() ); mygrid->getIndices( current, oind );
#endif
  for(unsigned i=0; i<bins_n[dir_n]; ++i) {
#ifndef DNDEBUG
    std::vector<unsigned> base_ind( ingrid->getDimension() ); ingrid->getIndices( shiftn, base_ind );
    for(unsigned j=0; j<gdirs.size(); ++j) plumed_dbg_assert( base_ind[gdirs[j]]==oind[j] );
#endif
    // Ensure inactive grid points are ignored
    if( ingrid->inactive( shiftn ) ) { shiftn += ingrid->getStride()[dir_n]; continue; }
    // Get the index of the current grid point
    ingrid->getIndices( shiftn, ind );
    // Exit if we are at the edge of the grid
    if( !ingrid->isPeriodic(dir_n) && (ind[dir_n]+1)==bins_n[dir_n] ) {
      shiftn += ingrid->getStride()[dir_n]; continue;
    }

    // Ensure points with inactive neighbours are ignored
    ingrid->getNeighbors( ind, ones, num_neighbours, neighbours );
    bool cycle=false;
    for(unsigned j=0; j<num_neighbours; ++j) {
      if( ingrid->inactive( neighbours[j]) ) { cycle=true; break; }
    }
    if( cycle ) { shiftn += ingrid->getStride()[dir_n]; continue; }

    // Now get the function value at two points
    double val1=getFunctionValue( shiftn ) - contour; double val2;
    if( (ind[dir_n]+1)==bins_n[dir_n] ) val2 = getFunctionValue( current ) - contour;
    else val2=getFunctionValue( shiftn + ingrid->getStride()[dir_n] ) - contour;

    // Check if the minimum is bracketed
    if( val1*val2<0 ) {
      ingrid->getGridPointCoordinates( shiftn, point ); findContour( direction, point );
      minp=point[dir_n]; nfound++; break;
    }


    // This moves us on to the next point
    shiftn += ingrid->getStride()[dir_n];
  }
  if( nfound==0 ) {
    std::string num; Tools::convert( getStep(), num );
    error("On step " + num + " failed to find required grid point");
  }
  myvals.setValue( 1, minp );
}
	void ContourFinder::findBalls(std::vector<MoveBall*>& balls, int numBalls)
	{
		bool needToComb = false;
		for (int i=0; i<numBalls; i++)
		{
			// if the center of the previous ball is in the new ball, don't search for it
			if (balls[i]->ballFound && balls[i]->getMask(balls[i]->position)>BALL_MARGIN)
			{
				balls[i]->position.x--;
				// search the left contour
				searchEdge(balls[i]);
			}
			// if not, we need to comb the whole image
			else
			{
				balls[i]->ballFound=false;
				needToComb=true;
			}
		}
		// comb image if needed
		if (needToComb)
		{
			combImage(balls, numBalls);
		}

		for (int i=0; i<numBalls; i++)
		{
			if (balls[i]->ballFound)
			{
				// find the contour of each ball
				findContour((balls[i]));
				// if the contour is too small, discard it
				if (balls[i]->ballContour.size()<3)
				{
					balls[i]->ballFound=false;
					continue;
				}
			}
		}
	}
示例#3
0
//--------------------------------------------------------------
void testApp::update(){
#ifndef __APPLE__
#ifndef __NO_KINECT__
        kinect.update();
        if(kinect.isFrameNew()) {
                grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
                colorImage.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
        }
		if(frameMerge) {
			frameMergeFilter();
			//ofLogNotice() << "Merging Frame";
		}
		if(filterOn) {
			grayImage.setFromPixels(filter->getFrame(grayImage), kinect.width, kinect.height);
		}
		if(sharpenOn)
			sharpenImage();
		if(invertOn)
			invertImage();
		if(contourOn)
			findContour();
#endif
#endif
}