Browse Source

MeshTools: deprecate remaining STL-ridden APIs.

The combineIndexArrays() and combineIndexedArrays() API is replaced with
a more generic combineIndexedAttributes(), and thanks to that we also
don't need STL-based duplicate() and removeDuplicates().
pull/371/head
Vladimír Vondruš 6 years ago
parent
commit
ec02341c84
  1. 6
      doc/changelog-old.dox
  2. 16
      doc/changelog.dox
  3. 18
      doc/snippets/MagnumMeshTools.cpp
  4. 12
      doc/snippets/MagnumShaders.cpp
  5. 8
      src/Magnum/MeshTools/CMakeLists.txt
  6. 4
      src/Magnum/MeshTools/CombineIndexedArrays.cpp
  7. 31
      src/Magnum/MeshTools/CombineIndexedArrays.h
  8. 2
      src/Magnum/MeshTools/CompressIndices.cpp
  9. 14
      src/Magnum/MeshTools/CompressIndices.h
  10. 18
      src/Magnum/MeshTools/Duplicate.h
  11. 2
      src/Magnum/MeshTools/GenerateNormals.cpp
  12. 15
      src/Magnum/MeshTools/RemoveDuplicates.h
  13. 14
      src/Magnum/MeshTools/Subdivide.h
  14. 13
      src/Magnum/MeshTools/Test/CMakeLists.txt
  15. 4
      src/Magnum/MeshTools/Test/CombineIndexedArraysTest.cpp
  16. 11
      src/Magnum/MeshTools/Test/CompressIndicesTest.cpp
  17. 8
      src/Magnum/MeshTools/Test/DuplicateTest.cpp
  18. 8
      src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp
  19. 12
      src/Magnum/MeshTools/Test/SubdivideTest.cpp

6
doc/changelog-old.dox

@ -343,7 +343,7 @@ for a high-level overview.
- @cpp Buffer::invalidateData() @ce, @cpp Buffer::invalidateSubData() @ce and
@cpp Renderer::resetNotificationStrategy() @ce functions are enabled on
OpenGL ES as a no-op
- Added @ref std::vector overload of @ref MeshTools::combineIndexArrays()
- Added @ref std::vector overload of @cpp MeshTools::combineIndexArrays() @ce
for greater runtime-usage flexibility
- @ref Platform::Sdl2Application now defaults to non-resizable window, you
can change the behavior using @ref Platform::Sdl2Application::Configuration::setWindowFlags()
@ -391,9 +391,9 @@ for a high-level overview.
which filled @cpp Mesh @ce and @cpp Buffer @ce directly are deprecated as
they had undesired side-effects in some cases, use the data-returning
versions instead and then configure mesh and buffer manually
- @ref MeshTools::combineIndexedArrays() taking @ref std::tuple is
- @cpp MeshTools::combineIndexedArrays() @ce taking @ref std::tuple is
deprecated, use version taking @ref std::pair instead
- @ref MeshTools::removeDuplicates() taking also list of indices is
- @cpp MeshTools::removeDuplicates() @ce taking also list of indices is
deprecated, use the function in conjunction with @ref MeshTools::duplicate().
See function documentation for more information.
- Parameter-less @cpp Mesh::draw() @ce and @cpp MeshView::draw() @ce are

16
doc/changelog.dox

@ -429,6 +429,17 @@ See also:
@ref MeshTools::flipFaceWindingInPlace() and @ref MeshTools::tipsifyInPlace()
that accept a @ref Corrade::Containers::StridedArrayView instead of a
@ref std::vector and work with 8- and 16-byte index types as well.
- `Magnum/MeshTools/CombineIndexedArrays.h`,
@cpp MeshTools::combineIndexArrays() @ce and
@cpp MeshTools::combineIndexedArrays() @ce are deprecated in favor of a more
flexible @ref MeshTools::combineIndexedAttributes() in the
@ref Magnum/MeshTools/Combine.h header
- @cpp MeshTools::compressIndicesAs() @ce, @cpp MeshTools::duplicate() @ce,
@cpp MeshTools::removeDuplicates() @ce and @cpp MeshTools::subdivide() @ce
operating on a @ref std::vector are deprecated, use the STL-free
@ref MeshTools::compressIndices(), @ref MeshTools::duplicate(),
@ref MeshTools::removeDuplicatesInPlace() and @ref MeshTools::subdivide() /
@ref MeshTools::subdivideInPlace() overloads instead
@subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs
@ -3214,9 +3225,10 @@ a high-level overview.
- Removed deprecated `*Texture::maxLayers()` functions, use
@ref GL::Shader::maxCombinedTextureImageUnits() "Shader::maxCombinedTextureImageUnits()"
instead
- Removed deprecated @ref MeshTools::combineIndexedArrays(),
- Removed deprecated @cpp MeshTools::combineIndexedArrays() @ce,
@ref MeshTools::compressIndices(), @ref MeshTools::interleave() and
@ref MeshTools::removeDuplicates() overloads, use the general ones instead
@cpp MeshTools::removeDuplicates() @ce overloads, use the general ones
instead
- Removed deprecated `Mesh*::set*{Range,Count}()` functions, use
@ref GL::Mesh::setCount() "Mesh*::setCount()" and
@ref GL::MeshView::setIndexRange() "MeshView::setIndexRange()" instead

