Skip to content
Snippets Groups Projects
Commit bc0b26eb authored by Patrick Imbo's avatar Patrick Imbo
Browse files

ENH: add testing for AmplitudeFunctor class

parent f3815fe7
No related branches found
No related tags found
No related merge requests found
......@@ -392,6 +392,15 @@ ${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${INPUTDATA}/Capitole-Shadows.shp
)
#------------ otb::AmplitudeFuntor ----------------------
ADD_TEST(vrTuAmplitudeFunctorTest ${VISUALIZATION_TESTS1}
otbAmplitudeFunctorTest
)
# Testing srcs
SET(Visualization_SRCS1
otbVisualizationTests1.cxx
......@@ -445,6 +454,7 @@ otbVerticalAsymptoteCurveNew.cxx
otbVectorDataModelNew.cxx
otbVectorDataModelTest.cxx
otbVectorDataModelAddVectorDataTest.cxx
otbAmplitudeFunctorTest.cxx
)
OTB_ADD_EXECUTABLE(otbVisualizationTests1 "${Visualization_SRCS1}" "OTBVisualization;OTBIO;OTBTesting")
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkExceptionObject.h"
#include "otbAmplitudeFunctor.h"
#include "itkVariableLengthVector.h"
#include "itkRGBPixel.h"
#include "itkRGBAPixel.h"
int otbAmplitudeFunctorTest(int argc, char * argv[])
{
typedef double ScalarType;
typedef otb::Function::AmplitudeFunctor<ScalarType> FunctorType;
typedef itk::VariableLengthVector<ScalarType> VectorPixelType;
typedef itk::RGBPixel<ScalarType> RGBPixelType;
typedef itk::RGBAPixel<ScalarType> RGBAPixelType;
typedef VectorPixelType OutputPixelType;
FunctorType funct;
OutputPixelType output;
std::vector<unsigned int> channels;
ScalarType result;
VectorPixelType vectorPixel;
vectorPixel.SetSize(3);
vectorPixel.SetElement(0,1.0);
vectorPixel.SetElement(1,2.0);
vectorPixel.SetElement(2,3.0);
// Test VectorPixelType
for(unsigned int i = 0 ; i < 3 ; ++i)
{
for(unsigned int j = 0 ; j < 3 ; ++j)
{
channels.clear();
channels.push_back(i);
channels.push_back(j);
funct.SetChannelList(channels);
output = funct.operator ()(vectorPixel);
result = vcl_sqrt(vectorPixel[i] * vectorPixel[i] + vectorPixel[j] * vectorPixel[j]);
if( abs(result-output[0]) > 0.0000001)
{
std::cout << "vectorPixelType Test VectorPixelType failed for channels " << i<< " and "
<< j << " !" << std::endl;
return EXIT_FAILURE;
}
}
}
// Test RGBPixelType
RGBPixelType rgbPixel;
rgbPixel.SetRed(1.0);
rgbPixel.SetGreen(2.0);
rgbPixel.SetBlue(3.0);
for(unsigned int i = 0 ; i < 3 ; ++i)
{
for(unsigned int j = 0 ; j < 3 ; ++j)
{
channels.clear();
channels.push_back(i);
channels.push_back(j);
funct.SetChannelList(channels);
output = funct.operator ()(rgbPixel);
result = vcl_sqrt(rgbPixel[i] * rgbPixel[i] + rgbPixel[j] * rgbPixel[j]);
if( abs(result-output[0]) > 0.0000001)
{
std::cout << "vectorPixelType Test RGBPixelType failed for channels " << i<< " and "
<< j << " !" << std::endl;
return EXIT_FAILURE;
}
}
}
// Test RGBPAixelType
RGBAPixelType rgbaPixel;
rgbaPixel.SetRed(1.0);
rgbaPixel.SetGreen(2.0);
rgbaPixel.SetBlue(3.0);
rgbaPixel.SetAlpha(4.0);
for(unsigned int i = 0 ; i < 4 ; ++i)
{
for(unsigned int j = 0 ; j < 4 ; ++j)
{
channels.clear();
channels.push_back(i);
channels.push_back(j);
funct.SetChannelList(channels);
output = funct.operator ()(rgbaPixel);
result = vcl_sqrt(rgbaPixel[i] * rgbaPixel[i] + rgbaPixel[j] * rgbaPixel[j]);
if( abs(result-output[0]) > 0.0000001)
{
std::cout << "vectorPixelType Test RGBAPixelType failed for channels " << i<< " and "
<< j << " !" << std::endl;
return EXIT_FAILURE;
}
}
}
return EXIT_SUCCESS;
}
......@@ -77,4 +77,5 @@ void RegisterTests()
REGISTER_TEST(otbVectorDataModelNew);
REGISTER_TEST(otbVectorDataModelTest);
REGISTER_TEST(otbVectorDataModelAddVectorDataTest);
REGISTER_TEST(otbAmplitudeFunctorTest);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment