static PyObject * DiffractionAnalysisWrap_BilinearInterpolation( PyObject *self, PyObject *args) { double x, y; PyArrayObject *data; PyArg_ParseTuple(args,"O!dd",&PyArray_Type,&data,&x,&y); return Py_BuildValue("d",bilinearInterpolation(data,x,y)); }
Vec4D CSceneData::getColor(float fX, float fY)const { int nCellX = fX; int nCellY = fY; float u = fX - nCellX; float v = fY - nCellY; Vec4D a = getVertexColor(nCellX, nCellY); Vec4D b = getVertexColor(nCellX+1, nCellY); Vec4D c = getVertexColor(nCellX, nCellY+1); Vec4D d = getVertexColor(nCellX+1, nCellY+1); return bilinearInterpolation(a,b,c,d,u,v); }
float CSceneData::getHeight(float fX, float fY)const { int nCellX = fX; int nCellY = fY; float u = fX - nCellX; float v = fY - nCellY; float a = getVertexHeight(nCellX, nCellY); float b = getVertexHeight(nCellX+1, nCellY); float c = getVertexHeight(nCellX, nCellY+1); float d = getVertexHeight(nCellX+1, nCellY+1); return bilinearInterpolation(a,b,c,d,u,v); }
QRgb NwwMapImage::pixel( double const lonRad, double const latRad ) { double const x = lonRadToPixelX( lonRad ); double const y = latRadToPixelY( latRad ); switch ( m_interpolationMethod ) { case NearestNeighborInterpolation: return nearestNeighbor( x, y ); case BilinearInterpolation: return bilinearInterpolation( x, y ); default: return nearestNeighbor( x, y ); } }
template <typename PointInT, typename PointOutT, typename IntensityT> void pcl::BriskKeypoint2D<PointInT, PointOutT, IntensityT>::detectKeypoints (PointCloudOut &output) { // image size const int width = int (input_->width); const int height = int (input_->height); // destination for intensity data; will be forwarded to BRISK std::vector<unsigned char> image_data (width*height); for (size_t i = 0; i < image_data.size (); ++i) image_data[i] = static_cast<unsigned char> (intensity_ ((*input_)[i])); pcl::keypoints::brisk::ScaleSpace brisk_scale_space (octaves_); brisk_scale_space.constructPyramid (image_data, width, height); // Check if the template types are the same. If true, avoid a copy. // The PointOutT MUST be registered using the POINT_CLOUD_REGISTER_POINT_STRUCT macro! if (isSamePointType<PointOutT, pcl::PointWithScale> ()) brisk_scale_space.getKeypoints (threshold_, output.points); else { pcl::PointCloud<pcl::PointWithScale> output_temp; brisk_scale_space.getKeypoints (threshold_, output_temp.points); pcl::copyPointCloud<pcl::PointWithScale, PointOutT> (output_temp, output); } // we do not change the denseness output.width = int (output.points.size ()); output.height = 1; output.is_dense = false; // set to false to be sure // 2nd pass to remove the invalid set of 3D keypoints if (remove_invalid_3D_keypoints_) { PointCloudOut output_clean; for (size_t i = 0; i < output.size (); ++i) { PointOutT pt; // Interpolate its position in 3D, as the "u" and "v" are subpixel accurate bilinearInterpolation (input_, output[i].x, output[i].y, pt); // Check if the point is finite if (pcl::isFinite (pt)) output_clean.push_back (output[i]); } output = output_clean; output.is_dense = true; // set to true as there's no keypoint at an invalid XYZ } }
const vec3 FileTexture::getTexel(float s, float t, const vec2 &scale) const { s *= scale.s; t *= scale.t; float wrappedS; float wrappedT; if (s >= 0) wrappedS = s - (int)s; else wrappedS = 1 - (abs(s) - (int)abs(s)); if (t >= 0) wrappedT = t - (int)t; else wrappedT = 1 - (abs(t) - (int)abs(t)); //return getTexelFromFile(wrappedS*(width-1), wrappedT*(height-1)); return bilinearInterpolation(wrappedS, wrappedT); }
/* * This function does the caking. */ static PyObject * DiffractionAnalysisWrap_cake(PyObject *self, PyObject *args) { PyArrayObject *diffractionData; PyArrayObject *cake; // the dimensions of the caked data int dimensions[2]; double centerX,centerY,distance,energy,alpha,beta,rotation; double qOrTwoThetaLower,qOrTwoThetaUpper; int numQOrTwoTheta; double chiLower,chiUpper; int numChi; double pixelLength,pixelHeight; double cos_beta,sin_beta,cos_alpha,sin_alpha,cos_rotation,sin_rotation; double x,y; double q,chi; double qOrTwoTheta; int qOrTwoThetaBin,chiBin; double qOrTwoThetaStep,chiStep; double intensity; int doPolarizationCorrection; double P,twoTheta; int doGreaterThanMask; double greaterThanMask; int doLessThanMask; double lessThanMask; int doPolygonMask; PyArrayObject * polygonsX; PyArrayObject * polygonsY; PyArrayObject * polygonBeginningsIndex; PyArrayObject * polygonNumberOfItems; char *type; // get all of the parameters out of the python call PyArg_ParseTuple(args,"O!dddddddddiddiidididiO!O!O!O!dds",&PyArray_Type,&diffractionData, ¢erX,¢erY,&distance,&energy,&alpha,&beta,&rotation, &qOrTwoThetaLower,&qOrTwoThetaUpper,&numQOrTwoTheta, &chiLower,&chiUpper,&numChi, &doPolarizationCorrection,&P, &doGreaterThanMask,&greaterThanMask,&doLessThanMask,&lessThanMask, &doPolygonMask, &PyArray_Type,&polygonsX, &PyArray_Type,&polygonsY, &PyArray_Type,&polygonBeginningsIndex, &PyArray_Type,&polygonNumberOfItems, &pixelLength,&pixelHeight,&type); // the types of integration // Remeber, strcmp returns 0 when they equal if (strcmp(type,"Q") != 0 && strcmp(type,"2theta") != 0) { PyErr_SetString( PyExc_Exception, "The type of integration must be Q, or 2theta"); return 0; } // passed array has the diffraction data if (diffractionData->nd != 2 || diffractionData->descr->type_num != PyArray_INT) { PyErr_SetString(PyExc_ValueError, "diffractionData must be two-dimensional and of type integer"); return 0; } // create a new Numeric data structure to hold the cake dimensions[0]=numChi; dimensions[1]=numQOrTwoTheta; cake=(PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_DOUBLE); // calculate sin & cos for later use. cos_beta = cos(beta*PI/180.0); sin_beta = sin(beta*PI/180.0); cos_alpha = cos(alpha*PI/180.0); sin_alpha = sin(alpha*PI/180.0); cos_rotation = cos(rotation*PI/180.0); sin_rotation = sin(rotation*PI/180.0); // calulate the step size between different bins qOrTwoThetaStep = (qOrTwoThetaUpper-qOrTwoThetaLower)/(numQOrTwoTheta-1); chiStep = (chiUpper-chiLower)/(numChi-1); // for each bin for (qOrTwoThetaBin = 0; qOrTwoThetaBin < numQOrTwoTheta; qOrTwoThetaBin += 1) { for (chiBin = 0; chiBin < numChi; chiBin += 1) { // get into the middle of the cell qOrTwoTheta = qOrTwoThetaLower + qOrTwoThetaBin*qOrTwoThetaStep + qOrTwoThetaStep/2.0; chi = chiLower + chiBin*chiStep + chiStep/2.0; if (strcmp(type,"Q")==0) { q = qOrTwoTheta; } else { q = convertTwoThetaToQ(qOrTwoTheta,convertEnergyToWavelength(energy)); } getXY(centerX,centerY,distance,energy,q,chi, pixelLength,pixelHeight,rotation, cos_beta,sin_beta,cos_alpha,sin_alpha, cos_rotation,sin_rotation,&x,&y); // if the qOrTwoTheta,chi value is in the diffraction // image, then find the intensity. Note that there is // only diffraction data up to (dimension-1) if (x >= 0 && x <= (diffractionData->dimensions[0]-1) && y >= 0 && y <= (diffractionData->dimensions[1]-1)) { intensity = bilinearInterpolation(diffractionData, x, y); // possibly do the polarization correction if (doPolarizationCorrection) { twoTheta = convertQToTwoTheta(q, convertEnergyToWavelength(energy)); intensity = polarizationCorrection(intensity,P,twoTheta,chi); } // clip all intensity values to be at least 0. if (intensity < 0) intensity = 0; if (doPolygonMask && isInPolygons(polygonsX,polygonsY, polygonBeginningsIndex,polygonNumberOfItems,x,y)) { // if we are doing a polygon mask and our pixel is // in one of the polygons, then we should assign its // value to be -4 (by convention) *(double *)(cake->data + chiBin*cake->strides[0] + qOrTwoThetaBin*cake->strides[1]) = -4; } else if (doGreaterThanMask && intensity > greaterThanMask) { // if we are doing the greater than mask, if the // current pixel is greater then the threshold, // then we should assign its value to be -2 // (by convention). *(double *)(cake->data + chiBin*cake->strides[0] + qOrTwoThetaBin*cake->strides[1]) = -2; } else if (doLessThanMask && intensity < lessThanMask) { // if we are doing the lower than mask, if the // current pixel is less then the threshold, then // we should assign its value to be -3 (by convention) *(double *)(cake->data + chiBin*cake->strides[0] + qOrTwoThetaBin*cake->strides[1]) = -3; } else { *(double *)(cake->data + chiBin*cake->strides[0] + qOrTwoThetaBin*cake->strides[1]) = intensity; } } else { // otherwise, define outside the image as -1 intensity. *(double *)(cake->data + chiBin*cake->strides[0] + qOrTwoThetaBin*cake->strides[1]) = -1; } } } return Py_BuildValue("N",cake); }