asmaloney/libE57Format

How to export colored cloud ?

Unreal34 opened this issue · 3 comments

Hello there,

I started using the lib and it works really nice for reading but i'm stucked into something weird. When I try to write a colored point cloud my program crash.

There is no crash when fields are set to false :

ColoredScanHeader.pointFields.colorRedField = false;
ColoredScanHeader.pointFields.colorGreenField = false;
ColoredScanHeader.pointFields.colorBlueField = false;

Maybe I missed something but I don't see anything weird in my code.

My code:

int main()
{
	e57::Writer eWriter("Cloud.e57");

	int64_t nPointsCount = 50'000;

	e57::Data3D	ColoredScanHeader;
	ColoredScanHeader.guid = "{D3817EC3-A3DD-4a81-9EF5-2FFD0EC91D5A}";
	ColoredScanHeader.pointsSize = nPointsCount;
	ColoredScanHeader.pointFields.cartesianXField = true;
	ColoredScanHeader.pointFields.cartesianYField = true;
	ColoredScanHeader.pointFields.cartesianZField = true;
	ColoredScanHeader.pointFields.colorRedField = true;
	ColoredScanHeader.pointFields.colorGreenField = true;
	ColoredScanHeader.pointFields.colorBlueField = true;

	int scanIndex = eWriter.NewData3D(ColoredScanHeader);

	e57::Data3DPointsData ColoredBuffer;

	ColoredBuffer.cartesianX = new float[nPointsCount];
	ColoredBuffer.cartesianY = new float[nPointsCount];
	ColoredBuffer.cartesianZ = new float[nPointsCount];
	ColoredBuffer.colorRed = new uint8_t[nPointsCount];
	ColoredBuffer.colorGreen = new uint8_t[nPointsCount];
	ColoredBuffer.colorBlue = new uint8_t[nPointsCount];

	e57::CompressedVectorWriter dataWriter = eWriter.SetUpData3DPointsData(scanIndex, nPointsCount, ColoredBuffer);

	for (int64_t i = 0; i < nPointsCount; i++)
	{
		ColoredBuffer.cartesianX[i] = RandomFloat(-100.f, 100.f);
		ColoredBuffer.cartesianY[i] = RandomFloat(-50.f, 50.f);
		ColoredBuffer.cartesianZ[i] = RandomFloat(-200.f, 200.f);

		ColoredBuffer.colorRed[i] = 0;
		ColoredBuffer.colorGreen[i] = 255;
		ColoredBuffer.colorBlue[i] = 0;
	}

	 dataWriter.write(nPointsCount); // <---- crash here when colorRedField, colorGreenField  and  colorBlueField  are set to true.

	dataWriter.close();
	eWriter.Close();

	delete ColoredBuffer.cartesianX;
	delete ColoredBuffer.cartesianY;
	delete ColoredBuffer.cartesianZ;
	delete ColoredBuffer.colorRed;
	delete ColoredBuffer.colorGreen;
	delete ColoredBuffer.colorBlue;

	std::cout << "Finished !" << std::endl;

	return 0;
}

Thank in advance,

You can wrap the call in a try/catch to check what the error is:

try
{
   dataWriter.write( nPointsCount );
}
catch ( e57::E57Exception &err )
{
   std::cerr << "ERROR:" << err.sourceFunctionName() << "() in " << err.sourceFileName() << " (line "
             << err.sourceLineNumber() << ") context: " << err.context() << std::endl;
}

That should be a starting point to figuring out what's happening.

Ok thank you I will try this.

Ok I managed to find the solution. In reading code from Encoder.cpp.

You have to set those values before writing colored cloud on disk.

ColoredScanHeader.colorLimits.colorRedMinimum = 0;
ColoredScanHeader.colorLimits.colorRedMaximum = 255;
ColoredScanHeader.colorLimits.colorGreenMinimum = 0;
ColoredScanHeader.colorLimits.colorGreenMaximum = 255;
ColoredScanHeader.colorLimits.colorBlueMinimum = 0;
ColoredScanHeader.colorLimits.colorBlueMaximum = 255;

Thnak you for your help.