1 #ifndef __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__
2 #define __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__
8 #include <itkImageRegionConstIteratorWithIndex.h>
10 // -------------------------------------------------------------------------
11 template< class _TTree >
12 void fpa::IO::MinimumSpanningTreeWriter< _TTree >::
13 SetInput( const _TTree* input )
15 this->itk::ProcessObject::SetNthInput( 0, const_cast< _TTree* >( input ) );
18 // -------------------------------------------------------------------------
19 template< class _TTree >
20 _TTree* fpa::IO::MinimumSpanningTreeWriter< _TTree >::
24 dynamic_cast< _TTree* >( this->itk::ProcessObject::GetInput( 0 ) )
28 // -------------------------------------------------------------------------
29 template< class _TTree >
30 const _TTree* fpa::IO::MinimumSpanningTreeWriter< _TTree >::
34 dynamic_cast< const _TTree* >( this->itk::ProcessObject::GetInput( 0 ) )
38 // -------------------------------------------------------------------------
39 template< class _TTree >
40 void fpa::IO::MinimumSpanningTreeWriter< _TTree >::
43 _TTree* input = this->GetInput( );
46 input->UpdateOutputInformation( );
47 input->UpdateOutputData( );
48 this->GenerateData( );
49 this->ReleaseInputs( );
54 // -------------------------------------------------------------------------
55 template< class _TTree >
56 fpa::IO::MinimumSpanningTreeWriter< _TTree >::
57 MinimumSpanningTreeWriter( )
61 this->SetNumberOfRequiredInputs( 1 );
64 // -------------------------------------------------------------------------
65 template< class _TTree >
66 fpa::IO::MinimumSpanningTreeWriter< _TTree >::
67 ~MinimumSpanningTreeWriter( )
71 // -------------------------------------------------------------------------
72 template< class _TTree >
73 void fpa::IO::MinimumSpanningTreeWriter< _TTree >::
76 typedef itk::Offset< _TTree::ImageDimension > _TOffset;
79 const _TTree* input = this->GetInput( );
82 std::stringstream out;
84 // Get tree properties
85 unsigned int dim = _TTree::ImageDimension;
86 auto lr = input->GetLargestPossibleRegion( );
87 auto rr = input->GetRequestedRegion( );
88 auto br = input->GetBufferedRegion( );
89 auto ori = input->GetOrigin( );
90 auto spc = input->GetSpacing( );
91 auto dir = input->GetDirection( );
93 // Write tree dimension
94 out << dim << std::endl;
95 out << ( ( input->GetFillNodeQueue( ) )? 1: 0 ) << std::endl;
98 out << lr.GetIndex( )[ 0 ] << " " << lr.GetSize( )[ 0 ];
99 for( unsigned int d = 1; d < dim; ++d )
100 out << " " << lr.GetIndex( )[ d ] << " " << lr.GetSize( )[ d ];
102 out << rr.GetIndex( )[ 0 ] << " " << rr.GetSize( )[ 0 ];
103 for( unsigned int d = 1; d < dim; ++d )
104 out << " " << rr.GetIndex( )[ d ] << " " << rr.GetSize( )[ d ];
106 out << br.GetIndex( )[ 0 ] << " " << br.GetSize( )[ 0 ];
107 for( unsigned int d = 1; d < dim; ++d )
108 out << " " << br.GetIndex( )[ d ] << " " << br.GetSize( )[ d ];
111 // Write spatial properties
113 for( unsigned int d = 1; d < dim; ++d )
114 out << " " << ori[ d ];
117 for( unsigned int d = 1; d < dim; ++d )
118 out << " " << spc[ d ];
120 out << dir[ 0 ][ 0 ];
121 for( unsigned int d = 0; d < dim; ++d )
122 for( unsigned int e = 0; e < dim; ++e )
123 if( d != 0 || e != 0 )
124 out << " " << dir[ d ][ e ];
128 auto& coll = input->GetCollisions( );
129 out << coll.size( ) << std::endl;
130 for( unsigned long i = 0; i < coll.size( ); ++i )
132 out << coll[ i ].size( );
133 for( unsigned long j = 0; j < coll[ i ].size( ); ++j )
135 for( unsigned int d = 0; d < dim; ++d )
136 out << " " << coll[ i ][ j ].first[ d ];
137 out << " " << coll[ i ][ j ].second << std::endl;
144 itk::ImageRegionConstIteratorWithIndex< _TTree > vIt( input, rr );
145 for( vIt.GoToBegin( ); !vIt.IsAtEnd( ); ++vIt )
148 vIt.Get( ).Parent != zero_off ||
149 vIt.Get( ).GlobalCost > double( 0 )
152 out << vIt.Get( ).FrontId << " " << vIt.Get( ).GlobalCost;
153 for( unsigned int d = 0; d < dim; ++d )
154 out << " " << vIt.GetIndex( )[ d ];
155 for( unsigned int d = 0; d < dim; ++d )
156 out << " " << vIt.Get( ).Parent[ d ];
165 this->m_FileName.c_str( ), std::ios::binary | std::ios::trunc
170 << "Error opening file to write a minimum spanning tree: \""
177 file.write( out.str( ).c_str( ), out.str( ).size( ) );
181 #endif // __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__