41 #include <boost/filesystem.hpp> 
   53         const int &xPos, 
const int& yPos, 
const int& zPos,
 
   54         const int &rPos, 
const int& gPos, 
const int& bPos, 
const int &iPos)
 
   57     boost::filesystem::path selectedFile(
filename);
 
   58     string extension(selectedFile.extension().string());
 
   60     if ( extension != 
".pts" && extension != 
".3d" && extension != 
".xyz" && extension != 
".txt" )
 
   62         cout << 
"»" << extension << 
"« is not a valid file extension." << endl;
 
   68     if ( lines_in_file < 2 )
 
   70         cout << 
timestamp << 
"AsciiIO: Too few lines in file (has to be > 2)." << endl;
 
   80     in.getline(buffer, 2048);
 
   81     in.getline(buffer, 2048);
 
   91     in.getline(buffer, 2048);
 
  101     numPoints = lines_in_file - 1;
 
  102     points = 
floatArr( 
new float[ numPoints * 3 ] );
 
  107     if(rPos > num_columns || gPos > num_columns || bPos > num_columns || iPos > num_columns)
 
  109         cout << 
timestamp << 
"Error: At least one attribute index is larger than the number of columns" << endl;
 
  115     bool has_color = (rPos > -1 && gPos > -1 && bPos > -1);
 
  116     bool has_intensity = (iPos > -1);
 
  121         pointColors = 
ucharArr( 
new uint8_t[ numPoints * 3 ] );
 
  126         pointIntensities = 
floatArr( 
new float[ numPoints ] );
 
  131     while (in.good() && c < numPoints)
 
  133         float x, y, z, intensity, dummy;
 
  134         unsigned int r, g, b;
 
  136         for(
int i = 0; i < num_columns; i++)
 
  176             pointColors[ c * 3     ] = (
unsigned char) r;
 
  177             pointColors[ c * 3 + 1 ] = (
unsigned char) g;
 
  178             pointColors[ c * 3 + 2 ] = (
unsigned char) b;
 
  184             pointIntensities[c] = intensity;
 
  189         points[ c * 3 + 1 ] = y;
 
  190         points[ c * 3 + 2 ] = z;
 
  197         cout << 
timestamp << 
"Warning: Point count / line count mismatch: " 
  198              << numPoints << 
" / " << c << endl;
 
  202     size_t numColors = 0;
 
  203     size_t numIntensities = 0;
 
  207         numColors = numPoints;
 
  208         model->m_pointCloud->setColorArray(pointColors, numColors);
 
  214         numIntensities = numPoints;
 
  215         model->m_pointCloud->addFloatChannel(pointIntensities, 
"intensities", numIntensities, 1);
 
  220     model->m_pointCloud->setPointArray(points, numPoints);
 
  230     boost::filesystem::path selectedFile(
filename);
 
  231     string extension(selectedFile.extension().string());
 
  233     if ( extension != 
".pts" && extension != 
".3d" && extension != 
".xyz" && extension != 
".txt" )
 
  235         cout << 
"»" << extension << 
"« is not a valid file extension." << endl;
 
  241     if ( lines_in_file < 2 )
 
  243         cout << 
timestamp << 
"AsciiIO: Too few lines in file (has to be > 2)." << endl;
 
  260     in.getline(buffer, 2048);
 
  261     in.getline(buffer, 2048);
 
  265     bool has_color      = (num_attributes == 3) || (num_attributes == 4);
 
  266     bool has_intensity  = (num_attributes == 1) || (num_attributes == 4);
 
  268     if(has_color || has_intensity)
 
  270         cout << 
timestamp << 
"Autodetected the following attributes" << endl;
 
  271         cout << 
timestamp << 
"Color:     " << has_color << endl;
 
  272         cout << 
timestamp << 
"Intensity: " << has_intensity << endl;
 
  274         if(has_color && has_intensity)
 
  282         else if(has_intensity)
 
  284             if(num_attributes == 1)
 
  303     if ( !this->
m_model->m_pointCloud ) {
 
  304         std::cerr << 
"No point buffer available for output." << std::endl;
 
  308     size_t   pointcount( 0 ), buf ( 0 );
 
  315     pointcount = this->
m_model->m_pointCloud->numPoints();
 
  316     points = this->
m_model->m_pointCloud->getPointArray();
 
  322     auto colors = this->
m_model->m_pointCloud->getChannel<
unsigned char>(
"colors");
 
  325       pointColors = (*colors).dataPtr();
 
  326       buf = (*colors).numElements();
 
  328       if ( pointcount != buf )
 
  331         std::cerr << 
"Amount of points and color information is" 
  332           " not equal. Color information won't be written" << std::endl;
 
  336     auto intensity = this->
m_model->m_pointCloud->getChannel<
float>(
"intensities");
 
  339       pointIntensities = (*intensity).dataPtr();
 
  340       buf = (*intensity).numElements();
 
  344       if ( pointcount != buf )
 
  346         pointIntensities.reset();
 
  347         std::cerr << 
"Amount of points and intensity values are" 
  348           " not equal. Intensity information will not be written." << std::endl;
 
  353     std::ofstream out( 
filename.c_str() );
 
  355     if ( !out.is_open() ) {
 
  356         std::cerr << 
"Could not open file »" << 
filename 
  357             << 
"« for output." << std::endl;
 
  361     for ( 
size_t i(0); i < pointcount; i++ )
 
  363         out << points[i * 3] << 
" " 
  364             << points[i * 3 + 1] << 
" " 
  365             << points[i * 3 + 2];
 
  366         if ( pointIntensities )
 
  368             out << 
" " << pointIntensities[i];
 
  374             out << 
" " << (
unsigned int) pointColors[i * 3]
 
  375                 << 
" " << (
unsigned int) pointColors[i * 3 + 1]
 
  376                 << 
" " << (
unsigned int) pointColors[i * 3 + 2];
 
  396         in.getline(line, 1024);
 
  411     in.getline(line, 1024);
 
  414     in.getline(line, 1024);
 
  420     char* pch = strtok(line, 
" ");
 
  423         pch = strtok(
NULL, 
" ");