diff --git a/.gitignore b/.gitignore index 85152fb6..c92fa187 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *~ *.swp *.cur_trans +*.vtk build .ipynb_checkpoints/ diff --git a/pointmatcher/IOFunctions.h b/pointmatcher/IOFunctions.h index 1eb50367..ba22c341 100644 --- a/pointmatcher/IOFunctions.h +++ b/pointmatcher/IOFunctions.h @@ -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 diff --git a/pointmatcher/Inspector.cpp b/pointmatcher/Inspector.cpp index 6be00f05..2011f8b0 100644 --- a/pointmatcher/Inspector.cpp +++ b/pointmatcher/Inspector.cpp @@ -86,5 +86,18 @@ template void PointMatcher::Inspector::finish(const size_t iterationCount) {} +template +void PointMatcher::Inspector::setAndValidateDumpPath(std::string path) { + if (!path.empty() && path.back() != '/') { + path += "/"; + } + dumpPath = path; +} + +template +std::string PointMatcher::Inspector::getDumpPath() const { + return dumpPath; +} + template struct PointMatcher::Inspector; template struct PointMatcher::Inspector; diff --git a/pointmatcher/InspectorsImpl.cpp b/pointmatcher/InspectorsImpl.cpp index 2b53129f..bc1bab0b 100644 --- a/pointmatcher/InspectorsImpl.cpp +++ b/pointmatcher/InspectorsImpl.cpp @@ -74,7 +74,7 @@ void InspectorsImpl::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); } @@ -142,7 +142,9 @@ InspectorsImpl::AbstractVTKInspector::AbstractVTKInspector(const std::string& bDumpDataLinks(Parametrizable::get("dumpDataLinks")), bDumpReading(Parametrizable::get("dumpReading")), bDumpReference(Parametrizable::get("dumpReference")), - bWriteBinary(Parametrizable::get("writeBinary")) + bWriteBinary(Parametrizable::get("writeBinary")), + bDumpReferenceOnlyFirstIter(Parametrizable::get("dumpReferenceOnlyFirstIter")), + isFirstIter(true) { } @@ -404,12 +406,15 @@ void InspectorsImpl::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 @@ -727,16 +732,16 @@ void InspectorsImpl::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 @@ -761,7 +766,7 @@ std::ostream* InspectorsImpl::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; @@ -772,7 +777,9 @@ std::ostream* InspectorsImpl::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; diff --git a/pointmatcher/InspectorsImpl.h b/pointmatcher/InspectorsImpl.h index d780fb91..f6122f96 100644 --- a/pointmatcher/InspectorsImpl.h +++ b/pointmatcher/InspectorsImpl.h @@ -120,6 +120,8 @@ struct InspectorsImpl const bool bDumpDataLinks; const bool bDumpReading; const bool bDumpReference; + const bool bDumpReferenceOnlyFirstIter; + bool isFirstIter; const bool bWriteBinary; public: @@ -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); @@ -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"} }; } diff --git a/pointmatcher/PointMatcher.h b/pointmatcher/PointMatcher.h index f26aa2ce..26021030 100644 --- a/pointmatcher/PointMatcher.h +++ b/pointmatcher/PointMatcher.h @@ -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 {