1 // This is brl/bseg/bvxm/algo/pro/processes/bvxm_mog_to_mpm_process.cxx
2 #include <iostream>
3 #include <string>
4 #include <bprb/bprb_func_process.h>
5 //:
6 // \file
7 // \brief A process to conver a grid of mixture of gaussians to a grid with the most probable mode
8 //
9 // \author Isabel Restrepo mir@lems.brown.edu
10 //
11 // \date  8/17/09
12 //
13 // \verbatim
14 //  Modifications
15 //   <none yet>
16 // \endverbatim
17 
18 #include <bvxm/algo/bvxm_merge_mog.h>
19 #include <bvxm/grid/bvxm_voxel_grid_base.h>
20 #include <bvxm/grid/bvxm_voxel_grid.h>
21 #include <bsta/bsta_gauss_sf1.h>
22 
23 #ifdef _MSC_VER
24 #  include "vcl_msvc_warnings.h"
25 #endif
26 
27 //: set input and output types
bvxm_mog_to_mpm_process_cons(bprb_func_process & pro)28 bool bvxm_mog_to_mpm_process_cons(bprb_func_process& pro)
29 {
30   // Inputs
31   // 0. Path to input grid(the one with gaussian mixtures)
32   // 1. Path to univariate gaussian grid
33   std::vector<std::string> input_types_(2);
34   input_types_[0] = "vcl_string";
35   input_types_[1] = "vcl_string";
36 
37 
38   // No outputs to the database. The resulting grid is stored on disk
39   std::vector<std::string> output_types_(0);
40 
41   if (!pro.set_input_types(input_types_))
42     return false;
43 
44   return pro.set_output_types(output_types_);
45 }
46 
47 
48 //: Execute the process
bvxm_mog_to_mpm_process(bprb_func_process & pro)49 bool bvxm_mog_to_mpm_process(bprb_func_process& pro)
50 {
51   // check number of inputs
52   if (pro.n_inputs() != 2)
53   {
54     std::cout << pro.name() << "The number of inputs should be " << 2 << std::endl;
55     return false;
56   }
57 
58   std::string apm_path = pro.get_input<std::string>(0);
59   std::string output_path = pro.get_input<std::string>(1);
60 
61   //get the grids
62   typedef bsta_num_obs<bsta_gauss_sf1> gauss_type;
63   typedef bsta_mixture_fixed<gauss_type, 3> mix_gauss;
64   typedef bsta_num_obs<mix_gauss> mix_gauss_type;
65 
66   bvxm_voxel_grid_base_sptr apm_base = new bvxm_voxel_grid<mix_gauss_type>(apm_path);
67 
68   bvxm_voxel_grid_base_sptr output_base = new bvxm_voxel_grid<gauss_type>(output_path, apm_base->grid_size());
69 
70   //merge mixtures
71   bvxm_merge_mog::mpm_grid(apm_base, output_base);
72 
73   return true;
74 }
75