Browse Source

MeshTools: remove STL-heavy generateFlatNormals() deprecated in 2019.10.

And also the deprecated GenerateFlatNormals.h header alias.
pull/659/head
Vladimír Vondruš 1 year ago
parent
commit
d7594fd5ef
  1. 4
      doc/changelog.dox
  2. 1
      src/Magnum/MeshTools/CMakeLists.txt
  3. 42
      src/Magnum/MeshTools/GenerateFlatNormals.h
  4. 37
      src/Magnum/MeshTools/GenerateNormals.cpp
  5. 26
      src/Magnum/MeshTools/GenerateNormals.h
  6. 39
      src/Magnum/MeshTools/Test/GenerateNormalsTest.cpp

4
doc/changelog.dox

@ -1769,6 +1769,10 @@ See also:
@relativeref{Math::Frustum,begin()} / @relativeref{Math::Frustum,end()}
instead
- @cpp Math::swizzle() @ce, use @ref Math::gather() instead
- @cpp Magnum/MeshTools/GenerateFlatNormals.h @ce, use
@ref Magnum/MeshTools/GenerateNormals.h instead
- @ref Magnum::MeshTools::generateFlatNormals() overload that used an
excessive amount of STL
- @cpp Text::FontFeature::MultiFile @ce,
@cpp Text::AbstractFont::openData() @ce taking a vector of pairs, and
@cpp openSingleData() @ce, use @ref Text::AbstractFont::openData() and

1
src/Magnum/MeshTools/CMakeLists.txt

@ -80,7 +80,6 @@ if(MAGNUM_BUILD_DEPRECATED)
list(APPEND MagnumMeshTools_HEADERS
CombineIndexedArrays.h
FilterAttributes.h
GenerateFlatNormals.h
Reference.h)
endif()

42
src/Magnum/MeshTools/GenerateFlatNormals.h

@ -1,42 +0,0 @@
#ifndef Magnum_MeshTools_GenerateFlatNormals_h
#define Magnum_MeshTools_GenerateFlatNormals_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023, 2024, 2025
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @m_deprecated_since{2019,10} Use @ref Magnum/MeshTools/GenerateNormals.h instead.
*/
#include "Magnum/configure.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include "Magnum/MeshTools/GenerateNormals.h"
CORRADE_DEPRECATED_FILE("use Magnum/MeshTools/GenerateNormals.h instead")
#else
#error use Magnum/MeshTools/GenerateNormals.h instead
#endif
#endif

37
src/Magnum/MeshTools/GenerateNormals.cpp

