46 #include <boost/type_traits/is_same.hpp>
72 if (!bDumpStats)
return;
74 HistogramMap::iterator it(stats.find(
name));
75 if (it == stats.end()) {
77 it = stats.insert(HistogramMap::value_type(
name,
Histogram(16,
name, baseFileName, bDumpPerfOnExit))).first;
79 it->second.push_back(
data);
86 for (BOOST_AUTO(it, stats.begin()); it != stats.end(); ++it)
88 it->second.dumpStats(stream);
91 if (jt != stats.end())
99 for (BOOST_AUTO(it, stats.begin()); it != stats.end(); ++it)
101 it->second.dumpStatsHeader(stream);
104 if (jt != stats.end())
152 if (boost::is_same<double, T>::value) {
165 stream <<
"# vtk DataFile Version 3.0\n";
166 stream <<
"File created by libpointmatcher\n";
167 stream << (bWriteBinary ?
"BINARY":
"ASCII") <<
"\n";
168 stream <<
"DATASET POLYDATA\n";
170 stream <<
"POINTS " << features.cols() <<
" " << getTypeName<T>() <<
"\n";
172 if(features.rows() == 4)
174 writeVtkData(bWriteBinary, features.topLeftCorner(3, features.cols()).transpose(), stream) <<
"\n";
178 writeVtkData(bWriteBinary, features.transpose(), stream) <<
"\n";
181 stream <<
"VERTICES " << features.cols() <<
" "<< features.cols() * 2 <<
"\n";
182 for (
int i = 0; i < features.cols(); ++i){
184 stream.write(
reinterpret_cast<const char*
>(&
oneBigEndian),
sizeof(
int));
189 stream.write(converter.
bytes,
sizeof(
int));
191 stream <<
"1 " << i <<
"\n";
197 stream <<
"POINT_DATA " << features.cols() <<
"\n";
200 for(BOOST_AUTO(it,
data.descriptorLabels.begin()); it !=
data.descriptorLabels.end(); it++)
203 if(it->text ==
"normals")
205 buildNormalStream(stream,
"normals",
data);
207 else if(it->text ==
"eigVectors")
209 buildTensorStream(stream,
"eigVectors",
data);
211 else if(it->text ==
"color")
213 buildColorStream(stream,
"color",
data);
216 else if(it->span == 1)
218 buildScalarStream(stream, it->text,
data);
220 else if(it->span == 3 || it->span == 2)
222 buildVectorStream(stream, it->text,
data);
226 LOG_WARNING_STREAM(
"Could not save label named " << it->text <<
" (dim=" << it->span <<
").");
231 for(BOOST_AUTO(it,
data.timeLabels.begin()); it !=
data.timeLabels.end(); it++)
233 buildTimeStream(stream, it->text,
data);
242 const Matrix& descriptors(
data.descriptors.transpose());
244 assert(descriptors.cols() >= 15);
246 stream <<
"# vtk DataFile Version 3.0\n";
247 stream <<
"Triangle mesh\n";
249 stream <<
"DATASET POLYDATA\n";
251 stream <<
"POINTS " << descriptors.rows() * 3 <<
" float\n";
252 for (
int i = 0; i < descriptors.rows(); i++)
255 stream << descriptors.block(i, 3, 1, 3) <<
"\n";
256 stream << descriptors.block(i, 6, 1, 3) <<
"\n";
257 stream << descriptors.block(i, 9, 1, 3) <<
"\n";
265 stream <<
"POLYGONS " << descriptors.rows() <<
" " << descriptors.rows() * 4 <<
"\n";
266 for (
int i = 0; i < descriptors.rows(); i++)
268 stream <<
"3 " << (i*3) <<
" " << (i*3 + 1) <<
" " << (i*3 + 2) <<
"\n";
271 stream <<
"CELL_DATA " << descriptors.rows() <<
"\n";
273 stream <<
"NORMALS triangle_normals float\n";
274 stream << descriptors.block(0, 0, descriptors.rows(), 3) <<
"\n";
292 std::ostream& stream)
296 const int refPtCount(refFeatures.cols());
299 const int readingPtCount(readingFeatures.cols());
300 const int totalPtCount(refPtCount+readingPtCount);
302 stream <<
"# vtk DataFile Version 3.0\n";
303 stream <<
"comment\n";
305 stream <<
"DATASET POLYDATA\n";
307 stream <<
"POINTS " << totalPtCount <<
" float\n";
308 if(refFeatures.rows() == 4)
311 stream << refFeatures.topLeftCorner(3, refFeatures.cols()).transpose() <<
"\n";
313 stream << readingFeatures.topLeftCorner(3, readingFeatures.cols()).transpose() <<
"\n";
318 stream << refFeatures.transpose() <<
"\n";
320 stream << readingFeatures.transpose() <<
"\n";
324 size_t matchCount = readingPtCount*
knn;
325 for (
int k = 0; k <
knn; ++k)
327 for (
int i = 0; i < readingPtCount; ++i)
335 stream <<
"LINES " << matchCount <<
" " << matchCount * 3 <<
"\n";
337 for (
int k = 0; k <
knn; k++)
339 for (
int i = 0; i < readingPtCount; ++i)
341 const auto id =
matches.ids(k, i);
343 stream <<
"2 " << refPtCount + i <<
" " <<
id <<
"\n";
348 stream <<
"CELL_DATA " << matchCount <<
"\n";
349 stream <<
"SCALARS outlier float 1\n";
350 stream <<
"LOOKUP_TABLE default\n";
352 for (
int k = 0; k <
knn; k++)
354 for (
int i = 0; i < readingPtCount; ++i)
356 const auto id =
matches.ids(k, i);
358 stream << featureOutlierWeights(k, i) <<
"\n";
372 ostream* stream(openStream(
name));
373 stream->precision(precision);
374 dumpDataPoints(filteredReference, *stream);
381 ostream* stream(openStream(
name));
382 dumpMeshNodes(filteredReference, *stream);
388 const size_t iterationNumber,
398 ostream* streamLinks(openStream(
"link", iterationNumber));
399 dumpDataLinks(filteredReference,
reading,
matches, outlierWeights, *streamLinks);
400 closeStream(streamLinks);
404 ostream* streamRead(openStream(
"reading", iterationNumber));
405 dumpDataPoints(
reading, *streamRead);
406 closeStream(streamRead);
410 ostream* streamRef(openStream(
"reference", iterationNumber));
411 dumpDataPoints(filteredReference, *streamRef);
412 closeStream(streamRef);
415 if (!bDumpIterationInfo)
return;
420 if(iterationNumber == 0)
423 for(
unsigned int j = 0; j < transCheck.size(); j++)
425 for(
unsigned int i=0; i < transCheck[j]->getConditionVariableNames().size(); i++)
427 if (!(j == 0 && i == 0))
429 *streamIter << transCheck[j]->getConditionVariableNames()[i] <<
", ";
430 *streamIter << transCheck[j]->getLimitNames()[i];
438 for(
unsigned int j = 0; j < transCheck.size(); j++)
440 for(
unsigned int i=0; i < transCheck[j]->getConditionVariables().size(); i++)
443 if (!(j == 0 && i == 0))
446 *streamIter << transCheck[j]->getConditionVariables()[i] <<
", ";
447 *streamIter << transCheck[j]->getLimits()[i];
461 assert(desc.rows() <= forcedDim);
465 if(attribute.compare(
"COLOR_SCALARS") == 0)
467 stream << attribute <<
" " << nameTag <<
" " << forcedDim <<
"\n";
469 std::vector<unsigned char> buffer(forcedDim, 0);
470 for (
int i = 0; i < desc.cols(); ++i){
471 for(
int r=0; r < desc.rows(); ++r){
472 buffer[r] =
static_cast<unsigned int>(desc(r, i) *
static_cast<T>(255) +
static_cast<T>(0.5));
474 stream.write(
reinterpret_cast<char *
>(&buffer.front()), forcedDim);
478 stream << padWithOnes(desc, forcedDim, desc.cols()).transpose();
483 stream << attribute <<
" " << nameTag <<
" " << getTypeName<T>() <<
"\n";
484 if(attribute.compare(
"SCALARS") == 0)
485 stream <<
"LOOKUP_TABLE default\n";
487 writeVtkData(bWriteBinary, padWithZeros(desc, forcedDim, desc.cols()).transpose(), stream);
498 buildGenericAttributeStream(stream,
"SCALARS",
name, cloud, 1);
506 buildGenericAttributeStream(stream,
"NORMALS",
name, cloud, 3);
514 buildGenericAttributeStream(stream,
"VECTORS",
name, cloud, 3);
522 buildGenericAttributeStream(stream,
"TENSORS",
name, cloud, 9);
530 buildGenericAttributeStream(stream,
"COLOR_SCALARS",
name, cloud, 4);
543 if(descRef.rows() != 0 && descRead.rows() != 0)
545 stream <<
"SCALARS " <<
name <<
" float\n";
546 stream <<
"LOOKUP_TABLE default\n";
548 stream << padWithZeros(
549 descRef, 1,
ref.descriptors.cols()).transpose();
551 stream << padWithZeros(
552 descRead, 1,
reading.descriptors.cols()).transpose();
568 if(descRef.rows() != 0 && descRead.rows() != 0)
570 stream <<
"NORMALS " <<
name <<
" float\n";
572 stream << padWithZeros(
573 descRef, 3,
ref.descriptors.cols()).transpose();
575 stream << padWithZeros(
576 descRead, 3,
reading.descriptors.cols()).transpose();
592 if(descRef.rows() != 0 && descRead.rows() != 0)
594 stream <<
"VECTORS " <<
name <<
" " << getTypeName<T>() <<
"\n";
596 stream << padWithZeros(
597 descRef, 3,
ref.descriptors.cols()).transpose();
599 stream << padWithZeros(
600 descRead, 3,
reading.descriptors.cols()).transpose();
616 if(descRef.rows() != 0 && descRead.rows() != 0)
618 stream <<
"TENSORS " <<
name <<
" float\n";
620 stream << padWithZeros(
621 descRef, 9,
ref.descriptors.cols()).transpose();
623 stream << padWithZeros(
624 descRead, 9,
reading.descriptors.cols()).transpose();
638 assert(time.rows() == 1);
643 Eigen::Matrix<uint32_t, 1, Eigen::Dynamic> high32(time.cols());
644 Eigen::Matrix<uint32_t, 1, Eigen::Dynamic> low32(time.cols());
646 for(
int i=0; i<time.cols(); i++)
648 high32(0, i) = (uint32_t)(time(0, i) >> 32);
649 low32(0, i) = (uint32_t)time(0, i);
652 stream <<
"SCALARS" <<
" " <<
name <<
"_splitTime_high32" <<
" " <<
"unsigned_int" <<
"\n";
653 stream <<
"LOOKUP_TABLE default\n";
659 stream <<
"SCALARS" <<
" " <<
name <<
"_splitTime_low32" <<
" " <<
"unsigned_int" <<
"\n";
660 stream <<
"LOOKUP_TABLE default\n";
670 const int expectedRow,
671 const int expectedCols)
673 assert(m.cols() <= expectedCols || m.rows() <= expectedRow);
674 if(m.cols() == expectedCols && m.rows() == expectedRow)
680 Matrix tmp = Matrix::Zero(expectedRow, expectedCols);
681 tmp.topLeftCorner(m.rows(), m.cols()) = m;
690 const int expectedRow,
691 const int expectedCols)
693 assert(m.cols() <= expectedCols || m.rows() <= expectedRow);
694 if(m.cols() == expectedCols && m.rows() == expectedRow)
700 Matrix tmp = Matrix::Ones(expectedRow, expectedCols);
701 tmp.topLeftCorner(m.rows(), m.cols()) = m;
732 if (!bDumpIterationInfo)
return;
735 oss << baseFileName <<
"-iterationInfo.csv";
739 this->streamIter =
new ofstream(oss.str().c_str());
740 if (this->streamIter->fail())
741 throw std::runtime_error(
"Couldn't open the file \"" + oss.str() +
"\". Check if directory exist.");
748 if (!bDumpIterationInfo)
return;
749 closeStream(this->streamIter);
755 string filteredStr = role;
756 if(role.substr(role.size()-4,4) ==
".vtk")
757 filteredStr = role.substr(0, role.size()-4);
760 if(baseFileName !=
"")
761 oss << baseFileName <<
"-" << filteredStr <<
".vtk";
763 oss << filteredStr <<
".vtk";
767 ofstream*
file =
new ofstream(oss.str().c_str(), std::ios::binary);
769 throw std::runtime_error(
"Couldn't open the file \"" + oss.str() +
"\". Check if directory exist.");
777 oss << baseFileName <<
"-" << role <<
"-" << iterationNumber <<
".vtk";
778 ofstream*
file =
new ofstream(oss.str().c_str());
780 throw std::runtime_error(
"Couldn't open the file \"" + oss.str() +
"\". Check if directory exist.");