bool Collision::foundSepAxis(Point& axis, BoundingQuad &boxA, BoundingQuad &boxB) { double boxAMin, boxBMin, boxAMax, boxBMax; getMinMax(axis, boxA, boxAMin, boxAMax); getMinMax(axis, boxB, boxBMin, boxBMax); if ((boxAMin > boxBMax) || (boxBMin > boxAMax)) { return true; } double d1 = boxAMax - boxBMin; double d2 = boxBMax - boxAMin; double depthTimesAxisLength = (d1 < d2) ? d1 : d2; double axisSqrLength = axis.getDotProd(&axis); //double axisLengthRecip = 1.0 / sqrt(axisSqrLength); //double d3 = depth * axisLengthRecip; //axis = Point(axis.pointX * axisLengthRecip * d3, axis.pointY * axisLengthRecip * d3); double axisSqrLengthRecip = 1.0 / axisSqrLength; axis = Point(axis.pointX * depthTimesAxisLength * axisSqrLengthRecip, axis.pointY * depthTimesAxisLength * axisSqrLengthRecip); return false; }
/*** * This will add the maximum spectrum number from ws1 to the data coming from ws2. * * @param ws1 The first workspace supplied to the algorithm. * @param ws2 The second workspace supplied to the algorithm. * @param output The workspace that is going to be returned by the algorithm. */ void ConjoinWorkspaces::fixSpectrumNumbers(API::MatrixWorkspace_const_sptr ws1, API::MatrixWorkspace_const_sptr /*ws2*/, API::MatrixWorkspace_sptr output) { // make sure we should bother. If you don't check for overlap, you don't need to if (this->getProperty("CheckOverlapping")) return; // is everything possibly ok? specid_t min; specid_t max; getMinMax(output, min, max); if (max - min >= static_cast<specid_t>(output->getNumberHistograms())) // nothing to do then return; // information for remapping the spectra numbers specid_t ws1min; specid_t ws1max; getMinMax(ws1, ws1min, ws1max); // change the axis by adding the maximum existing spectrum number to the current value for (size_t i = ws1->getNumberHistograms(); i < output->getNumberHistograms(); i++) { specid_t origid; origid = output->getSpectrum(i)->getSpectrumNo(); output->getSpectrum(i)->setSpectrumNo(origid + ws1max); } // To be deprecated: output->generateSpectraMap(); }
int main(const int argc, const char** argv) { if (argc != 2) LFATAL("USAGE: %s <image.pgm>", argv[0]); // let's start by trying out a single model: it starts with our // initial conditions and we give it a steady input of 255: SurpriseModelSP m(UPDFAC, INIVAL, VARIANCE); // the model SurpriseModelSP s(UPDFAC, 255.0f, VARIANCE); // the sample for (int i = 0; i < NITER; i ++) LINFO("iter = %d, mean = %f, stdev = %f, surprise = %f", i, m.getMean(), sqrt(m.getVar()), m.surprise(s)); // get the input feature map: Image<byte> input = Raster::ReadGray(argv[1]); // convert to double: Image<double> in(input); // create sample variances: Image<double> invar(input.getDims(), NO_INIT); invar.clear(VARIANCE); // create SurpriseImage from our samples and their variances: SurpriseImage<SurpriseModelSP> sample(UPDFAC, in, invar); // create an ImageCache to accumulate our results: ImageCacheMinMax<float> cache; // create a surprise map: SurpriseMap<SurpriseModelSP> smap; smap.init(QLEN, UPDFAC, NUPDFAC, INIVAL, VARIANCE, NEIGHSIGMA, LOCSIGMA); // let's do it! for (int i = 0; i < NITER; i ++) { // get the surprise: Image<float> surp = smap.surprise(sample); float mi, ma; getMinMax(surp, mi, ma); LINFO("Done %d/%d: [%f .. %f]", i+1, NITER, mi, ma); // cache it: cache.push_back(surp); } // ok, let's save the results. First find the global max: Image<float> imax = cache.getMax(); float mi, ma; getMinMax(imax, mi, ma); LINFO("Global max is %f", ma); for (int i = 0; i < NITER; i ++) { Image<byte> sav(cache.pop_front() * 255.0f / ma); Raster::WriteGray(sav, sformat("SURP%03d%s", i, argv[1])); } return 0; }
long getValue(long val){ long temp; long var = this->Curve1->getValue(val); long var2 = this->Curve2->getValue(val); if (var > var2) temp = getMinMax(var2, var); else if (var2 > var) temp = getMinMax(var, var2); else temp = var; return temp; }
void Triangle::setBoundingBox() { int maxX, minX, maxY, minY; std::vector<Point> coords; coords.push_back(a); coords.push_back(b); coords.push_back(c); maxX = getMinMax(coords, MAX_X); maxY = getMinMax(coords, MAX_Y); minX = getMinMax(coords, MIN_X); minY = getMinMax(coords, MIN_Y); setBbox(minX, minY, maxY - minY, maxX - minX); }
HullPoint* ConvexHullAlgorithm::combine(HullPoint* A, HullPoint* B) { HullPoint *rightA = getMinMax(A, 1); HullPoint *leftB = getMinMax(B, -1); HullPoint *a = rightA; HullPoint *b = leftB; while(true) { // Case 1 b = findTangent(a, b, B, 1, 1); // Case 4 if (isTangent(b, a, A, -1)) break; // Case 4 a = findTangent(b, a, A, -1, -1); // Case 1 if (isTangent(a, b, B, 1)) break; } HullPoint *upperA = a; HullPoint *upperB = b; a = rightA; b = leftB; while (true) { // Case 2 b = findTangent(a, b, B, -1, -1); // Case 3 if (isTangent(b, a, A, 1)) break; // Case 3 a = findTangent(b, a, A, 1, 1); // Case 2 if (isTangent(a, b, B, -1)) break; } HullPoint *lowerA = a; HullPoint *lowerB = b; upperA->next = upperB; upperB->prev = upperA; lowerA->prev = lowerB; lowerB->next = lowerA; //cout << "Upper tangent is : " << upperA->index <<" , " <<upperB->index<<endl; //cout << "Lower tangent is : " << lowerA->index <<" , " <<lowerB->index<<endl; return upperA; }
//compute bounding box void cData::computeCenterAndBBox(int idCloud) { QVector3D sum(0.,0.,0.); int cpt = 0; for (int bK=0; bK < _Clouds.size();++bK) { if(idCloud == -1 || bK == idCloud) { GlCloud * aCloud = _Clouds[bK]; sum = sum + aCloud->getSum(); cpt += aCloud->size(); for (int aK=0; aK < aCloud->size(); ++aK) { getMinMax(aCloud->getVertex(aK).getPosition()); } } } if(idCloud == -1) for (int cK=0; cK < _Cameras.size();++cK) { cCamHandler * aCam = _Cameras[cK]; QVector <QVector3D> vert; QVector3D c1, c2, c3, c4; aCam->getCoins(c1,c2,c3,c4,1.f); vert.push_back(aCam->getCenter()); vert.push_back(c1); vert.push_back(c2); vert.push_back(c3); vert.push_back(c4); for (int aK=0; aK < vert.size(); ++aK) { getMinMax(vert[aK]); } sum = sum + aCam->getCenter(); sum = sum + c1; sum = sum + c2; sum = sum + c3; sum = sum + c4; cpt += 5; } _centroid = sum / cpt; }
struct pair getMinMax(int arr[], int low, int high) { struct pair minmax, mml, mmr; int mid; /* IF THERE IS ONLY ON ELEMENT */ if (low == high) { minmax.max = arr[low]; minmax.min = arr[low]; return minmax; } /* IF THERE ARE TWO ELEMENTS */ if (high == low + 1) { if (arr[low] > arr[high]) { minmax.max = arr[low]; minmax.min = arr[high]; } else { minmax.max = arr[high]; minmax.min = arr[low]; } return minmax; } /* IF THERE ARE MORE THAN 2 ELEMENTS */ mid = (low + high)/2; mml = getMinMax(arr, low, mid); mmr = getMinMax(arr, mid+1, high); /* COMPARE MINIMUMS OF TWO PARTS*/ if (mml.min < mmr.min) minmax.min = mml.min; else minmax.min = mmr.min; /* COMPARE MAXIMUMS OF TWO PARTS*/ if (mml.max > mmr.max) minmax.max = mml.max; else minmax.max = mmr.max; return minmax; }
// ###################################################################### void TaskRelevanceMapGistClassify::integrate(SimEventQueue& q) { if (SeC<SimEventGistOutput> e = q.check<SimEventGistOutput>(this)) { if (itsMapComputedForCurrentFrame) return; //! to make the gist feature value in a reasonable range to get the // variance and determine value itsGist = e->gv() / 10.0F; gistmatch(reshape(itsGist, Dims(itsGist.getWidth() * itsGist.getHeight(), 1))); if (itsCacheSize.getVal() > 0) { itsTDMap.push_back(itsTmpTDMap); if (itsFrame % itsUpdatePeriod.getVal() ==0) itsCurrentTDMap = itsTDMap.mean(); } else itsCurrentTDMap = itsTmpTDMap; itsMap = rescale(itsCurrentTDMap, itsMap.getDims()); float mi, ma; getMinMax(itsMap, mi, ma); LINFO("\nFinal TRM range = [%.2f .. %.2f] -- 1.0 is baseline\n", mi, ma); itsMapComputedForCurrentFrame = true; } }
// ###################################################################### Image<float> TaskRelevanceMapGistClassify:: getTDMap(Image<float> gistDist) { std::string TDMapName; Image<float> TDMap; float coef = 0.0F; for(int i=1; i<= itsNumOfCategory; i++) { TDMapName = itsTemplateDir.getVal()+std::string("category") +convertToString(i)+std::string(".png"); Image<float> TDMapTmp = Raster::ReadGray(TDMapName); if(1==i) TDMap = TDMapTmp * gistDist.getVal(i-1,0); else TDMap += TDMapTmp * gistDist.getVal(i-1,0); coef += gistDist.getVal(i-1,0); } TDMap = (TDMap + 0.0001F) / (coef + 0.0001F); // consider that failure in classify then use the uniform template float mi, ma; getMinMax(TDMap, mi, ma); LINFO("\ncoef= %.6f TRM range = [%.2f .. %.2f] -- 1.0 is baseline\n", coef, mi, ma); return TDMap; }
void get_global_features(const pcl::PointCloud<PointT> &cloud, vector<float> &features, SpectralProfile & spectralProfileOfSegment) { Eigen::Vector4f min_p; Eigen::Vector4f max_p; // get bounding box features getSpectralProfile (cloud, spectralProfileOfSegment); getMinMax(cloud, min_p, max_p); float xExtent=max_p[0] - min_p[0]; float yExtent=max_p[1] - min_p[1]; float horizontalExtent=sqrt(xExtent*xExtent+yExtent*yExtent); float zExtent=max_p[2] - min_p[2]; features.push_back(horizontalExtent);addToNodeHeader ("horizontalExtent"); features.push_back(zExtent);addToNodeHeader ("zExtent"); features.push_back(spectralProfileOfSegment.centroid.z);addToNodeHeader ("centroid_z"); features.push_back (spectralProfileOfSegment.getNormalZComponent ());addToNodeHeader ("normal_z"); //spectral saliency features features.push_back ((spectralProfileOfSegment.getLinearNess ()));addToNodeHeader ("linearness"); features.push_back ((spectralProfileOfSegment.getPlanarNess ()));addToNodeHeader ("planarness"); features.push_back ((spectralProfileOfSegment.getScatter ()));addToNodeHeader ("scatter"); spectralProfileOfSegment.avgHOGFeatsOfSegment.pushBackAllFeats (features);addToNodeHeader ("HOG",31); }
// ###################################################################### void TaskRelevanceMapTigs::integrate(SimEventQueue& q) { if (SeC<SimEventGistOutput> e = q.check<SimEventGistOutput>(this)) { if (itsMapComputedForCurrentFrame) return; itsGist = e->gv(); itsTmpTDMap = getTDMap(itsGist); if (itsCacheSize.getVal() > 0) { itsTDMap.push_back(itsTmpTDMap); if (itsFrame % itsUpdatePeriod.getVal() ==0) itsCurrentTDMap = itsTDMap.mean(); } else itsCurrentTDMap = itsTmpTDMap; itsMap = rescale(itsCurrentTDMap, itsMap.getDims()); float mi, ma; getMinMax(itsMap, mi, ma); LINFO("\nFinal TRM range = [%.2f .. %.2f] -- 1.0 is baseline\n\n", mi, ma); itsMapComputedForCurrentFrame = true; } }
// ###################################################################### void TaskRelevanceMapKillN::integrate(SimEventQueue& q) { // anything from the ShapeEstimator? if (SeC<SimEventShapeEstimatorOutput> e = q.check<SimEventShapeEstimatorOutput>(this)) { // get the smooth object mask: Image<float> mask = e->smoothMask(); // downscale to our map's size: mask = downSize(mask, itsMap.getWidth(), itsMap.getHeight(), 5); // is the mask uniform (i.e., empty)? In this case, just push // it in, otherwise let's segment the objects out: float mi, ma; getMinMax(mask, mi, ma); if (fabs(mi - ma) < 1.0e-10) itsCache.push_back(mask); else { // let's build a distance map out of the object and threhold it: Image<float> dmap = chamfer34(mask, 255.0F); inplaceClamp(dmap, 0.0F, 15.0F); dmap /= 15.0F; // 0 inside obj, 1 outside // get this new input mask into our cache: itsCache.push_back(dmap); } // our current relevance map is the min over our cache: itsMap = itsCache.getMin(); } }
bool CheckCollision::checkForCollisions(BouncingSquare* shapeA,BouncingSquare* shapeB) { //if(shape.vec4 != NULL) //{ for(int i = 0; i<4; i++) { if(i == 0) { normVec1 = shapeA->vec1; normVec2 = shapeA->vec2; } if(i == 1) { normVec1 = shapeA->vec2; normVec2 = shapeA->vec3; } else if(i == 2) { normVec1 = shapeB->vec1; normVec2 = shapeB->vec2; } else if(i == 3) { normVec1 = shapeB->vec2; normVec2 = shapeB->vec3; } normalVec = getNormal(normVec1,normVec2); projectVecA1 = getProjVec(shapeA->vec1); projectVecA2 = getProjVec(shapeA->vec2); projectVecA3 = getProjVec(shapeA->vec3); projectVecA4 = getProjVec(shapeA->vec4); projectVecA1 += getProjVec(shapeA->centreVec); projectVecA2 += getProjVec(shapeA->centreVec); projectVecA3 += getProjVec(shapeA->centreVec); projectVecA4 += getProjVec(shapeA->centreVec); projectVecB1 = getProjVec(shapeB->vec1); projectVecB2 = getProjVec(shapeB->vec2); projectVecB3 = getProjVec(shapeB->vec3); projectVecB4 = getProjVec(shapeB->vec4); projectVecB1 += getProjVec(shapeB->centreVec); projectVecB2 += getProjVec(shapeB->centreVec); projectVecB3 += getProjVec(shapeB->centreVec); projectVecB4 += getProjVec(shapeB->centreVec); getMinMax(); if (maxVecA < minVecB || maxVecB < minVecA) { return false; } } return true; //} }
void DataConverter_i::pushDataService(std::vector<IN_TYPE, IN_TYPE_ALLOC> *data, OUT *output, bool EOS, BULKIO::PrecisionUTCTime tt, std::string streamID, bool sriChanged, BULKIO::StreamSRI& SRI, std::vector<OUT_TYPE, OUT_TYPE_ALLOC>* outputVec) { //if the output isn't hooked up - just quit now if (!output->isActive()) return; //std::cout<<"doing data for output "<<output->getName()<<std::endl; // Reconfigure if SRI Changed if (sriChanged || (output->getCurrentSRI().count(streamID)==0)) { output->pushSRI(SRI); } //Check if we need to scale the output OUT_TYPE outMax; OUT_TYPE outMin; if (isEnabled(&outMin, &outMax)) { IN_TYPE inMax; IN_TYPE inMin; //if we are scaling get the input min/max getMinMax(&inMin,&inMax); convert(data,outputVec,inMax,inMin,outMax,outMin); } else //just cast the data with no scaling cast(data, outputVec); //push the output and done output->pushPacket(*outputVec, tt, EOS, streamID); }
TerrainModel::TerrainModel(string heightMap) { vector<VertexData> vertices; vector<unsigned int> indices; VertexData v; SDL_Surface* image = utl::loadRawImage(heightMap); int vertexCount = image->h; m_heights.resize(vertexCount, vector<float>(vertexCount, 0)); m_gridSquareSize = DEFAULT_SIZE / ((float)vertexCount - 1); m_sideVertexCount = vertexCount; int maxGray, minGray; getMinMax(image, &maxGray, &minGray); for (int z = 0; z < vertexCount; z++) { for (int x = 0; x < vertexCount; x++) { VertexData v; v.m_position.x = (float)x / ((float)vertexCount - 1) * DEFAULT_SIZE; float height = getHeight(x, z, image, maxGray, minGray); m_heights[z][x] = height; v.m_position.y = height; v.m_position.z = (float)z / ((float)vertexCount - 1) * DEFAULT_SIZE; // http://stackoverflow.com/questions/13983189/opengl-how-to-calculate-normals-in-a-terrain-height-grid v.m_normal = computeNormal(x, z, image, maxGray, minGray); v.m_UV.x = (float)x / ((float)vertexCount - 1); v.m_UV.y = (float)z / ((float)vertexCount - 1); vertices.push_back(v); } } for (int gz = 0; gz < vertexCount - 1; gz++) { for (int gx = 0; gx < vertexCount - 1; gx++) { int topLeft = (gz * vertexCount) + gx; int topRight = topLeft + 1; int bottomLeft = ((gz + 1) * vertexCount) + gx; int bottomRight = bottomLeft + 1; indices.push_back(topLeft); indices.push_back(bottomLeft); indices.push_back(topRight); indices.push_back(topRight); indices.push_back(bottomLeft); indices.push_back(bottomRight); } } Mesh m(vertices, indices); m_meshes.push_back(m); }
void utilsTest02(){ Point a = Point(10, 22); Point b = Point(-12, 11); Point d = Point(-1, -6); Point c = Point(0, -4); std::vector<Point> coords; coords.push_back(a); coords.push_back(b); coords.push_back(c); coords.push_back(d); ASSERT_EQUAL(10,getMinMax(coords, MAX_X)); ASSERT_EQUAL(22,getMinMax(coords, MAX_Y)); ASSERT_EQUAL(-12,getMinMax(coords, MIN_X)); ASSERT_EQUAL(-6,getMinMax(coords, MIN_Y)); }
void INDI::CCD::addFITSKeywords(fitsfile *fptr, CCDChip *targetChip) { int status=0; char frame_s[32]; char dev_name[32]; char exp_start[32]; double min_val, max_val; double exposureDuration; double pixSize1,pixSize2; unsigned int xbin, ybin; getMinMax(&min_val, &max_val, targetChip); xbin = targetChip->getBinX(); ybin = targetChip->getBinY(); switch (targetChip->getFrameType()) { case CCDChip::LIGHT_FRAME: strcpy(frame_s, "Light"); break; case CCDChip::BIAS_FRAME: strcpy(frame_s, "Bias"); break; case CCDChip::FLAT_FRAME: strcpy(frame_s, "Flat Field"); break; case CCDChip::DARK_FRAME: strcpy(frame_s, "Dark"); break; } exposureDuration = targetChip->getExposureDuration(); pixSize1 = targetChip->getPixelSizeX(); pixSize2 = targetChip->getPixelSizeY(); strncpy(dev_name, getDeviceName(), 32); strncpy(exp_start, targetChip->getExposureStartTime(), 32); fits_update_key_s(fptr, TDOUBLE, "EXPTIME", &(exposureDuration), "Total Exposure Time (s)", &status); if(targetChip->getFrameType() == CCDChip::DARK_FRAME) fits_update_key_s(fptr, TDOUBLE, "DARKTIME", &(exposureDuration), "Total Exposure Time (s)", &status); fits_update_key_s(fptr, TDOUBLE, "PIXSIZE1", &(pixSize1), "Pixel Size 1 (microns)", &status); fits_update_key_s(fptr, TDOUBLE, "PIXSIZE2", &(pixSize2), "Pixel Size 2 (microns)", &status); fits_update_key_s(fptr, TUINT, "XBINNING", &(xbin) , "Binning factor in width", &status); fits_update_key_s(fptr, TUINT, "YBINNING", &(ybin), "Binning factor in height", &status); fits_update_key_s(fptr, TSTRING, "FRAME", frame_s, "Frame Type", &status); fits_update_key_s(fptr, TDOUBLE, "DATAMIN", &min_val, "Minimum value", &status); fits_update_key_s(fptr, TDOUBLE, "DATAMAX", &max_val, "Maximum value", &status); fits_update_key_s(fptr, TSTRING, "INSTRUME", dev_name, "CCD Name", &status); fits_update_key_s(fptr, TSTRING, "DATE-OBS", exp_start, "UTC start date of observation", &status); //fits_write_date(fptr, &status); }
// ###################################################################### void ContourBoundaryDetector::displayGradImage (std::vector<Image<float> > gradImg) { Image<float> gradImgX = gradImg[0]; Image<float> gradImgY = gradImg[1]; uint w = gradImgX.getWidth(); uint h = gradImgX.getHeight(); Image<PixRGB<byte> > dGradImg(w, h, NO_INIT); float mn, mx; Image<float> temp = gradImgX*gradImgX + gradImgY*gradImgY; getMinMax(temp, mn,mx); float max = pow(mx,.5); for(uint i = 0; i < w; i++) { for(uint j = 0; j < h; j++) { float x = gradImgX.getVal(i,j); float y = gradImgY.getVal(i,j); float dir = atan2(y,x) * 180.0 / M_PI; if(dir < 0.0) dir = 360.0 + dir; float mag = pow(x*x + y*y, 0.5); // PixHSV<byte> hsvp(byte(dir/360.0 * 255.0), // 100, // byte(max/max* 255.0)); PixHSV<byte> hsvp(180,100,50); //PixRGB<byte> rgbp(hsvp); byte m = byte(mag/max * 255.0); //byte d = byte(dir/360.0 * 255.0); PixRGB<byte> rgbp(m, m, m); dGradImg.setVal(i,j, rgbp); // PixRGB<byte> a(0,255,255); // PixHSV<byte> b(a); // PixRGB<byte> c(b); // LINFO("%d %d %d ==> %d %d %d ==> %d %d %d", // a.red(), a.green(), a.blue(), // b.H(), b.S(), b.V(), // c.red(), c.green(), c.blue()); // Raster::waitForKey(); // LINFO("%f %f || %f %f (%f): %d %d %d ==> %d %d %d", // x,y, dir, mag, mag/max* 255.0, // hsvp.H(), hsvp.S(), hsvp.V(), // rgbp.red(), rgbp.green(), rgbp.blue()); } } itsWin->drawImage(dGradImg, 0,0); Raster::waitForKey(); }
void autotrim(boost::shared_ptr<pcl::PointCloud<PointT>> &cloud, double &clip_N, double &clip_S, double &clip_E, double &clip_W, double tolerance) { struct bound_box bbox; getMinMax(*cloud, bbox); double resolution = 0.003; int length_x = (int)((bbox.E - bbox.W) / resolution + 0.5); int length_y = (int)((bbox.N - bbox.S) / resolution + 0.5); std::vector<int> x_array(length_x, 0); std::vector<int> y_array(length_y, 0); unsigned int idx; for(typename pcl::PointCloud<PointT>::iterator it = cloud->begin(); it!= cloud->end(); it++){ idx = int((it->x - bbox.W) / resolution); if (idx < x_array.size()) x_array[idx] += 1; idx = int((it->y - bbox.S) / resolution); if (idx < y_array.size()) y_array[idx] += 1; } int median_x = median(x_array); int median_y = median(y_array); clip_N = 0; clip_S = 0; clip_E = 0; clip_W = 0; for (int i = 0; i < x_array.size(); i++) { if (x_array[i] < tolerance * median_x) { clip_W = (i + 1) * resolution; } else break; } for (int i = x_array.size() - 1; i >= 0; i--) { if (x_array[i] < tolerance * median_x) { clip_E = (x_array.size() - i) * resolution; } else break; } for (int i = 0; i < y_array.size(); i++) { if (y_array[i] < tolerance * median_y) { clip_S = (i + 1) * resolution; } else break; } for (int i = y_array.size() - 1; i >= 0; i--) { if (y_array[i] < tolerance * median_y) { clip_N = (y_array.size() - i) * resolution; } else break; } //std::cout << clip_N << " " << clip_S << " " << clip_E << " " << clip_W << std::endl; }
/* DRIVER PROGRAM TO TEST ABOVE FUNCTION */ int main() { int arr[] = {1000, 11, 445, 1, 330, 3000}; int arr_size = 6; struct pair minmax = getMinMax (arr, arr_size); printf("\nMinimum element is %d", minmax.min); printf("\nMaximum element is %d", minmax.max); getchar(); }
int main(int argc, char **argv) { short numbers[] = { 7, 4, 1, 5, 9, 4 }; short * minMax = getMinMax(numbers, 5); printf("Minimum: %d\nMaximum: %d", minMax[0], minMax[1]); free(minMax); // Speicher freigeben. Nicht vergessen! return EXIT_SUCCESS; }
// getNext(x, 0) = getPre, getNext(x, 1) = getSucc Node* getNext(Node *x, int suc) { if (x->son[suc] != NIL) return getMinMax(x->son[suc], suc ^ 1); Node *y = x->par; while (y != NIL && x == y->son[suc]) { x = y; y = x->par; } return y; }
bool BezierCalc::boundingBoxesIntersects(QList<QPointF>& bezier1, QList<QPointF>& bezier2) { QPointF bezier1Min; QPointF bezier1Max; QPointF bezier2Min; QPointF bezier2Max; getMinMax(bezier1, bezier1Min, bezier1Max); getMinMax(bezier2, bezier2Min, bezier2Max); if (bezier1Min.x() < bezier2Max.x() && bezier1Max.x() > bezier2Min.x() && bezier1Min.y() < bezier2Max.y() && bezier1Max.y() > bezier2Min.y()) { return true; } return false; }
glm::vec3 ColliderManager::getPOCin1D(Collider3D A, Collider3D B, glm::vec3 n) { n = glm::normalize(n); float min1, min2, max1, max2, o; glm::vec3 POC; getMinMax(n, A, min1, max1); getMinMax(n, B, min2, max2); o = overlap(min1, max1, min2, max2); if (min1 < min2) { POC = n * (min2 + (o / 2.0f)); } else POC = n * (min1 + (o / 2.0f)); return POC; }
void TreeNode::place( TreeCoord& sibOff ) //--------------------------------------- { bool vert = (_parent->getDirection() == TreeVertical ); if( _flags.placed == Placed ) { sibOff += (vert) ? _descend.w() : _descend.h(); return; } if( !readyToPlace() ) { return; } _flags.placed = Placed; TreeCoord maxSibW = _sibWidth; TreeCoord minSib = (vert) ? _descend.x() : _descend.y(); TreeCoord maxSib = sibOff; sibOff = maxCoord( sibOff, minSib ); getMinMax( minSib, maxSib ); maxSibW = maxCoord( maxSibW, maxSib - maxCoord( minSib, sibOff ) ); TreeCoord oldMaxSibW = maxSibW; getFirstNonContend( sibOff, maxSibW ); (vert) ? _descend.x( maxCoord( _descend.x(), sibOff ) ) : _descend.y( maxCoord( _descend.y(), sibOff ) ); TreeCoord x; TreeCoord y; TreeCoord tryW; if( sibOff > minSib || oldMaxSibW > maxSibW ) { x = _descend.x() + maxSibW / 2 - _bounding.w() / 2; y = _descend.y() + maxSibW / 2 - _bounding.h() / 2; tryW = ( vert ? _descend.x() : _descend.y() ) + maxSibW; } else { x = minSib + maxSibW / 2 - _bounding.w() / 2; y = minSib + maxSibW / 2 - _bounding.h() / 2; tryW = minSib + maxSibW; } (vert) ? _descend.w( maxCoord( _descend.w(), tryW - _descend.x() ) ) : _descend.h( maxCoord( _descend.h(), tryW - _descend.y() ) ); move( x, y ); sibOff += maxSibW; _descend.w( maxCoord( _descend.w(), _bounding.x() + _bounding.w() - _descend.x() ) ); _descend.h( maxCoord( _descend.h(), _bounding.y() + _bounding.h() - _descend.y() ) ); }
void QDiagramWidget::build() { double xMin, xMax, CurveMainMin, CurveMainMax, CurveSecondaryMin, CurveSecondaryMax; // clear old values clear(); // get start time of track const GPX_wptType *trkpt = gpxmw->getPoint(gpxmw->getSelectedTrackNumber(), 0, 0); if (trkpt) startTimestamp = gpxmw->getTrackPointPropertyAsDouble(trkpt, GPX_wrapper::timestamp); else startTimestamp = 0; // generate new values gpxmw->generateDiagramValues(gpxmw->getSelectedTrackNumber(), gpxmw->getSelectedTrackSegmentNumber(), curveMain, curveSecondary); // get range getMinMax(gpxmw->getTimeValues(), xMin, xMax); getMinMax(gpxmw->getCurveMainValues(), CurveMainMin, CurveMainMax); getMinMax(gpxmw->getCurveSecondaryValues(), CurveSecondaryMin, CurveSecondaryMax); // set new values xAxis->setRange(xMin, xMax); yAxis->setLabel(gpxmw->getTrackPointPropertyLabel(curveMain)); yAxis->setRange(CurveMainMin, CurveMainMax); yAxis2->setLabel(gpxmw->getTrackPointPropertyLabel(curveSecondary)); yAxis2->setRange(CurveSecondaryMin, CurveSecondaryMax); graph(1)->setData(gpxmw->getTimeValues(), gpxmw->getCurveMainValues()); graph(0)->setData(gpxmw->getTimeValues(), gpxmw->getCurveSecondaryValues()); yAxis->setVisible((curveMain == GPX_wrapper::none) ? false : true); yAxis2->setVisible((curveSecondary == GPX_wrapper::none) ? false : true); // update extensions updateExt(); // replot replot(); }
/*** * This will ensure the spectrum numbers do not overlap by starting the second *on at the first + 1 * * @param ws1 The first workspace supplied to the algorithm. * @param ws2 The second workspace supplied to the algorithm. * @param output The workspace that is going to be returned by the algorithm. */ void ConjoinWorkspaces::fixSpectrumNumbers(API::MatrixWorkspace_const_sptr ws1, API::MatrixWorkspace_const_sptr ws2, API::MatrixWorkspace_sptr output) { bool needsFix(false); if (this->getProperty("CheckOverlapping")) { // If CheckOverlapping is required, then either skip fixing spectrum number // or get stopped by an exception if (!m_overlapChecked) checkForOverlap(ws1, ws2, true); needsFix = false; } else { // It will be determined later whether spectrum number needs to be fixed. needsFix = true; } if (!needsFix) return; // is everything possibly ok? specid_t min; specid_t max; getMinMax(output, min, max); if (max - min >= static_cast<specid_t>( output->getNumberHistograms())) // nothing to do then return; // information for remapping the spectra numbers specid_t ws1min; specid_t ws1max; getMinMax(ws1, ws1min, ws1max); // change the axis by adding the maximum existing spectrum number to the // current value for (size_t i = ws1->getNumberHistograms(); i < output->getNumberHistograms(); i++) { specid_t origid; origid = output->getSpectrum(i)->getSpectrumNo(); output->getSpectrum(i)->setSpectrumNo(origid + ws1max); } }
// ###################################################################### void TaskRelevanceMapKillStatic::inputFrame(const InputFrame& f) { // NOTE: we are guaranteed that itsMap is initialized and of correct // size, as this is done by the TaskRelevanceMapAdapter before // calling us. // NOTE: this is duplicating some of the computation done in the // IntensityChannel, so there is a tiny performance hit (~0.25%) in // doing this operation twice; however the benefit is that we avoid // having to somehow pick information out of an IntensityChannel and // pass it to a TaskRelevanceMap -- that was making for a mess in // Brain. In the future, we could avoid the ineffiency by caching // the intensity pyramid in the InputFrame object, and then letting // IntensityChannel and TaskRelevanceMap both share access to that // pyramid. const Image<float> img = downSize(f.grayFloat(), itsMap.getWidth(), itsMap.getHeight(), 5); // is this our first time here? if (itsStaticBuff.initialized() == false) { itsStaticBuff = img; return; } // otherwise derive TRM from difference between current frame and // staticBuf: Image<float> diff = absDiff(itsStaticBuff, img); // useful range of diff is 0..255; anything giving an output less // that itsKillStaticThresh will be considered static; here let's // clamp to isolate that: inplaceClamp(diff, 0.0F, itsKillStaticThresh.getVal()); // the more static, the greater the killing: so, first let's change // the range so that the min is at -itsKillStaticThresh and zero is // neutral: diff -= itsKillStaticThresh.getVal(); // itsKillStaticCoeff determines how strong the killing should be: diff *= (1.0F / itsKillStaticThresh.getVal()) * // normalize to min at -1.0 itsKillStaticCoeff.getVal(); // apply coeff // mix our new TRM to the old one; we want to have a fairly high // mixing coeff for the new one so that we don't penalize recent // onset objects too much (i.e., were previously static and killed, // but are not anymore): itsMap = itsMap * 0.25F + (diff + 1.0F) * 0.75F; float mi, ma; getMinMax(itsMap, mi, ma); LINFO("TRM range = [%.2f .. %.2f] -- 1.0 is baseline", mi, ma); // update our cumulative buffer: itsStaticBuff = itsStaticBuff * 0.75F + img * 0.25F; }
int main(int argc, char const* argv[]) { int i=0, *min, *max, arr[10]; do { printf("%d番目の数です\n", i); scanf("%d", &arr[i]); i++; } while(arr[i - 1] != -1 && i < 10); getMinMax(min, max, arr); printf("min: %d\n", *min); printf("max: %d\n", *max); return 0; }