fix stroke samples computation bug

This commit is contained in:
2019-07-14 18:09:03 +02:00
parent f93be10883
commit fc7301a9a8

View File

@@ -53,7 +53,7 @@ void Stroke::randomize_prng()
std::vector<StrokeSample> Stroke::compute_samples() std::vector<StrokeSample> Stroke::compute_samples()
{ {
if (m_keypoints.empty()) return {}; if (m_keypoints.size() < 2) return {};
int nsamples = (int)glm::floor((m_keypoints.back().dist - m_dist) / m_step); int nsamples = (int)glm::floor((m_keypoints.back().dist - m_dist) / m_step);
std::vector<StrokeSample> samples; std::vector<StrokeSample> samples;
samples.reserve(nsamples); // preallocate the estimate number of samples samples.reserve(nsamples); // preallocate the estimate number of samples
@@ -62,7 +62,7 @@ std::vector<StrokeSample> Stroke::compute_samples()
m_dist += m_step; m_dist += m_step;
m_dir_dist += m_step; m_dir_dist += m_step;
int old_kp = m_last_kp; int old_kp = m_last_kp;
while (m_dist > m_keypoints[m_last_kp + 1].dist) while (m_dist > m_keypoints[m_last_kp + 1].dist && m_last_kp < m_keypoints.size())
m_last_kp++; m_last_kp++;
const auto& A = m_keypoints[old_kp]; const auto& A = m_keypoints[old_kp];
const auto& B = m_keypoints[m_last_kp == old_kp ? m_last_kp + 1 : m_last_kp]; // NOTE: this should be true when while is true const auto& B = m_keypoints[m_last_kp == old_kp ? m_last_kp + 1 : m_last_kp]; // NOTE: this should be true when while is true
@@ -127,6 +127,14 @@ std::vector<StrokeSample> Stroke::compute_samples()
} }
else else
{ {
static bool invalid_logged = false;
if (!invalid_logged)
{
for (auto const& p : m_keypoints)
LOG("point dist %f pos %f %f %f", p.dist, p.pos.x, p.pos.y, p.pos.z);
invalid_logged = true;
}
LOG("A.dist %f B.dist %f", A.dist, B.dist);
LOG("Invalid sample"); LOG("Invalid sample");
} }
} }
@@ -134,7 +142,7 @@ std::vector<StrokeSample> Stroke::compute_samples()
} }
bool Stroke::has_sample() bool Stroke::has_sample()
{ {
return m_keypoints.empty() ? false : // no keypoints return m_keypoints.size() < 2 ? false : // no keypoints
(m_keypoints.back().dist > (m_dist + m_step)); // check if next kp is closer than spacing (m_keypoints.back().dist > (m_dist + m_step)); // check if next kp is closer than spacing
} }
void Stroke::reset(bool clear_keypoints /*= false*/) void Stroke::reset(bool clear_keypoints /*= false*/)