static std::vector<SupportFunctionDataItem> extractSupportFunctionDataItems( SContour *contour, SupportFunctionDataItemExtractor *extractor) { /* Check that the input contour is correct. */ ASSERT(contour); ASSERT(contour->sides); ASSERT(contour->ns > 0); ASSERT(!!contour->plane.norm); /* Check that normal != 0 */ ASSERT(fabs(contour->plane.norm.z) < EPS_MIN_DOUBLE); std::vector<SupportFunctionDataItem> items; /* Iterate through the array of sides of current contour. */ for (int iSide = 0; iSide < contour->ns; ++iSide) { SideOfContour *side = &contour->sides[iSide]; SupportFunctionDataItem item = extractor->run(side); item.info = SupportFunctionDataItemInfoPtr(new SupportFunctionDataItemInfo()); item.info->iContour = contour->id; item.info->numSidesContour = contour->ns; item.info->iSide = iSide; item.info->segment = Segment_3(Point_3(side->A1), Point_3(side->A2)); item.info->normalShadow = contour->plane.norm; items.push_back(item); } DEBUG_END; return items; }
bool triDoesNotIntersectFacet (Polyhedron::Halfedge_handle& heH, bool isOpposite) { Segment_3 checkSeg (heH->vertex()->point(),heH->prev()->prev()->vertex()->point()); Polyhedron::Halfedge_around_facet_circulator hafIt = heH->facet_begin()++; // skip itself and first while (++hafIt != heH->prev()->facet_begin()) { if (CGAL::do_intersect(checkSeg,Segment_3(hafIt->vertex()->point(),hafIt->prev()->vertex()->point()))) return false; } if (!isOpposite) return triDoesNotIntersectFacet (heH->opposite(), true); else return true; }
Segment_3 project_3(const Segment_2& s) { return Segment_3(s.source().point_3(), s.target().point_3()); }
void Volume::display_surface_mesher_result() { if(m_surface.empty() || // Either the surface is not computed. m_view_surface) // Or it is computed and displayed, and one want // to recompute it. { QTime total_time; total_time.start(); values_list->save_values(fileinfo.absoluteFilePath()); std::size_t nx = m_image.xdim(); std::size_t ny = m_image.ydim(); std::size_t nz = m_image.zdim(); if(nx * ny * nz == 0) { status_message("No volume loaded."); return; } m_surface.clear(); sm_timer.reset(); busy(); status_message("Surface meshing..."); sm_timer.start(); c2t3.clear(); del.clear(); Sphere bounding_sphere(m_image.center(),m_image.radius()*m_image.radius()); Classify_from_isovalue_list classify(values_list); Generate_surface_identifiers generate_ids(values_list); m_image.set_interpolation(mw->interpolationCheckBox->isChecked()); if(mw->labellizedRadioButton->isChecked()) { std::cerr << "Labellized image\n"; } m_image.set_labellized(mw->labellizedRadioButton->isChecked()); classify.set_identity(mw->labellizedRadioButton->isChecked()); generate_ids.set_labellized_image(mw->labellizedRadioButton->isChecked()); // definition of the surface Surface_3 surface(m_image, bounding_sphere, m_relative_precision); // Threshold threshold(m_image.isovalue()); // surface mesh traits class typedef CGAL::Surface_mesher::Implicit_surface_oracle_3<Kernel, // typedef CGAL::Surface_mesher::Image_surface_oracle_3<Kernel, Surface_3, Classify_from_isovalue_list, Generate_surface_identifiers> Oracle; Oracle oracle(classify, generate_ids); if(mw->searchSeedsCheckBox->isChecked()) { typedef std::vector<std::pair<Point, double> > Seeds; Seeds seeds; { std::cerr << "Search seeds...\n"; std::set<unsigned char> domains; search_for_connected_components(std::back_inserter(seeds), CGAL::inserter(domains), classify); std::cerr << "Found " << seeds.size() << " seed(s).\n"; if(mw->labellizedRadioButton->isChecked() && values_list->numberOfValues() == 0) { Q_FOREACH(unsigned char label, domains) { if(label != 0) { values_list->addValue(label); } } } } std::ofstream seeds_out("seeds.off"); std::ofstream segments_out("segments.txt"); seeds_out.precision(18); seeds_out << "OFF\n" << seeds.size() << " 0 0\n"; segments_out.precision(18); for(Seeds::const_iterator it = seeds.begin(), end = seeds.end(); it != end; ++it) { seeds_out << it->first << std::endl; CGAL::Random_points_on_sphere_3<Point> random_points_on_sphere_3(it->second); Oracle::Intersect_3 intersect = oracle.intersect_3_object(); for(int i = 0; i < 20; ++i) { const Point test = it->first + (*random_points_on_sphere_3++ - CGAL::ORIGIN); CGAL::Object o = intersect(surface, Segment_3(it->first, test)); if (const Point* intersection = CGAL::object_cast<Point>(&o)) { segments_out << "2 " << it->first << " " << *intersection << std::endl; del.insert(*intersection); } else { std::cerr << boost::format("Error. Segment (%1%, %2%) does not intersect the surface! values=(%3%, %4%)\n") % it->first % test % surface(it->first) % surface(test); } } } }