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 ; }
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 }