Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Segmentation.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: Segmentation.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.6 $        $Date: 2019/01/17 21:21:01 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Scale-space variant of Watershed image segmentation intended for use
00019  *   on 3-D cryo-EM density maps.
00020  ***************************************************************************/
00021 #ifndef SEGMENTATION_H
00022 #define SEGMENTATION_H
00023 
00024 #include "molfile_plugin.h"
00025 #include "GaussianBlur.h"
00026 #include "ScaleSpaceFilter.h"
00027 #include "VolumetricData.h"
00028 
00029 #define TIMER
00030 
00031 
00036 class Segmentation {
00037 
00038   public:
00041     Segmentation(const VolumetricData *map, bool cuda=true);
00042 
00045     Segmentation(float* data,
00046                  molfile_volumetric_t* metatdata,
00047                  bool cuda=true);
00048 
00049     Segmentation(unsigned short* data,
00050                  molfile_volumetric_t* metatdata,
00051                  bool cuda=true);
00052 
00053     Segmentation(unsigned char* data,
00054                  molfile_volumetric_t* metatdata,
00055                  bool cuda=true);
00056 
00057     ~Segmentation();
00058 
00061     double segment(int   num_final_groups,
00062                    float watershed_blur_sigma,
00063                    float blur_initial_sigma,
00064                    float blur_multiple,
00065                    MERGE_POLICY policy,
00066                    const bool verbose=true);
00067 
00070     template <typename OUT_T>
00071     void get_results(OUT_T* results);
00072 
00074     unsigned long get_num_groups();
00075 
00076   private:
00077 
00078     // The object keeps track of the current smallest datatype
00079     // we can use based on the number of groups in the segmentation.
00080     enum Datatype {
00081       DT_LONG,
00082       DT_INT,
00083       DT_SHORT,
00084       DT_CHAR,
00085       DT_ULONG,
00086       DT_UINT,
00087       DT_USHORT,
00088       DT_UCHAR,
00089       DT_FLOAT,
00090       DT_DOUBLE,
00091       DT_ERROR
00092     };
00093 
00094     unsigned long height;
00095     unsigned long width;
00096     unsigned long depth;
00097     unsigned long nVoxels;
00098     unsigned long nGroups;
00099     Datatype group_type;
00100     Datatype image_type;
00101     GaussianBlur<float>* gaussian_f;
00102     GaussianBlur<unsigned short>* gaussian_us;
00103     GaussianBlur<unsigned char>* gaussian_uc;
00104     unsigned long* segments_ul;
00105     unsigned int* segments_ui;
00106     unsigned short* segments_us;
00107     bool verbose;
00108 
00109 
00110     // The object will always try to use cuda unless explicitly told not to.
00111     // If an error occurs at any point in the segmentation process we should be 
00112     // able to fall back to the CPU seamlessly (TODO fallback not implemented yet)
00113     bool use_cuda;
00114 
00116     void init(unsigned long w,
00117               unsigned long h,
00118               unsigned long d,
00119               bool cuda);
00120 
00123     void update_type();
00124 
00125     void switch_to_cpu();
00126 
00128     Datatype get_new_group_type();
00129 
00133     template <typename IN_T, typename OUT_T>
00134     void copy_and_convert_type(IN_T* in, OUT_T* out, unsigned long num_elems,
00135                                bool copy_from_gpu=false);
00136 
00139     template <typename GROUP_T>
00140     void get_watershed_segmentation(float watershed_blur_sigma,
00141                                     GROUP_T* segments);
00142 
00145     template <typename GROUP_T>
00146     void merge_groups(unsigned long num_final_groups,
00147                       float blur_initial_sigma,
00148                       float blur_multiple, 
00149                       MERGE_POLICY policy,
00150                       GROUP_T* segments);
00151 
00152     template <typename GROUP_T, typename IMAGE_T>
00153     void merge_groups_helper(unsigned long num_final_groups,
00154                       float blur_initial_sigma,
00155                       float blur_multiple, 
00156                       GROUP_T* segments,
00157                       MERGE_POLICY policy,
00158                       GaussianBlur<IMAGE_T>* gaussian);
00159 
00160     template <typename GROUP_T>
00161     void sequentialize_groups(GROUP_T* segments,
00162                               GROUP_T* group_map);
00163 
00164     template <typename GROUP_T>
00165     unsigned long sequentialize_groups_cpu(GROUP_T* segments,
00166                                            GROUP_T* group_map);
00167 
00171     template <typename GROUP_T>
00172     GROUP_T* allocate_array(unsigned long num_elements);
00173 
00174     template <typename GROUP_T>
00175     void free_array(GROUP_T*& arr);
00176 
00177 };
00178 
00179 #endif

Generated on Fri Nov 8 02:45:32 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002