UCL / STIR

Software for Tomographic Image Reconstruction
http://stir.sourceforge.net/
Other
115 stars 95 forks source link

SWIG: add downcasting #284

Open KrisThielemans opened 6 years ago

KrisThielemans commented 6 years ago

A difficulty is that some members return a base class ptr, which cannot be downcasted in python. Example

input=recon.get_input_data()

Then input is of type ExamData and there's no way to get at members of a ProjData (or whatever it is).

This might be possible as mentioned for instance at https://github.com/tpaviot/pythonocc-generator/issues/28

rainman110 commented 5 years ago

This is possible using swigs factory feature, see example https://github.com/DLR-SC/tigl/blob/c62f4e0ebbc3ed9accbf46a2a51f21421ce590ed/bindings/python_internal/configuration.i#L406

KrisThielemans commented 5 years ago

Thanks for the suggestion! I had a look at swig source. This looks really useful. However, it is not clear to me if this only applies to actual factories (i.e. method that create a new object), or also to other methods that just return a (shared) ptr, as in the example above. I have the impression it's only the former (but my SWIG is rusty). Maybe this is a question for the SWIG list though.

rainman110 commented 5 years ago

It's both, object generation and object dispatch.

KrisThielemans commented 5 years ago

Here's the SWIG code https://github.com/swig/swig/blob/master/Lib/typemaps/factory.swg

confusingly, the SWIG FAQ makes it look much harder.

KrisThielemans commented 4 years ago

Possibly this might be as simple as include something like

%factory(stir::ExamData& stir::Reconstruction::get_input_data, stir::ListmodeData, stir::ProjData)

although how that will work templates I don't know.

KrisThielemans commented 4 years ago

probably we'd have to list CListmodeData, SPECTListmodeData. or even ideally all their derived classes, which becomes rather hard to maintain.