int main() { static int x[1024], y[1024], nr, nc, no, t; static hull_t r, c; char *s; int i; for (t = 1; scanf("%d %d %d", &nc, &nr, &no) == 3; t++) { if (nc == 0 && nr == 0 && no == 0) break; for (i = 0; i < nc && scanf("%d %d", &x[i], &y[i]) == 2; i++); hull(&c, x, y, nc); for (i = 0; i < nr && scanf("%d %d", &x[i], &y[i]) == 2; i++); hull(&r, x, y, nr); printf("Data set %d:\n", t); while (no-- > 0 && scanf("%d %d", &x[0], &y[0]) == 2) { if (inside(&c, x[0], y[0])) s = "safe"; else if (inside(&r, x[0], y[0])) s = "robbed"; else s = "neither"; printf(" Citizen at (%d,%d) is %s.\n", x[0], y[0], s); } printf("\n"); } return 0; }
void interval_set_mixed_assign_4_ordered_types() { typedef interval_set<T> IntervalSetT; typedef typename IntervalSetT::interval_type IntervalT; T v0 = boost::icl::identity_element<T>::value(); T v1 = unit_element<T>::value(); split_interval_set<T> split_set; separate_interval_set<T> sep_set; interval_set<T> join_set; split_set.add(v0); sep_set = split_set; join_set = sep_set; BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(sep_set).lower() ); BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(join_set).lower() ); split_interval_set<T> split_self = split_interval_set<T>().add(v0); separate_interval_set<T> sep_self = separate_interval_set<T>().add(v0).add(v1); interval_set<T> join_self = interval_set<T>().add(v1); split_self = split_self; sep_self = sep_self; join_self = join_self; BOOST_CHECK_EQUAL( split_self, split_self ); BOOST_CHECK_EQUAL( sep_self, sep_self ); BOOST_CHECK_EQUAL( join_self, join_self ); }
void interval_set_mixed_ctor_4_ordered_types() { typedef interval_set<T> IntervalSetT; typedef typename IntervalSetT::interval_type IntervalT; T v0 = boost::icl::identity_element<T>::value(); split_interval_set<T> split_set(v0); separate_interval_set<T> sep_set(split_set); interval_set<T> join_set(sep_set); BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(sep_set).lower() ); BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(join_set).lower() ); }
void interval_set_ctor_4_bicremental_types() { typedef IntervalSet<T> IntervalSetT; typedef typename IntervalSetT::interval_type IntervalT; T v4 = make<T>(4); IntervalT I4_4I(v4); IntervalSet<T> _I4_4I; BOOST_CHECK_EQUAL( _I4_4I.empty(), true ); IntervalSet<T> _I4_4I_1; IntervalSet<T> _I4_4I_2; IntervalSet<T> _I4_4I_3; _I4_4I += v4; _I4_4I_1 += I4_4I; BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_1 ); _I4_4I_2.add(v4); BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_2 ); _I4_4I_3.add(I4_4I); BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_3 ); _I4_4I_1.add(v4).add(I4_4I); BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_1 ); _I4_4I_1.insert(v4).insert(I4_4I); BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_1 ); (_I4_4I_1 += v4) += I4_4I; BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_1 ); BOOST_CHECK_EQUAL( cardinality(_I4_4I), unit_element<typename IntervalSet<T>::size_type>::value() ); BOOST_CHECK_EQUAL( _I4_4I.size(), unit_element<typename IntervalSet<T>::size_type>::value() ); BOOST_CHECK_EQUAL( interval_count(_I4_4I), 1 ); BOOST_CHECK_EQUAL( _I4_4I.iterative_size(), 1 ); BOOST_CHECK_EQUAL( iterative_size(_I4_4I), 1 ); BOOST_CHECK_EQUAL( hull(_I4_4I).lower(), v4 ); BOOST_CHECK_EQUAL( hull(_I4_4I).upper(), v4 ); IntervalSet<T> _I4_4I_copy(_I4_4I); IntervalSet<T> _I4_4I_assigned; _I4_4I_assigned = _I4_4I; BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_copy ); BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_assigned ); _I4_4I_assigned.clear(); BOOST_CHECK_EQUAL( true, _I4_4I_assigned.empty() ); _I4_4I_assigned.swap(_I4_4I_copy); BOOST_CHECK_EQUAL( true, _I4_4I_copy.empty() ); BOOST_CHECK_EQUAL( _I4_4I, _I4_4I_assigned ); }
// Returns a list of points on the convex hull in counter-clockwise order. // Note: the last point in the returned list is the same as the first one. std::vector<int> convex_hull(std::vector<int> idxs, std::function<Eigen::Vector2f(int)> & getPoint){ int n = idxs.size(), k = 0; std::vector<int> hull(2*n); // Sort points lexicographically sort(idxs.begin(), idxs.end(), [&getPoint](int a_, int b_){ Eigen::Vector2f a = getPoint(a_); Eigen::Vector2f b = getPoint(b_); return a.x() < b.x() || (a.x() == b.x() && a.y() < b.y()); }); // Build lower hull for (int i = 0; i < n; ++i) { while (k >= 2 && cross(getPoint(hull[k-2]), getPoint(hull[k-1]), getPoint(idxs[i])) <= 0) k--; hull[k++] = idxs[i]; } // Build upper hull for (int i = n-2, t = k+1; i >= 0; i--) { while (k >= t && cross(getPoint(hull[k-2]), getPoint(hull[k-1]), getPoint(idxs[i])) <= 0) k--; hull[k++] = idxs[i]; } hull.resize(k); return hull; }
void Noun::calculateWorld() const { BaseNode * pBaseNode = parent(); m_vWorldVelocity = m_vVelocity; if ( WidgetCast<Noun>( pBaseNode ) ) { Noun * pParent = (Noun *)pBaseNode; Vector3 vTranslate( pParent->worldFrame() % position() ); m_nWorldTick = m_Tick; m_WorldPosition = pParent->worldPosition() + vTranslate; m_WorldFrame = pParent->worldFrame() % frame(); m_vWorldVelocity += pParent->worldVelocity(); m_vZonePosition = pParent->zonePosition() + position(); } else { m_nWorldTick = m_Tick; m_WorldPosition = NodeTransform::worldPosition( (BaseNode *)this ); m_WorldFrame = NodeTransform::worldFrame( (BaseNode *)this ); m_vZonePosition = position(); } m_WorldHull.setBox( hull(), m_WorldFrame, m_WorldPosition ); }
Polygon convexHull(const Polygon& pol) { if (pol.size() <= 3) return pol; std::vector<Point> points = pol.get_points(); // Find leftmost point size_t p0 = 0; for (size_t i = 1; i < points.size(); ++i) { if (points[i].y < points[p0].y || (points[i].y == points[p0].y && points[i].x < points[p0].x)) p0 = i; } std::swap(points[0], points[p0]); std::sort(++points.begin(), points.end(), CCWSort(points[0])); std::vector<Point> hull(points.size()); hull.resize(points.size()); hull[0]= points[0]; hull[1] = points[1]; hull[2] = points[2]; int hi = 3; for (size_t i = 3; i < points.size(); ++i) { const Point& p = points[i]; for (; hi >= 2 && !ccw(hull[hi-2], hull[hi-1], p); hi--); hull[hi++] = p; } hull.resize(hi); return Polygon(hull); }
int main(int argc, char *argv[]) { // Create the world Enki::World world(200, 200); // Create a Khepera and position it Enki::EPuck *ePuck = new Enki::EPuck; ePuck->pos = Enki::Point(100, 100); ePuck->leftSpeed = 30; ePuck->rightSpeed = 20; // objects are garbage collected by the world on destruction world.addObject(ePuck); Enki::Polygone p; const double amount = 9; const double radius = 5; const double height = 20; for (double a = 0; a < 2*M_PI; a += 2*M_PI/amount) p.push_back(Enki::Point(radius * cos(a), radius * sin(a))); Enki::PhysicalObject* o = new Enki::PhysicalObject; Enki::PhysicalObject::Hull hull(Enki::PhysicalObject::Part(p, height)); o->setCustomHull(hull, 1); o->pos = Enki::Point(100, 100); o->setColor(Enki::Color(0.4,0.6,0.8)); world.addObject(o); // Run for some times for (unsigned i=0; i<10; i++) { // step of 50 ms world.step(0.05); std::cout << "E-puck pos is (" << ePuck->pos.x << "," << ePuck->pos.y << ")" << std::endl; } }
int main(int argc, char **argv){ if (argc < 2){ printf("Error: Debe especificar un archivo .pcd\n"); exit(1); } // Cargar nube de puntos PointCloud::Ptr cloud (new PointCloud), cloud_filt (new PointCloud); pcl::io::loadPCDFile(argv[1],*cloud); // Crear filtro. Remueve todos los puntos que se salen del campo especificado. // En este caso, quita puntos tales que "z" está fuera de [0,1.1]. // Se puede setear como filtro inverso con pass.setFilterLimitsNegative (true); /* pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud(cloud); pass.setFilterFieldName("z"); pass.setFilterLimits(0, 5); pass.setFilterLimitsNegative (true); pass.filter (*cloud_filt);*/ // Crear convex hull alrededor den nube PointCloud::Ptr hull(new PointCloud); pcl::ConcaveHull<pcl::PointXYZ> chull; chull.setInputCloud(cloud); chull.setAlpha(0.1); chull.reconstruct(*hull); // Crear visualizador boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = simpleVis(hull); while (!viewer->wasStopped()){ viewer->spinOnce(100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); } }
ExecStatus Pow<A,B>::propagate(Space& home, const ModEventDelta&) { if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED; GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),m_n))); if ((x1.min() == 0.0) && (x1.max() == 0.0)) { GECODE_ME_CHECK(x1.eq(home,0.0)); return home.ES_SUBSUMED(*this); } if ((m_n % 2) == 0) { if (x0.min() >= 0) GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n))); else if (x0.max() <= 0) GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),m_n))); else GECODE_ME_CHECK(x0.eq(home, hull( nroot(x1.domain(),m_n), -nroot(x1.domain(),m_n) ) )); } else GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n))); return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX; }
ExecStatus Pow<A,B>::post(Home home, A x0, B x1, int n) { if (n == 0) { if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED; GECODE_ME_CHECK(x1.eq(home,1.0)); return ES_OK; } GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),n))); if ((x1.min() == 0.0) && (x1.max() == 0.0)) { GECODE_ME_CHECK(x1.eq(home,0.0)); return ES_OK; } if ((n % 2) == 0) { if (x0.min() >= 0) GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n))); else if (x0.max() <= 0) GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),n))); else GECODE_ME_CHECK(x0.eq(home, hull( nroot(x1.domain(),n), -nroot(x1.domain(),n) ) )); } else GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n))); if (!x0.assigned()) (void) new (home) Pow<A,B>(home,x0,x1,n); return ES_OK; }
Polygon Polygon::convexHull(Polygon& polygon1, Polygon& polygon2) { std::vector<Position> vertices; vertices.reserve(polygon1.nVertices() + polygon2.nVertices()); vertices.insert(vertices.end(), polygon1.getVertices().begin(), polygon1.getVertices().end()); vertices.insert(vertices.end(), polygon2.getVertices().begin(), polygon2.getVertices().end()); std::vector<Position> hull(vertices.size()+1); // Sort points lexicographically. std::sort(vertices.begin(), vertices.end(), sortVertices); int k = 0; // Build lower hull for (int i = 0; i < vertices.size(); ++i) { while (k >= 2 && computeCrossProduct2D(hull.at(k - 1) - hull.at(k - 2), vertices.at(i) - hull.at(k - 2)) <= 0) k--; hull.at(k++) = vertices.at(i); } // Build upper hull. for (int i = vertices.size() - 2, t = k + 1; i >= 0; i--) { while (k >= t && computeCrossProduct2D(hull.at(k - 1) - hull.at(k - 2), vertices.at(i) - hull.at(k - 2)) <= 0) k--; hull.at(k++) = vertices.at(i); } hull.resize(k - 1); Polygon polygon(hull); return polygon; }
std::vector<FloatCoord<2> > convexHull(std::vector<FloatCoord<2> > *points) { std::size_t k = 0; std::vector<FloatCoord<2> > points_sorted = *points; std::vector<FloatCoord<2> > hull(2 * points_sorted.size()); std::sort(points_sorted.begin(), points_sorted.end(), floatCoordCompare); std::size_t n = points_sorted.size(); for (std::size_t i = 0; i < n; ++i) { while ((k >= 2) && cross(hull[k-2], hull[k-1], points_sorted[i]) <= 0) { --k; } hull[k++] = points_sorted[i]; } std::size_t t = k + 1; for (long i = n - 2; i >= 0; --i) { while ((k >= t) && cross(hull[k-2], hull[k-1], points_sorted[i]) <= 0) { --k; } hull[k++] = points_sorted[i]; } hull.resize(k); return hull; }
//---------------------------------------------------------------------------- void ExtremalQuery::CreateConvexPolyhedron (int numVertices) { // Create the convex hull of a randomly generated set of points on the // unit sphere. Vector3f* vertices = new1<Vector3f>(numVertices); int i, j; for (i = 0; i < numVertices; ++i) { for (j = 0; j < 3; ++j) { vertices[i][j] = Mathf::SymmetricRandom(); } vertices[i].Normalize(); } ConvexHull3f hull(numVertices, vertices, 0.001f, false, Query::QT_INT64); assertion(hull.GetDimension() == 3, "Invalid polyhedron.\n"); int numIndices = 3*hull.GetNumSimplices(); int* indices = new1<int>(numIndices); memcpy(indices, hull.GetIndices(), numIndices*sizeof(int)); mConvexPolyhedron = new0 ConvexPolyhedron3f(numVertices, vertices, numIndices/3, indices, 0); #ifdef USE_BSP_QUERY mExtremalQuery = new0 ExtremalQuery3BSPf(mConvexPolyhedron); #else mExtremalQuery = new0 ExtremalQuery3PRJf(mConvexPolyhedron); #endif #ifdef MEASURE_TIMING_OF_QUERY // For timing purposes and determination of asymptotic order. const int imax = 10000000; Vector3f* directions = new1<Vector3f>(imax); for (i = 0; i < imax; ++i) { for (j = 0; j < 3; ++j) { directions[i][j] = Mathf::SymmetricRandom(); } directions[i].Normalize(); } clock_t start = clock(); for (i = 0; i < imax; ++i) { int pos, neg; mExtremalQuery->GetExtremeVertices(directions[i], pos, neg); } clock_t final = clock(); long diff = final - start; double time = ((double)diff)/(double)CLOCKS_PER_SEC; std::ofstream outFile("timing.txt"); outFile << "time = " << time << " seconds" << std::endl; outFile.close(); delete1(directions); #endif }
bool BaseNode::intersect( const Matrix33 &frame, const Vector3 & position, IntersectContext & context ) { // rotate and transform the bounding box, it is still axis-aligned BoxHull tHull( hull(), frame, position ); // test for intersection with the bounding box return ( tHull.intersect( context.origin, context.ray, context.intersect ) ); }
bool Esbot:: Initialize(npm::RobotServer &server) { if ( !npm::RobotClient::Initialize(server)) return false; m_cheat = server.CreateCheatSheet(); shared_ptr<Hull> hull(CreateHull()); for(HullIterator ih(*hull); ih.IsValid(); ih.Increment()) server.AddLine(Line(ih.GetX0(), ih.GetY0(), ih.GetX1(), ih.GetY1())); const_cast<double &>(m_radius) = hull->CalculateRadius(); robox_parameters params; // make configurable... should we just subclass npm::Robox? m_front = server.DefineLidar(Frame(params.front_mount_x, params.front_mount_y, params.front_mount_theta), params.front_nscans, params.front_rhomax, params.front_phi0, params.front_phirange, params.front_channel)->GetScanner(); m_rear = server.DefineLidar(Frame(params.rear_mount_x, params.rear_mount_y, params.rear_mount_theta), params.rear_nscans, params.rear_rhomax, params.rear_phi0, params.rear_phirange, params.rear_channel)->GetScanner(); m_drive = server.DefineDiffDrive(params.model_wheelbase, params.model_wheelradius); const RobotModel::Parameters modelParms(CreateRobotParameters(params)); m_robotModel.reset(new RobotModel(modelParms, hull)); m_motionController.reset(new MotionController(m_robotModel, m_hal)); m_odometry.reset(new Odometry(m_hal)); m_multiscanner.reset(new Multiscanner(m_hal)); m_dynamicWindow.reset(new LegacyDynamicWindow(params.dwa_dimension, params.dwa_grid_width, params.dwa_grid_height, params.dwa_grid_resolution, m_robotModel, params.dwa_alpha_distance, params.dwa_alpha_heading, params.dwa_alpha_speed, true)); m_multiscanner->Add(m_front); m_multiscanner->Add(m_rear); CreateGfxStuff(server, name); return true; }
ConvexHull ValueBar::getConvexHull() { ConvexHull hull(4); hull[0] = background[0].position; hull[1] = background[1].position; hull[2] = background[2].position; hull[3] = background[3].position; return hull; }
// find contours of segmented hand and count fingers int Kinect::KinectZoom::DetectContour( ) { int numFingers = 0; cv::Mat drawing = cv::Mat::zeros( mask.size(), CV_8UC3 ); cv::vector<cv::vector<cv::Point> > contours; cv::vector<cv::Vec4i> hierarchy; findContours( mask,contours, hierarchy, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE, cv::Point() ); if ( contours.size()>0 ) { //hull MUSI byt typu int !!! cv::vector<std::vector<int> >hull( contours.size() ); cv::vector<cv::vector<cv::Vec4i> > convDef( contours.size() ); cv::vector<cv::vector<cv::Point> > hull_points( contours.size() ); cv::vector<cv::vector<cv::Point> > defect_points( contours.size() ); for ( size_t i = 0; i < contours.size(); i++ ) { if ( cv::contourArea( contours[i] )>500 ) { cv::convexHull( contours[i], hull[i], false ); cv::convexityDefects( contours[i],hull[i], convDef[i] ); for ( size_t k=0; k<hull[i].size(); k++ ) { auto ind=hull[i][k]; hull_points[i].push_back( contours[i][ind] ); } for ( size_t k=0; k<convDef[i].size(); k++ ) { if ( convDef[i][k][3]>20*256 ) { // filter defects by depth numFingers++; size_t ind_0=static_cast<size_t>( convDef[i][k][0] ); size_t ind_1=static_cast<size_t>( convDef[i][k][1] ); size_t ind_2=static_cast<size_t>( convDef[i][k][2] ); defect_points[i].push_back( contours[i][ind_2] ); cv::circle( drawing,contours[i][ind_0],5,cv::Scalar( 0,255,0 ),-1 ); cv::circle( drawing,contours[i][ind_1],5,cv::Scalar( 0,255,0 ),-1 ); cv::circle( drawing,contours[i][ind_2],5,cv::Scalar( 0,0,255 ),-1 ); cv::line( drawing,contours[i][ind_2],contours[i][ind_0],cv::Scalar( 0,0,255 ),1 );// filter defects by depth cv::line( drawing,contours[i][ind_2],contours[i][ind_1],cv::Scalar( 0,0,255 ),1 ); } } // draw results cv::drawContours( drawing, contours, static_cast<int>( i ), cv::Scalar( 0,255,0 ), 1, 8, cv::vector<cv::Vec4i>(), 0, cv::Point() ); drawContours( drawing, hull_points, static_cast<int>( i ), cv::Scalar( 255,0,0 ), 1, 8, cv::vector<cv::Vec4i>(), 0, cv::Point() ); } } } #ifdef QT_DEBUG // imshow( "Hull", drawing ); #endif return numFingers; }
Rect FindContourAndGetMaxRect(Mat frame) { //add find contours Rect maxRect(0,0,1,1); int Max = 0,MaxIndex = 0; Mat temp = frame.clone(); vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours( temp, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE); /// Draw contours vector<vector<Point> > hull( contours.size() ); for( int i = 0; i < contours.size(); i++ ) convexHull( Mat(contours[i]), hull[i], false ); Mat drawing = Mat::zeros( temp.size(), CV_8UC1 ); // double biggest_area = contourArea( hull[0],false); int most_important_area = 0; int max = 0; // cout <<"hull.size()" << hull.size() << endl; for( int i = 0; i < hull.size(); i++ ) { // approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true ); drawContours( drawing, hull, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy); // //find the biggest size // double contourarea = contourArea(contours[i],false); // if(biggest_area < contourarea){ // biggest_area = contourarea; // // cout << "biggest_area" << biggest_area << endl; // max = i; // } int temp_sum_pixels = SumAllPixelsInRect(frame, boundingRect(hull[i])); if(most_important_area < temp_sum_pixels) { most_important_area = temp_sum_pixels; max = i; } } if(hull.size() != 0){ maxRect = boundingRect(hull[max]); rectangle(drawing, maxRect.tl(), maxRect.br(), Scalar(255, 255, 255), 2); cout << "max rect " << maxRect << endl; } imshow("convex-hull",drawing); return maxRect; // return maxRect; }
ConvexHull findConvexHull(PointSet *pointSet) { int pointCount = pointSet->getSize(); pointSet->sortPointsByAngle(); if (pointCount <= 3) { // The points are already a convex hull ConvexHull hull; for (int i = 0; i < pointCount; ++i) { hull.addPoint(*pointSet->getPoint(i)); } if (pointCount > 0) { hull.addPoint(*pointSet->getPoint(0)); } return hull; } std::stack<const Point *> candiates; const Point *prev; const Point *now; candiates.push(pointSet->getLastPoint()); candiates.push(pointSet->getReferencePoint()); // Is always the first (idx 0) // element in the point set for (int i = 1; i < pointCount;) { const Point *point = pointSet->getPoint(i); now = candiates.top(); candiates.pop(); prev = candiates.top(); candiates.push(now); if (isCCW(prev->pos(), now->pos(), point->pos())) { if (point->pos() == now->pos() && USE_CUSTOM_ALGO_FIX) { std::cout << "I saved your algorithm" << std::endl; } else { candiates.push(point); } ++i; } else { candiates.pop(); } } ConvexHull hull(candiates); return hull; }
void StairDetection::drawStairs(std::string windowName, cv::InputArray colorImg, std::vector<cv::Point> &stairConvexHull) { if (!stairConvexHull.empty()) { cv::Mat temp; cv::resize(colorImg, temp, cv::Size(320, 240)); std::vector<std::vector<cv::Point> > hull(1); cv::Scalar color = cv::Scalar(cv::theRNG().uniform(0, 255), cv::theRNG().uniform(0, 255), cv::theRNG().uniform(0, 255)); hull.push_back(stairConvexHull); for (int i = 0; i<hull.size(); ++i) { drawContours(temp, hull, i, color, 3, 8, std::vector<cv::Vec4i>(), 0, cv::Point()); } cv::imshow(windowName, temp); //cv::imwrite(windowName + ".png", temp); } }
void interval_set_add_sub_4_bicremental_types() { typedef IntervalSet<T> IntervalSetT; typedef typename IntervalSetT::interval_type IntervalT; T v0 = make<T>(0); T v5 = make<T>(5); T v6 = make<T>(6); T v9 = make<T>(9); IntervalT I5_6I(v5,v6,interval_bounds::closed()); IntervalT I5_9I(v5,v9,interval_bounds::closed()); IntervalT I0_9I = IntervalT::closed(v0, v9); BOOST_CHECK_EQUAL( IntervalSet<T>(I5_6I).add(v0).add(v9), IntervalSet<T>().insert(v9).insert(I5_6I).insert(v0) ); IntervalSet<T> set_A = IntervalSet<T>(I5_6I).add(v0).add(v9); IntervalSet<T> set_B = IntervalSet<T>().insert(v9).insert(I5_6I).insert(v0); BOOST_CHECK_EQUAL( set_A, set_B ); BOOST_CHECK_EQUAL( hull(set_A), I0_9I ); BOOST_CHECK_EQUAL( hull(set_A).lower(), I0_9I.lower() ); BOOST_CHECK_EQUAL( hull(set_A).upper(), I0_9I.upper() ); IntervalSet<T> set_A1 = set_A, set_B1 = set_B, set_A2 = set_A, set_B2 = set_B; set_A1.subtract(I5_6I).subtract(v9); set_B1.erase(v9).erase(I5_6I); BOOST_CHECK_EQUAL( set_A1, set_B1 ); set_A2.subtract(I5_9I); set_B2.erase(I5_9I); BOOST_CHECK_EQUAL( set_A1, set_B1 ); BOOST_CHECK_EQUAL( set_A1, set_A2 ); BOOST_CHECK_EQUAL( set_B1, set_B2 ); }
static int select_face(WOBJECT *t,int x, int y) { WFACE *face; int a[8][2]; int i,j,ix1,ix2,iy1,iy2; for(j=0;j<t->faces;j++) { face= &(t->face[j]); for(i=0;i<face->verts;i++) { a[i][0]=t->vertex[face->vertex[i]].bd.x; a[i][1]=t->vertex[face->vertex[i]].bd.y; } hull(face->verts, a, &ix1,&ix2,&iy1,&iy2); if ((x>=a[ix1][0])&&(x<=a[ix2][0])&&(y>=a[iy1][1])&&(y<=a[iy2][1])) return j; } return -1; }
void Tn2Sampler::update_cdf(){ // cdf[i] is the integral of the outer hull from knots[i] to // knots[i+1] uint n = x.size(); cdf.resize(n); double y0 = logf[0]; for(uint k=0; k<n; ++k){ double d= dlogf[k]; double y= hull(knots[k], k); double increment; if( fabs(d) < .00000000001){ increment = exp(y - y0) * (knots[k+1] - knots[k]); }else{ increment = (exp(y - y0)/d) * (exp(d * knots[k+1]-knots[k]) - 1); } cdf[k] = (k==0 ? increment : cdf[k-1] + increment); } }
shared_ptr<Hull> CreateHull() { shared_ptr<Hull> hull(new Hull()); static const double octoSmall = 0.178; static const double octoBig = 0.430; Polygon outline; // temporary outline.AddPoint( octoBig , octoSmall); outline.AddPoint( octoSmall, octoBig); outline.AddPoint(-octoSmall, octoBig); outline.AddPoint(-octoBig , octoSmall); outline.AddPoint(-octoBig ,-octoSmall); outline.AddPoint(-octoSmall,-octoBig); outline.AddPoint( octoSmall,-octoBig); outline.AddPoint( octoBig ,-octoSmall); hull->AddPolygon(outline); return hull; }
typename enable_if< mpl::and_< is_interval_map<Type> , mpl::not_<is_total<Type> > > , bool>::type contains(const Type& super, const typename Type::interval_type& sub_interval) { typedef typename Type::const_iterator const_iterator; if(icl::is_empty(sub_interval)) return true; std::pair<const_iterator, const_iterator> exterior = super.equal_range(sub_interval); if(exterior.first == exterior.second) return false; const_iterator last_overlap = prior(exterior.second); return icl::contains(hull(exterior.first->first, last_overlap->first), sub_interval) && Interval_Set::is_joinable(super, exterior.first, last_overlap); }
double Tn2Sampler::draw(RNG &rng){ double u= runif_mt(rng, 0, cdf.back()); IT pos = std::lower_bound(cdf.begin(), cdf.end(), u); uint k = pos - cdf.begin(); // draw from the doubly truncated exponential distribution double lo = knots[k]; double hi = knots[k+1]; double lam = -1*dlogf[k]; double cand; if(lam==0){ cand = runif_mt(rng, lo, hi); }else{ cand = rtrun_exp_mt(rng, lam, lo, hi); } double target = f(cand); double logu = hull(cand, k) - rexp_mt(rng, 1); if(logu < target) return cand; add_point(cand); return draw(rng); }
vector<Point> convexHullExtraction(Mat src) { Mat src_gray; cvtColor(src, src_gray, CV_BGR2GRAY); blur(src_gray, src_gray, Size(3, 3)); // Convex Hull implementation Mat src_copy = src.clone(); Mat dst; vector<vector<Point> > contours; vector<Vec4i> hierarchy; // Find contours threshold(src_gray, dst, 200, 255, THRESH_BINARY); findContours(dst, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); // Find the convex hull object for each contour vector<vector<Point> >hull(1); convexHull(Mat(contours[1]), hull[0], false); // Draw contours + hull results if (convexShow) { RNG rng; Mat drawing = Mat::zeros(dst.size(), CV_8UC3); for (int i = 0; i< contours.size(); i++) { if (i == 1) drawContours(drawing, contours, i, Scalar(255, 255, 0), 1, 8, vector<Vec4i>(), 0, Point()); if (i == 0) drawContours(drawing, hull, i, Scalar(255, 255, 255), 1, 8, vector<Vec4i>(), 0, Point()); } // Show in a window namedWindow("Hull demo", CV_WINDOW_AUTOSIZE); imshow("Hull demo", drawing); if (save) imwrite("Hull.jpg", drawing); waitKey(0); } return hull[0]; }
static void key (int key, int x, int y) { if (key == ' ') { switch (mode) { case GEN: gen (); mode = HUL; break; case HUL: free (tri); tri = hull ((double*)point, size, &length); mode = GEN; break; } GLV_Redraw_All (); } }
void DemoPlugin::demoConvexhull() { QString wkt = QInputDialog::getText( NULL, QString("Read WKT"), QString("Type WKT") ); if ( wkt.isEmpty() ) return ; //parse wkt std::auto_ptr< Geometry > g( io::readWkt( wkt.toStdString() ) ); //build convexhull std::auto_ptr< Geometry > hull( algorithm::convexHull3D(*g) ); //create osg::Geode io::OsgFactory factory ; osg::Geometry * osgGeometry = factory.createGeometry( *hull ); osg::Geode* geode = new osg::Geode; geode->setName( wkt.toStdString() ); geode->addDrawable( osgGeometry ); viewerWindow()->viewer()->getScene()->addChild( geode ); }