SDK 0.6 Fix the Cube at a certain distance from the user


Hi, everyone
I am using the last SDK 0.6 and trying to put the box at a fixed distance from the camera as well in your Scanner App. I referred to a post here to change it but it didn’t work for 0.6 when I changed the line like @jim_selikoff mentioned in his post: [quote=“jim_selikoff, post:8, topic:5065”]
You could try translating the final camera pose calculated by STCameraPoseInitializer in enterScanningState, e.g.:

_slamState.tracker.initialCameraPose = GLKMatrix4Translate(_slamState.cameraPoseInitializer.cameraPose, 0.0, 0.0, 0.05);

Here’s a video showing the results:

The box disappears after I press Scan and won’t scan anything. I want my cube to behave like it does in this video:
Except I do not want the cube to constantly try to find a plane and I want it to put at a fixed distance in z-direction like for example 1 meter from the camera.
Thank you in advance.

Set vertical position of scan volume
Cube rotation axis
How does 'Detect Inner Pixels' work?
new ipad pro (2018 11") depth+rgb tracking problem
"Please put Model back in view" keep popping up with SDK 0.81


This topic has come up from time to time, and I’m certain that many devs have solved it individually. This time around I wanted to offer a step by step example of how to accomplish fixed cube placement.

Here are the basic steps:

  1. In setupSLAM, use STCameraPoseInitializerStrategyGravityAlignedAtOrigin when initializing STCameraPoseInitializer

  2. In setupMapper, set the kSTMapperVolumeHasSupportPlaneKey mapper option to @NO

  3. Since STCameraPoseInitializerStrategyGravityAlignedAtOrigin doesn’t require depth information we can pass nil as the depthFrame parameter in updateCameraPoseWithGravity:

    bool success = [_slamState.cameraPoseInitializer updateCameraPoseWithGravity:_lastGravity depthFrame:nil error:nil];

  4. Also while in ScannerStateCubePlacement state, we can tell the cube renderer there is no support plane since our strategy is not looking for one:

[_display.cubeRenderer setCubeHasSupportPlane:NO];

  1. For this example I added a GLKMatrix4 to struct SlamData with a fixed z-offset of 1 meter:
    GLKMatrix4 cubePose = GLKMatrix4Translate(GLKMatrix4Identity, 0.0, 0.0, -1.0);

  2. In renderSceneForDepthFrame while in ScannerStateCubePlacement add an offset to center the cube:

    float xOffset = _slamState.cameraPoseInitializer.volumeSizeInMeters.x / 2.0;
    float yOffset = _slamState.cameraPoseInitializer.volumeSizeInMeters.y / 2.0;

    _slamState.cubePose = GLKMatrix4Translate(cameraViewpoint, xOffset, yOffset, -1.0);

_slamState.cubePose will now be used instead of cameraViewpoint to render the cube outline and highlighted depth.

  1. Finally, in enterScanningState initialize the tracker’s camera pose using the offset cube, with some tweaks to account for the color-to-depth camera rigid body transform:

    GLKMatrix4 colorCameraPoseInSensorCoordinateSpace;
    [_sensorController colorCameraPoseInSensorCoordinateFrame:colorCameraPoseInSensorCoordinateSpace.m];

    bool invertible;
    GLKMatrix4 colorCameraInversePose = GLKMatrix4Invert (colorCameraPoseInSensorCoordinateSpace, &invertible);

    _slamState.cubePose = GLKMatrix4Multiply(_slamState.cubePose, colorCameraInversePose);

    _slamState.tracker.initialCameraPose = _slamState.cubePose;

Those are the basic steps! Here’s a link to a set of diff patches to the stock 0.6 SDK Scanner sample with the modifications outlined above:

Thanks @tuna.ozerdem for re-introducing this topic, and for your help testing the tweak!


Cube Size set with predefined sizes
How can I prevent the Bounding Box from jumping around?
How to scan rotating object or person?
Cube Size set with predefined sizes
Initial cube position
Controlling scanning cube and coordinate space
How to freeze cube position before scanning ?
What properties I can Set or Change to change scanner box frame?
Center cube placement bounding box with gravityAlignedAtOrigin STCameraPoseInitializerStrategy?
Scanning without support plane
Cube rotation axis
Room setup for 3D scanning where the object is hanging
Need to scan foot palm with rectangular size cube and cube distance of 30cm from scanner.
Problem at eye level on scan face in high resolution

Thank for this step by step.

However now If I scan an object which is on a table, in addition to the object, the scanners scans the table (support) whereas before it took only the object.
Is there a way to make it happen again ?



You can tweak _slamState.tracker.initialCameraPose before scanning begins as shown here:


Fixed cube position

Thank for your reply.
However I cannot access to your link. I have his message : “Sorry, you don’t have access to that topic!”

Volume Box Offset Into Support Plane

Here it is:

bool invertible;
GLKMatrix4 cubePose = GLKMatrix4Invert (_slamState.cameraPoseInitializer.cameraPose, &invertible);
cubePose = GLKMatrix4Translate(cubePose, 0, yOffset, 0);
GLKMatrix4 cameraPose = GLKMatrix4Invert (cubePose, &invertible);

_slamState.tracker.initialCameraPose = cameraPose;


Jim this tweak has to be done instead of :

bool invertible;
GLKMatrix4 colorCameraInversePose = GLKMatrix4Invert (colorCameraPoseInSensorCoordinateSpace, &invertible);

_slamState.cubePose = GLKMatrix4Multiply(_slamState.cubePose, colorCameraInversePose);

_slamState.tracker.initialCameraPose = _slamState.cubePose; 

Right ? Because I’m doing that but when I touch the scan button, the cube moved suddenly almost out of the screen…




The offset tweak I posted a few days ago assumed tabletop pose initializer strategy. For the fixed cube case, try inserting this just before bool invertible:

float yOffset = -0.01;
colorCameraPoseInSensorCoordinateSpace = GLKMatrix4Translate(colorCameraPoseInSensorCoordinateSpace, 0, yOffset, 0);



Would these changes also work in the more recent Scanner apps (Swift 4 etc.)?

For example I don’t see how to access “colorCameraPoseInSensorCoordinateSpace” from the enterScanningState method?

Any help appreciated :slight_smile:


i have a problem similar to yours.
Has yours been resolved?
i would like to know if the cube can be removed during acquisition.
Is there a particular reason why a cube is used?
Can you give me some device?


The bounding box is there to give dimension to the area needed to be scanned. If you are looking for an example without a bounding box, maybe the RoomCapture sample would be a good place to start.


I didn’t got this to run with the 0.10SDK

Are there some major changes? when i do the implementation as described i just see almost a quarter of the cube. It seems that my lower right corner oft the Ipad Screen is the center of the cube.

Does anybody have the same issue with that?


hi again,
i tried something more arround and with the 0.9SDK i got it to run but just while the CubePlacementState

when i hit Scan, in enterScanningState at position:

_slamState.tracker.initialCameraPose = _slamState.cubePose;

my App crashes.

i can’t find any further error in implementing the codes that mentioned above


Are you using STCaptureSession or the low level interface?


I’ve found a solution which works for me i guess, the cubePose was everywhere NaN so i removed the adjustments from Step 7 of your description in Post 2 and in EnterScanningState i’ve just replaced the
_slamState.tracker.initialCameraPose = _slamState.initialDepthCameraPose;
_slamState.tracker.initialCameraPose = _slamState.cubePose;

without the codelines you mentioned at Step 7 in your description. Do i have to expect any issues without your codelines? Scan seemed to be OK until now

As i am a very beginner to that topics i assume that i am using the STCaptureSession.

I’ve took the Sample Scanner App (SDK 0.10) without any adjustments on the settings.

Best Regards



The STCaptureSession based Scanner sample in a recent SDK was using an unitialized instance of the sensor controller. I’ll put together some diffs to share what I’ve done and post here today.



@thorsten.steparsch try applying this patch to the Scanner sample. Note that it also has the voxel size set to 1mm.

Best regards,



Hi Jim,

this works fine for me, thank you very much.

My Previous solution still works fine, do you think i will face any problems with keep using it as described in Post 15?

Best Regards



Some changes in the latest SDK update (0.10.2) may have broken my solution, but I haven’t had a chance to look at it.


I’ve applied your patch to the 0.10.2SDK in the Scanner Sample App and tried to do some changes to make it work (to be honest i don’t really know what i have done) :wink: .

    // Prepare the mapper for the new scan.
[self setupMapper];

STDepthFrame* depthFrame;
//    _slamState.tracker.initialCameraPose = _slamState.initialDepthCameraPose;
GLKMatrix4 depthCameraPoseAfterTracking = [_slamState.tracker lastFrameCameraPose];

GLKMatrix4 iOSColorFromDepthExtrinsics = [depthFrame iOSColorFromDepthExtrinsics];

GLKMatrix4 colorCameraPoseAfterTracking = GLKMatrix4Multiply(depthCameraPoseAfterTracking,
                                                             GLKMatrix4Invert(iOSColorFromDepthExtrinsics, nil));
// Make sure the pose is in color camera coordinates in case we are not using registered depth.

//GLKMatrix4 colorCameraPoseInSensorCoordinateSpace = GLKMatrix4();
//[[STSensorController sharedController] colorCameraPoseInSensorCoordinateFrame:colorCameraPoseInSensorCoordinateSpace.m];

bool invertible;
GLKMatrix4 colorCameraInversePose = GLKMatrix4Invert (colorCameraPoseAfterTracking, &invertible);
if (invertible)
    _slamState.cubePose = GLKMatrix4Multiply(_slamState.cubePose, colorCameraInversePose);
    _slamState.tracker.initialCameraPose = _slamState.cubePose;

// We will lock exposure during scanning to ensure better coloring. = STCaptureSessionPropertiesLockAllColorCameraPropertiesToCurrent();

_slamState.scannerState = ScannerStateScanning;

in the End the Scanning starts, but after pressing the SCAN Button, the Box is hopping to the right and is not keeping the position before scanning. But currently i have no explanation for that.

Do you have an idea what the reason of this behavior could be?