コード例 #1
0
ファイル: triangulate.cpp プロジェクト: dbc/pyPolyCSG
carve::poly::Polyhedron *readModel(const std::string &file) {
  carve::poly::Polyhedron *poly;

  if (file == "") {
    if (options.obj) {
      poly = readOBJ(std::cin);
    } else if (options.vtk) {
      poly = readVTK(std::cin);
    } else {
      poly = readPLY(std::cin);
    }
  } else if (endswith(file, ".ply")) {
    poly = readPLY(file);
  } else if (endswith(file, ".vtk")) {
    poly = readVTK(file);
  } else if (endswith(file, ".obj")) {
    poly = readOBJ(file);
  }

  if (poly == NULL) return NULL;

  std::cerr << "loaded polyhedron " << poly << " has "
    << poly->vertices.size() << " vertices "
    << poly->faces.size() << " faces "
    << poly->manifold_is_closed.size() << " manifolds (" << std::count(poly->manifold_is_closed.begin(), poly->manifold_is_closed.end(), true) << " closed)" << std::endl;

  return poly;
}
コード例 #2
0
ファイル: convert.cpp プロジェクト: ManojRollo/carve
int main(int argc, char **argv) {
  options.parse(argc, argv);

  carve::input::Input inputs;
  std::vector<carve::mesh::MeshSet<3> *> polys;
  std::vector<carve::line::PolylineSet *> lines;
  std::vector<carve::point::PointSet *> points;

  if (options.file == "") {
    readPLY(std::cin, inputs);
  } else {
    if (endswith(options.file, ".ply")) {
      readPLY(options.file, inputs);
    } else if (endswith(options.file, ".vtk")) {
      readVTK(options.file, inputs);
    } else if (endswith(options.file, ".obj")) {
      readOBJ(options.file, inputs);
    }
  }

  for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin(); i != inputs.input.end(); ++i) {
    carve::mesh::MeshSet<3> *p;
    carve::point::PointSet *ps;
    carve::line::PolylineSet *l;

    if ((p = carve::input::Input::create<carve::mesh::MeshSet<3> >(*i)) != NULL)  {
      if (options.canonicalize) p->canonicalize();
      if (options.obj) {
        writeOBJ(std::cout, p);
      } else if (options.vtk) {
        writeVTK(std::cout, p);
      } else {
        writePLY(std::cout, p, options.ascii);
      }
      delete p;
    } else if ((l = carve::input::Input::create<carve::line::PolylineSet>(*i)) != NULL)  {
      if (options.obj) {
        writeOBJ(std::cout, l);
      } else if (options.vtk) {
        writeVTK(std::cout, l);
      } else {
        writePLY(std::cout, l, options.ascii);
      }
      delete l;
    } else if ((ps = carve::input::Input::create<carve::point::PointSet>(*i)) != NULL)  {
      if (options.obj) {
        std::cerr << "Can't write a point set in .obj format" << std::endl;
      } else if (options.vtk) {
        std::cerr << "Can't write a point set in .vtk format" << std::endl;
      } else {
        writePLY(std::cout, ps, options.ascii);
      }
      delete ps;
    }
  }

  return 0;
}
コード例 #3
0
ファイル: slice.cpp プロジェクト: bigdoods/OpenInfraPlatform
static carve::mesh::MeshSet<3> *load(const std::string &file) {
  carve::input::Input inputs;

  if (file == "-") {
    readPLY(std::cin, inputs);
  } else if (endswith(file, ".ply")) {
    readPLY(file, inputs);
  } else if (endswith(file, ".vtk")) {
    readVTK(file, inputs);
  } else if (endswith(file, ".obj")) {
    readOBJ(file, inputs);
  }

  carve::mesh::MeshSet<3> *poly = NULL;

  for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin();
       poly == NULL && i != inputs.input.end();
       ++i) {
    poly = inputs.create<carve::mesh::MeshSet<3> >(*i, carve::input::Options());
  }

  return poly;
}
コード例 #4
0
ファイル: view.cpp プロジェクト: barche/carve
int main(int argc, char **argv) {
  TestScene *scene = new TestScene(argc, argv, std::min(1, argc - 1));
  options.parse(argc, argv);

  size_t count = 0;

  carve::input::Input inputs;
  std::vector<carve::mesh::MeshSet<3> *> polys;
  std::vector<carve::line::PolylineSet *> lines;
  std::vector<carve::point::PointSet *> points;

  if (options.files.size() == 0) {
    if (options.obj) {
      readOBJ(std::cin, inputs);
    } else if (options.vtk) {
      readVTK(std::cin, inputs);
    } else {
      readPLY(std::cin, inputs);
    }

  } else {
    for (size_t idx = 0; idx < options.files.size(); ++idx) {
      std::string &s(options.files[idx]);
      std::string::size_type i = s.rfind(".");

      if (i != std::string::npos) {
        std::string ext = s.substr(i, s.size() - i);
        if (!strcasecmp(ext.c_str(), ".obj")) {
          readOBJ(s, inputs);
        } else if (!strcasecmp(ext.c_str(), ".vtk")) {
          readVTK(s, inputs);
        } else {
          readPLY(s, inputs);
        }
      } else {
        readPLY(s, inputs);
      }
    }
  }

  for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin(); i != inputs.input.end(); ++i) {
    carve::mesh::MeshSet<3> *p;
    carve::point::PointSet *ps;
    carve::line::PolylineSet *l;

    if ((p = carve::input::Input::create<carve::mesh::MeshSet<3> >(*i, carve::input::opts("avoid_cavities", "true"))) != NULL)  {
      polys.push_back(p);
      std::cerr << "loaded polyhedron "
                << polys.back() << " has " << polys.back()->meshes.size()
                << " manifolds (" << std::count_if(polys.back()->meshes.begin(),
                                                   polys.back()->meshes.end(),
                                                   carve::mesh::Mesh<3>::IsClosed()) << " closed)" << std::endl; 

      std::cerr << "closed:    ";
      for (size_t i = 0; i < polys.back()->meshes.size(); ++i) {
        std::cerr << (polys.back()->meshes[i]->isClosed() ? '+' : '-');
      }
      std::cerr << std::endl;

      std::cerr << "negative:  ";
      for (size_t i = 0; i < polys.back()->meshes.size(); ++i) {
        std::cerr << (polys.back()->meshes[i]->isNegative() ? '+' : '-');
      }
      std::cerr << std::endl;

    } else if ((l = carve::input::Input::create<carve::line::PolylineSet>(*i)) != NULL)  {
      lines.push_back(l);
      std::cerr << "loaded polyline set "
                << lines.back() << std::endl; 
    } else if ((ps = carve::input::Input::create<carve::point::PointSet>(*i)) != NULL)  {
      points.push_back(ps);
      std::cerr << "loaded point set "
                << points.back() << std::endl; 
    }
  }

  scene->draw_list_base = genSceneDisplayList(polys, lines, points, &count, scene->is_wireframe);
  scene->draw_flags.assign(count, true);

  scene->run();

  delete scene;

  return 0;
}