|
18 | 18 | namespace polyscope { |
19 | 19 |
|
20 | 20 | class SparseVolumeGrid; |
21 | | -class SparseVolumeGridScalarQuantity; |
22 | | -class SparseVolumeGridColorQuantity; |
| 21 | +class SparseVolumeGridCellScalarQuantity; |
| 22 | +class SparseVolumeGridNodeScalarQuantity; |
| 23 | +class SparseVolumeGridCellColorQuantity; |
| 24 | +class SparseVolumeGridNodeColorQuantity; |
| 25 | + |
| 26 | +struct SparseVolumeGridPickResult { |
| 27 | + SparseVolumeGridElement elementType; |
| 28 | + glm::ivec3 cellIndex; // only populated if cell |
| 29 | + uint64_t cellFlatIndex; // only populated if cell |
| 30 | + glm::ivec3 nodeIndex; // only populated if node |
| 31 | +}; |
23 | 32 |
|
24 | 33 | class SparseVolumeGrid : public Structure { |
25 | 34 | public: |
26 | 35 | // Construct a new sparse volume grid structure |
| 36 | + // The origin is the NODE/CORNER orgin. That is, the cell 0,0,0, will have its lower-left corner sitting at this |
| 37 | + // origin. If you wish to specify the CENTER of the the 0,0,0 cell, you should pass (cellOrigin - 0.5 * |
| 38 | + // gridCellWidth). |
27 | 39 | SparseVolumeGrid(std::string name, glm::vec3 origin, glm::vec3 gridCellWidth, std::vector<glm::ivec3> occupiedCells); |
28 | 40 |
|
29 | 41 | // === Overloads |
@@ -78,27 +90,34 @@ class SparseVolumeGrid : public Structure { |
78 | 90 |
|
79 | 91 | // Cell scalar. Values array must be passed in the same order as initial input cell list. |
80 | 92 | template <class T> |
81 | | - SparseVolumeGridScalarQuantity* addCellScalarQuantity(std::string name, const T& values, |
82 | | - DataType type = DataType::STANDARD); |
| 93 | + SparseVolumeGridCellScalarQuantity* addCellScalarQuantity(std::string name, const T& values, |
| 94 | + DataType type = DataType::STANDARD); |
83 | 95 |
|
84 | 96 | // Node scalar. Indices are _node_ indices; the nodes are a shifted sparse grid offset from the cell enumeration. For |
85 | 97 | // a cell with indices ijk, its corrners are the nodes with indices (i k j, i+1 j k, ..., i+1 j+1, k+1). Node values |
86 | 98 | // are passed via a paired set of arrays, giving the node index and node value for each. Node values may be passed in |
87 | 99 | // any order, and having extra entries is fine too, as long as all required nodes values are present. |
88 | 100 | template <class TI, class TV> |
89 | | - SparseVolumeGridScalarQuantity* addNodeScalarQuantity(std::string name, const TI& nodeIndices, const TV& nodeValues, |
90 | | - DataType type = DataType::STANDARD); |
| 101 | + SparseVolumeGridNodeScalarQuantity* addNodeScalarQuantity(std::string name, const TI& nodeIndices, |
| 102 | + const TV& nodeValues, DataType type = DataType::STANDARD); |
91 | 103 |
|
92 | 104 | // Cell color. Values array must be passed in the same order as initial input cell list. |
93 | 105 | template <class T> |
94 | | - SparseVolumeGridColorQuantity* addCellColorQuantity(std::string name, const T& colors); |
| 106 | + SparseVolumeGridCellColorQuantity* addCellColorQuantity(std::string name, const T& colors); |
95 | 107 |
|
96 | 108 | // Node color. Indices are _node_ indices; the nodes are a shifted sparse grid offset from the cell enumeration. For |
97 | 109 | // a cell with indices ijk, its corrners are the nodes with indices (i k j, i+1 j k, ..., i+1 j+1, k+1). Node values |
98 | 110 | // are passed via a paired set of arrays, giving the node index and node value for each. Node values may be passed in |
99 | 111 | // any order, and having extra entries is fine too, as long as all required nodes values are present. |
100 | 112 | template <class TI, class TC> |
101 | | - SparseVolumeGridColorQuantity* addNodeColorQuantity(std::string name, const TI& nodeIndices, const TC& nodeColors); |
| 113 | + SparseVolumeGridNodeColorQuantity* addNodeColorQuantity(std::string name, const TI& nodeIndices, |
| 114 | + const TC& nodeColors); |
| 115 | + |
| 116 | + // Force the grid to act as if nodes are in use (enable them for picking) |
| 117 | + void markNodesAsUsed(); |
| 118 | + |
| 119 | + // Get data related to picking/selection |
| 120 | + SparseVolumeGridPickResult interpretPickResult(const PickResult& result); |
102 | 121 |
|
103 | 122 | // Rendering related helpers |
104 | 123 | void setCellGeometryAttributes(render::ShaderProgram& p); |
@@ -159,36 +178,46 @@ class SparseVolumeGrid : public Structure { |
159 | 178 | void computeCornerNodeIndices(); |
160 | 179 |
|
161 | 180 | // Picking-related |
162 | | - size_t globalPickConstant = INVALID_IND_64; |
163 | | - glm::vec3 pickColor; |
| 181 | + bool nodesHaveBeenUsed = false; |
| 182 | + void buildCellInfoGUI(const SparseVolumeGridPickResult& result); |
| 183 | + void buildNodeInfoGUI(const SparseVolumeGridPickResult& result); |
164 | 184 |
|
165 | 185 | // Drawing related things |
166 | 186 | std::shared_ptr<render::ShaderProgram> program; |
167 | 187 | std::shared_ptr<render::ShaderProgram> pickProgram; |
168 | 188 |
|
169 | 189 | // === Helpers |
170 | 190 | void checkForDuplicateCells(); |
| 191 | + size_t findCellFlatIndex(glm::ivec3 cellInd3); |
| 192 | + size_t findNodeFlatIndex(glm::ivec3 nodeInd3); |
171 | 193 | void ensureRenderProgramPrepared(); |
172 | 194 | void ensurePickProgramPrepared(); |
173 | 195 |
|
174 | 196 | // Quantity impl methods |
175 | | - SparseVolumeGridScalarQuantity* addCellScalarQuantityImpl(std::string name, const std::vector<float>& data, |
176 | | - DataType type); |
177 | | - SparseVolumeGridScalarQuantity* addNodeScalarQuantityImpl(std::string name, |
178 | | - const std::vector<glm::ivec3>& nodeIndices, |
179 | | - const std::vector<float>& nodeValues, DataType type); |
180 | | - SparseVolumeGridColorQuantity* addCellColorQuantityImpl(std::string name, const std::vector<glm::vec3>& colors); |
181 | | - SparseVolumeGridColorQuantity* addNodeColorQuantityImpl(std::string name, const std::vector<glm::ivec3>& nodeIndices, |
182 | | - const std::vector<glm::vec3>& nodeColors); |
| 197 | + SparseVolumeGridCellScalarQuantity* addCellScalarQuantityImpl(std::string name, const std::vector<float>& data, |
| 198 | + DataType type); |
| 199 | + SparseVolumeGridNodeScalarQuantity* addNodeScalarQuantityImpl(std::string name, |
| 200 | + const std::vector<glm::ivec3>& nodeIndices, |
| 201 | + const std::vector<float>& nodeValues, DataType type); |
| 202 | + SparseVolumeGridCellColorQuantity* addCellColorQuantityImpl(std::string name, const std::vector<glm::vec3>& colors); |
| 203 | + SparseVolumeGridNodeColorQuantity* addNodeColorQuantityImpl(std::string name, |
| 204 | + const std::vector<glm::ivec3>& nodeIndices, |
| 205 | + const std::vector<glm::vec3>& nodeColors); |
183 | 206 | }; |
184 | 207 |
|
185 | 208 |
|
186 | 209 | // Register a sparse volume grid |
| 210 | +// The origin is the NODE/CORNER orgin. That is, the cell 0,0,0, will have its lower-left corner sitting at this |
| 211 | +// origin. If you wish to specify the CENTER of the the 0,0,0 cell, you should pass (cellOrigin - 0.5 * |
| 212 | +// gridCellWidth). |
187 | 213 | template <class T> |
188 | 214 | SparseVolumeGrid* registerSparseVolumeGrid(std::string name, glm::vec3 origin, glm::vec3 gridCellWidth, |
189 | 215 | const T& occupiedCells); |
190 | 216 |
|
191 | | -// Non-template overloads |
| 217 | +// Register a sparse volume grid (non-templated overload) |
| 218 | +// The origin is the NODE/CORNER orgin. That is, the cell 0,0,0, will have its lower-left corner sitting at this |
| 219 | +// origin. If you wish to specify the CENTER of the the 0,0,0 cell, you should pass (cellOrigin - 0.5 * |
| 220 | +// gridCellWidth). |
192 | 221 | SparseVolumeGrid* registerSparseVolumeGrid(std::string name, glm::vec3 origin, glm::vec3 gridCellWidth, |
193 | 222 | const std::vector<glm::ivec3>& occupiedCells); |
194 | 223 |
|
|
0 commit comments