Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Oct 28, 2024
1 parent 7d4bc16 commit 870147f
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 1,210 deletions.
5 changes: 3 additions & 2 deletions code/CLI_Example_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ int main(int argc, char **argv)
std::cout << "loading input footprint data from file: " << input_footprint_file << std::endl;
const vec3& offset = pset->offset();
/// ToDo: in this demo the Z coordinate of the footprint/ground is set to the min_Z of the point cloud.
/// This is not optimal. In practice, the Z coordinate of each building should be determined
/// by extracting local ground planes, or directly from available DTM or DSM data.
/// This is not optimal (at least noise, outliers, and incompleteness not considered).
/// In practice, the Z coordinate of each building should be determined by extracting local ground planes,
/// or directly from available DTM or DSM data.
Map *footprint = MapIO::read(input_footprint_file, vec3(offset.x, offset.y, -pset->bbox().z_min()));
if (!footprint) {
std::cerr << "failed loading footprint data from file: " << input_footprint_file << std::endl;
Expand Down
7 changes: 4 additions & 3 deletions code/City3D/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,10 @@ bool MainWindow::doOpen(const QString &fileName)
return false;
}

/// ToDo: currently the Z coordinate of the footprint/ground is set to the min_Z of the point cloud.
/// This is not optimal. In practice, the Z coordinate of each building should be determined
/// by extracting local ground planes, or directly from available DTM or DSM data.
/// ToDo: in this demo the Z coordinate of the footprint/ground is set to the min_Z of the point cloud.
/// This is not optimal (at least noise, outliers, and incompleteness not considered).
/// In practice, the Z coordinate of each building should be determined by extracting local ground planes,
/// or directly from available DTM or DSM data.
const vec3& offset = pset->offset();
footprint = MapIO::read(name, vec3(offset.x, offset.y, -pset->bbox().z_min()));
if (footprint) {
Expand Down
80 changes: 40 additions & 40 deletions code/City3D/paint_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ PaintCanvas::PaintCanvas(QWidget *parent, QGLFormat format)
, coord_system_region_size_(150)
, show_coord_sys_(true)
, point_set_(nil)
, foot_print_(nil)
, footprint_(nil)
, reconstruction_(nil)
, show_point_set_(true)
, show_foot_print_(true)
, show_footprint_(true)
, show_reconstruction_(true)
{
setFPSIsDisplayed(true);
Expand Down Expand Up @@ -96,8 +96,8 @@ void PaintCanvas::clear() {
if (point_set_)
point_set_.forget();

if (foot_print_)
foot_print_.forget();
if (footprint_)
footprint_.forget();

if (reconstruction_)
reconstruction_.forget();
Expand Down Expand Up @@ -214,7 +214,7 @@ void PaintCanvas::draw() {
if (point_set_ && show_point_set_ && point_set_render_)
point_set_render_->draw(point_set_);

if (reconstruction_ || foot_print_) {
if (reconstruction_ || footprint_) {
glEnable(GL_LIGHTING);
Tessellator::draw();

Expand Down Expand Up @@ -407,22 +407,22 @@ vec3 PaintCanvas::unProjectionOf(double winx, double winy, double winz) { // sc

void PaintCanvas::setFootPrint(Map* mesh) {
bool scene_changed = false;
if (foot_print_ || mesh == nil) {
Tessellator::remove_mesh(foot_print_);
MeshRender::remove_mesh(foot_print_);
foot_print_.forget();
if (footprint_ || mesh == nil) {
Tessellator::remove_mesh(footprint_);
MeshRender::remove_mesh(footprint_);
footprint_.forget();
scene_changed = true;
}

if (mesh) {
foot_print_ = mesh;
footprint_ = mesh;

MapFacetAttribute<Color> color(foot_print_, "color");
FOR_EACH_FACET(Map, foot_print_, it)
MapFacetAttribute<Color> color(footprint_, "color");
FOR_EACH_FACET(Map, footprint_, it)
color[it] = random_color();

Tessellator::add_mesh(foot_print_);
MeshRender::add_mesh(foot_print_);
Tessellator::add_mesh(footprint_);
MeshRender::add_mesh(footprint_);
scene_changed = true;
}

Expand Down Expand Up @@ -462,10 +462,10 @@ void PaintCanvas::setPointSet(PointSet* pset) {

if (pset) {
point_set_ = pset;
if (foot_print_) {
Tessellator::remove_mesh(foot_print_);
MeshRender::remove_mesh(foot_print_);
foot_print_.forget();
if (footprint_) {
Tessellator::remove_mesh(footprint_);
MeshRender::remove_mesh(footprint_);
footprint_.forget();
Tessellator::invalidate();
MeshRender::invalidate();
}
Expand All @@ -481,7 +481,7 @@ void PaintCanvas::setPointSet(PointSet* pset) {


Map* PaintCanvas::footPrint() const {
return foot_print_;
return footprint_;
}

Map* PaintCanvas::reconstruction() const {
Expand Down Expand Up @@ -509,14 +509,14 @@ void PaintCanvas::setProjectionMode(bool b) {

void PaintCanvas::setShowFootPrint(bool b) {
if (b) {
Tessellator::add_mesh(foot_print_);
MeshRender::add_mesh(foot_print_);
show_foot_print_ = true;
Tessellator::add_mesh(footprint_);
MeshRender::add_mesh(footprint_);
show_footprint_ = true;
}
else {
Tessellator::remove_mesh(foot_print_);
MeshRender::remove_mesh(foot_print_);
show_foot_print_ = false;
Tessellator::remove_mesh(footprint_);
MeshRender::remove_mesh(footprint_);
show_footprint_ = false;
}

Tessellator::invalidate();
Expand Down Expand Up @@ -649,27 +649,27 @@ void PaintCanvas::estimateNormals() {
void PaintCanvas::segmentation() {
main_window_->updateWeights();
Reconstruction recon;
if (!foot_print_) {
if (!footprint_) {
if (main_window_->want_footprint()) {
auto foot_print = recon.generate_footprint(point_set_);
setFootPrint(foot_print);
auto footprint = recon.generate_footprint(point_set_);
setFootPrint(footprint);
}
else
return;
}

if (foot_print_) {
recon.segmentation(point_set_, foot_print_);
if (footprint_) {
recon.segmentation(point_set_, footprint_);
main_window_->wgtRender_->checkBoxPointSet->setChecked(false);

// foot_print may have been simplified in segmentation, so update the viewer
Tessellator::remove_mesh(foot_print_);
MeshRender::remove_mesh(foot_print_);
MapFacetAttribute<Color> color(foot_print_, "color");
FOR_EACH_FACET(Map, foot_print_, it)
// footprint may have been simplified in segmentation, so update the viewer
Tessellator::remove_mesh(footprint_);
MeshRender::remove_mesh(footprint_);
MapFacetAttribute<Color> color(footprint_, "color");
FOR_EACH_FACET(Map, footprint_, it)
color[it] = random_color();
Tessellator::add_mesh(foot_print_);
MeshRender::add_mesh(foot_print_);
Tessellator::add_mesh(footprint_);
MeshRender::add_mesh(footprint_);
Tessellator::invalidate();
MeshRender::invalidate();
}
Expand All @@ -686,7 +686,7 @@ void PaintCanvas::segmentation() {
void PaintCanvas::extractRoofs() {
main_window_->updateWeights();
Reconstruction recon;
auto status = recon.extract_roofs(point_set_, foot_print_);
auto status = recon.extract_roofs(point_set_, footprint_);
main_window_->wgtRender_->checkBoxPointSet->setChecked(!status);
main_window_->wgtRender_->checkBoxSegments->setChecked(true);
main_window_->checkBoxShowReconstruction->setChecked(false);
Expand All @@ -695,7 +695,7 @@ void PaintCanvas::extractRoofs() {


void PaintCanvas::reconstruct() {
if (!foot_print_) {
if (!footprint_) {
Logger::warn("-") << "footprint does not exist. You must either load it or generate it by clicking the 'Segmentation' button" << std::endl;
return;
}
Expand All @@ -704,7 +704,7 @@ void PaintCanvas::reconstruct() {
main_window_->updateWeights();
Reconstruction recon;

bool status = recon.reconstruct(point_set_, foot_print_, reconstruction_, main_window_->active_solver(), show_reconstruction_);
bool status = recon.reconstruct(point_set_, footprint_, reconstruction_, main_window_->active_solver(), show_reconstruction_);
if (!status)
setReconstruction(nil);

Expand Down
4 changes: 2 additions & 2 deletions code/City3D/paint_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ private :
int coord_system_region_size_;
bool show_coord_sys_;

Map::Ptr foot_print_;
Map::Ptr footprint_;
Map::Ptr reconstruction_;
PointSet::Ptr point_set_;

bool show_point_set_;
PointSetRender* point_set_render_;

bool show_foot_print_;
bool show_footprint_;
bool show_reconstruction_;
};

Expand Down
6 changes: 3 additions & 3 deletions code/method/alpha_shape_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Map* AlphaShapeMesh::apply(AlphaShape* as, const Plane3d& plane, double radius)
}

if (faces.empty())
return nil;
return nullptr;

Map* mesh = new Map;
MapBuilder builder(mesh);
Expand Down Expand Up @@ -94,7 +94,7 @@ Map* AlphaShapeMesh::apply(AlphaShape* as, const Plane3d& plane, double radius)
Map* AlphaShapeMesh::apply(const VertexGroup* g, double radius) {
const PointSet* pset = g->point_set();
if (!pset)
return nil;
return nullptr;

std::size_t num_input = g->size();
const std::vector<vec3>& points = pset->points();
Expand All @@ -118,7 +118,7 @@ Map* AlphaShapeMesh::apply(const VertexGroup* g, double radius) {
Map* AlphaShapeMesh::apply(const PointSet* pset, const std::vector<unsigned int>& point_indices, const Plane3d& plane, double radius) {
if (point_indices.size() < 10) {
//Logger::out("-") << "very few points - no need to compute AlphaShapeMesh" << std::endl;
return nil;
return nullptr;
}

const std::vector<vec3>& points = pset->points();
Expand Down
6 changes: 3 additions & 3 deletions code/method/face_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class FaceSelection

// optimization using the requested solver
// return false if failed or error occurred.
bool optimize(PolyFitInfo* polyfit_info, Map::Facet* foot_print, std::vector<Plane3d*>& v, LinearProgramSolver::SolverName solver_name);
bool optimize(PolyFitInfo* polyfit_info, Map::Facet* footprint, std::vector<Plane3d*>& v, LinearProgramSolver::SolverName solver_name);

private:
std::vector<std::vector<Map::Facet*> > find_multi_roofs(Map* mesh, Map::Facet* foot_print, std::vector<Plane3d*>& v);
std::vector<Map::Facet*> overlapping_faces(Map::Facet* f, const std::vector<Map::Facet*>& faces, Map::Facet* foot_print);
std::vector<std::vector<Map::Facet*> > find_multi_roofs(Map* mesh, Map::Facet* footprint, std::vector<Plane3d*>& v);
std::vector<Map::Facet*> overlapping_faces(Map::Facet* f, const std::vector<Map::Facet*>& faces, Map::Facet* footprint);

private:
PointSet* pset_;
Expand Down
12 changes: 6 additions & 6 deletions code/method/face_selection_optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

std::vector<Map::Facet*> FaceSelection::overlapping_faces(Map::Facet* f,
const std::vector<Map::Facet*>& faces,
Map::Facet* foot_print)
Map::Facet* footprint)
{
vec3 c(0, 0, 0);
int degree = 0;
Expand All @@ -43,7 +43,7 @@ std::vector<Map::Facet*> FaceSelection::overlapping_faces(Map::Facet* f,
}
c /= degree;

const Plane3d& plane = Geom::facet_plane(foot_print);
const Plane3d& plane = Geom::facet_plane(footprint);
c = plane.projection(c);
const vec2& p = plane.to_2d(c);

Expand Down Expand Up @@ -72,7 +72,7 @@ std::vector<Map::Facet*> FaceSelection::overlapping_faces(Map::Facet* f,
}

std::vector<std::vector<Map::Facet*> > FaceSelection::find_multi_roofs(Map* mesh,
Map::Facet* foot_print,
Map::Facet* footprint,
std::vector<Plane3d*>& v)
{
facet_attrib_supporting_plane_.bind_if_defined(model_, "FacetSupportingPlane");
Expand All @@ -94,15 +94,15 @@ std::vector<std::vector<Map::Facet*> > FaceSelection::find_multi_roofs(Map* mesh
for (std::size_t i = 0; i < faces.size(); ++i)
{
Map::Facet* ft = faces[i];
const std::vector<Map::Facet*>& roofs = overlapping_faces(ft, faces, foot_print);
const std::vector<Map::Facet*>& roofs = overlapping_faces(ft, faces, footprint);
if (roofs.size() > 1)
multiple_roofs.push_back(roofs);
}
return multiple_roofs;
}

bool FaceSelection::optimize(PolyFitInfo* polyfit_info,
Map::Facet* foot_print,
Map::Facet* footprint,
std::vector<Plane3d*>& v, LinearProgramSolver::SolverName solver_name)
{
if (pset_ == 0 || model_ == 0)
Expand Down Expand Up @@ -358,7 +358,7 @@ bool FaceSelection::optimize(PolyFitInfo* polyfit_info,
}

// Add constraints: single-roof
const std::vector<std::vector<Map::Facet*> >& multiple_roofs = find_multi_roofs(model_, foot_print, v);
const std::vector<std::vector<Map::Facet*> >& multiple_roofs = find_multi_roofs(model_, footprint, v);
std::set<std::vector<int>> multi_roof_set;
for (std::size_t i = 0; i < multiple_roofs.size(); ++i)
{
Expand Down
Loading

0 comments on commit 870147f

Please sign in to comment.