Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/point-in-polygon'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Commandeur committed Apr 3, 2017
2 parents 8fc18a1 + 00a8912 commit a69c320
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::string Bridge::get_mtl() {
return "usemtl Bridge";
}

bool Bridge::add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool Bridge::add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
if (lastreturn == true && lasclass != LAS_BUILDING && lasclass != LAS_WATER) {
Flat::add_elevation_point(p, z, radius, lasclass, lastreturn);
}
Expand Down
2 changes: 1 addition & 1 deletion Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Bridge: public Flat {
Bridge(char *wkt, std::string layername, std::vector<std::tuple<std::string, OGRFieldType, std::string>> attributes, std::string pid, float heightref);

bool lift();
bool add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn);
bool add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn);
std::string get_citygml();
std::string get_citygml_imgeo();
std::string get_mtl();
Expand Down
4 changes: 2 additions & 2 deletions Building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ bool Building::lift() {
return true;
}

bool Building::add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool Building::add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
if (lastreturn) {
if (bg::distance(p, *(_p2)) <= radius) {
if (within_range(p, *(_p2), radius)) {
int zcm = int(z * 100);
//-- 1. Save the ground points seperate for base height
if (lasclass == LAS_GROUND || lasclass == LAS_WATER) {
Expand Down
2 changes: 1 addition & 1 deletion Building.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Building: public Flat {
public:
Building(char *wkt, std::string layername, std::vector<std::tuple<std::string, OGRFieldType, std::string>> attributes, std::string pid, float heightref_top, float heightref_base);
bool lift();
bool add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn);
bool add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn);
std::string get_obj(std::unordered_map< std::string, unsigned long > &dPts, int lod, std::string mtl);
std::string get_citygml();
std::string get_citygml_imgeo();
Expand Down
2 changes: 1 addition & 1 deletion Forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::string Forest::get_mtl() {
return "usemtl Forest";
}

bool Forest::add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool Forest::add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool toadd = false;
if (lastreturn && ((_use_ground_points_only && lasclass == LAS_GROUND) || (_use_ground_points_only == false && lasclass != LAS_BUILDING))) {
toadd = TIN::add_elevation_point(p, z, radius, lasclass, lastreturn);
Expand Down
2 changes: 1 addition & 1 deletion Forest.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Forest: public TIN {
public:
Forest(char *wkt, std::string layername, std::vector<std::tuple<std::string, OGRFieldType, std::string>> attributes, std::string pid, int simplification, float innerbuffer, bool only_ground_points);
bool lift();
bool add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn);
bool add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn);
std::string get_citygml();
std::string get_citygml_imgeo();
std::string get_mtl();
Expand Down
53 changes: 26 additions & 27 deletions Map3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,12 @@ bool Map3d::get_shapefile(std::string filename) {
OGRLayer *layer = dataSource->CreateLayer("my3dmap", NULL, OGR_GT_SetZ(wkbMultiPolygon), NULL);

OGRFieldDefn oField("Id", OFTString);
if (layer->CreateField(&oField) != OGRERR_NONE)
{
if (layer->CreateField(&oField) != OGRERR_NONE) {
std::cerr << "Creating Id field failed." << std::endl;
return false;
}
OGRFieldDefn oField2("Class", OFTString);
if (layer->CreateField(&oField2) != OGRERR_NONE)
{
if (layer->CreateField(&oField2) != OGRERR_NONE) {
std::cerr << "Creating Class field failed." << std::endl;
return false;
}
Expand Down Expand Up @@ -385,8 +383,7 @@ void Map3d::add_elevation_point(liblas::Point const& laspt) {

for (auto& v : re) {
TopoFeature* f = v.second;
if (f->get_class() == BUILDING)
{
if (f->get_class() == BUILDING) {
radius = _building_radius_vertex_elevation;
}
else {
Expand Down Expand Up @@ -492,13 +489,12 @@ bool Map3d::add_polygons_files(std::vector<PolygonFile> &files) {
#endif

if (dataSource == NULL) {
std::cerr << "\tERROR: could not open file, skipping it." << std::endl;
std::cerr << "\tERROR: could not open file: " + file->filename << std::endl;
return false;
}

// if the file doesn't have layers specified, add all
if (file->layers[0].first.empty())
{
if (file->layers[0].first.empty()) {
std::string lifting = file->layers[0].second;
file->layers.clear();
int numberOfLayers = dataSource->GetLayerCount();
Expand All @@ -515,7 +511,6 @@ bool Map3d::add_polygons_files(std::vector<PolygonFile> &files) {
#endif

if (!wentgood) {
std::cerr << "ERROR: Something went bad while reading input polygons. Aborting." << std::endl;
return false;
}
}
Expand All @@ -538,7 +533,7 @@ bool Map3d::extract_and_add_polygon(GDALDataset* dataSource, PolygonFile* file)
}
if (dataLayer->FindFieldIndex(idfield, false) == -1) {
std::cerr << "ERROR: field '" << idfield << "' not found in layer '" << l.first << "'." << std::endl;
continue;
return false;
}
if (dataLayer->FindFieldIndex(heightfield, false) == -1) {
std::cerr << "ERROR: field '" << heightfield << "' not found in layer '" << l.first << "', using all polygons." << std::endl;
Expand Down Expand Up @@ -570,7 +565,7 @@ bool Map3d::extract_and_add_polygon(GDALDataset* dataSource, PolygonFile* file)
if (useRequestedExtent) {
geometry->getEnvelope(&env);
}

//-- add the polygon of no extent is used or if the envelope is within the extent
if (!useRequestedExtent || envelope.Intersects(env)) {
switch (geometry->getGeometryType()) {
Expand Down Expand Up @@ -666,7 +661,7 @@ bool Map3d::add_las_file(std::string ifile, std::vector<int> lasomits, int skip)
std::ifstream ifs;
ifs.open(ifile.c_str(), std::ios::in | std::ios::binary);
if (ifs.is_open() == false) {
std::cerr << "\tERROR: could not open file, skipping it." << std::endl;
std::cerr << "\tERROR: could not open file: " << ifile << std::endl;
return false;
}
//-- LAS classes to omit (create full list since eExclusion does not work
Expand All @@ -679,7 +674,7 @@ bool Map3d::add_las_file(std::string ifile, std::vector<int> lasomits, int skip)
};
for (int i : lasomits)
liblasomits.erase(std::find(liblasomits.begin(), liblasomits.end(), liblas::Classification(i)));
//-- read each point 1-by-1
//-- read each point 1-by-1
liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs);
liblas::Header const& header = reader.GetHeader();
Expand Down Expand Up @@ -726,18 +721,24 @@ bool Map3d::add_las_file(std::string ifile, std::vector<int> lasomits, int skip)
}
printProgressBar(0);
int i = 0;
while (reader.ReadNextPoint()) {
this->add_elevation_point(reader.GetPoint());
try {
while (reader.ReadNextPoint()) {
this->add_elevation_point(reader.GetPoint());

if (i % (pointCount / 100) == 0)
printProgressBar(100 * (i / double(pointCount)));
i++;
if (i % (pointCount / 100) == 0)
printProgressBar(100 * (i / double(pointCount)));
i++;
}
printProgressBar(100);
std::clog << "done" << std::endl;
}
catch (std::exception e) {
std::cerr << std::endl << e.what() << std::endl;
ifs.close();
return false;
}
printProgressBar(100);
std::clog << "done" << std::endl;
}
else
{
else {
std::clog << "\tskipping file, bounds do not intersect polygon extent" << std::endl;
}
ifs.close();
Expand Down Expand Up @@ -1013,8 +1014,7 @@ void Map3d::stitch_jumpedge(TopoFeature* f1, int ringi1, int pi1, TopoFeature* f
if (f2->get_class() != WATER) {
f2->set_vertex_elevation(ringi2, pi2, dynamic_cast<Building*>(f1)->get_height_base());
}
else
{
else {
//- keep water flat, add the water height to the nc
_nc[key_bucket].push_back(f2z);
}
Expand All @@ -1027,8 +1027,7 @@ void Map3d::stitch_jumpedge(TopoFeature* f1, int ringi1, int pi1, TopoFeature* f
if (f1->get_class() != WATER) {
f1->set_vertex_elevation(ringi1, pi1, dynamic_cast<Building*>(f2)->get_height_base());
}
else
{
else {
//- keep water flat, add the water height to the nc
_nc[key_bucket].push_back(f1z);
}
Expand Down
2 changes: 1 addition & 1 deletion Road.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::string Road::get_mtl() {
return "usemtl Road";
}

bool Road::add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool Road::add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
if (lastreturn == true && lasclass == LAS_GROUND) {
Boundary3D::add_elevation_point(p, z, radius, lasclass, lastreturn);
}
Expand Down
2 changes: 1 addition & 1 deletion Road.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Road: public Boundary3D {
public:
Road(char *wkt, std::string layername, std::vector<std::tuple<std::string, OGRFieldType, std::string>> attributes, std::string pid, float heightref);
bool lift();
bool add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn);
bool add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn);
std::string get_citygml();
std::string get_citygml_imgeo();
std::string get_mtl();
Expand Down
2 changes: 1 addition & 1 deletion Separation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ std::string Separation::get_mtl() {
return "usemtl Separation";
}

bool Separation::add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool Separation::add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
if (lastreturn == true && lasclass != LAS_BUILDING && lasclass != LAS_WATER) {
Boundary3D::add_elevation_point(p, z, radius, lasclass, lastreturn);
}
Expand Down
2 changes: 1 addition & 1 deletion Separation.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Separation: public Boundary3D {
public:
Separation(char *wkt, std::string layername, std::vector<std::tuple<std::string, OGRFieldType, std::string>> attributes, std::string pid, float heightref);
bool lift();
bool add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn);
bool add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn);
std::string get_citygml();
std::string get_citygml_imgeo();
std::string get_mtl();
Expand Down
2 changes: 1 addition & 1 deletion Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::string Terrain::get_mtl() {
return "usemtl Terrain";
}

bool Terrain::add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool Terrain::add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn) {
bool toadd = false;
if (lastreturn && lasclass == LAS_GROUND) {
toadd = TIN::add_elevation_point(p, z, radius, lasclass, lastreturn);
Expand Down
2 changes: 1 addition & 1 deletion Terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Terrain: public TIN {
public:
Terrain(char *wkt, std::string layername, std::vector<std::tuple<std::string, OGRFieldType, std::string>> attributes, std::string pid, int simplification, float innerbuffer);
bool lift();
bool add_elevation_point(Point2 p, double z, float radius, LAS14Class lasclass, bool lastreturn);
bool add_elevation_point(Point2 &p, double z, float radius, LAS14Class lasclass, bool lastreturn);
std::string get_citygml();
std::string get_mtl();
std::string get_citygml_imgeo();
Expand Down
Loading

0 comments on commit a69c320

Please sign in to comment.