Learning elementary structures for 3D shape generation and matching