squared_distance_t squaredDistanceSegmentTriangle3D( const Segment_3& sAB, const Triangle_3& tABC ) { typedef Kernel::FT squared_distance_t ; /* * If [sAsB] intersects the triangle (tA,tB,tC), distance is 0.0 */ if ( boost::none != CGAL::intersection( sAB, tABC ) ) { return 0.0 ; } /* * else, distance is the min of the following values : * - distance from sA to the Triangle * - distance from sB to the Triangle * - distance from sAB to the side of the Triangles */ squared_distance_t dMin = squaredDistancePointTriangle3D( sAB.vertex( 0 ), tABC ); dMin = std::min( dMin, squaredDistancePointTriangle3D( sAB.vertex( 1 ), tABC ) ); for ( int i = 0; i < 3; i++ ) { dMin = std::min( dMin, CGAL::squared_distance( sAB, Segment_3( tABC.vertex( i ), tABC.vertex( i+1 ) ) ) ) ; } return dMin ; }
std::string pp(const Segment_3& segment) { std::stringstream out; out << std::setprecision(pp_precision); out << "[" << pp(segment.source()) << ", " << pp(segment.target()) << "]"; return out.str(); }
std::string pp_id(const Segment_3& segment) { std::stringstream out; size_t a = segment.source().id(); size_t b = segment.target().id(); if (a > b) swap(a, b); out << a << "--" << b; return out.str(); }
double errorOfLineInPlane(Segment_3 &l, Eigen::Vector3d& point, Eigen::Vector3d& normal) { Plane_3 plane( Point_3(point.x(), point.y(), point.z()), Vector_3(normal.x(), normal.y(), normal.z()) ); double dist1 = squared_distance(plane, l.point(0)); double dist2 = squared_distance(plane, l.point(1)); return 0.5*(sqrt(dist1)+sqrt(dist2)); }
void Viewer::draw() { if( m_pScene == NULL ) return; QFont fontPrompt("Arial", 14); if( m_showAxis ) { qglColor(::Qt::black); drawAxis( sceneRadius() ); } /* Draw vertices */ if ( m_showVertex && m_pScene->m_dt.number_of_vertices()>0 ) { for(QList<Vertex_handle>::iterator vit = m_pScene->m_vhArray.begin(); vit < m_pScene->m_vhArray.end(); ++vit) { if( m_curMode == SELECT && (*vit)->isSeled() ) continue; if( (*vit) == m_nearestNb ) continue; drawVertex( (*vit)->point(), m_colorVertex, m_fSizeVertex ); }//end-for-points }//end-if-points /* Draw all points during incremental mode */ if( !m_incrementalPts.isEmpty() ) { /* draw the rest to-be-inserted vertices */ for(QList<Point_3>::iterator pit=m_incrementalPts.begin(); pit < m_incrementalPts.end(); ++pit) { drawVertex( (*pit), ::Qt::gray, m_fSizeVertex ); } switch( m_curStep ) { case NEWPT: /* Show prompt messages */ qglColor( ::Qt::black ); drawText( 10, 20, tr("Highlight the next-to-insert point"), fontPrompt ); /* Highlight the next-to-insert point */ drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex ); break; case CELL: // show the tetrahedron that contains the point /* Show prompt messages */ qglColor( ::Qt::black ); drawText( 10, 20, tr("Show the tetrahedron containing the point"), fontPrompt ); drawText( 10, 40, tr("(Only finite facets are drawn)"), fontPrompt ); /* Highlight the next-to-insert vertex */ drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex ); /* Draw the cell containing that point */ for(int i=0; i<4; ++i) { if( m_pScene->m_dt.is_infinite(m_cellContain, i) ) continue; drawFacet( m_pScene->m_dt.triangle( m_cellContain, i ), m_colorFacet ); }//end-for-facets break; case CONFLICT: // show the conflict region /* Show prompt messages */ qglColor( ::Qt::black ); drawText( 10, 20, tr("Show the conflict region"), fontPrompt ); /* Highlight the next-to-insert vertex */ drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex ); /* Draw conflict region */ for(QList<Facet>::iterator fit = m_boundaryFacets.begin(); fit < m_boundaryFacets.end(); ++fit) { if( m_pScene->m_dt.is_infinite(*fit) ) continue; drawFacet( m_pScene->m_dt.triangle(*fit), QColor(215, 80, 0, 96) ); //semi-transparent purple }//end-for-facets break; default: break; }//end-of=switch }//end-if-incpts /* Draw Delaunay edges */ if( m_showDEdge ) { for(edges_iterator eit = m_pScene->m_dt.finite_edges_begin(); eit != m_pScene->m_dt.finite_edges_end(); ++eit) { Segment_3 seg = m_pScene->m_dt.segment(*eit); drawEdge( seg.vertex(0), seg.vertex(1), m_colorDEdge, m_fSizeDEdge ); }//end-for-edges }//end-if-dt /* Draw Voronoi edges */ if( m_showVEdge ) { for(facets_iterator fit = m_pScene->m_dt.finite_facets_begin(); fit != m_pScene->m_dt.finite_facets_end(); ++fit) { Object_3 o = m_pScene->m_dt.dual(*fit); if (const Segment_3 *s = CGAL::object_cast<Segment_3>(&o)) { drawEdge( s->vertex(0), s->vertex(1), m_colorVEdge, m_fSizeVEdge ); } else if (const Ray_3 *r = CGAL::object_cast<Ray_3>(&o)) { drawEdge( r->point(0), // the source of the ray r->point(1), // another point on the ray, different from the source m_colorVEdge, m_fSizeVEdge ); } }//end-for-edges }//end-if-vd /* Draw facets */ if( m_showFacet ) { for(facets_iterator fit = m_pScene->m_dt.finite_facets_begin(); fit != m_pScene->m_dt.finite_facets_end(); ++fit) { drawFacet( m_pScene->m_dt.triangle(*fit), m_colorFacet ); }//end-for-facets }//end-if-facets /* Insert vertex mode */ if( m_curMode == INSERT_V ) { /* Show prompt messages */ qglColor( ::Qt::black ); drawText( width()-200, 20, tr("Shift+Left: Insert a vertex"), fontPrompt ); drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); /* Draw the trackball */ drawSphere( m_fRadius, m_colorTrackball ); }//end-if-insv /* Insert point mode */ else if( m_curMode == INSERT_PT ) { /* Show prompt messages */ qglColor( ::Qt::black ); drawText( width()-200, 20, tr("Shift+Left: Insert a point"), fontPrompt ); drawText( width()-200, 40, tr("Hold Left: Move the point"), fontPrompt ); drawText( width()-200, 60, tr("Return: Insert to DT"), fontPrompt ); drawText( width()-200, 80, tr("Escape: Cancel insertion"), fontPrompt ); drawText( width()-200, 100, tr("Shift+Wheel: Resize trackball"), fontPrompt ); /* Draw the trackball */ drawSphere( m_fRadius, m_colorTrackball ); if( m_hasNewPt ) { /* Draw the newly inserted point */ drawVertex( m_newPt, ::Qt::red, m_fSizeVertex ); /* Draw conflict region */ for(QList<Facet>::iterator fit = m_boundaryFacets.begin(); fit < m_boundaryFacets.end(); ++fit) { if( m_pScene->m_dt.is_infinite(*fit) ) continue; drawFacet( m_pScene->m_dt.triangle(*fit), QColor(215, 80, 0, 96) ); //semi-transparent purple }//end-for-facets }//end-if-shown }//end-if-inspt /* Select mode */ else if( m_curMode == SELECT) { /* Show prompt messages */ qglColor( ::Qt::black ); drawText( width()-200, 20, tr("Shift+Left: Select"), fontPrompt ); drawText( width()-200, 40, tr("Ctrl+Left: Add selection"), QFont("Arial", 14) ); drawText( width()-200, 60, tr("Escape: Cancel selection"), fontPrompt ); drawText( width()-200, 80, tr("DEL: Delete selected"), fontPrompt ); /* Highlight the selected vertices */ for(QList<int>::iterator vit=m_vidSeled.begin(); vit<m_vidSeled.end(); ++vit) { drawVertex( m_pScene->m_vhArray.at(*vit)->point(), ::Qt::red, m_fSizeVertex ); }//end-for-seledpts /* Draw the multiple selection window */ if( m_isPress ) { ::glDisable( GL_LIGHTING ); startScreenCoordinatesSystem(); qglColor( QColor(80, 180, 180, 64) ); ::glBegin(GL_QUADS); ::glVertex2i(m_rectSel.left(), m_rectSel.top()); ::glVertex2i(m_rectSel.right(), m_rectSel.top()); ::glVertex2i(m_rectSel.right(), m_rectSel.bottom()); ::glVertex2i(m_rectSel.left(), m_rectSel.bottom()); ::glEnd(); stopScreenCoordinatesSystem(); ::glEnable( GL_LIGHTING ); }//end-if-press }//end-if-sel /* Move mode */ else if( m_curMode == MOVE ) { /* Show prompt messages */ qglColor( ::Qt::black ); drawText( width()-200, 20, tr("Left Click: Select"), fontPrompt ); if( m_isMoving ) { drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); /* Draw the trackball */ drawSphere( m_fRadius, m_colorTrackball ); /* Highlight the moving point */ drawVertex( m_pScene->m_vhArray.at( m_vidMoving )->point(), ::Qt::red, m_fSizeVertex ); }//end-if-v }//end-if-move /* FindNb mode */ else if( m_curMode == FINDNB ) { /* Show prompt messages */ qglColor( ::Qt::black ); drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); /* Draw the trackball */ drawSphere( m_fRadius, m_colorTrackball ); /* Draw the nearest neighbor */ if( m_nearestNb != NULL ) { drawVertex( m_queryPt, ::Qt::red, m_fSizeVertex ); drawVertex( m_nearestNb->point(), ::Qt::red, m_fSizeVertex ); } }//end-if-findnb /* EmptySphere mode */ else if( m_curMode == EMPTYSPH ) { /* Show prompt messages */ qglColor( ::Qt::black ); drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); drawText( width()-200, 40, tr("Press S: Show/Hide trackball"), fontPrompt ); drawText( width()-200, 60, tr("Shift+Wheel: Resize trackball"), fontPrompt ); /* Draw the trackball */ if( m_showTrackball ) drawSphere( m_fRadius, m_colorTrackball ); if( m_hasEmptyS ) { /* Draw the query point */ drawVertex( m_queryPt, ::Qt::red, m_fSizeVertex ); /* Draw the cell containing that point */ for(int i=0; i<4; ++i) { if( m_pScene->m_dt.is_infinite(m_cellContain, i) ) continue; drawFacet( m_pScene->m_dt.triangle( m_cellContain, i ), m_colorFacet ); }//end-for-facets /* Draw the sphere */ drawSphere( m_fREmptyS, m_colorEmptySphere, m_centerPt ); } }//end-if-emptyS }
Segment_2 project_2(const Segment_3& s) { return Segment_2(s.source().point_2(), s.target().point_2()); }
Segment_3 lexicographically_ordered(const Segment_3& s) { if (CGAL::lexicographically_xyz_smaller(s.source(), s.target())) return s; return s.opposite(); }
void Viewer::compute_elements() { //glColor3f(1.0f, 0.72f, 0.06f); pos_points.resize(0); pos_lines.resize(0); pos_8lines.resize(0); pos_8lines2D.resize(0); for(Periodic_point_iterator ppit = scene->periodic_triangulation.periodic_points_begin( P3DT3::UNIQUE) ; ppit != scene->periodic_triangulation.periodic_points_end(P3DT3::UNIQUE); ++ppit){ Point_3 p(scene->periodic_triangulation.point(*ppit)); pos_points.push_back(p.x()); pos_points.push_back(p.y()); pos_points.push_back(p.z()); } //glColor3f(0.27f, 0.51f, 0.7f); for (Periodic_triangle_iterator ptit = scene->periodic_triangulation.periodic_triangles_begin( P3DT3::UNIQUE); ptit != scene->periodic_triangulation.periodic_triangles_end( P3DT3::UNIQUE); ++ptit) { for (int i=0 ; i<4 ; i++) { Segment_3 dual = scene->periodic_triangulation.construct_segment( scene->periodic_triangulation.dual(*(ptit.get_facet()))); FT sz = dual.source().z(); FT tz = dual.target().z(); if (scene->two_dimensional && ((sz-tz > 0.5) || (sz-tz < -0.5))) continue; if (scene->two_dimensional) { sz = 0.; tz = 0.; } FT sx = dual.source().x(); FT tx = dual.target().x(); FT sy = dual.source().y(); FT ty = dual.target().y(); pos_lines.push_back(sx); pos_lines.push_back(sy); pos_lines.push_back(sz); pos_lines.push_back(tx); pos_lines.push_back(ty); pos_lines.push_back(tz); Iso_cuboid_3 d = scene->periodic_triangulation.domain(); pos_8lines2D.push_back(sx+0.); pos_8lines2D.push_back(sy+d.ymax()-d.ymin()); pos_8lines2D.push_back(sz+0.); pos_8lines2D.push_back(tx+0.); pos_8lines2D.push_back(ty+d.ymax()-d.ymin()); pos_8lines2D.push_back(tz+0.); pos_8lines2D.push_back(sx+d.xmax()-d.xmin()); pos_8lines2D.push_back(sy+0.); pos_8lines2D.push_back(sz+0.); pos_8lines2D.push_back(tx+d.xmax()-d.xmin()); pos_8lines2D.push_back(ty+0.); pos_8lines2D.push_back(tz+0.); pos_8lines2D.push_back(sx+d.xmax()-d.xmin()); pos_8lines2D.push_back(sy+d.ymax()-d.ymin()); pos_8lines2D.push_back(sz+0.); pos_8lines2D.push_back(tx+d.xmax()-d.xmin()); pos_8lines2D.push_back(ty+d.ymax()-d.ymin()); pos_8lines2D.push_back(tz+0.); pos_8lines.push_back(sx+0.); pos_8lines.push_back(sy+0.); pos_8lines.push_back(sz+d.zmax()-d.zmin()); pos_8lines.push_back(tx+0.); pos_8lines.push_back(ty+0.); pos_8lines.push_back(tz+d.zmax()-d.zmin()); pos_8lines.push_back(sx+0.); pos_8lines.push_back(sy+d.ymax()-d.ymin()); pos_8lines.push_back(sz+d.zmax()-d.zmin()); pos_8lines.push_back(tx+0.); pos_8lines.push_back(ty+d.ymax()-d.ymin()); pos_8lines.push_back(tz+d.zmax()-d.zmin()); pos_8lines.push_back(sx+d.xmax()-d.xmin()); pos_8lines.push_back(sy+0.); pos_8lines.push_back(sz+d.zmax()-d.zmin()); pos_8lines.push_back(tx+d.xmax()-d.xmin()); pos_8lines.push_back(ty+0.); pos_8lines.push_back(tz+d.zmax()-d.zmin()); pos_8lines.push_back(sx+d.xmax()-d.xmin()); pos_8lines.push_back(sy+d.ymax()-d.ymin()); pos_8lines.push_back(sz+d.zmax()-d.zmin()); pos_8lines.push_back(tx+d.xmax()-d.xmin()); pos_8lines.push_back(ty+d.ymax()-d.ymin()); pos_8lines.push_back(tz+d.zmax()-d.zmin()); } } }
void Viewer::gl_draw_surface() { ::glColor3f(1.0f, 0.72f, 0.06f); ::glDisable(GL_LIGHTING); ::glEnable(GL_BLEND); ::glEnable(GL_POINT_SMOOTH); ::glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); ::glEnable(GL_LINE_SMOOTH); ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ::glPointSize(5); ::glBegin(GL_POINTS); for(Periodic_point_iterator ppit = scene->periodic_triangulation.periodic_points_begin( P3DT3::UNIQUE) ; ppit != scene->periodic_triangulation.periodic_points_end(P3DT3::UNIQUE); ++ppit){ Point_3 p(scene->periodic_triangulation.point(*ppit)); ::glVertex3d(p.x(), p.y(), p.z()); } ::glEnd(); ::glBegin(GL_LINES); ::glColor3f(0.27f, 0.51f, 0.7f); for (Periodic_triangle_iterator ptit = scene->periodic_triangulation.periodic_triangles_begin( P3DT3::UNIQUE); ptit != scene->periodic_triangulation.periodic_triangles_end( P3DT3::UNIQUE); ++ptit) { for (int i=0 ; i<4 ; i++) { Segment_3 dual = scene->periodic_triangulation.segment( scene->periodic_triangulation.dual(*(ptit.get_facet()))); FT sz = dual.source().z(); FT tz = dual.target().z(); if (scene->two_dimensional && ((sz-tz > 0.5) || (sz-tz < -0.5))) continue; if (scene->two_dimensional) { sz = 0.; tz = 0.; } FT sx = dual.source().x(); FT tx = dual.target().x(); FT sy = dual.source().y(); FT ty = dual.target().y(); ::glVertex3d(sx,sy,sz); ::glVertex3d(tx,ty,tz); Iso_cuboid_3 d = scene->periodic_triangulation.domain(); if (scene->eight_copies) { ::glColor3f(0.69f, 0.77f, 0.87f); ::glVertex3d(sx+0.,sy+d.ymax()-d.ymin(),sz+0.); ::glVertex3d(tx+0.,ty+d.ymax()-d.ymin(),tz+0.); ::glVertex3d(sx+d.xmax()-d.xmin(),sy+0.,sz+0.); ::glVertex3d(tx+d.xmax()-d.xmin(),ty+0.,tz+0.); ::glVertex3d(sx+d.xmax()-d.xmin(),sy+d.ymax()-d.ymin(),sz+0.); ::glVertex3d(tx+d.xmax()-d.xmin(),ty+d.ymax()-d.ymin(),tz+0.); if (!scene->two_dimensional) { ::glVertex3d(sx+0.,sy+0.,sz+d.zmax()-d.zmin()); ::glVertex3d(tx+0.,ty+0.,tz+d.zmax()-d.zmin()); ::glVertex3d(sx+0.,sy+d.ymax()-d.ymin(),sz+d.zmax()-d.zmin()); ::glVertex3d(tx+0.,ty+d.ymax()-d.ymin(),tz+d.zmax()-d.zmin()); ::glVertex3d(sx+d.xmax()-d.xmin(),sy+0.,sz+d.zmax()-d.zmin()); ::glVertex3d(tx+d.xmax()-d.xmin(),ty+0.,tz+d.zmax()-d.zmin()); ::glVertex3d(sx+d.xmax()-d.xmin(),sy+d.ymax()-d.ymin(),sz+d.zmax()-d.zmin()); ::glVertex3d(tx+d.xmax()-d.xmin(),ty+d.ymax()-d.ymin(),tz+d.zmax()-d.zmin()); } ::glColor3f(0.27f, 0.51f, 0.7f); } } } ::glEnd(); ::glEnable(GL_LIGHTING); }
bool Boundary_slice_chords::retired(const Segment_3& chord) { return (_retired.find(chord) != _retired.end() || _retired.find(chord.opposite()) != _retired.end()); }