Skip to content

Commit bf59a2f

Browse files
author
Vladislav Trnka
committed
Use pointer to PinholeCameraDistortion in Image2D
1 parent 0c35e58 commit bf59a2f

5 files changed

Lines changed: 98 additions & 98 deletions

File tree

include/E57SimpleData.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,6 @@ namespace e57
912912
/// Implements e57 extension from http://www.libe57.org/E57_LEICA_Camera_Distortion.txt
913913
struct E57_DLL PinholeCameraDistortion
914914
{
915-
/// Distortion parameters are optional part of standard
916-
bool initialized = false;
917-
918915
/// Optional - Camera number in a multiple camera app (1 - n).
919916
int64_t cameraNumber = 0;
920917

@@ -1009,7 +1006,7 @@ namespace e57
10091006

10101007
/// Optional distortion parameters for a pinhole camera, used when the stored image is not
10111008
/// undistorted.
1012-
PinholeCameraDistortion pinholeCameraDistortion;
1009+
std::unique_ptr<PinholeCameraDistortion> pinholeCameraDistortion;
10131010
};
10141011

10151012
/// @brief Identifies the format representation for the image data

src/ReaderImpl.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -490,34 +490,34 @@ namespace e57
490490
const StructureNode distortion( image.get( "dist:distortion" ) );
491491

492492
auto &pcd = image2DHeader.pinholeCameraDistortion;
493-
pcd.initialized = true;
493+
pcd = std::make_unique<PinholeCameraDistortion>();
494494

495495
if ( distortion.isDefined( "dist:CameraNumber" ) )
496496
{
497-
pcd.cameraNumber = IntegerNode( distortion.get( "dist:CameraNumber" ) ).value();
497+
pcd->cameraNumber = IntegerNode( distortion.get( "dist:CameraNumber" ) ).value();
498498
}
499499

500-
pcd.type = StringNode( distortion.get( "dist:Type" ) ).value();
500+
pcd->type = StringNode( distortion.get( "dist:Type" ) ).value();
501501

502-
pcd.CV_K1 = FloatNode( distortion.get( "dist:CV_K1" ) ).value();
503-
pcd.CV_K2 = FloatNode( distortion.get( "dist:CV_K2" ) ).value();
504-
pcd.CV_K3 = FloatNode( distortion.get( "dist:CV_K3" ) ).value();
505-
pcd.CV_K4 = FloatNode( distortion.get( "dist:CV_K4" ) ).value();
506-
pcd.CV_K5 = FloatNode( distortion.get( "dist:CV_K5" ) ).value();
507-
pcd.CV_K6 = FloatNode( distortion.get( "dist:CV_K6" ) ).value();
502+
pcd->CV_K1 = FloatNode( distortion.get( "dist:CV_K1" ) ).value();
503+
pcd->CV_K2 = FloatNode( distortion.get( "dist:CV_K2" ) ).value();
504+
pcd->CV_K3 = FloatNode( distortion.get( "dist:CV_K3" ) ).value();
505+
pcd->CV_K4 = FloatNode( distortion.get( "dist:CV_K4" ) ).value();
506+
pcd->CV_K5 = FloatNode( distortion.get( "dist:CV_K5" ) ).value();
507+
pcd->CV_K6 = FloatNode( distortion.get( "dist:CV_K6" ) ).value();
508508

509-
pcd.CV_P1 = FloatNode( distortion.get( "dist:CV_P1" ) ).value();
510-
pcd.CV_P2 = FloatNode( distortion.get( "dist:CV_P2" ) ).value();
509+
pcd->CV_P1 = FloatNode( distortion.get( "dist:CV_P1" ) ).value();
510+
pcd->CV_P2 = FloatNode( distortion.get( "dist:CV_P2" ) ).value();
511511

512-
pcd.CV_CX = FloatNode( distortion.get( "dist:CV_CX" ) ).value();
513-
pcd.CV_CY = FloatNode( distortion.get( "dist:CV_CY" ) ).value();
512+
pcd->CV_CX = FloatNode( distortion.get( "dist:CV_CX" ) ).value();
513+
pcd->CV_CY = FloatNode( distortion.get( "dist:CV_CY" ) ).value();
514514

515-
pcd.CV_FX = FloatNode( distortion.get( "dist:CV_FX" ) ).value();
516-
pcd.CV_FY = FloatNode( distortion.get( "dist:CV_FY" ) ).value();
515+
pcd->CV_FX = FloatNode( distortion.get( "dist:CV_FX" ) ).value();
516+
pcd->CV_FY = FloatNode( distortion.get( "dist:CV_FY" ) ).value();
517517

