diff --git a/Code/Visualization/otbVectorDataActionHandler.h b/Code/Visualization/otbVectorDataActionHandler.h index 5e850e74ca109dbb0b7d3f0d5a8cd92962d81c1b..d1f062e25232c3179a83bfc60a9b6c7ec9da0aea 100644 --- a/Code/Visualization/otbVectorDataActionHandler.h +++ b/Code/Visualization/otbVectorDataActionHandler.h @@ -94,11 +94,19 @@ public: = sourceWidget->GetScreenToImageTransform()->TransformPoint( screenPoint); + if( m_IsContinuousPoint == false ) + { + imagePoint[0] = static_cast<unsigned int>(imagePoint[0]) + 0.5; + imagePoint[1] = static_cast<unsigned int>(imagePoint[1]) + 0.5; + } + + // Transform to index typename ModelType::VertexType index; index[0] = imagePoint[0]; index[1] = imagePoint[1]; + //Add Offset index[0] += m_Offset[0]; index[1] += m_Offset[1]; @@ -178,18 +186,23 @@ public: itkSetMacro(Offset, OffsetType); itkGetMacro(Offset, OffsetType); - /** Set/Get End polygon Mouse butto */ + /** Set/Get End polygon Mouse button */ itkSetMacro(EndMouseButton, int); itkGetMacro(EndMouseButton, int); - /** Set/Get Add polygon Mouse butto */ + /** Set/Get Add polygon Mouse button */ itkSetMacro(AddMouseButton, int); itkGetMacro(AddMouseButton, int); + /** Set/Get if Screen Point Centered */ + itkSetMacro(IsContinuousPoint, bool); + itkGetMacro(IsContinuousPoint, bool); + protected: /** Constructor */ VectorDataActionHandler() : - m_Offset(), m_View(), m_Model(), m_EndMouseButton(3), m_AddMouseButton(1) + m_Offset(), m_View(), m_Model(), m_EndMouseButton(3), + m_AddMouseButton(1), m_IsContinuousPoint(true) { } @@ -222,6 +235,9 @@ private: /// Add polygon Mouse button int m_AddMouseButton; + // Is image point is continous otherwise centered + bool m_IsContinuousPoint; + }; // end class } // end namespace otb diff --git a/Testing/Code/IO/otbComplexImageManipulationTest.cxx b/Testing/Code/IO/otbComplexImageManipulationTest.cxx index 86c135dd610fd2f5f2bb4479110165ca9a5c527a..eba1491fda1174572c34f4d065a76946c36fa3b3 100644 --- a/Testing/Code/IO/otbComplexImageManipulationTest.cxx +++ b/Testing/Code/IO/otbComplexImageManipulationTest.cxx @@ -24,7 +24,11 @@ #include "itkImageRegionIteratorWithIndex.h" #include "itkImageRegionIterator.h" - +/*********** + * 1. + * Read Image<double> as Image<complex> + * out : real = a, imag = 0 + ***********/ int otbImageDoubleToImageComplex(int argc, char * argv[]) { typedef double RealType; @@ -68,7 +72,11 @@ int otbImageDoubleToImageComplex(int argc, char * argv[]) return EXIT_SUCCESS; } - +/*********** + * 2. + * Read Image<complex> as Image<double> + * out : norm(in) + ***********/ int otbImageComplexToImageDouble(int argc, char * argv[]) { typedef double RealType; @@ -116,7 +124,11 @@ int otbImageComplexToImageDouble(int argc, char * argv[]) } - +/*********** + * 3. + * Read Image<complex> as Image<complex> + * out : in + ***********/ int otbImageComplexToImageComplex(int argc, char * argv[]) { typedef double RealType; @@ -165,7 +177,11 @@ int otbImageComplexToImageComplex(int argc, char * argv[]) } - +/*********** + * 4. + * Read Image<complex> as VectorImage<double> + * out : [0]=in.real(), [1]=in.imag() + ***********/ int otbImageComplexToVectorImageDouble(int argc, char * argv[]) { typedef double RealType; @@ -211,7 +227,11 @@ int otbImageComplexToVectorImageDouble(int argc, char * argv[]) return EXIT_SUCCESS; } - +/*********** + * 5. + * Read Image<complex> as VectorImage<complex> + * out : [0]=in + ***********/ int otbImageComplexToVectorImageComplex(int argc, char * argv[]) { typedef double RealType; @@ -258,7 +278,11 @@ int otbImageComplexToVectorImageComplex(int argc, char * argv[]) return EXIT_SUCCESS; } - +/*********** + * 6. + * Read VectorImage<double> as Image<complex> + * out : out.real=in[0], out.imag=in[1] + ***********/ int otbVectorImageDoubleToImageComplex(int argc, char * argv[]) { typedef double RealType; @@ -305,7 +329,11 @@ int otbVectorImageDoubleToImageComplex(int argc, char * argv[]) return EXIT_SUCCESS; } - +/*********** + * 7. + * Read VectorImage<double> as VectorImage<complex> + * out : (out[0].real=in, out[0].imag=1), (out[1].real=in, out[1].imag=0), ... + ***********/ int otbVectorImageDoubleToVectorImageComplex(int argc, char * argv[]) { typedef double RealType; @@ -352,6 +380,11 @@ int otbVectorImageDoubleToVectorImageComplex(int argc, char * argv[]) return EXIT_SUCCESS; } +/*********** + * 8. + * Read VectorImage<complex> as VectorImage<complex> + * out : out[0]=in[0], out[1]=in[1], ... + ***********/ int otbVectorImageComplexToVectorImageDouble(int argc, char * argv[]) { typedef double RealType; @@ -363,7 +396,7 @@ int otbVectorImageComplexToVectorImageDouble(int argc, char * argv[]) reader->SetFileName(argv[1]); ScalVectorImageType::IndexType id; - SccalVectorImageType::SizeType size; + ScalVectorImageType::SizeType size; ScalVectorImageType::RegionType region; id.Fill(0); @@ -375,15 +408,15 @@ int otbVectorImageComplexToVectorImageDouble(int argc, char * argv[]) reader->GetOutput()->SetRequestedRegion(region); reader->Update(); + unsigned int l_Size = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]* reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; itk::ImageRegionIterator<ScalVectorImageType> it( reader->GetOutput(), region ); - unsigned int l_Size = reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[0]* reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[1]; unsigned int count = 0; it.GoToBegin(); while( it.IsAtEnd()==false ) { - RealType norm1 = static_cast<double>( vcl_sqrt( static_cast<double>( (count*count)+((count+1)*(count+1)) ) ) ); - RealType norm2 = static_cast<double>( vcl_sqrt( static_cast<double>( ((l_size+count)*(l_Size+count))+((l_Size+count+1)*(l_Size+count+1)) ) ) ); + double norm1 = vcl_sqrt(static_cast<double>(count*count + (count+1)*(count+1))); + double norm2 = vcl_sqrt(static_cast<double>((l_Size+count)*(l_Size+count) + (l_Size+count+1)*(l_Size+count+1))); if( (it.Get()[0] != norm1) || (it.Get()[1] != norm2) ) { std::cout<<"Vector Image complex read as Vector Image double error: "<<it.Get()<<", waited for ("<<norm1<<", "<<norm2<<")."<<std::endl; @@ -400,10 +433,79 @@ int otbVectorImageComplexToVectorImageDouble(int argc, char * argv[]) } +/*********** + * 9. + * Read VectorImage<complex> as VectorImage<complex> + * out : out[0]=norm(in[0]), out[0]=norm(in[1]), ... + ***********/ +int otbVectorImageComplexToVectorImageComplex(int argc, char * argv[]) +{ + typedef double RealType; + typedef std::complex<RealType> PixelType; + typedef otb::VectorImage<PixelType, 2> CmplxVectorImageType; + typedef otb::ImageFileReader<CmplxVectorImageType> ReaderType; + + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(argv[1]); + + CmplxVectorImageType::IndexType id; + CmplxVectorImageType::SizeType size; + CmplxVectorImageType::RegionType region; + + id.Fill(0); + size[0] = 10; + size[1] = 1; + + region.SetSize( size ); + region.SetIndex( id ); + + reader->GetOutput()->SetRequestedRegion(region); + reader->Update(); + + if(reader->GetOutput()->GetNumberOfComponentsPerPixel() != 1) + { + std::cout<<"Invalid image size, should be 1, no "<<reader->GetOutput()->GetNumberOfComponentsPerPixel()<<"."<<std::endl; + + return EXIT_FAILURE; + } + + itk::ImageRegionIterator<CmplxVectorImageType> it( reader->GetOutput(), region ); + unsigned int l_Size = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]* reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; + + unsigned int count = 0; + it.GoToBegin(); + while( it.IsAtEnd()==false ) + { + PixelType cmplx1(count, count+1); + PixelType cmplx2(l_Size+count, l_Size+count+1); + if( (it.Get()[0] != cmplx1) || (it.Get()[1] != cmplx2) ) + { + std::cout<<"Image double read as Vector Image complex error: "<<std::endl; + std::cout<<it.Get()[0]<<", waited for "<<cmplx1<<"."<<std::endl; + std::cout<<it.Get()[1]<<", waited for "<<cmplx2<<"."<<std::endl; + + return EXIT_FAILURE; + } + + count++; + ++it; + } + + + return EXIT_SUCCESS; +} + + +/*********** + * 10. + * Read Image<double> as VectorImage<complex> + * out : out[0].real()=in, out[0].imag=0 + ***********/ int otbImageDoubleToVectorImageComplex(int argc, char * argv[]) { typedef double RealType; - typedef std::complex<RealType> PixelType; + typedef std::complex<RealType> PixelType; typedef otb::VectorImage<PixelType, 2> CmplxVectorImageType; typedef otb::ImageFileReader<CmplxVectorImageType> ReaderType; @@ -433,7 +535,7 @@ int otbImageDoubleToVectorImageComplex(int argc, char * argv[]) } itk::ImageRegionIterator<CmplxVectorImageType> it( reader->GetOutput(), region ); - unsigned int l_Size = reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[0]* reader->GetOutpuGetOutput()->GetLargetPossibleRegion().GetSize()[1]; + unsigned int l_Size = reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]* reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]; unsigned int count = 0; it.GoToBegin(); diff --git a/Testing/Code/IO/otbIOTests21.cxx b/Testing/Code/IO/otbIOTests21.cxx index 9c0bf5842901117d2c6c1b1c3edbd4eac68508cd..495663ce640507f2d35e006f5127f962b10a36ca 100644 --- a/Testing/Code/IO/otbIOTests21.cxx +++ b/Testing/Code/IO/otbIOTests21.cxx @@ -38,6 +38,7 @@ void RegisterTests() REGISTER_TEST(otbImageComplexToVectorImageComplex); REGISTER_TEST(otbVectorImageDoubleToImageComplex); REGISTER_TEST(otbVectorImageDoubleToVectorImageComplex); + REGISTER_TEST(otbVectorImageComplexToVectorImageDouble); REGISTER_TEST(otbVectorImageComplexToVectorImageComplex); REGISTER_TEST(otbImageDoubleToVectorImageComplex); } diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt index 4d58d4944dcaac00914999c16f4ea120ed1fa1a0..274b3d4e12e3cd6641832742c7eed2d0e74f4348 100644 --- a/Testing/Code/Projections/CMakeLists.txt +++ b/Testing/Code/Projections/CMakeLists.txt @@ -251,7 +251,7 @@ FOREACH( file ${SARSENSORMODEL_TYPES}) STRING(REGEX REPLACE "${sharp_regexp}" "\\1" sensor_name "${file}") # Tests ADD_TEST(prTvSensorModelGrid_${sensor_name} ${PROJECTIONS_TESTS1} - --compare-n-images ${NOTOL} 2 + --compare-n-images ${EPSILON_6} 2 ${BASELINE}/prTvSensorModelGridDeltaX_${sensor_name}.tif ${TEMP}/prTvSensorModelGridDeltaX_${sensor_name}.tif ${BASELINE}/prTvSensorModelGridDeltaY_${sensor_name}.tif @@ -264,7 +264,7 @@ FOREACH( file ${SARSENSORMODEL_TYPES}) ) ADD_TEST(prTvForwardSensorModelGrid_${sensor_name} ${PROJECTIONS_TESTS1} - --compare-n-images ${NOTOL} 2 + --compare-n-images ${EPSILON_6} 2 ${BASELINE}/prTvForwardSensorModelGridX_${sensor_name}.tif ${TEMP}/prTvForwardSensorModelGridX_${sensor_name}.tif ${BASELINE}/prTvForwardSensorModelGridY_${sensor_name}.tif