PLY: prepare bugfix by adding missing unittest.

pull/1180/head
Kim Kulling 2017-02-11 14:19:34 +01:00
parent 615bdb27d9
commit a75fa44bde
6 changed files with 3395 additions and 3277 deletions

View File

@ -53,7 +53,7 @@ struct aiNode;
struct aiMaterial; struct aiMaterial;
struct aiMesh; struct aiMesh;
namespace Assimp { namespace Assimp {
using namespace PLY; using namespace PLY;

View File

@ -53,9 +53,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp; using namespace Assimp;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOut) PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOut) {
{ ai_assert( NULL != pCur );
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCurOut );
PLY::EDataType eOut = PLY::EDT_INVALID; PLY::EDataType eOut = PLY::EDT_INVALID;
if (TokenMatch(pCur,"char",4) || if (TokenMatch(pCur,"char",4) ||
@ -100,33 +101,25 @@ PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOu
DefaultLogger::get()->info("Found unknown data type in PLY file. This is OK"); DefaultLogger::get()->info("Found unknown data type in PLY file. This is OK");
} }
*pCurOut = pCur; *pCurOut = pCur;
return eOut; return eOut;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
PLY::ESemantic PLY::Property::ParseSemantic(const char* pCur,const char** pCurOut) PLY::ESemantic PLY::Property::ParseSemantic(const char* pCur,const char** pCurOut) {
{ ai_assert (NULL != pCur );
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCurOut );
PLY::ESemantic eOut = PLY::EST_INVALID; PLY::ESemantic eOut = PLY::EST_INVALID;
if (TokenMatch(pCur,"red",3)) if (TokenMatch(pCur,"red",3)) {
{
eOut = PLY::EST_Red; eOut = PLY::EST_Red;
} } else if (TokenMatch(pCur,"green",5)) {
else if (TokenMatch(pCur,"green",5))
{
eOut = PLY::EST_Green; eOut = PLY::EST_Green;
} } else if (TokenMatch(pCur,"blue",4)) {
else if (TokenMatch(pCur,"blue",4))
{
eOut = PLY::EST_Blue; eOut = PLY::EST_Blue;
} } else if (TokenMatch(pCur,"alpha",5)) {
else if (TokenMatch(pCur,"alpha",5))
{
eOut = PLY::EST_Alpha; eOut = PLY::EST_Alpha;
} } else if (TokenMatch(pCur,"vertex_index",12) || TokenMatch(pCur,"vertex_indices",14)) {
else if (TokenMatch(pCur,"vertex_index",12) || TokenMatch(pCur,"vertex_indices",14))
{
eOut = PLY::EST_VertexIndex; eOut = PLY::EST_VertexIndex;
} }
else if (TokenMatch(pCur,"material_index",14)) else if (TokenMatch(pCur,"material_index",14))
@ -248,7 +241,8 @@ bool PLY::Property::ParseProperty (const char* pCur,
const char** pCurOut, const char** pCurOut,
PLY::Property* pOut) PLY::Property* pOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
// Forms supported: // Forms supported:
// "property float x" // "property float x"
@ -256,7 +250,9 @@ bool PLY::Property::ParseProperty (const char* pCur,
*pCurOut = pCur; *pCurOut = pCur;
// skip leading spaces // skip leading spaces
if (!SkipSpaces(pCur,&pCur))return false; if (!SkipSpaces(pCur,&pCur)) {
return false;
}
// skip the "property" string at the beginning // skip the "property" string at the beginning
if (!TokenMatch(pCur,"property",8)) if (!TokenMatch(pCur,"property",8))
@ -265,7 +261,9 @@ bool PLY::Property::ParseProperty (const char* pCur,
return false; return false;
} }
// get next word // get next word
if (!SkipSpaces(pCur,&pCur))return false; if (!SkipSpaces(pCur,&pCur)) {
return false;
}
if (TokenMatch(pCur,"list",4)) if (TokenMatch(pCur,"list",4))
{ {
pOut->bIsList = true; pOut->bIsList = true;
@ -313,6 +311,7 @@ bool PLY::Property::ParseProperty (const char* pCur,
SkipSpacesAndLineEnd(pCur,&pCur); SkipSpacesAndLineEnd(pCur,&pCur);
*pCurOut = pCur; *pCurOut = pCur;
return true; return true;
} }
@ -350,6 +349,7 @@ PLY::EElementSemantic PLY::Element::ParseSemantic(const char* pCur,
eOut = PLY::EEST_Material; eOut = PLY::EEST_Material;
} }
*pCurOut = pCur; *pCurOut = pCur;
return eOut; return eOut;
} }
@ -358,13 +358,17 @@ bool PLY::Element::ParseElement (const char* pCur,
const char** pCurOut, const char** pCurOut,
PLY::Element* pOut) PLY::Element* pOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != pOut );
// Example format: "element vertex 8" // Example format: "element vertex 8"
*pCurOut = pCur; *pCurOut = pCur;
// skip leading spaces // skip leading spaces
if (!SkipSpaces(&pCur))return false; if (!SkipSpaces(&pCur)) {
return false;
}
// skip the "element" string at the beginning // skip the "element" string at the beginning
if (!TokenMatch(pCur,"element",7)) if (!TokenMatch(pCur,"element",7))
@ -405,6 +409,7 @@ bool PLY::Element::ParseElement (const char* pCur,
pOut->alProperties.push_back(prop); pOut->alProperties.push_back(prop);
} }
*pCurOut = pCur; *pCurOut = pCur;
return true; return true;
} }
@ -412,30 +417,35 @@ bool PLY::Element::ParseElement (const char* pCur,
bool PLY::DOM::SkipComments (const char* pCur, bool PLY::DOM::SkipComments (const char* pCur,
const char** pCurOut) const char** pCurOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
*pCurOut = pCur; *pCurOut = pCur;
// skip spaces // skip spaces
if (!SkipSpaces(pCur,&pCur))return false; if (!SkipSpaces(pCur,&pCur)) {
return false;
}
if (TokenMatch(pCur,"comment",7)) if (TokenMatch(pCur,"comment",7))
{ {
if ( !IsLineEnd(pCur[-1]) ) if ( !IsLineEnd(pCur[-1]) )
{ {
SkipLine(pCur,&pCur); SkipLine(pCur,&pCur);
} }
SkipComments(pCur,&pCur); SkipComments(pCur,&pCur);
*pCurOut = pCur; *pCurOut = pCur;
return true; return true;
} }
*pCurOut = pCur; *pCurOut = pCur;
return false; return false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool PLY::DOM::ParseHeader (const char* pCur,const char** pCurOut,bool isBinary) bool PLY::DOM::ParseHeader (const char* pCur,const char** pCurOut,bool isBinary) {
{ ai_assert( NULL != pCur );
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCurOut );
DefaultLogger::get()->debug("PLY::DOM::ParseHeader() begin"); DefaultLogger::get()->debug("PLY::DOM::ParseHeader() begin");
// after ply and format line // after ply and format line
@ -479,7 +489,8 @@ bool PLY::DOM::ParseElementInstanceLists (
const char* pCur, const char* pCur,
const char** pCurOut) const char** pCurOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() begin"); DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() begin");
*pCurOut = pCur; *pCurOut = pCur;
@ -507,7 +518,8 @@ bool PLY::DOM::ParseElementInstanceListsBinary (
const char** pCurOut, const char** pCurOut,
bool p_bBE) bool p_bBE)
{ {
ai_assert(NULL != pCur && NULL != pCurOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut);
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() begin"); DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() begin");
*pCurOut = pCur; *pCurOut = pCur;
@ -532,7 +544,8 @@ bool PLY::DOM::ParseElementInstanceListsBinary (
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool PLY::DOM::ParseInstanceBinary (const char* pCur,DOM* p_pcOut,bool p_bBE) bool PLY::DOM::ParseInstanceBinary (const char* pCur,DOM* p_pcOut,bool p_bBE)
{ {
ai_assert(NULL != pCur && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != p_pcOut );
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() begin"); DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() begin");
@ -580,7 +593,10 @@ bool PLY::ElementInstanceList::ParseInstanceList (
const PLY::Element* pcElement, const PLY::Element* pcElement,
PLY::ElementInstanceList* p_pcOut) PLY::ElementInstanceList* p_pcOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != pcElement );
ai_assert( NULL != p_pcOut );
if (EEST_INVALID == pcElement->eSemantic || pcElement->alProperties.empty()) if (EEST_INVALID == pcElement->eSemantic || pcElement->alProperties.empty())
{ {
@ -614,7 +630,10 @@ bool PLY::ElementInstanceList::ParseInstanceListBinary (
PLY::ElementInstanceList* p_pcOut, PLY::ElementInstanceList* p_pcOut,
bool p_bBE /* = false */) bool p_bBE /* = false */)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != pcElement );
ai_assert( NULL != p_pcOut );
// we can add special handling code for unknown element semantics since // we can add special handling code for unknown element semantics since
// we can't skip it as a whole block (we don't know its exact size // we can't skip it as a whole block (we don't know its exact size
@ -636,9 +655,14 @@ bool PLY::ElementInstance::ParseInstance (
const PLY::Element* pcElement, const PLY::Element* pcElement,
PLY::ElementInstance* p_pcOut) PLY::ElementInstance* p_pcOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != pcElement );
ai_assert( NULL != p_pcOut );
if (!SkipSpaces(pCur, &pCur))return false; if (!SkipSpaces(pCur, &pCur)) {
return false;
}
// allocate enough storage // allocate enough storage
p_pcOut->alProperties.resize(pcElement->alProperties.size()); p_pcOut->alProperties.resize(pcElement->alProperties.size());
@ -671,7 +695,10 @@ bool PLY::ElementInstance::ParseInstanceBinary (
PLY::ElementInstance* p_pcOut, PLY::ElementInstance* p_pcOut,
bool p_bBE /* = false */) bool p_bBE /* = false */)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != pcElement );
ai_assert( NULL != p_pcOut );
// allocate enough storage // allocate enough storage
p_pcOut->alProperties.resize(pcElement->alProperties.size()); p_pcOut->alProperties.resize(pcElement->alProperties.size());
@ -696,12 +723,17 @@ bool PLY::ElementInstance::ParseInstanceBinary (
bool PLY::PropertyInstance::ParseInstance (const char* pCur,const char** pCurOut, bool PLY::PropertyInstance::ParseInstance (const char* pCur,const char** pCurOut,
const PLY::Property* prop, PLY::PropertyInstance* p_pcOut) const PLY::Property* prop, PLY::PropertyInstance* p_pcOut)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != prop && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != prop );
ai_assert( NULL != p_pcOut );
*pCurOut = pCur; *pCurOut = pCur;
// skip spaces at the beginning // skip spaces at the beginning
if (!SkipSpaces(pCur, &pCur))return false; if (!SkipSpaces(pCur, &pCur)) {
return false;
}
if (prop->bIsList) if (prop->bIsList)
{ {
@ -741,7 +773,10 @@ bool PLY::PropertyInstance::ParseInstanceBinary (
PLY::PropertyInstance* p_pcOut, PLY::PropertyInstance* p_pcOut,
bool p_bBE) bool p_bBE)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != prop && NULL != p_pcOut); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != prop );
ai_assert( NULL != p_pcOut );
if (prop->bIsList) if (prop->bIsList)
{ {
@ -770,8 +805,7 @@ bool PLY::PropertyInstance::ParseInstanceBinary (
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
PLY::PropertyInstance::ValueUnion PLY::PropertyInstance::DefaultValue( PLY::PropertyInstance::ValueUnion PLY::PropertyInstance::DefaultValue( PLY::EDataType eType )
PLY::EDataType eType)
{ {
PLY::PropertyInstance::ValueUnion out; PLY::PropertyInstance::ValueUnion out;
@ -798,7 +832,9 @@ bool PLY::PropertyInstance::ParseValue(
PLY::EDataType eType, PLY::EDataType eType,
PLY::PropertyInstance::ValueUnion* out) PLY::PropertyInstance::ValueUnion* out)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != out); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != out );
bool ret = true; bool ret = true;
*pCurOut = pCur; *pCurOut = pCur;
@ -827,7 +863,6 @@ bool PLY::PropertyInstance::ParseValue(
break; break;
case EDT_Double: case EDT_Double:
double d; double d;
pCur = fast_atoreal_move<double>(pCur,d); pCur = fast_atoreal_move<double>(pCur,d);
out->fDouble = (double)d; out->fDouble = (double)d;
@ -835,8 +870,10 @@ bool PLY::PropertyInstance::ParseValue(
default: default:
ret = false; ret = false;
break;
} }
*pCurOut = pCur; *pCurOut = pCur;
return ret; return ret;
} }
@ -848,7 +885,9 @@ bool PLY::PropertyInstance::ParseValueBinary(
PLY::PropertyInstance::ValueUnion* out, PLY::PropertyInstance::ValueUnion* out,
bool p_bBE) bool p_bBE)
{ {
ai_assert(NULL != pCur && NULL != pCurOut && NULL != out); ai_assert( NULL != pCur );
ai_assert( NULL != pCurOut );
ai_assert( NULL != out );
bool ret = true; bool ret = true;
switch (eType) switch (eType)
@ -925,6 +964,7 @@ bool PLY::PropertyInstance::ParseValueBinary(
ret = false; ret = false;
} }
*pCurOut = pCur; *pCurOut = pCur;
return ret; return ret;
} }

