2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Copyright 2014 DreamWorks Animation LLC.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
|
|
//
|
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
|
|
//
|
|
|
|
// You may obtain a copy of the Apache License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
|
|
|
//
|
|
|
|
#ifndef FAR_TOPOLOGY_REFINER_H
|
|
|
|
#define FAR_TOPOLOGY_REFINER_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
#include "../sdc/type.h"
|
|
|
|
#include "../sdc/options.h"
|
2014-11-18 01:19:30 +00:00
|
|
|
#include "../sdc/bilinearScheme.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../sdc/catmarkScheme.h"
|
2014-11-18 01:19:30 +00:00
|
|
|
#include "../sdc/loopScheme.h"
|
2014-09-05 22:07:46 +00:00
|
|
|
#include "../vtr/level.h"
|
|
|
|
#include "../vtr/fvarLevel.h"
|
|
|
|
#include "../vtr/refinement.h"
|
|
|
|
#include "../vtr/fvarRefinement.h"
|
|
|
|
#include "../vtr/maskInterfaces.h"
|
|
|
|
#include "../far/types.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
|
|
|
namespace Vtr { class SparseSelector; }
|
|
|
|
|
|
|
|
namespace Far {
|
|
|
|
|
|
|
|
template <class MESH> class TopologyRefinerFactory;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// \brief Stores topology data for a specified set of refinement options.
|
|
|
|
///
|
|
|
|
class TopologyRefiner {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// \brief Constructor
|
|
|
|
TopologyRefiner(Sdc::Type type, Sdc::Options options = Sdc::Options());
|
|
|
|
|
|
|
|
/// \brief Destructor
|
|
|
|
~TopologyRefiner();
|
|
|
|
|
|
|
|
/// \brief Returns the subdivision scheme
|
|
|
|
Sdc::Type GetSchemeType() const { return _subdivType; }
|
|
|
|
|
|
|
|
/// \brief Returns the subdivision options
|
|
|
|
Sdc::Options GetSchemeOptions() const { return _subdivOptions; }
|
|
|
|
|
|
|
|
/// \brief Returns true if uniform subdivision has been applied
|
|
|
|
bool IsUniform() const { return _isUniform; }
|
2014-12-23 18:07:24 +00:00
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
/// \brief Returns the number of refinement levels
|
|
|
|
int GetNumLevels() const { return (int)_levels.size(); }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Returns the highest level of refinement
|
|
|
|
int GetMaxLevel() const { return _maxLevel; }
|
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
/// \ brief Returns true if faces have been tagged as holes
|
|
|
|
bool HasHoles() const { return _hasHoles; }
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// XXXX barfowl -- should cache these internally for trivial return)
|
|
|
|
|
|
|
|
/// \brief Returns the total number of vertices in all levels
|
|
|
|
int GetNumVerticesTotal() const;
|
|
|
|
|
|
|
|
/// \brief Returns the total number of edges in all levels
|
|
|
|
int GetNumEdgesTotal() const;
|
|
|
|
|
|
|
|
/// \brief Returns the total number of edges in all levels
|
|
|
|
int GetNumFacesTotal() const;
|
|
|
|
|
|
|
|
/// \brief Returns the total number of face vertices in all levels
|
|
|
|
int GetNumFaceVerticesTotal() const;
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
2014-12-23 18:07:24 +00:00
|
|
|
/// @name High-level refinement and related methods
|
2014-10-21 23:36:26 +00:00
|
|
|
///
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2014-12-23 18:07:24 +00:00
|
|
|
// Uniform refinement
|
|
|
|
//
|
|
|
|
|
|
|
|
/// \brief Uniform refinement options
|
|
|
|
struct UniformOptions {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-12-30 22:07:24 +00:00
|
|
|
UniformOptions(int level) :
|
|
|
|
refinementLevel(level),
|
2014-12-23 18:07:24 +00:00
|
|
|
fullTopologyInLastLevel(false) { }
|
|
|
|
|
2014-12-30 22:07:24 +00:00
|
|
|
unsigned int refinementLevel:4, ///< Number of refinement iterations
|
|
|
|
fullTopologyInLastLevel:1; ///< Skip secondary topological relationships
|
2014-12-23 18:07:24 +00:00
|
|
|
///< at the highest level of refinement.
|
|
|
|
};
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Refine the topology uniformly
|
|
|
|
///
|
2014-12-30 22:07:24 +00:00
|
|
|
/// @param options Options controlling uniform refinement
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-12-30 22:07:24 +00:00
|
|
|
void RefineUniform(UniformOptions options);
|
2014-12-23 18:07:24 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Adaptive refinement
|
|
|
|
//
|
|
|
|
|
|
|
|
/// \brief Adaptive refinement options
|
|
|
|
struct AdaptiveOptions {
|
|
|
|
|
2014-12-30 22:07:24 +00:00
|
|
|
AdaptiveOptions(int level) :
|
|
|
|
isolationLevel(level),
|
2014-12-23 18:07:24 +00:00
|
|
|
fullTopologyInLastLevel(false),
|
|
|
|
useSingleCreasePatch(false) { }
|
|
|
|
|
2014-12-30 22:07:24 +00:00
|
|
|
unsigned int isolationLevel:4, ///< Number of iterations applied to isolate
|
|
|
|
///< extraordinary vertices and creases
|
|
|
|
fullTopologyInLastLevel:1, ///< Skip secondary topological relationships
|
2014-12-23 18:07:24 +00:00
|
|
|
///< at the highest level of refinement.
|
|
|
|
useSingleCreasePatch:1; ///< Use 'single-crease' patch and stop
|
|
|
|
///< isolation where applicable
|
|
|
|
};
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Feature Adaptive topology refinement
|
|
|
|
///
|
2014-12-30 22:07:24 +00:00
|
|
|
/// @param options Options controlling adaptive refinement
|
2014-10-13 15:52:09 +00:00
|
|
|
///
|
2014-12-30 22:07:24 +00:00
|
|
|
void RefineAdaptive(AdaptiveOptions options);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Unrefine the topology (keep control cage)
|
|
|
|
void Unrefine();
|
|
|
|
|
|
|
|
/// \brief Clear the topology entirely
|
|
|
|
void Clear();
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
|
|
|
/// @name Primvar data interpolation
|
|
|
|
///
|
|
|
|
/// \anchor templating
|
|
|
|
///
|
|
|
|
/// \note Interpolation methods template both the source and destination
|
2014-12-22 17:40:14 +00:00
|
|
|
/// data buffer classes. Client-code is expected to provide interfaces
|
|
|
|
/// that implement the functions specific to its primitive variable
|
|
|
|
/// data layout. Template APIs must implement the following:
|
2014-10-21 23:36:26 +00:00
|
|
|
/// <br><br> \code{.cpp}
|
|
|
|
///
|
2014-12-22 17:40:14 +00:00
|
|
|
/// class MySource {
|
|
|
|
/// MySource & operator[](int index);
|
2014-10-21 23:36:26 +00:00
|
|
|
/// };
|
|
|
|
///
|
2014-12-22 17:40:14 +00:00
|
|
|
/// class MyDestination {
|
2014-10-21 23:36:26 +00:00
|
|
|
/// void Clear();
|
2014-12-22 17:40:14 +00:00
|
|
|
/// void AddWithWeight(MySource const & value, float weight);
|
|
|
|
/// void AddWithWeight(MyDestination const & value, float weight);
|
|
|
|
///
|
|
|
|
/// // optional
|
|
|
|
/// void AddVaryingWithWeight(MySource const & value, float weight);
|
2014-10-21 23:36:26 +00:00
|
|
|
/// };
|
|
|
|
///
|
|
|
|
/// \endcode
|
|
|
|
/// <br>
|
|
|
|
/// It is possible to implement a single interface only and use it as
|
|
|
|
/// both source and destination.
|
|
|
|
/// <br><br>
|
2014-12-22 17:40:14 +00:00
|
|
|
/// Primitive variable buffers are expected to be arrays of instances,
|
|
|
|
/// passed either as direct pointers or with a container
|
|
|
|
/// (ex. std::vector<MyVertex>).
|
|
|
|
/// Some interpolation methods however allow passing the buffers by
|
2014-10-21 23:36:26 +00:00
|
|
|
/// reference: this allows to work transparently with arrays and
|
|
|
|
/// containers (or other scheme that overload the '[]' operator)
|
|
|
|
/// <br><br>
|
|
|
|
/// See the <a href=http://internal-graphics.pixar.com/opensubdiv/docs/tutorials.html>
|
|
|
|
/// Far tutorials</a> for code examples.
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Apply vertex and varying interpolation weights to a primvar
|
|
|
|
/// buffer
|
|
|
|
///
|
|
|
|
/// The destination buffer must allocate an array of data for all the
|
|
|
|
/// refined vertices (at least GetNumVerticesTotal()-GetNumVertices(0))
|
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param src Source primvar buffer (\ref templating control vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param dst Destination primvar buffer (\ref templating refined vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
|
|
|
template <class T, class U> void Interpolate(T const * src, U * dst) const;
|
|
|
|
|
|
|
|
/// \brief Apply vertex and varying interpolation weights to a primvar
|
|
|
|
/// buffer for a single level
|
|
|
|
/// level of refinement.
|
|
|
|
///
|
|
|
|
/// The destination buffer must allocate an array of data for all the
|
|
|
|
/// refined vertices (at least GetNumVertices(level))
|
|
|
|
///
|
|
|
|
/// @param level The refinement level
|
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param src Source primvar buffer (\ref templating control vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param dst Destination primvar buffer (\ref templating refined vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
template <class T, class U> void Interpolate(int level, T const & src, U & dst) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Apply only varying interpolation weights to a primvar buffer
|
|
|
|
///
|
|
|
|
/// This method can be a useful alternative if the varying primvar data
|
|
|
|
/// does not need to be re-computed over time.
|
|
|
|
///
|
|
|
|
/// The destination buffer must allocate an array of data for all the
|
|
|
|
/// refined vertices (at least GetNumVerticesTotal()-GetNumVertices(0))
|
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param src Source primvar buffer (\ref templating control vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param dst Destination primvar buffer (\ref templating refined vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
|
|
|
template <class T, class U> void InterpolateVarying(T const * src, U * dst) const;
|
|
|
|
|
|
|
|
/// \brief Apply only varying interpolation weights to a primvar buffer
|
|
|
|
/// for a single level level of refinement.
|
|
|
|
///
|
|
|
|
/// This method can be a useful alternative if the varying primvar data
|
|
|
|
/// does not need to be re-computed over time.
|
|
|
|
///
|
|
|
|
/// The destination buffer must allocate an array of data for all the
|
|
|
|
/// refined vertices (at least GetNumVertices(level))
|
|
|
|
///
|
|
|
|
/// @param level The refinement level
|
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param src Source primvar buffer (\ref templating control vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
/// @param dst Destination primvar buffer (\ref templating refined vertex data)
|
2014-09-05 22:07:46 +00:00
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
template <class T, class U> void InterpolateVarying(int level, T const & src, U & dst) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Apply face-varying interpolation weights to a primvar buffer
|
|
|
|
// associated with a particular face-varying channel
|
|
|
|
///
|
|
|
|
template <class T, class U> void InterpolateFaceVarying(T const * src, U * dst, int channel = 0) const;
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
template <class T, class U> void InterpolateFaceVarying(int level, T const & src, U & dst, int channel = 0) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
template <class T, class U> void LimitFaceVarying(T const & src, U * dst, int channel = 0) const;
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Apply vertex interpolation limit weights to a primvar buffer
|
|
|
|
///
|
|
|
|
/// The source buffer must refer to an array of previously interpolated
|
|
|
|
/// vertex data for the last refinement level. The destination buffer
|
|
|
|
/// must allocate an array for all vertices at the last refinement level
|
|
|
|
/// (at least GetNumVertices(GetMaxLevel()))
|
|
|
|
///
|
|
|
|
/// @param src Source primvar buffer (refined vertex data) for last level
|
|
|
|
///
|
|
|
|
/// @param dst Destination primvar buffer (vertex data at the limit)
|
|
|
|
///
|
2014-10-21 23:36:26 +00:00
|
|
|
template <class T, class U> void Limit(T const & src, U * dst) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
|
|
|
/// @name Inspection of components per level
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Returns the number of vertices at a given level of refinement
|
|
|
|
int GetNumVertices(int level) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getNumVertices();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the number of edges at a given level of refinement
|
|
|
|
int GetNumEdges(int level) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getNumEdges();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the number of face vertex indices at a given level of refinement
|
|
|
|
int GetNumFaces(int level) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getNumFaces();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 20:52:40 +00:00
|
|
|
/// \brief Returns the number of faces marked as holes at the given level
|
|
|
|
int GetNumHoles(int level) const;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Returns the number of faces at a given level of refinement
|
|
|
|
int GetNumFaceVertices(int level) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getNumFaceVerticesTotal();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the sharpness of a given edge (at 'level' of refinement)
|
|
|
|
float GetEdgeSharpness(int level, Index edge) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getEdgeSharpness(edge);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the sharpness of a given vertex (at 'level' of refinement)
|
|
|
|
float GetVertexSharpness(int level, Index vert) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getVertexSharpness(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the subdivision rule of a given vertex (at 'level' of refinement)
|
|
|
|
Sdc::Crease::Rule GetVertexRule(int level, Index vert) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getVertexRule(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
|
|
|
/// @name Topological relations -- incident/adjacent components
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Returns the vertices of a 'face' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetFaceVertices(int level, Index face) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the edges of a 'face' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetFaceEdges(int level, Index face) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getFaceEdges(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 20:52:40 +00:00
|
|
|
/// \brief Returns true if 'face' at 'level' is tagged as a hole
|
|
|
|
bool IsHole(int level, Index face) const {
|
|
|
|
return _levels[level]->isHole(face);
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Returns the vertices of an 'edge' at 'level' (2 of them)
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetEdgeVertices(int level, Index edge) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getEdgeVertices(edge);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the faces incident to 'edge' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetEdgeFaces(int level, Index edge) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getEdgeFaces(edge);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the faces incident to 'vertex' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetVertexFaces(int level, Index vert) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getVertexFaces(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the edges incident to 'vertex' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetVertexEdges(int level, Index vert) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getVertexEdges(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the local face indices of vertex 'vert' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstLocalIndexArray VertexFaceLocalIndices(int level, Index vert) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getVertexFaceLocalIndices(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the local edge indices of vertex 'vert' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstLocalIndexArray VertexEdgeLocalIndices(int level, Index vert) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getVertexEdgeLocalIndices(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-01 00:07:45 +00:00
|
|
|
bool FaceIsRegular(int level, Index face) const {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fVerts = _levels[level]->getFaceVertices(face);
|
2014-11-01 00:07:45 +00:00
|
|
|
Vtr::Level::VTag compFaceVertTag =
|
|
|
|
_levels[level]->getFaceCompositeVTag(fVerts);
|
|
|
|
return not compFaceVertTag._xordinary;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
/// \brief Returns the edge with vertices'v0' and 'v1' (or -1 if they are
|
|
|
|
/// not connected)
|
|
|
|
Index FindEdge(int level, Index v0, Index v1) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->findEdge(v0, v1);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
|
|
|
/// @name Inspection of face-varying channels and their contents:
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Returns the number of face-varying channels in the tables
|
|
|
|
int GetNumFVarChannels() const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[0]->getNumFVarChannels();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the total number of face-varying values in all levels
|
|
|
|
int GetNumFVarValuesTotal(int channel = 0) const;
|
|
|
|
|
|
|
|
/// \brief Returns the number of face-varying values at a given level of refinement
|
|
|
|
int GetNumFVarValues(int level, int channel = 0) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getNumFVarValues(channel);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the face-varying values of a 'face' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray const GetFVarFaceValues(int level, Index face, int channel = 0) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->getFVarFaceValues(face, channel);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
|
|
|
/// @name Parent-to-child relationships,
|
|
|
|
/// Telationships between components in one level
|
|
|
|
/// and the next (entries may be invalid if sparse):
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Returns the child faces of face 'f' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetFaceChildFaces(int level, Index f) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _refinements[level]->getFaceChildFaces(f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the child edges of face 'f' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetFaceChildEdges(int level, Index f) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _refinements[level]->getFaceChildEdges(f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the child edges of edge 'e' at 'level'
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray GetEdgeChildEdges(int level, Index e) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _refinements[level]->getEdgeChildEdges(e);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the child vertex of face 'f' at 'level'
|
|
|
|
Index GetFaceChildVertex( int level, Index f) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _refinements[level]->getFaceChildVertex(f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the child vertex of edge 'e' at 'level'
|
|
|
|
Index GetEdgeChildVertex( int level, Index e) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _refinements[level]->getEdgeChildVertex(e);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Returns the child vertex of vertex 'v' at 'level'
|
|
|
|
Index GetVertexChildVertex(int level, Index v) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _refinements[level]->getVertexChildVertex(v);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/// Ptex
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Returns the number of ptex faces in the mesh
|
|
|
|
int GetNumPtexFaces() const;
|
|
|
|
|
|
|
|
/// \brief Returns the ptex face index given a coarse face 'f' or -1
|
|
|
|
int GetPtexIndex(Index f) const;
|
|
|
|
|
2014-09-26 22:10:57 +00:00
|
|
|
/// \brief Returns ptex face adjacency information for a given coarse face
|
|
|
|
///
|
|
|
|
/// @param face coarse face index
|
|
|
|
///
|
|
|
|
/// @param quadrant quadrant index if 'face' is not a quad (the local ptex
|
|
|
|
// sub-face index). Must be less than the number of face
|
|
|
|
// vertices.
|
|
|
|
///
|
|
|
|
/// @param adjFaces ptex face indices of adjacent faces
|
|
|
|
///
|
2014-10-01 01:53:14 +00:00
|
|
|
/// @param adjEdges ptex edge indices of adjacent faces
|
2014-09-26 22:10:57 +00:00
|
|
|
///
|
|
|
|
void GetPtexAdjacency(int face, int quadrant,
|
|
|
|
int adjFaces[4], int adjEdges[4]) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@{
|
|
|
|
/// @name Debugging aides
|
|
|
|
///
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
/// \brief Returns true if the topology of 'level' is valid
|
|
|
|
bool ValidateTopology(int level) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
return _levels[level]->validateTopology();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Prints topology information to console
|
|
|
|
void PrintTopology(int level, bool children = true) const {
|
2014-10-15 01:59:05 +00:00
|
|
|
_levels[level]->print(children ? _refinements[level] : 0);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
//@}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
//
|
2015-01-05 00:33:18 +00:00
|
|
|
// For use by the TopologyRefinerFactory<MESH> subclasses to construct the base level:
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
template <class MESH>
|
|
|
|
friend class TopologyRefinerFactory;
|
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
// Topology sizing methods required before allocation:
|
2014-10-15 01:59:05 +00:00
|
|
|
void setNumBaseFaces( int count) { _levels[0]->resizeFaces(count); }
|
|
|
|
void setNumBaseEdges( int count) { _levels[0]->resizeEdges(count); }
|
|
|
|
void setNumBaseVertices(int count) { _levels[0]->resizeVertices(count); }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
void setNumBaseFaceVertices(Index f, int count) { _levels[0]->resizeFaceVertices(f, count); }
|
|
|
|
void setNumBaseEdgeFaces( Index e, int count) { _levels[0]->resizeEdgeFaces(e, count); }
|
|
|
|
void setNumBaseVertexFaces( Index v, int count) { _levels[0]->resizeVertexFaces(v, count); }
|
|
|
|
void setNumBaseVertexEdges( Index v, int count) { _levels[0]->resizeVertexEdges(v, count); }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
// Topology assignment methods to populate base level after allocation:
|
2014-10-15 01:59:05 +00:00
|
|
|
IndexArray setBaseFaceVertices(Index f) { return _levels[0]->getFaceVertices(f); }
|
|
|
|
IndexArray setBaseFaceEdges( Index f) { return _levels[0]->getFaceEdges(f); }
|
|
|
|
IndexArray setBaseEdgeVertices(Index e) { return _levels[0]->getEdgeVertices(e); }
|
|
|
|
IndexArray setBaseEdgeFaces( Index e) { return _levels[0]->getEdgeFaces(e); }
|
|
|
|
IndexArray setBaseVertexFaces( Index v) { return _levels[0]->getVertexFaces(v); }
|
|
|
|
IndexArray setBaseVertexEdges( Index v) { return _levels[0]->getVertexEdges(v); }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
LocalIndexArray setBaseVertexFaceLocalIndices(Index v) { return _levels[0]->getVertexFaceLocalIndices(v); }
|
|
|
|
LocalIndexArray setBaseVertexEdgeLocalIndices(Index v) { return _levels[0]->getVertexEdgeLocalIndices(v); }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
void populateBaseLocalIndices() { _levels[0]->populateLocalIndices(); }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-01-02 22:22:03 +00:00
|
|
|
void setBaseEdgeNonManifold(Index e, bool b) { _levels[0]->setEdgeNonManifold(e, b); }
|
|
|
|
void setBaseVertexNonManifold(Index v, bool b) { _levels[0]->setVertexNonManifold(v, b); }
|
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
// Optional feature tagging methods for setting sharpness, holes, etc.:
|
|
|
|
void setBaseEdgeSharpness(Index e, float s) { _levels[0]->getEdgeSharpness(e) = s; }
|
|
|
|
void setBaseVertexSharpness(Index v, float s) { _levels[0]->getVertexSharpness(v) = s; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
void setBaseFaceHole(Index f, bool b) { _levels[0]->setHole(f, b); _hasHoles |= b; }
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-01-05 00:33:18 +00:00
|
|
|
// Optional methods for creating and assigning face-varying data channels:
|
|
|
|
int createBaseFVarChannel(int numValues) { return _levels[0]->createFVarChannel(numValues, _subdivOptions); }
|
|
|
|
int createBaseFVarChannel(int numValues, Sdc::Options const& options) { return _levels[0]->createFVarChannel(numValues, options); }
|
|
|
|
|
|
|
|
IndexArray setBaseFVarFaceValues(Index face, int channel = 0) { return _levels[0]->getFVarFaceValues(face, channel); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lower level protected methods intended stricty for internal use:
|
|
|
|
//
|
|
|
|
friend class TopologyRefinerFactoryBase;
|
|
|
|
friend class PatchTablesFactory;
|
|
|
|
friend class GregoryBasisFactory;
|
|
|
|
|
|
|
|
Vtr::Level & getLevel(int l) { return *_levels[l]; }
|
|
|
|
Vtr::Level const & getLevel(int l) const { return *_levels[l]; }
|
|
|
|
|
|
|
|
Vtr::Refinement & getRefinement(int l) { return *_refinements[l]; }
|
|
|
|
Vtr::Refinement const & getRefinement(int l) const { return *_refinements[l]; }
|
2014-10-21 23:36:26 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
private:
|
2014-11-18 01:19:30 +00:00
|
|
|
void selectFeatureAdaptiveComponents(Vtr::SparseSelector& selector);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U> void interpolateChildVertsFromFaces(Vtr::Refinement const &, T const & src, U & dst) const;
|
|
|
|
template <Sdc::Type SCHEME, class T, class U> void interpolateChildVertsFromEdges(Vtr::Refinement const &, T const & src, U & dst) const;
|
|
|
|
template <Sdc::Type SCHEME, class T, class U> void interpolateChildVertsFromVerts(Vtr::Refinement const &, T const & src, U & dst) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
template <class T, class U> void varyingInterpolateChildVertsFromFaces(Vtr::Refinement const &, T const & src, U & dst) const;
|
|
|
|
template <class T, class U> void varyingInterpolateChildVertsFromEdges(Vtr::Refinement const &, T const & src, U & dst) const;
|
|
|
|
template <class T, class U> void varyingInterpolateChildVertsFromVerts(Vtr::Refinement const &, T const & src, U & dst) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U> void faceVaryingInterpolateChildVertsFromFaces(Vtr::Refinement const &, T const & src, U & dst, int channel) const;
|
|
|
|
template <Sdc::Type SCHEME, class T, class U> void faceVaryingInterpolateChildVertsFromEdges(Vtr::Refinement const &, T const & src, U & dst, int channel) const;
|
|
|
|
template <Sdc::Type SCHEME, class T, class U> void faceVaryingInterpolateChildVertsFromVerts(Vtr::Refinement const &, T const & src, U & dst, int channel) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-22 00:19:21 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U> void limit(T const & src, U * dst) const;
|
|
|
|
|
|
|
|
template <Sdc::Type SCHEME, class T, class U> void faceVaryingLimit(T const & src, U * dst, int channel) const;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
void initializePtexIndices() const;
|
|
|
|
|
|
|
|
private:
|
2014-09-26 22:10:57 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Sdc::Type _subdivType;
|
|
|
|
Sdc::Options _subdivOptions;
|
|
|
|
|
2014-10-24 20:52:40 +00:00
|
|
|
unsigned char _isUniform : 1,
|
|
|
|
_hasHoles : 1,
|
|
|
|
_useSingleCreasePatch : 1,
|
|
|
|
_maxLevel : 4;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
std::vector<Vtr::Level *> _levels;
|
|
|
|
std::vector<Vtr::Refinement *> _refinements;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-09-26 22:10:57 +00:00
|
|
|
std::vector<Index> _ptexIndices;
|
2014-09-05 22:07:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::Interpolate(T const * src, U * dst) const {
|
|
|
|
|
|
|
|
for (int level=1; level<=GetMaxLevel(); ++level) {
|
|
|
|
|
|
|
|
Interpolate(level, src, dst);
|
|
|
|
|
|
|
|
src = dst;
|
|
|
|
dst += GetNumVertices(level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-21 23:36:26 +00:00
|
|
|
TopologyRefiner::Interpolate(int level, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
assert(level>0 and level<=(int)_refinements.size());
|
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
Vtr::Refinement const & refinement = getRefinement(level-1);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
switch (_subdivType) {
|
|
|
|
case Sdc::TYPE_CATMARK:
|
|
|
|
interpolateChildVertsFromFaces<Sdc::TYPE_CATMARK>(refinement, src, dst);
|
|
|
|
interpolateChildVertsFromEdges<Sdc::TYPE_CATMARK>(refinement, src, dst);
|
|
|
|
interpolateChildVertsFromVerts<Sdc::TYPE_CATMARK>(refinement, src, dst);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_LOOP:
|
|
|
|
interpolateChildVertsFromFaces<Sdc::TYPE_LOOP>(refinement, src, dst);
|
|
|
|
interpolateChildVertsFromEdges<Sdc::TYPE_LOOP>(refinement, src, dst);
|
|
|
|
interpolateChildVertsFromVerts<Sdc::TYPE_LOOP>(refinement, src, dst);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_BILINEAR:
|
|
|
|
interpolateChildVertsFromFaces<Sdc::TYPE_BILINEAR>(refinement, src, dst);
|
|
|
|
interpolateChildVertsFromEdges<Sdc::TYPE_BILINEAR>(refinement, src, dst);
|
|
|
|
interpolateChildVertsFromVerts<Sdc::TYPE_BILINEAR>(refinement, src, dst);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
2014-09-05 22:07:46 +00:00
|
|
|
inline void
|
|
|
|
TopologyRefiner::interpolateChildVertsFromFaces(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
if (refinement.getNumChildVerticesFromFaces() == 0) return;
|
|
|
|
|
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::Level& parent = refinement.parent();
|
|
|
|
|
|
|
|
float * fVertWeights = (float *)alloca(parent.getMaxValence()*sizeof(float));
|
|
|
|
|
|
|
|
for (int face = 0; face < parent.getNumFaces(); ++face) {
|
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getFaceChildVertex(face);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Declare and compute mask weights for this vertex relative to its parent face:
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fVerts = parent.getFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float fVaryingWeight = 1.0f / (float) fVerts.size();
|
|
|
|
|
|
|
|
Vtr::MaskInterface fMask(fVertWeights, 0, 0);
|
|
|
|
Vtr::FaceInterface fHood(fVerts.size());
|
|
|
|
|
|
|
|
scheme.ComputeFaceVertexMask(fHood, fMask);
|
|
|
|
|
|
|
|
// Apply the weights to the parent face's vertices:
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].Clear();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < fVerts.size(); ++i) {
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddWithWeight(src[fVerts[i]], fVertWeights[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddVaryingWithWeight(src[fVerts[i]], fVaryingWeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
2014-09-05 22:07:46 +00:00
|
|
|
inline void
|
|
|
|
TopologyRefiner::interpolateChildVertsFromEdges(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::Level& parent = refinement.parent();
|
|
|
|
const Vtr::Level& child = refinement.child();
|
|
|
|
|
|
|
|
Vtr::EdgeInterface eHood(parent);
|
|
|
|
|
|
|
|
float eVertWeights[2],
|
|
|
|
* eFaceWeights = (float *)alloca(parent.getMaxEdgeFaces()*sizeof(float));
|
|
|
|
|
|
|
|
for (int edge = 0; edge < parent.getNumEdges(); ++edge) {
|
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getEdgeChildVertex(edge);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Declare and compute mask weights for this vertex relative to its parent edge:
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray eVerts = parent.getEdgeVertices(edge),
|
|
|
|
eFaces = parent.getEdgeFaces(edge);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::MaskInterface eMask(eVertWeights, 0, eFaceWeights);
|
|
|
|
|
|
|
|
eHood.SetIndex(edge);
|
|
|
|
|
2014-10-03 17:07:05 +00:00
|
|
|
Sdc::Crease::Rule pRule = (parent.getEdgeSharpness(edge) > 0.0f) ? Sdc::Crease::RULE_CREASE : Sdc::Crease::RULE_SMOOTH;
|
2014-09-05 22:07:46 +00:00
|
|
|
Sdc::Crease::Rule cRule = child.getVertexRule(cVert);
|
|
|
|
|
|
|
|
scheme.ComputeEdgeVertexMask(eHood, eMask, pRule, cRule);
|
|
|
|
|
|
|
|
// Apply the weights to the parent edges's vertices and (if applicable) to
|
|
|
|
// the child vertices of its incident faces:
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].Clear();
|
|
|
|
dst[cVert].AddWithWeight(src[eVerts[0]], eVertWeights[0]);
|
|
|
|
dst[cVert].AddWithWeight(src[eVerts[1]], eVertWeights[1]);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddVaryingWithWeight(src[eVerts[0]], 0.5f);
|
|
|
|
dst[cVert].AddVaryingWithWeight(src[eVerts[1]], 0.5f);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (eMask.GetNumFaceWeights() > 0) {
|
|
|
|
|
|
|
|
for (int i = 0; i < eFaces.size(); ++i) {
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
if (eMask.AreFaceWeightsForFaceCenters()) {
|
|
|
|
assert(refinement.getNumChildVerticesFromFaces() > 0);
|
|
|
|
Vtr::Index cVertOfFace = refinement.getFaceChildVertex(eFaces[i]);
|
|
|
|
|
|
|
|
assert(Vtr::IndexIsValid(cVertOfFace));
|
|
|
|
dst[cVert].AddWithWeight(dst[cVertOfFace], eFaceWeights[i]);
|
|
|
|
} else {
|
|
|
|
Vtr::Index pFace = eFaces[i];
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray pFaceEdges = parent.getFaceEdges(pFace),
|
|
|
|
pFaceVerts = parent.getFaceVertices(pFace);
|
2014-11-18 01:19:30 +00:00
|
|
|
|
|
|
|
int eInFace = 0;
|
|
|
|
for ( ; pFaceEdges[eInFace] != edge; ++eInFace ) ;
|
|
|
|
|
|
|
|
int vInFace = eInFace + 2;
|
|
|
|
if (vInFace >= pFaceVerts.size()) vInFace -= pFaceVerts.size();
|
|
|
|
|
|
|
|
Vtr::Index pVertNext = pFaceVerts[vInFace];
|
|
|
|
dst[cVert].AddWithWeight(src[pVertNext], eFaceWeights[i]);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
2014-09-05 22:07:46 +00:00
|
|
|
inline void
|
|
|
|
TopologyRefiner::interpolateChildVertsFromVerts(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::Level& parent = refinement.parent();
|
|
|
|
const Vtr::Level& child = refinement.child();
|
|
|
|
|
|
|
|
Vtr::VertexInterface vHood(parent, child);
|
|
|
|
|
|
|
|
float * weightBuffer = (float *)alloca(2*parent.getMaxValence()*sizeof(float));
|
|
|
|
|
|
|
|
for (int vert = 0; vert < parent.getNumVertices(); ++vert) {
|
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getVertexChildVertex(vert);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Declare and compute mask weights for this vertex relative to its parent edge:
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vEdges = parent.getVertexEdges(vert),
|
|
|
|
vFaces = parent.getVertexFaces(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float vVertWeight,
|
|
|
|
* vEdgeWeights = weightBuffer,
|
|
|
|
* vFaceWeights = vEdgeWeights + vEdges.size();
|
|
|
|
|
|
|
|
Vtr::MaskInterface vMask(&vVertWeight, vEdgeWeights, vFaceWeights);
|
|
|
|
|
|
|
|
vHood.SetIndex(vert, cVert);
|
|
|
|
|
|
|
|
Sdc::Crease::Rule pRule = parent.getVertexRule(vert);
|
|
|
|
Sdc::Crease::Rule cRule = child.getVertexRule(cVert);
|
|
|
|
|
|
|
|
scheme.ComputeVertexVertexMask(vHood, vMask, pRule, cRule);
|
|
|
|
|
|
|
|
// Apply the weights to the parent vertex, the vertices opposite its incident
|
|
|
|
// edges, and the child vertices of its incident faces:
|
2014-10-03 17:07:05 +00:00
|
|
|
//
|
|
|
|
// In order to improve numerical precision, its better to apply smaller weights
|
|
|
|
// first, so begin with the face-weights followed by the edge-weights and the
|
|
|
|
// vertex weight last.
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].Clear();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-03 17:07:05 +00:00
|
|
|
if (vMask.GetNumFaceWeights() > 0) {
|
2014-11-18 01:19:30 +00:00
|
|
|
assert(vMask.AreFaceWeightsForFaceCenters());
|
2014-10-03 17:07:05 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < vFaces.size(); ++i) {
|
|
|
|
|
|
|
|
Vtr::Index cVertOfFace = refinement.getFaceChildVertex(vFaces[i]);
|
|
|
|
assert(Vtr::IndexIsValid(cVertOfFace));
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddWithWeight(dst[cVertOfFace], vFaceWeights[i]);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
if (vMask.GetNumEdgeWeights() > 0) {
|
|
|
|
|
|
|
|
for (int i = 0; i < vEdges.size(); ++i) {
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray eVerts = parent.getEdgeVertices(vEdges[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
Vtr::Index pVertOppositeEdge = (eVerts[0] == vert) ? eVerts[1] : eVerts[0];
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddWithWeight(src[pVertOppositeEdge], vEdgeWeights[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddWithWeight(src[vert], vVertWeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddVaryingWithWeight(src[vert], 1.0f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Varying only interpolation
|
|
|
|
//
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::InterpolateVarying(T const * src, U * dst) const {
|
|
|
|
|
|
|
|
for (int level=1; level<=GetMaxLevel(); ++level) {
|
|
|
|
|
|
|
|
InterpolateVarying(level, src, dst);
|
|
|
|
|
|
|
|
src = dst;
|
|
|
|
dst += GetNumVertices(level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-21 23:36:26 +00:00
|
|
|
TopologyRefiner::InterpolateVarying(int level, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
assert(level>0 and level<=(int)_refinements.size());
|
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
Vtr::Refinement const & refinement = getRefinement(level-1);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
varyingInterpolateChildVertsFromFaces(refinement, src, dst);
|
|
|
|
varyingInterpolateChildVertsFromEdges(refinement, src, dst);
|
|
|
|
varyingInterpolateChildVertsFromVerts(refinement, src, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::varyingInterpolateChildVertsFromFaces(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
if (refinement.getNumChildVerticesFromFaces() == 0) return;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
const Vtr::Level& parent = refinement.parent();
|
|
|
|
|
|
|
|
for (int face = 0; face < parent.getNumFaces(); ++face) {
|
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getFaceChildVertex(face);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fVerts = parent.getFaceVertices(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float fVaryingWeight = 1.0f / (float) fVerts.size();
|
|
|
|
|
|
|
|
// Apply the weights to the parent face's vertices:
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].Clear();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < fVerts.size(); ++i) {
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddVaryingWithWeight(src[fVerts[i]], fVaryingWeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::varyingInterpolateChildVertsFromEdges(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::Level& parent = refinement.parent();
|
|
|
|
|
|
|
|
for (int edge = 0; edge < parent.getNumEdges(); ++edge) {
|
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getEdgeChildVertex(edge);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Declare and compute mask weights for this vertex relative to its parent edge:
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray eVerts = parent.getEdgeVertices(edge);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// Apply the weights to the parent edges's vertices
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].Clear();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].AddVaryingWithWeight(src[eVerts[0]], 0.5f);
|
|
|
|
dst[cVert].AddVaryingWithWeight(src[eVerts[1]], 0.5f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::varyingInterpolateChildVertsFromVerts(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::Level& parent = refinement.parent();
|
|
|
|
|
|
|
|
for (int vert = 0; vert < parent.getNumVertices(); ++vert) {
|
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getVertexChildVertex(vert);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Apply the weights to the parent vertex
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVert].Clear();
|
|
|
|
dst[cVert].AddVaryingWithWeight(src[vert], 1.0f);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Face-varying only interpolation
|
|
|
|
//
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::InterpolateFaceVarying(T const * src, U * dst, int channel) const {
|
|
|
|
|
|
|
|
for (int level=1; level<=GetMaxLevel(); ++level) {
|
|
|
|
|
|
|
|
InterpolateFaceVarying(level, src, dst, channel);
|
2014-09-26 22:10:57 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
src = dst;
|
2014-10-15 18:22:32 +00:00
|
|
|
dst += getLevel(level).getNumFVarValues();
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-21 23:36:26 +00:00
|
|
|
TopologyRefiner::InterpolateFaceVarying(int level, T const & src, U & dst, int channel) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
assert(level>0 and level<=(int)_refinements.size());
|
|
|
|
|
2014-10-15 01:59:05 +00:00
|
|
|
Vtr::Refinement const & refinement = getRefinement(level-1);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
switch (_subdivType) {
|
|
|
|
case Sdc::TYPE_CATMARK:
|
|
|
|
faceVaryingInterpolateChildVertsFromFaces<Sdc::TYPE_CATMARK>(refinement, src, dst, channel);
|
|
|
|
faceVaryingInterpolateChildVertsFromEdges<Sdc::TYPE_CATMARK>(refinement, src, dst, channel);
|
|
|
|
faceVaryingInterpolateChildVertsFromVerts<Sdc::TYPE_CATMARK>(refinement, src, dst, channel);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_LOOP:
|
|
|
|
faceVaryingInterpolateChildVertsFromFaces<Sdc::TYPE_LOOP>(refinement, src, dst, channel);
|
|
|
|
faceVaryingInterpolateChildVertsFromEdges<Sdc::TYPE_LOOP>(refinement, src, dst, channel);
|
|
|
|
faceVaryingInterpolateChildVertsFromVerts<Sdc::TYPE_LOOP>(refinement, src, dst, channel);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_BILINEAR:
|
|
|
|
faceVaryingInterpolateChildVertsFromFaces<Sdc::TYPE_BILINEAR>(refinement, src, dst, channel);
|
|
|
|
faceVaryingInterpolateChildVertsFromEdges<Sdc::TYPE_BILINEAR>(refinement, src, dst, channel);
|
|
|
|
faceVaryingInterpolateChildVertsFromVerts<Sdc::TYPE_BILINEAR>(refinement, src, dst, channel);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
2014-09-05 22:07:46 +00:00
|
|
|
inline void
|
|
|
|
TopologyRefiner::faceVaryingInterpolateChildVertsFromFaces(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst, int channel) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
if (refinement.getNumChildVerticesFromFaces() == 0) return;
|
|
|
|
|
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-09 21:25:09 +00:00
|
|
|
const Vtr::Level& parentLevel = refinement.parent();
|
|
|
|
const Vtr::Level& childLevel = refinement.child();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-09 21:25:09 +00:00
|
|
|
const Vtr::FVarLevel& parentFVar = *parentLevel._fvarChannels[channel];
|
|
|
|
const Vtr::FVarLevel& childFVar = *childLevel._fvarChannels[channel];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-09 21:25:09 +00:00
|
|
|
float * fValueWeights = (float *)alloca(parentLevel.getMaxValence()*sizeof(float));
|
|
|
|
|
|
|
|
for (int face = 0; face < parentLevel.getNumFaces(); ++face) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getFaceChildVertex(face);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
2014-11-09 21:25:09 +00:00
|
|
|
Vtr::Index cVertValue = childFVar.getVertexValueOffset(cVert);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// The only difference for face-varying here is that we get the values associated
|
|
|
|
// with each face-vertex directly from the FVarLevel, rather than using the parent
|
|
|
|
// face-vertices directly. If any face-vertex has any sibling values, then we may
|
|
|
|
// get the wrong one using the face-vertex index directly.
|
|
|
|
|
|
|
|
// Declare and compute mask weights for this vertex relative to its parent face:
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fValues = parentFVar.getFaceValues(face);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::MaskInterface fMask(fValueWeights, 0, 0);
|
|
|
|
Vtr::FaceInterface fHood(fValues.size());
|
|
|
|
|
|
|
|
scheme.ComputeFaceVertexMask(fHood, fMask);
|
|
|
|
|
|
|
|
// Apply the weights to the parent face's vertices:
|
2014-11-09 21:25:09 +00:00
|
|
|
dst[cVertValue].Clear();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < fValues.size(); ++i) {
|
2014-11-09 21:25:09 +00:00
|
|
|
dst[cVertValue].AddWithWeight(src[fValues[i]], fValueWeights[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
2014-09-05 22:07:46 +00:00
|
|
|
inline void
|
|
|
|
TopologyRefiner::faceVaryingInterpolateChildVertsFromEdges(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst, int channel) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
const Vtr::Level& parentLevel = refinement.parent();
|
|
|
|
const Vtr::Level& childLevel = refinement.child();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::FVarRefinement& refineFVar = *refinement._fvarChannels[channel];
|
2014-11-04 01:31:24 +00:00
|
|
|
const Vtr::FVarLevel& parentFVar = *parentLevel._fvarChannels[channel];
|
|
|
|
const Vtr::FVarLevel& childFVar = *childLevel._fvarChannels[channel];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate and intialize (if linearly interpolated) interpolation weights for
|
|
|
|
// the edge mask:
|
|
|
|
//
|
|
|
|
float eVertWeights[2],
|
2014-11-04 01:31:24 +00:00
|
|
|
* eFaceWeights = (float *)alloca(parentLevel.getMaxEdgeFaces()*sizeof(float));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::MaskInterface eMask(eVertWeights, 0, eFaceWeights);
|
|
|
|
|
|
|
|
bool isLinearFVar = parentFVar._isLinear;
|
|
|
|
if (isLinearFVar) {
|
|
|
|
eMask.SetNumVertexWeights(2);
|
|
|
|
eMask.SetNumEdgeWeights(0);
|
|
|
|
eMask.SetNumFaceWeights(0);
|
|
|
|
|
|
|
|
eVertWeights[0] = 0.5f;
|
|
|
|
eVertWeights[1] = 0.5f;
|
|
|
|
}
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::EdgeInterface eHood(parentLevel);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
for (int edge = 0; edge < parentLevel.getNumEdges(); ++edge) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getEdgeChildVertex(edge);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray cVertValues = childFVar.getVertexValues(cVert);
|
2014-11-04 01:31:24 +00:00
|
|
|
|
|
|
|
bool fvarEdgeVertMatchesVertex = childFVar.valueTopologyMatches(cVertValues[0]);
|
2014-09-05 22:07:46 +00:00
|
|
|
if (fvarEdgeVertMatchesVertex) {
|
|
|
|
//
|
|
|
|
// If smoothly interpolated, compute new weights for the edge mask:
|
|
|
|
//
|
|
|
|
if (!isLinearFVar) {
|
|
|
|
eHood.SetIndex(edge);
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Sdc::Crease::Rule pRule = (parentLevel.getEdgeSharpness(edge) > 0.0f)
|
|
|
|
? Sdc::Crease::RULE_CREASE : Sdc::Crease::RULE_SMOOTH;
|
|
|
|
Sdc::Crease::Rule cRule = childLevel.getVertexRule(cVert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
scheme.ComputeEdgeVertexMask(eHood, eMask, pRule, cRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the weights to the parent edges's vertices and (if applicable) to
|
|
|
|
// the child vertices of its incident faces:
|
|
|
|
//
|
|
|
|
// Even though the face-varying topology matches the vertex topology, we need
|
|
|
|
// to be careful here when getting values corresponding to the two end-vertices.
|
|
|
|
// While the edge may be continuous, the vertices at their ends may have
|
|
|
|
// discontinuities elsewhere in their neighborhood (i.e. on the "other side"
|
|
|
|
// of the end-vertex) and so have sibling values associated with them. In most
|
|
|
|
// cases the topology for an end-vertex will match and we can use it directly,
|
|
|
|
// but we must still check and retrieve as needed.
|
|
|
|
//
|
|
|
|
// Indices for values corresponding to face-vertices are guaranteed to match,
|
|
|
|
// so we can use the child-vertex indices directly.
|
|
|
|
//
|
|
|
|
// And by "directly", we always use getVertexValue(vertexIndex) to reference
|
|
|
|
// values in the "src" to account for the possible indirection that may exist at
|
|
|
|
// level 0 -- where there may be fewer values than vertices and an additional
|
|
|
|
// indirection is necessary. We can use a vertex index directly for "dst" when
|
|
|
|
// it matches.
|
|
|
|
//
|
|
|
|
Vtr::Index eVertValues[2];
|
|
|
|
|
2014-11-09 21:25:09 +00:00
|
|
|
parentFVar.getEdgeFaceValues(edge, 0, eVertValues);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Index cVertValue = cVertValues[0];
|
|
|
|
|
|
|
|
dst[cVertValue].Clear();
|
|
|
|
dst[cVertValue].AddWithWeight(src[eVertValues[0]], eVertWeights[0]);
|
|
|
|
dst[cVertValue].AddWithWeight(src[eVertValues[1]], eVertWeights[1]);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
if (eMask.GetNumFaceWeights() > 0) {
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray eFaces = parentLevel.getEdgeFaces(edge);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < eFaces.size(); ++i) {
|
2014-11-18 01:19:30 +00:00
|
|
|
if (eMask.AreFaceWeightsForFaceCenters()) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Vtr::Index cVertOfFace = refinement.getFaceChildVertex(eFaces[i]);
|
|
|
|
assert(Vtr::IndexIsValid(cVertOfFace));
|
2014-11-09 21:25:09 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Vtr::Index cValueOfFace = childFVar.getVertexValueOffset(cVertOfFace);
|
|
|
|
dst[cVertValue].AddWithWeight(dst[cValueOfFace], eFaceWeights[i]);
|
|
|
|
} else {
|
|
|
|
Vtr::Index pFace = eFaces[i];
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray pFaceEdges = parentLevel.getFaceEdges(pFace),
|
|
|
|
pFaceVerts = parentLevel.getFaceVertices(pFace);
|
2014-11-18 01:19:30 +00:00
|
|
|
|
|
|
|
int eInFace = 0;
|
|
|
|
for ( ; pFaceEdges[eInFace] != edge; ++eInFace ) ;
|
|
|
|
|
|
|
|
// Edge "i" spans vertices [i,i+1] so we want i+2...
|
|
|
|
int vInFace = eInFace + 2;
|
|
|
|
if (vInFace >= pFaceVerts.size()) vInFace -= pFaceVerts.size();
|
|
|
|
|
|
|
|
Vtr::Index pValueNext = parentFVar.getFaceValues(pFace)[vInFace];
|
|
|
|
dst[cVertValue].AddWithWeight(src[pValueNext], eFaceWeights[i]);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Mismatched edge-verts should just be linearly interpolated between the pairs of
|
|
|
|
// values for each sibling of the child edge-vertex -- the question is: which face
|
|
|
|
// holds that pair of values for a given sibling?
|
|
|
|
//
|
|
|
|
// In the manifold case, the sibling and edge-face indices will correspond. We
|
|
|
|
// will eventually need to update this to account for > 3 incident faces.
|
|
|
|
//
|
2014-11-04 01:31:24 +00:00
|
|
|
for (int i = 0; i < cVertValues.size(); ++i) {
|
2014-09-05 22:07:46 +00:00
|
|
|
Vtr::Index eVertValues[2];
|
|
|
|
int eFaceIndex = refineFVar.getChildValueParentSource(cVert, i);
|
|
|
|
assert(eFaceIndex == i);
|
|
|
|
|
|
|
|
parentFVar.getEdgeFaceValues(edge, eFaceIndex, eVertValues);
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Index cVertValue = cVertValues[i];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[cVertValue].Clear();
|
|
|
|
dst[cVertValue].AddWithWeight(src[eVertValues[0]], 0.5);
|
|
|
|
dst[cVertValue].AddWithWeight(src[eVertValues[1]], 0.5);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
2014-09-05 22:07:46 +00:00
|
|
|
inline void
|
|
|
|
TopologyRefiner::faceVaryingInterpolateChildVertsFromVerts(
|
2014-10-21 23:36:26 +00:00
|
|
|
Vtr::Refinement const & refinement, T const & src, U & dst, int channel) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-18 01:19:30 +00:00
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
const Vtr::Level& parentLevel = refinement.parent();
|
|
|
|
const Vtr::Level& childLevel = refinement.child();
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
const Vtr::FVarRefinement& refineFVar = *refinement._fvarChannels[channel];
|
2014-11-04 01:31:24 +00:00
|
|
|
const Vtr::FVarLevel& parentFVar = *parentLevel._fvarChannels[channel];
|
|
|
|
const Vtr::FVarLevel& childFVar = *childLevel._fvarChannels[channel];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
bool isLinearFVar = parentFVar._isLinear;
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
float * weightBuffer = (float *)alloca(2*parentLevel.getMaxValence()*sizeof(float));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::Index * vEdgeValues = (Vtr::Index *)alloca(parentLevel.getMaxValence()*sizeof(Vtr::Index));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::VertexInterface vHood(parentLevel, childLevel);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
for (int vert = 0; vert < parentLevel.getNumVertices(); ++vert) {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
Vtr::Index cVert = refinement.getVertexChildVertex(vert);
|
|
|
|
if (!Vtr::IndexIsValid(cVert))
|
|
|
|
continue;
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray pVertValues = parentFVar.getVertexValues(vert),
|
|
|
|
cVertValues = childFVar.getVertexValues(cVert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
bool fvarVertVertMatchesVertex = childFVar.valueTopologyMatches(cVertValues[0]);
|
|
|
|
if (isLinearFVar && fvarVertVertMatchesVertex) {
|
|
|
|
dst[cVertValues[0]].Clear();
|
|
|
|
dst[cVertValues[0]].AddWithWeight(src[pVertValues[0]], 1.0f);
|
2014-09-05 22:07:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fvarVertVertMatchesVertex) {
|
|
|
|
//
|
|
|
|
// Declare and compute mask weights for this vertex relative to its parent edge:
|
|
|
|
//
|
|
|
|
// (We really need to encapsulate this somewhere else for use here and in the
|
|
|
|
// general case)
|
|
|
|
//
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vEdges = parentLevel.getVertexEdges(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float vVertWeight;
|
|
|
|
float * vEdgeWeights = weightBuffer;
|
|
|
|
float * vFaceWeights = vEdgeWeights + vEdges.size();
|
|
|
|
|
|
|
|
Vtr::MaskInterface vMask(&vVertWeight, vEdgeWeights, vFaceWeights);
|
|
|
|
|
|
|
|
vHood.SetIndex(vert, cVert);
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Sdc::Crease::Rule pRule = parentLevel.getVertexRule(vert);
|
|
|
|
Sdc::Crease::Rule cRule = childLevel.getVertexRule(cVert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
scheme.ComputeVertexVertexMask(vHood, vMask, pRule, cRule);
|
|
|
|
|
|
|
|
// Apply the weights to the parent vertex, the vertices opposite its incident
|
|
|
|
// edges, and the child vertices of its incident faces:
|
|
|
|
//
|
|
|
|
// Even though the face-varying topology matches the vertex topology, we need
|
|
|
|
// to be careful here when getting values corresponding to vertices at the
|
|
|
|
// ends of edges. While the edge may be continuous, the end vertex may have
|
|
|
|
// discontinuities elsewhere in their neighborhood (i.e. on the "other side"
|
|
|
|
// of the end-vertex) and so have sibling values associated with them. In most
|
|
|
|
// cases the topology for an end-vertex will match and we can use it directly,
|
|
|
|
// but we must still check and retrieve as needed.
|
|
|
|
//
|
|
|
|
// Indices for values corresponding to face-vertices are guaranteed to match,
|
|
|
|
// so we can use the child-vertex indices directly.
|
|
|
|
//
|
|
|
|
// And by "directly", we always use getVertexValue(vertexIndex) to reference
|
|
|
|
// values in the "src" to account for the possible indirection that may exist at
|
|
|
|
// level 0 -- where there may be fewer values than vertices and an additional
|
|
|
|
// indirection is necessary. We can use a vertex index directly for "dst" when
|
|
|
|
// it matches.
|
|
|
|
//
|
2014-10-03 17:07:05 +00:00
|
|
|
// As with applying the mask to vertex data, in order to improve numerical
|
|
|
|
// precision, its better to apply smaller weights first, so begin with the
|
|
|
|
// face-weights followed by the edge-weights and the vertex weight last.
|
|
|
|
//
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::Index pVertValue = pVertValues[0];
|
|
|
|
Vtr::Index cVertValue = cVertValues[0];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVertValue].Clear();
|
2014-10-03 17:07:05 +00:00
|
|
|
if (vMask.GetNumFaceWeights() > 0) {
|
2014-11-18 01:19:30 +00:00
|
|
|
assert(vMask.AreFaceWeightsForFaceCenters());
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vFaces = parentLevel.getVertexFaces(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-03 17:07:05 +00:00
|
|
|
for (int i = 0; i < vFaces.size(); ++i) {
|
|
|
|
|
2014-11-09 21:25:09 +00:00
|
|
|
Vtr::Index cVertOfFace = refinement.getFaceChildVertex(vFaces[i]);
|
2014-10-03 17:07:05 +00:00
|
|
|
assert(Vtr::IndexIsValid(cVertOfFace));
|
2014-11-09 21:25:09 +00:00
|
|
|
|
|
|
|
Vtr::Index cValueOfFace = childFVar.getVertexValueOffset(cVertOfFace);
|
|
|
|
dst[cVertValue].AddWithWeight(dst[cValueOfFace], vFaceWeights[i]);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
if (vMask.GetNumEdgeWeights() > 0) {
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
parentFVar.getVertexEdgeValues(vert, vEdgeValues);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
for (int i = 0; i < vEdges.size(); ++i) {
|
|
|
|
dst[cVertValue].AddWithWeight(src[vEdgeValues[i]], vEdgeWeights[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVertValue].AddWithWeight(src[pVertValue], vVertWeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
} else {
|
|
|
|
//
|
2014-10-03 17:07:05 +00:00
|
|
|
// Each FVar value associated with a vertex will be either a corner or a crease,
|
|
|
|
// or potentially in transition from corner to crease:
|
2014-11-04 01:31:24 +00:00
|
|
|
// - if the CHILD is a corner, there can be no transition so we have a corner
|
|
|
|
// - otherwise if the PARENT is a crease, both will be creases (no transition)
|
|
|
|
// - otherwise the parent must be a corner and the child a crease (transition)
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
2014-12-15 18:23:13 +00:00
|
|
|
Vtr::FVarLevel::ConstValueTagArray pValueTags = parentFVar.getVertexValueTags(vert);
|
|
|
|
Vtr::FVarLevel::ConstValueTagArray cValueTags = childFVar.getVertexValueTags(cVert);
|
2014-11-04 01:31:24 +00:00
|
|
|
|
|
|
|
for (int cSibling = 0; cSibling < cVertValues.size(); ++cSibling) {
|
2014-09-05 22:07:46 +00:00
|
|
|
int pSibling = refineFVar.getChildValueParentSource(cVert, cSibling);
|
|
|
|
assert(pSibling == cSibling);
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::Index pVertValue = pVertValues[pSibling];
|
|
|
|
Vtr::Index cVertValue = cVertValues[cSibling];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVertValue].Clear();
|
2014-11-04 01:31:24 +00:00
|
|
|
if (cValueTags[cSibling].isCorner()) {
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVertValue].AddWithWeight(src[pVertValue], 1.0f);
|
2014-09-30 01:46:33 +00:00
|
|
|
} else {
|
2014-10-06 19:07:44 +00:00
|
|
|
//
|
|
|
|
// We have either a crease or a transition from corner to crease -- in
|
2014-11-04 01:31:24 +00:00
|
|
|
// either case, we need the end values for the full/fractional crease:
|
2014-10-06 19:07:44 +00:00
|
|
|
//
|
2014-09-30 01:46:33 +00:00
|
|
|
Index pEndValues[2];
|
|
|
|
parentFVar.getVertexCreaseEndValues(vert, pSibling, pEndValues);
|
|
|
|
|
2014-10-06 19:07:44 +00:00
|
|
|
float vWeight = 0.75f;
|
|
|
|
float eWeight = 0.125f;
|
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
//
|
|
|
|
// If semisharp we need to apply fractional weighting -- if made sharp because
|
|
|
|
// of the other sibling (dependent-sharp) use the fractional weight from that
|
|
|
|
// other sibling (should only occur when there are 2):
|
|
|
|
//
|
|
|
|
if (pValueTags[pSibling].isSemiSharp()) {
|
|
|
|
float wCorner = pValueTags[pSibling].isDepSharp()
|
2014-10-24 23:15:22 +00:00
|
|
|
? refineFVar.getFractionalWeight(vert, !pSibling, cVert, !cSibling)
|
|
|
|
: refineFVar.getFractionalWeight(vert, pSibling, cVert, cSibling);
|
2014-10-06 19:07:44 +00:00
|
|
|
float wCrease = 1.0f - wCorner;
|
|
|
|
|
|
|
|
vWeight = wCrease * 0.75f + wCorner;
|
|
|
|
eWeight = wCrease * 0.125f;
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[cVertValue].AddWithWeight(src[pEndValues[0]], eWeight);
|
|
|
|
dst[cVertValue].AddWithWeight(src[pEndValues[1]], eWeight);
|
|
|
|
dst[cVertValue].AddWithWeight(src[pVertValue], vWeight);
|
2014-09-30 01:46:33 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-21 23:36:26 +00:00
|
|
|
TopologyRefiner::Limit(T const & src, U * dst) const {
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-11-22 00:19:21 +00:00
|
|
|
assert(GetMaxLevel() > 0);
|
|
|
|
|
|
|
|
switch (_subdivType) {
|
|
|
|
case Sdc::TYPE_CATMARK:
|
|
|
|
limit<Sdc::TYPE_CATMARK>(src, dst);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_LOOP:
|
|
|
|
limit<Sdc::TYPE_LOOP>(src, dst);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_BILINEAR:
|
|
|
|
limit<Sdc::TYPE_BILINEAR>(src, dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::limit(T const & src, U * dst) const {
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//
|
|
|
|
// Work in progress...
|
|
|
|
// - does not support tangents yet (unclear how)
|
|
|
|
// - need to verify that each vertex is "limitable", i.e.:
|
|
|
|
// - is not semi-sharp, inf-sharp or non-manifold
|
|
|
|
// - is "complete" wrt its parent (if refinement is sparse)
|
|
|
|
// - copy (or weight by 1.0) src to dst when not "limitable"
|
|
|
|
// - currently requires one refinement to get rid of N-sided faces:
|
|
|
|
// - could limit regular vertices from level 0
|
|
|
|
//
|
2014-11-22 00:19:21 +00:00
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-15 18:22:32 +00:00
|
|
|
Vtr::Level const & level = getLevel(GetMaxLevel());
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
int maxWeightsPerMask = 1 + 2 * level.getMaxValence();
|
|
|
|
|
|
|
|
float * weightBuffer = (float *)alloca(maxWeightsPerMask * sizeof(float));
|
|
|
|
|
|
|
|
// This is a bit obscure -- assign both parent and child as last level
|
|
|
|
Vtr::VertexInterface vHood(level, level);
|
|
|
|
|
|
|
|
for (int vert = 0; vert < level.getNumVertices(); ++vert) {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vEdges = level.getVertexEdges(vert);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
float * vWeights = weightBuffer,
|
|
|
|
* eWeights = vWeights + 1,
|
|
|
|
* fWeights = eWeights + vEdges.size();
|
|
|
|
|
|
|
|
Vtr::MaskInterface vMask(vWeights, eWeights, fWeights);
|
|
|
|
|
|
|
|
// This is a bit obscure -- child vertex index will be ignored here
|
|
|
|
vHood.SetIndex(vert, vert);
|
|
|
|
|
|
|
|
scheme.ComputeVertexLimitMask(vHood, vMask);
|
|
|
|
|
|
|
|
// Apply the weights to the vertex, the vertices opposite its incident
|
|
|
|
// edges, and the opposite vertices of its incident faces:
|
2014-10-03 17:07:05 +00:00
|
|
|
//
|
|
|
|
// As with applying refinment masks to vertex data, in order to improve
|
|
|
|
// numerical precision, its better to apply smaller weights first, so
|
|
|
|
// begin with the face-weights followed by the edge-weights and the vertex
|
|
|
|
// weight last.
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[vert].Clear();
|
2014-10-03 17:07:05 +00:00
|
|
|
if (vMask.GetNumFaceWeights() > 0) {
|
2014-11-18 01:19:30 +00:00
|
|
|
assert(!vMask.AreFaceWeightsForFaceCenters());
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vFaces = level.getVertexFaces(vert);
|
|
|
|
ConstLocalIndexArray vInFace = level.getVertexFaceLocalIndices(vert);
|
2014-10-03 17:07:05 +00:00
|
|
|
for (int i = 0; i < vFaces.size(); ++i) {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray fVerts = level.getFaceVertices(vFaces[i]);
|
2014-11-22 00:19:21 +00:00
|
|
|
|
|
|
|
LocalIndex vOppInFace = (vInFace[i] + 2);
|
|
|
|
if (vOppInFace >= fVerts.size()) vOppInFace -= (LocalIndex)fVerts.size();
|
|
|
|
Index vertOppositeFace = level.getFaceVertices(vFaces[i])[vOppInFace];
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[vert].AddWithWeight(src[vertOppositeFace], fWeights[i]);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
if (vMask.GetNumEdgeWeights() > 0) {
|
|
|
|
for (int i = 0; i < vEdges.size(); ++i) {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray eVerts = level.getEdgeVertices(vEdges[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
Index vertOppositeEdge = (eVerts[0] == vert) ? eVerts[1] : eVerts[0];
|
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[vert].AddWithWeight(src[vertOppositeEdge], eWeights[i]);
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[vert].AddWithWeight(src[vert], vWeights[0]);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-03 17:07:05 +00:00
|
|
|
template <class T, class U>
|
|
|
|
inline void
|
2014-10-21 23:36:26 +00:00
|
|
|
TopologyRefiner::LimitFaceVarying(T const & src, U * dst, int channel) const {
|
2014-10-03 17:07:05 +00:00
|
|
|
|
|
|
|
assert(GetMaxLevel() > 0);
|
2014-11-22 00:19:21 +00:00
|
|
|
|
|
|
|
switch (_subdivType) {
|
|
|
|
case Sdc::TYPE_CATMARK:
|
|
|
|
faceVaryingLimit<Sdc::TYPE_CATMARK>(src, dst, channel);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_LOOP:
|
|
|
|
faceVaryingLimit<Sdc::TYPE_LOOP>(src, dst, channel);
|
|
|
|
break;
|
|
|
|
case Sdc::TYPE_BILINEAR:
|
|
|
|
faceVaryingLimit<Sdc::TYPE_BILINEAR>(src, dst, channel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <Sdc::Type SCHEME, class T, class U>
|
|
|
|
inline void
|
|
|
|
TopologyRefiner::faceVaryingLimit(T const & src, U * dst, int channel) const {
|
|
|
|
|
|
|
|
Sdc::Scheme<SCHEME> scheme(_subdivOptions);
|
|
|
|
|
2014-10-15 18:22:32 +00:00
|
|
|
Vtr::Level const & level = getLevel(GetMaxLevel());
|
2014-10-03 17:07:05 +00:00
|
|
|
Vtr::FVarLevel const & fvarChannel = *level._fvarChannels[channel];
|
|
|
|
|
|
|
|
int maxWeightsPerMask = 1 + 2 * level.getMaxValence();
|
|
|
|
|
|
|
|
float * weightBuffer = (float *)alloca(maxWeightsPerMask * sizeof(float));
|
|
|
|
Index * indexBuffer = (Index *)alloca(level.getMaxValence() * sizeof(Index));
|
|
|
|
|
|
|
|
// This is a bit obscure -- assign both parent and child as last level
|
|
|
|
Vtr::VertexInterface vHood(level, level);
|
|
|
|
|
|
|
|
for (int vert = 0; vert < level.getNumVertices(); ++vert) {
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vValues = fvarChannel.getVertexValues(vert);
|
2014-11-04 01:31:24 +00:00
|
|
|
|
|
|
|
bool fvarVertMatchesVertex = fvarChannel.valueTopologyMatches(vValues[0]);
|
2014-10-03 17:07:05 +00:00
|
|
|
if (fvarChannel._isLinear && fvarVertMatchesVertex) {
|
|
|
|
Vtr::Index srcValueIndex = fvarChannel.getVertexValue(vert);
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::Index dstValueIndex = vValues[0];
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-10-21 23:36:26 +00:00
|
|
|
dst[dstValueIndex].Clear();
|
|
|
|
dst[dstValueIndex].AddWithWeight(src[srcValueIndex], 1.0f);
|
2014-10-03 17:07:05 +00:00
|
|
|
} else if (fvarVertMatchesVertex) {
|
|
|
|
//
|
|
|
|
// Compute the limit mask based on vertex topology:
|
|
|
|
//
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vEdges = level.getVertexEdges(vert);
|
2014-10-03 17:07:05 +00:00
|
|
|
|
|
|
|
float * vWeights = weightBuffer,
|
|
|
|
* eWeights = vWeights + 1,
|
|
|
|
* fWeights = eWeights + vEdges.size();
|
|
|
|
|
|
|
|
Vtr::MaskInterface vMask(vWeights, eWeights, fWeights);
|
|
|
|
|
|
|
|
vHood.SetIndex(vert, vert);
|
|
|
|
|
|
|
|
scheme.ComputeVertexLimitMask(vHood, vMask);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Apply mask to corresponding FVar values for neighboring vertices:
|
|
|
|
//
|
2014-11-04 01:31:24 +00:00
|
|
|
Vtr::Index vValue = vValues[0];
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[vValue].Clear();
|
2014-10-03 17:07:05 +00:00
|
|
|
if (vMask.GetNumFaceWeights() > 0) {
|
2014-11-18 01:19:30 +00:00
|
|
|
assert(!vMask.AreFaceWeightsForFaceCenters());
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray vFaces = level.getVertexFaces(vert);
|
|
|
|
ConstLocalIndexArray vInFace = level.getVertexFaceLocalIndices(vert);
|
2014-10-03 17:07:05 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < vFaces.size(); ++i) {
|
2014-12-15 18:23:13 +00:00
|
|
|
ConstIndexArray faceValues = fvarChannel.getFaceValues(vFaces[i]);
|
2014-11-18 01:19:30 +00:00
|
|
|
LocalIndex vOppInFace = vInFace[i] + 2;
|
|
|
|
if (vOppInFace >= faceValues.size()) vOppInFace -= faceValues.size();
|
|
|
|
|
|
|
|
Index vValueOppositeFace = faceValues[vOppInFace];
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[vValue].AddWithWeight(src[vValueOppositeFace], fWeights[i]);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vMask.GetNumEdgeWeights() > 0) {
|
|
|
|
Index * vEdgeValues = indexBuffer;
|
|
|
|
fvarChannel.getVertexEdgeValues(vert, vEdgeValues);
|
|
|
|
|
|
|
|
for (int i = 0; i < vEdges.size(); ++i) {
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[vValue].AddWithWeight(src[vEdgeValues[i]], eWeights[i]);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[vValue].AddWithWeight(src[vValue], vWeights[0]);
|
2014-10-03 17:07:05 +00:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Sibling FVar values associated with a vertex will be either a corner or a crease:
|
|
|
|
//
|
2014-11-04 01:31:24 +00:00
|
|
|
for (int i = 0; i < vValues.size(); ++i) {
|
|
|
|
Vtr::Index vValue = vValues[i];
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[vValue].Clear();
|
|
|
|
if (fvarChannel.getValueTag(vValue).isCorner()) {
|
|
|
|
dst[vValue].AddWithWeight(src[vValue], 1.0f);
|
2014-10-03 17:07:05 +00:00
|
|
|
} else {
|
|
|
|
Index vEndValues[2];
|
2014-11-04 01:31:24 +00:00
|
|
|
fvarChannel.getVertexCreaseEndValues(vert, i, vEndValues);
|
2014-10-03 17:07:05 +00:00
|
|
|
|
2014-11-04 01:31:24 +00:00
|
|
|
dst[vValue].AddWithWeight(src[vEndValues[0]], 1.0f/6.0f);
|
|
|
|
dst[vValue].AddWithWeight(src[vEndValues[1]], 1.0f/6.0f);
|
|
|
|
dst[vValue].AddWithWeight(src[vValue], 2.0f/3.0f);
|
2014-10-03 17:07:05 +00:00
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace Far
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif /* FAR_TOPOLOGY_REFINER_H */
|