geometry_object.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2020 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. #ifndef API_GEOMETRY_OBJECT_H
  12. #define API_GEOMETRY_OBJECT_H
  13. #include "bng/bng_defines.h"
  14. #include "generated/gen_geometry_object.h"
  15. #include "api/api_common.h"
  16. #include "api/surface_region.h"
  17. #include "defines.h"
  18. namespace MCell {
  19. namespace API {
  20. class GeometryObject;
  21. typedef std::set<std::shared_ptr<API::GeometryObject>> GeometryObjectSet;
  22. class GeometryObject: public GenGeometryObject {
  23. public:
  24. GEOMETRY_OBJECT_CTOR()
  25. public:
  26. void postprocess_in_ctor() override;
  27. void set_all_custom_attributes_to_default() override;
  28. void check_semantics() const override;
  29. void translate(const std::vector<double> move) override;
  30. // using shorter printout when all_details is false
  31. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  32. // --- added manually ---
  33. void check_is_initialized() {
  34. if (geometry_object_id == GEOMETRY_OBJECT_ID_INVALID) {
  35. throw RuntimeError("Geometry object " + name + " is not present in model (or model was not initialized).");
  36. }
  37. }
  38. vertex_index_t get_partition_vertex_index(const int vertex_index) const {
  39. check_vertex_index(vertex_index);
  40. return first_vertex_index + vertex_index;
  41. }
  42. int get_object_vertex_index(const vertex_index_t vertex_index) const {
  43. int res = vertex_index - first_vertex_index;
  44. assert(res >= 0 && res < (int)vertex_list.size());
  45. return res;
  46. }
  47. wall_index_t get_partition_wall_index(const int wall_index) const {
  48. check_wall_index(wall_index);
  49. return first_wall_index + wall_index;
  50. }
  51. int get_object_wall_index(const wall_index_t wall_index) const {
  52. int res = wall_index - first_wall_index;
  53. assert(res >= 0 && res < (int)wall_list.size());
  54. return res;
  55. }
  56. private:
  57. void check_vertex_index(const int vertex_index) const {
  58. if (vertex_index < 0 || vertex_index >= (int)vertex_list.size()) {
  59. throw RuntimeError(
  60. "Vertex index " + std::to_string(vertex_index) + " is out of range for " + NAME_VERTEX_LIST + " of " + name + ".");
  61. }
  62. }
  63. void check_wall_index(const int wall_index) const {
  64. if (wall_index < 0 || wall_index >= (int)wall_list.size()) {
  65. throw RuntimeError(
  66. "Vertex index " + std::to_string(wall_index) + " is out of range for " + NAME_VERTEX_LIST + " of " + name + ".");
  67. }
  68. }
  69. public:
  70. // extra information used in MCell4 converter
  71. // if this is a compartment, its parent and children are set
  72. // in API::set_children_compartments
  73. std::shared_ptr<API::GeometryObject> parent_compartment;
  74. GeometryObjectSet child_compartments;
  75. // simulation engine mapping
  76. partition_id_t partition_id;
  77. geometry_object_id_t geometry_object_id;
  78. vertex_index_t first_vertex_index; // index of the first vertex created in partition for this object
  79. wall_index_t first_wall_index;
  80. std::vector<vertex_index_t> vertex_indices; // vertex_list[i] has vertex index vertex_indices[i]
  81. std::vector<wall_index_t> wall_indices; // wall_list[i] has wall index wall_indices[i]
  82. BNG::compartment_id_t vol_compartment_id;
  83. BNG::compartment_id_t surf_compartment_id;
  84. };
  85. } // namespace API
  86. } // namespace MCell
  87. #endif // API_GEOMETRY_OBJECT_H