From 3ea678d2ab8394242f4eb56f9128a6676c76cd76 Mon Sep 17 00:00:00 2001 From: Zhivko Bogdanov Date: Tue, 26 Oct 2021 19:51:31 +0200 Subject: [PATCH 1/2] Fixed output from `generateGridVertices`. After changes from pull request #45 initialization with a grid no longer worked and the file didn't compile at all. --- CDT/extras/InitializeWithGrid.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/CDT/extras/InitializeWithGrid.h b/CDT/extras/InitializeWithGrid.h index 559d358a..d80ec013 100644 --- a/CDT/extras/InitializeWithGrid.h +++ b/CDT/extras/InitializeWithGrid.h @@ -35,9 +35,10 @@ namespace detail * @param yfirst beginning of Y-ticks range * @param ylast end of Y-ticks range */ -template +template void generateGridVertices( - OutputIt outFirst, + OutVertIt outVert, + OutTriIt outTri, const TXCoordIter xfirst, const TXCoordIter xlast, const TYCoordIter yfirst, @@ -53,33 +54,33 @@ void generateGridVertices( TXCoordIter xiter = xfirst; for(std::size_t ix = 0; xiter != xlast; ++xiter, ++ix) { - Vertex v; - v.pos = V2d::make(*xiter, *yiter); - const std::size_t i = iy * xres + ix; + std::vector ind; + ind.reserve(6); // left-up if(ix > 0 && iy < yres) { - v.triangles.push_back(2 * (i - 1)); - v.triangles.push_back(2 * (i - 1) + 1); + ind.push_back(2 * (i - 1)); + ind.push_back(2 * (i - 1) + 1); } // right-up if(ix < xres && iy < yres) { - v.triangles.push_back(2 * i); + ind.push_back(2 * i); } // left-down if(ix > 0 && iy > 0) { - v.triangles.push_back(2 * (i - xres - 1) + 1); + ind.push_back(2 * (i - xres - 1) + 1); } // right-down if(ix < xres && iy > 0) { - v.triangles.push_back(2 * (i - xres)); - v.triangles.push_back(2 * (i - xres) + 1); + ind.push_back(2 * (i - xres)); + ind.push_back(2 * (i - xres) + 1); } - *outFirst++ = v; + *outVert++ = V2d::make(*xiter, *yiter); + *outTri++ = std::move(ind); } } } @@ -196,8 +197,9 @@ void initializeWithIrregularGrid( const std::size_t yres = std::distance(yfirst, ylast) - 1; out.triangles.reserve(xres * yres * 2); out.vertices.reserve((xres + 1) * (yres + 1)); + out.vertTris.reserve((xres + 1) * (yres + 1)); detail::generateGridVertices( - std::back_inserter(out.vertices), xfirst, xlast, yfirst, ylast); + std::back_inserter(out.vertices), std::back_inserter(out.vertTris), xfirst, xlast, yfirst, ylast); detail::generateGridTriangles( std::back_inserter(out.triangles), xres, yres); out.initializedWithCustomSuperGeometry(); From 86be401abfcfa79bc1a77db561d1a69ab72590a0 Mon Sep 17 00:00:00 2001 From: artem-ogre Date: Tue, 26 Oct 2021 21:00:06 +0200 Subject: [PATCH 2/2] Fix InitializeWithGrid and VerifyTopology after CDT re-factoring Add instantiations to CDT.cpp to avoid such problems in the future --- CDT/extras/InitializeWithGrid.h | 52 ++++++++++++++++++++------------- CDT/extras/VerifyTopology.h | 3 +- CDT/src/CDT.cpp | 22 ++++++++++++++ 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/CDT/extras/InitializeWithGrid.h b/CDT/extras/InitializeWithGrid.h index d80ec013..ec536cec 100644 --- a/CDT/extras/InitializeWithGrid.h +++ b/CDT/extras/InitializeWithGrid.h @@ -26,7 +26,8 @@ namespace detail /** * Generate grid vertices given of X- and Y-ticks * - * @tparam OutputIt output iterator + * @tparam OutputVertIt output vertices iterator + * @tparam OutputTriIt output triangles iterator * @tparam TXCoordIter iterator dereferencing to X coordinate * @tparam TYCoordIter iterator dereferencing to Y coordinate * @param outFirst the beginning of the destination range @@ -35,10 +36,14 @@ namespace detail * @param yfirst beginning of Y-ticks range * @param ylast end of Y-ticks range */ -template +template < + typename OutputVertIt, + typename OutputTriIt, + typename TXCoordIter, + typename TYCoordIter> void generateGridVertices( - OutVertIt outVert, - OutTriIt outTri, + OutputVertIt outVertsFirst, + OutputTriIt outTrisFirst, const TXCoordIter xfirst, const TXCoordIter xlast, const TYCoordIter yfirst, @@ -54,33 +59,33 @@ void generateGridVertices( TXCoordIter xiter = xfirst; for(std::size_t ix = 0; xiter != xlast; ++xiter, ++ix) { + *outVertsFirst++ = V2d::make(*xiter, *yiter); const std::size_t i = iy * xres + ix; - std::vector ind; - ind.reserve(6); + TriIndVec vTris; + vTris.reserve(6); // left-up if(ix > 0 && iy < yres) { - ind.push_back(2 * (i - 1)); - ind.push_back(2 * (i - 1) + 1); + vTris.push_back(2 * (i - 1)); + vTris.push_back(2 * (i - 1) + 1); } // right-up if(ix < xres && iy < yres) { - ind.push_back(2 * i); + vTris.push_back(2 * i); } // left-down if(ix > 0 && iy > 0) { - ind.push_back(2 * (i - xres - 1) + 1); + vTris.push_back(2 * (i - xres - 1) + 1); } // right-down if(ix < xres && iy > 0) { - ind.push_back(2 * (i - xres)); - ind.push_back(2 * (i - xres) + 1); + vTris.push_back(2 * (i - xres)); + vTris.push_back(2 * (i - xres) + 1); } - *outVert++ = V2d::make(*xiter, *yiter); - *outTri++ = std::move(ind); + *outTrisFirst++ = vTris; } } } @@ -96,20 +101,20 @@ void generateGridVertices( template void generateGridTriangles( OutputIt outFirst, - const std::size_t xres, - const std::size_t yres) + const IndexSizeType xres, + const IndexSizeType yres) { - for(std::size_t iy = 0; iy < yres; ++iy) + for(IndexSizeType iy = 0; iy < yres; ++iy) { - for(std::size_t ix = 0; ix < xres; ++ix) + for(IndexSizeType ix = 0; ix < xres; ++ix) { // 2___3 v3 // |\ | /\ // | \ | n3/ \n2 // |__\| /____\ // 0 1 v1 n1 v2 - const std::size_t i = iy * xres + ix; - const std::size_t iv = iy * (xres + 1) + ix; + const IndexSizeType i = iy * xres + ix; + const IndexSizeType iv = iy * (xres + 1) + ix; const VertInd vv[4] = {iv, iv + 1, iv + xres + 1, iv + xres + 2}; Triangle t; @@ -199,7 +204,12 @@ void initializeWithIrregularGrid( out.vertices.reserve((xres + 1) * (yres + 1)); out.vertTris.reserve((xres + 1) * (yres + 1)); detail::generateGridVertices( - std::back_inserter(out.vertices), std::back_inserter(out.vertTris), xfirst, xlast, yfirst, ylast); + std::back_inserter(out.vertices), + std::back_inserter(out.vertTris), + xfirst, + xlast, + yfirst, + ylast); detail::generateGridTriangles( std::back_inserter(out.triangles), xres, yres); out.initializedWithCustomSuperGeometry(); diff --git a/CDT/extras/VerifyTopology.h b/CDT/extras/VerifyTopology.h index 08f1f6fe..f4387033 100644 --- a/CDT/extras/VerifyTopology.h +++ b/CDT/extras/VerifyTopology.h @@ -26,8 +26,9 @@ namespace CDT * - each of triangle's vertices has triangle as adjacent * * @tparam T type of vertex coordinates (e.g., float, double) + * @tparam TNearPointLocator class providing locating near point for efficiently */ -template +template > inline bool verifyTopology(const CDT::Triangulation& cdt) { // Check if vertices' adjacent triangles contain vertex diff --git a/CDT/src/CDT.cpp b/CDT/src/CDT.cpp index 53480577..f0c8f40a 100644 --- a/CDT/src/CDT.cpp +++ b/CDT/src/CDT.cpp @@ -15,6 +15,8 @@ #include "CDT.hpp" #include "CDTUtils.hpp" +#include "InitializeWithGrid.h" +#include "VerifyTopology.h" namespace CDT { @@ -39,6 +41,26 @@ template DuplicatesInfo RemoveDuplicatesAndRemapEdges( std::vector >&, std::vector&); +template bool verifyTopology(const CDT::Triangulation&); +template bool verifyTopology(const CDT::Triangulation&); + +template void initializeWithRegularGrid( + float, + float, + float, + float, + std::size_t, + std::size_t, + Triangulation&); +template void initializeWithRegularGrid( + double, + double, + double, + double, + std::size_t, + std::size_t, + Triangulation&); + } // namespace CDT #endif