@@ -808,240 +808,6 @@ TEST (PCL, ASCIIReader)
808808
809809}
810810
811- // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
812- TEST (PCL , PLYReaderWriter)
813- {
814- pcl::PCLPointCloud2 cloud_blob, cloud_blob2;
815- PointCloud<PointXYZI> cloud, cloud2;
816-
817- cloud.width = 640 ;
818- cloud.height = 480 ;
819- cloud.resize (cloud.width * cloud.height );
820- cloud.is_dense = true ;
821-
822- srand (static_cast <unsigned int > (time (NULL )));
823- size_t nr_p = cloud.size ();
824- // Randomly create a new point cloud
825- for (size_t i = 0 ; i < nr_p; ++i)
826- {
827- cloud[i].x = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
828- cloud[i].y = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
829- cloud[i].z = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
830- cloud[i].intensity = static_cast <float > (i);
831- }
832-
833- // Convert from data type to blob
834- toPCLPointCloud2 (cloud, cloud_blob);
835-
836- EXPECT_EQ (cloud_blob.width , cloud.width ); // test for toPCLPointCloud2 ()
837- EXPECT_EQ (cloud_blob.height , cloud.height ); // test for toPCLPointCloud2 ()
838- EXPECT_EQ (cloud_blob.is_dense , cloud.is_dense ); // test for toPCLPointCloud2 ()
839- EXPECT_EQ (cloud_blob.data .size (),
840- cloud_blob.width * cloud_blob.height * sizeof (PointXYZI));
841-
842- // test for toPCLPointCloud2 ()
843- PLYWriter writer;
844- writer.write (" test_pcl_io.ply" , cloud_blob, Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), true , true );
845-
846- PLYReader reader;
847- reader.read (" test_pcl_io.ply" , cloud_blob2);
848- // PLY DOES preserve organiziation
849- EXPECT_EQ (cloud_blob.width * cloud_blob.height , cloud_blob2.width * cloud_blob2.height );
850- EXPECT_EQ (cloud_blob.is_dense , cloud.is_dense );
851- EXPECT_EQ (size_t (cloud_blob2.data .size ()), // PointXYZI is 16*2 (XYZ+1, Intensity+3)
852- cloud_blob2.width * cloud_blob2.height * sizeof (PointXYZ)); // test for loadPLYFile ()
853-
854- // Convert from blob to data type
855- fromPCLPointCloud2 (cloud_blob2, cloud2);
856-
857- // EXPECT_EQ (cloud.width, cloud2.width); // test for fromPCLPointCloud2 ()
858- // EXPECT_EQ (cloud.height, cloud2.height); // test for fromPCLPointCloud2 ()
859- // EXPECT_EQ (cloud.is_dense, cloud2.is_dense); // test for fromPCLPointCloud2 ()
860- EXPECT_EQ (cloud.size (), cloud2.size ()); // test for fromPCLPointCloud2 ()
861-
862- for (uint32_t counter = 0 ; counter < cloud.size (); ++counter)
863- {
864- EXPECT_FLOAT_EQ (cloud[counter].x , cloud2[counter].x ); // test for fromPCLPointCloud2 ()
865- EXPECT_FLOAT_EQ (cloud[counter].y , cloud2[counter].y ); // test for fromPCLPointCloud2 ()
866- EXPECT_FLOAT_EQ (cloud[counter].z , cloud2[counter].z ); // test for fromPCLPointCloud2 ()
867- EXPECT_FLOAT_EQ (cloud[counter].intensity , cloud2[counter].intensity ); // test for fromPCLPointCloud2 ()
868- }
869- }
870-
871- // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
872- class PLYTest : public ::testing::Test
873- {
874- protected:
875-
876- PLYTest () : mesh_file_ply_(" ply_color_mesh.ply" )
877- {
878- std::ofstream fs;
879- fs.open (mesh_file_ply_.c_str ());
880- fs << " ply\n "
881- " format ascii 1.0\n "
882- " element vertex 4\n "
883- " property float x\n "
884- " property float y\n "
885- " property float z\n "
886- " property uchar red\n "
887- " property uchar green\n "
888- " property uchar blue\n "
889- " property uchar alpha\n "
890- " element face 2\n "
891- " property list uchar int vertex_indices\n "
892- " end_header\n "
893- " 4.23607 0 1.61803 255 0 0 255\n "
894- " 2.61803 2.61803 2.61803 0 255 0 0\n "
895- " 0 1.61803 4.23607 0 0 255 128\n "
896- " 0 -1.61803 4.23607 255 255 255 128\n "
897- " 3 0 1 2\n "
898- " 3 1 2 3\n " ;
899- fs.close ();
900-
901- // Test colors from ply_benchmark.ply
902- rgba_1_ = static_cast <uint32_t > (255 ) << 24 | static_cast <uint32_t > (255 ) << 16 |
903- static_cast <uint32_t > (0 ) << 8 | static_cast <uint32_t > (0 );
904- rgba_2_ = static_cast <uint32_t > (0 ) << 24 | static_cast <uint32_t > (0 ) << 16 |
905- static_cast <uint32_t > (255 ) << 8 | static_cast <uint32_t > (0 );
906- rgba_3_ = static_cast <uint32_t > (128 ) << 24 | static_cast <uint32_t > (0 ) << 16 |
907- static_cast <uint32_t > (0 ) << 8 | static_cast <uint32_t > (255 );
908- rgba_4_ = static_cast <uint32_t > (128 ) << 24 | static_cast <uint32_t > (255 ) << 16 |
909- static_cast <uint32_t > (255 ) << 8 | static_cast <uint32_t > (255 );
910- }
911-
912- virtual
913- ~PLYTest () { remove (mesh_file_ply_.c_str ()); }
914-
915- std::string mesh_file_ply_;
916- uint32_t rgba_1_;
917- uint32_t rgba_2_;
918- uint32_t rgba_3_;
919- uint32_t rgba_4_;
920- };
921-
922- // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
923- TEST_F (PLYTest, LoadPLYFileColoredASCIIIntoBlob)
924- {
925- int res;
926- uint32_t rgba;
927-
928- PCLPointCloud2 cloud_blob;
929- uint32_t ps;
930- int32_t offset = -1 ;
931-
932- // check if loading is ok
933- res = loadPLYFile (mesh_file_ply_, cloud_blob);
934- ASSERT_EQ (res, 0 );
935-
936- // blob has proper structure
937- EXPECT_EQ (cloud_blob.height , 1 );
938- EXPECT_EQ (cloud_blob.width , 4 );
939- EXPECT_EQ (cloud_blob.fields .size (), 4 );
940- EXPECT_FALSE (cloud_blob.is_bigendian );
941- EXPECT_EQ (cloud_blob.point_step , 16 );
942- EXPECT_EQ (cloud_blob.row_step , 16 * 4 );
943- EXPECT_EQ (cloud_blob.data .size (), 16 * 4 );
944- EXPECT_TRUE (cloud_blob.is_dense );
945-
946- // scope blob data
947- ps = cloud_blob.point_step ;
948- for (size_t i = 0 ; i < cloud_blob.fields .size (); ++i)
949- if (cloud_blob.fields [i].name == std::string (" rgba" ))
950- offset = static_cast <int32_t > (cloud_blob.fields [i].offset );
951-
952- ASSERT_GE (offset, 0 );
953-
954- // 1st point
955- rgba = *reinterpret_cast <uint32_t *> (&cloud_blob.data [offset]);
956- ASSERT_EQ (rgba, rgba_1_);
957-
958- // 2th point
959- rgba = *reinterpret_cast <uint32_t *> (&cloud_blob.data [ps + offset]);
960- ASSERT_EQ (rgba, rgba_2_);
961-
962- // 3th point
963- rgba = *reinterpret_cast <uint32_t *> (&cloud_blob.data [2 * ps + offset]);
964- ASSERT_EQ (rgba, rgba_3_);
965-
966- // 4th point
967- rgba = *reinterpret_cast <uint32_t *> (&cloud_blob.data [3 * ps + offset]);
968- ASSERT_EQ (rgba, rgba_4_);
969- }
970-
971- // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
972- TEST_F (PLYTest, LoadPLYFileColoredASCIIIntoPolygonMesh)
973- {
974- int res;
975- uint32_t rgba;
976- PolygonMesh mesh;
977- uint32_t ps;
978- int32_t offset = -1 ;
979-
980- // check if loading is ok
981- res = loadPLYFile (mesh_file_ply_, mesh);
982- ASSERT_EQ (res, 0 );
983-
984- // blob has proper structure
985- EXPECT_EQ (mesh.cloud .height , 1 );
986- EXPECT_EQ (mesh.cloud .width , 4 );
987- EXPECT_EQ (mesh.cloud .fields .size (), 4 );
988- EXPECT_FALSE (mesh.cloud .is_bigendian );
989- EXPECT_EQ (mesh.cloud .point_step , 16 );
990- EXPECT_EQ (mesh.cloud .row_step , 16 * 4 );
991- EXPECT_EQ (mesh.cloud .data .size (), 16 * 4 );
992- EXPECT_TRUE (mesh.cloud .is_dense );
993-
994- // scope blob data
995- ps = mesh.cloud .point_step ;
996- for (size_t i = 0 ; i < mesh.cloud .fields .size (); ++i)
997- if (mesh.cloud .fields [i].name == std::string (" rgba" ))
998- offset = static_cast <int32_t > (mesh.cloud .fields [i].offset );
999-
1000- ASSERT_GE (offset, 0 );
1001-
1002- // 1st point
1003- rgba = *reinterpret_cast <uint32_t *> (&mesh.cloud .data [offset]);
1004- ASSERT_EQ (rgba, rgba_1_);
1005-
1006- // 2th point
1007- rgba = *reinterpret_cast <uint32_t *> (&mesh.cloud .data [ps + offset]);
1008- ASSERT_EQ (rgba, rgba_2_);
1009-
1010- // 3th point
1011- rgba = *reinterpret_cast <uint32_t *> (&mesh.cloud .data [2 * ps + offset]);
1012- ASSERT_EQ (rgba, rgba_3_);
1013-
1014- // 4th point
1015- rgba = *reinterpret_cast <uint32_t *> (&mesh.cloud .data [3 * ps + offset]);
1016- ASSERT_EQ (rgba, rgba_4_);
1017- }
1018-
1019- // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1020- template <typename T> class PLYPointCloudTest : public PLYTest { };
1021- typedef ::testing::Types<BOOST_PP_SEQ_ENUM (PCL_RGB_POINT_TYPES )> RGBPointTypes;
1022- TYPED_TEST_CASE (PLYPointCloudTest, RGBPointTypes);
1023- TYPED_TEST (PLYPointCloudTest, LoadPLYFileColoredASCIIIntoPointCloud)
1024- {
1025- int res;
1026- PointCloud<TypeParam> cloud_rgb;
1027-
1028- // check if loading is ok
1029- res = loadPLYFile (PLYTest::mesh_file_ply_, cloud_rgb);
1030- ASSERT_EQ (res, 0 );
1031-
1032- // cloud has proper structure
1033- EXPECT_EQ (cloud_rgb.height , 1 );
1034- EXPECT_EQ (cloud_rgb.width , 4 );
1035- EXPECT_EQ (cloud_rgb.points .size (), 4 );
1036- EXPECT_TRUE (cloud_rgb.is_dense );
1037-
1038- // scope cloud data
1039- ASSERT_EQ (cloud_rgb[0 ].rgba , PLYTest::rgba_1_);
1040- ASSERT_EQ (cloud_rgb[1 ].rgba , PLYTest::rgba_2_);
1041- ASSERT_EQ (cloud_rgb[2 ].rgba , PLYTest::rgba_3_);
1042- ASSERT_EQ (cloud_rgb[3 ].rgba , PLYTest::rgba_4_);
1043- }
1044-
1045811// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1046812
1047813struct PointXYZFPFH33
0 commit comments