void Leafcutter::leafcut(shared_ptr<Image<Vec4f> > image, shared_ptr<LightTree > lightTree, uint32_t samples, shared_ptr<ReportHandler> report) { _report = report; _image = image; _lightTree = lightTree; _nCore = pthread_num_processors_np(); stringstream sout; sout << "Leafcut on " << _nCore << " threads"; if (_report) _report->beginActivity(sout.str()); uint32_t lightNum = lightTree->DirectionalLightNum() + lightTree->OrientedLightNum(); image->Alloc(lightNum, samples); _curLine = 0; _mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_init(&_mutex, NULL); vector<pthread_t> threads(_nCore); _sampler->BeginPixel(samples); for (uint64_t idx = 0; idx < threads.size(); idx++) { pthread_create(&threads[idx], NULL, TreeWalkThread, this); } for (uint64_t idx = 0; idx < threads.size(); idx++) { pthread_join(threads[idx], NULL); } _sampler->EndPixel(); pthread_mutex_destroy(&_mutex); if (_report) _report->endActivity(); }