Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KLResult, Meanshift::Result::aborted, Command::isAborted(), some cons…
…t correctness
- Loading branch information
Georg Altmann
committed
Nov 14, 2014
1 parent
9cfe6b3
commit 7268ccf
Showing
12 changed files
with
197 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ vole_compile_library( | |
"meanshift_shell" | ||
"meanshift_sp" | ||
"meanshift_som" | ||
"meanshift_klresult" | ||
) | ||
|
||
vole_add_module() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "meanshift_klresult.h" | ||
|
||
#include <iostream> | ||
|
||
namespace seg_meanshift { | ||
|
||
void diagnoseKLResult(KLResult const& ret) | ||
{ | ||
if (ret.isState(KLState::Aborted)) { | ||
std::cerr << "findKL computation was aborted" << std::endl; | ||
} else if (ret.isState(KLState::NoneFound)) { | ||
std::cerr << "findKL computation found no solution" << std::endl; | ||
} | ||
} | ||
|
||
void KLResult::insertInto(std::map<std::string, boost::any> &dest) | ||
{ | ||
std::map<std::string, boost::any> rmap = makeKeyValueMap(); | ||
dest.insert(rmap.begin(), rmap.end()); | ||
} | ||
|
||
std::map<std::string, boost::any> KLResult::makeKeyValueMap() const | ||
{ | ||
std::map<std::string, boost::any> res; | ||
res["findKL.K"] = K; | ||
res["findKL.L"] = L; | ||
res["findKL.aborted"] = isState(KLState::Aborted); | ||
res["findKL.good"] = isGood(); | ||
return res; | ||
} | ||
|
||
} // namespace seg_meanshift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#ifndef MEANSHIFT_KLRESULT_H | ||
#define MEANSHIFT_KLRESULT_H | ||
|
||
// These are for makeKeyValueMap() only. Maybe find better solution than | ||
// adding these include dependencies. | ||
#include <map> | ||
#include <string> | ||
#include <boost/any.hpp> | ||
|
||
namespace seg_meanshift { | ||
|
||
struct KLState { | ||
/** KLState flags. */ | ||
enum t { | ||
Good = 0x0, //! Good result, 0 for bitwise operations. | ||
Aborted = 0x1, //! The computation was aborted. | ||
NoneFound = 0x2 //! No solution found. | ||
}; | ||
}; | ||
|
||
class KLResult{ | ||
public: | ||
/** Create KLResult with flags s0 and s1 set. */ | ||
KLResult(int K, int L, | ||
KLState::t s0 = KLState::Good, | ||
KLState::t s1 = KLState::Good | ||
) | ||
: K(K), L(L), state(KLState::t(s0 | s1)) | ||
{} | ||
|
||
const int K; | ||
const int L; | ||
|
||
/** Returns true if flag s is set. */ | ||
bool isState(KLState::t s) const { | ||
if (KLState::Good == s) | ||
return isGood(); | ||
else | ||
return (state & s) != 0; | ||
} | ||
|
||
/** Returns true if findKL did not abort and found a valid result. */ | ||
bool isGood() const { | ||
return state == KLState::Good; | ||
} | ||
|
||
/** Insert result and flags into key-value map. | ||
* | ||
* The inserted values are: | ||
* | ||
* * findKL.K int | ||
* * findKL.L int | ||
* * findKL.aborted bool | ||
* * findKL.good bool | ||
*/ | ||
void insertInto(std::map<std::string, boost::any> &dest); | ||
|
||
private: | ||
std::map<std::string, boost::any> makeKeyValueMap() const; | ||
KLState::t state; | ||
}; | ||
|
||
/** Print informational messages to cerr on KLResult state. */ | ||
void diagnoseKLResult(KLResult const& ret); | ||
|
||
} // namespace seg_meanshift | ||
|
||
#endif // MEANSHIFT_KLRESULT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.