39 #include <boost/filesystem.hpp> 65 return read(filename, 4);
75 ifstream in(filename.c_str(), std::ios::binary);
80 in.read((
char*)&numPoints,
sizeof(
int));
84 if(reduction != 0 && numPoints > reduction)
86 mod_filter = (int)(numPoints / reduction);
87 cout <<
timestamp <<
"Reduction mode. Reading every " << mod_filter <<
"th point." << endl;
88 numPoints = reduction;
92 reduction = numPoints;
97 float* pointArray =
new float[3 * numPoints];
98 unsigned char* colorArray =
new unsigned char[3 * numPoints];
103 intensityArray =
floatArr(
new float[numPoints] );
106 float* buffer =
new float[n-1];
114 memset(buffer, 0, (n - 1) *
sizeof(
float));
116 in.read((
char*)buffer, (n - 1) *
sizeof(
float));
121 in.read((
char*)&reflect,
sizeof(
int));
124 if(c % mod_filter == 0 && d < numPoints)
128 pointArray[pos] = buffer[0];
129 pointArray[pos + 1] = buffer[1];
130 pointArray[pos + 2] = buffer[2];
134 intensityArray[d] = (float) reflect;
136 colorArray[pos] = (
unsigned char)reflect;
137 colorArray[pos + 1] = (
unsigned char)reflect;
138 colorArray[pos + 2] = (
unsigned char)reflect;
142 colorArray[pos] = (
unsigned char)0;
143 colorArray[pos + 1] = (
unsigned char)0;
144 colorArray[pos + 2] = (
unsigned char)0;
155 pointArray = (
float*)realloc(pointArray, 3 * d *
sizeof(
float));
156 colorArray = (
unsigned char*)realloc(colorArray, 3 * d *
sizeof(
unsigned char));
158 cout <<
timestamp <<
"Creating point buffer with " << d <<
"points." << endl;
163 pointBuffer->setPointArray(parr, d);
164 pointBuffer->setColorArray(carr, d);
165 pointBuffer->addFloatChannel(intensityArray,
"intensities", d, 1);
167 model->m_pointCloud = pointBuffer;
184 ofstream out(filename.c_str(), std::ios::binary);
187 size_t numPoints = pointBuffer->numPoints();
188 size_t numIntensities;
189 size_t w_intensities;
190 floatArr pointArray = pointBuffer->getPointArray();
191 floatArr intensityArray = pointBuffer->getFloatArray(
"intensities", numIntensities, w_intensities);
193 cout <<
timestamp <<
"Writing " << numPoints <<
" to " << filename << endl;
194 for(
size_t i = 0; i < numPoints; i++)
196 memset(buffer, 0, 4 *
sizeof(
float));
198 buffer[0] = pointArray[pos];
199 buffer[1] = pointArray[pos + 1];
200 buffer[2] = pointArray[pos + 2];
203 buffer[3] = intensityArray[i * w_intensities];
205 out.write((
char*)buffer, 4 *
sizeof(
float));
211 cout <<
timestamp <<
"DatIO: Unable to open file " << filename <<
" for writing." << endl;
A class to handle point information with an arbitrarily large number of attribute channels...
virtual ModelPtr read(string filename, int n, int reduction=0)
static Timestamp timestamp
A global time stamp object for program runtime measurement.
boost::shared_array< unsigned char > ucharArr
std::shared_ptr< PointBuffer > PointBufferPtr
virtual void save(ModelPtr model, string filename)
boost::shared_array< float > floatArr
std::shared_ptr< Model > ModelPtr
string getElapsedTime() const
Returns a string representation of the current timer value.