void Implicit_Surface_Meshing_Component::MeshSurface(C2t3& c2t3,float angleBound, float radiusBound, float distanceBound,int opt) { if(opt==0) { Surface_3 surface(sphere_function,GT::Sphere_3(CGAL::ORIGIN,2)); CGAL::Surface_mesh_default_criteria_3<Tr> criteria(angleBound,radiusBound,distanceBound); CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag()); } else if(opt==1) { Surface_3 surface(oblate_function,GT::Sphere_3(CGAL::ORIGIN,80000)); CGAL::Surface_mesh_default_criteria_3<Tr> criteria(angleBound,radiusBound,distanceBound); CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag()); } else if (opt==2) { Surface_3 surface(prolate_function,GT::Sphere_3(CGAL::ORIGIN,8)); CGAL::Surface_mesh_default_criteria_3<Tr> criteria(angleBound,radiusBound,distanceBound); CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag()); } else if (opt==3) { Surface_3 surface(ellipsoid_function,GT::Sphere_3(CGAL::ORIGIN,32)); CGAL::Surface_mesh_default_criteria_3<Tr> criteria(angleBound,radiusBound,distanceBound); CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag()); } }
void ImplicitMesher::ImpSurfToMeshJDBois(ImpPolyhedron& ImpPoly) { //transfer data from inside of class to global RadialBasisFunc::CopyRadialBasisFunction(this->Weights,this->PolyNom,this->InterpoPoints); SMDT3 tr; // 3D-Delaunay triangulation C2T3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface ImpSurface_3 surface(&RadialBasisFunc::RadialBasisFunction,// pointer to function SMDT3GTSphere_3(CGAL::ORIGIN, 2.)); // bounding sphere // Note that "2." above is the *squared* radius of the bounding sphere! // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<SMDT3> criteria(30., // angular bound 0.1, // radius bound 0.1); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); //std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; CGAL::output_surface_facets_to_polyhedron(c2t3,ImpPoly); std::ofstream out("out.off"); CGAL::output_surface_facets_to_off (out, c2t3); }
void ShereMesh() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface Surface_3 surface(sphere_function, // pointer to function Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere // Note that "2." above is the *squared* radius of the bounding sphere! // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., // angular bound 0.1, // radius bound 0.1); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; //Output mesh //Polyhedron polymesh; //bool result = CGAL::output_surface_facets_to_polyhedron(c2t3, polymesh); //std::cout << "output_surface_facets_to_polyhedron: " << result << "\n"; //Scommentare per salvare mesh su file std::ofstream out("mesh_sphere_test_low.off"); CGAL::output_surface_facets_to_off (out, c2t3); std::cout << "SAVED MESH\n"; //std::list<TriangleGT> triangleMesh; //std::back_insert_iterator<std::list<TriangleGT> > bii(triangleMesh); //output_surface_facets_to_triangle_soup(c2t3, bii); }
int main() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface Surface_3 surface(moebius_function, // pointer to function Sphere_3(Point_3(0.0001, -0.0003, 0.), 2.)); // bounding sphere // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., // angular bound 0.05, // radius bound 0.05); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); std::ofstream out("out.off"); #ifndef NDEBUG const bool result = #endif CGAL::output_surface_facets_to_off(out, c2t3, CGAL::Surface_mesher::IO_VERBOSE | CGAL::Surface_mesher::IO_ORIENT_SURFACE); assert(result == false); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; }
int main(int argc, char*argv[]) { const char* fname = (argc>1)?argv[1]:"data/elephant.off"; // Create and fill polyhedron Polyhedron polyhedron; std::ifstream input(fname); input >> polyhedron; if(input.bad()){ std::cerr << "Error: Cannot read file " << fname << std::endl; return EXIT_FAILURE; } input.close(); // Implicit function built by AABB_tree projection queries Polyhedral_wrapper polyhedral_wrapper(polyhedron, 3, 0.01, -0.01); Mesh_domain domain(polyhedral_wrapper, polyhedral_wrapper.bounding_sphere(), 1e-4); // Set mesh criteria Facet_criteria facet_criteria(20, 5, 0.002); // angle, size, approximation Cell_criteria cell_criteria(4, 0.05); // radius-edge ratio, size Mesh_criteria criteria(facet_criteria, cell_criteria); // Mesh generation C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria); // Output std::ofstream medit_file("out.mesh"); CGAL::output_to_medit(medit_file, c3t3); return 0; }
void criteries() { cell *c; if (!line_number || current_fragment!=curr_frag) { dist_point_of_i_1=dist_point_of_i_2=dist_point_of_i_3= dist_point_of_i_b=0; curr_frag=current_fragment; } c=cell_f(); while ((c=c->nextl)->nextl != NULL) { criteria(c); if(language == PUMA_LANG_RUSSIAN ) { r_criteria(c,NULL); if( c->nvers>0 && memchr("’вѓЈ",c->vers[0].let,4) && !is_russian_baltic_conflict(c->vers[0].let)&& // 17.07.2001 E.P. !is_russian_turkish_conflict(c->vers[0].let) // 21.05.2002 E.P. ) stick_center_study(c,NULL,1); } } }
void VoronoiCgal_Patch::Compute() { m_CgalPatchs = MakePatchs(m_ImageSpline); for (int i = 0; i < m_CgalPatchs.size(); ++i) { m_Delaunay = Delaunay(); insert_polygon(m_Delaunay, m_ImageSpline, i); insert_polygonInter(m_Delaunay, m_ImageSpline, i); Mesher mesher(m_Delaunay); Criteria criteria(0, 100); mesher.set_criteria(criteria); mesher.refine_mesh(); mark_domains(m_Delaunay); LineSegs lineSegs; for (auto e = m_Delaunay.finite_edges_begin(); e != m_Delaunay.finite_edges_end(); ++e) { Delaunay::Face_handle fn = e->first->neighbor(e->second); //CGAL::Object o = m_Delaunay.dual(e); if (!fn->is_in_domain() || !fn->info().in_domain()) { continue; } if (!m_Delaunay.is_constrained(*e) && (!m_Delaunay.is_infinite(e->first)) && (!m_Delaunay.is_infinite(e->first->neighbor(e->second)))) { Delaunay::Segment s = m_Delaunay.geom_traits().construct_segment_2_object() (m_Delaunay.circumcenter(e->first), m_Delaunay.circumcenter(e->first->neighbor(e->second))); const CgalInexactKernel::Segment_2* seg = &s; CgalPoint p1(seg->source().hx(), seg->source().hy()); CgalPoint p2(seg->target().hx(), seg->target().hy()); Vector2 pp1(p1.hx(), p1.hy()); Vector2 pp2(p2.hx(), p2.hy()); if (pp1 == pp2) { continue; } lineSegs.push_back(LineSeg(pp1, pp2)); } } for (auto it = lineSegs.begin(); it != lineSegs.end(); ++it) { //m_PositionGraph.AddNewLine(it->beg, it->end, ); } } m_PositionGraph.ComputeJoints(); //printf("joints: %d\n", m_PositionGraph.m_Joints.size()); //MakeLines(); MakeGraphLines(); }
void operator()() const { typedef CGAL::Mesh_3::Robust_intersection_traits_3<K> Gt; typedef CGAL::Polyhedral_mesh_domain_with_features_3<Gt> Mesh_domain; typedef typename CGAL::Mesh_triangulation_3< Mesh_domain, typename CGAL::Kernel_traits<Mesh_domain>::Kernel, Concurrency_tag>::type Tr; typedef CGAL::Mesh_complex_3_in_triangulation_3 < Tr, typename Mesh_domain::Corner_index, typename Mesh_domain::Curve_segment_index > C3t3; typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria; typedef typename Mesh_criteria::Edge_criteria Edge_criteria; typedef typename Mesh_criteria::Facet_criteria Facet_criteria; typedef typename Mesh_criteria::Cell_criteria Cell_criteria; //------------------------------------------------------- // Data generation //------------------------------------------------------- std::cout << "\tSeed is\t" << CGAL::default_random.get_seed() << std::endl; Mesh_domain domain("data/cube.off", &CGAL::default_random); domain.detect_features(); // Set mesh criteria Edge_criteria edge_criteria(0.2); Facet_criteria facet_criteria(30, 0.2, 0.02); Cell_criteria cell_criteria(3, 0.2); Mesh_criteria criteria(edge_criteria, facet_criteria, cell_criteria); // Mesh generation C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, CGAL::parameters::no_exude(), CGAL::parameters::no_perturb()); CGAL::remove_far_points_in_mesh_3(c3t3); // Verify this->verify(c3t3,domain,criteria, Polyhedral_tag()); //, 1099, 1099, 1158, 1158, 4902, 4902); std::ofstream out_medit("test-medit.mesh"); CGAL::output_to_medit(out_medit, c3t3); CGAL::output_to_tetgen("test-tetgen", c3t3); std::ofstream out_binary("test-binary.mesh.cgal", std::ios_base::out|std::ios_base::binary); CGAL::Mesh_3::save_binary_file(out_binary, c3t3); out_binary.close(); C3t3 c3t3_bis; std::ifstream in_binary("test-binary.mesh.cgal", std::ios_base::in|std::ios_base::binary); CGAL::Mesh_3::load_binary_file(in_binary, c3t3_bis); assert(c3t3_bis.triangulation() == c3t3.triangulation()); }
void test_facet(const FT angle, const FT radius, const FT distance, const bool is_facet1_bad = false, const bool is_facet2_bad = false, const bool compare_facets = false) const { typedef typename Facet_criteria::Facet_badness Badness; Facet f1 = facet_handle(f1_); Facet f2 = facet_handle(f2_); Facet_criteria criteria(angle, radius, distance); Badness b1 = criteria(f1); Badness b2 = criteria(f2); std::cerr << "\t[Angle bound: " << angle << " - Radius bound: " << radius << " - Distance bound: " << distance << "] \tf1 is "; if ( b1 ) std::cerr << "BAD q=<" << b1->first << ";" << b1->second << ">"; else std::cerr << "GOOD "; std::cerr << "\t\tf2 is "; if ( b2 ) std::cerr << "BAD q=<" << b2->first << ";" << b2->second << ">"; else std::cerr << "GOOD"; assert( is_facet1_bad == (bool)b1 ); assert( is_facet2_bad == (bool)b2 ); // b1 is badder than b2 if ( compare_facets ) { std::cerr << "\t\tq(f1) < q(f2)"; assert(*b1<*b2); } std::cerr << std::endl; }
int16_t recop_cell(cell *c) { c->reasno=0; criteria(c); if (db_pidx_crit) v2_pidx_crit(c); if ( c->nvers == 0 ) { c->recsource = 0; c->history = 0; } return c->nvers; }
int main(void) { int i = 2522; while (!criteria(i)) { i += 2; } printf("%i\n",i); return 0; }
static int16_t second_recog(cell *c) { levcut(c, 1); if (db_status && (db_trace_flag & 2)) est_snap(db_pass, c, "second rec linear"); criteria(c); if (db_status && (db_trace_flag & 2)) est_snap(db_pass, c, "second rec criteria"); if (c->nvers == 0) { c->recsource &= 0; c->history &= 0; } return c->nvers; }
void LearningKernel::initRandomTrees() { std::cout << "init random trees\n"; m_pTrees->setMaxDepth(2000); m_pTrees->setMinSampleCount(50); cv::TermCriteria criteria(cv::TermCriteria::COUNT, 50, 0); m_pTrees->setTermCriteria(criteria); m_pTrees->setCalculateVarImportance(false); // This is a binary classifier (max of 2 classes). m_pTrees->setMaxCategories(2); }
void make_simples_diff(int16_t lang) { extern char db_pass; cell *c,*e=cell_l(); int16_t dbp = db_pass; db_pass=0; for(c=cell_f()->next;c!=e;c=c->next) if( !c->env->scale ) { criteria(c); if( lang==PUMA_LANG_RUSSIAN ) r_criteria(c,NULL); } db_pass = (uchar)dbp; return; }
int main(void) { GetHistogram gh; ObjectFinder of; cv::Mat img1, img2; cv::Mat imgROI; cv::Mat histogram; cv::Mat backProject; img1 = cv::imread("..\\..\\..\\source\\1.jpg"); if(!img1.data) return 0; imgROI = img1(cv::Rect(80,300,35,40)); cv::rectangle(img1,cv::Rect(110,260,35,40),cv::Scalar(0,0,255)); cv::namedWindow("img1"); cv::imshow("img1", img1); //获得imgROI的直方图 histogram = gh.getHueHistogram(imgROI, 65); cv::normalize(histogram,histogram,1.0); of.setHistogram(histogram); //获取并处理第二幅图像 cv::Mat hsv; std::vector<cv::Mat> hue; img2 = cv::imread("..\\..\\..\\source\\2.jpg"); cv::cvtColor(img2, hsv, CV_BGR2HSV); cv::split(hsv, hue); cv::threshold(hue[1], hue[1], 65, 255, cv::THRESH_BINARY);//这个是为了将低饱和度的图像从反向投影结果中剔除 //对于第二幅图进行反向投影,使用第一幅图ROI的直方图 backProject = of.finder(img2); cv::bitwise_and(backProject, hue[1], backProject); cv::namedWindow("backProject"); cv::imshow("backProject",backProject); //均值漂移 cv::Rect rect(110,260,35,40); cv::rectangle(img2, rect, cv::Scalar(0,0,255)); cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER,10,0.01);//最大迭代次数是10,移动距离阈值是0.01 cv::meanShift(backProject,rect,criteria); cv::rectangle(img2, rect, cv::Scalar(0,255,0)); cv::namedWindow("img2"); cv::imshow("img2",img2); cv::waitKey(0); return 0; }
int main() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface Surface_3 surface(sphere_function, // pointer to function Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere // Note that "2." above is the *squared* radius of the bounding sphere! // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., // angular bound 0.1, // radius bound 0.1); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; }
void image() const { typedef CGAL::Image_3 Image; typedef CGAL::Labeled_image_mesh_domain_3<Image, K_e_i> Mesh_domain; typedef typename CGAL::Mesh_triangulation_3< Mesh_domain, CGAL::Kernel_traits<Mesh_domain>::Kernel, Concurrency_tag>::type Tr; typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3; typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria; typedef typename Mesh_criteria::Facet_criteria Facet_criteria; typedef typename Mesh_criteria::Cell_criteria Cell_criteria; //------------------------------------------------------- // Data generation //------------------------------------------------------- Image image; image.read("data/liver.inr.gz"); std::cout << "\tSeed is\t" << CGAL::get_default_random().get_seed() << std::endl; Mesh_domain domain(image, 1e-9, &CGAL::get_default_random()); // Set mesh criteria Facet_criteria facet_criteria(25, 20*image.vx(), 5*image.vx()); Cell_criteria cell_criteria(4, 25*image.vx()); Mesh_criteria criteria(facet_criteria, cell_criteria); // Mesh generation C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, CGAL::parameters::no_exude(), CGAL::parameters::no_perturb()); // Verify this->verify_c3t3_volume(c3t3, 1772330*0.95, 1772330*1.05); this->verify(c3t3,domain,criteria, Bissection_tag()); typedef typename Mesh_domain::Surface_patch_index Patch_id; CGAL_static_assertion(CGAL::Output_rep<Patch_id>::is_specialized); CGAL_USE_TYPE(Patch_id); }
int main(int argc, char** argv) { std::vector<std::string> args(argv, argv + argc); for(auto a : args) { std::cout << a << "\n"; } cv::Mat base = cv::imread(args[1]); cv::Mat dest = cv::imread(args[2]); cv::Mat base_gray, dest_gray; cv::cvtColor(base, base_gray, CV_BGR2GRAY); cv::cvtColor(dest, dest_gray, CV_BGR2GRAY); const int warp_mode = cv::MOTION_EUCLIDEAN; cv::Mat warp_matrix = warp_mode == cv::MOTION_HOMOGRAPHY ? cv::Mat::eye(3, 3, CV_32F) : cv::Mat::eye(2, 3, CV_32F); int iterations = 5000; double termination_eps = 1e-10; cv::TermCriteria criteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, iterations, termination_eps); cv::Mat fusedImage; cv::findTransformECC(base_gray, dest_gray, warp_matrix, warp_mode, criteria); if (warp_mode != cv::MOTION_HOMOGRAPHY) { cv::warpAffine(dest, fusedImage, warp_matrix, base.size(), cv::INTER_LINEAR + cv::WARP_INVERSE_MAP); } cv::imwrite("fishexample.png", fusedImage); }
int GoodFeaturesToTrack(const T *img, int width, int height, int maxpos, double *pos, double quality, double mindist, bool bHarris, bool bSubPix){ cv::Mat cvimg(width,height,CV_8UC1); double maxval = *std::max_element(img,img+width*height); double scale = (maxval==0)?1:255/maxval; /* 8bitデータへの変換 */ for(int i=0;i<height;++i){ for(int j=0;j<width;++j){ *cvimg.ptr(i,j) = static_cast<unsigned char>(img[i*width+j] * scale); }} std::vector<cv::Point2f> cvpnts; cv::goodFeaturesToTrack(cvimg,cvpnts,maxpos,quality,mindist,cv::Mat(),3,bHarris); if(bSubPix){ cv::TermCriteria criteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 20, 0.03); cv::cornerSubPix(cvimg,cvpnts,cv::Size(10,10), cv::Size(-1,-1), criteria); } for(int i=0;i<cvpnts.size();++i){ pos[2*i ] = cvpnts[i].x; pos[2*i+1] = cvpnts[i].y; } return cvpnts.size(); }
int main() { hazelcast::client::ClientConfig config; hazelcast::client::HazelcastClient hz(config); hazelcast::client::IMap<int, Car> map = hz.getMap<int, Car>("cars"); map.put(1, Car("Audi Q7", 250, 22000)); map.put(2, Car("BMW X5", 312, 34000)); map.put(3, Car("Porsche Cayenne", 408, 57000)); // we're using a custom attribute called 'attribute' which is provided by the 'CarAttributeExtractor' // we are also passing an argument 'mileage' to the extractor hazelcast::client::query::SqlPredicate criteria("attribute[mileage] < 30000"); std::vector<Car> cars = map.values(criteria); for (std::vector<Car>::const_iterator it = cars.begin(); it != cars.end(); ++it) { std::cout << (*it) << std::endl; } std::cout << "Finished" << std::endl; return 0; }
/** * test opencv wrapper for sba. Receive camera data and point data files * e.g. "test_cvsba 54camsvarKD.txt 54pts.txt" using sba sample data files */ int main(int argc, char** argv) { if(argc<3) { std::cerr << "Usage: inputcamsfile inputpointsfile" << std::endl; return 0; } std::vector<cv::Point3f> points; std::vector<std::vector<cv::Point2f> > imagePoints; std::vector<std::vector<int> > visibility; std::vector<cv::Mat> cameraMatrix; std::vector<cv::Mat> R; std::vector<cv::Mat> T; std::vector<cv::Mat> distCoeffs; cv::TermCriteria criteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 150, 1e-10); // read data from sba file format. All obtained data is in opencv format (including rotation in rodrigues format) readDataCVFormat(argv[1], argv[2], points, imagePoints, visibility, cameraMatrix, distCoeffs, R, T); // run sba optimization cvsba::Sba sba; // change params if desired cvsba::Sba::Params params ; params.type = cvsba::Sba::MOTIONSTRUCTURE; params.iterations = 150; params.minError = 1e-10; params.fixedIntrinsics = 5; params.fixedDistortion = 5; params.verbose=true; sba.setParams(params); sba.run( points, imagePoints, visibility, cameraMatrix, R, T,distCoeffs); std::cout<<"Optimization. Initial error="<<sba.getInitialReprjError()<<" and Final error="<<sba.getFinalReprjError()<<std::endl; return 0; }
void Kmeans::k_means(const Mat& feature) { int try_again = 5; TermCriteria criteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0); kmeans(feature, k, indices, criteria, try_again, KMEANS_PP_CENTERS, centers); }
// adapted from http://www.cgal.org/Manual/beta/examples/Surface_reconstruction_points_3/poisson_reconstruction_example.cpp Mesh poissonSurface(const Mat ipoints, const Mat normals) { // Poisson options FT sm_angle = 20.0; // Min triangle angle in degrees. FT sm_radius = 300; // Max triangle size w.r.t. point set average spacing. FT sm_distance = 0.375; // Surface Approximation error w.r.t. point set average spacing. PointList points; points.reserve(ipoints.rows); float min = 0, max = 0; for (int i=0; i<ipoints.rows; i++) { float const *p = ipoints.ptr<float const>(i), *n = normals.ptr<float const>(i); points.push_back(Point_with_normal(Point(p[0]/p[3], p[1]/p[3], p[2]/p[3]), Vector(n[0], n[1], n[2]))); if (p[0]/p[3] > max) max = p[0]/p[3]; if (p[0]/p[3] < min) min = p[0]/p[3]; } // Creates implicit function from the read points using the default solver. // Note: this method requires an iterator over points // + property maps to access each point's position and normal. // The position property map can be omitted here as we use iterators over Point_3 elements. Poisson_reconstruction_function function(points.begin(), points.end(), CGAL::make_normal_of_point_with_normal_pmap(points.begin()) ); // Computes the Poisson indicator function f() at each vertex of the triangulation. bool success = function.compute_implicit_function(); assert(success); #ifdef TEST_BUILD printf("implicit function ready. Meshing...\n"); #endif // Computes average spacing FT average_spacing = CGAL::compute_average_spacing(points.begin(), points.end(), 6 /* knn = 1 ring */); // Gets one point inside the implicit surface // and computes implicit function bounding sphere radius. Point inner_point = function.get_inner_point(); Sphere bsphere = function.bounding_sphere(); FT radius = std::sqrt(bsphere.squared_radius()); // Defines the implicit surface: requires defining a // conservative bounding sphere centered at inner point. FT sm_sphere_radius = 5.0 * radius; FT sm_dichotomy_error = sm_distance*average_spacing/1000.0; // Dichotomy error must be << sm_distance Surface_3 surface(function, Sphere(inner_point,sm_sphere_radius*sm_sphere_radius), sm_dichotomy_error/sm_sphere_radius); // Defines surface mesh generation criteria // parameters: min triangle angle (degrees), max triangle size, approximation error CGAL::Surface_mesh_default_criteria_3<STr> criteria(sm_angle, sm_radius*average_spacing, sm_distance*average_spacing); // Generates surface mesh with manifold option STr tr; // 3D Delaunay triangulation for surface mesh generation C2t3 c2t3(tr); // 2D complex in 3D Delaunay triangulation // parameters: reconstructed mesh, implicit surface, meshing criteria, 'do not require manifold mesh' CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); assert(tr.number_of_vertices() > 0); // Search structure: index of the vertex at an exactly given position std::map<Point, int> vertexIndices; // Extract all vertices of the resulting mesh Mat vertices(tr.number_of_vertices(), 4, CV_32FC1), faces(c2t3.number_of_facets(), 3, CV_32SC1); #ifdef TEST_BUILD printf("%i vertices, %i facets. Converting...\n", vertices.rows, faces.rows); #endif { int i=0; for (C2t3::Vertex_iterator it=c2t3.vertices_begin(); it!=c2t3.vertices_end(); it++, i++) { float *vertex = vertices.ptr<float>(i); Point p = it->point(); vertex[0] = p.x(); vertex[1] = p.y(); vertex[2] = p.z(); vertex[3] = 1; vertexIndices[p] = i; } vertices.resize(i); } // Extract all faces of the resulting mesh and calculate the index of each of their vertices { int i=0; for (C2t3::Facet_iterator it=c2t3.facets_begin(); it!=c2t3.facets_end(); it++, i++) { Cell cell = *it->first; int vertex_excluded = it->second; int32_t* outfacet = faces.ptr<int32_t>(i); // a little magic so that face normals are oriented outside char sign = (function(cell.vertex(vertex_excluded)->point()) > 0) ? 1 : 2; // 2 = -1 (mod 3) for (char j = vertex_excluded + 1; j < vertex_excluded + 4; j++) { outfacet[(sign*j)%3] = vertexIndices[cell.vertex(j%4)->point()]; } } } return Mesh(vertices, faces); }
void PoissonSurfaceReconstruction::reconstruct(std::vector<Eigen::Vector3d> &points, std::vector<Eigen::Vector3d> &normals, TriangleMesh &mesh){ assert(points.size() == normals.size()); std::cout << "creating points with normal..." << std::endl; std::vector<Point_with_normal> points_with_normal; points_with_normal.resize((int)points.size()); for(int i=0; i<(int)points.size(); i++){ Vector vec(normals[i][0], normals[i][1], normals[i][2]); //Point_with_normal pwn(points[i][0], points[i][1], points[i][2], vec); //points_with_normal[i] = pwn; points_with_normal[i] = Point_with_normal(points[i][0], points[i][1], points[i][2], vec); } std::cout << "constructing poisson reconstruction function..." << std::endl; Poisson_reconstruction_function function(points_with_normal.begin(), points_with_normal.end(), CGAL::make_normal_of_point_with_normal_pmap(PointList::value_type())); std::cout << "computing implicit function..." << std::endl; if( ! function.compute_implicit_function() ) { std::cout << "compute implicit function is failure" << std::endl; return; } //return EXIT_FAILURE; // Computes average spacing std::cout << "compute average spacing..." << std::endl; FT average_spacing = CGAL::compute_average_spacing(points_with_normal.begin(), points_with_normal.end(), 6 /* knn = 1 ring */); // Gets one point inside the implicit surface // and computes implicit function bounding sphere radius. Point inner_point = function.get_inner_point(); Sphere bsphere = function.bounding_sphere(); FT radius = std::sqrt(bsphere.squared_radius()); // Defines the implicit surface: requires defining a // conservative bounding sphere centered at inner point. FT sm_sphere_radius = 5.0 * radius; FT sm_dichotomy_error = distance_criteria*average_spacing/1000.0; // Dichotomy error must be << sm_distance //FT sm_dichotomy_error = distance_criteria*average_spacing/10.0; // Dichotomy error must be << sm_distance std::cout << "reconstructed surface" << std::endl; Surface_3 reconstructed_surface(function, Sphere(inner_point,sm_sphere_radius*sm_sphere_radius), sm_dichotomy_error/sm_sphere_radius); // Defines surface mesh generation criteria CGAL::Surface_mesh_default_criteria_3<STr> criteria(angle_criteria, // Min triangle angle (degrees) radius_criteria*average_spacing, // Max triangle size distance_criteria*average_spacing); // Approximation error std::cout << "generating surface mesh..." << std::endl; // Generates surface mesh with manifold option STr tr; // 3D Delaunay triangulation for surface mesh generation C2t3 c2t3(tr); // 2D complex in 3D Delaunay triangulation CGAL::make_surface_mesh(c2t3, // reconstructed mesh reconstructed_surface, // implicit surface criteria, // meshing criteria CGAL::Manifold_tag()); // require manifold mesh if(tr.number_of_vertices() == 0){ std::cout << "surface mesh generation is failed" << std::endl; return; } Polyhedron surface; CGAL::output_surface_facets_to_polyhedron(c2t3, surface); // convert CGAL::surface to TriangleMesh // std::cout << "converting CGA::surface to TriangleMesh..." << std::endl; std::vector<Eigen::Vector3d> pts; std::vector<std::vector<int> > faces; pts.resize(surface.size_of_vertices()); faces.resize(surface.size_of_facets()); Polyhedron::Point_iterator pit; int index = 0; for(pit=surface.points_begin(); pit!=surface.points_end(); ++pit){ pts[index][0] = pit->x(); pts[index][1] = pit->y(); pts[index][2] = pit->z(); index ++; } index = 0; Polyhedron::Face_iterator fit; for(fit=surface.facets_begin(); fit!=surface.facets_end(); ++fit){ std::vector<int > face(3); Halfedge_facet_circulator j = fit->facet_begin(); int f_index = 0; do { face[f_index] = std::distance(surface.vertices_begin(), j->vertex()); f_index++; } while ( ++j != fit->facet_begin()); faces[index] = face; index++; } mesh.createFromFaceVertex(pts, faces); }
/* * List Job record(s) that match JOB_DBR */ void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, const char *range, const char* clientname, int jobstatus, const char* volumename, utime_t since_time, int last, int count, OUTPUT_FORMATTER *sendit, e_list_type type) { char ed1[50]; char esc[MAX_ESCAPE_NAME_LENGTH]; POOL_MEM temp(PM_MESSAGE), selection(PM_MESSAGE), criteria(PM_MESSAGE); POOL_MEM selection_last(PM_MESSAGE); char dt[MAX_TIME_LENGTH]; if (jr->JobId > 0) { temp.bsprintf("AND Job.JobId=%s", edit_int64(jr->JobId, ed1)); pm_strcat(selection, temp.c_str()); } if (jr->Name[0] != 0) { mdb->db_escape_string(jcr, esc, jr->Name, strlen(jr->Name)); temp.bsprintf( "AND Job.Name = '%s' ", esc); pm_strcat(selection, temp.c_str()); } if (clientname) { temp.bsprintf("AND Client.Name = '%s' ", clientname); pm_strcat(selection, temp.c_str()); } if (jobstatus) { temp.bsprintf("AND Job.JobStatus = '%c' ", jobstatus); pm_strcat(selection, temp.c_str()); } if (volumename) { temp.bsprintf("AND Media.Volumename = '%s' ", volumename); pm_strcat(selection, temp.c_str()); } if (since_time) { bstrutime(dt, sizeof(dt), since_time); temp.bsprintf("AND Job.SchedTime > '%s' ", dt); pm_strcat(selection, temp.c_str()); } if (last > 0) { /* * Show only the last run of a job (Job.Name). * Do a subquery to get a list of matching JobIds * to be used in the main query later. * * range: while it might be more efficient, * to apply the range to the subquery, * at least mariadb 10 does not support this. * Therefore range is handled in the main query. */ temp.bsprintf("AND Job.JobId IN (%s) ", list_jobs_last); selection_last.bsprintf(temp.c_str(), selection.c_str(), ""); /* * As the existing selection is handled in the subquery, * overwrite the main query selection * by the newly created selection_last. */ pm_strcpy(selection, selection_last.c_str()); } db_lock(mdb); if (count > 0) { Mmsg(mdb->cmd, list_jobs_count, selection.c_str(), range); } else { if (type == VERT_LIST) { Mmsg(mdb->cmd, list_jobs_long, selection.c_str(), range); } else { Mmsg(mdb->cmd, list_jobs, selection.c_str(), range); } } if (!QUERY_DB(jcr, mdb, mdb->cmd)) { goto bail_out; } sendit->array_start("jobs"); list_result(jcr, mdb, sendit, type); sendit->array_end("jobs"); sql_free_result(mdb); bail_out: db_unlock(mdb); }
int Reconstruccion3D::Delaunay() { // Poisson options FT sm_angle = 20; // Min triangle angle in degrees. 10 FT sm_radius = 1; // Max triangle size w.r.t. point set average spacing. 2 FT sm_distance = 0.1; // Surface Approximation error w.r.t. point set average spacing.0.375 // Reads the point set file in points[]. // Note: read_xyz_points_and_normals() requires an iterator over points // + property maps to access each point's position and normal. // The position property map can be omitted here as we use iterators over Point_3 elements. PointList points; std::ifstream stream("puntosNormalizados.off"); if (!stream || !CGAL::read_xyz_points_and_normals( stream, std::back_inserter(points), CGAL::make_normal_of_point_with_normal_pmap(std::back_inserter(points)))) { std::cerr << "Error: cannot read file data/kitten.xyz" << std::endl; return EXIT_FAILURE; } // Creates implicit function from the read points. // Note: this method requires an iterator over points // + property maps to access each point's position and normal. // The position property map can be omitted here as we use iterators over Point_3 elements. Poisson_reconstruction_function function( points.begin(), points.end(), CGAL::make_normal_of_point_with_normal_pmap(points.begin())); // Computes the Poisson indicator function f() // at each vertex of the triangulation. if ( ! function.compute_implicit_function() ) return EXIT_FAILURE; // Computes average spacing FT average_spacing = CGAL::compute_average_spacing(points.begin(), points.end(), 6 /* knn = 1 ring */); // Gets one point inside the implicit surface // and computes implicit function bounding sphere radius. Point inner_point = function.get_inner_point(); Sphere bsphere = function.bounding_sphere(); FT radius = std::sqrt(bsphere.squared_radius()); // Defines the implicit surface: requires defining a // conservative bounding sphere centered at inner point. FT sm_sphere_radius = 0.5 * radius; //0.5 FT sm_dichotomy_error = sm_distance*average_spacing/1000.0; // Dichotomy error must be << sm_distance Surface_3 surface(function, Sphere(inner_point,sm_sphere_radius*sm_sphere_radius), sm_dichotomy_error/sm_sphere_radius); // Defines surface mesh generation criteria CGAL::Surface_mesh_default_criteria_3<STr> criteria(sm_angle, // Min triangle angle (degrees) sm_radius*average_spacing, // Max triangle size sm_distance*average_spacing); // Approximation error // Generates surface mesh with manifold option STr tr; // 3D Delaunay triangulation for surface mesh generation C2t3 c2t3(tr); // 2D complex in 3D Delaunay triangulation CGAL::make_surface_mesh(c2t3, // reconstructed mesh surface, // implicit surface criteria, // meshing criteria CGAL::Manifold_with_boundary_tag()); // require manifold mesh if(tr.number_of_vertices() == 0) return EXIT_FAILURE; // saves reconstructed surface mesh std::ofstream out("kitten_poisson-20-30-0.375.off"); Polyhedron output_mesh; CGAL::output_surface_facets_to_polyhedron(c2t3, output_mesh); out << output_mesh; return EXIT_SUCCESS; }
int main(int argc, char** argv) { QApplication app(argc, argv); Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // the 'function' is a 3D gray level image Gray_level_image image("../../../examples/Surface_mesher/data/skull_2.9.inr", 2.9); // Carefully choosen bounding sphere: the center must be inside the // surface defined by 'image' and the radius must be high enough so that // the sphere actually bounds the whole image. GT::Point_3 bounding_sphere_center(122., 102., 117.); GT::FT bounding_sphere_squared_radius = 200.*200.*2.; GT::Sphere_3 bounding_sphere(bounding_sphere_center, bounding_sphere_squared_radius); // definition of the surface, with 10^-2 as relative precision Surface_3 surface(image, bounding_sphere, 1e-5); // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., 5., 1.); // meshing surface, with the "manifold without boundary" algorithm CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag()); QVTKWidget widget; widget.resize(256,256); // vtkImageData* vtk_image = CGAL::vtk_image_sharing_same_data_pointer(image); vtkRenderer *aRenderer = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer(aRenderer); widget.SetRenderWindow(renWin); // vtkContourFilter *skinExtractor = vtkContourFilter::New(); // skinExtractor->SetInput(vtk_image); // skinExtractor->SetValue(0, isovalue); // skinExtractor->SetComputeNormals(0); vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New(); // skinNormals->SetInputConnection(skinExtractor->GetOutputPort()); vtkPolyData* polydata = CGAL::output_c2t3_to_vtk_polydata(c2t3); skinNormals->SetInput(polydata); skinNormals->SetFeatureAngle(60.0); vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New(); // skinMapper->SetInputConnection(skinExtractor->GetOutputPort()); skinMapper->SetInput(polydata); skinMapper->ScalarVisibilityOff(); vtkActor *skin = vtkActor::New(); skin->SetMapper(skinMapper); // An outline provides context around the data. // // vtkOutlineFilter *outlineData = vtkOutlineFilter::New(); // outlineData->SetInput(vtk_image); // vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New(); // mapOutline->SetInputConnection(outlineData->GetOutputPort()); // vtkActor *outline = vtkActor::New(); // outline->SetMapper(mapOutline); // outline->GetProperty()->SetColor(0,0,0); // It is convenient to create an initial view of the data. The FocalPoint // and Position form a vector direction. Later on (ResetCamera() method) // this vector is used to position the camera to look at the data in // this direction. vtkCamera *aCamera = vtkCamera::New(); aCamera->SetViewUp (0, 0, -1); aCamera->SetPosition (0, 1, 0); aCamera->SetFocalPoint (0, 0, 0); aCamera->ComputeViewPlaneNormal(); // Actors are added to the renderer. An initial camera view is created. // The Dolly() method moves the camera towards the FocalPoint, // thereby enlarging the image. // aRenderer->AddActor(outline); aRenderer->AddActor(skin); aRenderer->SetActiveCamera(aCamera); aRenderer->ResetCamera (); aCamera->Dolly(1.5); // Set a background color for the renderer and set the size of the // render window (expressed in pixels). aRenderer->SetBackground(1,1,1); renWin->SetSize(640, 480); // Note that when camera movement occurs (as it does in the Dolly() // method), the clipping planes often need adjusting. Clipping planes // consist of two planes: near and far along the view direction. The // near plane clips out objects in front of the plane; the far plane // clips out objects behind the plane. This way only what is drawn // between the planes is actually rendered. aRenderer->ResetCameraClippingRange (); // Initialize the event loop and then start it. // iren->Initialize(); // iren->Start(); // It is important to delete all objects created previously to prevent // memory leaks. In this case, since the program is on its way to // exiting, it is not so important. But in applications it is // essential. // vtk_image->Delete(); // skinExtractor->Delete(); skinNormals->Delete(); skinMapper->Delete(); skin->Delete(); // outlineData->Delete(); // mapOutline->Delete(); // outline->Delete(); aCamera->Delete(); // iren->Delete(); renWin->Delete(); aRenderer->Delete(); polydata->Delete(); widget.show(); app.exec(); return 0; }
void calibrateProcess(Configure& conf, cv::Mat& cameraMatrix, cv::Mat& distCoeffs) { const cv::Size frameSize(conf.getConfInt("universal.frameWidth"), conf.getConfInt("universal.frameHeight")); const cv::string dataPath(conf.getConfString("universal.dataPath")); const std::string checkerPrefix (conf.getConfString("calibration.checkerPrefix")); const std::string checkerSuffix (conf.getConfString("calibration.checkerSuffix")); const int checkerNum = conf.getConfInt("calibration.checkerNum"); const cv::Size checkerSize(conf.getConfInt("calibration.checkerWidth"), conf.getConfInt("calibration.checkerHeight")); cv::vector<cv::Mat> checkerImgs; cv::vector<cv::vector<cv::Point3f>> worldPoints(checkerNum); cv::vector<cv::vector<cv::Point2f>> imagePoints(checkerNum); cv::TermCriteria criteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 20, 0.001); cv::vector<cv::Mat> rotationVectors; cv::vector<cv::Mat> translationVectors; for(int i=0; i<checkerNum; i++){ std::stringstream stream; stream << checkerPrefix << i+1 << checkerSuffix; std::string fileName = stream.str(); cv::Mat tmp = cv::imread(dataPath + fileName, 0); cv::resize(tmp, tmp, frameSize); checkerImgs.push_back(tmp); std::cout << "load checker image: " << fileName << std::endl; } cv::namedWindow("Source", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO); for(int i=0; i<checkerNum; i++){ std::cout << "find corners from image " << i+1; if(cv::findChessboardCorners(checkerImgs[i], checkerSize, imagePoints[i])){ std::cout << " ... all corners found." << std::endl; cv::cornerSubPix(checkerImgs[i], imagePoints[i], cv::Size(5, 5), cv::Size(-1, -1), criteria); cv::drawChessboardCorners(checkerImgs[i], checkerSize, (cv::Mat)(imagePoints[i]), true); cv::imshow("Source", checkerImgs[i]); cv::waitKey(200); }else{ std::cout << " ... at least 1 corner not found." << std::endl; cv::waitKey(0); exit(-1); } } cv::destroyWindow("Source"); for(int i=0; i<checkerNum; i++){ for(int j=0; j<checkerSize.area(); j++){ worldPoints[i]. push_back(cv::Point3f(static_cast<float>(j%checkerSize.width*10), static_cast<float>(j/checkerSize.width*10), 0.0)); } } cv::calibrateCamera(worldPoints, imagePoints, frameSize, cameraMatrix, distCoeffs, rotationVectors, translationVectors); std::cout << "camera matrix" << std::endl; std::cout << cameraMatrix << std::endl; std::cout << "dist coeffs" << std::endl; std::cout << distCoeffs << std::endl; }
bool checkSquare(const vector<int>& veca, const vector<int>& vecb){ if(vless(vecb, veca)) return false; return criteria(veca, vecb); }
int Quoter_Client::init (int argc, ACE_TCHAR **argv) { this->argc_ = argc; int i; // Make a copy of argv since ORB_init will change it. this->argv_ = new ACE_TCHAR *[argc]; for (i = 0; i < argc; i++) this->argv_[i] = argv[i]; try { // Retrieve the ORB. this->orb_ = CORBA::ORB_init (this->argc_, this->argv_, "internet"); // Parse command line and verify parameters. if (this->parse_args () == -1) return -1; int naming_result = this->init_naming_service (); if (naming_result == -1) return naming_result; if (this->debug_level_ >= 2) ACE_DEBUG ((LM_DEBUG, "Quoter Client: Factory received OK\n")); // using the Quoter Generic Factory CosLifeCycle::Key genericFactoryName (1); // max = 1 genericFactoryName.length(1); genericFactoryName[0].id = CORBA::string_dup ("Quoter_Factory"); // The final factory CosLifeCycle::Criteria criteria(1); criteria.length (1); criteria[0].name = CORBA::string_dup ("filter"); criteria[0].value <<= CORBA::string_dup ("name=='Quoter_Generic_Factory'"); // used to find the last generic factory in the chain CORBA::Object_var quoterObject_var = this->generic_Factory_var_->create_object (genericFactoryName, criteria); this->quoter_var_ = Stock::Quoter::_narrow (quoterObject_var.in()); if (this->debug_level_ >= 2) ACE_DEBUG ((LM_DEBUG, "Quoter Client: Quoter Created\n")); if (CORBA::is_nil (this->quoter_var_.in())) { ACE_ERROR_RETURN ((LM_ERROR, "null quoter objref returned by factory\n"), -1); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Quoter::init"); return -1; } return 0; }