From 7a0b05778b4c785a9e3ef592cb389736c528a1d1 Mon Sep 17 00:00:00 2001 From: artem-ogre Date: Tue, 26 Oct 2021 20:32:57 +0200 Subject: [PATCH] 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, 56 insertions(+), 21 deletions(-) diff --git a/CDT/extras/InitializeWithGrid.h b/CDT/extras/InitializeWithGrid.h index 559d358a..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,9 +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( - OutputIt outFirst, + OutputVertIt outVertsFirst, + OutputTriIt outTrisFirst, const TXCoordIter xfirst, const TXCoordIter xlast, const TYCoordIter yfirst, @@ -53,33 +59,33 @@ void generateGridVertices( TXCoordIter xiter = xfirst; for(std::size_t ix = 0; xiter != xlast; ++xiter, ++ix) { - Vertex v; - v.pos = V2d::make(*xiter, *yiter); - + *outVertsFirst++ = V2d::make(*xiter, *yiter); const std::size_t i = iy * xres + ix; + TriIndVec vTris; + vTris.reserve(6); // left-up if(ix > 0 && iy < yres) { - v.triangles.push_back(2 * (i - 1)); - v.triangles.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) { - v.triangles.push_back(2 * i); + vTris.push_back(2 * i); } // left-down if(ix > 0 && iy > 0) { - v.triangles.push_back(2 * (i - xres - 1) + 1); + vTris.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); + vTris.push_back(2 * (i - xres)); + vTris.push_back(2 * (i - xres) + 1); } - *outFirst++ = v; + *outTrisFirst++ = vTris; } } } @@ -95,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; @@ -196,8 +202,14 @@ 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(); 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