Esempio n. 1
0
// 图灵新API要求POST方式
int httpost(char *apikey, char *userid, char *text)
{
    CURL *curl;
    CURLcode res;
    char *post_data = combine_data(apikey, userid, text);
// Debug
//	printf("Post Data  %s\n", post_data);
//
    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
    if (curl) {
	curl_easy_setopt(curl, CURLOPT_URL, TULING_URL);
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
// Debug
//	printf("Starting... GET\n");
//
	res = curl_easy_perform(curl);
	if (res != CURLE_OK) {
		    fprintf(stderr, "curl_easy_perform() failed: %s\n",
		    curl_easy_strerror(res));
	    curl_global_cleanup();
	    return -1;
	}
    }
    return 1;
}
int gpuCSICoilEstimationGadget::process(
		GadgetContainerMessage<IsmrmrdAcquisitionBucket>* m1) {
	IsmrmrdAcquisitionBucket* bucket = m1->getObjectPtr();

	auto cm1 = new GadgetContainerMessage<cuSenseData>();
	auto senseData = cm1->getObjectPtr();

	coils = bucket->data_.front().head_->getObjectPtr()->active_channels;
	GDEBUG("Active channels %i \n",coils);


	{

		hoNDArray<std::complex<float>> * ho_data;
		hoNDArray<float>* ho_traj;

		std::tie(ho_data,ho_traj) = combine_data(bucket->data_);

		if (skip_lines_ > 0){
			auto cal_dims = *ho_data->get_dimensions();
			cal_dims.back() = skip_lines_;
			auto data_dims = *ho_data->get_dimensions();
			data_dims.back() -= skip_lines_;


			hoNDArray<float_complext> cal_view(cal_dims,(float_complext*) ho_data->get_data_ptr());
			senseData->freq_calibration = boost::make_shared<cuNDArray<float_complext>>(cal_view);
			senseData->freq_calibration->squeeze();
			hoNDArray<float_complext> data_view(data_dims,(float_complext*)ho_data->get_data_ptr()+cal_view.get_number_of_elements());
			senseData->data = boost::make_shared<cuNDArray<float_complext>>(data_view);
		} else {

			senseData->data = boost::make_shared<cuNDArray<float_complext>>(reinterpret_cast<hoNDArray<float_complext>*>(ho_data));
		}


		if (ho_traj->get_size(0) > 2){ //We have dcw
			auto traj_dcw = separate_traj_and_dcw(ho_traj);
			senseData->traj = boost::make_shared<cuNDArray<floatd2>>(*std::get<0>(traj_dcw));
			senseData->dcw = boost::make_shared<cuNDArray<float>>(*std::get<1>(traj_dcw));
		} else {
			std::vector<size_t> tdims = *ho_traj->get_dimensions();
			std::vector<size_t> tmp_dim(tdims.begin()+1,tdims.end());
			hoNDArray<floatd2> tmp(tmp_dim,reinterpret_cast<floatd2*>(ho_traj->get_data_ptr()));
			senseData->traj = boost::make_shared<cuNDArray<floatd2>>(tmp);
		}

		delete ho_data;
		delete ho_traj;
	}


	//Remove Initial Spirals

	boost::shared_ptr< cuNDArray<float_complext> >  ref_data;
	boost::shared_ptr< cuNDArray<floatd2> > ref_traj;
	boost::shared_ptr<cuNDArray<float> > ref_dcw;


	if (bucket->ref_.empty()){
		ref_data = senseData->data;
		ref_traj = senseData->traj;
		ref_dcw = senseData->dcw;
	} else {

		hoNDArray<std::complex<float>> * ho_data;
		hoNDArray<float>* ho_traj;
		std::tie(ho_data,ho_traj) = combine_data(bucket->ref_);

		ref_data = boost::make_shared<cuNDArray<float_complext>>(reinterpret_cast<hoNDArray<float_complext>*>(ho_data));
		if (ho_traj->get_size(0) > 2){
			auto traj_dcw = separate_traj_and_dcw(ho_traj);
			ref_traj =boost::make_shared<cuNDArray<floatd2>>(*std::get<0>(traj_dcw));
			ref_dcw = boost::make_shared<cuNDArray<float>>(*std::get<1>(traj_dcw));
		} else {
			std::vector<size_t> tdims = *ho_traj->get_dimensions();
			std::vector<size_t> tmp_dim(tdims.begin()+1,tdims.end());
			hoNDArray<floatd2> tmp(tmp_dim,reinterpret_cast<floatd2*>(ho_traj->get_data_ptr()));
			ref_traj = boost::make_shared<cuNDArray<floatd2>>(tmp);
		}
		delete ho_data;
		delete ho_traj;


	}

	senseData->csm = calculate_CSM(ref_data.get(),ref_traj.get(),ref_dcw.get());


	if (this->next()->putq(cm1) == GADGET_FAIL){
		GERROR("Failed to put message on que\n");
		return GADGET_FAIL;
	}

	return GADGET_OK;


}