518-
pcd.CV_HEIGHT =
518+
pcd->CV_HEIGHT =
519519
static_cast<int32_t>( IntegerNode( distortion.get( "dist:CV_HEIGHT" ) ).value() );
520-
pcd.CV_WIDTH =
520+
pcd->CV_WIDTH =
521521
static_cast<int32_t>( IntegerNode( distortion.get( "dist:CV_WIDTH" ) ).value() );
522522
}
523523

src/WriterImpl.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ namespace e57
417417

418418
// E57_LEICA_Camera_Distortion
419419
// See: http://www.libe57.org/E57_LEICA_Camera_Distortion.txt
420-
if ( image2DHeader.pinholeCameraDistortion.initialized )
420+
if ( image2DHeader.pinholeCameraDistortion )
421421
{
422422
// make sure we declare the extension before using the fields with prefix
423423
if ( !imf_.extensionsLookupPrefix( "dist" ) )
@@ -429,34 +429,34 @@ namespace e57
429429
image.set( "dist:distortion", distortion );
430430

431431
auto &pcd = image2DHeader.pinholeCameraDistortion;
432-
if ( pcd.cameraNumber > 0 )
432+
if ( pcd->cameraNumber > 0 )
433433
{
434-
distortion.set( "dist:CameraNumber", IntegerNode( imf_, pcd.cameraNumber ) );
434+
distortion.set( "dist:CameraNumber", IntegerNode( imf_, pcd->cameraNumber ) );
435435
}
436436

437-
distortion.set( "dist:Type", StringNode( imf_, pcd.type ) );
437+
distortion.set( "dist:Type", StringNode( imf_, pcd->type ) );
438438

439-
distortion.set( "dist:CV_K1", FloatNode( imf_, pcd.CV_K1 ) );
440-
distortion.set( "dist:CV_K2", FloatNode( imf_, pcd.CV_K2 ) );
441-
distortion.set( "dist:CV_K3", FloatNode( imf_, pcd.CV_K3 ) );
442-
distortion.set( "dist:CV_K4", FloatNode( imf_, pcd.CV_K4 ) );
443-
distortion.set( "dist:CV_K5", FloatNode( imf_, pcd.CV_K5 ) );
444-
distortion.set( "dist:CV_K6", FloatNode( imf_, pcd.CV_K6 ) );
439+
distortion.set( "dist:CV_K1", FloatNode( imf_, pcd->CV_K1 ) );
440+
distortion.set( "dist:CV_K2", FloatNode( imf_, pcd->CV_K2 ) );
441+
distortion.set( "dist:CV_K3", FloatNode( imf_, pcd->CV_K3 ) );
442+
distortion.set( "dist:CV_K4", FloatNode( imf_, pcd->CV_K4 ) );
443+
distortion.set( "dist:CV_K5", FloatNode( imf_, pcd->CV_K5 ) );
444+
distortion.set( "dist:CV_K6", FloatNode( imf_, pcd->CV_K6 ) );
445445

446-
distortion.set( "dist:CV_P1", FloatNode( imf_, pcd.CV_P1 ) );
447-
distortion.set( "dist:CV_P2", FloatNode( imf_, pcd.CV_P2 ) );
446+
distortion.set( "dist:CV_P1", FloatNode( imf_, pcd->CV_P1 ) );
447+
distortion.set( "dist:CV_P2", FloatNode( imf_, pcd->CV_P2 ) );
448448

449-
distortion.set( "dist:CV_CX", FloatNode( imf_, pcd.CV_CX ) );
450-
distortion.set( "dist:CV_CY", FloatNode( imf_, pcd.CV_CY ) );
449+
distortion.set( "dist:CV_CX", FloatNode( imf_, pcd->CV_CX ) );
450+
distortion.set( "dist:CV_CY", FloatNode( imf_, pcd->CV_CY ) );
451451

452-
distortion.set( "dist:CV_FX", FloatNode( imf_, pcd.CV_FX ) );
453-
distortion.set( "dist:CV_FY", FloatNode( imf_, pcd.CV_FY ) );
452+
distortion.set( "dist:CV_FX", FloatNode( imf_, pcd->CV_FX ) );
453+
distortion.set( "dist:CV_FY", FloatNode( imf_, pcd->CV_FY ) );
454454

455455
distortion.set( "dist:CV_HEIGHT",
456-
IntegerNode( imf_, static_cast<int64_t>( pcd.CV_HEIGHT ) ) );
456+
IntegerNode( imf_, static_cast<int64_t>( pcd->CV_HEIGHT ) ) );
457457

458458
distortion.set( "dist:CV_WIDTH",
459-
IntegerNode( imf_, static_cast<int64_t>( pcd.CV_WIDTH ) ) );
459+
IntegerNode( imf_, static_cast<int64_t>( pcd->CV_WIDTH ) ) );
460460
}
461461

462462
return pos;

