intersection.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Begin License:
  2. // Copyright (C) 2006-2014 Tobias Sargeant (tobias.sargeant@gmail.com).
  3. // All rights reserved.
  4. //
  5. // This file is part of the Carve CSG Library (http://carve-csg.com/)
  6. //
  7. // This file may be used under the terms of either the GNU General
  8. // Public License version 2 or 3 (at your option) as published by the
  9. // Free Software Foundation and appearing in the files LICENSE.GPL2
  10. // and LICENSE.GPL3 included in the packaging of this file.
  11. //
  12. // This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
  13. // INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
  14. // A PARTICULAR PURPOSE.
  15. // End:
  16. #if defined(HAVE_CONFIG_H)
  17. # include <carve_config.h>
  18. #endif
  19. #include <algorithm>
  20. #include <carve/carve.hpp>
  21. #include <carve/poly.hpp>
  22. #include <carve/timing.hpp>
  23. #include <carve/intersection.hpp>
  24. void carve::csg::Intersections::collect(const IObj &obj,
  25. std::vector<carve::mesh::MeshSet<3>::vertex_t *> *collect_v,
  26. std::vector<carve::mesh::MeshSet<3>::edge_t *> *collect_e,
  27. std::vector<carve::mesh::MeshSet<3>::face_t *> *collect_f) const {
  28. carve::csg::Intersections::const_iterator i = find(obj);
  29. if (i != end()) {
  30. Intersections::mapped_type::const_iterator a, b;
  31. for (a = (*i).second.begin(), b = (*i).second.end(); a != b; ++a) {
  32. switch ((*a).first.obtype) {
  33. case carve::csg::IObj::OBTYPE_VERTEX:
  34. if (collect_v) collect_v->push_back((*a).first.vertex);
  35. break;
  36. case carve::csg::IObj::OBTYPE_EDGE:
  37. if (collect_e) collect_e->push_back((*a).first.edge);
  38. break;
  39. case carve::csg::IObj::OBTYPE_FACE:
  40. if (collect_f) collect_f->push_back((*a).first.face);
  41. break;
  42. default:
  43. throw carve::exception("should not happen " __FILE__ ":" XSTR(__LINE__));
  44. }
  45. }
  46. }
  47. }
  48. bool carve::csg::Intersections::intersectsFace(carve::mesh::MeshSet<3>::vertex_t *v,
  49. carve::mesh::MeshSet<3>::face_t *f) const {
  50. const_iterator i = find(v);
  51. if (i != end()) {
  52. mapped_type::const_iterator a, b;
  53. for (a = (*i).second.begin(), b = (*i).second.end(); a != b; ++a) {
  54. switch ((*a).first.obtype) {
  55. case IObj::OBTYPE_VERTEX: {
  56. const carve::mesh::MeshSet<3>::edge_t *edge = f->edge;
  57. do {
  58. if (edge->vert == (*a).first.vertex) return true;
  59. edge = edge->next;
  60. } while (edge != f->edge);
  61. break;
  62. }
  63. case carve::csg::IObj::OBTYPE_EDGE: {
  64. const carve::mesh::MeshSet<3>::edge_t *edge = f->edge;
  65. do {
  66. if (edge == (*a).first.edge) return true;
  67. edge = edge->next;
  68. } while (edge != f->edge);
  69. break;
  70. }
  71. case carve::csg::IObj::OBTYPE_FACE: {
  72. if ((*a).first.face == f) return true;
  73. break;
  74. }
  75. default:
  76. throw carve::exception("should not happen " __FILE__ ":" XSTR(__LINE__));
  77. }
  78. }
  79. }
  80. return false;
  81. }