Beispiel #1
0
static void write_poly(const Polyhedron& p, std::ostream& out)
{
  for (unsigned i=0; i< p.get_mesh().num_tris(); i++)
  {
    Vector3 color((Real) rand()/RAND_MAX, (Real) rand()/RAND_MAX, (Real) rand()/RAND_MAX);
    Triangle t = p.get_mesh().get_triangle(i);
    t.to_vrml(out, color);
  }
  
  const vector<Vector3>& v = p.get_mesh().get_vertices();
  for (unsigned i=0; i< v.size(); i++)
  {
    out << "Transform {" << std::endl;
    out << "  translation " << v[i][0] << " " << v[i][1] << " " << v[i][2] << std::endl;
    out << "  scale 0.1 0.1 0.1" << std::endl;
    out << "  children Shape { " << std::endl;
    out << "    geometry Text { " << std::endl;
    out << "      string \"" << i << "\"" << std::endl;
    out << "      } } }" << std::endl;
  }
}
Beispiel #2
0
static void write_poly2(const Polyhedron& p, std::ostream& out)
{
  const unsigned X = 0, Y = 1, Z = 2;
 
  const vector<Vector3>& v = p.get_mesh().get_vertices();
  for (unsigned i=0; i< v.size(); i++)
  {
    out << "Transform {" << std::endl;
    out << "  translation " << v[i][0] << " " << v[i][1] << " " << v[i][2] << std::endl;
    out << "  scale 0.1 0.1 0.1" << std::endl;
    out << "  children Shape { " << std::endl;
    out << "    geometry Text { " << std::endl;
    out << "      string \"" << i << "\"" << std::endl;
    out << "      } } }" << std::endl;
  }
 
  // get the vertices and the facets
  const std::vector<Vector3>& vertices = p.get_vertices();
  const std::vector<IndexedTri>& facets = p.get_facets();

  // first write the consistent edges
  out << "Shape {" << std::endl;
  out << "  appearance Appearance { material Material { diffuseColor 1 1 1 } }" << std::endl;
  out << "  geometry ";
  out << "IndexedLineSet {" << std::endl;
  out << "    coord Coordinate { point [ ";
  for (unsigned i=0; i< vertices.size(); i++)
    out << vertices[i][X] << " " << vertices[i][Y] << " " << vertices[i][Z] << ", ";
  out << " ] }" << std::endl;
  out << "    coordIndex [ ";
  for (unsigned i=0; i< facets.size(); i++)
  {
    if (consistent(facets, facets[i].a, facets[i].b))
      out << facets[i].a << " " << facets[i].b << " -1, ";
    if (consistent(facets, facets[i].b, facets[i].c))
      out << facets[i].b << " " << facets[i].c << " -1, ";
    if (consistent(facets, facets[i].a, facets[i].c))
      out << facets[i].a << " " << facets[i].c << " -1, ";
  }
  out << " ] } }" << std::endl;

  // now write the inconsistent edges
  std::set<pair<unsigned, unsigned> > marked;
  out << "Shape {" << std::endl;
  out << "  appearance Appearance { material Material { diffuseColor 1 0 0 } }" << std::endl;
  out << "  geometry ";
  out << "IndexedLineSet {" << std::endl;
  out << "    coord Coordinate { point [ ";
  for (unsigned i=0; i< vertices.size(); i++)
    out << vertices[i][X] << " " << vertices[i][Y] << " " << vertices[i][Z] << ", ";
  out << " ] }" << std::endl;
  out << "    coordIndex [ ";
  for (unsigned i=0; i< facets.size(); i++)
  {
    if (marked.find(make_pair(facets[i].a, facets[i].b)) == marked.end() && 
        !consistent(facets, facets[i].a, facets[i].b))
    {
      out << facets[i].a << " " << facets[i].b << " -1, ";
      marked.insert(make_pair(facets[i].a, facets[i].b));
std::cout << "edge: " << facets[i].a << " " << facets[i].b << std::endl;
    }
    if (marked.find(make_pair(facets[i].b, facets[i].c)) == marked.end() && 
        !consistent(facets, facets[i].b, facets[i].c))
    {
      out << facets[i].b << " " << facets[i].c << " -1, ";
      marked.insert(make_pair(facets[i].b, facets[i].c));
std::cout << "edge: " << facets[i].b << " " << facets[i].c << std::endl;
    }
    if (marked.find(make_pair(facets[i].a, facets[i].c)) == marked.end() && 
        !consistent(facets, facets[i].a, facets[i].c))
    {
      out << facets[i].a << " " << facets[i].c << " -1, ";
      marked.insert(make_pair(facets[i].a, facets[i].c));
std::cout << "edge: " << facets[i].a << " " << facets[i].c << std::endl;
    }
  }
  out << " ] } }" << std::endl;
}