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
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
#ifndef HBRHIERARCHICALEDIT_H
|
|
|
|
#define HBRHIERARCHICALEDIT_H
|
|
|
|
|
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 HbrHierarchicalEdit;
|
|
|
|
template <class T> class HbrFace;
|
|
|
|
template <class T> class HbrVertex;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class HbrHierarchicalEdit {
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef enum Operation {
|
2012-08-04 02:51:27 +00:00
|
|
|
Set,
|
|
|
|
Add,
|
|
|
|
Subtract
|
2012-06-08 18:18:20 +00:00
|
|
|
} Operation;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
HbrHierarchicalEdit(int _faceid, int _nsubfaces, unsigned char *_subfaces)
|
2012-08-04 02:51:27 +00:00
|
|
|
: faceid(_faceid), nsubfaces(_nsubfaces) {
|
|
|
|
subfaces = new unsigned char[_nsubfaces];
|
|
|
|
for (int i = 0; i < nsubfaces; ++i) {
|
|
|
|
subfaces[i] = _subfaces[i];
|
|
|
|
}
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HbrHierarchicalEdit(int _faceid, int _nsubfaces, int *_subfaces)
|
2012-08-04 02:51:27 +00:00
|
|
|
: faceid(_faceid), nsubfaces(_nsubfaces) {
|
|
|
|
subfaces = new unsigned char[_nsubfaces];
|
|
|
|
for (int i = 0; i < nsubfaces; ++i) {
|
|
|
|
subfaces[i] = static_cast<unsigned char>(_subfaces[i]);
|
|
|
|
}
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~HbrHierarchicalEdit() {
|
2012-08-04 02:51:27 +00:00
|
|
|
delete[] subfaces;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const HbrHierarchicalEdit& p) const {
|
2012-08-04 02:51:27 +00:00
|
|
|
if (faceid < p.faceid) return true;
|
|
|
|
if (faceid > p.faceid) return false;
|
|
|
|
int minlength = nsubfaces;
|
|
|
|
if (minlength > p.nsubfaces) minlength = p.nsubfaces;
|
|
|
|
for (int i = 0; i < minlength; ++i) {
|
|
|
|
if (subfaces[i] < p.subfaces[i]) return true;
|
|
|
|
if (subfaces[i] > p.subfaces[i]) return false;
|
|
|
|
}
|
|
|
|
return (nsubfaces < p.nsubfaces);
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the face id (the first element in the path)
|
|
|
|
int GetFaceID() const { return faceid; }
|
|
|
|
|
|
|
|
// Return the number of subfaces in the path
|
|
|
|
int GetNSubfaces() const { return nsubfaces; }
|
|
|
|
|
|
|
|
// Return a subface element in the path
|
|
|
|
unsigned char GetSubface(int index) const { return subfaces[index]; }
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
// Determines whether this hierarchical edit is relevant to the
|
|
|
|
// face in question
|
|
|
|
bool IsRelevantToFace(HbrFace<T>* face) const;
|
|
|
|
|
|
|
|
// Applys edit to face. All subclasses may override this method
|
|
|
|
virtual void ApplyEditToFace(HbrFace<T>* /* face */) {}
|
|
|
|
|
|
|
|
// Applys edit to vertex. Subclasses may override this method.
|
2012-08-04 02:51:27 +00:00
|
|
|
virtual void ApplyEditToVertex(HbrFace<T>* /* face */, HbrVertex<T>* /* vertex */) {}
|
2012-06-08 18:18:20 +00:00
|
|
|
|
|
|
|
#ifdef PRMAN
|
|
|
|
// Gets the effect of this hierarchical edit on the bounding box.
|
|
|
|
// Subclasses may override this method
|
2012-08-04 02:51:27 +00:00
|
|
|
virtual void ApplyToBound(struct bbox& /* box */, RtMatrix * /* mx */) const {}
|
2012-06-08 18:18:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// ID of the top most face in the mesh which begins the path
|
|
|
|
const int faceid;
|
|
|
|
|
|
|
|
// Number of subfaces
|
|
|
|
const int nsubfaces;
|
|
|
|
|
|
|
|
// IDs of the subfaces
|
|
|
|
unsigned char *subfaces;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class HbrHierarchicalEditComparator {
|
|
|
|
public:
|
2012-08-04 02:51:27 +00:00
|
|
|
bool operator() (const HbrHierarchicalEdit<T>* path1, const HbrHierarchicalEdit<T>* path2) const {
|
2012-06-08 18:18:20 +00:00
|
|
|
return (*path1 < *path2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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/face.h"
|
2012-08-20 19:58:00 +00:00
|
|
|
#include <cstring>
|
2012-06-08 18:18:20 +00:00
|
|
|
|
2012-06-15 01:47:57 +00:00
|
|
|
namespace OpenSubdiv {
|
|
|
|
namespace OPENSUBDIV_VERSION {
|
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
template <class T>
|
|
|
|
bool
|
|
|
|
HbrHierarchicalEdit<T>::IsRelevantToFace(HbrFace<T>* face) const {
|
|
|
|
|
|
|
|
// Key assumption: the face's first vertex edit is relevant to
|
|
|
|
// that face. We will then compare ourselves to that edit and if
|
|
|
|
// the first part of our subpath is identical to the entirety of
|
|
|
|
// that subpath, this edit is relevant.
|
|
|
|
|
|
|
|
// Calling code is responsible for making sure we don't
|
|
|
|
// dereference a null pointer here
|
|
|
|
HbrHierarchicalEdit<T>* p = *face->GetHierarchicalEdits();
|
|
|
|
if (!p) return false;
|
|
|
|
|
|
|
|
if (this == p) return true;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-06-08 18:18:20 +00:00
|
|
|
if (faceid != p->faceid) return false;
|
|
|
|
|
|
|
|
// If our path length is less than the face depth, it should mean
|
|
|
|
// that we're dealing with another face somewhere up the path, so
|
|
|
|
// we're not relevant
|
|
|
|
if (nsubfaces < face->GetDepth()) return false;
|
|
|
|
|
|
|
|
if (memcmp(subfaces, p->subfaces, face->GetDepth() * sizeof(unsigned char)) != 0) {
|
2012-08-04 02:51:27 +00:00
|
|
|
return false;
|
2012-06-08 18:18:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
#endif /* HBRHIERARCHICALEDIT_H */
|