Controlled integration of selected detectors and emitters in photonic integrated circuits