diff --git a/Code/IO/otbGDALImageIO.cxx b/Code/IO/otbGDALImageIO.cxx index e35e9ec99420a458dd09edcd61b9177f474135e9..b09b44a31be5bff1cee23bd2f3ae8fb71975a618 100644 --- a/Code/IO/otbGDALImageIO.cxx +++ b/Code/IO/otbGDALImageIO.cxx @@ -247,22 +247,101 @@ void GDALImageIO::Read(void* buffer) && (m_PxType != GDT_CFloat32) && (m_PxType != GDT_CFloat64)) { - CPLErr lCrGdal = dataset->GetRasterBand(1)->RasterIO(GF_Read, - lFirstColumn, - lFirstLine, - lNbColumns, - lNbLines, - p, - lNbColumns, - lNbLines, - m_PxType, - 0, - 0); + std::cout << "*** GDT_INT32 AND GDT_INT16 CASE ***" << std::endl; + int pixelOffset = m_BytePerPixel * m_NbBands; + int lineOffset = m_BytePerPixel * m_NbBands * lNbColumns; + int bandOffset = m_BytePerPixel; + int nbBands = m_NbBands; + + int nbPixelToRead = lNbColumns * lNbLines; + std::streamoff nbBytes = static_cast<std::streamoff>(m_NbBands) * static_cast<std::streamoff>(nbPixelToRead) * static_cast<std::streamoff>(m_BytePerPixel); + unsigned char *pBufferTemp = new unsigned char[static_cast<unsigned int>(nbBytes)]; + + + // keep it for the moment + std::cout << "*** GDALimageIO::Read: nominal case ***"<<std::endl; + std::cout << "Paremeters RasterIO :" \ + << ", indX = " << lFirstColumn \ + << ", indY = " << lFirstLine \ + << ", sizeX = " << lNbColumns \ + << ", sizeY = " << lNbLines \ + << ", GDAL Data Type = " << GDALGetDataTypeName(m_PxType) \ + << ", pixelOffset = " << pixelOffset \ + << ", lineOffset = " << lineOffset + << ", bandOffset = " << bandOffset << std::endl; + + + CPLErr lCrGdal = m_Dataset->GetDataSet()->RasterIO(GF_Read, + lFirstColumn, + lFirstLine, + lNbColumns, + lNbLines, + pBufferTemp, //p, // pData + lNbColumns, + lNbLines, + m_PxType, + nbBands, + // We want to read all bands + NULL, + pixelOffset, + lineOffset, + bandOffset); // Check for gdal error if (lCrGdal == CE_Failure) { itkExceptionMacro(<< "Error while reading image (GDAL format) " << m_FileName ); } + + // Reorganiser le buffer pour le faire fitter avec p qui doit contenir des GDT_Float64 + typedef std::complex<double> RealType; + typedef double ScalarRealType; + + RealType *realPxlValue = new RealType[nbPixelToRead * m_NbBands]; + if (m_PxType == GDT_CInt32) + { + std::cout << "Convert from input File from GDT_CInt32 to GDT_CFloat64" << std::endl; + typedef std::complex<int> ComplexIntType; + + ComplexIntType *pxlValue = new ComplexIntType[nbPixelToRead * m_NbBands]; + for (unsigned int itPxl = 0; itPxl < (unsigned int) (nbPixelToRead * m_NbBands); itPxl++) + { + pxlValue[itPxl] = *(static_cast<ComplexIntType*>( static_cast<void*>(pBufferTemp)) + itPxl ); + std::cout << "originalBuffer["<< itPxl << "] = " << pxlValue[itPxl] << std::endl; + + RealType pxlValueReal( static_cast<ScalarRealType>(pxlValue[itPxl].real()), static_cast<ScalarRealType>(pxlValue[itPxl].imag()) ); + realPxlValue[itPxl] = pxlValueReal; + std::cout << "newBuffer["<< itPxl << "] = " << realPxlValue[itPxl] << std::endl; + + memcpy((void*) (&(p[itPxl*sizeof(RealType)])), (const void*) (&(realPxlValue[itPxl])), (size_t) (sizeof(RealType))); + + RealType pxlValueRealOut = *(static_cast<RealType*>( static_cast<void*>(p)) + itPxl ); + std::cout << "p["<< itPxl << "] = " << pxlValueRealOut << std::endl; + } + delete[] pxlValue; + } + else if (m_PxType == GDT_CInt16) + { + std::cout << "Convert from input File from GDT_CInt16 to GDT_CFloat64" << std::endl; + typedef std::complex<short> ComplexShortType; + ComplexShortType *pxlValue = new ComplexShortType[nbPixelToRead * m_NbBands]; + for (unsigned int itPxl = 0; itPxl < (unsigned int) (nbPixelToRead * m_NbBands); itPxl++) + { + pxlValue[itPxl] = *(static_cast<ComplexShortType*>( static_cast<void*>(pBufferTemp)) + itPxl ); + std::cout << "originalBuffer["<< itPxl << "] = " << pxlValue[itPxl] << std::endl; + + RealType pxlValueReal( static_cast<ScalarRealType>(pxlValue[itPxl].real()), static_cast<ScalarRealType>(pxlValue[itPxl].imag()) ); + realPxlValue[itPxl] = pxlValueReal; + std::cout << "newBuffer["<< itPxl << "] = " << realPxlValue[itPxl] << std::endl; + + memcpy((void*) (&(p[itPxl*sizeof(RealType)])), (const void*) (&(realPxlValue[itPxl])), (size_t) (sizeof(RealType))); + + RealType pxlValueRealOut = *(static_cast<RealType*>( static_cast<void*>(p)) + itPxl ); + std::cout << "p["<< itPxl << "] = " << pxlValueRealOut << std::endl; + } + delete[] pxlValue; + } + delete[] realPxlValue; + } // In the indexed case, one has to retrieve the index image and the @@ -312,6 +391,7 @@ void GDALImageIO::Read(void* buffer) else { // Nominal case + std::cout << "*** NOMINAL CASE ***" << std::endl; int pixelOffset = m_BytePerPixel * m_NbBands; int lineOffset = m_BytePerPixel * m_NbBands * lNbColumns; int bandOffset = m_BytePerPixel; @@ -321,7 +401,7 @@ void GDALImageIO::Read(void* buffer) // if the file is complex and the reader is based on a vector of scalar, // output 2 times the number of bands, with real and imaginary parts interleaved - if(GDALDataTypeIsComplex(m_PxType) && !m_IsComplex && m_IsVectorImage) + /*if(GDALDataTypeIsComplex(m_PxType) && !m_IsComplex && m_IsVectorImage) { // ImageIO NbComponents is set to 2 * m_NbBands // m_BytePerPixel is already sizeof(std::complex<m_PxType>) / 2 @@ -329,24 +409,24 @@ void GDALImageIO::Read(void* buffer) lineOffset = pixelOffset * lNbColumns; bandOffset = 2 * m_BytePerPixel; nbBands = this->GetNumberOfComponents() / 2; - } + }*/ // if the file is scalar with only one band and the reader is based on a vector of complex - if(!GDALDataTypeIsComplex(m_PxType) && (m_NbBands == 1) && m_IsComplex && m_IsVectorImage ) + /*if(!GDALDataTypeIsComplex(m_PxType) && (m_NbBands == 1) && m_IsComplex && m_IsVectorImage ) { pixelOffset = m_BytePerPixel / 2; lineOffset =pixelOffset * lNbColumns; bandOffset = m_BytePerPixel / 2; - } - if(!GDALDataTypeIsComplex(m_PxType) && ((unsigned int)m_NbBands == this->GetNumberOfComponents()) && m_IsComplex && m_IsVectorImage && (m_NbBands > 1)) + }*/ + if(!GDALDataTypeIsComplex(m_PxType) /*&& ((unsigned int)m_NbBands == this->GetNumberOfComponents())*/ && m_IsComplex && m_IsVectorImage && (m_NbBands > 1)) { - pixelOffset = m_BytePerPixel; + pixelOffset = m_BytePerPixel * 2 ; lineOffset = pixelOffset * lNbColumns; - bandOffset = m_BytePerPixel / 2; + bandOffset = m_BytePerPixel /*/ 2*/; } // keep it for the moment - /* + std::cout << "*** GDALimageIO::Read: nominal case ***"<<std::endl; std::cout << "Paremeters RasterIO :" \ << ", indX = " << lFirstColumn \ @@ -357,7 +437,7 @@ void GDALImageIO::Read(void* buffer) << ", pixelOffset = " << pixelOffset \ << ", lineOffset = " << lineOffset << ", bandOffset = " << bandOffset << std::endl; - */ + CPLErr lCrGdal = m_Dataset->GetDataSet()->RasterIO(GF_Read, lFirstColumn, @@ -379,14 +459,19 @@ void GDALImageIO::Read(void* buffer) { itkExceptionMacro(<< "Error while reading image (GDAL format) " << m_FileName.c_str() << "."); } + typedef std::complex<int> ComplexType; + int nbPixelToRead = lNbColumns * lNbLines; + ComplexType *pxlValue = new ComplexType[nbPixelToRead * m_NbBands]; + unsigned int count = 0; + ComplexType expectedValue; + for (unsigned int itPxl = 0; itPxl < (unsigned int) (nbPixelToRead * m_NbBands); itPxl++) + { + pxlValue[itPxl] = *(static_cast<ComplexType*>( static_cast<void*>(p)) + itPxl ); + std::cout << "loadBuffer["<< itPxl << "] = " << pxlValue[itPxl] << std::endl; + } } } -void GDALImageIO::ReadImageInformation() -{ - //std::ifstream file; - this->InternalReadImageInformation(); -} bool GDALImageIO::GetSubDatasetInfo(std::vector<std::string> &names, std::vector<std::string> &desc) { @@ -425,6 +510,12 @@ bool GDALImageIO::GetSubDatasetInfo(std::vector<std::string> &names, std::vector return true; } +void GDALImageIO::ReadImageInformation() +{ + //std::ifstream file; + this->InternalReadImageInformation(); +} + void GDALImageIO::InternalReadImageInformation() { // Detecting if we are in the case of an image with subdatasets @@ -481,15 +572,15 @@ void GDALImageIO::InternalReadImageInformation() // Get Number of Bands m_NbBands = dataset->GetRasterCount(); - otbMsgDevMacro(<< "Dimension: " << m_Dimensions[0] << ", " << m_Dimensions[1]); - otbMsgDevMacro(<< "Number of bands: " << m_NbBands); + otbMsgDevMacro(<< "Input file dimension: " << m_Dimensions[0] << ", " << m_Dimensions[1]); + otbMsgDevMacro(<< "Number of bands inside input file: " << m_NbBands); this->SetNumberOfComponents(m_NbBands); // Set the number of dimensions (verify for the dim ) this->SetNumberOfDimensions(2); - otbMsgDevMacro(<< "Nb of Dimensions : " << m_NumberOfDimensions); + otbMsgDevMacro(<< "Nb of Dimensions of the input file: " << m_NumberOfDimensions); // Automatically set the Type to Binary for GDAL data this->SetFileTypeToBinary(); @@ -498,7 +589,7 @@ void GDALImageIO::InternalReadImageInformation() // Consider only the data type given by the first band // Maybe be could changed (to check) m_PxType = dataset->GetRasterBand(1)->GetRasterDataType(); - + otbMsgDevMacro(<< "PixelType inside input file: "<< GDALGetDataTypeName(m_PxType) ); if (m_PxType == GDT_Byte) { SetComponentType(UCHAR); @@ -507,7 +598,7 @@ void GDALImageIO::InternalReadImageInformation() { SetComponentType(USHORT); } - else if ((m_PxType == GDT_Int16) || (m_PxType == GDT_CInt16)) + else if (m_PxType == GDT_Int16) { SetComponentType(SHORT); } @@ -515,7 +606,7 @@ void GDALImageIO::InternalReadImageInformation() { SetComponentType(UINT); } - else if ((m_PxType == GDT_Int32) || (m_PxType == GDT_CInt32)) + else if (m_PxType == GDT_Int32) { SetComponentType(INT); } @@ -531,7 +622,7 @@ void GDALImageIO::InternalReadImageInformation() { SetComponentType(CFLOAT); } - else if (m_PxType == GDT_CFloat64) + else if ( (m_PxType == GDT_CFloat64) || (m_PxType == GDT_CInt32) || (m_PxType == GDT_CInt16) ) { SetComponentType(CDOUBLE); } @@ -578,7 +669,12 @@ void GDALImageIO::InternalReadImageInformation() } else if (this->GetComponentType() == CDOUBLE) { - m_BytePerPixel = sizeof(std::complex<double>); + if (m_PxType == GDT_CInt16) + m_BytePerPixel = sizeof(std::complex<short>); + else if (m_PxType == GDT_CInt32) + m_BytePerPixel = sizeof(std::complex<int>); + else + m_BytePerPixel = sizeof(std::complex<double>); } else { @@ -590,15 +686,27 @@ void GDALImageIO::InternalReadImageInformation() //Once all sorts of gdal complex image are handle, this won't be //necessary any more - if (GDALDataTypeIsComplex(m_PxType) //TODO should disappear - && (m_PxType != GDT_CFloat32) && (m_PxType != GDT_CFloat64)) + + // Set the pixel type with some special cases linked to the fact + // we read some data with complex type + if ( GDALDataTypeIsComplex(m_PxType) ) // Try to read data with complex type with GDAL { - m_BytePerPixel = m_BytePerPixel * 2; - this->SetNumberOfComponents(2); - this->SetPixelType(COMPLEX); - // Is this necessary ? + if ( !m_IsComplex && m_IsVectorImage ) + { + // we are reading a complex data set into an image where the pixel + // type is Vector<real>: we have to double the number of component + // for that to work + otbDebugMacro( "GDALtypeIO= Complex and IFReader::InternalPixelType= Scalar and IFReader::PixelType= Vector"); + this->SetNumberOfComponents(m_NbBands*2); + this->SetPixelType(VECTOR); + } + else + { + this->SetPixelType(COMPLEX); + } } - else + else // Try to read data with scalar type with GDAL + //if ( !GDALDataTypeIsComplex(m_PxType) ) { this->SetNumberOfComponents(m_NbBands); if (this->GetNumberOfComponents() == 1) @@ -611,35 +719,39 @@ void GDALImageIO::InternalReadImageInformation() } } - if (GDALDataTypeIsComplex(m_PxType) && !m_IsComplex && m_IsVectorImage) + /*if (GDALDataTypeIsComplex(m_PxType) && ) { // we are reading a complex data set into an image where the pixel // type is Vector<real>: we have to double the number of component // for that to work - //std::cout << "GDALtypeIO = complex and OTB::OutputPixelType = double and OTB::PixelType = Vector" << std::endl; - m_BytePerPixel = m_BytePerPixel / 2; + std::cout << "GDALtypeIO = Complex and IFReader::InternalPixelType = Scalar and IFReader::PixelType = Vector" << std::endl; + //if ( (m_PxType != GDT_CInt32) && (m_PxType != GDT_CInt16) ) + // m_BytePerPixel = m_BytePerPixel / 2; this->SetNumberOfComponents(m_NbBands*2); this->SetPixelType(VECTOR); - } + }*/ - if (!GDALDataTypeIsComplex(m_PxType) && m_IsComplex && m_IsVectorImage) + /*if (!GDALDataTypeIsComplex(m_PxType) && m_IsComplex && m_IsVectorImage && (m_NbBands > 1)) { // we are reading a non-complex data set into an image where the pixel // type is Vector<complex>: we have to double the number of byte per pixel // for that to work - //std::cout << "GDALtypeIO = double and OTB::OutputPixelType = complex and OTB::PixelType = Vector" << std::endl; - m_BytePerPixel = m_BytePerPixel * 2; + std::cout << "GDALtypeIO = Scalar and IFReader::InternalPixelType = Complex and IFReader::PixelType = Vector" << std::endl; + //if ( (m_PxType != GDT_CInt32) && (m_PxType != GDT_CInt16) ) + //m_BytePerPixel = m_BytePerPixel * 2; this->SetPixelType(VECTOR); - } + }*/ + + /* if (!GDALDataTypeIsComplex(m_PxType) && m_IsComplex && !m_IsVectorImage && ( (m_PxType == GDT_CInt32) || (m_PxType == GDT_CInt16) ) ) + { + m_BytePerPixel = m_BytePerPixel / 2; + }*/ - // keep it for the moment - /* std::cout << " *** Parameters set in Internal Read function ***" << std::endl; - std::cout << " Pixel Type GDAL = " << GDALGetDataTypeName(m_PxType) << std::endl; - std::cout << " Pixel Type otb = " << GetPixelTypeAsString(this->GetPixelType()) << std::endl; - std::cout << " Number of band in file = " << m_NbBands << std::endl; - std::cout << " Number of component otb = " << this->GetNumberOfComponents() << std::endl; - std::cout << " Byte per pixel = " << m_BytePerPixel << std::endl; - std::cout << " Component Type otb = " << GetComponentTypeAsString(this->GetComponentType()) <<std::endl; */ + /*** Parameters set by Internal Read function ***/ + otbMsgDevMacro( << " Pixel Type IFReader = " << GetPixelTypeAsString(this->GetPixelType()) ) + otbMsgDevMacro( << " Number of component IFReader = " << this->GetNumberOfComponents() ) + otbMsgDevMacro( << " Byte per pixel set = " << m_BytePerPixel ) + otbMsgDevMacro( << " Component Type set = " << GetComponentTypeAsString(this->GetComponentType()) ); /*----------------------------------------------------------------------*/ /*-------------------------- METADATA ----------------------------------*/ diff --git a/Code/IO/otbImageFileReader.txx b/Code/IO/otbImageFileReader.txx index 879035b5c072ed922e1cf795152a556be148cd30..c94d41d679ed74177dd5ff5f5b107c735cbbaf60 100644 --- a/Code/IO/otbImageFileReader.txx +++ b/Code/IO/otbImageFileReader.txx @@ -175,11 +175,11 @@ ImageFileReader<TOutputImage> * static_cast<std::streamoff>(region.GetNumberOfPixels()); char * loadBuffer = new char[nbBytes]; - /*std::cout<< "*** IFReader : read with conversion ***" << std::endl; + std::cout<< "*** IFReader : read with conversion ***" << std::endl; std::cout<< "size of Buffer to GDALImageIO::read = " << nbBytes << " = " \ << "ComponentSize ("<< this->m_ImageIO->GetComponentSize() << ") x " \ << "Nb of Component (" << this->m_ImageIO->GetNumberOfComponents() << ") x " \ - << "Nb of Pixel to read (" << region.GetNumberOfPixels() << ")" << std::endl; */ + << "Nb of Pixel to read (" << region.GetNumberOfPixels() << ")" << std::endl; this->m_ImageIO->Read(loadBuffer); this->DoConvertBuffer(loadBuffer, region.GetNumberOfPixels()); diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 49a9cdf4cf1f89ac0b0348f7e4a58631c4ed5de9..02456f867d31ea283a43f29278b2f39ea29fa2fc 100644 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -2859,19 +2859,43 @@ FOREACH(INPUTFILE_PIXELTYPE ${INPUTFILE_PIXELTYPES_LIST}) # otbMultibandComplexToImageScalar${READING_PIXELTYPE} # ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands.tif) #hdr) - ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToVectorImageScalar${READING_PIXELTYPE} - ${IO_TESTS21} - otbMultibandComplexToVectorImageScalar${READING_PIXELTYPE} - ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands.tif) #hdr) + # Size: 100x100 is to large to store pixel values coded as short. + IF ( NOT ${INPUTFILE_PIXELTYPE} MATCHES "Short" ) + ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToVectorImageScalar${READING_PIXELTYPE} + ${IO_TESTS21} + otbMultibandComplexToVectorImageScalar${READING_PIXELTYPE} + ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands.tif) #hdr) + + ELSE ( NOT ${INPUTFILE_PIXELTYPE} MATCHES "Short" ) + + ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToVectorImageScalar${READING_PIXELTYPE} + ${IO_TESTS21} + otbMultibandComplexToVectorImageScalar${READING_PIXELTYPE} + ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands_50x50.tif) #hdr) + + ENDIF ( NOT ${INPUTFILE_PIXELTYPE} MATCHES "Short" ) + # Weird case : need specifications to write the test # [missing impl] # ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToImageComplex${READING_PIXELTYPE}) - - ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToVectorImageComplex${READING_PIXELTYPE} - ${IO_TESTS21} - otbMultibandComplexToVectorImageComplex${READING_PIXELTYPE} - ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands.tif) #hdr) + + # Size: 100x100 is to large to store pixel values coded as short. + IF ( NOT ${INPUTFILE_PIXELTYPE} MATCHES "Short" ) + + ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToVectorImageComplex${READING_PIXELTYPE} + ${IO_TESTS21} + otbMultibandComplexToVectorImageComplex${READING_PIXELTYPE} + ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands.tif) #hdr) + + ELSE ( NOT ${INPUTFILE_PIXELTYPE} MATCHES "Short" ) + + ADD_TEST(ioTvMultibandComplex${INPUTFILE_PIXELTYPE}${NBBANDS}BandsToVectorImageComplex${READING_PIXELTYPE} + ${IO_TESTS21} + otbMultibandComplexToVectorImageComplex${READING_PIXELTYPE} + ${INPUTDATA}/multibandComplex${INPUTFILE_PIXELTYPE}_${NBBANDS}bands_50x50.tif) #hdr) + + ENDIF ( NOT ${INPUTFILE_PIXELTYPE} MATCHES "Short" ) ENDFOREACH(NBBANDS ${NBBANDS_LIST}) diff --git a/Testing/Code/IO/otbComplexImageManipulationTest.cxx b/Testing/Code/IO/otbComplexImageManipulationTest.cxx index 468360326dc0a6014df94368939d2d7a9c439ed5..6af1d57f62567219a623d7d540e0dbbd71235072 100644 --- a/Testing/Code/IO/otbComplexImageManipulationTest.cxx +++ b/Testing/Code/IO/otbComplexImageManipulationTest.cxx @@ -175,11 +175,13 @@ int otbMonobandScalarToImageComplexShort(int argc, char * argv[]) template<class InternalType> int otbMonobandComplexToImageScalarGeneric(int argc, char * argv[]) { - typedef InternalType RealType; - typedef std::complex<RealType> ComplexType; + typedef InternalType InputType; + typedef std::complex<InputType> ComplexType; + typedef typename itk::NumericTraits<ComplexType>::RealType RealType; + typedef typename itk::NumericTraits<ComplexType>::ScalarRealType ScalarRealType; - typedef RealType PixelType; - typedef otb::Image<PixelType, 2> ImageType; + typedef InputType PixelType; + typedef otb::Image<PixelType, 2> ImageType; const unsigned int w = 10; const unsigned int h = 2; @@ -194,11 +196,11 @@ int otbMonobandComplexToImageScalarGeneric(int argc, char * argv[]) for (it.GoToBegin(); !it.IsAtEnd(); ++it) { count = 2 * (it.GetIndex()[1] * largestRegion[0] + it.GetIndex()[0]); - std::cout << "it.GetIndex() " << it.GetIndex() << std::endl; - std::cout << "largestRegion " << largestRegion << std::endl; - std::cout << "count " << count << std::endl; - if ( !TestCompare(it.GetIndex(), it.Get(), vcl_abs(ComplexType(count, count+1)) ) ) + ComplexType expected = ComplexType(count, count+1); + RealType expectedReal( static_cast<ScalarRealType>(expected.real()), static_cast<ScalarRealType>(expected.imag()) ); + + if ( !TestCompare(it.GetIndex(), it.Get(), static_cast<InputType>(vcl_abs(expectedReal)) ) ) return EXIT_FAILURE; } diff --git a/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx b/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx index 76e61893434a786cd5d047a5f4ee05a8729aefb0..fe982f7f31697b5a0ff55b29c0457a27ecaf4af5 100644 --- a/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx +++ b/Utilities/ITK/Code/IO/itkConvertPixelBuffer.txx @@ -609,8 +609,7 @@ ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits> while(inputData != endInput) { OutputConvertTraits::SetNthComponent(0, *outputData, - static_cast<OutputPixelType> - (SpecialCast(*inputData,dummy))); + static_cast<OutputPixelType> (SpecialCast(*inputData,dummy))); inputData++; outputData++; } @@ -724,14 +723,25 @@ template<typename InputType, typename OutputType> OutputType SpecialCast(const std::complex<InputType>& in, const OutputType& itkNotUsed(dummy)) { - return static_cast < OutputType >( std::abs(in) ); + typedef typename itk::NumericTraits<std::complex<InputType> >::RealType RealType; + typedef typename itk::NumericTraits<std::complex<InputType> >::ScalarRealType ScalarRealType; + + //RealType inReal = static_cast<RealType>(in); + RealType inReal( static_cast<ScalarRealType>(in.real()), static_cast<ScalarRealType>(in.imag()) ); + + return static_cast < OutputType >( vcl_abs(inReal) ); } template<typename InputType, typename OutputType> std::complex<OutputType> SpecialCast(const std::complex<InputType>& in, const std::complex<OutputType>& itkNotUsed(dummy)) { - return static_cast < std::complex<OutputType> >( in ); + typedef typename itk::NumericTraits<std::complex<InputType> >::RealType RealType; + typedef typename itk::NumericTraits<std::complex<InputType> >::ScalarRealType ScalarRealType; + + RealType inReal( static_cast<ScalarRealType>(in.real()), static_cast<ScalarRealType>(in.imag()) ); + + return static_cast < std::complex<OutputType> >( inReal ); } template < typename InputPixelType, diff --git a/Utilities/ITK/Code/IO/itkImageFileReader.txx b/Utilities/ITK/Code/IO/itkImageFileReader.txx index ec6b8a94e597ec7253a7bb29207a052442b7242a..1df9a9ef5f9f86a8784496101c5d0bd33c9536e0 100644 --- a/Utilities/ITK/Code/IO/itkImageFileReader.txx +++ b/Utilities/ITK/Code/IO/itkImageFileReader.txx @@ -533,8 +533,10 @@ ImageFileReader<TOutputImage, ConvertPixelTraits> { \ if( strcmp( this->GetOutput()->GetNameOfClass(), "VectorImage" ) == 0 ) \ { \ - if( (typeid(OutputImagePixelType) == typeid(std::complex<double>)) \ - || (typeid(OutputImagePixelType) == typeid(std::complex<float>)) )\ + if( (typeid(OutputImagePixelType) == typeid(std::complex<double>)) \ + || (typeid(OutputImagePixelType) == typeid(std::complex<float>)) \ + || (typeid(OutputImagePixelType) == typeid(std::complex<int>)) \ + || (typeid(OutputImagePixelType) == typeid(std::complex<short>)) ) \ {\ /*std::cout << "Complex -> OTB::VectorImage Complex" << std::endl;*/ \ ConvertPixelBuffer< \ @@ -592,6 +594,8 @@ ImageFileReader<TOutputImage, ConvertPixelTraits> ITK_CONVERT_BUFFER_IF_BLOCK( long) ITK_CONVERT_BUFFER_IF_BLOCK(float) ITK_CONVERT_BUFFER_IF_BLOCK( double) + ITK_CONVERT_CBUFFER_IF_BLOCK(std::complex<short>) + ITK_CONVERT_CBUFFER_IF_BLOCK(std::complex<int>) ITK_CONVERT_CBUFFER_IF_BLOCK(std::complex<float>) ITK_CONVERT_CBUFFER_IF_BLOCK(std::complex<double>) else