Skip to content

Commit

Permalink
core: fix dome roof is not created correctly if there is more than on…
Browse files Browse the repository at this point in the history
…e outer polygon

Apply the same logic for cylinder facade builder as well
  • Loading branch information
reinterpretcat committed Jun 3, 2016
1 parent 7105fa6 commit cd55afd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
24 changes: 13 additions & 11 deletions core/src/builders/buildings/facades/CylinderFacadeBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ class CylinderFacadeBuilder : public FacadeBuilder

void build(utymap::meshing::Polygon& polygon)
{
utymap::meshing::Vector2 center2d;
double radius;
utymap::utils::getCircle(polygon.rectangle, center2d, radius);
utymap::utils::outerRectangles(polygon, [&](const utymap::meshing::Rectangle& rectangle) {
utymap::meshing::Vector2 center2d;
double radius;
utymap::utils::getCircle(rectangle, center2d, radius);

CylinderGenerator cylinderGenerator(builderContext_, meshContext_, FacadeColorKey);
cylinderGenerator
.setCenter(utymap::meshing::Vector3(center2d.x, minHeight_, center2d.y))
.setHeight(height_)
.setMaxSegmentHeight(5)
.setRadialSegments(7)
.setRadius(radius)
.generate();
CylinderGenerator cylinderGenerator(builderContext_, meshContext_, FacadeColorKey);
cylinderGenerator
.setCenter(utymap::meshing::Vector3(center2d.x, minHeight_, center2d.y))
.setHeight(height_)
.setMaxSegmentHeight(5)
.setRadialSegments(7)
.setRadius(radius)
.generate();
});
}
};

Expand Down
2 changes: 1 addition & 1 deletion core/src/builders/buildings/facades/FlatFacadeBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FlatFacadeBuilder : public FacadeBuilder
std::int64_t last = range.second - 2;
for (std::int64_t i = last; i >= first; i -= 2) {
utymap::meshing::Vector2 p1(polygon.points[i], polygon.points[i + 1]);
int j = i == first ? last : i - 2;
auto j = i == first ? last : i - 2;
utymap::meshing::Vector2 p2(polygon.points[j], polygon.points[j + 1]);

builderContext_.meshBuilder.addPlane(meshContext_.mesh,
Expand Down
37 changes: 18 additions & 19 deletions core/src/builders/buildings/roofs/DomeRoofBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@ class DomeRoofBuilder : public RoofBuilder

void build(utymap::meshing::Polygon& polygon)
{
utymap::meshing::Vector2 center2d;
double radius;
utymap::utils::getCircle(polygon.rectangle, center2d, radius);

double heightInMeters = utymap::utils::GeoUtils::distance(
utymap::GeoCoordinate(center2d.y, center2d.x),
utymap::GeoCoordinate(center2d.y + radius, center2d.x));

utymap::builders::IcoSphereGenerator generator(builderContext_, meshContext_, RoofColorKey);
generator
.setCenter(utymap::meshing::Vector3(center2d.x, minHeight_, center2d.y))
.setRadius(radius, heightInMeters)
.setRecursionLevel(2)
.isSemiSphere(true)
.setVertexNoiseFreq(0.0)
.generate();
utymap::utils::outerRectangles(polygon, [&](const utymap::meshing::Rectangle& rectangle) {
utymap::meshing::Vector2 center2d;
double radius;
utymap::utils::getCircle(rectangle, center2d, radius);

double heightInMeters = utymap::utils::GeoUtils::distance(
utymap::GeoCoordinate(center2d.y, center2d.x),
utymap::GeoCoordinate(center2d.y + radius, center2d.x));

utymap::builders::IcoSphereGenerator generator(builderContext_, meshContext_, RoofColorKey);
generator
.setCenter(utymap::meshing::Vector3(center2d.x, minHeight_, center2d.y))
.setRadius(radius, heightInMeters)
.setRecursionLevel(2)
.isSemiSphere(true)
.setVertexNoiseFreq(0.0)
.generate();
});
}

private:

};

}}
Expand Down
17 changes: 17 additions & 0 deletions core/src/utils/GeometryUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ namespace utymap { namespace utils {
return utymap::meshing::Vector2(centroidX, centroidY);
}

// Iterates through polygon outers and call visitor with rectangle of this outer
template <typename Visitor>
inline void outerRectangles(const utymap::meshing::Polygon& polygon, Visitor& visitor)
{
if (polygon.outers.size() == 1) {
visitor(polygon.rectangle);
return;
}

for (const auto& outer : polygon.outers) {
auto rectangle = utymap::meshing::Rectangle();
for (auto i = outer.first; i < outer.second; i += 2) {
rectangle.expand(utymap::meshing::Vector2(polygon.points[i], polygon.points[i + 1]));
}
visitor(rectangle);
}
}
}}

#endif // UTILS_GEOMETRYUTILS_HPP_DEFINED

0 comments on commit cd55afd

Please sign in to comment.