2012-08-04 02:51:27 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) Pixar. All rights reserved.
|
|
|
|
//
|
|
|
|
// This license governs use of the accompanying software. If you
|
|
|
|
// use the software, you accept this license. If you do not accept
|
|
|
|
// the license, do not use the software.
|
|
|
|
//
|
|
|
|
// 1. Definitions
|
|
|
|
// The terms "reproduce," "reproduction," "derivative works," and
|
|
|
|
// "distribution" have the same meaning here as under U.S.
|
|
|
|
// copyright law. A "contribution" is the original software, or
|
|
|
|
// any additions or changes to the software.
|
|
|
|
// A "contributor" is any person or entity that distributes its
|
|
|
|
// contribution under this license.
|
|
|
|
// "Licensed patents" are a contributor's patent claims that read
|
|
|
|
// directly on its contribution.
|
|
|
|
//
|
|
|
|
// 2. Grant of Rights
|
|
|
|
// (A) Copyright Grant- Subject to the terms of this license,
|
|
|
|
// including the license conditions and limitations in section 3,
|
|
|
|
// each contributor grants you a non-exclusive, worldwide,
|
|
|
|
// royalty-free copyright license to reproduce its contribution,
|
|
|
|
// prepare derivative works of its contribution, and distribute
|
|
|
|
// its contribution or any derivative works that you create.
|
|
|
|
// (B) Patent Grant- Subject to the terms of this license,
|
|
|
|
// including the license conditions and limitations in section 3,
|
|
|
|
// each contributor grants you a non-exclusive, worldwide,
|
|
|
|
// royalty-free license under its licensed patents to make, have
|
|
|
|
// made, use, sell, offer for sale, import, and/or otherwise
|
|
|
|
// dispose of its contribution in the software or derivative works
|
|
|
|
// of the contribution in the software.
|
|
|
|
//
|
|
|
|
// 3. Conditions and Limitations
|
|
|
|
// (A) No Trademark License- This license does not grant you
|
|
|
|
// rights to use any contributor's name, logo, or trademarks.
|
|
|
|
// (B) If you bring a patent claim against any contributor over
|
|
|
|
// patents that you claim are infringed by the software, your
|
|
|
|
// patent license from such contributor to the software ends
|
|
|
|
// automatically.
|
|
|
|
// (C) If you distribute any portion of the software, you must
|
|
|
|
// retain all copyright, patent, trademark, and attribution
|
|
|
|
// notices that are present in the software.
|
|
|
|
// (D) If you distribute any portion of the software in source
|
|
|
|
// code form, you may do so only under this license by including a
|
|
|
|
// complete copy of this license with your distribution. If you
|
|
|
|
// distribute any portion of the software in compiled or object
|
|
|
|
// code form, you may only do so under a license that complies
|
|
|
|
// with this license.
|
|
|
|
// (E) The software is licensed "as-is." You bear the risk of
|
|
|
|
// using it. The contributors give no express warranties,
|
|
|
|
// guarantees or conditions. You may have additional consumer
|
|
|
|
// rights under your local laws which this license cannot change.
|
|
|
|
// To the extent permitted under your local laws, the contributors
|
|
|
|
// exclude the implied warranties of merchantability, fitness for
|
|
|
|
// a particular purpose and non-infringement.
|
|
|
|
//
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
#ifndef FAR_VERTEX_EDIT_TABLES_H
|
|
|
|
#define FAR_VERTEX_EDIT_TABLES_H
|
|
|
|
|
|
|
|
#include "../version.h"
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
template <class U> class FarMesh;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-10-07 00:53:51 +00:00
|
|
|
/// \brief A serialized container for hierarchical edits.
|
|
|
|
///
|
|
|
|
/// Some of the hierarchical edits are resolved into the vertex weights computed
|
|
|
|
/// into the FarSubdivision tables. Certain edits however have to be "post-processed"
|
|
|
|
/// after the tables are applied to the vertices and require their HBR representation
|
|
|
|
/// to be serialized into a specific container.
|
|
|
|
///
|
2012-09-18 01:41:48 +00:00
|
|
|
class FarVertexEdit {
|
2013-05-07 02:05:50 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
public:
|
2012-10-07 00:53:51 +00:00
|
|
|
/// Type of edit operation - equivalent to HbrHiearachicalEdit<T>::Operation
|
2012-08-04 02:51:27 +00:00
|
|
|
enum Operation {
|
|
|
|
Set,
|
|
|
|
Add
|
2012-10-07 00:53:51 +00:00
|
|
|
/// Note : subtract edits are converted to Add edits for better serialization
|
2012-08-04 02:51:27 +00:00
|
|
|
};
|
|
|
|
|
2012-10-07 00:53:51 +00:00
|
|
|
/// Get the type of operation
|
2012-09-18 01:41:48 +00:00
|
|
|
Operation GetOperation() const { return _op; }
|
|
|
|
|
2012-10-07 00:53:51 +00:00
|
|
|
/// Return index of variable this edit applies to
|
2012-09-18 01:41:48 +00:00
|
|
|
int GetIndex() const { return _index; }
|
|
|
|
|
2012-10-07 00:53:51 +00:00
|
|
|
/// Return width of the variable
|
2012-09-18 01:41:48 +00:00
|
|
|
int GetWidth() const { return _width; }
|
|
|
|
|
2012-10-07 00:53:51 +00:00
|
|
|
/// Get the numerical value of the edit
|
2012-09-18 01:41:48 +00:00
|
|
|
const float* GetEdit() const { return _edit; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <class U> friend class FarVertexEditTables;
|
|
|
|
|
|
|
|
FarVertexEdit(Operation op, int index, int width) :
|
|
|
|
_op(op), _edit(0), _index(index), _width(width)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void SetEdit(float const * edit) { _edit=edit; }
|
|
|
|
|
|
|
|
Operation _op;
|
|
|
|
float const * _edit;
|
|
|
|
int _index,
|
|
|
|
_width;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class U> class FarVertexEditTables {
|
|
|
|
public:
|
2013-03-08 01:50:15 +00:00
|
|
|
FarVertexEditTables( FarMesh<U> * mesh );
|
2012-09-18 01:41:48 +00:00
|
|
|
|
|
|
|
// Note : Subtract type edits are converted into Adds in order to save kernel calls.
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
int GetNumBatches() const {
|
|
|
|
return (int)_batches.size();
|
|
|
|
}
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
// This class holds an array of edits. each batch has unique index/width/operation
|
|
|
|
class VertexEditBatch {
|
2012-08-04 02:51:27 +00:00
|
|
|
public:
|
2012-09-18 01:41:48 +00:00
|
|
|
VertexEditBatch(int index, int width, FarVertexEdit::Operation operation);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// copy vertex id and edit values into table
|
|
|
|
void Append(int level, int vertexID, const float *values, bool negate);
|
|
|
|
|
|
|
|
// Compute-kernel applied to vertices
|
2013-03-08 01:50:15 +00:00
|
|
|
void ApplyVertexEdits(U * vsrc, int offset, int tableOffset, int start, int end) const;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// Edit tables accessors
|
|
|
|
|
|
|
|
// Returns the edit offset table
|
2013-03-08 01:50:15 +00:00
|
|
|
const std::vector<unsigned int> &GetVertexIndices() const { return _vertIndices; }
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// Returns the edit values table
|
2013-03-08 01:50:15 +00:00
|
|
|
const std::vector<float> &GetValues() const { return _edits; }
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
FarVertexEdit::Operation GetOperation() const { return _op; }
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
int GetPrimvarIndex() const { return _primvarIndex; }
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
int GetPrimvarWidth() const { return _primvarWidth; }
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
private:
|
2012-12-11 01:15:13 +00:00
|
|
|
template <class X, class Y> friend class FarVertexEditTablesFactory;
|
2013-03-08 01:50:15 +00:00
|
|
|
template <class X, class Y> friend class FarMultiMeshFactory;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
std::vector<unsigned int> _vertIndices; // absolute vertex index array for edits
|
|
|
|
std::vector<float> _edits; // edit values array
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
int _primvarIndex, // primvar offset in vertex
|
|
|
|
_primvarWidth; // numElements per vertex in values
|
|
|
|
FarVertexEdit::Operation _op; // edit operation (Set, Add)
|
2012-08-04 02:51:27 +00:00
|
|
|
};
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
VertexEditBatch const & GetBatch(int index) const {
|
2012-08-04 02:51:27 +00:00
|
|
|
return _batches[index];
|
|
|
|
}
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
private:
|
2012-12-11 01:15:13 +00:00
|
|
|
template <class X, class Y> friend class FarVertexEditTablesFactory;
|
2013-03-08 01:50:15 +00:00
|
|
|
template <class X, class Y> friend class FarMultiMeshFactory;
|
|
|
|
template <class CONTROLLER> friend class FarComputeController;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
// Compute-kernel that applies the edits
|
2013-03-08 01:50:15 +00:00
|
|
|
void computeVertexEdits(int tableIndex, int offset, int tableOffset, int start, int end, void *clientdata) const;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// mesh that owns this vertexEditTable
|
2012-09-18 01:41:48 +00:00
|
|
|
FarMesh<U> * _mesh;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
// XXX(dyu): seems like there is a compiler bug in g++ that requires
|
|
|
|
// this struct to be public
|
|
|
|
public:
|
|
|
|
#endif
|
2012-09-18 01:41:48 +00:00
|
|
|
std::vector<VertexEditBatch> _batches;
|
2012-08-04 02:51:27 +00:00
|
|
|
};
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
template <class U>
|
|
|
|
FarVertexEditTables<U>::VertexEditBatch::VertexEditBatch(int index, int width, FarVertexEdit::Operation op) :
|
|
|
|
_primvarIndex(index),
|
|
|
|
_primvarWidth(width),
|
|
|
|
_op(op) {
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
template <class U>
|
2012-08-04 02:51:27 +00:00
|
|
|
void
|
2013-03-08 01:50:15 +00:00
|
|
|
FarVertexEditTables<U>::VertexEditBatch::ApplyVertexEdits(U * vsrc, int vertexOffset, int tableOffset, int start, int end) const
|
2012-08-04 02:51:27 +00:00
|
|
|
{
|
2013-03-08 01:50:15 +00:00
|
|
|
int primvarWidth = GetPrimvarWidth();
|
|
|
|
assert(tableOffset+end <= (int)_vertIndices.size());
|
|
|
|
const unsigned int * vindices = &_vertIndices[tableOffset];
|
|
|
|
const float * values = &_edits[tableOffset * primvarWidth];
|
2012-09-18 01:41:48 +00:00
|
|
|
FarVertexEdit edit( GetOperation(), GetPrimvarIndex(), GetPrimvarWidth() );
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
for (int i=start; i<end; ++i) {
|
|
|
|
U * vdst = vsrc + vindices[i] + vertexOffset;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
edit.SetEdit(const_cast<float*>(&values[i*primvarWidth]));
|
|
|
|
vdst->ApplyVertexEdit(edit);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
template <class U>
|
2013-03-08 01:50:15 +00:00
|
|
|
FarVertexEditTables<U>::FarVertexEditTables( FarMesh<U> * mesh ) :
|
2012-08-04 02:51:27 +00:00
|
|
|
_mesh(mesh) {
|
|
|
|
}
|
|
|
|
|
2012-09-18 01:41:48 +00:00
|
|
|
template <class U> void
|
2013-03-08 01:50:15 +00:00
|
|
|
FarVertexEditTables<U>::computeVertexEdits(int tableIndex, int offset, int tableOffset, int start, int end, void *clientdata) const {
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
assert(this->_mesh);
|
|
|
|
|
|
|
|
U * vsrc = &this->_mesh->GetVertices().at(0);
|
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
_batches[tableIndex].ApplyVertexEdits(vsrc, offset, tableOffset, start, end);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
|
|
|
#endif /* FAR_VERTEX_EDIT_TABLES_H */
|