test/src/test_SimpleReader.cpp

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -395,23 +395,24 @@ TEST( SimpleReaderData, PinholeImageWithDistortionParameters )
395395
EXPECT_EQ( image2Dheader.pinholeRepresentation.imageWidth, 225 );
396396
EXPECT_EQ( image2Dheader.pinholeRepresentation.imageHeight, 300 );
397397

398-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.initialized, true );
399-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.cameraNumber, 1 );
400-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.type, "Testing type" );
401-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K1, 1.01 );
402-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K2, 2.02 );
403-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K3, 3.03 );
404-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K4, 4.04 );
405-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K5, 5.05 );
406-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K6, 6.06 );
407-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_P1, 11.11 );
408-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_P2, 12.12 );
409-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_CX, 21.21 );
410-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_CY, 22.22 );
411-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_FX, 31.31 );
412-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_FY, 32.32 );
413-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.CV_HEIGHT, 225 );
414-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.CV_WIDTH, 300 );
398+
const auto& pcd = image2Dheader.pinholeCameraDistortion;
399+
EXPECT_TRUE( pcd );
400+
EXPECT_EQ( pcd->cameraNumber, 1 );
401+
EXPECT_EQ( pcd->type, "Testing type" );
402+
EXPECT_FLOAT_EQ( pcd->CV_K1, 1.01 );
403+
EXPECT_FLOAT_EQ( pcd->CV_K2, 2.02 );
404+
EXPECT_FLOAT_EQ( pcd->CV_K3, 3.03 );
405+
EXPECT_FLOAT_EQ( pcd->CV_K4, 4.04 );
406+
EXPECT_FLOAT_EQ( pcd->CV_K5, 5.05 );
407+
EXPECT_FLOAT_EQ( pcd->CV_K6, 6.06 );
408+
EXPECT_FLOAT_EQ( pcd->CV_P1, 11.11 );
409+
EXPECT_FLOAT_EQ( pcd->CV_P2, 12.12 );
410+
EXPECT_FLOAT_EQ( pcd->CV_CX, 21.21 );
411+
EXPECT_FLOAT_EQ( pcd->CV_CY, 22.22 );
412+
EXPECT_FLOAT_EQ( pcd->CV_FX, 31.31 );
413+
EXPECT_FLOAT_EQ( pcd->CV_FY, 32.32 );
414+
EXPECT_EQ( pcd->CV_HEIGHT, 225 );
415+
EXPECT_EQ( pcd->CV_WIDTH, 300 );
415416
}
416417

417418
{
@@ -422,23 +423,24 @@ TEST( SimpleReaderData, PinholeImageWithDistortionParameters )
422423
EXPECT_EQ( image2Dheader.pinholeRepresentation.imageWidth, 225 );
423424
EXPECT_EQ( image2Dheader.pinholeRepresentation.imageHeight, 300 );
424425

425-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.initialized, true );
426-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.cameraNumber, 2 );
427-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.type, "" );
428-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K1, 1.01 );
429-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K2, 2.02 );
430-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K3, 0 );
431-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K4, 0 );
432-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K5, 0 );
433-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_K6, 0 );
434-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_P1, 0 );
435-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_P2, 0 );
436-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_CX, 0 );
437-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_CY, 0 );
438-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_FX, 0 );
439-
EXPECT_FLOAT_EQ( image2Dheader.pinholeCameraDistortion.CV_FY, 0 );
440-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.CV_HEIGHT, 225 );
441-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.CV_WIDTH, 300 );
426+
const auto& pcd = image2Dheader.pinholeCameraDistortion;
427+
EXPECT_TRUE( pcd );
428+
EXPECT_EQ( pcd->cameraNumber, 2 );
429+
EXPECT_EQ( pcd->type, "" );
430+
EXPECT_FLOAT_EQ( pcd->CV_K1, 1.01 );
431+
EXPECT_FLOAT_EQ( pcd->CV_K2, 2.02 );
432+
EXPECT_FLOAT_EQ( pcd->CV_K3, 0 );
433+
EXPECT_FLOAT_EQ( pcd->CV_K4, 0 );
434+
EXPECT_FLOAT_EQ( pcd->CV_K5, 0 );
435+
EXPECT_FLOAT_EQ( pcd->CV_K6, 0 );
436+
EXPECT_FLOAT_EQ( pcd->CV_P1, 0 );
437+
EXPECT_FLOAT_EQ( pcd->CV_P2, 0 );
438+
EXPECT_FLOAT_EQ( pcd->CV_CX, 0 );
439+
EXPECT_FLOAT_EQ( pcd->CV_CY, 0 );
440+
EXPECT_FLOAT_EQ( pcd->CV_FX, 0 );
441+
EXPECT_FLOAT_EQ( pcd->CV_FY, 0 );
442+
EXPECT_EQ( pcd->CV_HEIGHT, 225 );
443+
EXPECT_EQ( pcd->CV_WIDTH, 300 );
442444
}
443445

444446
{
@@ -449,7 +451,7 @@ TEST( SimpleReaderData, PinholeImageWithDistortionParameters )
449451
EXPECT_EQ( image2Dheader.pinholeRepresentation.imageWidth, 225 );
450452
EXPECT_EQ( image2Dheader.pinholeRepresentation.imageHeight, 300 );
451453

452-
EXPECT_EQ( image2Dheader.pinholeCameraDistortion.initialized, false );
454+
EXPECT_FALSE( image2Dheader.pinholeCameraDistortion );
453455
}
454456

455457
delete reader;

test/src/test_SimpleWriter.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -743,23 +743,24 @@ TEST( SimpleWriterData, PinholeImageWithDistortionParameters )
743743
image2DHeader.pinholeRepresentation.jpegImageSize = cImageSize;
744744

745745
auto &pcd = image2DHeader.pinholeCameraDistortion;
746-
pcd.initialized = true;
747-
pcd.cameraNumber = 1;
748-
pcd.type = "Testing type";
749-
pcd.CV_K1 = 1.01;
750-
pcd.CV_K2 = 2.02;
751-
pcd.CV_K3 = 3.03;
752-
pcd.CV_K4 = 4.04;
753-
pcd.CV_K5 = 5.05;
754-
pcd.CV_K6 = 6.06;
755-
pcd.CV_P1 = 11.11;
756-
pcd.CV_P2 = 12.12;
757-
pcd.CV_CX = 21.21;
758-
pcd.CV_CY = 22.22;
759-
pcd.CV_FX = 31.31;
760-
pcd.CV_FY = 32.32;
761-
pcd.CV_HEIGHT = 225;
762-
pcd.CV_WIDTH = 300;
746+
pcd = std::make_unique<e57::PinholeCameraDistortion>();
747+
748+
pcd->cameraNumber = 1;
749+
pcd->type = "Testing type";
750+
pcd->CV_K1 = 1.01;
751+
pcd->CV_K2 = 2.02;
752+
pcd->CV_K3 = 3.03;
753+
pcd->CV_K4 = 4.04;
754+
pcd->CV_K5 = 5.05;
755+
pcd->CV_K6 = 6.06;
756+
pcd->CV_P1 = 11.11;
757+
pcd->CV_P2 = 12.12;
758+
pcd->CV_CX = 21.21;
759+
pcd->CV_CY = 22.22;
760+
pcd->CV_FX = 31.31;
761+
pcd->CV_FY = 32.32;
762+
pcd->CV_HEIGHT = 225;
763+
pcd->CV_WIDTH = 300;
763764

764765
std::size_t bytesWritten = 0;
765766
E57_ASSERT_NO_THROW( bytesWritten = writer->WriteImage2DData( image2DHeader, e57::ImageJPEG,
@@ -780,12 +781,12 @@ TEST( SimpleWriterData, PinholeImageWithDistortionParameters )
780781
image2DHeader.pinholeRepresentation.jpegImageSize = cImageSize;
781782

782783
auto &pcd = image2DHeader.pinholeCameraDistortion;
783-
pcd.initialized = true;
784-
pcd.cameraNumber = 2;
785-
pcd.CV_K1 = 1.01;
786-
pcd.CV_K2 = 2.02;
787-
pcd.CV_HEIGHT = 225;
788-
pcd.CV_WIDTH = 300;
784+
pcd = std::make_unique<e57::PinholeCameraDistortion>();
785+
pcd->cameraNumber = 2;
786+
pcd->CV_K1 = 1.01;
787+
pcd->CV_K2 = 2.02;
788+
pcd->CV_HEIGHT = 225;
789+
pcd->CV_WIDTH = 300;
789790

790791
std::size_t bytesWritten = 0;
791792
E57_ASSERT_NO_THROW( bytesWritten = writer->WriteImage2DData( image2DHeader, e57::ImageJPEG,
@@ -799,7 +800,7 @@ TEST( SimpleWriterData, PinholeImageWithDistortionParameters )
799800
// test writing image without distortion header
800801
e57::Image2D image2DHeader;
801802
image2DHeader.name = "JPEG Image Test 3";
802-
image2DHeader.guid = "Pinhole Image 2 - JPEG Image GUID";
803+
image2DHeader.guid = "Pinhole Image 3 - JPEG Image GUID";
803804
image2DHeader.description = "JPEG image test 3 - without distortion header";
804805
image2DHeader.pinholeRepresentation.imageWidth = 225;
805806
image2DHeader.pinholeRepresentation.imageHeight = 300;

0 commit comments

Comments
 (0)