Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
file_io.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR a PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 namespace pcl
37 {
38 
39 #ifndef _WIN32
40  void getAllPcdFilesInDirectory(const std::string& directory, std::vector<std::string>& file_names)
41  {
42  DIR *dp;
43  struct dirent *dirp;
44  if((dp = opendir(directory.c_str())) == NULL) {
45  std::cerr << "Could not open directory.\n";
46  return;
47  }
48  while ((dirp = readdir(dp)) != NULL) {
49  if (dirp->d_type == DT_REG) // Only regular files
50  {
51  std::string file_name = dirp->d_name;
52  if (file_name.substr(file_name.size()-4, 4)==".pcd")
53  file_names.push_back(dirp->d_name);
54  }
55  }
56  closedir(dp);
57  std::sort(file_names.begin(), file_names.end());
58  //for (unsigned int i=0; i<file_names.size(); ++i)
59  //cout << file_names[i]<<"\n";
60  }
61 #endif
62 
63 std::string getFilenameWithoutPath(const std::string& input)
64 {
65  size_t filename_start = input.find_last_of('/', static_cast<size_t>(-1)) + 1;
66  return input.substr(filename_start, input.size()-filename_start);
67 }
68 
69 std::string getFilenameWithoutExtension(const std::string& input)
70 {
71  size_t dot_position = input.find_last_of('.', input.size());
72  return input.substr(0, dot_position);
73 }
74 
75 std::string getFileExtension(const std::string& input)
76 {
77  size_t dot_position = input.find_last_of('.', input.size());
78  return input.substr(dot_position+1, input.size());
79 }
80 
81 } // namespace end