View File

@ -104,6 +104,7 @@ SET( TEST_SRCS
unit/utSIBImporter.cpp unit/utSIBImporter.cpp
unit/utObjImportExport.cpp unit/utObjImportExport.cpp
unit/utPretransformVertices.cpp unit/utPretransformVertices.cpp
unit/utPLYImportExport.cpp
unit/utRemoveComments.cpp unit/utRemoveComments.cpp
unit/utRemoveComponent.cpp unit/utRemoveComponent.cpp
unit/utRemoveRedundantMaterials.cpp unit/utRemoveRedundantMaterials.cpp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
ply
format ascii 1.0
comment VCGLIB generated
element vertex 3
property float x
property float y
property float z
property float red
property float green
property float blue
property float alpha
element face 1
property list uchar int vertex_indices
end_header
0.0 0.0 0.0 0 0 1 1
100.0 0.0 0.0 0 0 1 1
200.0 200.0 0.0 0 0 1 1
3 0 1 2

View File

@ -0,0 +1,59 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2017, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "UnitTestPCH.h"
#include <assimp/Importer.hpp>
#include "AbstractImportExportBase.h"
using namespace ::Assimp;
class utPLYImportExport : public AbstractImportExportBase {
public:
virtual bool importerTest() {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/PLY/cube.ply", 0 );
return nullptr != scene;
}
};
TEST_F( utPLYImportExport, importTest ) {
EXPECT_TRUE( importerTest() );
}