Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_ISOSURFACE_PROJECTION_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_ISOSURFACE_PROJECTION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/grid/util/grid_value_at_point.h>
00013 #include <OpenTissue/core/containers/grid/util/grid_gradient_at_point.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace grid
00018 {
00019
00037 template<typename grid_type,typename vector3_iterator>
00038 inline void isosurface_projection(
00039 grid_type const & phi
00040 , vector3_iterator begin
00041 , vector3_iterator end
00042 , bool project_inside = true
00043 , bool project_outside = true
00044 , double isovalue = 0.0
00045 )
00046 {
00047 typedef typename grid_type::math_types math_types;
00048 typedef typename math_types::vector3_type vector3_type;
00049 typedef typename math_types::value_type real_type;
00050
00051 using std::min;
00052 using std::max;
00053 using std::fabs;
00054
00055 assert(isovalue > OpenTissue::grid::min_element(phi) || !"isosurface_projection(): isovalue exceeded minimum value");
00056 assert(isovalue < OpenTissue::grid::max_element(phi) || !"isosurface_projection(): isovalue exceeded maximum value");
00057
00058 real_type threshold = 0.0001;
00059
00060 for(vector3_iterator v = begin; v!=end; ++v)
00061 {
00062 vector3_type & p = (*v);
00063
00064 real_type distance = value_at_point( phi, p ) - isovalue;
00065
00066 if(!project_inside && distance < -threshold)
00067 continue;
00068
00069 if(!project_outside && distance > threshold )
00070 continue;
00071
00072 while ( fabs(distance) > threshold)
00073 {
00074 vector3_type g = gradient_at_point( phi, p );
00075 while ( g*g < threshold )
00076 {
00077 vector3_type noise;
00078 random(noise, -threshold, threshold );
00079 p += noise;
00080 g = gradient_at_point(phi, p );
00081 }
00082 g = unit(g);
00083 p -= g * distance;
00084 distance = value_at_point( phi, p ) - isovalue;
00085 }
00086 }
00087 }
00088
00089 }
00090 }
00091
00092
00093 #endif