generate_cube.hh 2.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#ifndef GENERATE_CUBE_HH
#define GENERATE_CUBE_HH

template <typename MeshType>
size_t generate_cube( MeshType& mesh )
{
  typedef typename MeshType::VertexHandle VertexHandle;
  typedef typename MeshType::Point Point;

  typename MeshType::VertexHandle vhandle[8];

  vhandle[0] = mesh.add_vertex(Point(-1, -1,  1));
  vhandle[1] = mesh.add_vertex(Point( 1, -1,  1));
  vhandle[2] = mesh.add_vertex(Point( 1,  1,  1));
  vhandle[3] = mesh.add_vertex(Point(-1,  1,  1));
  vhandle[4] = mesh.add_vertex(Point(-1, -1, -1));
  vhandle[5] = mesh.add_vertex(Point( 1, -1, -1));
  vhandle[6] = mesh.add_vertex(Point( 1,  1, -1));
  vhandle[7] = mesh.add_vertex(Point(-1,  1, -1));

  // generate (quadrilateral) faces

  std::vector< VertexHandle >  face_vhandles;

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[3]);
  mesh.add_face(face_vhandles);
 
  face_vhandles.clear();
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[6]);
  face_vhandles.push_back(vhandle[5]);
  face_vhandles.push_back(vhandle[4]);
  mesh.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[4]);
  face_vhandles.push_back(vhandle[5]);
  mesh.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[5]);
  face_vhandles.push_back(vhandle[6]);
  mesh.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[6]);
  face_vhandles.push_back(vhandle[7]);
  mesh.add_face(face_vhandles);

  face_vhandles.clear();
  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[7]);
  face_vhandles.push_back(vhandle[4]);
  mesh.add_face(face_vhandles);  

  return mesh.n_vertices();
};

#endif