I'm including all of my code, however, my major issue here is about returning the vector/array/pointer (I don't really know what to choose) in this function:
std::vector<TNREstimationResult>TemporalNoiseReduction::PrepareResults(std::vector<std::pair<double,int>> sortI, int newRows, cv::Mat timeStdv, int nControlPoints, double** ctrl_sigma, std::vector<double> ctrl_y)
My problem is regarding returning allocated memory (long lists of double
s). I used std::vector
but I basically copy using TNREstimation
's copy constructor into a new std::vector
here:
std::vector<TNREstimationResult> resultsArray;
resultsArray.push_back(TNREstimationResult(timeMeanY, timeStdVChannelY, ctrl_y, ctrlSigmaRow0));
resultsArray.push_back(TNREstimationResult(timeMeanY, timeStdVChannelCb, ctrl_y, ctrlSigmaRow1));
resultsArray.push_back(TNREstimationResult(timeMeanY, timeStdVChannelCr, ctrl_y, ctrlSigmaRow2));
Is there a better/easier way of doing it?
TNREstimationResult::TNREstimationResult(const TNREstimationResult& other)
{
for (int i = 0; i < other._timeMeanY.size(); i++)
{
_timeMeanY.push_back(other._timeMeanY[i]);
}
for (int i = 0; i < other._timeStdVChannel.size(); i++)
{
_timeStdVChannel.push_back(other._timeStdVChannel[i]);
}
for (int i = 0; i < other._ctrlY.size(); i++)
{
_ctrlY.push_back(other._ctrlY[i]);
}
for (int i = 0; i < other._ctrlSigmaRow.size(); i++)
{
_ctrlSigmaRow.push_back(other._ctrlSigmaRow[i]);
}
}
The function to review:
std::vector<TNREstimationResult>TemporalNoiseReduction::PrepareResults(std::vector<std::pair<double,int>> sortI, int newRows, cv::Mat timeStdv,
int nControlPoints, double** ctrl_sigma, std::vector<double> ctrl_y)
{
std::vector<double> timeMeanY;
for (int i = 0; i < sortI.size(); i++)
{
timeMeanY.push_back(sortI[i].first);
}
std::vector<double>timeStdVChannelY;
std::vector<double>timeStdVChannelCb;
std::vector<double>timeStdVChannelCr;
for (int i = 0; i < newRows; i++)
{
timeStdVChannelY.push_back(timeStdv.at<double>(i,0));
timeStdVChannelCb.push_back(timeStdv.at<double>(i,1));
timeStdVChannelCr.push_back(timeStdv.at<double>(i,2));
}
std::vector<double> ctrlSigmaRow0;
std::vector<double> ctrlSigmaRow1;
std::vector<double> ctrlSigmaRow2;
for (int i = 0; i < nControlPoints + 2; i++)
{
ctrlSigmaRow0.push_back(ctrl_sigma[i][0]);
ctrlSigmaRow1.push_back(ctrl_sigma[i][1]);
ctrlSigmaRow2.push_back(ctrl_sigma[i][2]);
}
std::vector<TNREstimationResult> resultsArray;
resultsArray.push_back(TNREstimationResult(timeMeanY, timeStdVChannelY, ctrl_y, ctrlSigmaRow0));
resultsArray.push_back(TNREstimationResult(timeMeanY, timeStdVChannelCb, ctrl_y, ctrlSigmaRow1));
resultsArray.push_back(TNREstimationResult(timeMeanY, timeStdVChannelCr, ctrl_y, ctrlSigmaRow2));
return resultsArray;
}