FarSubdivisionTables: fixed vertsOffsets and removed unused members.

a new function is added to avoid confusion.
-GetNumVertices() returns number of vertices
-GetNumVerticesTotal() returns total number of vertices includins number of lower levels.

#closes 156
This commit is contained in:
Takahito Tejima 2013-04-25 12:01:06 -07:00
parent 643b664067
commit 3df04db2cd
5 changed files with 26 additions and 23 deletions

View File

@ -112,6 +112,7 @@ FarBilinearSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFact
// Prepare batch table // Prepare batch table
batches->reserve(maxlevel*5); batches->reserve(maxlevel*5);
int vertexOffset = 0;
int F_IT_offset = 0; int F_IT_offset = 0;
int faceTableOffset = 0; int faceTableOffset = 0;
int edgeTableOffset = 0; int edgeTableOffset = 0;
@ -125,8 +126,8 @@ FarBilinearSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFact
for (int level=1; level<=maxlevel; ++level) { for (int level=1; level<=maxlevel; ++level) {
// pointer to the first vertex corresponding to this level // pointer to the first vertex corresponding to this level
int vertexOffset = tablesFactory._vertVertIdx[level-1] + vertexOffset = tablesFactory._vertVertIdx[level-1] +
(int)tablesFactory._vertVertsList[level-1].size(); (int)tablesFactory._vertVertsList[level-1].size();
result->_vertsOffsets[level] = vertexOffset; result->_vertsOffsets[level] = vertexOffset;
// Face vertices // Face vertices
@ -214,6 +215,7 @@ FarBilinearSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFact
} }
V_ITa += nVertVertices; V_ITa += nVertVertices;
} }
result->_vertsOffsets[maxlevel+1] = vertexOffset;
return result; return result;
} }

View File

@ -116,6 +116,7 @@ FarCatmarkSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFacto
// Prepare batch table // Prepare batch table
batches->reserve(maxlevel*5); batches->reserve(maxlevel*5);
int vertexOffset = 0;
int F_IT_offset = 0; int F_IT_offset = 0;
int V_IT_offset = 0; int V_IT_offset = 0;
int faceTableOffset = 0; int faceTableOffset = 0;
@ -133,7 +134,8 @@ FarCatmarkSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFacto
for (int level=1; level<=maxlevel; ++level) { for (int level=1; level<=maxlevel; ++level) {
// pointer to the first vertex corresponding to this level // pointer to the first vertex corresponding to this level
int vertexOffset = tablesFactory._vertVertIdx[level-1] + (int)tablesFactory._vertVertsList[level-1].size(); vertexOffset = tablesFactory._vertVertIdx[level-1] +
(int)tablesFactory._vertVertsList[level-1].size();
result->_vertsOffsets[level] = vertexOffset; result->_vertsOffsets[level] = vertexOffset;
// Face vertices // Face vertices
@ -357,8 +359,8 @@ FarCatmarkSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFacto
batchFactory.AppendCatmarkBatches(batches, level, vertTableOffset, vertexOffset); batchFactory.AppendCatmarkBatches(batches, level, vertTableOffset, vertexOffset);
vertexOffset += nVertVertices; vertexOffset += nVertVertices;
vertTableOffset += nVertVertices; vertTableOffset += nVertVertices;
result->_numTotalVertices = vertexOffset;
} }
result->_vertsOffsets[maxlevel+1] = vertexOffset;
return result; return result;
} }

View File

@ -113,6 +113,7 @@ FarLoopSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFactory,
// Prepare batch table // Prepare batch table
batches->reserve(maxlevel*5); batches->reserve(maxlevel*5);
int vertexOffset = 0;
int V_IT_offset = 0; int V_IT_offset = 0;
int edgeTableOffset = 0; int edgeTableOffset = 0;
int vertTableOffset = 0; int vertTableOffset = 0;
@ -126,7 +127,7 @@ FarLoopSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFactory,
for (int level=1; level<=maxlevel; ++level) { for (int level=1; level<=maxlevel; ++level) {
// pointer to the first vertex corresponding to this level // pointer to the first vertex corresponding to this level
int vertexOffset = tablesFactory._vertVertIdx[level-1] + vertexOffset = tablesFactory._vertVertIdx[level-1] +
(int)tablesFactory._vertVertsList[level-1].size(); (int)tablesFactory._vertVertsList[level-1].size();
result->_vertsOffsets[level] = vertexOffset; result->_vertsOffsets[level] = vertexOffset;
@ -288,8 +289,8 @@ FarLoopSubdivisionTablesFactory<T,U>::Create( FarMeshFactory<T,U> * meshFactory,
batchFactory.AppendLoopBatches(batches, level, vertTableOffset, vertexOffset); batchFactory.AppendLoopBatches(batches, level, vertTableOffset, vertexOffset);
vertexOffset += nVertVertices; vertexOffset += nVertVertices;
vertTableOffset += nVertVertices; vertTableOffset += nVertVertices;
result->_numTotalVertices = vertexOffset;
} }
result->_vertsOffsets[maxlevel+1] = vertexOffset;
return result; return result;
} }