@ -33,13 +33,6 @@
#include "Magnum/Math/Functions.h"
#include "Magnum/Math/Vector3.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <vector>
#include "Magnum/MeshTools/Duplicate.h"
#include "Magnum/MeshTools/RemoveDuplicates.h"
#endif
namespace Magnum { namespace MeshTools {
void generateFlatNormalsInto(const Containers::StridedArrayView1D<const Vector3>& positions, const Containers::StridedArrayView1D<Vector3>& normals) {
@ -60,36 +53,6 @@ Containers::Array<Vector3> generateFlatNormals(const Containers::StridedArrayVie
return out;
}
#ifdef MAGNUM_BUILD_DEPRECATED
/* Original implementation kept verbatim as I can't be bothered rewriting it
using the new APIs (the original test is kept as well) */
std::pair<std::vector<UnsignedInt>, std::vector<Vector3>> generateFlatNormals(const std::vector<UnsignedInt>& indices, const std::vector<Vector3>& positions) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", {});
/* Create normal for every triangle (assuming counterclockwise winding) */
std::vector<UnsignedInt> normalIndices;
normalIndices.reserve(indices.size());
std::vector<Vector3> normals;
normals.reserve(indices.size()/3);
for(std::size_t i = 0; i != indices.size(); i += 3) {
const Vector3 normal = Math::cross(positions[indices[i+2]]-positions[indices[i+1]],
positions[indices[i]]-positions[indices[i+1]]).normalized();
/* Use the same normal for all three vertices of the face */
normalIndices.push_back(normals.size());
normalIndices.push_back(normals.size());
normalIndices.push_back(normals.size());
normals.push_back(normal);
}
/* Remove duplicate normals and return */
CORRADE_IGNORE_DEPRECATED_PUSH
normalIndices = duplicate(normalIndices, removeDuplicates(normals));
CORRADE_IGNORE_DEPRECATED_POP
return {Utility::move(normalIndices), Utility::move(normals)};
}
#endif
namespace {
#if defined(CORRADE_TARGET_MSVC) && !defined(CORRADE_MSVC_COMPATIBILITY) && _MSC_VER >= 1920 && _MSC_VER < 1930

26
src/Magnum/MeshTools/GenerateNormals.h

@ -33,12 +33,6 @@
#include "Magnum/Magnum.h"
#include "Magnum/MeshTools/visibility.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <utility> /* std::pair */
#include <Corrade/Utility/StlForwardVector.h>
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace MeshTools {
/**
@ -81,26 +75,6 @@ conversions:
*/
MAGNUM_MESHTOOLS_EXPORT void generateFlatNormalsInto(const Containers::StridedArrayView1D<const Vector3>& positions, const Containers::StridedArrayView1D<Vector3>& normals);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief Generate flat normals
@param indices Triangle face indices
@param positions Triangle vertex positions
@return Normal indices and vectors
All vertices in each triangle face get the same normal vector. Removes
duplicates before returning. Expects that the position count is divisible by 3.
@m_deprecated_since{2019,10} This will generate index buffer that's different
from the input @p indices array, so you'll need to recombine them using
@ref combineIndexedArrays() in order to have a single index array for both
vertices and normals. Because this makes the usage more complex than
strictly necessary, this function is deprecated in favor of
@ref generateFlatNormals(const Containers::StridedArrayView1D<const Vector3>&).
*/
CORRADE_DEPRECATED("use generateFlatNormals(const Containers::StridedArrayView1D<const Vector3>&) instead") std::pair<std::vector<UnsignedInt>, std::vector<Vector3>> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector<UnsignedInt>& indices, const std::vector<Vector3>& positions);
#endif
/**
@brief Generate smooth normals
@param indices Triangle face indices

39
src/Magnum/MeshTools/Test/GenerateNormalsTest.cpp

@ -38,20 +38,12 @@
#include "Magnum/Primitives/Cylinder.h"
#include "Magnum/Trade/MeshData.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <tuple>
#include <vector>
#endif
namespace Magnum { namespace MeshTools { namespace Test { namespace {
struct GenerateNormalsTest: TestSuite::Tester {
explicit GenerateNormalsTest();
void flat();
#ifdef MAGNUM_BUILD_DEPRECATED
void flatDeprecated();
#endif
void flatWrongCount();
void flatIntoWrongSize();
@ -75,9 +67,6 @@ struct GenerateNormalsTest: TestSuite::Tester {
GenerateNormalsTest::GenerateNormalsTest() {
addTests({&GenerateNormalsTest::flat,
#ifdef MAGNUM_BUILD_DEPRECATED
&GenerateNormalsTest::flatDeprecated,
#endif
&GenerateNormalsTest::flatWrongCount,
&GenerateNormalsTest::flatIntoWrongSize,
@ -126,34 +115,6 @@ void GenerateNormalsTest::flat() {
}), TestSuite::Compare::Container);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void GenerateNormalsTest::flatDeprecated() {
/* Two vertices connected by one edge, each wound in another direction */
std::vector<UnsignedInt> indices;
std::vector<Vector3> normals;
CORRADE_IGNORE_DEPRECATED_PUSH
std::tie(indices, normals) = generateFlatNormals({
0, 1, 2,
1, 2, 3
}, {
{-1.0f, 0.0f, 0.0f},
{0.0f, -1.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
{1.0f, 0.0f, 0.0f}
});
CORRADE_IGNORE_DEPRECATED_POP
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{
0, 0, 0,
1, 1, 1
}));
CORRADE_COMPARE(normals, (std::vector<Vector3>{
Vector3::zAxis(),
-Vector3::zAxis()
}));
}
#endif
void GenerateNormalsTest::flatWrongCount() {
CORRADE_SKIP_IF_NO_ASSERT();

Loading…
Cancel
Save