int determineCoverage(x,y,z){ //printf("Inside determine coverage\n"); int incube = in_cube(x,y,z); int insphere = in_sphere (x,y,z, X0, X1, X2); if (incube && insphere) return 2; if ((incube && !insphere)) return 1; if (!incube && insphere) return 3; return 0; }
void MainWindow::newPoints(int n) { scene.periodic_triangulation.clear(); scene.points.clear(); CGAL::Random rnd(std::time(NULL)); CGAL::Random_points_in_cube_3<Point_3, Creator> in_cube(1,rnd); for (int i=0 ; i<n ; i++) if (scene.two_dimensional) { Point_3 rdpt = *in_cube++; scene.points.push_back(Point_3(rdpt.x(),rdpt.y(),0.)); } else scene.points.push_back(*in_cube++); Iso_cuboid_3 dom(-1,-1,-1,1,1,1); scene.periodic_triangulation.set_domain(dom); scene.periodic_triangulation.insert(scene.points.begin(), scene.points.end()); FT cx(0),cy(0),cz(0); for (int i=0 ; i<8 ; i++) { cx += dom[i].x(); cy += dom[i].y(); cy += dom[i].y(); } qglviewer::Vec center(cx/8.,cy/8.,cz/8.); viewer->setSceneCenter(center); viewer->setSceneRadius(std::sqrt( ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())) + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())) + ((dom.xmax()-dom.xmin())*(dom.xmax()-dom.xmin())))); speedSlider->setRange(0,100); speedSlider->setSliderPosition(100); emit (sceneChanged()); }
int main() { typedef CGAL::Creator_uniform_3<double, Point> Creator; CGAL::Random random(7); CGAL::Random_points_in_cube_3<Point, Creator> in_cube(1, random); std::vector<Point> pts; // Generating 1000 random points for (int i=0 ; i < 1000 ; i++) { Point p = *in_cube++; pts.push_back(p); } // Define the periodic cube P3DT3 pdt(PK::Iso_cuboid_3(-1,-1,-1,1,1,1)); // Heuristic for inserting large point sets (if pts is reasonably large) pdt.insert(pts.begin(), pts.end(), true); // As pdt won't be modified anymore switch to 1-sheeted cover if possible if (pdt.is_triangulation_in_1_sheet()) pdt.convert_to_1_sheeted_covering(); std::cout << "Periodic Delaunay computed." << std::endl; // compute alpha shape Alpha_shape_3 as(pdt); std::cout << "Alpha shape computed in REGULARIZED mode by default." << std::endl; // find optimal alpha values Alpha_shape_3::NT alpha_solid = as.find_alpha_solid(); Alpha_shape_3::Alpha_iterator opt = as.find_optimal_alpha(1); std::cout << "Smallest alpha value to get a solid through data points is " << alpha_solid << std::endl; std::cout << "Optimal alpha value to get one connected component is " << *opt << std::endl; as.set_alpha(*opt); assert(as.number_of_solid_components() == 1); return 0; }
main(int argc, char *argv[]) { int i, j, k; /* voxel index in x,y,z */ FILE *fp; /* target VRML file "voxel.wrl" */ double x0, y0, z0; /* sphere center position */ double x, y, z; /* current cell position */ double cellsize = BOXSIZE/NDIV; /* current cell size */ fprintf(stderr, "\n>> 24786 GEOMETRIC MODELING PS4-1:VOXEL <<\n\n"); /* Check if the number of arguments is correct */ if (argc != 4){ fprintf(stderr, "use: voxel x0 y0 z0 \n"); exit(-1); } /* set sphere's center */ x0 = atof(argv[1]); y0 = atof(argv[2]); z0 = atof(argv[3]); /* open the target VRML file, "voxel.wrl" */ fp = fopen("voxel.wrl", "w"); fprintf(fp, "#VRML V2.0 utf8\n\n"); /* draw the cube and the sphere */ fprintf(fp, "Background { skyColor 1 1 1 }\n"); fprintf(fp, "NavigationInfo { type \"EXAMINE\"}\n"); fprintf(fp, "Shape {\n"); fprintf(fp, "\tappearance Appearance { material Material { diffuseColor 0 0 1 }}\n"); fprintf(fp, "\tgeometry Box { size %lf %lf %lf}\n",WIDTH, HEIGHT, DEPTH); fprintf(fp, "}\n"); fprintf(fp, "Transform {\n"); fprintf(fp, "\ttranslation %lf %lf %lf\n",x0,y0,z0); fprintf(fp, "\tchildren Shape {\n"); fprintf(fp, "\t\tgeometry Sphere { radius %lf }\n", RADIUS); fprintf(fp, "\t\tappearance Appearance { material Material { diffuseColor 1 0 0 }}\n"); fprintf(fp, "\t}\n"); fprintf(fp, "}\n"); fprintf(fp, "Transform {\n"); fprintf(fp, "\ttranslation 0.0 %lf 0.0\n",1.5*BOXSIZE); fprintf(fp, "\tchildren [\n"); /* * visit each voxel and draw a cube if the voxel center is inside * the solid defined as: Solid = Cube -* Sphere. */ for(k=0; k<NDIV; k++){ for(j=0; j<NDIV; j++){ for(i=0; i<NDIV; i++){ x = BOXPOSX + i*cellsize; y = BOXPOSY + j*cellsize; z = BOXPOSZ + k*cellsize; if ( in_cube(x,y,z) == 1 && in_sphere(x,y,z,x0,y0,z0) == 0 ) { fprintf(fp, "\tTransform {\n"); fprintf(fp, "\t\ttranslation %lf %lf %lf\n",x,y,z); fprintf(fp, "\t\tchildren Shape {\n"); fprintf(fp, "\t\t\tappearance Appearance { material Material { diffuseColor 0 0 1 }}\n"); fprintf(fp, "\t\t\tgeometry Box {size %lf %lf %lf}\n", 0.9*cellsize,0.9*cellsize,0.9*cellsize); fprintf(fp, "\t\t}\n"); fprintf(fp, "\t},\n"); } } } } fprintf(fp, "\t]\n"); // close children fprintf(fp, "}\n"); // close Transform /* close the target VRML file "output.wrl" */ fclose(fp); }