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())
151 if (boost::is_same<double, T>::value) {
164 stream <<
"# vtk DataFile Version 3.0\n";
165 stream <<
"File created by libpointmatcher\n";
166 stream << (bWriteBinary ?
"BINARY":
"ASCII") <<
"\n";
167 stream <<
"DATASET POLYDATA\n";
169 stream <<
"POINTS " << features.cols() <<
" " << getTypeName<T>() <<
"\n";
171 if(features.rows() == 4)
173 writeVtkData(bWriteBinary, features.topLeftCorner(3, features.cols()).transpose(), stream) <<
"\n";
177 writeVtkData(bWriteBinary, features.transpose(), stream) <<
"\n";
180 stream <<
"VERTICES " << features.cols() <<
" "<< features.cols() * 2 <<
"\n";
181 for (
int i = 0; i < features.cols(); ++i){
183 stream.write(
reinterpret_cast<const char*
>(&
oneBigEndian),
sizeof(
int));
188 stream.write(converter.
bytes,
sizeof(
int));
190 stream <<
"1 " << i <<
"\n";
196 stream <<
"POINT_DATA " << features.cols() <<
"\n";
202 if(it->text ==
"normals")
204 buildNormalStream(stream,
"normals", data);
206 else if(it->text ==
"eigVectors")
208 buildTensorStream(stream,
"eigVectors", data);
210 else if(it->text ==
"color")
212 buildColorStream(stream,
"color", data);
215 else if(it->span == 1)
217 buildScalarStream(stream, it->text, data);
219 else if(it->span == 3 || it->span == 2)
221 buildVectorStream(stream, it->text, data);
225 LOG_WARNING_STREAM(
"Could not save label named " << it->text <<
" (dim=" << it->span <<
").");
232 buildTimeStream(stream, it->text, data);
243 assert(descriptors.cols() >= 15);
245 stream <<
"# vtk DataFile Version 3.0\n";
246 stream <<
"Triangle mesh\n";
248 stream <<
"DATASET POLYDATA\n";
250 stream <<
"POINTS " << descriptors.rows() * 3 <<
" float\n";
251 for (
int i = 0; i < descriptors.rows(); i++)
254 stream << descriptors.block(i, 3, 1, 3) <<
"\n";
255 stream << descriptors.block(i, 6, 1, 3) <<
"\n";
256 stream << descriptors.block(i, 9, 1, 3) <<
"\n";
264 stream <<
"POLYGONS " << descriptors.rows() <<
" " << descriptors.rows() * 4 <<
"\n";
265 for (
int i = 0; i < descriptors.rows(); i++)
267 stream <<
"3 " << (i*3) <<
" " << (i*3 + 1) <<
" " << (i*3 + 2) <<
"\n";
270 stream <<
"CELL_DATA " << descriptors.rows() <<
"\n";
272 stream <<
"NORMALS triangle_normals float\n";
273 stream << descriptors.block(0, 0, descriptors.rows(), 3) <<
"\n";
291 std::ostream& stream)
295 const int refPtCount(refFeatures.cols());
298 const int readingPtCount(readingFeatures.cols());
299 const int totalPtCount(refPtCount+readingPtCount);
301 stream <<
"# vtk DataFile Version 3.0\n";
302 stream <<
"comment\n";
304 stream <<
"DATASET POLYDATA\n";
306 stream <<
"POINTS " << totalPtCount <<
" float\n";
307 if(refFeatures.rows() == 4)
310 stream << refFeatures.topLeftCorner(3, refFeatures.cols()).transpose() <<
"\n";
312 stream << readingFeatures.topLeftCorner(3, readingFeatures.cols()).transpose() <<
"\n";
317 stream << refFeatures.transpose() <<
"\n";
319 stream << readingFeatures.transpose() <<
"\n";
321 const int knn = matches.
ids.rows();
323 size_t matchCount = readingPtCount*knn;
324 for (
int k = 0; k < knn; ++k)
326 for (
int i = 0; i < readingPtCount; ++i)
334 stream <<
"LINES " << matchCount <<
" " << matchCount * 3 <<
"\n";
336 for (
int k = 0; k < knn; k++)
338 for (
int i = 0; i < readingPtCount; ++i)
340 const auto id = matches.
ids(k, i);
342 stream <<
"2 " << refPtCount + i <<
" " <<
id <<
"\n";
347 stream <<
"CELL_DATA " << matchCount <<
"\n";
348 stream <<
"SCALARS outlier float 1\n";
349 stream <<
"LOOKUP_TABLE default\n";
351 for (
int k = 0; k < knn; k++)
353 for (
int i = 0; i < readingPtCount; ++i)
355 const auto id = matches.
ids(k, i);
357 stream << featureOutlierWeights(k, i) <<
"\n";
371 ostream* stream(openStream(name));
372 dumpDataPoints(filteredReference, *stream);
379 ostream* stream(openStream(name));
380 dumpMeshNodes(filteredReference, *stream);
386 const size_t iterationNumber,
396 ostream* streamLinks(openStream(
"link", iterationNumber));
397 dumpDataLinks(filteredReference, reading, matches, outlierWeights, *streamLinks);
398 closeStream(streamLinks);
402 ostream* streamRead(openStream(
"reading", iterationNumber));
403 dumpDataPoints(reading, *streamRead);
404 closeStream(streamRead);
408 ostream* streamRef(openStream(
"reference", iterationNumber));
409 dumpDataPoints(filteredReference, *streamRef);
410 closeStream(streamRef);
413 if (!bDumpIterationInfo)
return;
418 if(iterationNumber == 0)
421 for(
unsigned int j = 0; j < transCheck.size(); j++)
423 for(
unsigned int i=0; i < transCheck[j]->getConditionVariableNames().size(); i++)
425 if (!(j == 0 && i == 0))
427 *streamIter << transCheck[j]->getConditionVariableNames()[i] <<
", ";
428 *streamIter << transCheck[j]->getLimitNames()[i];
436 for(
unsigned int j = 0; j < transCheck.size(); j++)
438 for(
unsigned int i=0; i < transCheck[j]->getConditionVariables().size(); i++)
441 if (!(j == 0 && i == 0))
444 *streamIter << transCheck[j]->getConditionVariables()[i] <<
", ";
445 *streamIter << transCheck[j]->getLimits()[i];
459 assert(desc.rows() <= forcedDim);
463 if(attribute.compare(
"COLOR_SCALARS") == 0)
465 stream << attribute <<
" " << nameTag <<
" " << forcedDim <<
"\n";
467 std::vector<unsigned char> buffer(forcedDim, 0);
468 for (
int i = 0; i < desc.cols(); ++i){
469 for(
int r=0; r < desc.rows(); ++r){
470 buffer[r] =
static_cast<unsigned int>(desc(r, i) *
static_cast<T
>(255) +
static_cast<T
>(0.5));
472 stream.write(
reinterpret_cast<char *
>(&buffer.front()), forcedDim);
476 stream << padWithOnes(desc, forcedDim, desc.cols()).transpose();
481 stream << attribute <<
" " << nameTag <<
" " << getTypeName<T>() <<
"\n";
482 if(attribute.compare(
"SCALARS") == 0)
483 stream <<
"LOOKUP_TABLE default\n";
485 writeVtkData(bWriteBinary, padWithZeros(desc, forcedDim, desc.cols()).transpose(), stream);
496 buildGenericAttributeStream(stream,
"SCALARS", name, cloud, 1);
504 buildGenericAttributeStream(stream,
"NORMALS", name, cloud, 3);
512 buildGenericAttributeStream(stream,
"VECTORS", name, cloud, 3);
520 buildGenericAttributeStream(stream,
"TENSORS", name, cloud, 9);
528 buildGenericAttributeStream(stream,
"COLOR_SCALARS", name, cloud, 4);
538 const Matrix descRef(ref.getDescriptorByName(name));
539 const Matrix descRead(reading.getDescriptorByName(name));
541 if(descRef.rows() != 0 && descRead.rows() != 0)
543 stream <<
"SCALARS " << name <<
" float\n";
544 stream <<
"LOOKUP_TABLE default\n";
546 stream << padWithZeros(
549 stream << padWithZeros(
550 descRead, 1, reading.
descriptors.cols()).transpose();
563 const Matrix descRef(ref.getDescriptorByName(name));
564 const Matrix descRead(reading.getDescriptorByName(name));
566 if(descRef.rows() != 0 && descRead.rows() != 0)
568 stream <<
"NORMALS " << name <<
" float\n";
570 stream << padWithZeros(
573 stream << padWithZeros(
574 descRead, 3, reading.
descriptors.cols()).transpose();
587 const Matrix descRef(ref.getDescriptorByName(name));
588 const Matrix descRead(reading.getDescriptorByName(name));
590 if(descRef.rows() != 0 && descRead.rows() != 0)
592 stream <<
"VECTORS " << name <<
" " << getTypeName<T>() <<
"\n";
594 stream << padWithZeros(
597 stream << padWithZeros(
598 descRead, 3, reading.
descriptors.cols()).transpose();
611 const Matrix descRef(ref.getDescriptorByName(name));
612 const Matrix descRead(reading.getDescriptorByName(name));
614 if(descRef.rows() != 0 && descRead.rows() != 0)
616 stream <<
"TENSORS " << name <<
" float\n";
618 stream << padWithZeros(
621 stream << padWithZeros(
622 descRead, 9, reading.
descriptors.cols()).transpose();
636 assert(time.rows() == 1);
641 Eigen::Matrix<uint32_t, 1, Eigen::Dynamic> high32(time.cols());
642 Eigen::Matrix<uint32_t, 1, Eigen::Dynamic> low32(time.cols());
644 for(
int i=0; i<time.cols(); i++)
646 high32(0, i) = (uint32_t)(time(0, i) >> 32);
647 low32(0, i) = (uint32_t)time(0, i);
650 stream <<
"SCALARS" <<
" " << name <<
"_splitTime_high32" <<
" " <<
"unsigned_int" <<
"\n";
651 stream <<
"LOOKUP_TABLE default\n";
657 stream <<
"SCALARS" <<
" " << name <<
"_splitTime_low32" <<
" " <<
"unsigned_int" <<
"\n";
658 stream <<
"LOOKUP_TABLE default\n";
668 const int expectedRow,
669 const int expectedCols)
671 assert(m.cols() <= expectedCols || m.rows() <= expectedRow);
672 if(m.cols() == expectedCols && m.rows() == expectedRow)
678 Matrix tmp = Matrix::Zero(expectedRow, expectedCols);
679 tmp.topLeftCorner(m.rows(), m.cols()) = m;
688 const int expectedRow,
689 const int expectedCols)
691 assert(m.cols() <= expectedCols || m.rows() <= expectedRow);
692 if(m.cols() == expectedCols && m.rows() == expectedRow)
698 Matrix tmp = Matrix::Ones(expectedRow, expectedCols);
699 tmp.topLeftCorner(m.rows(), m.cols()) = m;
729 if (!bDumpIterationInfo)
return;
732 oss << baseFileName <<
"-iterationInfo.csv";
736 this->streamIter =
new ofstream(oss.str().c_str());
737 if (this->streamIter->fail())
738 throw std::runtime_error(
"Couldn't open the file \"" + oss.str() +
"\". Check if directory exist.");
745 if (!bDumpIterationInfo)
return;
746 closeStream(this->streamIter);
752 string filteredStr = role;
753 if(role.substr(role.size()-4,4) ==
".vtk")
754 filteredStr = role.substr(0, role.size()-4);
757 if(baseFileName !=
"")
758 oss << baseFileName <<
"-" << filteredStr <<
".vtk";
760 oss << filteredStr <<
".vtk";
764 ofstream* file =
new ofstream(oss.str().c_str(), std::ios::binary);
766 throw std::runtime_error(
"Couldn't open the file \"" + oss.str() +
"\". Check if directory exist.");
774 oss << baseFileName <<
"-" << role <<
"-" << iterationNumber <<
".vtk";
775 ofstream* file =
new ofstream(oss.str().c_str());
777 throw std::runtime_error(
"Couldn't open the file \"" + oss.str() +
"\". Check if directory exist.");