View File

@ -774,9 +774,6 @@ FarMeshFactory<T,U>::Create( bool requirePtexCoordinate, // XXX yuck.
assert(0); assert(0);
assert(result->_subdivisionTables); assert(result->_subdivisionTables);
const_cast<FarSubdivisionTables<U> *>(result->GetSubdivisionTables())->_numCoarseVertices=GetNumCoarseVertices();
// If the vertex classes aren't place-holders, copy the data of the coarse // If the vertex classes aren't place-holders, copy the data of the coarse
// vertices into the vertex buffer. // vertices into the vertex buffer.
result->_vertices.resize( _numVertices ); result->_vertices.resize( _numVertices );

View File

@ -102,7 +102,7 @@ public:
virtual ~FarSubdivisionTables<U>() {} virtual ~FarSubdivisionTables<U>() {}
/// Return the highest level of subdivision possible with these tables /// Return the highest level of subdivision possible with these tables
int GetMaxLevel() const { return (int)(_vertsOffsets.size()); } int GetMaxLevel() const { return (int)(_vertsOffsets.size()-1); }
/// Memory required to store the indexing tables /// Memory required to store the indexing tables
int GetMemoryUsed() const; int GetMemoryUsed() const;
@ -114,9 +114,12 @@ public:
/// represented by this set of FarCatmarkSubdivisionTables /// represented by this set of FarCatmarkSubdivisionTables
int GetFirstVertexOffset( int level ) const; int GetFirstVertexOffset( int level ) const;
// Total number of vertices at a given level /// Number of vertices at a given level
int GetNumVertices( int level ) const; int GetNumVertices( int level ) const;
/// Total number of vertices at a given level
int GetNumVerticesTotal( int level ) const;
/// Indexing tables accessors /// Indexing tables accessors
/// Returns the face vertices codex table /// Returns the face vertices codex table
@ -164,34 +167,32 @@ protected:
std::vector<float> _V_W; // weights std::vector<float> _V_W; // weights
std::vector<int> _vertsOffsets; // offset to the first vertex of each level std::vector<int> _vertsOffsets; // offset to the first vertex of each level
unsigned int _numCoarseVertices;
unsigned int _numTotalVertices;
}; };
template <class U> template <class U>
FarSubdivisionTables<U>::FarSubdivisionTables( FarMesh<U> * mesh, int maxlevel ) : FarSubdivisionTables<U>::FarSubdivisionTables( FarMesh<U> * mesh, int maxlevel ) :
_mesh(mesh), _mesh(mesh),
_vertsOffsets(maxlevel+1,0), _vertsOffsets(maxlevel+2, 0)
_numCoarseVertices(0)
{ {
assert( maxlevel > 0 ); assert( maxlevel > 0 );
} }
template <class U> int template <class U> int
FarSubdivisionTables<U>::GetFirstVertexOffset( int level ) const { FarSubdivisionTables<U>::GetFirstVertexOffset( int level ) const {
assert(level>=0 and level<=(int)_vertsOffsets.size()); assert(level>=0 and level<(int)_vertsOffsets.size());
return _vertsOffsets[level]; return _vertsOffsets[level];
} }
template <class U> int template <class U> int
FarSubdivisionTables<U>::GetNumVertices( int level ) const { FarSubdivisionTables<U>::GetNumVertices( int level ) const {
assert(level>=0 and level<=((int)_vertsOffsets.size()+1)); assert(level>=0 and level<((int)_vertsOffsets.size()-1));
if (level <= (int)_vertsOffsets.size()) return _vertsOffsets[level+1] - _vertsOffsets[level];
return _vertsOffsets[level+1]; }
else
return _numTotalVertices; template <class U> int
FarSubdivisionTables<U>::GetNumVerticesTotal( int level ) const {
assert(level>=0 and level<((int)_vertsOffsets.size()-1));
return _vertsOffsets[level+1];
} }
template <class U> int template <class U> int