How to check which geometric shape a geom::Source is?

A pretty simple question – I’d like a function that takes a geom::Source and then can tell me which type the function takes in (geom::Sphere, geom::Cube, geom::Cylinder, etc.). However, I’m not sure of the right way to do this!

void function(ci::geom::Source& source) {
    if source.type() is ci::geom::Sphere()
        then print("This is a sphere")
    else if source.type() is ci::geom::Cube()
        then print("This is a cube")

It looks like there’s some primitive enums in GeomIo.h, but they’re all OpenGL primitives like triangle strips and fans, not actual geometric primitives.

If there was a clever way to overload the == operator that’d work too. I basically just want to have a single function that can take any functioning source, and then perform different behaviors based on which geometric shape is input.

Any suggestions? This feels like it should be pretty simple, but I haven’t figured out a good way to do it…


You’re probably overthinking it. Just write an overload for each primitive and it can call a common function with any shared functionality. You could probably use RTTI if you absolutely had to, but thar be dragons.

void iDontRecommendDoingThis ( const ci::geom::Source& source )
    if ( typeid(source) == typeid(geom::Sphere) )
        std::cout << "Sphere\n";
    }else if ( typeid(source) == typeid(geom::Cube) )
        std::cout << "Cube\n";

void YourApp::setup()
    iDontRecommendDoingThis( geom::Sphere() );
    iDontRecommendDoingThis( geom::Cube() );

I guess what function to use is where I’m stuck here. I didn’t think about using typeid() – wasn’t sure if there were other, better options as well built-in to Cinder.

Well what exactly are you trying to do? Maybe work backwards and see if a solution shakes itself out.

1 Like