mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2025-01-04 22:20:14 +00:00
Updates to simple cpu osdutil classes, split topology into a separate file, added first support for stencil evaluation.
Getting there, this code is being tested with Presto deformers and is working well. Valgrind reports no memory errors with the simple projectTest test harness.
This commit is contained in:
parent
2a825b9d1c
commit
3dda914e34
118
opensubdiv/osdutil/topology.cpp
Normal file
118
opensubdiv/osdutil/topology.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include "topology.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
PxOsdUtilSubdivTopology::PxOsdUtilSubdivTopology():
|
||||
name("noname"),
|
||||
numVertices(0),
|
||||
maxLevels(2) // arbitrary, start with a reasonable subdivision level
|
||||
{
|
||||
std::cout << "Creating subdiv topology object\n";
|
||||
}
|
||||
|
||||
PxOsdUtilSubdivTopology::~PxOsdUtilSubdivTopology()
|
||||
{
|
||||
std::cout << "Destroying subdiv topology object\n";
|
||||
}
|
||||
|
||||
bool
|
||||
PxOsdUtilSubdivTopology::Initialize(
|
||||
int numVerticesParam,
|
||||
const int *nvertsParam, int numFaces,
|
||||
const int *indicesParam, int indicesLen,
|
||||
int levels,
|
||||
string *errorMessage)
|
||||
{
|
||||
|
||||
numVertices = numVerticesParam;
|
||||
maxLevels = levels;
|
||||
|
||||
nverts.resize(numFaces);
|
||||
for (int i=0; i<numFaces; ++i) {
|
||||
nverts[i] = nvertsParam[i];
|
||||
}
|
||||
|
||||
indices.resize(indicesLen);
|
||||
for (int i=0; i<indicesLen; ++i) {
|
||||
indices[i] = indicesParam[i];
|
||||
}
|
||||
|
||||
return IsValid(errorMessage);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PxOsdUtilSubdivTopology::IsValid(string *errorMessage) const
|
||||
{
|
||||
if (numVertices == 0) {
|
||||
if (errorMessage) {
|
||||
stringstream ss;
|
||||
ss << "Topology " << name << " has no vertices";
|
||||
*errorMessage = ss.str();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i=0; i<(int)indices.size(); ++i) {
|
||||
if ((indices[i] < 0) or
|
||||
(indices[i] >= numVertices)) {
|
||||
if (errorMessage) {
|
||||
stringstream ss;
|
||||
ss << "Topology " << name << " has bad index " << indices[i] << " at index " << i;
|
||||
*errorMessage = ss.str();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int totalNumIndices = 0;
|
||||
for (int i=0; i< (int)nverts.size(); ++i) {
|
||||
if (nverts[i] < 1) {
|
||||
if (errorMessage) {
|
||||
stringstream ss;
|
||||
ss << "Topology " << name << " has bad nverts " << nverts[i] << " at index " << i;
|
||||
*errorMessage = ss.str();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
totalNumIndices += nverts[i];
|
||||
}
|
||||
|
||||
if (totalNumIndices != (int)indices.size()) {
|
||||
if (errorMessage) {
|
||||
*errorMessage = "Bad indexing for face topology";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PxOsdUtilSubdivTopology::Print() const
|
||||
{
|
||||
std::cout << "Mesh " << name << "\n";
|
||||
std::cout << "\tnumVertices = " << numVertices << "\n";
|
||||
std::cout << "\tmaxLevels = " << maxLevels << "\n";
|
||||
std::cout << "\tindices ( " << indices.size() << ") : ";
|
||||
for (int i=0; i<(int)indices.size(); ++i) {
|
||||
std::cout << indices[i] << ", ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
||||
std::cout << "\tnverts ( " << nverts.size() << ") : ";
|
||||
for (int i=0; i<(int)nverts.size(); ++i) {
|
||||
std::cout << nverts[i] << ", ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
||||
}
|
||||
|
68
opensubdiv/osdutil/topology.h
Normal file
68
opensubdiv/osdutil/topology.h
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef PX_OSD_UTIL_TOPOLOGY_H
|
||||
#define PX_OSD_UTIL_TOPOLOGY_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
// A value struct that holds annotations on a subdivision surface
|
||||
// such as creases, boundaries, holes, corners, hierarchical edits, etc.
|
||||
//
|
||||
// For OpenSubdiv documentation on tags, see:
|
||||
// See http://graphics.pixar.com/opensubdiv/docs/subdivision_surfaces.html#hierarchical-edits
|
||||
//
|
||||
struct PxOsdUtilTagData {
|
||||
std::vector<std::string> tags;
|
||||
std::vector<int> numArgs;
|
||||
std::vector<int> intArgs;
|
||||
std::vector<float> floatArgs;
|
||||
std::vector<std::string> stringArgs;
|
||||
};
|
||||
|
||||
// A value struct intended to hold within it topology for the base mesh
|
||||
// of a subdivision surface, and any annotation tags.
|
||||
// It is used to initialize classes that create and operate on subdivs.
|
||||
//
|
||||
class PxOsdUtilSubdivTopology {
|
||||
public:
|
||||
|
||||
PxOsdUtilSubdivTopology();
|
||||
~PxOsdUtilSubdivTopology();
|
||||
|
||||
// XXX Would be great for these members to be private with accessors
|
||||
std::string name;
|
||||
int numVertices;
|
||||
int maxLevels;
|
||||
std::vector<int> indices;
|
||||
std::vector<int> nverts;
|
||||
std::vector<std::string> vvNames;
|
||||
std::vector<std::string> fvNames;
|
||||
std::vector<float> fvData;
|
||||
PxOsdUtilTagData tagData;
|
||||
|
||||
|
||||
// Initialize using raw types.
|
||||
//
|
||||
// This is useful for automated tests initializing with data like:
|
||||
// int nverts[] = { 4, 4, 4, 4, 4, 4};
|
||||
//
|
||||
bool Initialize(
|
||||
int numVertices,
|
||||
const int *nverts, int numFaces,
|
||||
const int *indices, int indicesLen,
|
||||
int levels,
|
||||
std::string *errorMessage);
|
||||
|
||||
// checks indices etc to ensure that mesh isn't in a
|
||||
// broken state. Returns false on error, and will populate
|
||||
// errorMessage (if non-NULL) with a descriptive error message
|
||||
bool IsValid(std::string *errorMessage = NULL) const;
|
||||
|
||||
// for debugging, print the contents of the topology to stdout
|
||||
void Print() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* PX_OSD_UTIL_TOPOLOGY_H */
|
Loading…
Reference in New Issue
Block a user