iMSTK
Interactive Medical Simulation Toolkit
imstkFastMarch.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkImageData.h"
10 
11 #include <unordered_set>
12 #include <queue>
13 
14 namespace imstk
15 {
21 class FastMarch
22 {
23 protected:
24  // Setup Node struct for priority queue
25  struct Node
26  {
27  int m_nodeId;
28  double m_cost;
29  Vec3i m_coord;
30 
31  Node(int nodeId, double cost, Vec3i coord) :
32  m_nodeId(nodeId), m_cost(cost), m_coord(coord)
33  {
34  }
35  };
37  {
38  bool operator()(const Node& a, const Node& b)
39  {
40  return a.m_cost > b.m_cost;
41  }
42  };
43 
44 public:
45  bool isVisited(int nodeId) { return m_visited.count(nodeId) == 0 ? false : true; }
46  double getDistance(int nodeId) { return m_distances.count(nodeId) == 0 ? IMSTK_DOUBLE_MAX : m_distances.at(nodeId); }
47 
48  void solve();
49 
50  void solveNode(Vec3i coord, int index);
51 
52  void setSeeds(std::vector<Vec3i> seedVoxels) { m_seedVoxels = seedVoxels; }
53  void setVisited(std::unordered_set<int> visited) { m_visited = visited; }
54  void setDistnaces(std::unordered_map<int, double> distances) { m_distances = distances; }
55  void setImage(std::shared_ptr<ImageData> image) { m_imageData = image; }
56  void setDistThreshold(double distThreshold) { m_distThreshold = distThreshold; }
57 
58 protected:
59  // The image to operate on
60  std::shared_ptr<ImageData> m_imageData;
61  Vec3i m_dim;
62  Vec3d m_spacing;
63  int m_indexShift;
64 
65  std::unordered_set<int> m_visited;
66  std::unordered_map<int, double> m_distances;
67 
68  // The starting voxels
69  std::vector<Vec3i> m_seedVoxels;
70 
71  // Distance to go too
72  double m_distThreshold;
73 
74  std::priority_queue<Node, std::vector<Node>, NodeComparator> m_queue;
75 };
76 } // namespace imstk
Compound Geometry.