// // 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. // #include "../far/topologyRefinerFactory.h" #include "../far/topologyRefiner.h" #include "../vtr/level.h" #if _MSC_VER #define snprintf _snprintf #endif namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { namespace Far { // // Methods for the Factory base class -- general enough to warrant including in // the base class rather than the subclass template (and so replicated for each // usage) // // void TopologyRefinerFactoryBase::validateComponentTopologySizing(TopologyRefiner& refiner) { Vtr::Level& baseLevel = refiner.getBaseLevel(); int vCount = baseLevel.getNumVertices(); int eCount = baseLevel.getNumEdges(); int fCount = baseLevel.getNumFaces(); assert((vCount > 0) && (fCount > 0)); // // This still needs a little work -- currently we are assuming all counts and offsets // have been assigned, but eventually only the counts will be assigined (in arbitrary // order) and we will need to accumulate the offsets to get the total sizes. That // will require new methods on Vtr::Level -- we do not want direct member access here. // int fVertCount = 0; for (int i = 0; i < fCount; ++i) { fVertCount += baseLevel.getNumFaceVertices(i); } baseLevel.resizeFaceVertices(fVertCount); assert(baseLevel.getNumFaceVerticesTotal() > 0); if (eCount > 0) { baseLevel.resizeFaceEdges(baseLevel.getNumFaceVerticesTotal()); baseLevel.resizeEdgeVertices(); baseLevel.resizeEdgeFaces( baseLevel.getNumEdgeFaces(eCount-1) + baseLevel.getOffsetOfEdgeFaces(eCount-1)); baseLevel.resizeVertexFaces(baseLevel.getNumVertexFaces(vCount-1) + baseLevel.getOffsetOfVertexFaces(vCount-1)); baseLevel.resizeVertexEdges(baseLevel.getNumVertexEdges(vCount-1) + baseLevel.getOffsetOfVertexEdges(vCount-1)); assert(baseLevel.getNumFaceEdgesTotal() > 0); assert(baseLevel.getNumEdgeVerticesTotal() > 0); assert(baseLevel.getNumEdgeFacesTotal() > 0); assert(baseLevel.getNumVertexFacesTotal() > 0); assert(baseLevel.getNumVertexEdgesTotal() > 0); } } void TopologyRefinerFactoryBase::validateFaceVaryingComponentTopologyAssignment(TopologyRefiner& refiner) { for (int channel=0; channel 0); vTag._rule = (Vtr::Level::VTag::VTagSize)creasing.DetermineVertexVertexRule(vSharpness, sharpEdgeCount); // // Assign topological tags -- note that the "xordinary" (or conversely a "regular") // tag is still being considered, but regardless, it depends on the Sdc::Scheme... // vTag._boundary = (vFaces.size() < vEdges.size()); if (isCorner) { vTag._xordinary = !sharpenCornerVerts; } else if (vTag._boundary) { vTag._xordinary = (vFaces.size() != schemeRegularBoundaryValence); } else { vTag._xordinary = (vFaces.size() != schemeRegularInteriorValence); } vTag._incomplete = 0; } // // Anything more to be done with Face tags? (eventually when processing edits perhaps) // // for (Vtr::Index fIndex = 0; fIndex < baseLevel.getNumFaces(); ++fIndex) { // } } // // Specialization for raw topology data // template <> void TopologyRefinerFactory::resizeComponentTopology( TopologyRefiner & refiner, TopologyDescriptor const & desc) { refiner.setNumBaseVertices(desc.numVertices); refiner.setNumBaseFaces(desc.numFaces); for (int face=0; face void TopologyRefinerFactory::assignComponentTopology( TopologyRefiner & refiner, TopologyDescriptor const & desc) { for (int face=0, idx=0; face void TopologyRefinerFactory::assignFaceVaryingTopology( TopologyRefiner & refiner, TopologyDescriptor const & desc) { if (desc.numFVarChannels>0) { for (int channel=0; channel void TopologyRefinerFactory::assignComponentTags( TopologyRefiner & refiner, TopologyDescriptor const & desc) { if ((desc.numCreases>0) and desc.creaseVertexIndexPairs and desc.creaseWeights) { int const * vertIndexPairs = desc.creaseVertexIndexPairs; for (int edge=0; edge0) and desc.cornerVertexIndices and desc.cornerWeights) { for (int vert=0; vert 0 and idx < refiner.GetNumVertices(0)) { refiner.baseVertexSharpness(idx) = desc.cornerWeights[vert]; } else { char msg[1024]; snprintf(msg, 1024, "Vertex %d specified to be sharp does not exist", idx); reportInvalidTopology(Vtr::Level::TOPOLOGY_INVALID_CREASE_VERT, msg, desc); } } } if (desc.numHoles>0) { for (int i=0; i void TopologyRefinerFactory::reportInvalidTopology( TopologyError /* errCode */, char const * msg, TopologyDescriptor const& /* mesh */) { Warning(msg); } TopologyRefinerFactoryBase::TopologyDescriptor::TopologyDescriptor() { memset(this, 0, sizeof(TopologyDescriptor)); } } // end namespace Far } // end namespace OPENSUBDIV_VERSION } // end namespace OpenSubdiv