Beispiel #1
0
void MeshImplData::copy_mesh( size_t* vertex_handle_array,
                              size_t* element_handle_array,
                              size_t* element_conn_offsets,
                              size_t* element_conn_indices )
{
  std::vector<size_t> vertex_map( vertexList.size() );
  size_t vh_index = 0;
  for (size_t v = 0; v < vertexList.size(); ++v)
  {
    if (vertexList[v].valid
#ifdef SEPARATE_MID_NODES
        && vertexList[v].midcount < vertexList[v].adjacencies.size()
#endif
       )
    {
      vertex_handle_array[vh_index] = v;
      vertex_map[v] = vh_index;
      ++vh_index;
    }
    else
    {
      vertex_map[v] = vertexList.size();
    }
  }
  
  size_t offset = 0;
  for (size_t e = 0; e < elementList.size(); ++e)
  {
    Element& elem = elementList[e];
    size_t cl;
#ifdef SEPARATE_MID_NODES
    cl = TopologyInfo::corners( elem.topology );
    if (!cl)
#endif
      cl = elem.connectivity.size();
    if (cl)
    {
      *element_handle_array = e;
      ++element_handle_array;
      
      *element_conn_offsets = offset;
      ++element_conn_offsets;
      offset += cl;
    
      std::vector<size_t>::iterator conn = elem.connectivity.begin();
      std::vector<size_t>::iterator end = conn + cl;
      while (conn != end)
      {
        *element_conn_indices = vertex_map[*conn];
        ++element_conn_indices;
        ++conn;
      }
    }
  }
  *element_conn_offsets = offset;
}
Beispiel #2
0
  bool vtkPointSet_to_polygon_mesh(vtkPointSet* poly_data,
                                   TM& tmesh)
  {
    typedef typename boost::property_map<TM, CGAL::vertex_point_t>::type VPMap;
    typedef typename boost::property_map_value<TM, CGAL::vertex_point_t>::type Point_3;
    typedef typename boost::graph_traits<TM>::vertex_descriptor vertex_descriptor;

    VPMap vpmap = get(CGAL::vertex_point, tmesh);

    // get nb of points and cells
    vtkIdType nb_points = poly_data->GetNumberOfPoints();
    vtkIdType nb_cells = poly_data->GetNumberOfCells();

    //extract points
    std::vector<vertex_descriptor> vertex_map(nb_points);
    for (vtkIdType i = 0; i<nb_points; ++i)
    {
      double coords[3];
      poly_data->GetPoint(i, coords);

      vertex_descriptor v = add_vertex(tmesh);
      put(vpmap, v, Point_3(coords[0], coords[1], coords[2]));
      vertex_map[i]=v;
    }

    //extract cells
    for (vtkIdType i = 0; i<nb_cells; ++i)
    {
      if(poly_data->GetCellType(i) != 5
         && poly_data->GetCellType(i) != 7
         && poly_data->GetCellType(i) != 9) //only supported cells are triangles, quads and polygons
        continue;
      vtkCell* cell_ptr = poly_data->GetCell(i);

      vtkIdType nb_vertices = cell_ptr->GetNumberOfPoints();
      if (nb_vertices < 3)
        return false;
      std::vector<vertex_descriptor> vr(nb_vertices);
      for (vtkIdType k=0; k<nb_vertices; ++k)
        vr[k]=vertex_map[cell_ptr->GetPointId(k)];

      CGAL::Euler::add_face(vr, tmesh);
    }
    return true;
  }