33 set_program_brief(
"convert point cloud data into a .bam file");
34 set_program_description
35 (
"This program reads a point clound in a pts file and outputs a bam files, " 36 "suitable for viewing in Panda.");
39 add_runline(
"[opts] input.pts output.bam");
40 add_runline(
"[opts] -o output.bam input.pts");
44 "Specify the filename to which the resulting .bam file will be written. " 45 "If this option is omitted, the last parameter name is taken to be the " 46 "name of the output file.",
47 &PtsToBam::dispatch_filename, &_got_output_filename, &_output_filename);
51 "Decimates the point cloud by the indicated divisor. The number of points\n" 52 "added is 1/divisor; numbers larger than 1.0 mean correspondingly fewer\n" 54 &PtsToBam::dispatch_double,
nullptr, &_decimate_divisor);
56 _decimate_divisor = 1.0;
67 nout <<
"Cannot open " << _pts_filename <<
"\n";
73 _num_points_expected = 0;
74 _num_points_found = 0;
75 _num_points_added = 0;
76 _decimate_factor = 1.0 / std::max(1.0, _decimate_divisor);
79 _decimated_point_number = 0.0;
82 while (std::getline(pts, line)) {
87 nout <<
"\nFound " << _num_points_found <<
" points of " << _num_points_expected <<
" expected.\n";
88 nout <<
"Generated " << _num_points_added <<
" points to bam file.\n";
96 nout <<
"Writing " << filename <<
"\n";
99 nout <<
"Error in writing.\n";
104 nout <<
"Error in writing.\n";
115 nout <<
"You must specify the pts file to read on the command line.\n";
119 if (args.size() > 1) {
120 nout <<
"Specify only one pts on the command line.\n";
133 process_line(
const string &line) {
136 if (_line_number % 1000000 == 0) {
137 std::cerr <<
"." << std::flush;
140 if (line.empty() || !isdigit(line[0])) {
144 if (_line_number == 1) {
148 if (words.size() == 1) {
151 nout <<
"Expecting " << _num_points_expected <<
" points, will generate " 152 << (int)(_num_points_expected * _decimate_factor) <<
"\n";
159 _decimated_point_number += _decimate_factor;
160 int point_number = int(_decimated_point_number);
161 if (point_number > _point_number) {
162 _point_number = point_number;
166 if (words.size() >= 3) {
176 add_point(
const vector_string &words) {
177 if (_data ==
nullptr || _data->get_num_rows() >= egg_max_vertices) {
195 if (_data !=
nullptr) {
207 close_vertex_data() {
208 if (_data ==
nullptr) {
213 nout <<
"\nGenerating " << _num_points_added <<
" points in " << _num_vdatas <<
" GeomVertexDatas\n";
217 int num_vertices = _data->get_num_rows();
218 int vertices_so_far = 0;
219 while (num_vertices > 0) {
220 int this_num_vertices = std::min(num_vertices, (
int)egg_max_indices);
222 points->add_consecutive_vertices(vertices_so_far, this_num_vertices);
223 geom->add_primitive(points);
224 vertices_so_far += this_num_vertices;
225 num_vertices -= this_num_vertices;
228 _gnode->add_geom(geom);
233 int main(
int argc,
char *argv[]) {
The principle public interface to reading and writing Bam disk files.
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool write_object(const TypedWritable *object)
Writes the indicated object to the Bam file.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
Defines a series of disconnected points.
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
void set_text()
Indicates that the filename represents a text file.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
bool has_output_filename() const
Returns true if the user specified an output filename, false otherwise (e.g.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
string trim(const string &str)
Returns a new string representing the contents of the given string with both leading and trailing whi...
void add_data3d(double x, double y, double z)
Sets the write row to a particular 3-component value, and advances the write row.
std::string get_basename() const
Returns the basename part of the filename.
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
void tokenize(const string &str, vector_string &words, const string &delimiters, bool discard_repeated_delimiters)
Chops the source string up into pieces delimited by any of the characters specified in delimiters.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
bool open_write(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated file for writing.
A node that holds Geom objects, renderable pieces of geometry.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...