Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/inspector files debug directories #330

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*~
*.swp
*.cur_trans
*.vtk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have .vtk files in /examples/data ignoring this extension could cause problems

build
.ipynb_checkpoints/
1 change: 0 additions & 1 deletion pointmatcher/IOFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ std::istream & readVtkData(std::string dataType, bool readBinary, MatrixRef into
//! Replaces getline for handling windows style CR/LF line endings
std::istream & safeGetLine( std::istream& is, std::string & t);


} // PointMatcherSupport

#endif // __POINTMATCHER_IOFUNCTIONS_H
13 changes: 13 additions & 0 deletions pointmatcher/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,18 @@ template<typename T>
void PointMatcher<T>::Inspector::finish(const size_t iterationCount)
{}

template<typename T>
void PointMatcher<T>::Inspector::setAndValidateDumpPath(std::string path) {
if (!path.empty() && path.back() != '/') {
path += "/";
}
dumpPath = path;
}

template<typename T>
std::string PointMatcher<T>::Inspector::getDumpPath() const {
return dumpPath;
}

template struct PointMatcher<float>::Inspector;
template struct PointMatcher<double>::Inspector;
25 changes: 16 additions & 9 deletions pointmatcher/InspectorsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void InspectorsImpl<T>::PerformanceInspector::addStat(const std::string& name, d
HistogramMap::iterator it(stats.find(name));
if (it == stats.end()) {
LOG_INFO_STREAM("Adding new stat: " << name);
it = stats.insert(HistogramMap::value_type(name, Histogram(16, name, baseFileName, bDumpPerfOnExit))).first;
it = stats.insert(HistogramMap::value_type(name, Histogram(16, name, this->dumpPath + baseFileName, bDumpPerfOnExit))).first;
}
it->second.push_back(data);
}
Expand Down Expand Up @@ -142,7 +142,9 @@ InspectorsImpl<T>::AbstractVTKInspector::AbstractVTKInspector(const std::string&
bDumpDataLinks(Parametrizable::get<bool>("dumpDataLinks")),
bDumpReading(Parametrizable::get<bool>("dumpReading")),
bDumpReference(Parametrizable::get<bool>("dumpReference")),
bWriteBinary(Parametrizable::get<bool>("writeBinary"))
bWriteBinary(Parametrizable::get<bool>("writeBinary")),
bDumpReferenceOnlyFirstIter(Parametrizable::get<bool>("dumpReferenceOnlyFirstIter")),
isFirstIter(true)
{
}

Expand Down Expand Up @@ -404,12 +406,15 @@ void InspectorsImpl<T>::AbstractVTKInspector::dumpIteration(
closeStream(streamRead);
}

if (bDumpReference){
if (bDumpReference &&
((bDumpReferenceOnlyFirstIter && isFirstIter) || !bDumpReferenceOnlyFirstIter)
){
isFirstIter = false;
ostream* streamRef(openStream("reference", iterationNumber));
dumpDataPoints(filteredReference, *streamRef);
closeStream(streamRef);
}

if (!bDumpIterationInfo) return;

// streamIter must be define by children
Expand Down Expand Up @@ -727,16 +732,16 @@ void InspectorsImpl<T>::VTKFileInspector::init()
{

if (!bDumpIterationInfo) return;

ostringstream oss;
oss << baseFileName << "-iterationInfo.csv";
//std::cerr << "writing to " << oss.str() << std::endl;
LOG_INFO_STREAM("writing to " << oss.str());

this->streamIter = new ofstream(oss.str().c_str());
this->streamIter = new ofstream(this->dumpPath + oss.str().c_str());
if (this->streamIter->fail())
throw std::runtime_error("Couldn't open the file \"" + oss.str() + "\". Check if directory exist.");

}

template<typename T>
Expand All @@ -761,7 +766,7 @@ std::ostream* InspectorsImpl<T>::VTKFileInspector::openStream(const std::string&

//std::cerr << "writing to " << oss.str() << std::endl;
LOG_INFO_STREAM("writing to " << oss.str());
ofstream* file = new ofstream(oss.str().c_str(), std::ios::binary);
ofstream* file = new ofstream(this->dumpPath + oss.str().c_str(), std::ios::binary);
if (file->fail())
throw std::runtime_error("Couldn't open the file \"" + oss.str() + "\". Check if directory exist.");
return file;
Expand All @@ -772,7 +777,9 @@ std::ostream* InspectorsImpl<T>::VTKFileInspector::openStream(const std::string&
{
ostringstream oss;
oss << baseFileName << "-" << role << "-" << iterationNumber << ".vtk";
ofstream* file = new ofstream(oss.str().c_str());

LOG_INFO_STREAM("writing to " << oss.str());
ofstream* file = new ofstream(this->dumpPath + oss.str().c_str());
if (file->fail())
throw std::runtime_error("Couldn't open the file \"" + oss.str() + "\". Check if directory exist.");
return file;
Expand Down
7 changes: 6 additions & 1 deletion pointmatcher/InspectorsImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ struct InspectorsImpl
const bool bDumpDataLinks;
const bool bDumpReading;
const bool bDumpReference;
const bool bDumpReferenceOnlyFirstIter;
bool isFirstIter;
const bool bWriteBinary;

public:
Expand All @@ -130,6 +132,8 @@ struct InspectorsImpl
virtual void dumpIteration(const size_t iterationNumber, const TransformationParameters& parameters, const DataPoints& filteredReference, const DataPoints& reading, const Matches& matches, const OutlierWeights& outlierWeights, const TransformationCheckers& transformationCheckers);
virtual void finish(const size_t iterationCount);

virtual void resetIsFirstIter() { isFirstIter = true; }

private:
void buildGenericAttributeStream(std::ostream& stream, const std::string& attribute, const std::string& nameTag, const DataPoints& cloud, const int forcedDim);

Expand Down Expand Up @@ -171,7 +175,8 @@ struct InspectorsImpl
{"dumpDataLinks", "dump data links at each iteration", "0" },
{"dumpReading", "dump the reading cloud at each iteration", "0"},
{"dumpReference", "dump the reference cloud at each iteration", "0"},
{"writeBinary", "write binary VTK files", "0"}
{"writeBinary", "write binary VTK files", "0"},
{"dumpReferenceOnlyFirstIter", "dump the reference cloud only for the first iteration", "0"}
};
}

Expand Down
36 changes: 22 additions & 14 deletions pointmatcher/PointMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,42 +615,50 @@ struct PointMatcher
};
typedef typename TransformationCheckers::iterator TransformationCheckersIt; //!< alias
typedef typename TransformationCheckers::const_iterator TransformationCheckersConstIt; //!< alias

DEF_REGISTRAR(TransformationChecker)

// ---------------------------------

//! An inspector allows to log data at the different steps, for analysis.
struct Inspector: public Parametrizable
{

Inspector();
Inspector(const std::string& className, const ParametersDoc paramsDoc, const Parameters& params);
//

//
virtual ~Inspector();
virtual void init();

// performance statistics
virtual void addStat(const std::string& name, double data);
virtual void dumpStats(std::ostream& stream);
virtual void dumpStatsHeader(std::ostream& stream);
// data statistics

// data statistics
virtual void dumpIteration(const size_t iterationNumber, const TransformationParameters& parameters, const DataPoints& filteredReference, const DataPoints& reading, const Matches& matches, const OutlierWeights& outlierWeights, const TransformationCheckers& transformationCheckers);
virtual void finish(const size_t iterationCount);

virtual void setAndValidateDumpPath(std::string path);
virtual std::string getDumpPath() const;

virtual void resetIsFirstIter() {}

protected:
std::string dumpPath;
};
DEF_REGISTRAR(Inspector)

DEF_REGISTRAR(Inspector)

// ---------------------------------

DEF_REGISTRAR_IFACE(Logger, PointMatcherSupport::Logger)

// ---------------------------------

// algorithms

//! Stuff common to all ICP algorithms
struct ICPChainBase
{
Expand Down