17 #ifndef ITKLINEHISTOGRAMBASEDMASSIMAGEFILTER_CPP
18 #define ITKLINEHISTOGRAMBASEDMASSIMAGEFILTER_CPP
21 #include <itkImageRegionIteratorWithIndex.h>
22 #include <itkBinaryContourImageFilter.h>
27 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
32 if(m_ImageMask.IsNull())
34 itkExceptionMacro(
"No binary mask image provided.")
37 if(m_BinaryContour.IsNull()){
40 typename TMaskImageType::RegionType region = m_ImageMask->GetLargestPossibleRegion();
41 unsigned int xdim = region.GetSize(0);
42 unsigned int ydim = region.GetSize(1);
43 unsigned int zdim = region.GetSize(2);
47 mask_copy->SetSpacing(m_ImageMask->GetSpacing());
48 mask_copy->SetDirection(m_ImageMask->GetDirection());
49 mask_copy->SetOrigin(m_ImageMask->GetOrigin());
50 mask_copy->SetRegions(region);
51 mask_copy->Allocate();
52 mask_copy->FillBuffer(0);
54 itk::ImageRegionIteratorWithIndex<TMaskImageType> oit(mask_copy, mask_copy->GetLargestPossibleRegion());
55 itk::ImageRegionConstIteratorWithIndex<TMaskImageType> mit(m_ImageMask, m_ImageMask->GetLargestPossibleRegion());
59 && mit.GetIndex()[0] != 0
60 && mit.GetIndex()[1] != 0
61 && mit.GetIndex()[2] != 0
62 && mit.GetIndex()[0] != xdim-1
63 && mit.GetIndex()[1] != ydim-1
64 && mit.GetIndex()[2] != zdim-1)
72 typedef itk::BinaryContourImageFilter<TMaskImageType,TMaskImageType> BinaryContourImagefilterType;
74 filter->SetInput(mask_copy);
75 filter->SetBackgroundValue(0);
76 filter->SetForegroundValue(1);
77 filter->SetFullyConnected(
true);
80 m_BinaryContour = filter->GetOutput();
85 if(m_BinaryContour.IsNull())
87 itkExceptionMacro(
"No binary contour image provided.")
90 m_CenterOfMask = GetCenterOfMass(m_ImageMask);
92 if(m_CenterOfMask.is_zero())
94 itkExceptionMacro(
"Center of mass is corrupt.")
100 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
107 typedef itk::ImageRegionConstIterator< TMaskImageType > IteratorType;
108 IteratorType iter( maskImage, maskImage->GetLargestPossibleRegion() );
111 vnl_vector_fixed<double,3> mean_index;
113 unsigned int count = 0;
114 while ( !iter.IsAtEnd() )
116 if ( iter.Get() != 0 )
119 img->GetGeometry()->IndexToWorld(iter.GetIndex(),current_index_pos);
120 mean_index += current_index_pos.GetVnlVector();
130 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
132 ::ThreadedGenerateData(
const typename Superclass::OutputImageRegionType &outputRegionForThread, ThreadIdType )
135 TOutputImageType * outimage = this->GetOutput();
138 itk::ImageRegionConstIteratorWithIndex<TMaskImageType> cit(m_BinaryContour, outputRegionForThread);
139 itk::ImageRegionConstIteratorWithIndex<TInputImageType> iit(this->GetInput(), outputRegionForThread);
140 itk::ImageRegionIteratorWithIndex<TOutputImageType > oit(outimage,outputRegionForThread);
141 typedef typename itk::ImageRegionIteratorWithIndex<TInputImageType >::IndexType IndexType;
143 std::vector<IndexType> target_world_indices;
145 while(!cit.IsAtEnd())
147 if(cit.Value() != 0 )
148 target_world_indices.push_back(cit.GetIndex());
156 while(!target_world_indices.empty())
158 vnl_vector<double> u_v(3,1), x_v(3,1), p_v(3,1);
159 double line_histo_area = 0;
163 image->GetGeometry()->IndexToWorld(target_world_indices.back(),skull_point);
167 u_v = skull_point.GetVnlVector() - m_CenterOfMask;
170 p_v = m_CenterOfMask;
177 center_point[0] = m_CenterOfMask[0];
178 center_point[1] = m_CenterOfMask[1];
179 center_point[2] = m_CenterOfMask[2];
182 oit.SetIndex(tmp_index);
184 std::vector<IndexType> under_line_indices;
190 under_line_indices.push_back(tmp_index);
193 iit.SetIndex(tmp_index);
194 line_histo_area += iit.Value();
197 if(tmp_index == target_world_indices.back())
203 while(tmp_index == oit.GetIndex())
205 x_v = p_v + s_s * u_v;
206 tmp_point.GetVnlVector().set(x_v.data_block());
211 oit.SetIndex(tmp_index);
215 while (!under_line_indices.empty()) {
216 IndexType current_index = under_line_indices.back();
217 under_line_indices.pop_back();
219 oit.SetIndex(current_index);
220 oit.Set(line_histo_area / (s_s * u_v).magnitude() );
223 target_world_indices.pop_back();
229 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
232 this->m_ImageMask = maskimage;
235 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
238 this->m_BinaryContour = binarycontour;
241 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
244 this->SetNumberOfIndexedOutputs(1);
245 this->SetNumberOfIndexedInputs(1);
247 m_CenterOfMask.fill(0);
250 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
itk::SmartPointer< Self > Pointer
void SetBinaryContour(TMaskImageType *contouriamge)
void SetImageMask(TMaskImageType *maskimage)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
BaseGeometry Describes the geometry of a data object.
void WorldToIndex(const mitk::Point3D &pt_mm, mitk::Point3D &pt_units) const
Convert world coordinates (in mm) of a point to (continuous!) index coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.