Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_EXTRACT_VOXELS_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_EXTRACT_VOXELS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace grid
00015 {
00016
00027 template < typename grid_type_in, typename transfer_function, typename grid_type_out >
00028 inline void extract_voxels(
00029 grid_type_in const& in
00030 , transfer_function const& func
00031 , grid_type_out & out
00032 )
00033 {
00034 typedef typename grid_type_in::value_type value_type_in;
00035 typedef typename grid_type_out::value_type value_type_out;
00036 typedef typename grid_type_in::math_types_in math_types_in;
00037 typedef typename math_types_in::vector3_type vector3_type_in;
00038
00039 typedef typename grid_type_in::const_index_iterator const_index_iterator_in;
00040
00041 std::cout << "-- OpenTissue::extract_voxels()" << std::endl;
00042
00043 int entries = func.getSize();
00044
00045
00046
00047 value_type_in data_min = OpenTissue::grid::min_element(in);
00048 value_type_in data_max = OpenTissue::grid::max_element(in);
00049
00050 if ( data_min < 0 )
00051 std::cout << "OpenTissue::extract_voxels(): WARNING, data-range not compatible with Colortable (min<0)!" << std::endl;
00052
00053 if ( data_max > entries )
00054 std::cout << "OpenTissue::extract_voxels(): WARNING, data-range not compatible with Colortable (max>entries)!" << std::endl;
00055
00056 size_t count = 0;
00057 const_index_iterator_in voxel;
00058 for ( voxel = in.begin(); voxel != in.end(); ++voxel )
00059 {
00060 int index = static_cast<int>( *voxel );
00061 float r = *static_cast<float*>( func.get( index, 0 ) );
00062 float g = *static_cast<float*>( func.get( index, 1 ) );
00063 float b = *static_cast<float*>( func.get( index, 2 ) );
00064 float alpha = *static_cast<float*>( func.get( index, 3 ) );
00065
00066 if ( alpha && ( r || g || b ) )
00067 {
00068 out( voxel.get_index() ) = value_type_out(0);
00069 ++count;
00070 }
00071 else
00072 out( voxel.get_index() ) = out.infinity();
00073 }
00074
00075 std::cout << "OpenTissue::extract_voxels(): Found "
00076 << count
00077 << " voxels from "
00078 << in.size()
00079 << " possible"
00080 << std::endl;
00081
00082 std::cout << "OpenTissue::extract_voxels(): Done" << std::endl;
00083 }
00084
00085 }
00086 }
00087
00088
00089 #endif