Esempio n. 1
0
void Viewer::drawAllFaces(bool flat)
{
  LCC &lcc = *scene->lcc;

  for (LCC::Attribute_range<3>::type::iterator
         it=lcc.attributes<3>().begin(),
         itend=lcc.attributes<3>().end(); it!=itend; ++it )
  {
    if ( it->info().is_visible() )
    {
      for(LCC::One_dart_per_incident_cell_range<2,3>::iterator
            dartIter=lcc.one_dart_per_incident_cell<2,3>
            (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter)
      {
        // We draw the polygon
        ::glBegin(GL_POLYGON);

        //  double r = (double)dartIter->attribute<3>()->info().r()/255.0;
        double r = (double)lcc.info<3>(dartIter).color().r()/255.0;
        double g = (double)lcc.info<3>(dartIter).color().g()/255.0;
        double b = (double)lcc.info<3>(dartIter).color().b()/255.0;
        if ( !lcc.is_free(dartIter, 3) )
        {
          r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0;
          g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0;
          b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0;
          r /= 2; g /= 2; b /= 2;
        }

        ::glColor3f(r,g,b);

        if(flat)
        {
          LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter);
          normal = normal/(CGAL::sqrt(normal*normal));
          ::glNormal3d(normal.x(), normal.y(), normal.z());
        }

        for (LCC::Dart_of_orbit_range<1>::const_iterator
               orbitIter = lcc.darts_of_orbit<1>(dartIter).begin();
             orbitIter.cont(); ++orbitIter)
        {
          if(!flat)
          {
            // If Gouraud shading: 1 normal per vertex
            LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter);
            normal = normal/(CGAL::sqrt(normal*normal));
            ::glNormal3d(normal.x(), normal.y(), normal.z());
          }

          const LCC::Point& p = lcc.point(orbitIter);
          ::glVertex3d(p.x(),p.y(),p.z());
        }

        ::glEnd();
      }
    }
  }
}
Esempio n. 2
0
void Viewer::drawFacet(Dart_const_handle ADart)
{
    LCC &m = *scene->lcc;
    ::glBegin(GL_POLYGON);
    CGAL_assertion( ADart->attribute<3>()!=NULL );

    //  double r = (double)ADart->attribute<3>()->info().r()/255.0;
    double r = (double)ADart->attribute<3>()->info().color().r()/255.0;
    double g = (double)ADart->attribute<3>()->info().color().g()/255.0;
    double b = (double)ADart->attribute<3>()->info().color().b()/255.0;
    if ( !ADart->is_free(3) )
    {
        r += (double)ADart->beta(3)->attribute<3>()->info().color().r()/255.0;
        g += (double)ADart->beta(3)->attribute<3>()->info().color().g()/255.0;
        b += (double)ADart->beta(3)->attribute<3>()->info().color().b()/255.0;
        r /= 2;
        g /= 2;
        b /= 2;
    }

    ::glColor3f(r,g,b);

    // If Flat shading: 1 normal per polygon
    if (flatShading)
    {
        LCC::Vector n = CGAL::compute_normal_of_cell_2(m,ADart);
        n = n/(CGAL::sqrt(n*n));
        ::glNormal3d(n.x(),n.y(),n.z());
    }

    for ( LCC::Dart_of_orbit_range<1>::const_iterator it(m,ADart);
            it.cont(); ++it)
    {
        // If Gouraud shading: 1 normal per vertex
        if (!flatShading)
        {
            LCC::Vector n = CGAL::compute_normal_of_cell_0<LCC>(m,it);
            n = n/(CGAL::sqrt(n*n));
            ::glNormal3d(n.x(),n.y(),n.z());
        }

        LCC::Point p = m.point(it);
        ::glVertex3d( p.x(),p.y(),p.z());
    }
    ::glEnd();
}
Esempio n. 3
0
void Viewer::triangulate_facet()
{


    pos_facets.resize(0);
    flat_normals.resize(0);
    smooth_normals.resize(0);
    colors.resize(0);

    LCC &lcc = *scene->lcc;

    for (LCC::Attribute_range<3>::type::iterator
         it=lcc.attributes<3>().begin(),
         itend=lcc.attributes<3>().end(); it!=itend; ++it )
    {
        if ( it->info().is_visible() )
        {
            for(LCC::One_dart_per_incident_cell_range<2,3>::iterator
                dartIter=lcc.one_dart_per_incident_cell<2,3>
                (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter)
            {

                //Computes the normal of the facet
                Traits::Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc,dartIter);
                normal = normal/(CGAL::sqrt(normal*normal));

                P_traits cdt_traits(normal);
                CDT cdt(cdt_traits);

               LCC::Dart_of_orbit_range<1>::const_iterator
                 he_circ = lcc.darts_of_orbit<1>(dartIter).begin(),
                 he_circ_end = lcc.darts_of_orbit<1>(dartIter).end();

                // Iterates on the vector of facet handles
                CDT::Vertex_handle previous, first;
                do {
                    CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ));
                    if(first == 0) {
                        first = vh;
                    }
                    //vh->info() = he_circ;
                    if(previous != 0 && previous != vh) {
                        cdt.insert_constraint(previous, vh);
                    }
                    previous = vh;
                } while( ++he_circ != he_circ_end );
                cdt.insert_constraint(previous, first);

                // sets mark is_external
                for(CDT::All_faces_iterator
                    fit = cdt.all_faces_begin(),
                    end = cdt.all_faces_end();
                    fit != end; ++fit)
                {
                    fit->info().is_external = false;
                }
                //check if the facet is external or internal
                std::queue<CDT::Face_handle> face_queue;
                face_queue.push(cdt.infinite_vertex()->face());
                while(! face_queue.empty() ) {
                    CDT::Face_handle fh = face_queue.front();
                    face_queue.pop();
                    if(fh->info().is_external) continue;
                    fh->info().is_external = true;
                    for(int i = 0; i <3; ++i) {
                        if(!cdt.is_constrained(std::make_pair(fh, i)))
                        {
                            face_queue.push(fh->neighbor(i));
                        }
                    }
                }

                //iterates on the internal faces to add the vertices to the positions
                //and the normals to the appropriate vectors
                for(CDT::Finite_faces_iterator
                    ffit = cdt.finite_faces_begin(),
                    end = cdt.finite_faces_end();
                    ffit != end; ++ffit)
                {
                    if(ffit->info().is_external)
                        continue;

                    //compute normals (no smooth for non-triangle facets objects
                    LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter);
                    normal = normal/(CGAL::sqrt(normal*normal));

                     smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z());
                     smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z());
                     smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z());

                     flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z());
                     flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z());
                     flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z());



                    pos_facets.push_back(ffit->vertex(0)->point().x()); pos_facets.push_back(ffit->vertex(0)->point().y()); pos_facets.push_back(ffit->vertex(0)->point().z());
                    pos_facets.push_back(ffit->vertex(1)->point().x()); pos_facets.push_back(ffit->vertex(1)->point().y()); pos_facets.push_back(ffit->vertex(1)->point().z());
                     pos_facets.push_back(ffit->vertex(2)->point().x()); pos_facets.push_back(ffit->vertex(2)->point().y()); pos_facets.push_back(ffit->vertex(2)->point().z());

                     double r = (double)lcc.info<3>(dartIter).color().r()/255.0;
                     double g = (double)lcc.info<3>(dartIter).color().g()/255.0;
                     double b = (double)lcc.info<3>(dartIter).color().b()/255.0;
                     if ( !lcc.is_free(dartIter, 3) )
                     {
                       r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0;
                       g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0;
                       b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0;
                       r /= 2; g /= 2; b /= 2;
                     }
                     colors.push_back(r);colors.push_back(g);colors.push_back(b);
                     colors.push_back(r);colors.push_back(g);colors.push_back(b);
                     colors.push_back(r);colors.push_back(g);colors.push_back(b);


                }
            }
        }
    }
}
Esempio n. 4
0
void Viewer::compute_elements()
{

    //Facets
    if(is_Triangulated())
    {
        pos_facets.resize(0);
        flat_normals.resize(0);
        smooth_normals.resize(0);
        colors.resize(0);
        LCC &lcc = *scene->lcc;

        for (LCC::Attribute_range<3>::type::iterator
             it=lcc.attributes<3>().begin(),
             itend=lcc.attributes<3>().end(); it!=itend; ++it )
        {
            if ( it->info().is_visible() )
            {
                for(LCC::One_dart_per_incident_cell_range<2,3>::iterator
                    dartIter=lcc.one_dart_per_incident_cell<2,3>
                    (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter)
                {
                    // We draw the polygon


                    //  double r = (double)dartIter->attribute<3>()->info().r()/255.0;
                    float r = (float)lcc.info<3>(dartIter).color().r()/255.0;
                    float g = (float)lcc.info<3>(dartIter).color().g()/255.0;
                    float b = (float)lcc.info<3>(dartIter).color().b()/255.0;
                    if ( !lcc.is_free(dartIter, 3) )
                    {
                        r += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0;
                        g += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0;
                        b += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0;
                        r /= 2; g /= 2; b /= 2;
                    }

                    colors.push_back(r);colors.push_back(g);colors.push_back(b);
                    colors.push_back(r);colors.push_back(g);colors.push_back(b);
                    colors.push_back(r);colors.push_back(g);colors.push_back(b);
                    //compute flat normals
                    LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter);
                    normal = normal/(CGAL::sqrt(normal*normal));
                    flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z());
                    flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z());
                    flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z());



                    for (LCC::Dart_of_orbit_range<1>::const_iterator
                         orbitIter = lcc.darts_of_orbit<1>(dartIter).begin();
                         orbitIter.cont(); ++orbitIter)
                    {
                        //compute Smooth normals
                        LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter);
                        normal = normal/(CGAL::sqrt(normal*normal));
                        smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z());

                        const LCC::Point& p = lcc.point(orbitIter);
                        pos_facets.push_back(p.x()); pos_facets.push_back(p.y()); pos_facets.push_back(p.z());
                    }

                }
            }
        }

    }
    else
        triangulate_facet();

    //Edges
    {
        pos_lines.resize(0);
        LCC &lcc = *scene->lcc;

        if ( !lcc.is_empty() )
        {

            for (LCC::Attribute_range<3>::type::iterator
                 it=lcc.attributes<3>().begin(),
                 itend=lcc.attributes<3>().end(); it!=itend; ++it )
            {
                if ( it->info().is_visible() )
                {
                    for(LCC::One_dart_per_incident_cell_range<1,3>::iterator
                        dartIter=lcc.one_dart_per_incident_cell<1,3>
                        (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter)
                    {
                        const LCC::Point& p =  lcc.point(dartIter);
                        Dart_handle d2 = lcc.other_extremity(dartIter);
                        if ( d2!=NULL )
                        {
                            const LCC::Point& p2 = lcc.point(d2);
                            pos_lines.push_back(p.x()); pos_lines.push_back(p.y()); pos_lines.push_back(p.z());
                            pos_lines.push_back(p2.x()); pos_lines.push_back(p2.y()); pos_lines.push_back(p2.z());
                        }
                    }
                }
            }

        }
    }
    //Points
    {
        pos_points.resize(0);
        LCC &lcc = *scene->lcc;

        if ( lcc.is_empty() )
        {
            bb = LCC::Point(CGAL::ORIGIN).bbox();
            bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer
            return;
        }

        bool empty = true;
        for (LCC::Attribute_range<3>::type::iterator
             it=lcc.attributes<3>().begin(),
             itend=lcc.attributes<3>().end(); it!=itend; ++it )
        {
            if ( it->info().is_visible() )
            {
                for(LCC::One_dart_per_incident_cell_range<0,3>::iterator
                    dartIter=lcc.one_dart_per_incident_cell<0,3>
                    (lcc.dart_of_attribute<3>(it)).begin();
                    dartIter.cont(); ++dartIter)
                {
                    const LCC::Point& p =  lcc.point(dartIter);
                    pos_points.push_back(p.x()); pos_points.push_back(p.y()); pos_points.push_back(p.z());

                    if ( empty )
                    {
                        bb = p.bbox();
                        empty = false;
                    }
                    else
                        bb = bb + p.bbox();
                }
            }
        }


        if ( lcc.is_empty() )
        {
            bb = LCC::Point(CGAL::ORIGIN).bbox();
            bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer
        }

    }

}
Esempio n. 5
0
void Viewer::compute_face(Dart_handle dh, LCC::size_type markface)
{
  LCC &lcc = *scene->lcc;

  CGAL::mark_cell<LCC, 2>(lcc, dh, markface);

  double r = (double)lcc.info<3>(dh).color().r()/255.0;
  double g = (double)lcc.info<3>(dh).color().g()/255.0;
  double b = (double)lcc.info<3>(dh).color().b()/255.0;
  if ( !lcc.is_free(dh, 3) )
  {
    r += (double)lcc.info<3>(lcc.beta(dh,3)).color().r()/255.0;
    g += (double)lcc.info<3>(lcc.beta(dh,3)).color().g()/255.0;
    b += (double)lcc.info<3>(lcc.beta(dh,3)).color().b()/255.0;
    r /= 2; g /= 2; b /= 2;
  }

  //compute flat normals
  LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dh);
  normal = normal/(CGAL::sqrt(normal*normal));

  if (lcc.beta<1,1,1>(dh)!=dh)
  {
    P_traits cdt_traits(normal);
    CDT cdt(cdt_traits);

    // Iterates on the vector of facet handles
    CDT::Vertex_handle previous = NULL, first = NULL;
    for (LCC::Dart_of_orbit_range<1>::const_iterator
           he_circ = lcc.darts_of_orbit<1>(dh).begin(),
           he_circ_end = lcc.darts_of_orbit<1>(dh).end();
         he_circ!=he_circ_end; ++he_circ)
    {
      CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ));
      if(first == NULL)
      { first = vh; }
      vh->info().v = CGAL::compute_normal_of_cell_0<LCC>(lcc, he_circ);
      if(previous!=NULL && previous != vh)
      { cdt.insert_constraint(previous, vh); }
      previous = vh;
    }
    if (previous!=NULL)
      cdt.insert_constraint(previous, first);

    // sets mark is_external
    for(CDT::All_faces_iterator fit = cdt.all_faces_begin(),
          fitend = cdt.all_faces_end(); fit!=fitend; ++fit)
    {
      fit->info().is_external = true;
      fit->info().is_process = false;
    }
    //check if the facet is external or internal
    std::queue<CDT::Face_handle> face_queue;
    CDT::Face_handle face_internal = NULL;
    face_queue.push(cdt.infinite_vertex()->face());
    while(! face_queue.empty() )
    {
      CDT::Face_handle fh = face_queue.front();
      face_queue.pop();
      if(!fh->info().is_process)
      {
        fh->info().is_process = true;
        for(int i = 0; i <3; ++i)
        {
          if(!cdt.is_constrained(std::make_pair(fh, i)))
          {
            face_queue.push(fh->neighbor(i));
          }
          else if (face_internal==NULL)
          {
            face_internal = fh->neighbor(i);
          }
        }
      }
    }

    if ( face_internal!=NULL )
      face_queue.push(face_internal);

    while(! face_queue.empty() )
    {
      CDT::Face_handle fh = face_queue.front();
      face_queue.pop();
      if(!fh->info().is_process)
      {
        fh->info().is_process = true;
        fh->info().is_external = false;
        for(int i = 0; i <3; ++i)
        {
          if(!cdt.is_constrained(std::make_pair(fh, i)))
          {
            face_queue.push(fh->neighbor(i));
          }
        }
      }
    }

    //iterates on the internal faces to add the vertices to the positions
    //and the normals to the appropriate vectors
    for(CDT::Finite_faces_iterator ffit = cdt.finite_faces_begin(),
          ffitend = cdt.finite_faces_end(); ffit != ffitend; ++ffit)
    {
      if(!ffit->info().is_external)
      {
        flat_normals.push_back(normal.x());
        flat_normals.push_back(normal.y());
        flat_normals.push_back(normal.z());

        flat_normals.push_back(normal.x());
        flat_normals.push_back(normal.y());
        flat_normals.push_back(normal.z());

        flat_normals.push_back(normal.x());
        flat_normals.push_back(normal.y());
        flat_normals.push_back(normal.z());

        smooth_normals.push_back(ffit->vertex(0)->info().v.x());
        smooth_normals.push_back(ffit->vertex(0)->info().v.y());
        smooth_normals.push_back(ffit->vertex(0)->info().v.z());

        smooth_normals.push_back(ffit->vertex(1)->info().v.x());
        smooth_normals.push_back(ffit->vertex(1)->info().v.y());
        smooth_normals.push_back(ffit->vertex(1)->info().v.z());

        smooth_normals.push_back(ffit->vertex(2)->info().v.x());
        smooth_normals.push_back(ffit->vertex(2)->info().v.y());
        smooth_normals.push_back(ffit->vertex(2)->info().v.z());

        pos_facets.push_back(ffit->vertex(0)->point().x());
        pos_facets.push_back(ffit->vertex(0)->point().y());
        pos_facets.push_back(ffit->vertex(0)->point().z());

        pos_facets.push_back(ffit->vertex(1)->point().x());
        pos_facets.push_back(ffit->vertex(1)->point().y());
        pos_facets.push_back(ffit->vertex(1)->point().z());

        pos_facets.push_back(ffit->vertex(2)->point().x());
        pos_facets.push_back(ffit->vertex(2)->point().y());
        pos_facets.push_back(ffit->vertex(2)->point().z());

        colors.push_back(r);colors.push_back(g);colors.push_back(b);
        colors.push_back(r);colors.push_back(g);colors.push_back(b);
        colors.push_back(r);colors.push_back(g);colors.push_back(b);
      }
    }
  }
  else
  {
    colors.push_back(r);colors.push_back(g);colors.push_back(b);
    colors.push_back(r);colors.push_back(g);colors.push_back(b);
    colors.push_back(r);colors.push_back(g);colors.push_back(b);

    flat_normals.push_back(normal.x());
    flat_normals.push_back(normal.y());
    flat_normals.push_back(normal.z());

    flat_normals.push_back(normal.x());
    flat_normals.push_back(normal.y());
    flat_normals.push_back(normal.z());

    flat_normals.push_back(normal.x());
    flat_normals.push_back(normal.y());
    flat_normals.push_back(normal.z());

    for (LCC::Dart_of_orbit_range<1>::const_iterator
           orbitIter = lcc.darts_of_orbit<1>(dh).begin();
         orbitIter.cont(); ++orbitIter)
    {
      //compute Smooth normals
      LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter);
      normal = normal/(CGAL::sqrt(normal*normal));

      smooth_normals.push_back(normal.x());
      smooth_normals.push_back(normal.y());
      smooth_normals.push_back(normal.z());

      const LCC::Point& p = lcc.point(orbitIter);
      pos_facets.push_back(p.x());
      pos_facets.push_back(p.y());
      pos_facets.push_back(p.z());
    }
  }
}