MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ extract() [2/2]

std::optional< Kakshya::VolumeData > MayaFlux::IO::VolumeReader::extract ( const VolumeReadOptions options = {}) const

Extract every selected grid after open() has already been called.

As load(), but reads the currently open file rather than opening one. Does not call close().

Parameters
optionsGrid selection.
Returns
Populated VolumeData, or nullopt if no file is open or on failure; check get_last_error().

Definition at line 146 of file VolumeReader.cpp.

148{
149 if (!m_is_open) {
150 set_error("No file open");
151 return std::nullopt;
152 }
153
154 const size_t count = m_archive->read_grid_count();
155 if (count == 0) {
156 set_error("No grids in file");
157 return std::nullopt;
158 }
159
160 const auto indices = select_indices(*m_archive, count, options.field_names);
161 if (indices.empty()) {
162 set_error("No matching grids");
163 return std::nullopt;
164 }
165
166 glm::ivec3 union_min { 0 };
167 glm::ivec3 union_max { 0 };
168 bool have_any = false;
169
170 for (size_t idx : indices) {
171 const auto summary = m_archive->grid_summary(idx);
172 if (!summary.has_active) {
173 continue;
174 }
175 if (!have_any) {
176 union_min = summary.active_min;
177 union_max = summary.active_max;
178 have_any = true;
179 } else {
180 union_min = glm::min(union_min, summary.active_min);
181 union_max = glm::max(union_max, summary.active_max);
182 }
183 }
184
185 if (!have_any) {
186 set_error("Selected grids have no active voxels");
187 return std::nullopt;
188 }
189
190 const auto first = m_archive->grid_summary(indices.front());
191
192 Kinesis::Lattice3D lattice;
193 lattice.resolution = glm::uvec3(union_max - union_min);
194 lattice.bounds.min = first.translation + first.voxel_size * (glm::vec3(union_min) - 0.5F);
195 lattice.bounds.max = first.translation + first.voxel_size * (glm::vec3(union_max) - 0.5F);
196
197 return materialize(indices, union_min, lattice);
198}
size_t count
void set_error(std::string msg) const
std::optional< Kakshya::VolumeData > materialize(const std::vector< size_t > &indices, const glm::ivec3 &region_min, const Kinesis::Lattice3D &lattice) const
Build VolumeData from selected grids over an explicit region.
std::unique_ptr< Detail::VDBArchive > m_archive

References MayaFlux::Kinesis::Lattice3D::bounds, count, MayaFlux::IO::VolumeReadOptions::field_names, m_archive, m_is_open, materialize(), MayaFlux::Kinesis::AABB3D::max, MayaFlux::Kinesis::AABB3D::min, MayaFlux::Kinesis::Lattice3D::resolution, and set_error().

Referenced by load(), and load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: