Skip to content

Commit

Permalink
Split util functions into multiple files.
Browse files Browse the repository at this point in the history
  • Loading branch information
bing-jian committed Aug 16, 2015
1 parent 1525892 commit 12506e7
Show file tree
Hide file tree
Showing 26 changed files with 1,005 additions and 707 deletions.
21 changes: 6 additions & 15 deletions C++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#=========================================================================
# $Author: bingjian $
# $Date: 2013-01-04 01:39:25 -0500 (Fri, 04 Jan 2013) $
# $Revision: 145 $
#=========================================================================

CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
Expand Down Expand Up @@ -85,36 +79,35 @@ ENDIF(WIN32)


SET(GMMREG_API_SRCS
gmmreg_utils.cpp
gmmreg_api.cpp
gmmreg_base.cpp
gmmreg_cpd.cpp
gmmreg_tps.cpp
gmmreg_tps_func.cpp
gmmreg_grbf.cpp
gmmreg_grbf_func.cpp
gmmreg_rigid.cpp
gmmreg_rigid_func.cpp
gmmreg_api.cpp
gmmreg_tps.cpp
gmmreg_tps_func.cpp
utils/misc_utils.cc
)
file(GLOB_RECURSE GMMREG_API_HDRS *.h)

#IF( VXL_VNL_FOUND )
INCLUDE_DIRECTORIES( ${VXL_VNL_INCLUDE_DIR} )

SET(gauss_transform_sources ${gauss_transform_sources}
test_gauss_transform.cpp gmmreg_utils.cpp
test_gauss_transform.cpp
)
ADD_EXECUTABLE(test_gauss_transform ${gauss_transform_sources}
)
#TARGET_LINK_LIBRARIES( test_gauss_transform ${VXL_VNL_LIBRARIES} )
TARGET_LINK_LIBRARIES(test_gauss_transform vnl_algo vnl vcl)

ADD_EXECUTABLE(gmmreg_aux gmmreg_aux.cpp
)
TARGET_LINK_LIBRARIES(gmmreg_aux vnl vnl_algo)

ADD_EXECUTABLE(extract_correspondence
extract_correspondence.cpp gmmreg_utils.cpp
extract_correspondence.cpp
)
TARGET_LINK_LIBRARIES(extract_correspondence vnl vnl_algo)

Expand All @@ -135,7 +128,6 @@ TARGET_LINK_LIBRARIES(gmmreg_demo gmmreg_api)

SET(gmmreg_transform_sources ${gmmreg_transform_sources}
gmmreg_transform.cpp
gmmreg_utils.cpp
)

ADD_EXECUTABLE(gmmreg_transform ${gmmreg_transform_sources}
Expand All @@ -145,5 +137,4 @@ IF(UNIX)
TARGET_LINK_LIBRARIES(gmmreg_transform m port_ini)
ENDIF(UNIX)


#ENDIF( VXL_VNL_FOUND )
56 changes: 34 additions & 22 deletions C++/extract_correspondence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,54 @@
#include <vnl/vnl_vector.h>

#include "gmmreg_utils.h"
#include "utils/match_utils.h"

void f(const vnl_matrix<double>& model,
const vnl_matrix<double>& scene, double threshold,
vnl_matrix<double>& extracted_model,
vnl_matrix<double>& extracted_scene) {
vnl_matrix<double> dist;
namespace gmmreg {

template <typename T>
void ExtractMatchingPairs(
const vnl_matrix<T>& model,
const vnl_matrix<T>& scene,
const T& threshold,
vnl_matrix<T>& extracted_model,
vnl_matrix<T>& extracted_scene) {
vnl_matrix<T> dist;
vnl_matrix<int> pairs;
ComputeSquaredDistanceMatrix(model, scene, dist);
pick_indices(dist, pairs, threshold*threshold);
ComputeSquaredDistanceMatrix<T>(model, scene, dist);
PickIndices<T>(dist, pairs, threshold*threshold);
std::cout << "distance threshold : " << threshold << std::endl;
int j, n = pairs.cols();
int n = pairs.cols();
int d = model.cols();
extracted_model.set_size(n,d);
extracted_scene.set_size(n,d);
extracted_model.set_size(n, d);
extracted_scene.set_size(n, d);
std::cout << "# of matched point pairs : " << n << std::endl;
for (j=0; j<n; ++j) {
extracted_model.set_row(j,model.get_row(pairs(0,j)));
for (int j = 0; j < n; ++j) {
extracted_model.set_row(j,model.get_row(pairs(0, j)));
}
for (j=0; j<n; ++j) {
extracted_scene.set_row(j,scene.get_row(pairs(1,j)));
for (int j = 0; j < n; ++j) {
extracted_scene.set_row(j,scene.get_row(pairs(1, j)));
}
}

void g( const char* model_file,
template <typename T>
void ExtractMatchingPairs(
const char* model_file,
const char* scene_file,
double threshold,
const T& threshold,
const char* extracted_model_file,
const char* extracted_scene_file) {

std::ifstream infile1(model_file);
vnl_matrix<double> model;
vnl_matrix<T> model;
model.read_ascii(infile1);

std::ifstream infile2(scene_file);
vnl_matrix<double> scene;
vnl_matrix<T> scene;
scene.read_ascii(infile2);

vnl_matrix<double> extracted_model, extracted_scene;
f(model, scene, threshold, extracted_model, extracted_scene);
vnl_matrix<T> extracted_model, extracted_scene;
ExtractMatchingPairs<T>(
model, scene, threshold, extracted_model, extracted_scene);

std::ofstream outfile1(extracted_model_file, std::ios_base::out);
extracted_model.print(outfile1);
Expand All @@ -61,12 +70,15 @@ void g( const char* model_file,
extracted_scene.print(outfile2);
}

} // namespace gmmreg

int main(int argc, char* argv[]) {
if (argc<6) {
if (argc < 6) {
std::cerr << "Usage: " << argv[0]
<< " modelFile sceneFile threshold extracted_model extracted_scene"
<< std::endl;
return -1;
}
g(argv[1], argv[2], atof(argv[3]), argv[4], argv[5]);
gmmreg::ExtractMatchingPairs<float>(
argv[1], argv[2], atof(argv[3]), argv[4], argv[5]);
}
5 changes: 3 additions & 2 deletions C++/gmmreg_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "gmmreg_rigid.h"
#include "gmmreg_tps.h"
#include "gmmreg_utils.h"
#include "utils/misc_utils.h"

using std::cerr;
using std::cout;
Expand Down Expand Up @@ -65,8 +66,8 @@ int gmmreg_api(const char* input_config, const char* method) {
cout << "Robust Point Set Registration Using Gaussian Mixture Models" << endl;
cout << "Compiled on " << __DATE__ << ", " << __TIME__ << endl;
cout << "Copyright Bing Jian & Baba C. Vemuri " << endl;
char f_config[BUFSIZE];
get_config_fullpath(input_config, f_config);
char f_config[1024];
gmmreg::utils::get_config_fullpath(input_config, f_config);

if (!strcmp(strupr((char*)method), "EM_TPS")) {
gmmreg::CoherentPointDriftTps().Run(f_config);
Expand Down
9 changes: 6 additions & 3 deletions C++/gmmreg_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <vcl_string.h>

#include "gmmreg_utils.h"
#include "utils/io_utils.h"
#include "utils/match_utils.h"
#include "utils/misc_utils.h"

namespace gmmreg {

Expand Down Expand Up @@ -113,7 +116,7 @@ void Base::SaveTransformed(const char* filename,
double threshold = min_threshold + i * interval;
//int n_match = find_working_pair(model, scene, transformed_model,
// threshold, working_M, working_S);
pick_indices(dist, pairs, threshold * threshold);
PickIndices<double>(dist, pairs, threshold * threshold);
//printf("%f : %d\n",threshold, n_match);
f_pair << "distance threshold : " << threshold << std::endl;
f_pair << "# of matched point pairs : " << pairs.cols() << std::endl;
Expand Down Expand Up @@ -148,14 +151,14 @@ void Base::MultiScaleOptions(const char* f_config) {
char s_scale[256] = {0}, s_func_evals[256] = {0};
char delims[] = " -,;";
GetPrivateProfileString(section_, "sigma", NULL, s_scale, 255, f_config);
parse_tokens(s_scale, delims, v_scale_);
utils::parse_tokens(s_scale, delims, v_scale_);
if (v_scale_.size() < level_) {
std::cerr << " too many levels " << std::endl;
exit(1);
}
GetPrivateProfileString(section_, "max_function_evals", NULL,
s_func_evals, 255, f_config);
parse_tokens(s_func_evals, delims, v_func_evals_);
utils::parse_tokens(s_func_evals, delims, v_func_evals_);
if (v_func_evals_.size() < level_) {
std::cerr << " too many levels " << std::endl;
exit(1);
Expand Down
8 changes: 4 additions & 4 deletions C++/gmmreg_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Base {
char section_[80], common_section_[80];

unsigned int level_;
std::vector<double> v_scale_;
std::vector<float> v_scale_;
std::vector<int> v_func_evals_;

// load input data from files
Expand All @@ -56,9 +56,9 @@ class Base {
void DenormalizeAll();
int Initialize(const char* f_config);

friend class RigidFunc;
friend class ThinPlateSplineFunc;
friend class GaussianRadialBasisFunc;
friend class RigidFunc;
friend class ThinPlateSplineFunc;
friend class GaussianRadialBasisFunc;

private:
double model_scale_, scene_scale_;
Expand Down
5 changes: 3 additions & 2 deletions C++/gmmreg_cpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vnl/vnl_trace.h>

#include "gmmreg_utils.h"
#include "utils/io_utils.h"

namespace gmmreg {

Expand Down Expand Up @@ -138,7 +139,7 @@ void CoherentPointDrift::StartRegistration(vnl_vector<double>& params) {
//std::cout << "E="<<E<<"\t";
//std::cout << "sigma="<<sigma<<std::endl;
E_old = E;
compute_P(moving_model, scene_, P, Eu, sigma_, outliers);
ComputeP(moving_model, scene_, P, Eu, sigma_, outliers);
bending = UpdateParam();
moving_model = model_ + basis_ * param_all_;
E = Eu + (lambda_ / 2) * bending;
Expand Down Expand Up @@ -189,7 +190,7 @@ void CoherentPointDrift::SaveResults(const char* f_config,
char f_final_params[256] = {0};
GetPrivateProfileString(common_section_, "final_params", NULL,
f_final_params, 255, f_config);
save_matrix(f_final_params, param_all_);
SaveMatrixToAsciiFile(f_final_params, param_all_);
}

void CoherentPointDrift::PrepareOwnOptions(const char* f_config) {
Expand Down
8 changes: 5 additions & 3 deletions C++/gmmreg_grbf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <vnl/vnl_trace.h>

#include "gmmreg_utils.h"
#include "utils/io_utils.h"
#include "utils/misc_utils.h"

namespace gmmreg {

Expand Down Expand Up @@ -105,17 +107,17 @@ void GrbfRegistration::SaveResults(const char* f_config,
GetPrivateProfileString(common_section_, "transformed_model", NULL,
f_transformed, 255, f_config);
SaveTransformed(f_transformed, params, f_config);
save_matrix(f_final_grbf, param_grbf_);
SaveMatrixToAsciiFile(f_final_grbf, param_grbf_);
}

void GrbfRegistration::PrepareOwnOptions(const char* f_config) {
MultiScaleOptions(f_config);
char delims[] = " -,;";
char s_lambda[256] = {0};
GetPrivateProfileString(section_, "lambda", NULL, s_lambda, 255, f_config);
parse_tokens(s_lambda, delims, v_lambda);
utils::parse_tokens(s_lambda, delims, v_lambda);
if (v_lambda.size() < level_) {
std::cerr<< " too many levels " << std::endl;
std::cerr << " too many levels " << std::endl;
exit(1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions C++/gmmreg_grbf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class GrbfRegistration: public Base {
private:
vnl_matrix<double> param_grbf_;
vnl_matrix<double> after_grbf, basis_, param_all_;
std::vector<double> v_beta;
std::vector<float> v_beta;
double beta_;
std::vector<double> v_lambda;
std::vector<float> v_lambda;
std::vector<int> v_affine;

void StartRegistration(vnl_vector<double>&) override;
Expand Down
Loading

0 comments on commit 12506e7

Please sign in to comment.