vtk_utils.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2020 by
  4. * The Salk Institute for Biological Studies and
  5. * Pittsburgh Supercomputing Center, Carnegie Mellon University
  6. *
  7. * Use of this source code is governed by an MIT-style
  8. * license that can be found in the LICENSE file or at
  9. * https://opensource.org/licenses/MIT.
  10. *
  11. ******************************************************************************/
  12. #ifndef SRC4_COUNTED_VOLUME_UTIL_H_
  13. #define SRC4_COUNTED_VOLUME_UTIL_H_
  14. #include <vector>
  15. #include <map>
  16. #include <vtkSmartPointer.h>
  17. #include <vtkPolyData.h>
  18. #include "defines.h"
  19. #include "geometry.h"
  20. namespace MCell {
  21. class World;
  22. class Partition;
  23. class GeometryObject;
  24. namespace VtkUtils {
  25. class GeomObjectInfo {
  26. public:
  27. GeomObjectInfo(const partition_id_t partition_id_, const geometry_object_id_t geometry_object_id_)
  28. : for_counted_objects(true), partition_id(partition_id_), geometry_object_id(geometry_object_id_) {
  29. }
  30. GeomObjectInfo(const std::string& name_)
  31. : for_counted_objects(false), partition_id(PARTITION_ID_INVALID), geometry_object_id(GEOMETRY_OBJECT_ID_INVALID),
  32. name(name_) {
  33. }
  34. // true - for counted objects
  35. // false - for compartments
  36. bool for_counted_objects;
  37. // partition_id and geometry_object_id are used when
  38. // we are computing containment for counted objects
  39. // TODO: remove partition_id - it is not needed because we can get this info from geometry_object_id
  40. partition_id_t partition_id;
  41. geometry_object_id_t geometry_object_id;
  42. // name is used when we are computing containment for compartments
  43. std::string name;
  44. vtkSmartPointer<vtkPolyData> polydata;
  45. GeometryObject& get_geometry_object_noconst(World* world) const;
  46. const GeometryObject& get_geometry_object(const World* world) const;
  47. // comparison uses geometry_object_id only, used in maps
  48. bool operator < (const GeomObjectInfo& other) const {
  49. if (for_counted_objects) {
  50. return geometry_object_id < other.geometry_object_id;
  51. }
  52. else {
  53. return name < other.name;
  54. }
  55. }
  56. bool operator == (const GeomObjectInfo& other) const {
  57. if (for_counted_objects) {
  58. return geometry_object_id == other.geometry_object_id;
  59. }
  60. else {
  61. return name == other.name;
  62. }
  63. }
  64. };
  65. typedef std::vector<GeomObjectInfo> GeomObjectInfoVector;
  66. // containment mapping of counted geometry objects
  67. typedef std::map<GeomObjectInfo, std::set<GeomObjectInfo>> ContainmentMap;
  68. typedef std::set<GeomObjectInfo> IntersectingSet;
  69. // return true if counted volumes were correctly set up
  70. bool initialize_counted_volumes(World* world, bool& has_intersecting_counted_objects);
  71. #if 0
  72. bool is_point_inside_counted_volume(GeometryObject& obj, const Vec3& point);
  73. #endif
  74. // world is nullptr for compartment hierarchy computation
  75. bool compute_containement_mapping(
  76. const World* world, const GeomObjectInfoVector& counted_objects,
  77. ContainmentMap& contained_in_mapping,
  78. IntersectingSet& intersecting_objects);
  79. const GeomObjectInfo* get_direct_parent_info(
  80. const GeomObjectInfo& obj_info, const ContainmentMap& contained_in_mapping);
  81. // auxiliary function to compute volume, not related to counted volumes but uses VTK
  82. double get_geometry_object_volume(const World* world, const GeometryObject& obj);
  83. void export_geometry_objects_to_obj(
  84. const World* world, const GeometryObjectVector& objs, const std::string& file_prefix);
  85. }; // namespace VtkUtils
  86. } // namespace MCell
  87. #endif // SRC4_COUNTED_VOLUME_UTIL_H_