Skip to content

Commit

Permalink
Replace usage of boost::transform_iterator in pxr/usd/usd
Browse files Browse the repository at this point in the history
  • Loading branch information
nvmkuruc committed Jun 26, 2023
1 parent 2641f6e commit f8a596f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
11 changes: 3 additions & 8 deletions pxr/usd/usd/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/pcp/targetIndex.h"

#include <boost/iterator/transform_iterator.hpp>

PXR_NAMESPACE_OPEN_SCOPE


Expand Down Expand Up @@ -185,17 +183,14 @@ using _PathMap = std::vector<std::pair<SdfPath, SdfPath>>;
static SdfPath
_MapPath(_PathMap const &map, SdfPath const &path)
{
using boost::make_transform_iterator;

if (map.empty()) {
return path;
}

auto it = SdfPathFindLongestPrefix(
make_transform_iterator(map.begin(), TfGet<0>()),
make_transform_iterator(map.end(), TfGet<0>()), path);
if (it.base() != map.end()) {
return path.ReplacePrefix(it.base()->first, it.base()->second);
map.begin(), map.end(), path, TfGet<0>());
if (it != map.end()) {
return path.ReplacePrefix(it->first, it->second);
}
return path;
}
Expand Down
35 changes: 16 additions & 19 deletions pxr/usd/usd/stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
#include "pxr/base/work/withScopedParallelism.h"

#include <boost/optional.hpp>
#include <boost/iterator/transform_iterator.hpp>

#include <tbb/spin_rw_mutex.h>
#include <tbb/spin_mutex.h>
Expand All @@ -111,7 +110,6 @@

PXR_NAMESPACE_OPEN_SCOPE

using boost::make_transform_iterator;
using std::pair;
using std::make_pair;
using std::map;
Expand Down Expand Up @@ -3818,9 +3816,9 @@ template <class ChangedPaths>
static std::string
_Stringify(const ChangedPaths& paths)
{
return _Stringify(SdfPathVector(
make_transform_iterator(paths.begin(), TfGet<0>()),
make_transform_iterator(paths.end(), TfGet<0>())));
SdfPathVector temp(paths.size());
std::transform(paths.cbegin(), paths.cend(), temp.begin(), TfGet<0>());
return _Stringify(temp);
}

// Add paths in the given cache that depend on the given path in the given
Expand Down Expand Up @@ -4540,8 +4538,7 @@ UsdStage::_RecomposePrims(T *pathsToRecompose)
// around this.
std::vector<Usd_PrimDataPtr> subtreesToRecompose;
_ComputeSubtreesToRecompose(
make_transform_iterator(pathsToRecompose->begin(), TfGet<0>()),
make_transform_iterator(pathsToRecompose->end(), TfGet<0>()),
pathsToRecompose->begin(), pathsToRecompose->end(),
&subtreesToRecompose);

// Recompose subtrees.
Expand Down Expand Up @@ -4583,31 +4580,31 @@ UsdStage::_ComputeSubtreesToRecompose(
subtreesToRecompose->size() + std::distance(i, end));

while (i != end) {
TF_DEBUG(USD_CHANGES).Msg("Recomposing: %s\n", i->GetText());
TF_DEBUG(USD_CHANGES).Msg("Recomposing: %s\n", i->first.GetText());
// TODO: refactor into shared method
// We only care about recomposing prim-like things
// so avoid recomposing anything else.
if (!i->IsAbsoluteRootOrPrimPath() ||
i->ContainsPrimVariantSelection()) {
if (!i->first.IsAbsoluteRootOrPrimPath() ||
i->first.ContainsPrimVariantSelection()) {
TF_DEBUG(USD_CHANGES).Msg("Skipping non-prim: %s\n",
i->GetText());
i->first.GetText());
++i;
continue;
}

// Add prototypes to list of subtrees to recompose and instantiate any
// new prototype not present in the primMap from before
PathToNodeMap::const_accessor acc;
if (_instanceCache->IsPrototypePath(*i)) {
if (_instanceCache->IsPrototypePath(i->first)) {
Usd_PrimDataPtr prototypePrim;
if (_primMap.find(acc, *i)) {
if (_primMap.find(acc, i->first)) {
// should be a changed prototype if already in the primMap
prototypePrim = acc->second.get();
acc.release();
} else {
// newPrototype should be absent from the primMap, instantiate
// these now to be added to subtreesToRecompose
prototypePrim = _InstantiatePrototypePrim(*i);
prototypePrim = _InstantiatePrototypePrim(i->first);
}
subtreesToRecompose->push_back(prototypePrim);
++i;
Expand All @@ -4616,7 +4613,7 @@ UsdStage::_ComputeSubtreesToRecompose(

// Collect all non-prototype prims (including descendants of prototypes)
// to be added to subtreesToRecompute
SdfPath const &parentPath = i->GetParentPath();
SdfPath const &parentPath = i->first.GetParentPath();
if (_primMap.find(acc, parentPath)) {

// Since our input range contains no descendant paths, siblings
Expand All @@ -4634,18 +4631,18 @@ UsdStage::_ComputeSubtreesToRecompose(

// Recompose the subtree for each affected sibling.
do {
if (_primMap.find(acc, *i)) {
if (_primMap.find(acc, i->first)) {
subtreesToRecompose->push_back(acc->second.get());
acc.release();
} else if (_instanceCache->IsPrototypePath(*i)) {
} else if (_instanceCache->IsPrototypePath(i->first)) {
// If this path is a prototype path and is not present in
// the primMap, then this must be a new prototype added
// during this processing, instantiate and add it.
Usd_PrimDataPtr protoPrim = _InstantiatePrototypePrim(*i);
Usd_PrimDataPtr protoPrim = _InstantiatePrototypePrim(i->first);
subtreesToRecompose->push_back(protoPrim);
}
++i;
} while (i != end && i->GetParentPath() == parentPath);
} while (i != end && i->first.GetParentPath() == parentPath);
} else if (parentPath.IsEmpty()) {
// This is the pseudo root, so we need to blow and rebuild
// everything.
Expand Down
3 changes: 2 additions & 1 deletion pxr/usd/usd/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,8 @@ class UsdStage : public TfRefBase, public TfWeakBase {
// Helper for _Recompose to find the subtrees that need to be
// fully recomposed and to recompose the name children of the
// parents of these subtrees. Note that [start, finish) must be a
// sorted range of paths with no descendent paths.
// sorted range of map iterators whose keys are paths with no descendent
// paths. In C++20, consider using the ranges API to improve this.
template <class Iter>
void _ComputeSubtreesToRecompose(Iter start, Iter finish,
std::vector<Usd_PrimDataPtr>* recompose);
Expand Down

0 comments on commit f8a596f

Please sign in to comment.