18
doc/snippets/MagnumMeshTools.cpp

@ -25,7 +25,6 @@
#include "Magnum/Math/Color.h"
#include "Magnum/Math/FunctionsBatch.h"
#include "Magnum/MeshTools/CombineIndexedArrays.h"
#include "Magnum/MeshTools/CompressIndices.h"
#include "Magnum/MeshTools/Duplicate.h"
#include "Magnum/MeshTools/GenerateNormals.h"
@ -34,12 +33,19 @@
#include "Magnum/MeshTools/Transform.h"
#include "Magnum/Trade/MeshData.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#define _MAGNUM_NO_DEPRECATED_COMBINEINDEXEDARRAYS
#include "Magnum/MeshTools/CombineIndexedArrays.h"
#endif
using namespace Magnum;
using namespace Magnum::Math::Literals;
int main() {
#ifdef MAGNUM_BUILD_DEPRECATED
{
CORRADE_IGNORE_DEPRECATED_PUSH
/* [combineIndexedArrays] */
std::vector<UnsignedInt> vertexIndices;
std::vector<Vector3> positions;
@ -53,7 +59,9 @@ std::vector<UnsignedInt> indices = MeshTools::combineIndexedArrays(
std::make_pair(std::cref(normalTextureIndices), std::ref(textureCoordinates))
);
/* [combineIndexedArrays] */
CORRADE_IGNORE_DEPRECATED_POP
}
#endif
{
/* [compressIndices-offset] */
@ -66,13 +74,17 @@ std::pair<Containers::Array<char>, MeshIndexType> result =
/* [compressIndices-offset] */
}
#ifdef MAGNUM_BUILD_DEPRECATED
{
CORRADE_IGNORE_DEPRECATED_PUSH
/* [compressIndicesAs] */
std::vector<UnsignedInt> indices;
Containers::Array<UnsignedShort> indexData =
MeshTools::compressIndicesAs<UnsignedShort>(indices);
/* [compressIndicesAs] */
CORRADE_IGNORE_DEPRECATED_POP
}
#endif
{
/* [generateFlatNormals] */
@ -143,7 +155,9 @@ data = data.prefix(size);
/* [removeDuplicates] */
}
#ifdef MAGNUM_BUILD_DEPRECATED
{
CORRADE_IGNORE_DEPRECATED_PUSH
/* [removeDuplicates-multiple] */
std::vector<Vector3> positions;
std::vector<Vector2> texCoords;
@ -156,7 +170,9 @@ std::vector<UnsignedInt> indices = MeshTools::combineIndexedArrays(
std::make_pair(std::cref(texCoordIndices), std::ref(texCoords))
);
/* [removeDuplicates-multiple] */
CORRADE_IGNORE_DEPRECATED_POP
}
#endif
{
/* [transformVectors] */

12
doc/snippets/MagnumShaders.cpp

@ -290,17 +290,11 @@ mesh.addVertexBuffer(vertexIndices, 0, Shaders::MeshVisualizer::VertexIndex{});
{
/* [MeshVisualizer-usage-no-geom1] */
std::vector<UnsignedInt> indices{
// ...
};
std::vector<Vector3> indexedPositions{
// ...
};
Containers::StridedArrayView1D<const UnsignedInt> indices;
Containers::StridedArrayView1D<const Vector3> indexedPositions;
/* De-indexing the position array */
GL::Buffer vertices;
vertices.setData(MeshTools::duplicate(indices, indexedPositions),
GL::BufferUsage::StaticDraw);
GL::Buffer vertices{MeshTools::duplicate(indices, indexedPositions)};
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{});

8
src/Magnum/MeshTools/CMakeLists.txt

@ -30,7 +30,6 @@ set(MagnumMeshTools_SRCS
# Files compiled with different flags for main library and unit test library
set(MagnumMeshTools_GracefulAssert_SRCS
Combine.cpp
CombineIndexedArrays.cpp
CompressIndices.cpp
Duplicate.cpp
FlipNormals.cpp
@ -40,7 +39,6 @@ set(MagnumMeshTools_GracefulAssert_SRCS
set(MagnumMeshTools_HEADERS
Combine.h
CombineIndexedArrays.h
CompressIndices.h
Duplicate.h
FlipNormals.h
@ -57,7 +55,11 @@ set(MagnumMeshTools_INTERNAL_HEADERS
Implementation/Tipsify.h)
if(BUILD_DEPRECATED)
list(APPEND MagnumMeshTools_HEADERS GenerateFlatNormals.h)
list(APPEND MagnumMeshTools_GracefulAssert_SRCS
CombineIndexedArrays.cpp)
list(APPEND MagnumMeshTools_HEADERS
CombineIndexedArrays.h
GenerateFlatNormals.h)
endif()
if(TARGET_GL)

4
src/Magnum/MeshTools/CombineIndexedArrays.cpp

@ -23,6 +23,8 @@
DEALINGS IN THE SOFTWARE.
*/
#define _MAGNUM_NO_DEPRECATED_COMBINEINDEXEDARRAYS
#include "CombineIndexedArrays.h"
#include <cstring>
@ -56,7 +58,9 @@ std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> interleaveAndCombi
/* Combine them */
std::vector<UnsignedInt> combinedIndices;
CORRADE_IGNORE_DEPRECATED_PUSH
std::tie(combinedIndices, interleavedArrays) = MeshTools::combineIndexArrays(interleavedArrays, stride);
CORRADE_IGNORE_DEPRECATED_POP
return {combinedIndices, interleavedArrays};
}

31
src/Magnum/MeshTools/CombineIndexedArrays.h

@ -25,18 +25,30 @@
DEALINGS IN THE SOFTWARE.
*/
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file
* @brief Function @ref Magnum::MeshTools::combineIndexArrays(), @ref Magnum::MeshTools::combineIndexedArrays()
* @m_deprecated_since_latest Use @ref Magnum/MeshTools/Combine.h and
* @ref Magnum::MeshTools::combineIndexedAttributes() instead.
*/
#endif
#include "Magnum/configure.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <functional>
#include <tuple>
#include <vector>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/Macros.h>
#include "Magnum/Types.h"
#include "Magnum/MeshTools/visibility.h"
#ifndef _MAGNUM_NO_DEPRECATED_COMBINEINDEXEDARRAYS
CORRADE_DEPRECATED_FILE("use Magnum/Trade/MeshData.h and combineIndexedAttributes() instead")
#endif
namespace Magnum { namespace MeshTools {
/**
@ -44,6 +56,7 @@ namespace Magnum { namespace MeshTools {
@param[in,out] arrays Index arrays to combine. These arrays are updated
in-place to contain unique combinations of the original indices.
@return Resulting combined index array
@m_deprecated_since_latest Use @ref combineIndexedAttributes() instead.
Creates new combined index array and updates the original ones with translation
to new ones. For example, when you have position and normal array, each indexed
@ -81,13 +94,17 @@ This function calls @ref combineIndexArrays(const std::vector<UnsignedInt>&, Uns
internally. See also @ref combineIndexedArrays() which does the vertex data
reordering automatically.
*/
MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(const std::vector<std::reference_wrapper<std::vector<UnsignedInt>>>& arrays);
CORRADE_DEPRECATED("use combineIndexedAttributes() instead") MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(const std::vector<std::reference_wrapper<std::vector<UnsignedInt>>>& arrays);
/** @overload */
MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays);
/**
@overload
@m_deprecated_since_latest Use @ref combineIndexedAttributes() instead.
*/
CORRADE_DEPRECATED("use combineIndexedAttributes() instead") MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays);
/**
@brief Combine interleaved index arrays
@m_deprecated_since_latest Use @ref combineIndexedAttributes() instead.
Unlike above, this function takes one interleaved array instead of separate
index arrays. Continuing with the above example, you would call this function
@ -107,7 +124,7 @@ And second pair value is the cleaned up interleaved array:
@see @ref combineIndexedArrays()
*/
MAGNUM_MESHTOOLS_EXPORT std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> combineIndexArrays(const std::vector<UnsignedInt>& interleavedArrays, UnsignedInt stride);
CORRADE_DEPRECATED("use combineIndexedAttributes() instead") MAGNUM_MESHTOOLS_EXPORT std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> combineIndexArrays(const std::vector<UnsignedInt>& interleavedArrays, UnsignedInt stride);
namespace Implementation {
@ -140,6 +157,7 @@ template<class T, class ...U> inline void writeCombinedArrays(UnsignedInt stride
@brief Combine indexed arrays
@param[in,out] indexedArrays Index and attribute arrays
@return Array with resulting indices
@m_deprecated_since_latest Use @ref combineIndexedAttributes() instead.
Creates new combined index array and reorders original attribute arrays so they
can be indexed with the new single index array.
@ -160,7 +178,7 @@ procedure.
/* Implementation note: It's done using tuples because it is more clear which
parameter is index array and which is attribute array, mainly when both are
of the same type. */
template<class ...T> std::vector<UnsignedInt> combineIndexedArrays(const std::pair<const std::vector<UnsignedInt>&, std::vector<T>&>&... indexedArrays) {
template<class ...T> CORRADE_DEPRECATED("use combineIndexedAttributes() instead") std::vector<UnsignedInt> combineIndexedArrays(const std::pair<const std::vector<UnsignedInt>&, std::vector<T>&>&... indexedArrays) {
/* Interleave and combine index arrays */
std::vector<UnsignedInt> combinedIndices;
std::vector<UnsignedInt> interleavedCombinedIndexArrays;
@ -174,5 +192,8 @@ template<class ...T> std::vector<UnsignedInt> combineIndexedArrays(const std::pa
}
}}
#else
#error use functions in Combine.h instead
#endif
#endif

2
src/Magnum/MeshTools/CompressIndices.cpp

@ -178,7 +178,6 @@ std::tuple<Containers::Array<char>, MeshIndexType, UnsignedInt, UnsignedInt> com
std::tie(data, type) = compressIndices(indices, MeshIndexType::UnsignedByte);
return std::make_tuple(std::move(data), type, minmax.first, minmax.second);
}
#endif
template<class T> Containers::Array<T> compressIndicesAs(const std::vector<UnsignedInt>& indices) {
#if !defined(CORRADE_NO_ASSERT) || defined(CORRADE_GRACEFUL_ASSERT)
@ -196,5 +195,6 @@ template<class T> Containers::Array<T> compressIndicesAs(const std::vector<Unsig
template Containers::Array<UnsignedByte> compressIndicesAs(const std::vector<UnsignedInt>&);
template Containers::Array<UnsignedShort> compressIndicesAs(const std::vector<UnsignedInt>&);
template Containers::Array<UnsignedInt> compressIndicesAs(const std::vector<UnsignedInt>&);
#endif
}}

14
src/Magnum/MeshTools/CompressIndices.h

@ -26,12 +26,11 @@
*/
/** @file
* @brief Function @ref Magnum::MeshTools::compressIndices(), @ref Magnum::MeshTools::compressIndicesAs()
* @brief Function @ref Magnum::MeshTools::compressIndices()
*/
#include <utility>
#include <Corrade/Containers/Containers.h>
#include <Corrade/Utility/StlForwardVector.h>
#include "Magnum/Mesh.h"
#include "Magnum/MeshTools/visibility.h"
@ -40,6 +39,7 @@
#ifdef MAGNUM_BUILD_DEPRECATED
#include <tuple>
#include <Corrade/Utility/Macros.h>
#include <Corrade/Utility/StlForwardVector.h>
#endif
namespace Magnum { namespace MeshTools {
@ -178,14 +178,13 @@ sufficient.
Example usage:
@snippet MagnumMeshTools-gl.cpp compressIndices-stl
@see @ref compressIndicesAs()
*/
CORRADE_DEPRECATED("use compressIndices(const Containers::StridedArrayView1D<const UnsignedInt>&, MeshIndexType, Long) instead") MAGNUM_MESHTOOLS_EXPORT std::tuple<Containers::Array<char>, MeshIndexType, UnsignedInt, UnsignedInt> compressIndices(const std::vector<UnsignedInt>& indices);
#endif
/**
@brief Compress vertex indices as given type
@m_deprecated_since_latest Use @ref compressIndices(const Containers::StridedArrayView1D<const UnsignedInt>&, MeshIndexType, Long)
instead.
The type can be either @ref Magnum::UnsignedByte "UnsignedByte",
@ref Magnum::UnsignedShort "UnsignedShort" or @ref Magnum::UnsignedInt "UnsignedInt".
@ -194,16 +193,15 @@ Values in the index array are expected to be representable with given type.
Example usage:
@snippet MagnumMeshTools.cpp compressIndicesAs
@see @ref compressIndices()
*/
template<class T> MAGNUM_MESHTOOLS_EXPORT Containers::Array<T> compressIndicesAs(const std::vector<UnsignedInt>& indices);
template<class T> CORRADE_DEPRECATED("use compressIndices(const Containers::StridedArrayView1D<const UnsignedInt>&, MeshIndexType, Long) instead") MAGNUM_MESHTOOLS_EXPORT Containers::Array<T> compressIndicesAs(const std::vector<UnsignedInt>& indices);
#if defined(CORRADE_TARGET_WINDOWS) && !defined(__MINGW32__)
extern template MAGNUM_MESHTOOLS_EXPORT Containers::Array<UnsignedByte> compressIndicesAs<UnsignedByte>(const std::vector<UnsignedInt>&);
extern template MAGNUM_MESHTOOLS_EXPORT Containers::Array<UnsignedShort> compressIndicesAs<UnsignedShort>(const std::vector<UnsignedInt>&);
extern template MAGNUM_MESHTOOLS_EXPORT Containers::Array<UnsignedInt> compressIndicesAs<UnsignedInt>(const std::vector<UnsignedInt>&);
#endif
#endif
}}

18
src/Magnum/MeshTools/Duplicate.h

@ -29,15 +29,18 @@
* @brief Function @ref Magnum::MeshTools::duplicate(), @ref Magnum::MeshTools::duplicateInto()
*/
#include <vector>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StridedArrayView.h>
#include "Magnum/Magnum.h"
#include "Magnum/MeshTools/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <vector>
#include <Corrade/Containers/ArrayViewStl.h>
#endif
namespace Magnum { namespace MeshTools {
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -56,7 +59,7 @@ indices are in range for the @p data array.
If you want to fill an existing memory (or, for example a @ref std::vector),
use @ref duplicateInto().
@see @ref removeDuplicates(), @ref combineIndexedArrays()
@see @ref removeDuplicatesInPlace(), @ref combineIndexedAttributes()
*/
template<class IndexType, class T> Containers::Array<T> duplicate(const Containers::StridedArrayView1D<const IndexType>& indices, const Containers::StridedArrayView1D<const T>& data) {
Containers::Array<T> out{Containers::NoInit, indices.size()};
@ -64,17 +67,18 @@ template<class IndexType, class T> Containers::Array<T> duplicate(const Containe
return out;
}
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief Duplicate data using given index array
Like @ref duplicate(const Containers::StridedArrayView1D<const IndexType>&, const Containers::StridedArrayView1D<const T>&),
but putting the result into a @ref std::vector.
@m_deprecated_since_latest Use @ref duplicate(const Containers::StridedArrayView1D<const IndexType>&, const Containers::StridedArrayView1D<const T>&)
or @ref duplicateInto() instead.
*/
template<class T> std::vector<T> duplicate(const std::vector<UnsignedInt>& indices, const std::vector<T>& data) {
template<class T> CORRADE_DEPRECATED("use duplicate() taking a StridedArrayView instead") std::vector<T> duplicate(const std::vector<UnsignedInt>& indices, const std::vector<T>& data) {
std::vector<T> out(indices.size());
duplicateInto<UnsignedInt, T>(indices, data, out);
return out;
}
#endif
/**
@brief Duplicate data using an index array into given output array

2
src/Magnum/MeshTools/GenerateNormals.cpp

@ -81,7 +81,9 @@ std::pair<std::vector<UnsignedInt>, std::vector<Vector3>> generateFlatNormals(co
}
/* Remove duplicate normals and return */
CORRADE_IGNORE_DEPRECATED_PUSH
normalIndices = MeshTools::duplicate(normalIndices, MeshTools::removeDuplicates(normals));
CORRADE_IGNORE_DEPRECATED_POP
return {std::move(normalIndices), std::move(normals)};
}
#endif

15
src/Magnum/MeshTools/RemoveDuplicates.h

@ -26,7 +26,7 @@
*/
/** @file
* @brief Function @ref Magnum::MeshTools::removeDuplicatesInPlace(), @ref Magnum::MeshTools::removeDuplicatesIndexedInPlace(), @ref Magnum::MeshTools::removeDuplicates()
* @brief Function @ref Magnum::MeshTools::removeDuplicatesInPlace(), @ref Magnum::MeshTools::removeDuplicatesIndexedInPlace()
*/
#include <limits>
@ -133,11 +133,14 @@ instead.
If you want to remove duplicate data from an already indexed array, use
@ref removeDuplicatesIndexedInPlace(const Containers::StridedArrayView1D<IndexType>&, const Containers::StridedArrayView1D<Vector>&, typename Vector::Type) instead.
See also @ref removeDuplicates(std::vector<Vector>&, typename Vector::Type) for
a variant operating on a STL vector.
If you want to remove duplicates in multiple incidental arrays, first remove
duplicates in each array separately and then combine the resulting index arrays
back into a single one using @ref combineIndexedAttributes().
*/
template<class Vector> std::pair<Containers::Array<UnsignedInt>, std::size_t> removeDuplicatesInPlace(const Containers::StridedArrayView1D<Vector>& data, typename Vector::Type epsilon = Math::TypeTraits<typename Vector::Type>::epsilon());
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief Remove duplicate floating-point vector data from a STL vector in-place
@param[in,out] data Data array, duplicate items will be cut away with order
@ -145,6 +148,7 @@ template<class Vector> std::pair<Containers::Array<UnsignedInt>, std::size_t> re
@param[in] epsilon Epsilon value, vertices closer than this distance will be
melt together
@return Resulting index array
@m_deprecated_since_latest Use @ref removeDuplicatesInPlace() instead.
Similar to the above, except that it's operating on a @ref std::vector, which
gets shrunk as a result (instead of the prefix size being returned). This
@ -155,7 +159,8 @@ array, and reorder the data accordingly:
@snippet MagnumMeshTools.cpp removeDuplicates-multiple
*/
template<class Vector> std::vector<UnsignedInt> removeDuplicates(std::vector<Vector>& data, typename Vector::Type epsilon = Math::TypeTraits<typename Vector::Type>::epsilon());
template<class Vector> CORRADE_DEPRECATED("use removeDuplicatesInPlace() instead") std::vector<UnsignedInt> removeDuplicates(std::vector<Vector>& data, typename Vector::Type epsilon = Math::TypeTraits<typename Vector::Type>::epsilon());
#endif
/**
@brief Remove duplicates from indexed floating-point vector data in-place
@ -245,6 +250,7 @@ template<class Vector> std::pair<Containers::Array<UnsignedInt>, std::size_t> re
return {std::move(indices), size};
}
#ifdef MAGNUM_BUILD_DEPRECATED
template<class Vector> std::vector<UnsignedInt> removeDuplicates(std::vector<Vector>& data, typename Vector::Type epsilon) {
/* A trivial index array that'll be remapped and returned after */
std::vector<UnsignedInt> indices(data.size());
@ -253,6 +259,7 @@ template<class Vector> std::vector<UnsignedInt> removeDuplicates(std::vector<Vec
data.resize(size);
return indices;
}
#endif
}}

14
src/Magnum/MeshTools/Subdivide.h

@ -29,7 +29,6 @@
* @brief Function @ref Magnum::MeshTools::subdivide(), @ref Magnum::MeshTools::subdivideInPlace()
*/
#include <vector>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StridedArrayView.h>
@ -37,6 +36,10 @@
#include "Magnum/Magnum.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <vector>
#endif
namespace Magnum { namespace MeshTools {
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -66,19 +69,20 @@ template<class IndexType, class Vertex, class Interpolator> void subdivide(Conta
subdivideInPlace(Containers::stridedArrayView(indices), Containers::stridedArrayView(vertices), interpolator);
}
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief Subdivide a mesh
Same as @ref subdivide(Containers::Array<IndexType>&, Containers::Array<Vertex>&vertices, Interpolator), only
working on a @ref std::vector.
@m_deprecated_since_latest Use @ref subdivide(Containers::Array<IndexType>&, Containers::Array<Vertex>&vertices, Interpolator)
or @ref subdivideInPlace() instead.
*/
template<class Vertex, class Interpolator> void subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) {
template<class Vertex, class Interpolator> CORRADE_DEPRECATED("use subdivide(Containers::Array<IndexType>&, Containers::Array<Vertex>&vertices, Interpolator) or subdivideInPlace() instead") void subdivide(std::vector<UnsignedInt>& indices, std::vector<Vertex>& vertices, Interpolator interpolator) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3", );
vertices.resize(vertices.size() + indices.size());
indices.resize(indices.size()*4);
subdivideInPlace(Containers::stridedArrayView(indices), Containers::stridedArrayView(vertices), interpolator);
}
#endif
/**
@brief Subdivide a mesh in-place

13
src/Magnum/MeshTools/Test/CMakeLists.txt

@ -24,7 +24,6 @@
#
corrade_add_test(MeshToolsCombineTest CombineTest.cpp LIBRARIES MagnumMeshToolsTestLib)
corrade_add_test(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp LIBRARIES MagnumMeshToolsTestLib)
corrade_add_test(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshToolsTestLib)
corrade_add_test(MeshToolsDuplicateTest DuplicateTest.cpp LIBRARIES MagnumMeshToolsTestLib)
corrade_add_test(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib)
@ -38,7 +37,6 @@ corrade_add_test(MeshToolsSubdivideRemov___Benchmark SubdivideRemoveDuplicatesBe
# Graceful assert for testing
set_property(TARGET
MeshToolsCombineIndexedArraysTest
MeshToolsDuplicateTest
MeshToolsInterleaveTest
MeshToolsRemoveDuplicatesTest
@ -47,7 +45,6 @@ set_property(TARGET
set_target_properties(
MeshToolsCombineTest
MeshToolsCombineIndexedArraysTest
MeshToolsCompressIndicesTest
MeshToolsDuplicateTest
MeshToolsFlipNormalsTest
@ -60,6 +57,16 @@ set_target_properties(
MeshToolsSubdivideRemov___Benchmark
PROPERTIES FOLDER "Magnum/MeshTools/Test")
if(BUILD_DEPRECATED)
corrade_add_test(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp LIBRARIES MagnumMeshToolsTestLib)
set_property(TARGET
MeshToolsCombineIndexedArraysTest
APPEND PROPERTY COMPILE_DEFINITIONS "CORRADE_GRACEFUL_ASSERT")
set_target_properties(
MeshToolsCombineIndexedArraysTest
PROPERTIES FOLDER "Magnum/MeshTools/Test")
endif()
if(BUILD_GL_TESTS)
# Otherwise CMake complains that Corrade::PluginManager is not found
find_package(Corrade REQUIRED PluginManager)

4
src/Magnum/MeshTools/Test/CombineIndexedArraysTest.cpp

@ -28,6 +28,8 @@
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#define _MAGNUM_NO_DEPRECATED_COMBINEINDEXEDARRAYS
#include "Magnum/Magnum.h"
#include "Magnum/MeshTools/CombineIndexedArrays.h"
@ -47,6 +49,7 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() {
&CombineIndexedArraysTest::indexedArrays});
}
CORRADE_IGNORE_DEPRECATED_PUSH
void CombineIndexedArraysTest::wrongIndexCount() {
std::stringstream ss;
Error redirectError{&ss};
@ -87,6 +90,7 @@ void CombineIndexedArraysTest::indexedArrays() {
CORRADE_COMPARE(array2, (std::vector<UnsignedInt>{3, 4}));
CORRADE_COMPARE(array3, (std::vector<UnsignedInt>{6, 7}));
}
CORRADE_IGNORE_DEPRECATED_POP
}}}}

11
src/Magnum/MeshTools/Test/CompressIndicesTest.cpp

@ -58,7 +58,9 @@ struct CompressIndicesTest: TestSuite::Tester {
void compressMeshDataMove();
void compressMeshDataNonIndexed();
#ifdef MAGNUM_BUILD_DEPRECATED
void compressAsShort();
#endif
};
CompressIndicesTest::CompressIndicesTest() {
@ -85,7 +87,10 @@ CompressIndicesTest::CompressIndicesTest() {
&CompressIndicesTest::compressMeshDataMove,
&CompressIndicesTest::compressMeshDataNonIndexed,
&CompressIndicesTest::compressAsShort});
#ifdef MAGNUM_BUILD_DEPRECATED
&CompressIndicesTest::compressAsShort
#endif
});
}
template<class T> void CompressIndicesTest::compressUnsignedByte() {
@ -318,7 +323,9 @@ void CompressIndicesTest::compressMeshDataNonIndexed() {
"MeshTools::compressIndices(): mesh data not indexed\n");
}
#ifdef MAGNUM_BUILD_DEPRECATED
void CompressIndicesTest::compressAsShort() {
CORRADE_IGNORE_DEPRECATED_PUSH
CORRADE_COMPARE_AS(MeshTools::compressIndicesAs<UnsignedShort>({123, 456}),
Containers::arrayView<UnsignedShort>({123, 456}),
TestSuite::Compare::Container);
@ -327,7 +334,9 @@ void CompressIndicesTest::compressAsShort() {
Error redirectError{&out};
MeshTools::compressIndicesAs<UnsignedShort>({65536});
CORRADE_COMPARE(out.str(), "MeshTools::compressIndicesAs(): type too small to represent value 65536\n");
CORRADE_IGNORE_DEPRECATED_POP
}
#endif
}}}}

8
src/Magnum/MeshTools/Test/DuplicateTest.cpp

@ -42,7 +42,9 @@ struct DuplicateTest: TestSuite::Tester {
void duplicate();
void duplicateOutOfBounds();
#ifdef MAGNUM_BUILD_DEPRECATED
void duplicateStl();
#endif
void duplicateInto();
void duplicateIntoWrongSize();
@ -67,7 +69,9 @@ struct DuplicateTest: TestSuite::Tester {
DuplicateTest::DuplicateTest() {
addTests({&DuplicateTest::duplicate,
&DuplicateTest::duplicateOutOfBounds,
#ifdef MAGNUM_BUILD_DEPRECATED
&DuplicateTest::duplicateStl,
#endif
&DuplicateTest::duplicateInto,
&DuplicateTest::duplicateIntoWrongSize,
@ -116,10 +120,14 @@ void DuplicateTest::duplicateOutOfBounds() {
"MeshTools::duplicateInto(): index 4 out of bounds for 4 elements\n");
}
#ifdef MAGNUM_BUILD_DEPRECATED
void DuplicateTest::duplicateStl() {
CORRADE_IGNORE_DEPRECATED_PUSH
CORRADE_COMPARE(MeshTools::duplicate({1, 1, 0, 3, 2, 2}, std::vector<int>{-7, 35, 12, -18}),
(std::vector<Int>{35, 35, -7, -18, 12, 12}));
CORRADE_IGNORE_DEPRECATED_POP
}
#endif
void DuplicateTest::duplicateInto() {
constexpr UnsignedByte indices[]{1, 1, 0, 3, 2, 2};

8
src/Magnum/MeshTools/Test/RemoveDuplicatesTest.cpp

@ -45,7 +45,9 @@ struct RemoveDuplicatesTest: TestSuite::Tester {
void removeDuplicatesIndexedInPlaceEmptyIndicesVertices();
void removeDuplicatesFuzzyInPlace();
#ifdef MAGNUM_BUILD_DEPRECATED
void removeDuplicatesFuzzyStl();
#endif
template<class T> void removeDuplicatesFuzzyIndexedInPlace();
void removeDuplicatesFuzzyIndexedInPlaceSmallType();
void removeDuplicatesFuzzyIndexedInPlaceEmptyIndices();
@ -66,7 +68,9 @@ RemoveDuplicatesTest::RemoveDuplicatesTest() {
&RemoveDuplicatesTest::removeDuplicatesIndexedInPlaceEmptyIndicesVertices,
&RemoveDuplicatesTest::removeDuplicatesFuzzyInPlace,
#ifdef MAGNUM_BUILD_DEPRECATED
&RemoveDuplicatesTest::removeDuplicatesFuzzyStl,
#endif
&RemoveDuplicatesTest::removeDuplicatesFuzzyIndexedInPlace<UnsignedByte>,
&RemoveDuplicatesTest::removeDuplicatesFuzzyIndexedInPlace<UnsignedShort>,
&RemoveDuplicatesTest::removeDuplicatesFuzzyIndexedInPlace<UnsignedInt>,
@ -173,6 +177,7 @@ void RemoveDuplicatesTest::removeDuplicatesFuzzyInPlace() {
TestSuite::Compare::Container);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void RemoveDuplicatesTest::removeDuplicatesFuzzyStl() {
/* Same but with implicit bloat. HEH HEH */
std::vector<Vector2i> data{
@ -182,7 +187,9 @@ void RemoveDuplicatesTest::removeDuplicatesFuzzyStl() {
{1, 5}
};
CORRADE_IGNORE_DEPRECATED_PUSH
const std::vector<UnsignedInt> indices = MeshTools::removeDuplicates(data, 2);
CORRADE_IGNORE_DEPRECATED_POP
CORRADE_COMPARE_AS(indices,
(std::vector<UnsignedInt>{0, 0, 1, 1}),
TestSuite::Compare::Container);
@ -190,6 +197,7 @@ void RemoveDuplicatesTest::removeDuplicatesFuzzyStl() {
(std::vector<Vector2i>{{1, 0}, {0, 4}}),
TestSuite::Compare::Container);
}
#endif
template<class T> void RemoveDuplicatesTest::removeDuplicatesFuzzyIndexedInPlace() {
setTestCaseTemplateName(Math::TypeTraits<T>::name());

12
src/Magnum/MeshTools/Test/SubdivideTest.cpp

@ -37,7 +37,9 @@ struct SubdivideTest: TestSuite::Tester {
explicit SubdivideTest();
void subdivide();
#ifdef MAGNUM_BUILD_DEPRECATED
void subdivideStl();
#endif
void subdivideWrongIndexCount();
template<class T> void subdivideInPlace();
void subdivideInPlaceWrongIndexCount();
@ -52,7 +54,9 @@ inline Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; }
SubdivideTest::SubdivideTest() {
addTests({&SubdivideTest::subdivide,
#ifdef MAGNUM_BUILD_DEPRECATED
&SubdivideTest::subdivideStl,
#endif
&SubdivideTest::subdivideWrongIndexCount,
&SubdivideTest::subdivideInPlace<UnsignedByte>,
&SubdivideTest::subdivideInPlace<UnsignedShort>,
@ -74,10 +78,13 @@ void SubdivideTest::subdivide() {
}), TestSuite::Compare::Container);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void SubdivideTest::subdivideStl() {
std::vector<Vector1> positions{0, 2, 6, 8};
std::vector<UnsignedInt> indices{0, 1, 2, 1, 2, 3};
CORRADE_IGNORE_DEPRECATED_PUSH
MeshTools::subdivide(indices, positions, interpolator);
CORRADE_IGNORE_DEPRECATED_POP
CORRADE_COMPARE_AS(indices,
(std::vector<UnsignedInt>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3}),
@ -86,13 +93,14 @@ void SubdivideTest::subdivideStl() {
(std::vector<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5}),
TestSuite::Compare::Container);
}
#endif
void SubdivideTest::subdivideWrongIndexCount() {
std::stringstream out;
Error redirectError{&out};
std::vector<Vector1> positions;
std::vector<UnsignedInt> indices{0, 1};
Containers::Array<Vector1> positions;
Containers::Array<UnsignedInt> indices{2};
MeshTools::subdivide(indices, positions, interpolator);
CORRADE_COMPARE(out.str(), "MeshTools::subdivide(): index count is not divisible by 3\n");
}

Loading…
Cancel
Save