17 #include "config_util.h"
18 #include "geomPoints.h"
20 #include "pandaNode.h"
24 #include "string_utils.h"
25 #include "config_egg2pg.h"
35 set_program_brief(
"convert point cloud data into a .bam file");
36 set_program_description
37 (
"This program reads a point clound in a pts file and outputs a bam files, "
38 "suitable for viewing in Panda.");
41 add_runline(
"[opts] input.pts output.bam");
42 add_runline(
"[opts] -o output.bam input.pts");
46 "Specify the filename to which the resulting .bam file will be written. "
47 "If this option is omitted, the last parameter name is taken to be the "
48 "name of the output file.",
49 &PtsToBam::dispatch_filename, &_got_output_filename, &_output_filename);
53 "Decimates the point cloud by the indicated divisor. The number of points\n"
54 "added is 1/divisor; numbers larger than 1.0 mean correspondingly fewer\n"
56 &PtsToBam::dispatch_double, NULL, &_decimate_divisor);
58 _decimate_divisor = 1.0;
71 nout <<
"Cannot open " << _pts_filename <<
"\n";
77 _num_points_expected = 0;
78 _num_points_found = 0;
79 _num_points_added = 0;
80 _decimate_factor = 1.0 / max(1.0, _decimate_divisor);
83 _decimated_point_number = 0.0;
86 while (getline(pts, line)) {
91 nout <<
"\nFound " << _num_points_found <<
" points of " << _num_points_expected <<
" expected.\n";
92 nout <<
"Generated " << _num_points_added <<
" points to bam file.\n";
100 nout <<
"Writing " << filename <<
"\n";
103 nout <<
"Error in writing.\n";
108 nout <<
"Error in writing.\n";
121 nout <<
"You must specify the pts file to read on the command line.\n";
125 if (args.size() > 1) {
126 nout <<
"Specify only one pts on the command line.\n";
141 process_line(
const string &line) {
144 if (_line_number % 1000000 == 0) {
145 cerr <<
"." << flush;
148 if (line.empty() || !isdigit(line[0])) {
152 if (_line_number == 1) {
155 tokenize(trim(line), words,
" \t",
true);
156 if (words.size() == 1) {
158 _num_points_expected = string_to_int(words[0], tail);
159 nout <<
"Expecting " << _num_points_expected <<
" points, will generate "
160 << (int)(_num_points_expected * _decimate_factor) <<
"\n";
167 _decimated_point_number += _decimate_factor;
168 int point_number = int(_decimated_point_number);
169 if (point_number > _point_number) {
170 _point_number = point_number;
173 tokenize(trim(line), words,
" \t",
true);
174 if (words.size() >= 3) {
186 add_point(
const vector_string &words) {
187 if (_data == NULL || _data->get_num_rows() >= egg_max_vertices) {
193 x = string_to_double(words[0], tail);
194 y = string_to_double(words[1], tail);
195 z = string_to_double(words[2], tail);
210 CPT(GeomVertexFormat) format = GeomVertexFormat::get_v3();
222 close_vertex_data() {
228 nout <<
"\nGenerating " << _num_points_added <<
" points in " << _num_vdatas <<
" GeomVertexDatas\n";
232 int num_vertices = _data->get_num_rows();
233 int vertices_so_far = 0;
234 while (num_vertices > 0) {
235 int this_num_vertices = min(num_vertices, (
int)egg_max_indices);
237 points->add_consecutive_vertices(vertices_so_far, this_num_vertices);
238 geom->add_primitive(points);
239 vertices_so_far += this_num_vertices;
240 num_vertices -= this_num_vertices;
243 _gnode->add_geom(geom);
248 int main(
int argc,
char *argv[]) {
The principle public interface to reading and writing Bam disk files.
bool write_object(const TypedWritable *object)
Writes the indicated object to the Bam file.
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
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(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
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.
The name of a file, such as a texture file or an Egg file.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
void add_data3d(double x, double y, double z)
Sets the write row to a particular 3-component value, and advances the write row. ...
This is the bare functionality (intended to be inherited from along with ProgramBase or some derivati...
string get_basename() const
Returns the basename part of the filename.
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 string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).