Expect a vtkImageData and extract its setting for the dash_vtk.Volume state
(dataset)
| 181 | |
| 182 | |
| 183 | def volume(dataset): |
| 184 | """Expect a vtkImageData and extract its setting for the dash_vtk.Volume state""" |
| 185 | if dataset is None or not dataset.IsA("vtkImageData"): |
| 186 | return None |
| 187 | |
| 188 | state = { |
| 189 | "image": { |
| 190 | "dimensions": dataset.GetDimensions(), |
| 191 | "spacing": dataset.GetSpacing(), |
| 192 | "origin": dataset.GetOrigin(), |
| 193 | }, |
| 194 | } |
| 195 | |
| 196 | # Capture image orientation if any |
| 197 | if hasattr(dataset, "GetDirectionMatrix"): |
| 198 | matrix = dataset.GetDirectionMatrix() |
| 199 | js_mat = [] |
| 200 | for j in range(3): |
| 201 | for i in range(3): |
| 202 | js_mat.append(matrix.GetElement(i, j)) |
| 203 | |
| 204 | state["image"]["direction"] = js_mat |
| 205 | |
| 206 | scalars = dataset.GetPointData().GetScalars() |
| 207 | field = data_array(scalars, location="PointData") |
| 208 | if field: |
| 209 | state["field"] = field |
| 210 | |
| 211 | return state |
nothing calls this directly
no test coverage detected