3

Background

I'm using VES to leverage the Kiwi point cloud viewer on iOS devices.

Error

vesVector3f v = self->mKiwiApp->cameraFocalPoint();
NSLog(@"%@",  v);

results in

Cannot pass non-POD object of type `vesVector3f` (aka 'Matrix<float, 3, 1>') to variadic function; expected type from format string was 'id'

Question

I understand that NSLog is expected to output an object of type id. How do I get NSLog to output type vesVector3f ?

Extra Details

Here are some details I found about the custom type. It appears Vector3f is a vector of 3 floats.

  • typedef Eigen::Vector3f vesVector3f;
  • EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)

Solution

Per trojanfoe's comment:

NSLog(@"%f, %f, %f", v(0, 0), v(1, 0), v(2, 0));
Community
  • 1
  • 1
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284

2 Answers2

3

This looks like Objective-C++ given Eigen is a C++ library.

You'll want to print each of the float member variables something like this:

NSLog(@"%f, %f, %f", v(0, 0), v(1, 0), v(2, 0));

I say "something like this" as I've never used Eigen.

You can only use %@ with an Objective-C class, where you would override the description method in order for it to work to your liking.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I didn't know "Objective-C++" was a term but yes, it is definitely that. This gave me a `SIGABRT` initially but after flipping the params inside `v(n, m)` I was able to get the values I was looking for. – Jacksonkr May 18 '16 at 16:57
  • 1
    @Jacksonkr Cheers; flipped arguments in my answer for future visitors. – trojanfoe May 18 '16 at 18:19
2

How do I get NSLog to output type vesVector3f ?

It would need to be an object, as the error message tells you. If it's a struct, it cannot be output directly via NSLog. You could output the three floats yourself, individually. But if you are going to be doing this a lot, you could, for example, write a routine that converts the three floats to a string and output that string. That is what built-in routines like NSStringFromCGVector do.

matt
  • 515,959
  • 87
  • 875
  • 1,141