comparison transform/ModelTransformerFactory.cpp @ 877:b109b88bfa85 tonioni

Callback handler for additional models at end of processing
author Chris Cannam
date Wed, 29 Jan 2014 15:58:15 +0000
parents 13803edd513d
children a2689db084f4
comparison
equal deleted inserted replaced
876:47aa3aeb687b 877:b109b88bfa85
193 } 193 }
194 194
195 Model * 195 Model *
196 ModelTransformerFactory::transform(const Transform &transform, 196 ModelTransformerFactory::transform(const Transform &transform,
197 const ModelTransformer::Input &input, 197 const ModelTransformer::Input &input,
198 QString &message) 198 QString &message,
199 AdditionalModelHandler *handler)
199 { 200 {
200 SVDEBUG << "ModelTransformerFactory::transform: Constructing transformer with input model " << input.getModel() << endl; 201 SVDEBUG << "ModelTransformerFactory::transform: Constructing transformer with input model " << input.getModel() << endl;
201 202
202 Transforms transforms; 203 Transforms transforms;
203 transforms.push_back(transform); 204 transforms.push_back(transform);
204 vector<Model *> mm = transformMultiple(transforms, input, message); 205 vector<Model *> mm = transformMultiple(transforms, input, message, handler);
205 if (mm.empty()) return 0; 206 if (mm.empty()) return 0;
206 else return mm[0]; 207 else return mm[0];
207 } 208 }
208 209
209 vector<Model *> 210 vector<Model *>
210 ModelTransformerFactory::transformMultiple(const Transforms &transforms, 211 ModelTransformerFactory::transformMultiple(const Transforms &transforms,
211 const ModelTransformer::Input &input, 212 const ModelTransformer::Input &input,
212 QString &message) 213 QString &message,
214 AdditionalModelHandler *handler)
213 { 215 {
214 SVDEBUG << "ModelTransformerFactory::transformMultiple: Constructing transformer with input model " << input.getModel() << endl; 216 SVDEBUG << "ModelTransformerFactory::transformMultiple: Constructing transformer with input model " << input.getModel() << endl;
215 217
216 ModelTransformer *t = createTransformer(transforms, input); 218 ModelTransformer *t = createTransformer(transforms, input);
217 if (!t) return vector<Model *>(); 219 if (!t) return vector<Model *>();
218 220
221 if (handler) {
222 m_handlers[t] = handler;
223 }
224
225 m_runningTransformers.insert(t);
226
219 connect(t, SIGNAL(finished()), this, SLOT(transformerFinished())); 227 connect(t, SIGNAL(finished()), this, SLOT(transformerFinished()));
220
221 m_runningTransformers.insert(t);
222 228
223 t->start(); 229 t->start();
224 vector<Model *> models = t->detachOutputModels(); 230 vector<Model *> models = t->detachOutputModels();
225 231
226 if (!models.empty()) { 232 if (!models.empty()) {
268 << endl; 274 << endl;
269 } 275 }
270 276
271 m_runningTransformers.erase(transformer); 277 m_runningTransformers.erase(transformer);
272 278
279 if (m_handlers.find(transformer) != m_handlers.end()) {
280 if (transformer->willHaveAdditionalOutputModels()) {
281 vector<Model *> mm = transformer->detachAdditionalOutputModels();
282 m_handlers[transformer]->moreModelsAvailable(mm);
283 }
284 m_handlers.erase(transformer);
285 }
286
273 transformer->wait(); // unnecessary but reassuring 287 transformer->wait(); // unnecessary but reassuring
274 delete transformer; 288 delete transformer;
275 } 289 }
276 290
277 void 291 void