From: dsarrut Date: Mon, 11 Apr 2011 16:48:46 +0000 (+0000) Subject: Romulo: X-Git-Tag: v1.2.0~55 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ad026a6ff3c2d3d57b7d25c55179e3460d0d04a3;p=clitk.git Romulo: - 1st version of the LineProfile tool + clitkLineProfile -i IMAGE --p0 POINT --p1 POINT + POINT can, in principle, be in 2D or 3D, but must match the image dimension (needs testing still) + output to std out * [INDEX] VALUE * index is comma separated list of coordinates --- diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index cc77ea3..7ff9705 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -249,4 +249,9 @@ IF (CLITK_BUILD_TOOLS) ADD_EXECUTABLE(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C}) TARGET_LINK_LIBRARIES(clitkTransformLandmarks clitkCommon ITKIO) + WRAP_GGO(clitkLineProfile_GGO_C clitkLineProfile.ggo) + ADD_EXECUTABLE(clitkLineProfile clitkLineProfile.cxx clitkLineProfileGenericFilter.cxx ${clitkLineProfile_GGO_C}) + TARGET_LINK_LIBRARIES(clitkLineProfile clitkCommon ITKIO) + ENDIF(CLITK_BUILD_TOOLS) + diff --git a/tools/clitkLineProfile.cxx b/tools/clitkLineProfile.cxx new file mode 100755 index 0000000..2eb2eb0 --- /dev/null +++ b/tools/clitkLineProfile.cxx @@ -0,0 +1,21 @@ +#include "clitkLineProfile_ggo.h" +#include "clitkLineProfileGenericFilter.h" + + +bool verbose = false; + +template +void run(const args_info_clitkLineProfile& argsInfo); + +int main(int argc, char** argv) +{ + GGO(clitkLineProfile, args_info); + + clitk::LineProfileGenericFilter::Pointer filter = clitk::LineProfileGenericFilter::New(); + filter->SetArgsInfo(args_info); + filter->Update(); + + return EXIT_SUCCESS; +} + + diff --git a/tools/clitkLineProfile.ggo b/tools/clitkLineProfile.ggo new file mode 100755 index 0000000..b61caa2 --- /dev/null +++ b/tools/clitkLineProfile.ggo @@ -0,0 +1,12 @@ +#File clitkLineProfile.ggo +package "clitkLineProfile" +version "1.0" +purpose "Get the HU profile along the given line. Output to stdout." + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off + +option "input" i "Input image" string yes +option "p0" - "First point of the line" int no multiple default="0" +option "p1" - "Second point of the line" int no multiple default="0" +#option "output" o "Output file containing formated line points and values" string yes diff --git a/tools/clitkLineProfileGenericFilter.cxx b/tools/clitkLineProfileGenericFilter.cxx new file mode 100755 index 0000000..b7cca14 --- /dev/null +++ b/tools/clitkLineProfileGenericFilter.cxx @@ -0,0 +1,27 @@ +#include "clitkLineProfileGenericFilter.h" + +namespace clitk +{ + //----------------------------------------------------------- + // Constructor + //----------------------------------------------------------- + LineProfileGenericFilter::LineProfileGenericFilter() + : ImageToImageGenericFilter("Resample") + { + m_Verbose=false; + + InitializeImageType<2>(); + InitializeImageType<3>(); + //InitializeImageType<4>(); + } + //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + template + void LineProfileGenericFilter::InitializeImageType() + { + ADD_DEFAULT_IMAGE_TYPES(Dim); + //ADD_IMAGE_TYPE(Dim, short); + } + //-------------------------------------------------------------------- + +} \ No newline at end of file diff --git a/tools/clitkLineProfileGenericFilter.h b/tools/clitkLineProfileGenericFilter.h new file mode 100755 index 0000000..8a3803b --- /dev/null +++ b/tools/clitkLineProfileGenericFilter.h @@ -0,0 +1,104 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ +#ifndef clitkLineProfileGenericFilter_h +#define clitkLineProfileGenericFilter_h + +/* ================================================= + * @file clitkLineProfileGenericFilter.h + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "clitkImageToImageGenericFilter.h" +#include "clitkLineProfile_ggo.h" + + +namespace clitk +{ + + class ITK_EXPORT LineProfileGenericFilter: + public ImageToImageGenericFilter + { + public: + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + LineProfileGenericFilter(); + ~LineProfileGenericFilter() {}; + + + //---------------------------------------- + // ITK + //---------------------------------------- + typedef LineProfileGenericFilter Self; + typedef itk::LightObject Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + // Method for creation through the object factory + itkNewMacro(Self); + + // Run-time type information (and related methods) + itkTypeMacro( SetSpacingGenericFilter, LightObject ); + + //---------------------------------------- + // Typedefs + //---------------------------------------- + typedef args_info_clitkLineProfile ArgsInfoType; + + //---------------------------------------- + // Set & Get + //---------------------------------------- + void SetArgsInfo(const ArgsInfoType & a) + { + m_ArgsInfo=a; + m_Verbose=m_ArgsInfo.verbose_flag; + SetIOVerbose(m_Verbose); + SetInputFilename(m_ArgsInfo.input_arg); + } + + //---------------------------------------- + // Templated members + //---------------------------------------- + template void UpdateWithInputImageType(); + + protected: + + //---------------------------------------- + // Templated members + //---------------------------------------- + //template void UpdateWithDim(std::string PixelType, unsigned int Components); + template void InitializeImageType(); + + //---------------------------------------- + // Data members + //---------------------------------------- + args_info_clitkLineProfile m_ArgsInfo; + bool m_Verbose; + + }; +} + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkLineProfileGenericFilter.txx" +#endif + +#endif // clitkLineProfileGenericFilter_h \ No newline at end of file diff --git a/tools/clitkLineProfileGenericFilter.txx b/tools/clitkLineProfileGenericFilter.txx new file mode 100755 index 0000000..9967db1 --- /dev/null +++ b/tools/clitkLineProfileGenericFilter.txx @@ -0,0 +1,134 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ +#ifndef clitkLineProfileGenericFilter_cxx +#define clitkLineProfileGenericFilter_cxx + +/* ================================================= + * @file clitkLineProfileGenericFilter.cxx + * @author + * @date + * + * @brief + * + ===================================================*/ + +#include "itkBresenhamLine.h" + +namespace clitk +{ + +//----------------------------------------------------------- + // Update + //----------------------------------------------------------- + template + void LineProfileGenericFilter::UpdateWithInputImageType() + { + typedef InputImageType ImageType; + + if (m_Verbose) + std::cout << "LineProfileGenericFilter::UpdateWithInputImageType" << std::endl; + + // type checks + if (m_ArgsInfo.p0_given != ImageType::ImageDimension || + m_ArgsInfo.p1_given != ImageType::ImageDimension) + throw std::logic_error("Dimension of input points and image do not match."); + + typename ImageType::Pointer image = this->template GetInput(0); + typename ImageType::RegionType region = image->GetLargestPossibleRegion(); + + typedef typename ImageType::PointType PointType; + PointType p0, p1; + for (unsigned int i = 0; i < ImageType::ImageDimension; i++) { + p0[i] = m_ArgsInfo.p0_arg[i]; + p1[i] = m_ArgsInfo.p1_arg[i]; + } + + // compute params of line between p0 and p1 + // length (magnitude) must be an integer value, so it's + // the max distance along one the axes plus one to account + // for the last point. + typedef itk::BresenhamLine LineType; + typename LineType::LType direction = p1 - p0; + typename LineType::LType::RealValueType mag = 0; + for (unsigned int i = 0; i < ImageType::ImageDimension; i++) { + if (direction[i] > mag) + mag = direction[i]; + } + mag++; + + if (m_Verbose) + std::cout << "Building line with direction = " << direction << " and length = " << mag << "..." << std::endl; + + // build the line itself + LineType line; + typename LineType::OffsetArray offsets; + offsets = line.BuildLine(direction, mag); + + if (m_Verbose) + std::cout << "Line has " << offsets.size() << " points" << std::endl; + + // fill the output vectors + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::OffsetType OffsetType; + typedef typename ImageType::IndexType IndexType; + typedef std::vector IndexArrayType; + typedef std::vector ValueArrayType; + + IndexType index0, index1; + for (unsigned int i = 0; i < ImageType::ImageDimension; i++) { + index0[i] = m_ArgsInfo.p0_arg[i]; + index1[i] = m_ArgsInfo.p1_arg[i]; + } + + if (m_Verbose) + std::cout << "Getting profile along line..." << std::endl; + + IndexType index; + IndexArrayType line_indices; + ValueArrayType line_values; + for (size_t i = 0; i < offsets.size(); i++) + { + index = index0 + offsets[i]; + if (m_Verbose) { + std::cout << "index " << i << " = " << index << std::endl; + } + + if (region.IsInside(index)) { + if (m_Verbose) + std::cout << "value " << i << " = " << image->GetPixel(index) << std::endl; + + line_indices.push_back(index); + line_values.push_back(image->GetPixel(index)); + } + else if (m_Verbose) + std::cout << "index outside image" << std::endl; + } + + if (m_Verbose) { + std::cout << "I bring to you The Computed Points!" << std::endl; + } + + for (size_t i = 0; i < line_indices.size(); i++) { + std::cout << line_indices[i] << " " << line_values[i] << std::endl; + } + } + + +} //end clitk + +#endif //#define clitkLineProfileGenericFilter_cxx