Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing NFT with threading support with emscripten #2

Open
wants to merge 24 commits into
base: fixing-nft
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
162bc15
implementing NFT with threading support
kalwalt Jul 22, 2019
41eb40a
trackingInitGetResult instead of kpmGetResult
kalwalt Jul 22, 2019
ec03ab4
adding quit tracking and other stuf for the transpose matrix
kalwalt Jul 22, 2019
6f46ad1
improved getNFTMarkerInfo with threaded tracking
kalwalt Jul 22, 2019
a3e19c3
tested a different conditional
kalwalt Jul 24, 2019
f5694a9
adding pthreads also in the bytecode libs
kalwalt Jul 26, 2019
218cb8f
simplifying part of the code
kalwalt Jul 26, 2019
0914d82
this solved the issue: arc->videoFrame instead of arc->videoLuma !!!
kalwalt Jul 27, 2019
359292b
cleaning the code
kalwalt Jul 27, 2019
67b0413
restoring the previous conditional
kalwalt Jul 27, 2019
07a85f2
re-adding wasm support
kalwalt Jul 27, 2019
2cb54f9
fix for threejs_from_scratch.html
kalwalt Jul 28, 2019
5918469
new setupAR2Threads function threads initialization only for NFT
kalwalt Jul 28, 2019
966d6d7
optimization in dataHeap transfer, from comment https://github.com/je…
kalwalt Aug 2, 2019
14f67b5
transferDataToHeap also for debug lib version
kalwalt Aug 2, 2019
04233e1
new libjpeg and related changes
kalwalt Aug 30, 2019
f86f165
deleting files ARMarkerNFT
kalwalt Aug 30, 2019
43ecde3
added NFT example with a gltf model
kalwalt Sep 15, 2019
08eecc4
gltf model needs some lights
kalwalt Sep 18, 2019
e0beb69
gltf Duck example for NFT
kalwalt Sep 22, 2019
cb6d29e
scaling and repositioning the model solved the issue view
kalwalt Sep 22, 2019
e9a88e3
fix for CesiumMan example
kalwalt Sep 22, 2019
e50e52b
fix gitmodules
kalwalt Feb 15, 2023
759c846
fix to build with emsdk 3.1.20
kalwalt Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,684 changes: 2,390 additions & 2,294 deletions build/artoolkitNft.debug.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions build/artoolkitNft.min.js

Large diffs are not rendered by default.

