Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

# MarchingT.hh

    00001 #ifndef MARCHINGT_HH
    00002 #define MARCHINGT_HH
    00003
    00004 //=============================================================================
    00005
    00006 #include <iostream>
    00007 #include <stdio.h>
    00008 #include <assert.h>
    00009
    00010 #include <ACG/Utils/HeapT.hh>
    00011 #include <OpenMesh/Core/Math/VectorT.hh>
    00012
    00013 #include <vector>
    00014 #include "HeapDefinition.hh"
    00015 #include "HelperVolume.hh"
    00016
    00017
    00018 //--------------------------------------------------------------------------
    00019 //                         Marching class
    00020 //--------------------------------------------------------------------------
    00021
    00022 template <class Volume>
    00023 class MarchingT
    00024 {
    00025
    00026 public:
    00027
    00028   MarchingT(Volume& _volume, HelperVolume& _helper )
    00029     : volume_(_volume), helper_(_helper), heap_interface(volume_, helper_),
    00030       heap_(heap_interface)
    00031   {
    00032
    00033     Point x_unit_dir = _volume.x_axis()/Scalar( _volume.x_resolution() -1);
    00034     Point y_unit_dir = _volume.y_axis()/Scalar( _volume.y_resolution() -1);
    00035     Point z_unit_dir = _volume.z_axis()/Scalar( _volume.z_resolution() -1);
    00036
    00037     Scalar z1 =  x_unit_dir.norm();
    00038     Scalar z2 =  y_unit_dir.norm();
    00039     Scalar z3 =  z_unit_dir.norm();
    00040
    00041     if ((z1 != z2) || (z2 != z3))
    00042     {
    00043       std::cerr << "zīs: " << z1 << " " << z2 << " " << z3 << std::endl;
    00044       std::cerr << "Only Isotropic Marching possible -> "
    00045                 << "volume axis should be of equal length!\n";
    00046       std::cerr << "Due to numerical error no assertion,"
    00047                 << " but zīs should be equal.\n";
    00048     }
    00049     force_ = 1.0/z1;
    00050   };
    00051
    00052   ~MarchingT() {};
    00053
    00054   void set_force(typename Volume::Scalar _force) {force_ = _force; };
    00055
    00056   void initialize_inner_6();
    00057   void initialize_outer_6();
    00058
    00059   void march_inner_6();
    00060   void march_outer_6();
    00061
    00062   void initialize_outer_26();
    00063   void initialize_inner_26();
    00064
    00065   void march_inner_26();
    00066   void march_outer_26();
    00067
    00068   void march_inner_both();
    00069   void march_outer_both();
    00070
    00071   void march();
    00072
    00073 private:
    00074
    00075   // -------------------------------- Data -----------------------------------
    00076
    00077   typedef typename Volume::Scalar Scalar;
    00078   typedef OpenMesh::VectorT<Scalar,3> Point;
    00079   typedef MyHeapInterfaceT<Volume, HelperVolume> MyHeapInterface;
    00080
    00081   enum Dirs {up, down, right, left, front, back} dir_;
    00082
    00083   Volume& volume_;
    00084   HelperVolume& helper_;
    00085   Scalar force_;
    00086
    00087   MyHeapInterface heap_interface;
    00088   ACG::HeapT<HeapEntry, MyHeapInterface> heap_;
    00089
    00090   int xresolution_, yresolution_ , zresolution_;
    00091
    00092   // ------------------------- Functions -------------------------------------
    00093
    00094   void initialize_6(bool inner);
    00095   void initialize_26(bool inner);
    00096
    00097   void march_6(bool inner);
    00098   void march_26(bool inner);
    00099   void march_both(bool inner);
    00100
    00101   inline void update_entry(Scalar _val, int _i, int _j, int _k, bool inner);
    00102
    00103   void init_entry_6(int _i, int _j, int _k, bool inner);
    00104   inline void update_entry_6(int _i, int _j, int _k, bool inner);
    00105
    00106   inline void update_entry_26(int _i, int _j, int _k, bool inner, Dirs dir);
    00107   inline void init_entry_26(int _i, int _j, int _k, bool inner, Dirs dir);
    00108
    00109   inline void update_entry_both(int _i, int _j, int _k, bool inner, Dirs dir);
    00110
    00111   inline Scalar my_first_order_distance_6(int i, int j, int k, bool inner);
    00112
    00113   inline Scalar my_first_order_distance_26(int i, int j, int k,
    00114                                            bool inner, Dirs dir);
    00115
    00116   inline Scalar first_order_distance_6(Scalar _d0m, Scalar _d0p,
    00117                                        Scalar _d1m, Scalar _d1p,
    00118                                        Scalar _d2m, Scalar _d2p,
    00119                                        Scalar _force);
    00120
    00121   inline Scalar first_order_distance_26(Scalar _dA, Scalar _dB,
    00122                                         Scalar _dC1, Scalar _dC2,
    00123                                         Scalar _force);
    00124
    00125
    00126   inline Scalar minimum(Scalar a, Scalar b, Scalar c)
    00127   {
    00128     if (a < b && a < c) return a;
    00129     if (b < a && b < c) return b;
    00130     return c;
    00131   }
    00132
    00133 };
    00134
    00135 template <class Volume>
    00136 void MarchingT<Volume>::
    00137 march()
    00138 {
    00139   // march outer region
    00140   initialize_outer_26();
    00141   march_outer_26();
    00142
    00143   // march inner region
    00144   initialize_inner_26();
    00145   march_inner_26();
    00146 };
    00147 // combination possible (because of minimum is searched)
    00148 // just a slight improvement is felt
    00149
    00150 #if defined(INCLUDE_TEMPLATES) && !defined(MARCHINGT_C)
    00151 #define MARCHINGT_TEMPLATES
    00152 #include "MarchingT.cc"
    00153 #endif
    00154 //=============================================================================
    00155 #endif // MARCHINGT_HH defined
    00156 //=============================================================================
    00157