Skip to content
Snippets Groups Projects
Commit e683b56b authored by Julien Malik's avatar Julien Malik
Browse files

BUG: fix memory error with vnl

parent b3fc4f34
Branches
Tags
No related merge requests found
......@@ -31,7 +31,7 @@ template <class TInput, class TOutput, class TPrecision>
ISRAUnmixingFunctor<TInput, TOutput, TPrecision>
::ISRAUnmixingFunctor()
: m_OutputSize(0),
m_MaxIteration(10)
m_MaxIteration(100)
{
}
......@@ -90,7 +90,11 @@ ISRAUnmixingFunctor<TInput, TOutput, TPrecision>
::operator ()(const InputType& in) const
{
// TODO : support different types between input and output ?
VectorType inVector(in.GetDataPointer(), in.Size());
VectorType inVector(in.Size());
for (int i = 0; i < in.GetSize(); i++ )
{
inVector[i] = in[i];
}
// Initialize with Unconstrained Least Square solution
VectorType outVector = m_Svd->solve(inVector);
......@@ -130,7 +134,12 @@ ISRAUnmixingFunctor<TInput, TOutput, TPrecision>
outVector = outVectorNew;
}
return OutputType(outVector.data_block(), outVector.size());
OutputType out(outVector.size());
for (int i = 0; i < out.GetSize(); i++ )
{
out[i] = outVector[i];
}
return out;
}
}
......
......@@ -54,7 +54,7 @@ public:
bool operator !=(const UnConstrainedLeastSquareFunctor& other) const
{
return false;
return true;
}
bool operator ==(const UnConstrainedLeastSquareFunctor& other) const
......@@ -64,16 +64,30 @@ public:
void SetMatrix(const MatrixType& m)
{
std::cout << "m : " << m.rows() << " " << m.cols() << std::endl;
m_Svd.reset( new SVDType(m) );
m_Inv = m_Svd->inverse();
m_OutputSize = m.cols();
}
OutputType operator ()(const InputType& in)
{
// TODO : support different types between input and output ?
VectorType inVector(in.GetDataPointer(), in.Size());
VectorType outVector = m_Svd->solve(inVector);
return OutputType(outVector.data_block(), outVector.size());
VectorType inVector(in.Size());
for (int i = 0; i < in.GetSize(); i++ )
{
inVector[i] = in[i];
}
VectorType outVector = m_Inv * inVector;
OutputType out(outVector.size());
for (int i = 0; i < out.GetSize(); i++ )
{
out[i] = outVector[i];
}
return out;
}
private:
......@@ -83,6 +97,7 @@ private:
unsigned int m_OutputSize;
SVDPointerType m_Svd;
MatrixType m_Inv;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment