Volume* load_volume(tinyxml2::XMLElement *elem, VolumeCache &cache, const std::string &scene_file){ if (!elem->Attribute("name")){ std::cout << "Scene error: Volumes require a name" << std::endl; return nullptr; } if (!elem->Attribute("type")){ std::cout << "Scene error: Volumes require a type" << std::endl; return nullptr; } std::string name = elem->Attribute("name"); std::string type = elem->Attribute("type"); Volume *vol = cache.get(name); if (vol){ return vol; } Colorf sig_a, sig_s, emit; float phase_asym; read_color(elem->FirstChildElement("absorption"), sig_a); read_color(elem->FirstChildElement("scattering"), sig_s); read_color(elem->FirstChildElement("emission"), emit); read_float(elem->FirstChildElement("phase_asymmetry"), phase_asym); if (type == "homogeneous"){ Point min, max; read_point(elem->FirstChildElement("min"), min); read_point(elem->FirstChildElement("max"), max); return cache.add(name, std::make_unique<HomogeneousVolume>(sig_a, sig_s, emit, phase_asym, BBox{min, max})); } if (type == "exponential"){ float a = 0, b = 0; Vector up; Point min, max; read_float(elem->FirstChildElement("a"), a); read_float(elem->FirstChildElement("b"), b); read_vector(elem->FirstChildElement("up"), up); read_point(elem->FirstChildElement("min"), min); read_point(elem->FirstChildElement("max"), max); return cache.add(name, std::make_unique<ExponentialVolume>(sig_a, sig_s, emit, phase_asym, BBox{min, max}, a, b, up)); } if (type == "vol"){ std::string file = scene_file.substr(0, scene_file.rfind(PATH_SEP) + 1) + elem->Attribute("file"); float density_scale = 1; read_float(elem->FirstChildElement("density_scale"), density_scale); return cache.add(name, std::make_unique<GridVolume>(sig_a, sig_s, emit, phase_asym, file, density_scale)); } std::cout << "Scene error: Unrecognized volume type " << type << std::endl; return nullptr; }
int main() { int T; Point A, B, C, D, E, F; scanf("%d", &T); while(T--) { A = read_point(); B = read_point(); C = read_point(); D = getD(A, B, C); E = getD(B, C, A); F = getD(C, A, B); printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y); } return 0; }
v3dmc_object load_object(GLchar *filename){ FILE *file; GLint i,npoints,nlines,ntriangles,nquads; v3dmc_object obj = object(); v3dmc_point p; v3dmc_line l; v3dmc_triangle t; v3dmc_quad q; file = fopen(filename,"r"); if(file!=NULL){ fread(&npoints,sizeof(int),1,file); fread(&nlines,sizeof(int),1,file); fread(&ntriangles,sizeof(int),1,file); fread(&nquads,sizeof(int),1,file); for(i=0;i<npoints;i++){ read_point(file,&p); add_point(&obj,p); } for(i=0;i<nlines;i++){ fread(&l,sizeof(v3dmc_line),1,file); add_line(&obj,l); } for(i=0;i<ntriangles;i++){ fread(&t,sizeof(v3dmc_triangle),1,file); add_triangle(&obj,t); } for(i=0;i<nquads;i++){ fread(&q,sizeof(v3dmc_quad),1,file); add_quad(&obj,q); } fclose(file); } return obj; }
geometry_ptr read() { geometry_ptr geom; int type=read_integer(); switch (type) { case wkbPoint: geom = read_point(); break; case wkbLineString: geom = read_linestring(); break; case wkbPolygon: geom = read_polygon(); break; case wkbMultiPoint: geom = read_multipoint(); break; case wkbMultiLineString: geom = read_multilinestring(); break; case wkbMultiPolygon: geom=read_multipolygon(); break; case wkbGeometryCollection: break; default: break; } return geom; }
//Test [Main program] int main(int argc, char *argv[]){ Tpoint p1, p2; float dist; read_point(&p1); read_point(&p2); dist= distance(p1,p2); printf("\nDistance from point1:"); print_point(p1); printf("\nDistance to point2:"); print_point(p2); printf("\nResult => %f\n",dist); return 0; }
QPolygonF read_line(uint8_t byte_order, InputIterator& itr, const frame& fr) { const uint32_t count(brig::detail::ogc::read<uint32_t>(byte_order, itr)); QPolygonF line; line.reserve(count); for (uint32_t i(0); i < count; ++i) line.push_back( read_point(byte_order, itr, fr) ); return line; }
void read_multipoint(boost::ptr_vector<geometry_type> & paths) { int num_points = read_integer(); for (int i = 0; i < num_points; ++i) { pos_ += 5; read_point(paths); } }
void read(boost::ptr_vector<geometry_type> & paths) { int type = read_integer(); #ifdef MAPNIK_LOG MAPNIK_LOG_DEBUG(wkb_reader) << "wkb_reader: Read=" << wkb_geometry_type_string(type) << "," << type; #endif switch (type) { case wkbPoint: read_point(paths); break; case wkbLineString: read_linestring(paths); break; case wkbPolygon: read_polygon(paths); break; case wkbMultiPoint: read_multipoint(paths); break; case wkbMultiLineString: read_multilinestring(paths); break; case wkbMultiPolygon: read_multipolygon(paths); break; case wkbGeometryCollection: read_collection(paths); break; case wkbPointZ: read_point_xyz(paths); break; case wkbLineStringZ: read_linestring_xyz(paths); break; case wkbPolygonZ: read_polygon_xyz(paths); break; case wkbMultiPointZ: read_multipoint_xyz(paths); break; case wkbMultiLineStringZ: read_multilinestring_xyz(paths); break; case wkbMultiPolygonZ: read_multipolygon_xyz(paths); break; case wkbGeometryCollectionZ: read_collection(paths); break; default: break; } }
void read(boost::ptr_vector<geometry_type> & paths) { int type = read_integer(); switch (type) { case wkbPoint: read_point(paths); break; case wkbLineString: read_linestring(paths); break; case wkbPolygon: read_polygon(paths); break; case wkbMultiPoint: read_multipoint(paths); break; case wkbMultiLineString: read_multilinestring(paths); break; case wkbMultiPolygon: read_multipolygon(paths); break; case wkbGeometryCollection: read_collection(paths); break; case wkbPointZ: read_point_xyz(paths); break; case wkbLineStringZ: read_linestring_xyz(paths); break; case wkbPolygonZ: read_polygon_xyz(paths); break; case wkbMultiPointZ: read_multipoint_xyz(paths); break; case wkbMultiLineStringZ: read_multilinestring_xyz(paths); break; case wkbMultiPolygonZ: read_multipolygon_xyz(paths); break; case wkbGeometryCollectionZ: read_collection(paths); break; default: break; } }
int main(int argc, char** argv) { struct point a = {.x = 1, .y = 1}; struct point *b = malloc(sizeof(struct point));; FILE *fp = fopen("ex3_db", "w+"); print_point(&a); save_point(&a, fp); rewind(fp); read_point(b, fp); print_point(b); fclose(fp); return 0; }
mapnik::geometry::geometry<double> read() { mapnik::geometry::geometry<double> geom = mapnik::geometry::geometry_empty(); int type = read_integer(); switch (type) { case wkbPoint: geom = std::move(read_point()); break; case wkbLineString: geom = std::move(read_linestring()); break; case wkbPolygon: geom = std::move(read_polygon()); break; case wkbMultiPoint: geom = std::move(read_multipoint()); break; case wkbMultiLineString: geom = std::move(read_multilinestring()); break; case wkbMultiPolygon: geom = std::move(read_multipolygon()); break; case wkbGeometryCollection: geom = std::move(read_collection()); break; case wkbPointZ: case wkbPointM: geom = std::move(read_point<true>()); break; case wkbPointZM: geom = std::move(read_point<true,true>()); break; case wkbLineStringZ: case wkbLineStringM: geom = std::move(read_linestring<true>()); break; case wkbLineStringZM: geom = std::move(read_linestring<true,true>()); break; case wkbPolygonZ: case wkbPolygonM: geom = std::move(read_polygon<true>()); break; case wkbPolygonZM: geom = std::move(read_polygon<true,true>()); break; case wkbMultiPointZ: case wkbMultiPointM: geom = std::move(read_multipoint<true>()); break; case wkbMultiPointZM: geom = std::move(read_multipoint<true,true>()); break; case wkbMultiLineStringZ: case wkbMultiLineStringM: geom = std::move(read_multilinestring<true>()); break; case wkbMultiLineStringZM: geom = std::move(read_multilinestring<true,true>()); break; case wkbMultiPolygonZ: case wkbMultiPolygonM: geom = std::move(read_multipolygon<true>()); break; case wkbMultiPolygonZM: geom = std::move(read_multipolygon<true,true>()); break; case wkbGeometryCollectionZ: case wkbGeometryCollectionM: case wkbGeometryCollectionZM: geom = std::move(read_collection()); break; default: break; } return geom; }
int main (int argc, char **argv) { char *inf_name; int ch; int i; int nm_sites; int normalize = 0; /* Make all weights sum to one? */ fastf_t *coeff; fastf_t x, y, z; FILE *infp; struct bu_list site_list; struct bu_vls *tail_buf = 0; struct site *sp; BU_LIST_INIT(&site_list); while ((ch = bu_getopt(argc, argv, OPT_STRING)) != EOF) switch (ch) { case 'n': normalize = 1; break; case 's': if (sscanf(bu_optarg, "%lf %lf %lf", &x, &y, &z) != 3) { bu_log("Illegal site: '%s'\n", bu_optarg); print_usage(); } enqueue_site(&site_list, x, y, z); break; case 't': if (tail_buf == 0) /* Only initialize it once */ tail_buf = bu_vls_vlsinit(); break; case '?': default: print_usage(); } switch (argc - bu_optind) { case 0: inf_name = "stdin"; infp = stdin; break; case 1: inf_name = argv[bu_optind++]; if ((infp = fopen(inf_name, "r")) == NULL) bu_exit (1, "Cannot open file '%s'\n", inf_name); break; default: print_usage(); } if (BU_LIST_IS_EMPTY(&site_list)) { enqueue_site(&site_list, (fastf_t) 1.0, (fastf_t) 0.0, (fastf_t) 0.0); enqueue_site(&site_list, (fastf_t) 0.0, (fastf_t) 1.0, (fastf_t) 0.0); enqueue_site(&site_list, (fastf_t) 0.0, (fastf_t) 0.0, (fastf_t) 1.0); } nm_sites = 0; for (BU_LIST_FOR(sp, site, &site_list)) ++nm_sites; coeff = (fastf_t *) bu_malloc(nm_sites * sizeof(fastf_t), "coefficient array"); while (read_point(infp, coeff, nm_sites, normalize, tail_buf) != EOF) { x = y = z = 0.0; i = 0; for (BU_LIST_FOR(sp, site, &site_list)) { x += sp -> s_x * coeff[i]; y += sp -> s_y * coeff[i]; z += sp -> s_z * coeff[i]; ++i; } bu_flog(stdout, "%g %g %g", x, y, z); if (tail_buf) bu_flog(stdout, "%s", bu_vls_addr(tail_buf)); bu_flog(stdout, "\n"); } return 0; }
int DxfMap::load(char *filename, double mapOffsetX, double mapOffsetY, double scaleFactor) { FILE *fp; int groupCode; char string[256]; int number; double real; int line; int level; int vertices; int i; double x, y; if ((fp = fopen(filename, "r")) == NULL) { printf("Can't open dxf file \"%s\"\n", filename); return -EIO; } featureNum = 0; line = 0; while ((groupCode = read_group (fp, string, &number, &real, &line, &level, &vertices)) >= 0) { if ((groupCode == 0) && (strncmp(string, "POLYLINE", 9) == 0)) { if (read_polyline(fp) < 0) { break; } } if ((groupCode == 0) && (strncmp(string, "LINE", 5) == 0)) { if (read_line(fp) < 0) { break; } } if ((groupCode == 0) && (strncmp(string, "LWPOLYLINE", 11) == 0)) { if (read_lwpolyline(fp) < 0) { break; } } if ((groupCode == 0) && (strncmp(string, "POINT", 5) == 0)) { if (read_point(fp) < 0) { break; } } if ((groupCode == 0) && (strncmp(string, "EOF", 3) == 0)) break; } fclose(fp); for (i = 0; i < featureNum; i++) { x = (feature[i].y - mapOffsetX) * scaleFactor; y = (feature[i].x - mapOffsetY) * scaleFactor; feature[i].x = x; feature[i].y = y; x = (feature[i].y2 - mapOffsetX) * scaleFactor; y = (feature[i].x2 - mapOffsetY) * scaleFactor; feature[i].x2 = x; feature[i].y2 = y; x = feature[i].x2 - feature[i].x; y = feature[i].y2 - feature[i].y; feature[i].l = sqrt(x * x + y * y); if (feature[i].l > 0.0) { feature[i].rho = atan2(y, x); feature[i].sin = sin(feature[i].rho); feature[i].cos = cos(feature[i].rho); } else { feature[i].rho = 0.0; feature[i].sin = 0.0; feature[i].cos = 1.0; } } return 0; }
int main(int argc, char* argv[]) { // We've put the typedefs here as VC7 gives us an ICE if they are global typedefs typedef Nef_polyhedron::SNC_structure SNC_structure; typedef CGAL::visual_hull_creator<SNC_structure> VHC; if(argc!=2) { std::cerr << "Usage: visual_hull file" << std::endl; std::cerr << "For more information read the README file" << std::endl; return 1; } std::ifstream in(argv[1]); NaryInt ni; CGAL::Timer t; Point_3 room_min = read_point(in); Point_3 room_max = read_point(in); int ncameras; in >> ncameras; for(int cam=0; cam<ncameras; ++cam) { Point_3 camera(read_point(in)); int npolygons; in >> npolygons; std::list<std::list<Point_3> > polygon_list; for(int poly=0; poly<npolygons; ++poly) { int npoints; in >> npoints; std::list<Point_3> input_points; for(int pnt=0; pnt<npoints; ++pnt) input_points.push_back(read_point(in)); polygon_list.push_back(input_points); } std::list<std::list<Point_3> >::iterator li; for(li=polygon_list.begin(); li!=polygon_list.end(); ++li) { std::list<Point_3>::iterator pi(li->begin()), pimin(pi), pi_next,pi_prev; for(; pi!=li->end(); ++pi) { if(CGAL::lexicographically_xyz_smaller(*pi,*pimin)) pimin=pi; } pi_next=pi_prev=pimin; ++pi_next; if(pi_next==li->end()) pi_next=li->begin(); if(pi_prev==li->begin()) pi_prev=li->end(); --pi_prev; if(CGAL::orientation(*pi_prev,*pimin,*pi_next,camera) == CGAL::POSITIVE) li->reverse(); } t.start(); Nef_polyhedron N; VHC vhc(room_min, room_max, camera, polygon_list); N.delegate(vhc,true); CGAL_assertion(N.is_valid()); t.stop(); std::cerr << "create view " << t.time() << std::endl; t.reset(); ni.add_polyhedron(N); } Nef_polyhedron result = ni.get_intersection(); QApplication a(argc,argv); CGAL::Qt_widget_Nef_3<Nef_polyhedron>* w = new CGAL::Qt_widget_Nef_3<Nef_polyhedron>(result); a.setMainWidget(w); w->show(); a.exec(); }
int main(int argc, char **argv) { if (argc > 5 || argc < 4) { fprintf(stderr, "Usage: %s <size>\n", argv[0]); return 2; } point p1, p2, p3; if (!read_point(argv[1], &p1)) { fprintf(stderr, "Invalid point: %s\n", argv[1]); return 1; } if (!read_point(argv[2], &p2)) { fprintf(stderr, "Invalid point: %s\n", argv[2]); return 1; } if (!read_point(argv[3], &p3)) { fprintf(stderr, "Invalid point: %s\n", argv[3]); return 1; } int size = 100; if (argc == 5) size = atoi(argv[4]); if (size < 0) { fprintf(stderr, "Please enter a positive size: %d\n", size); } vector dir1, dir2; minus(p2, p1, &dir1); minus(p3, p1, &dir2); int count; { double count_x, count_y, count_z; count_x = max(dir1.x / size, dir2.x / size); count_y = max(dir1.y / size, dir2.y / size); count_z = max(dir1.z / size, dir2.z / size); count = (int) max(count_x, max(count_y, count_z)); } divide(&dir1, count); divide(&dir2, count); int x, y; int idx0, idx1, idx2, idx3; printf("Shape \"trianglemesh\"\n"); printf("\t\"point P\" [\n"); for (x = 0; x <= count; x++) { for (y = 0; y <= count; y++) { printf("\t\t%f %f %f\n", p1.x + (x * dir1.x) + (y * dir2.x), p1.y + (x * dir1.y) + (y * dir2.y), p1.z + (x * dir1.z) + (y * dir2.z) ); } } printf("\t\n]"); printf("\t\"integer indices\" [\n"); for (x = 0; x < count; x++) { for (y = 0; y < count; y++) { idx0 = x * (count + 1) + y; idx1 = (x + 1) * (count + 1) + y; idx2 = (x + 1) * (count + 1) + (y + 1); idx3 = x * (count + 1) + (y + 1); printf("\t\t%d %d %d %d %d %d\n", idx0, idx1, idx2, idx2, idx3, idx0 ); } } printf("\t]\n"); return 0; }
int read_one_obj( FILE *fp, Polygon *poly, Surface *surface) { char b[MWS]; int flag_material = 0; int flag_point = 0; int flag_index = 0; /* initialize surface */ surface->diff[0] = 1.0; surface->diff[1] = 1.0; surface->diff[2] = 1.0; surface->spec[0] = 0.0; surface->spec[1] = 0.0; surface->spec[2] = 0.0; surface->ambi = 0.0; surface->shine = 0.2; if ( getword(fp,b,MWS) <= 0) return 0; poly->vtx_num = 0; poly->idx_num = 0; while (flag_material==0 || flag_point==0 || flag_index==0) { if (strindex(b,"Material")>=0) { getword(fp,b,MWS); flag_material = 1; } else if (strindex(b,"point")>=0) { fprintf(stderr,"Counting... [point]\n"); poly->vtx_num = count_point(fp, b); flag_point = 1; } else if (strindex(b,"coordIndex")>=0) { fprintf(stderr,"Counting... [coordIndex]\n"); poly->idx_num = count_index(fp, b); flag_index = 1; } else if (getword(fp,b,MWS) <= 0) return 0; } flag_material = 0; flag_point = 0; flag_index = 0; fseek(fp, 0, SEEK_SET); poly->vtx = (double *)malloc(sizeof(double)*3*poly->vtx_num); poly->idx = (int *)malloc(sizeof(int)*3*poly->idx_num); while (flag_material==0 || flag_point==0 || flag_index==0) { if (strindex(b,"Material")>=0) { fprintf(stderr,"Reading... [Material]\n"); read_material(fp,surface,b); flag_material = 1; } else if (strindex(b,"point")>=0) { fprintf(stderr,"Reading... [point]\n"); read_point(fp,poly,b); flag_point = 1; } else if (strindex(b,"coordIndex")>=0) { fprintf(stderr,"Reading... [coordIndex]\n"); read_index(fp,poly,b); flag_index = 1; } else if (getword(fp,b,MWS) <= 0) return 0; } return 1; }
void demo_res (int Screen_Mode, int X_max, int Y_max) { char *Error1 = "Failure while calling SET_MODEX"; char *Error2 = "Failure during READ_PIXEL test"; char *Abort_Msg = "Demo aborted by User"; char *Demo_Msg = " This is a MODE X demo "; char *Scrn_Msg = "Screen Resolution is by "; char *Cont_Msg = "Press <ANY KEY> to Continue"; char *Line_Msg = "LINE TEST"; char *Fill_Msg = "FILL TEST"; char *Pixel_Msg = "PIXEL TEST"; char Text[10]; int x1, y1, x2, y2 = 0; int x, y, z = 0; int X_Center, gap = 0; if (set_modex (Screen_Mode) == 0) { error_out (Error1); } X_Center = X_max / 2; x1 = 10; y1 = 10; x2 = X_max - 1; y2 = Y_max - 1; for (z = 0; z <= 3; z++) { y = 31 - z -z; draw_line (x1+z, y1+z, x2-z, y1+z, y); draw_line (x1+z, y1+z, x1+z, y2-z, y); draw_line (x1+z, y2-z, x2-z, y2-z, y); draw_line (x2-z, y1+z, x2-z, y2-z, y); } for (x = 0; x < (X_max / 10); x++) { tgprintc (48 + ((x+1) % 10), x*10+1, 1, 9 + ((x/8) % 7) ); draw_line (x*10+9, 0, x*10+9, 3, c_bWHITE); } for (y = 0; y < (Y_max / 10); y++) { tgprintc (48 + ((y+1) % 10), 1, y*10+1, 9 + ((y/10) % 7) ); draw_line (0, y*10+9, 3, y*10+9, c_bWHITE); } for (x = 0; x <= 63; x++) { z = 15 + (x * 3 / 4); set_dac_register (64+x, z, z, z); set_dac_register (128+x, 0, z, z); draw_line (103-x, 60, 40+x, 123, 64+x); draw_line (40, 60+x, 103, 123-x, 128+x); } tprint_str (Line_Msg, 9, 37, 130, c_BLUE); y = 60; gap = 0; for (x = 0; x <= 9; x++) { fill_block (120, y, 120+x, y+gap, 64+x); fill_block (140 - (15-x), y, 150+x, y+gap, 230+x); fill_block (170 - (15-x), y, 170, y+gap, 128+x); y = y + gap + 2; gap++; } tprint_str (Fill_Msg, 9, 110, 46, c_GREEN); for (x = 190; x <= 250; x+=2) { for (y = 60; y <= 122; y+=2) { z = (x+x+y+y) & 0xff; set_point (x, y, z); } } tprint_str (Pixel_Msg, 10, 182, 130, c_RED); for (x = 190; x <= 250; x+=2) { for (y = 60; y <= 122; y+=2) { z = (x+x+y+y) & 0xff; if (read_point(x, y) != z) { error_out (Error2); } } } print_str (Demo_Msg, 23, X_Center - 92, 20, c_bRED, c_BLUE); x = X_Center - 124; print_str (Scrn_Msg, 28, x, 30, c_bGREEN, c_BLACK); sprintf (Text, "%3d", X_max); print_str (Text, 3, x+168, 30, c_bPURPLE, c_BLACK); sprintf (Text, "%3d", Y_max); print_str (Text, 3, x + 224, 30, c_bWHITE, c_BLACK); for (x = 0; x <= 15; x++) { set_dac_register (230+x, 63-x*4, 0, 15+x*3); draw_line (30+x, Y_max-6-x, X_max-20-x, Y_max-6-x, 230+x); } tprint_str (Cont_Msg, 27, X_Center - 103, Y_max-18, c_YELLOW); if (get_key () == Ky_ESC) { error_out (Abort_Msg); } return ; }
BOOL LASreaderBIN::open(ByteStreamIn* stream) { int i; if (stream == 0) { fprintf(stderr,"ERROR: ByteStreamIn* pointer is zero\n"); return FALSE; } this->stream = stream; // read the TS header TSheader tsheader; try { stream->getBytes((U8*)&tsheader, sizeof(TSheader)); } catch(...) { fprintf(stderr,"ERROR: reading terrasolid header\n"); return FALSE; } // check the TS header if (tsheader.size != sizeof(TSheader)) { fprintf(stderr,"ERROR: corrupt terrasolid header. size != 56.\n"); return FALSE; } if (tsheader.recog_val != 970401) { fprintf(stderr,"ERROR: corrupt terrasolid header. recog_val != 979401.\n"); return FALSE; } if (strncmp(tsheader.recog_str, "CXYZ", 4) != 0) { fprintf(stderr,"ERROR: corrupt terrasolid header. recog_str != CXYZ.\n"); return FALSE; } version = tsheader.version; // populate the header as much as possible sprintf(header.system_identifier, "LAStools (c) by rapidlasso GmbH"); sprintf(header.generating_software, "via LASreaderBIN (%d)", LAS_TOOLS_VERSION); if (tsheader.time) { if (tsheader.rgb) { header.point_data_format = 3; header.point_data_record_length = 34; } else { header.point_data_format = 1; header.point_data_record_length = 28; } } else { if (tsheader.rgb) { header.point_data_format = 2; header.point_data_record_length = 26; } else { header.point_data_format = 0; header.point_data_record_length = 20; } } header.number_of_point_records = tsheader.npoints; npoints = tsheader.npoints; F64 scale = 1.0/(F64)tsheader.units; header.x_scale_factor = scale; header.y_scale_factor = scale; header.z_scale_factor = scale; header.x_offset = -tsheader.origin_x*scale; header.y_offset = -tsheader.origin_y*scale; header.z_offset = -tsheader.origin_z*scale; // initialize point point.init(&header, header.point_data_format, header.point_data_record_length); // set point count to zero p_count = 0; // approximate bounding box init if (read_point()) { header.min_x = header.max_x = point.get_x(); header.min_y = header.max_y = point.get_y(); header.min_z = header.max_z = point.get_z(); if (tsheader.npoints > 10) { for (i = tsheader.npoints/10; i < tsheader.npoints; i += (tsheader.npoints/10)) { if (!seek(i)) return FALSE; if (!read_point()) return FALSE; } } header.number_of_points_by_return[0] = 0; header.number_of_points_by_return[1] = 0; } return seek(0); }
BOOL LASreaderQFIT::open(ByteStreamIn* stream) { U32 i; if (stream == 0) { fprintf(stderr,"ERROR: ByteStreamIn* pointer is zero\n"); return FALSE; } this->stream = stream; // read the QFIT header try { stream->get32bitsLE((U8*)&version); } catch(...) { fprintf(stderr,"ERROR: reading QFIT header\n"); return FALSE; } // is QFIT file little-endian if (version == 40 || version == 48 || version == 56) { little_endian = TRUE; endian_swap = (IS_LITTLE_ENDIAN() == FALSE); } else { ENDIAN_SWAP_32((U8*)&version); if (version == 40 || version == 48 || version == 56) { little_endian = FALSE; endian_swap = (IS_LITTLE_ENDIAN() == TRUE); } else { fprintf(stderr,"ERROR: corrupt QFIT header.\n"); return FALSE; } } // read version bytes until point start offset try { stream->getBytes((U8*)buffer, version); } catch(...) { fprintf(stderr,"ERROR: reading %d bytes until point start offset from QFIT header\n", version); return FALSE; } // read point start offset try { if (little_endian) stream->get32bitsLE((U8*)&offset); else stream->get32bitsBE((U8*)&offset); } catch(...) { fprintf(stderr,"ERROR: reading point start offset from QFIT header\n"); return FALSE; } // seek to end of file find out number of points stream->seekEnd(); npoints = (stream->tell() - offset) / version; // seek back to start of points stream->seek(offset); // populate the header as much as possible sprintf(header.system_identifier, "LAStools (c) by Martin Isenburg"); sprintf(header.generating_software, "via LASreaderQFIT (%d)", LAS_TOOLS_VERSION); header.number_of_point_records = (U32)npoints; header.number_of_points_by_return[0] = header.number_of_point_records; header.extended_number_of_point_records = npoints; header.extended_number_of_points_by_return[0] = npoints; header.x_scale_factor = 0.000001; header.y_scale_factor = 0.000001; header.z_scale_factor = 0.001; header.x_offset = 0; header.y_offset = 0; header.z_offset = 0; try { LASattribute scan_azimuth(LAS_ATTRIBUTE_I32, "scan azimuth", "Scan Azimuth (degrees X 1,000)"); scan_azimuth.set_scale(0.001); scan_azimuth.set_min(0); scan_azimuth.set_max(360000); header.add_extra_attribute(scan_azimuth); } catch(...) { fprintf(stderr,"ERROR: initializing attribute scan_azimuth\n"); return FALSE; } try { LASattribute pitch(LAS_ATTRIBUTE_I32, "pitch", "Pitch (degrees X 1,000)"); pitch.set_scale(0.001); pitch.set_min(-90000); pitch.set_max(90000); header.add_extra_attribute(pitch); } catch(...) { fprintf(stderr,"ERROR: initializing attribute pitch\n"); return FALSE; } try { LASattribute roll(LAS_ATTRIBUTE_I32, "roll", "Roll (degrees X 1,000)"); roll.set_scale(0.001); roll.set_min(-90000); roll.set_max(90000); header.add_extra_attribute(roll); } catch(...) { fprintf(stderr,"ERROR: initializing attribute roll\n"); return FALSE; } if (version == 48) { try { LASattribute pulse_width(LAS_ATTRIBUTE_U8, "pulse width", "Pulse Width (digitizer samples)"); header.add_extra_attribute(pulse_width); } catch(...) { fprintf(stderr,"ERROR: initializing attribute pulse width\n"); return FALSE; } } header.update_extra_bytes_vlr(); // set point type header.point_data_format = 1; header.point_data_record_length = 28 + header.get_total_extra_attributes_size(); // initialize point point.init(&header, header.point_data_format, header.point_data_record_length, &header); // initialize extra attribute offsets scan_azimuth_array_offset = point.attributer->get_extra_attribute_array_offset("scan azimuth"); pitch_array_offset = point.attributer->get_extra_attribute_array_offset("pitch"); roll_array_offset = point.attributer->get_extra_attribute_array_offset("roll"); if (version == 48) { pulse_width_array_offset = point.attributer->get_extra_attribute_array_offset("pulse width"); } // set point count to zero p_count = 0; // approximate bounding box init populated_header = FALSE; if (!read_point()) return FALSE; header.min_x = header.max_x = point.get_x(); header.min_y = header.max_y = point.get_y(); header.min_z = header.max_z = point.get_z(); for (i = header.number_of_point_records/50; i < header.number_of_point_records; i += header.number_of_point_records/50) { if (!seek(i)) return FALSE; if (!read_point()) return FALSE; } return seek(0); }