Commit e53d41a6 authored by Jussi Lindgren's avatar Jussi Lindgren

Plugins: Matrix Transpose can now upgrade 1 dimensional matrix to 2 dims

parent 80660cb6
......@@ -40,31 +40,51 @@ boolean CBoxAlgorithmMatrixTranspose::process(void)
if(m_oDecoder.isHeaderReceived())
{
if(m_oDecoder.getOutputMatrix()->getDimensionCount()!=2)
{
this->getLogManager() << LogLevel_Error << "Only 2-dimensional matrices supported\n";
return false;
}
const uint32 l_ui32DimensionCount = m_oDecoder.getOutputMatrix()->getDimensionCount();
const IMatrix* l_pInput = m_oDecoder.getOutputMatrix();
IMatrix* l_pOutput = m_oEncoder.getInputMatrix();
l_pOutput->setDimensionCount(2);
l_pOutput->setDimensionSize(0, l_pInput->getDimensionSize(1));
l_pOutput->setDimensionSize(1, l_pInput->getDimensionSize(0));
if(l_ui32DimensionCount==1)
{
this->getLogManager() << LogLevel_Trace << "Upgrading your 1 dimensional matrix to 2 dimensions, [" << l_pInput->getDimensionSize(0) << "x 1]\n";
this->getLogManager() << LogLevel_Trace << "Output matrix will be ["
<< l_pOutput->getDimensionSize(0) << "x"
<< l_pOutput->getDimensionSize(1) << "]\n";
l_pOutput->setDimensionCount(2);
l_pOutput->setDimensionSize(0, l_pInput->getDimensionSize(0));
l_pOutput->setDimensionSize(1, 1);
for(uint32 j=0;j<l_pOutput->getDimensionSize(0);j++)
for(uint32 j=0;j<l_pInput->getDimensionSize(0);j++)
{
l_pOutput->setDimensionLabel(0, j, l_pInput->getDimensionLabel(0, j));
}
l_pOutput->setDimensionLabel(1, 0, "Dimension 0");
}
else if(l_ui32DimensionCount==2)
{
l_pOutput->setDimensionLabel(0, j, l_pInput->getDimensionLabel(1, j));
l_pOutput->setDimensionCount(2);
l_pOutput->setDimensionSize(0, l_pInput->getDimensionSize(1));
l_pOutput->setDimensionSize(1, l_pInput->getDimensionSize(0));
for(uint32 j=0;j<l_pOutput->getDimensionSize(0);j++)
{
l_pOutput->setDimensionLabel(0, j, l_pInput->getDimensionLabel(1, j));
}
for(uint32 j=0;j<l_pOutput->getDimensionSize(1);j++)
{
l_pOutput->setDimensionLabel(1, j, l_pInput->getDimensionLabel(0, j));
}
}
for(uint32 j=0;j<l_pOutput->getDimensionSize(1);j++)
else
{
l_pOutput->setDimensionLabel(1, j, l_pInput->getDimensionLabel(0, j));
this->getLogManager() << LogLevel_Error << "Only 1 and 2 dimensional matrices supported\n";
return false;
}
this->getLogManager() << LogLevel_Trace << "Output matrix will be ["
<< l_pOutput->getDimensionSize(0) << "x"
<< l_pOutput->getDimensionSize(1) << "]\n";
m_oEncoder.encodeHeader();
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_rDynamicBoxContext.getInputChunkStartTime(0, chunk), l_rDynamicBoxContext.getInputChunkEndTime(0, chunk));
}
......@@ -74,17 +94,31 @@ boolean CBoxAlgorithmMatrixTranspose::process(void)
const IMatrix* l_pInput = m_oDecoder.getOutputMatrix();
IMatrix* l_pOutput = m_oEncoder.getInputMatrix();
const uint32 l_ui32nCols = l_pInput->getDimensionSize(0);
const uint32 l_ui32nRows = l_pInput->getDimensionSize(1);
const float64* l_pInputBuffer = l_pInput->getBuffer();
float64* l_pOutputBuffer = l_pOutput->getBuffer();
if(l_pInput->getDimensionCount() == 1)
{
const float64* l_pInputBuffer = l_pInput->getBuffer();
float64* l_pOutputBuffer = l_pOutput->getBuffer();
for(uint32 i=0;i<l_ui32nRows;i++)
for(uint32 i=0;i<l_pInput->getBufferElementCount(); i++)
{
l_pOutputBuffer[i] = l_pInputBuffer[i];
}
}
else
{
for(uint32 j=0;j<l_ui32nCols;j++)
// 2 dim
const uint32 l_ui32nCols = l_pInput->getDimensionSize(0);
const uint32 l_ui32nRows = l_pInput->getDimensionSize(1);
const float64* l_pInputBuffer = l_pInput->getBuffer();
float64* l_pOutputBuffer = l_pOutput->getBuffer();
for(uint32 i=0;i<l_ui32nRows;i++)
{
l_pOutputBuffer[j*l_ui32nRows+i] = l_pInputBuffer[i*l_ui32nCols+j];
for(uint32 j=0;j<l_ui32nCols;j++)
{
l_pOutputBuffer[j*l_ui32nRows+i] = l_pInputBuffer[i*l_ui32nCols+j];
}
}
}
......
......@@ -41,7 +41,7 @@ namespace OpenViBEPlugins
virtual OpenViBE::CString getAuthorName(void) const { return OpenViBE::CString("Jussi T. Lindgren"); }
virtual OpenViBE::CString getAuthorCompanyName(void) const { return OpenViBE::CString("Inria"); }
virtual OpenViBE::CString getShortDescription(void) const { return OpenViBE::CString("Transposes each matrix of the input stream"); }
virtual OpenViBE::CString getDetailedDescription(void) const { return OpenViBE::CString("Only works for 2-dimensional matrices"); }
virtual OpenViBE::CString getDetailedDescription(void) const { return OpenViBE::CString("Only works for 1 and 2 dimensional matrices. One-dimensional matrixes will be upgraded to two dimensions: [N x 1]"); }
virtual OpenViBE::CString getCategory(void) const { return OpenViBE::CString("Signal processing/Basic"); }
virtual OpenViBE::CString getVersion(void) const { return OpenViBE::CString("1.0"); }
virtual OpenViBE::CString getStockItemName(void) const { return OpenViBE::CString("gtk-sort-ascending"); }
......
......@@ -287,6 +287,10 @@ void CBufferDatabase::setMatrixDimensionCount(const uint32 ui32DimensionCount)
m_bError = true;
m_oParentPlugin.getBoxAlgorithmContext()->getPlayerContext()->getLogManager() << LogLevel_Error << "Caller tried to set a " << ui32DimensionCount << "-dimensional matrix. Only 2-dimensional matrices are supported (e.g. [rows X cols]).\n";
}
if(ui32DimensionCount == 1)
{
m_oParentPlugin.getBoxAlgorithmContext()->getPlayerContext()->getLogManager() << LogLevel_Error << "Note: For 1-dimensional matrices, you may try Matrix Transpose box to upgrade the stream to [N X 1] first.\n";
}
}
void CBufferDatabase::setMatrixDimensionSize(const uint32 ui32DimensionIndex, const uint32 ui32DimensionSize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment