How to access points' corrdinate of the edge

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to access points' corrdinate of the edge

Yongzhou Gu
Hi,

My final purpose is to constrain some edges during isotropic_remseshing with proper splits on these edges.
However, when I use split_long_edge, the original edges are replaced by the new shorter edges. Thus the original constrained edges are no longer exist. 
So, I tried to reset the constrained_edge_map. This requires me to determine whether the edge lies on the original long edge which is split by the function before. Thus I need to get the coordinates of both end of an edge to compare the position with the original long edge.

I've got iterator of edge descriptor now and I want to get the points' coordinates of both ends. But I don't know how to get it from an edge descriptor. Follows is my code:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/remesh.h>
#include <CGAL/Polygon_mesh_processing/border.h>
#include <boost/function_output_iterator.hpp>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <stdio.h>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef boost::graph_traits<Mesh>::edge_descriptor     edge_descriptor;
typedef boost::graph_traits<Mesh>::vertex_descriptor     vertex_descriptor;
namespace PMP = CGAL::Polygon_mesh_processing;
struct halfedge2edge
{
  halfedge2edge(const Mesh& m, std::vector<edge_descriptor>& edges)
    : m_mesh(m), m_edges(edges)
  {}
  void operator()(const halfedge_descriptor& h) const
  {
    m_edges.push_back(edge(h, m_mesh));
  }
  const Mesh& m_mesh;
  std::vector<edge_descriptor>& m_edges;
};
int main(int argc, char* argv[])
{
  Mesh mesh;

  vertex_descriptor vd[12];
  vd[0] = mesh.add_vertex(K::Point_3(0,0,0));   // cons
  vd[1] = mesh.add_vertex(K::Point_3(1,0,0));
  vd[2] = mesh.add_vertex(K::Point_3(2,0,0));
  vd[3] = mesh.add_vertex(K::Point_3(0,1,0));
  vd[4] = mesh.add_vertex(K::Point_3(1,1,0));   // cons
  vd[5] = mesh.add_vertex(K::Point_3(2,1,0));
  vd[6] = mesh.add_vertex(K::Point_3(0,2,0));
  vd[7] = mesh.add_vertex(K::Point_3(1,2,0));   // cons
  vd[8] = mesh.add_vertex(K::Point_3(2,2,0));
  vd[9] = mesh.add_vertex(K::Point_3(0,3,0));
  vd[10] = mesh.add_vertex(K::Point_3(1,3,0));
  vd[11] = mesh.add_vertex(K::Point_3(2,3,0));  // cons

  mesh.add_face(vd[0], vd[1], vd[4]);
  mesh.add_face(vd[1], vd[2], vd[5]);
  mesh.add_face(vd[0], vd[4], vd[3]);
  mesh.add_face(vd[1], vd[5], vd[4]);
  mesh.add_face(vd[3], vd[4], vd[7]);
  mesh.add_face(vd[4], vd[5], vd[8]);
  mesh.add_face(vd[3], vd[7], vd[6]);
  mesh.add_face(vd[4], vd[8], vd[7]);
  mesh.add_face(vd[6], vd[7], vd[10]);
  mesh.add_face(vd[7], vd[8], vd[11]);
  mesh.add_face(vd[6], vd[10], vd[9]);
  mesh.add_face(vd[7], vd[11], vd[10]);

  double target_edge_length;
  std::cout << "input tartget_edge_length: ";
  std::cin >> target_edge_length;
  unsigned int nb_iter = 3;
  //std::cin >> nb_iter;
  std::cout << "Split border...";

  std::vector<edge_descriptor> border;



  std::map<edge_descriptor, bool> edgeMap;
  boost::associative_property_map< std::map<edge_descriptor, bool> >
    edge_map(edgeMap);

  std::map<vertex_descriptor, bool> vertexMap;
  boost::associative_property_map< std::map<vertex_descriptor, bool> >
    vertex_map(vertexMap);



  Mesh::Edge_range::iterator  eb, ee;
  Mesh::Edge_range r = mesh.edges();
  eb = r.begin();
  ee = r.end();
  auto it = eb;

// Let's split the outiside boundary

double outside_boundary_split_length = 0.1;
  std::cin >> outside_boundary_split_length;

// split the selected border
  for (; it != r.end(); it++){
        border.push_back(*it);
        edgeMap.insert(std::make_pair(*it, 
          true));
  }
printf("boder size = %d\n", border.size());
  
PMP::split_long_edges(border, outside_boundary_split_length, mesh);

// Set my constrained edge ends
  r = mesh.edges();
  it = r.begin();

int cnt = 0;

  for (; it != r.end(); it++){
/****************************** How do I get the coordinates of vertices here? ********************************************/

   it->???





    cnt ++;
  }
printf("num of edges %d\n", cnt);

  std::cout << "done." << std::endl;
  std::cout << "Start remeshing of "
    << " (" << num_faces(mesh) << " faces)..." << std::endl;
 
  PMP::isotropic_remeshing(
      faces(mesh),
      target_edge_length,
      mesh,
      PMP::parameters::number_of_iterations(nb_iter)
      .edge_is_constrained_map(edge_map)
      .protect_constraints(true)//i.e. protect border, here
      );

  //PMP::split_long_edges(border, target_edge_length, mesh);
  
  std::ofstream iso_off("isotropic.off");
  iso_off << mesh;
  iso_off.close();
  std::cout << "Remeshing done." << std::endl;
  return 0;
}



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to access points' corrdinate of the edge

Sebastien Loriot (GeometryFactory)
IIRC, the constrained edge map is updated. Meaning that if an edge was
split and that edge was contrained, sub-edges are then constrained.

Did you observe a different behavior?

Sebastien.

On 04/13/2017 09:20 PM, Yongzhou Gu wrote:

> Hi,
>
> My final purpose is to constrain some edges during isotropic_remseshing
> with proper splits on these edges.
> However, when I use split_long_edge, the original edges are replaced by
> the new shorter edges. Thus the original constrained edges are no longer
> exist.
> So, I tried to reset the constrained_edge_map. This requires me to
> determine whether the edge lies on the original long edge which is split
> by the function before. Thus I need to get the coordinates of both end
> of an edge to compare the position with the original long edge.
>
> I've got iterator of edge descriptor now and I want to get the points'
> coordinates of both ends. But I don't know how to get it from an edge
> descriptor. Follows is my code:
>
> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
> #include <CGAL/Surface_mesh.h>
> #include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
> #include <CGAL/Polygon_mesh_processing/remesh.h>
> #include <CGAL/Polygon_mesh_processing/border.h>
> #include <boost/function_output_iterator.hpp>
> #include <fstream>
> #include <vector>
> #include <map>
> #include <string>
> #include <stdio.h>
> #include <boost/property_map/property_map.hpp>
> #include <boost/graph/kruskal_min_spanning_tree.hpp>
>
> typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
> typedef CGAL::Surface_mesh<K::Point_3> Mesh;
> typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
> typedef boost::graph_traits<Mesh>::edge_descriptor     edge_descriptor;
> typedef boost::graph_traits<Mesh>::vertex_descriptor     vertex_descriptor;
> namespace PMP = CGAL::Polygon_mesh_processing;
> struct halfedge2edge
> {
>   halfedge2edge(const Mesh& m, std::vector<edge_descriptor>& edges)
>     : m_mesh(m), m_edges(edges)
>   {}
>   void operator()(const halfedge_descriptor& h) const
>   {
>     m_edges.push_back(edge(h, m_mesh));
>   }
>   const Mesh& m_mesh;
>   std::vector<edge_descriptor>& m_edges;
> };
> int main(int argc, char* argv[])
> {
>   Mesh mesh;
>
>   vertex_descriptor vd[12];
>   vd[0] = mesh.add_vertex(K::Point_3(0,0,0));   // cons
>   vd[1] = mesh.add_vertex(K::Point_3(1,0,0));
>   vd[2] = mesh.add_vertex(K::Point_3(2,0,0));
>   vd[3] = mesh.add_vertex(K::Point_3(0,1,0));
>   vd[4] = mesh.add_vertex(K::Point_3(1,1,0));   // cons
>   vd[5] = mesh.add_vertex(K::Point_3(2,1,0));
>   vd[6] = mesh.add_vertex(K::Point_3(0,2,0));
>   vd[7] = mesh.add_vertex(K::Point_3(1,2,0));   // cons
>   vd[8] = mesh.add_vertex(K::Point_3(2,2,0));
>   vd[9] = mesh.add_vertex(K::Point_3(0,3,0));
>   vd[10] = mesh.add_vertex(K::Point_3(1,3,0));
>   vd[11] = mesh.add_vertex(K::Point_3(2,3,0));  // cons
>
>   mesh.add_face(vd[0], vd[1], vd[4]);
>   mesh.add_face(vd[1], vd[2], vd[5]);
>   mesh.add_face(vd[0], vd[4], vd[3]);
>   mesh.add_face(vd[1], vd[5], vd[4]);
>   mesh.add_face(vd[3], vd[4], vd[7]);
>   mesh.add_face(vd[4], vd[5], vd[8]);
>   mesh.add_face(vd[3], vd[7], vd[6]);
>   mesh.add_face(vd[4], vd[8], vd[7]);
>   mesh.add_face(vd[6], vd[7], vd[10]);
>   mesh.add_face(vd[7], vd[8], vd[11]);
>   mesh.add_face(vd[6], vd[10], vd[9]);
>   mesh.add_face(vd[7], vd[11], vd[10]);
>
>   double target_edge_length;
>   std::cout << "input tartget_edge_length: ";
>   std::cin >> target_edge_length;
>   unsigned int nb_iter = 3;
>   //std::cin >> nb_iter;
>   std::cout << "Split border...";
>
>   std::vector<edge_descriptor> border;
>
>
>
>   std::map<edge_descriptor, bool> edgeMap;
>   boost::associative_property_map< std::map<edge_descriptor, bool> >
>     edge_map(edgeMap);
>
>   std::map<vertex_descriptor, bool> vertexMap;
>   boost::associative_property_map< std::map<vertex_descriptor, bool> >
>     vertex_map(vertexMap);
>
>
>
>   Mesh::Edge_range::iterator  eb, ee;
>   Mesh::Edge_range r = mesh.edges();
>   eb = r.begin();
>   ee = r.end();
>   auto it = eb;
>
> // Let's split the outiside boundary
>
> double outside_boundary_split_length = 0.1;
>   std::cin >> outside_boundary_split_length;
>
> // split the selected border
>   for (; it != r.end(); it++){
>         border.push_back(*it);
>         edgeMap.insert(std::make_pair(*it,
>           true));
>   }
> printf("boder size = %d\n", border.size());
>
> PMP::split_long_edges(border, outside_boundary_split_length, mesh);
>
> // Set my constrained edge ends
>   r = mesh.edges();
>   it = r.begin();
>
> int cnt = 0;
>
>   for (; it != r.end(); it++){
> /****************************** How do I get the coordinates of vertices
> here? ********************************************/
>
>    it->???
>
>
>
>
>
>     cnt ++;
>   }
> printf("num of edges %d\n", cnt);
>
>   std::cout << "done." << std::endl;
>   std::cout << "Start remeshing of "
>     << " (" << num_faces(mesh) << " faces)..." << std::endl;
>
>   PMP::isotropic_remeshing(
>       faces(mesh),
>       target_edge_length,
>       mesh,
>       PMP::parameters::number_of_iterations(nb_iter)
>       .edge_is_constrained_map(edge_map)
>       .protect_constraints(true)//i.e. protect border, here
>       );
>
>   //PMP::split_long_edges(border, target_edge_length, mesh);
>
>   std::ofstream iso_off("isotropic.off");
>   iso_off << mesh;
>   iso_off.close();
>   std::cout << "Remeshing done." << std::endl;
>   return 0;
> }
>
>
>


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Loading...