geometry_object.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2021 by
  4. * The Salk Institute for Biological Studies
  5. *
  6. * Use of this source code is governed by an MIT-style
  7. * license that can be found in the LICENSE file or at
  8. * https://opensource.org/licenses/MIT.
  9. *
  10. ******************************************************************************/
  11. #include "api/geometry_object.h"
  12. #include "api/surface_class.h"
  13. using namespace std;
  14. namespace MCell {
  15. namespace API {
  16. void GeometryObject::postprocess_in_ctor() {
  17. set_all_custom_attributes_to_default();
  18. }
  19. void GeometryObject::set_all_custom_attributes_to_default() {
  20. Region::set_all_custom_attributes_to_default();
  21. // overwrite value in Region construction
  22. region_type = RegionType::VOLUME;
  23. node_type = RegionNodeType::LEAF_GEOMETRY_OBJECT;
  24. partition_id = PARTITION_ID_INVALID;
  25. geometry_object_id = GEOMETRY_OBJECT_ID_INVALID;
  26. first_vertex_index = VERTEX_INDEX_INVALID;
  27. parent_compartment = nullptr;
  28. vol_compartment_id = BNG::COMPARTMENT_ID_INVALID;
  29. surf_compartment_id = BNG::COMPARTMENT_ID_INVALID;
  30. }
  31. void GeometryObject::check_semantics() const {
  32. GenGeometryObject::check_semantics();
  33. for (auto& v: vertex_list) {
  34. if (v.size() != 3) {
  35. throw ValueError(
  36. S("Each item in the '") + NAME_VERTEX_LIST + "' argument must be a triplet of floats, error for " +
  37. vec_nonptr_to_str(v) + ".");
  38. }
  39. }
  40. for (auto& e: wall_list) {
  41. if (e.size() != 3) {
  42. throw ValueError(
  43. S("Each item in the '") + NAME_WALL_LIST + "' argument must be a triplet of integers, error for " +
  44. vec_nonptr_to_str(e) + ".");
  45. for (int vertex_index: e) {
  46. if (vertex_index < 0 || vertex_index >= (int)vertex_list.size()) {
  47. throw ValueError(
  48. S("Vertex index the '") + NAME_WALL_LIST + "' is out of range, error for " +
  49. std::to_string(vertex_index));
  50. }
  51. }
  52. }
  53. }
  54. for (auto& sr: surface_regions) {
  55. for (int wall_index: sr->wall_indices) {
  56. if (wall_index >= (int)wall_list.size()) {
  57. throw ValueError(
  58. S("Wall index in the '") + NAME_WALL_INDICES + "' of '" + sr->name + "' is out of range, error for " +
  59. std::to_string(wall_index));
  60. }
  61. }
  62. }
  63. }
  64. void GeometryObject::translate(const std::vector<double> move) {
  65. if (move.size() != 3) {
  66. throw ValueError(S("Argument ") + NAME_MOVE + " must be a list containing exactly 3 floats.");
  67. }
  68. if (geometry_object_id != GEOMETRY_OBJECT_ID_INVALID) {
  69. throw RuntimeError(S("Method ") + NAME_TRANSLATE + " may be called only before model initialization.");
  70. }
  71. for (auto& v: vertex_list) {
  72. v[0] += move[0];
  73. v[1] += move[1];
  74. v[2] += move[2];
  75. }
  76. }
  77. std::string GeometryObject::to_str(const bool all_details, const std::string ind) const {
  78. if (!all_details) {
  79. std::stringstream ss;
  80. ss << get_object_name() << ": " <<
  81. "name=" << name << ", " <<
  82. "is_bngl_compartment=" << is_bngl_compartment << ", " <<
  83. "surface_compartment_name=" << surface_compartment_name << ", " <<
  84. "surface_class=" << "(" << ((surface_class != nullptr) ? surface_class->to_str(all_details, ind + " ") : "null" ) << ")" << ", " << "\n" << ind + " ";
  85. return ss.str();
  86. }
  87. else {
  88. return GenGeometryObject::to_str(true, ind);
  89. }
  90. }
  91. } // namespace API
  92. } // namespace MCell