aboutsummaryrefslogtreecommitdiff
path: root/src/persistent_scene.c
diff options
context:
space:
mode:
authorCNLohr <charles@cnlohr.com>2018-03-16 00:02:03 -0400
committerGitHub <noreply@github.com>2018-03-16 00:02:03 -0400
commit6e67cc1996fbcba36e11cb281c78d3b00c4de85d (patch)
tree543390fcbd17dfce8845dff942fc6ecd928270b7 /src/persistent_scene.c
parent61a01d0ddfd8e99c97e3d235d4f0782fbf0ed032 (diff)
parent029b2909b37cc58ba35e0f46be1802866ee59730 (diff)
downloadlibsurvive-6e67cc1996fbcba36e11cb281c78d3b00c4de85d.tar.gz
libsurvive-6e67cc1996fbcba36e11cb281c78d3b00c4de85d.tar.bz2
Merge pull request #113 from cnlohr/epnp
Epnp
Diffstat (limited to 'src/persistent_scene.c')
-rw-r--r--src/persistent_scene.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/persistent_scene.c b/src/persistent_scene.c
new file mode 100644
index 0000000..9bbbf41
--- /dev/null
+++ b/src/persistent_scene.c
@@ -0,0 +1,36 @@
+#include "persistent_scene.h"
+#include "linmath.h"
+#include <stdlib.h>
+#include <string.h>
+#include <survive.h>
+
+bool PersistentScene_isStillValid(const PersistentScene *self, uint32_t timecode_now, uint32_t idx, int lh) {
+ const uint32_t *data_timecode = self->timecode[idx][lh];
+ return !(timecode_now - data_timecode[0] > self->tolerance || timecode_now - data_timecode[1] > self->tolerance);
+}
+
+void PersistentScene_add(PersistentScene *self, SurviveObject *so, PoserDataLight *lightData) {
+ int axis = (lightData->acode & 1);
+ uint32_t *data_timecode = &self->timecode[lightData->sensor_id][lightData->lh][axis];
+ FLT *angle = &self->angles[lightData->sensor_id][lightData->lh][axis];
+
+ *angle = lightData->angle;
+ *data_timecode = lightData->timecode;
+}
+
+void PersistentScene_ForEachCorrespondence(PersistentScene *self, PersistentScene_ForEachCorrespondence_fn fn,
+ SurviveObject *so, uint32_t timecode_now, void *user) {
+ for (int lh = 0; lh < NUM_LIGHTHOUSES; lh++) {
+ for (size_t i = 0; i < so->nr_locations; i++) {
+ if (PersistentScene_isStillValid(self, timecode_now, i, lh)) {
+ double *pts = self->angles[i][lh];
+ fn(so, lh, i, pts, user);
+ }
+ }
+ }
+}
+
+void PersistentScene_ctor(PersistentScene *self) {
+ memset(self, 0, sizeof(PersistentScene));
+ self->tolerance = 1500000;
+}