Binary file modified build/artoolkitNft_wasm.wasm
Binary file not shown.
65 changes: 40 additions & 25 deletions emscripten/ARToolKitJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct arController {
KpmHandle* kpmHandle;
AR2HandleT* ar2Handle;
THREAD_HANDLE_T *threadHandle = NULL;
int detectedPage = -2; // -2 Tracking not inited, -1 tracking inited OK, >= 0 tracking online on page.

int surfaceSetCount = 0; // Running NFT marker id
std::unordered_map<int, AR2SurfaceSetT*> surfaceSets;
Expand Down Expand Up @@ -97,23 +98,41 @@ extern "C" {
KpmResult *kpmResult = NULL;
int kpmResultNum = -1;
int pageNo;

//kpmGetResult( arc->kpmHandle, &kpmResult, &kpmResultNum );


int i, j, k;
int flag = -1;
float err = -1;
float trans[3][4];
float trackingTrans[3][4];

kpmResultNum = trackingInitGetResult( arc->threadHandle, trackingTrans, &pageNo);
ar2SetInitTrans(arc->surfaceSet[pageNo], trackingTrans);
if( ar2Tracking(arc->ar2Handle, arc->surfaceSet[pageNo], arc->videoLuma, trackingTrans, &err) < 0 ) {
float err = -1;
float trans[3][4];
float trackingTrans[3][4] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
if (arc->threadHandle) {
int ret;
if( arc->detectedPage == -1 ) {
ret = trackingInitGetResult( arc->threadHandle, trackingTrans, &pageNo);
if( ret == 1 ) {
if (pageNo >= 0 && pageNo < arc->surfaceSetCount) {
ARLOGd("Detected page %d.\n", pageNo);
arc->detectedPage = pageNo;
ar2SetInitTrans(arc->surfaceSet[pageNo], trackingTrans);
} else {
ARLOGe("Detected bad page %d.\n", pageNo);
arc->detectedPage = -2;
}
} else if( ret < 0 ) {
ARLOGd("No page detected.\n");
arc->detectedPage = -2;
}
}
if( arc->detectedPage >= 0 && arc->detectedPage < arc->surfaceSetCount) {
if( ar2Tracking(arc->ar2Handle, arc->surfaceSet[pageNo], arc->videoLuma, trackingTrans, &err) < 0 ) {
ARLOGd("Tracking lost.\n");
arc->detectedPage = -2;
} else {
ARLOGd("Tracked page %d (max %d).\n", arc->detectedPage, arc->surfaceSetCount - 1);
}
//ar2SetInitTrans(surfaceSet[detectedPage], trackingTrans);
ARLOGi("kpmResultNum is: %d\n", kpmResultNum);
}
} else {
ARLOGe("Error: threadHandle\n");
arc->detectedPage = -2;
}

for( i = 0; i < kpmResultNum; i++ ) {
//if (kpmResult[i].pageNo == markerIndex && kpmResult[i].camPoseF == 0 ) {
Expand All @@ -122,19 +141,19 @@ extern "C" {
if( flag == -1 ) { // Take the first or best result.
flag = i;
err = kpmResult[i].error;
ARLOGe("error in the tracking");
ARLOGe("error in the tracking: %d \n", err);
}
}
}
flag = kpmResultNum;
ARLOGi("flag is: %d\n", flag);
if (flag > -1) {

//ARLOGi("flag is: %d\n", arc->detectedPage);
if (pageNo >= 0 && pageNo == arc->detectedPage) {
Copy link
Owner Author

@kalwalt kalwalt Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is this we do not pass any data to the EM_ASM
if i change the variable in the conditional for example:
if (pageNo >= 0) we get data but with that Threejs error, and the sphere appear and disappears. MAybe we should use another condition or what else?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't remember why i put this:
if (pageNo >= 0 && pageNo == arc->detectedPage) {

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it should be

if (arc->detectedPage >= -1) {

//// or better

if (arc->detectedPage > -1) {

Copy link

@evaristoc evaristoc Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather ask why appears and disappears. As you put it, it is a hack that might work for some but not all cases. I would prefer to understand why pageNo should be as condition.

However, this might not have sense: pageNo >= 0 && pageNo == arc->detectedPage. I can see some contradictory behaviour there.

If you leave it as arc->detectedPage > -1, does it mean that pageNo >= 0? For what I read from the code, detectedPage was a sort of flag for different states. What meant -1 status for detectedPage?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

if (pageNo >= 0 && arc->detectedPage SOMETHING -1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the flagging I found for detectedPage:

int detectedPage  = -2;  // -2 Tracking not inited, -1 tracking inited OK, >= 0 tracking online on page.

for (j = 0; j < 3; j++) {
for (k = 0; k < 4; k++) {
trans[j][k] = trackingTrans[j][k];
}
}
//ARLOGi("trackingTrans %d\n", trans);

EM_ASM_({
var $a = arguments;
var i = 0;
Expand Down Expand Up @@ -231,7 +250,6 @@ extern "C" {

KpmResult *kpmResult = NULL;
// NFT results.
int detectedPage = -2; // -2 Tracking not inited, -1 tracking inited OK, >= 0 tracking online on page.
float trackingTrans[3][4];
int kpmResultNum = -1;

Expand All @@ -243,12 +261,9 @@ extern "C" {
int ret;
int pageNo;

if( detectedPage == -2 ) {
if( arc->detectedPage == -2 ) {
trackingInitStart( arc->threadHandle, arc->videoLuma );
detectedPage = -1;
}
if( detectedPage == -1 ) {
kpmResultNum = trackingInitGetResult( arc->threadHandle, trackingTrans, &pageNo);
arc->detectedPage = -1;
}
}
return kpmResultNum;
Expand Down Expand Up @@ -281,7 +296,7 @@ extern "C" {
// AR2 init.
if( (arc->ar2Handle = ar2CreateHandle(arc->paramLT, arc->pixFormat, AR2_TRACKING_DEFAULT_THREAD_NUM)) == NULL ) {
ARLOGe("Error: ar2CreateHandle.\n");
//kpmDeleteHandle(arc->kpmHandle);
kpmDeleteHandle(&arc->kpmHandle);
return (FALSE);
}
if (threadGetCPU() <= 1) {
Expand Down