29IsoOctree::compute_voxels (
void)
33 this->compute_all_voxels();
34 std::cout <<
"Generated " << this->voxels.size()
35 <<
" voxels, took " << timer.
get_elapsed() <<
"ms." << std::endl;
39IsoOctree::compute_all_voxels (
void)
42 std::cout <<
"Computing sampling of the implicit function..." << std::endl;
45 typedef std::set<VoxelIndex> VoxelIndexSet;
46 VoxelIndexSet voxel_set;
52 for (
int i = 0; i < 8; ++i)
56 voxel_set.insert(index);
62 this->voxels.reserve(voxel_set.size());
63 for (VoxelIndexSet::const_iterator i = voxel_set.begin();
64 i != voxel_set.end(); ++i)
65 this->voxels.push_back(std::make_pair(*i, VoxelData()));
68 std::cout <<
"Sampling the implicit function at " << this->voxels.size()
69 <<
" positions, fetch a beer..." << std::endl;
72 std::size_t num_processed = 0;
73#pragma omp parallel for schedule(dynamic)
74 for (std::size_t i = 0; i < voxels.size(); ++i)
76 VoxelIndex index = this->voxels[i].first;
78 this->get_root_node_center(), this->get_root_node_size());
79 this->voxels[i].second = this->sample_ifn(voxel_pos);
84 this->print_progress(num_processed, this->voxels.size());
89 this->print_progress(this->voxels.size(), this->voxels.size());
90 std::cout << std::endl;
97 std::vector<Sample const*> samples;
98 samples.reserve(2048);
99 this->influence_query(voxel_pos, 3.0, &samples);
109 std::size_t num_samples = samples.size() / 10;
110 std::nth_element(samples.begin(), samples.begin() + num_samples,
111 samples.end(), sample_scale_compare);
112 float const sample_max_scale = samples[num_samples]->scale * 2.0f;
115#if FSSR_USE_DERIVATIVES
127 double total_value = 0.0;
128 double total_weight = 0.0;
129 double total_scale = 0.0;
130 double total_color_weight = 0.0;
135 for (std::size_t i = 0; i < samples.size(); ++i)
137 Sample
const& sample = *samples[i];
138 if (sample.scale > sample_max_scale)
142 double value, weight;
144 evaluate(voxel_pos, sample, &value, &weight,
145 &value_deriv, &weight_deriv);
148 total_value += value * weight * sample.confidence;
149 total_weight += weight * sample.confidence;
150 total_value_deriv += (value_deriv * weight + weight_deriv * value)
152 total_weight_deriv += weight_deriv * sample.confidence;
155 double const color_weight = gaussian_normalized<double>
156 (sample.scale / 5.0f, voxel_pos - sample.pos) * sample.confidence;
157 total_scale += sample.scale * color_weight;
158 total_color += sample.color * color_weight;
159 total_color_weight += color_weight;
164 voxel.value = total_value / total_weight;
165 voxel.conf = total_weight;
166 voxel.deriv = (total_value_deriv * total_weight
167 - total_weight_deriv * total_value) /
MATH_POW2(total_weight);
168 voxel.scale = total_scale / total_color_weight;
169 voxel.color = total_color / total_color_weight;
174 double total_ifn = 0.0;
175 double total_weight = 0.0;
176 double total_scale = 0.0;
178 double total_color_weight = 0.0;
180 for (std::size_t i = 0; i < samples.size(); ++i)
182 Sample
const& sample = *samples[i];
183 if (sample.scale > sample_max_scale)
188 double const value = fssr_basis<double>(sample.scale, tpos);
189 double const weight = fssr_weight<double>(sample.scale, tpos)
193 total_ifn += value * weight;
194 total_weight += weight;
196 double const color_weight = gaussian_normalized<double>
197 (sample.scale / 5.0f, tpos) * sample.confidence;
198 total_scale += sample.scale * color_weight;
199 total_color += sample.color * color_weight;
200 total_color_weight += color_weight;
205 voxel.value = total_ifn / total_weight;
206 voxel.conf = total_weight;
207 voxel.scale = total_scale / total_color_weight;
208 voxel.color = total_color / total_color_weight;
216IsoOctree::print_progress (std::size_t voxels_done, std::size_t voxels_total)
218 static std::size_t last_voxels_done = 0;
220 static std::size_t last_elapsed = 0;
223 if (voxels_done != voxels_total && voxels_done - last_voxels_done < 1000)
225 last_voxels_done = voxels_done;
229 if (voxels_done != voxels_total && elapsed - last_elapsed < 100)
231 last_elapsed = elapsed;
234 std::size_t elapsed_mins = elapsed / (1000 * 60);
235 std::size_t elapsed_secs = (elapsed / 1000) % 60;
236 float percentage =
static_cast<float>(voxels_done)
237 /
static_cast<float>(voxels_total) ;
238 std::size_t total =
static_cast<std::size_t
>(elapsed / percentage);
239 std::size_t remaining = total - elapsed;
240 std::size_t remaining_mins = remaining / (1000 * 60);
241 std::size_t remaining_secs = (remaining / 1000) % 60;
243 std::cout <<
"\rProcessing voxel " << voxels_done
245 << elapsed_mins <<
":"
247 << remaining_mins <<
":"
Cross-platform high-resolution real-time timer.
std::size_t get_elapsed(void) const
Returns the milli seconds since last reset.
#define FSSR_NAMESPACE_END
#define FSSR_NAMESPACE_BEGIN
math::Vec3f transform_position(math::Vec3f const &pos, Sample const &sample)
Transforms 'pos' according to the samples position and normal.
void evaluate(math::Vec3f const &pos, Sample const &sample, double *value, double *weight, math::Vector< double, 3 > *value_deriv, math::Vector< double, 3 > *weight_deriv)
Rotates the given point in the LCS of the sample, evaluates the basis and weight functions and their ...
std::string get_filled(T const &value, int width, char fill='0')
Returns a string filled to the left to a length of 'width' chars.
std::string get_fixed(T const &value, int digits)
Returns string with 'digits' of fixed precision (fills with zeros).
Octree iterator that keeps track of level and path through the octree.
The voxel index is a unique 64 bit ID for each voxel in the octree.
void from_path_and_corner(uint8_t level, uint64_t path, int corner)
Computes the octree corner index given octree node path and level.