-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes PLY parsing of char and uchar scalars #1443
Conversation
Some feedback requested here. Am I missing something? To clear a little bit the purpose of this PR, I was going through the items mentioned in #1381, and noticed I wasn't able to load color information from PLY files if I used This was my test code #include <pcl/common/common.h>
#include <pcl/console/parse.h>
#include <pcl/point_cloud.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main(int argc, char* argv[])
{
std::vector<int> ply_args = pcl::console::parse_file_extension_argument (argc, argv, ".ply");
if (ply_args.size() != 1)
{
PCL_ERROR("Usage: %s input.ply\n", argv[0]);
return -1;
}
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
if (pcl::io::loadPLYFile(argv[ply_args[0]], *cloud) != 0)
{
PCL_ERROR("Could not load %s\n", argv[ply_args[0]]);
return -1;
}
pcl::visualization::PCLVisualizer viewer;
viewer.addPointCloud(cloud);
viewer.spin();
return 0;
} and this was my test ply file
|
So for your example file the old code would do: value = boost::lexical_cast<uint8> (value_s); and the new one: value = static_cast<uint8> (boost::lexical_cast<uint16> (value_s)); Do I understand right that the former does not work as expected? Could you please elaborate on what happens exactly? |
For my example file, the old code (in my platform) would evaluate value = boost::lexical_cast<unsigned char> (value_s); and |
Aha, okay. Apparently, whenever we do lexical cast from a multi-digit string to an (unsigned) char, a 👍 for the patch. Would you mind to change the commit message to explain the problem it solves in greater detail? (To reduce confusion for posterity.) |
Thanks for trying it out. I'll probably amend the commit description with this small summary you just wrote on your comment. Regarding the test, don't merge this PR right yet, I'll write the test as well. I already gave a look into that file and test_io.cpp which has the PLYReaderWriter test and I was wondering if it would not be preferable to gather all these PLY specific tests in a new test_ply.cpp file. I also found very strange the absence of PLY files in the test folder. Going through the source I realised that most code is actually saving and loading PLY files on-the-fly for each test. Which makes it more challenging to understand if the issue is actually on the reader/load or the writer/save. We should at least make sure the reader is working reliably before using it to evaluate the outputs of the writer. |
Yep, you are right. Our coverage is very far from 100% and does not always do tests appropriately. |
@taketwo please take a look at the test if you can and once that's done I'll squash the commits and amend the message. |
I think the actual name of the file and the path you specified in CMakeLists do not match (ply vs. vtk). In fact, the file is so small and simple, why not embedding it directly in the test (e.g. like it is done here)? Also I noticed that the test is not built/executed on Travis, likely because of this guard. Looking at the unit tests, it's clear that OpenNI is not required. So I think we should drop this condition. |
a359b65
to
ed1bdb3
Compare
Done 👍. Added the fixture for the teardown functionality (in case an assertion fails). I'm not really fond of dumping things in the HDD and not cleaning up afterwards :/ |
ed1bdb3
to
1df66e9
Compare
Apparently it blew up in Travis -_- |
WIP of PointCloudLibrary#1381. int8 and uint8 types were being evaluated as char and unsigned char, their actual original type, so whenever a lexical_cast was performed from a multi-digit string to an (unsigned) char, a bad_lexical_cast exception was thrown and the value set to a quiet NaN. Functionally-wise, this PR will make color parsing work.
1df66e9
to
4fc3ab3
Compare
Fixes PLY parsing of char and uchar scalars
WIP of #1381
int8
anduint8
types were being evaluated aschar
andunsigned char
, their actual original type, which breaks their lexical_cast evaluation as integers. Functionally-wise, this PR will make color parsing work.