- Fix Importer::FindLoader - it failed on file extensions with only one character (i.e. x). This fixes an unit test.

- Revert VTAdj code. It fails the unit test and the new facility (support arbitrary polygons instead of triangles only) is not used anywhere.
- Unit test suite passes now.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@592 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-03-11 16:47:36 +00:00
parent 4f6d81a29b
commit 08ace2f27b
2 changed files with 36 additions and 46 deletions

View File

@ -968,7 +968,7 @@ BaseImporter* Importer::FindLoader (const char* szExtension)
for(;*szExtension == '*' || *szExtension == '.'; ++szExtension); for(;*szExtension == '*' || *szExtension == '.'; ++szExtension);
std::string ext(szExtension); std::string ext(szExtension);
if (ext.length() <= 1) if (ext.empty())
return NULL; return NULL;
std::set<std::string> str; std::set<std::string> str;

View File

@ -39,103 +39,93 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
*/ */
/** @file Implementation of the VertexTriangleAdjacency helper class */ /** @file Implementation of the VertexTriangleAdjacency helper class
*/
#include "AssimpPCH.h" #include "AssimpPCH.h"
// internal headers // internal headers
#include "VertexTriangleAdjacency.h" #include "VertexTriangleAdjacency.h"
using namespace Assimp; using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Compute a vertex-to-faces adjacency table. To save small memory allocations, the information
// is encoded in three continous buffers - the offset table maps a single vertex index to an
// entry in the adjacency table, which in turn contains n entries, which are the faces adjacent
// to the vertex. n is taken from the third buffer, which stores face counts per vertex.
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces, VertexTriangleAdjacency::VertexTriangleAdjacency(aiFace *pcFaces,
unsigned int iNumFaces, unsigned int iNumFaces,
unsigned int iNumVertices /*= 0*/, unsigned int iNumVertices /*= 0*/,
bool bComputeNumTriangles /*= false*/) bool bComputeNumTriangles /*= false*/)
{ {
// --------------------------------------------------------------------- // compute the number of referenced vertices if it wasn't specified by the caller
// 0: compute the number of referenced vertices if not
// specified by the caller.
// ---------------------------------------------------------------------
const aiFace* const pcFaceEnd = pcFaces + iNumFaces; const aiFace* const pcFaceEnd = pcFaces + iNumFaces;
if (!iNumVertices) { if (!iNumVertices) {
for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) { for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) {
for (unsigned int i = 0; i < pcFace->mNumIndices; ++i) { ai_assert(3 == pcFace->mNumIndices);
iNumVertices = std::max(iNumVertices,pcFace->mIndices[i]); iNumVertices = std::max(iNumVertices,pcFace->mIndices[0]);
} iNumVertices = std::max(iNumVertices,pcFace->mIndices[1]);
iNumVertices = std::max(iNumVertices,pcFace->mIndices[2]);
} }
} }
unsigned int* pi; unsigned int* pi;
// --------------------------------------------------------------------- // allocate storage
// 1. Allocate output storage
// ---------------------------------------------------------------------
if (bComputeNumTriangles) { if (bComputeNumTriangles) {
pi = mLiveTriangles = new unsigned int[iNumVertices+1]; pi = mLiveTriangles = new unsigned int[iNumVertices+1];
memset(mLiveTriangles,0,sizeof(unsigned int)*(iNumVertices+1)); memset(mLiveTriangles,0,sizeof(unsigned int)*(iNumVertices+1));
mOffsetTable = new unsigned int[iNumVertices+2]+1; mOffsetTable = new unsigned int[iNumVertices+2]+1;
} }
else { else {
pi = mOffsetTable = new unsigned int[iNumVertices+2]+1; pi = mOffsetTable = new unsigned int[iNumVertices+2]+1;
memset(mOffsetTable,0,sizeof(unsigned int)*(iNumVertices+1)); memset(mOffsetTable,0,sizeof(unsigned int)*(iNumVertices+1));
// important, otherwise the d'tor would crash mLiveTriangles = NULL; // important, otherwise the d'tor would crash
mLiveTriangles = NULL;
} }
// get a pointer to the end of the buffer
unsigned int* piEnd = pi+iNumVertices; unsigned int* piEnd = pi+iNumVertices;
*piEnd++ = 0u; *piEnd++ = 0u;
// --------------------------------------------------------------------- // first pass: compute the number of faces referencing each vertex
// 2. Compute the number of faces referencing each vertex for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace)
// --------------------------------------------------------------------- {
for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace) { pi[pcFace->mIndices[0]]++;
for (unsigned int i = 0; i < pcFace->mNumIndices; ++i) { pi[pcFace->mIndices[1]]++;
pi[pcFace->mIndices[i]]++; pi[pcFace->mIndices[2]]++;
}
} }
// --------------------------------------------------------------------- // second pass: compute the final offset table
// 3. Compute the offset table to map each face to a
// start position in the adjacency table.
// ---------------------------------------------------------------------
unsigned int iSum = 0; unsigned int iSum = 0;
unsigned int* piCurOut = mOffsetTable; unsigned int* piCurOut = this->mOffsetTable;
for (unsigned int* piCur = pi; piCur != piEnd;++piCur,++piCurOut) { for (unsigned int* piCur = pi; piCur != piEnd;++piCur,++piCurOut) {
unsigned int iLastSum = iSum; unsigned int iLastSum = iSum;
iSum += *piCur; iSum += *piCur;
*piCurOut = iLastSum; *piCurOut = iLastSum;
} }
pi = mOffsetTable; pi = this->mOffsetTable;
// --------------------------------------------------------------------- // third pass: compute the final table
// 4. Compute the final adjacency table this->mAdjacencyTable = new unsigned int[iSum];
// ---------------------------------------------------------------------
mAdjacencyTable = new unsigned int[iSum];
iSum = 0; iSum = 0;
for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace,++iSum) { for (aiFace* pcFace = pcFaces; pcFace != pcFaceEnd; ++pcFace,++iSum) {
for (unsigned int i = 0; i < pcFace->mNumIndices; ++i) {
mAdjacencyTable[pi[pcFace->mIndices[i]]++] = iSum;
}
}
// --------------------------------------------------------------------- unsigned int idx = pcFace->mIndices[0];
// 5. Undo the offset computations made during step 4 mAdjacencyTable[pi[idx]++] = iSum;
// ---------------------------------------------------------------------
idx = pcFace->mIndices[1];
mAdjacencyTable[pi[idx]++] = iSum;
idx = pcFace->mIndices[2];
mAdjacencyTable[pi[idx]++] = iSum;
}
// fourth pass: undo the offset computations made during the third pass
// We could do this in a separate buffer, but this would be TIMES slower.
--mOffsetTable; --mOffsetTable;
*mOffsetTable = 0u; *mOffsetTable = 0u;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
VertexTriangleAdjacency::~VertexTriangleAdjacency() VertexTriangleAdjacency::~VertexTriangleAdjacency()
{ {
// delete allocated storage
delete[] mOffsetTable; delete[] mOffsetTable;
delete[] mAdjacencyTable; delete[] mAdjacencyTable;
delete[] mLiveTriangles; delete[] mLiveTriangles;