Пример #1
0
    WarpPoint * WarpGrid::selectNearest(const QPointF& _p)
    {
        size_t _nearestIdx = getNearest(_p);
        auto   _nearest    =
            (_nearestIdx == -1) ? nullptr : &points_[_nearestIdx];
        hasChanged_ = true;

        return _nearest;
    }
Пример #2
0
bool Foam::surfaceToCell::differingPointNormals
(
    const triSurfaceSearch& querySurf,

    const vector& span,         // Current search span
    const label celli,
    const label cellTriI,       // Nearest (to cell centre) surface triangle

    Map<label>& pointToNearest  // Cache for nearest triangle to point
) const
{
    const triSurface& surf = querySurf.surface();
    const vectorField& normals = surf.faceNormals();

    const faceList& faces = mesh().faces();
    const pointField& points = mesh().points();

    const labelList& cFaces = mesh().cells()[celli];

    forAll(cFaces, cFacei)
    {
        const face& f = faces[cFaces[cFacei]];

        forAll(f, fp)
        {
            label pointi = f[fp];

            label pointTriI =
                getNearest
                (
                    querySurf,
                    pointi,
                    points[pointi],
                    span,
                    pointToNearest
                );

            if (pointTriI != -1 && pointTriI != cellTriI)
            {
                scalar cosAngle = normals[pointTriI] & normals[cellTriI];

                if (cosAngle < 0.9)
                {
                    return true;
                }
            }
        }
    }
Пример #3
0
    /**
     * Draws the LetterCube
     */
    void LetterCube::draw() {
        glPushMatrix();
        
        glEnable(GL_BLEND); //Enable alpha blending
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Set the blend function
        
        if (Window::getInstance()->LODSwitch)
        {
            Point camera = Point(Window::getInstance()->camera_pos[0], Window::getInstance()->camera_pos[1], Window::getInstance()->camera_pos[2]);
            Point nearest = getNearest(camera);
            GLfloat distance = sqrt(pow(camera.getXCoord()-nearest.getXCoord(), 2)+pow(camera.getYCoord()-nearest.getYCoord(), 2)+pow(camera.getZCoord()-nearest.getZCoord(), 2));

            if( distance >= LOD_RANGE_3 )
            {
                this->setColor(1.0f, 0.0f, 0.0f, 0.5f);
            }
            else if( distance >= LOD_RANGE_2 )
            {
                this->setColor(0.0f, 1.0f, 0.0f, 0.5f);
            }
            else if( distance >= LOD_RANGE_1 )
            {
                this->setColor(0.0f, 0.0f, 1.0f, 0.5f);
            }
            else
            {
                this->setColor(1.0f, 1.0f, 1.0f, 0.5f);
            }
        }
        else
        {
            this->setColor(1.0f, 1.0f, 1.0f, 0.5f);
        }

        GLCube::draw();
        glDisable(GL_BLEND);
        glPopMatrix();
    }
Пример #4
0
TreeNode* Starbucks_Sonodabe::getNearest(double x, double y, TreeNode* root){
    if(root == NULL)
        return NULL;
    double distSquared, distFromBorder;
    //Candidate is the nearest of the side that the point is on
    
    //If the distance between the border and the point is closer than the point and the candidate search the other side
    
    TreeNode* candidate;
    bool left;
    if(root->isX){
        if(x < root->data->x){
            candidate = (root->left != NULL)? getNearest(x, y, root->left) : root;
            left = true;   
        }
        else{
            candidate = (root->right != NULL)? getNearest(x, y, root->right) : root;
            left = false;
        }
        
        distSquared = (candidate->data->x-x)*(candidate->data->x-x)+(candidate->data->y-y)*(candidate->data->y-y);
        distFromBorder = root->data->x - x;
        if(distFromBorder*distFromBorder < distSquared){
            TreeNode* candidate2;
            
            if(left){
                candidate2 = (root->right != NULL)? getNearest(x, y, root->right) : root;
            }
            else{
                candidate2 = (root->left != NULL)? getNearest(x, y, root->left) : root;
            }
            
            double distSquared2 = (candidate2->data->x-x)*(candidate2->data->x-x)+(candidate2->data->y-y)*(candidate2->data->y-y);
            if(distSquared2 < distSquared){
                candidate = candidate2;
                distSquared = (candidate->data->x-x)*(candidate->data->x-x)+(candidate->data->y-y)*(candidate->data->y-y);
            }
        }
        
        
        //Check to see if the root is closer
        double distFromRoot = (root->data->x-x)*(root->data->x-x)+(root->data->y-y)*(root->data->y-y);
        
        if(distFromRoot < distSquared)
            return root;
        return candidate;
    }else{
        if(y < root->data->y){
            candidate = (root->left != NULL)? getNearest(x, y, root->left) : root;
            left = true;   
        }
        else{
            candidate = (root->right != NULL)? getNearest(x, y, root->right) : root;
            left = false;
        }
        
        distSquared = (candidate->data->x-x)*(candidate->data->x-x)+(candidate->data->y-y)*(candidate->data->y-y);
        distFromBorder = root->data->y - y;
        if(distFromBorder*distFromBorder < distSquared){
            TreeNode* candidate2;
            
            if(left){
                candidate2 = (root->right != NULL)? getNearest(x, y, root->right) : root;
            }
            else{
                candidate2 = (root->left != NULL)? getNearest(x, y, root->left) : root;
            }
            
            double distSquared2 = (candidate2->data->x-x)*(candidate2->data->x-x)+(candidate2->data->y-y)*(candidate2->data->y-y);
            if(distSquared2 < distSquared)
                candidate = candidate2;
            
            distSquared = (candidate->data->x-x)*(candidate->data->x-x)+(candidate->data->y-y)*(candidate->data->y-y);
        }
        
        
        //Check to see if the root is closer
        double distFromRoot = (root->data->x-x)*(root->data->x-x)+(root->data->y-y)*(root->data->y-y);
        
        if(distFromRoot < distSquared)
            return root;
        return candidate;
    }
}
Пример #5
0
Entry* Starbucks_Sonodabe::getNearest(double x, double y){
    /*Reasoning find the nearest in the right tree, and the left
     tree, and compare that to the root, return the smallest. */
    return getNearest(x, y, tree->root)->data;
}
Пример #6
0
vector<int> CSVop::getNearestrows(vector<int> rows, int col, double val, double precision, bool absolute)
{
    double maxval;
    maxval = getNearest(col, val, rows);
    return getrowswtol(rows, col, maxval, precision, absolute);
}
CUnit* UnitFinder::getNearest(int x, int y, UnitFinderCallbackMatchInterface &callback) {
  return getNearest(x, y, 0, 0, mapTileSize->width * 32, mapTileSize->height * 32, callback);
}
Пример #8
0
void mexFunction( int nlhs, 
		  mxArray *plhs[], 
		  int nrhs, 
		  const mxArray *prhs[] )
{ 
    double *yp; 
    
    double *t,*y, *refPtr, *inpPtr, *outPtr, *distPtr; 
    unsigned int refRows,refCols,inpRows,inpCols; 

    /* Check for proper number of arguments */

    if (nrhs != 2) { 
		mexErrMsgTxt("Two input vectors required."); 
    } else if (nlhs > 2) {
		mexErrMsgTxt("Error! Too many output arguments."); 
    } 

    
  /*  Get the dimensions and a pointer to the reference matrix. */
	refRows = mxGetM(prhs[0]);
	refCols = mxGetN(prhs[0]);
	refPtr = mxGetPr(prhs[0]);

  /*  Get the dimensions and a pointer to the input matrix. */
	inpRows = mxGetM(prhs[1]);
	inpCols = mxGetN(prhs[1]);
	inpPtr = mxGetPr(prhs[1]);

  
 	/* Check for type and size */

    if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0])) { 
		mexErrMsgTxt("Argument 1 must be a real double"); 
    } 
    
    if (!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1])) { 
		mexErrMsgTxt("Argument 2 must be a real double"); 
    } 

	if ((refRows!=3) || (inpRows!=3)) {
		mexErrMsgTxt("Both input arguments must have 3 rows"); 
	}

    /* printf("Got here ... assigning");*/
    /* Create a matrix for the return argument */ 
    plhs[0] = mxCreateDoubleMatrix(inpCols, 1, mxREAL); 
    plhs[1] = mxCreateDoubleMatrix(inpCols, 1, mxREAL); 

  
    outPtr=mxGetPr(plhs[0]);
    distPtr=mxGetPr(plhs[1]);
    /* Assign pointers to the various parameters */ 

    if ((!outPtr) || (!distPtr)) { 
		mexErrMsgTxt("Could not assign output matrices. Out of memory?"); 
    } 

  /*  printf("Got here 232");
    /* Do the actual computations in a subroutine */
    getNearest(inpPtr,refPtr,outPtr,distPtr,inpCols,refCols); 
/*  printf("Got here dfjdkj");  */
    
	/* Don't compute the flops */
  return;
}