2012-06-08 18:18:20 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-06-08 18:18:20 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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:
|
2012-06-08 18:18:20 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-06-08 18:18:20 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-06-08 18:18:20 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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.
|
2012-06-08 18:18:20 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#ifndef OPENSUBDIV3_HBRFVARDATA_H
|
|
|
|
#define OPENSUBDIV3_HBRFVARDATA_H
|
2012-06-08 18:18:20 +00:00
|
|
|
|
2012-08-20 19:58:00 +00:00
|
|
|
#include <cstring>
|
2012-06-08 18:18:20 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2012-06-15 01:47:57 +00:00
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
template <class T> class HbrFVarEdit;
|
|
|
|
template <class T> class HbrFace;
|
2013-07-18 16:07:28 +00:00
|
|
|
template <class T> class HbrVertex;
|
2012-06-08 18:18:20 +00:00
|
|
|
|
|
|
|
// This class implements a "face varying vector item". Really it's
|
|
|
|
// just a smart wrapper around face varying data (itself just a bunch
|
|
|
|
// of floats) stored on each vertex.
|
|
|
|
template <class T> class HbrFVarData {
|
|
|
|
|
2013-07-18 16:07:28 +00:00
|
|
|
private:
|
2013-01-10 18:47:50 +00:00
|
|
|
HbrFVarData()
|
2013-01-22 22:47:46 +00:00
|
|
|
: faceid(0), initialized(0) {
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~HbrFVarData() {
|
|
|
|
Uninitialize();
|
|
|
|
}
|
|
|
|
|
2014-05-15 20:34:32 +00:00
|
|
|
HbrFVarData(const HbrFVarData &/* data */) {}
|
2013-07-18 16:07:28 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-01-10 18:47:50 +00:00
|
|
|
// Sets the face id
|
|
|
|
void SetFaceID(int id) {
|
|
|
|
faceid = id;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 18:47:50 +00:00
|
|
|
// Returns the id of the face to which this data is bound
|
|
|
|
int GetFaceID() const {
|
|
|
|
return faceid;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
// Clears the initialized flag
|
|
|
|
void Uninitialize() {
|
2013-01-10 18:47:50 +00:00
|
|
|
initialized = 0;
|
|
|
|
faceid = 0;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns initialized flag
|
|
|
|
bool IsInitialized() const {
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets initialized flag
|
|
|
|
void SetInitialized() {
|
2013-01-10 18:47:50 +00:00
|
|
|
initialized = 1;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
// Return the data from the NgpFVVector
|
2013-01-10 18:47:50 +00:00
|
|
|
float* GetData(int item) { return data + item; }
|
2012-06-08 18:18:20 +00:00
|
|
|
|
|
|
|
// Clears the indicates value of this item
|
|
|
|
void Clear(int startindex, int width) {
|
|
|
|
memset(data + startindex, 0, width * sizeof(float));
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// Clears all values of this item
|
2012-06-08 18:18:20 +00:00
|
|
|
void ClearAll(int width) {
|
2013-01-10 18:47:50 +00:00
|
|
|
initialized = 1;
|
2012-06-08 18:18:20 +00:00
|
|
|
memset(data, 0, width * sizeof(float));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set values of the indicated item (with the indicated weighing)
|
|
|
|
// on this item
|
|
|
|
void SetWithWeight(const HbrFVarData& fvvi, int startindex, int width, float weight) {
|
2013-01-10 18:47:50 +00:00
|
|
|
float *dst = data + startindex;
|
|
|
|
const float *src = fvvi.data + startindex;
|
2012-08-04 02:51:27 +00:00
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
*dst++ = weight * *src++;
|
|
|
|
}
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
// Add values of the indicated item (with the indicated weighing)
|
|
|
|
// to this item
|
|
|
|
void AddWithWeight(const HbrFVarData& fvvi, int startindex, int width, float weight) {
|
2013-01-10 18:47:50 +00:00
|
|
|
float *dst = data + startindex;
|
|
|
|
const float *src = fvvi.data + startindex;
|
2012-08-04 02:51:27 +00:00
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
*dst++ += weight * *src++;
|
|
|
|
}
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add all values of the indicated item (with the indicated
|
|
|
|
// weighing) to this item
|
|
|
|
void AddWithWeightAll(const HbrFVarData& fvvi, int width, float weight) {
|
2013-01-10 18:47:50 +00:00
|
|
|
float *dst = data;
|
|
|
|
const float *src = fvvi.data;
|
2012-08-04 02:51:27 +00:00
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
*dst++ += weight * *src++;
|
|
|
|
}
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compare all values item against a float buffer. Returns true
|
|
|
|
// if all values match
|
|
|
|
bool CompareAll(int width, const float *values, float tolerance=0.0f) const {
|
|
|
|
if (!initialized) return false;
|
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
if (fabsf(values[i] - data[i]) > tolerance) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes data
|
|
|
|
void SetAllData(int width, const float *values) {
|
2013-01-10 18:47:50 +00:00
|
|
|
initialized = 1;
|
2012-06-08 18:18:20 +00:00
|
|
|
memcpy(data, values, width * sizeof(float));
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
// Compare this item against another item with tolerance. Returns
|
|
|
|
// true if it compares identical
|
|
|
|
bool Compare(const HbrFVarData& fvvi, int startindex, int width, float tolerance=0.0f) const {
|
|
|
|
for (int i = 0; i < width; ++i) {
|
|
|
|
if (fabsf(data[startindex + i] - fvvi.data[startindex + i]) > tolerance) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Modify the data of the item with an edit
|
|
|
|
void ApplyFVarEdit(const HbrFVarEdit<T>& edit);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-07-18 16:07:28 +00:00
|
|
|
friend class HbrVertex<T>;
|
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
private:
|
2013-01-10 18:47:50 +00:00
|
|
|
unsigned int faceid:31;
|
|
|
|
unsigned int initialized:1;
|
|
|
|
float data[1];
|
2012-06-08 18:18:20 +00:00
|
|
|
};
|
|
|
|
|
2012-06-15 01:47:57 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
#include "../hbr/fvarEdit.h"
|
|
|
|
|
2012-06-15 01:47:57 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
template <class T>
|
|
|
|
void
|
|
|
|
HbrFVarData<T>::ApplyFVarEdit(const HbrFVarEdit<T>& edit) {
|
2012-08-04 02:51:27 +00:00
|
|
|
float *dst = data + edit.GetIndex() + edit.GetOffset();
|
|
|
|
const float *src = edit.GetEdit();
|
|
|
|
for (int i = 0; i < edit.GetWidth(); ++i) {
|
|
|
|
switch(edit.GetOperation()) {
|
|
|
|
case HbrVertexEdit<T>::Set:
|
|
|
|
*dst++ = *src++;
|
|
|
|
break;
|
|
|
|
case HbrVertexEdit<T>::Add:
|
|
|
|
*dst++ += *src++;
|
|
|
|
break;
|
|
|
|
case HbrVertexEdit<T>::Subtract:
|
|
|
|
*dst++ -= *src++;
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 18:47:50 +00:00
|
|
|
initialized = 1;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-15 01:47:57 +00:00
|
|
|
} // end namespace OPENSUBDIV_VERSION
|
|
|
|
using namespace OPENSUBDIV_VERSION;
|
|
|
|
|
|
|
|
} // end namespace OpenSubdiv
|
|
|
|
|
2015-05-19 18:22:37 +00:00
|
|
|
#endif /* OPENSUBDIV3_HBRFVARDATA_H */
|