1) removed problems with gcc

2) removed stupid bug setContent
3) removed the diamond inherits in AddiotionalInfoDAE
4) removed some compiler warnings
This commit is contained in:
granzuglia 2006-11-09 02:24:41 +00:00
parent deb5402d35
commit 609ee7db96
3 changed files with 245 additions and 291 deletions

View File

@ -32,9 +32,9 @@ private:
// n.appendChild(el);
//}
static void SaveTextureName(QDomDocument& doc,QDomNode& lbim,const std::vector<std::string>& stv)
static void SaveTextureName(QDomDocument doc,QDomNode lbim,const std::vector<std::string>& stv)
{
for(int img = 0;img < stv.size();++img)
for(unsigned int img = 0;img < stv.size();++img)
{
QDomElement imgnode = doc.createElement("image");
imgnode.setAttribute("id","file"+QString::number(img));
@ -47,23 +47,23 @@ private:
}
}
static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector<std::string>& stv)
static void SaveTexture(QDomDocument doc,QDomNode n,const std::vector<std::string>& stv)
{
QDomElement el = doc.createElement("library_images");
SaveTextureName(doc,el,stv);
n.appendChild(el);
}
static void SaveTexture(QDomDocument& doc,const std::vector<std::string>& stv)
static void SaveTexture(QDomDocument doc,const std::vector<std::string>& stv)
{
QDomNodeList lbim = doc.elementsByTagName("library_images");
assert(lbim.size() == 1);
if (lbim.size() == 1)
removeChildNode(lbim.at(0));
SaveTextureName(doc,lbim.at(0),stv);
}
static void CreateVertInput(QDomDocument& doc,QDomNode& vert,const QString& attr,const QString& ref)
static void CreateVertInput(QDomDocument doc,QDomNode vert,const QString& attr,const QString& ref)
{
QDomElement vinp_pos = doc.createElement("input");
vinp_pos.setAttribute("semantic",attr);
@ -71,7 +71,7 @@ private:
vert.appendChild(vinp_pos);
}
static void CreateFaceInput(QDomDocument& doc,QDomNode& tri,const QString& attr,const QString& ref,const int offset)
static void CreateFaceInput(QDomDocument doc,QDomNode tri,const QString& attr,const QString& ref,const int offset)
{
QDomElement tinp_vert = doc.createElement("input");
tinp_vert.setAttribute("offset",QString::number(offset));
@ -80,7 +80,7 @@ private:
tri.appendChild(tinp_vert);
}
static void CreateSource(QDomDocument& doc,QDomNode& meshnode,const QString& attr,const QDomText& val,int nvert)
static void CreateSource(QDomDocument doc,QDomNode meshnode,const QString& attr,const QDomText& val,int nvert)
{
int nel;
std::vector<QString> coord;
@ -137,7 +137,7 @@ private:
meshnode.appendChild(srcnmnode);
}
static int SaveMesh(SaveMeshType& m,QDomDocument& doc,QDomNode& meshnode,const int mask)
static int SaveMesh(SaveMeshType& m,QDomDocument& doc,QDomNode meshnode,const int mask)
{
QString arrp;
arrp.reserve(10 * 3 * m.vert.size());
@ -333,7 +333,7 @@ public:
QFile file(filename);
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate))
return E_CANTOPEN;
doc.setContent(&file);
file.write(st.toAscii());
file.close();
return E_NOERROR;
@ -351,7 +351,7 @@ public:
InfoDAE* info = inf->dae;
QDomNodeList scenelst = info->doc->elementsByTagName("scene");
//removeChildNode(scenelst,"instance_visual_scene");
assert(scenelst.size() == 1);
//assert(scenelst.size() == 1);
if (m.textures.size() != 0)
SaveTexture(*(info->doc),m.textures);
@ -359,6 +359,7 @@ public:
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
assert(geolib.size() == 1);
if (info->doc->elementsByTagName("instance_geometry").size() != 0)
@ -408,6 +409,7 @@ public:
/*QDomElement mshnode;
mshnode.setTagName("mesh");*/
geolib.at(0).childNodes().size();
removeChildNode(geolib.at(0),QString("geometry"),QString("id"),QString("vcg-mesh-lib"));
QDomElement geonode = info->doc->createElement("geometry");
geonode.setAttribute("id","vcg-mesh-lib");
@ -417,12 +419,13 @@ public:
int res = SaveMesh(m,*(info->doc),meshnode,mask);
if (res != 0) return res;
geonode.appendChild(meshnode);
geolib.at(0).appendChild(geonode);
}
else
{
removeChildNodeList(scenelst,QString("instance_visual_scene"));
/* removeChildNodeList(scenelst,QString("instance_visual_scene")); */
for(int vsscn = 0;vsscn < scenelst.size();++vsscn)
{
QString url = scenelst.at(vsscn).toElement().attribute("url");
@ -432,7 +435,7 @@ public:
vsnode.setAttribute("url","#vcg-scene-node");
scenelst.at(0).appendChild(vsnode);
int vsscene_size = vsscene.size();
assert(vsscene.size() == 1);
removeChildNodeList(vsscene,QString("visual_scene"),QString("id"),QString("vcg-scene-node"));
QDomElement vslnode = info->doc->createElement("visual_scene");
@ -464,13 +467,16 @@ public:
geonode.appendChild(meshnode);
geolib.at(0).appendChild(geonode);
}
QString st = info->doc->toString();
QFile file(filename);
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate))
return E_CANTOPEN;
info->doc->setContent(&file);
file.write(st.toAscii());
file.close();
return E_NOERROR;
}

View File

@ -15,7 +15,7 @@ namespace io {
private:
static int LoadMesh(OpenMeshType& m,InfoDAE* info,const QDomNode& geo,const vcg::Matrix44f& t, CallBackPos *cb=0)
static int LoadMesh(OpenMeshType& m,AdditionalInfoDAE* info,const QDomNode& geo,const vcg::Matrix44f& t, CallBackPos *cb=0)
{
if (isThereTag(geo,"mesh"))
{
@ -31,7 +31,7 @@ namespace io {
if (vertices_size != 1)
return E_INCOMPATIBLECOLLADA141FORMAT;
QDomNode srcnode = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"POSITION");
QDomNode srcnode = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"POSITION");
if (srcnode.isNull())
return E_NOVERTEXPOSITION;
@ -43,19 +43,21 @@ namespace io {
return E_CANTOPEN;
int nvert = geosrcposarr_size / 3;
size_t offset = m.vert.size();
if (geosrcposarr_size != 0)
{
vcg::tri::Allocator<OpenMeshType>::AddVertices(m,nvert);
QDomNode srcnodenorm = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"NORMAL");
QDomNode srcnodenorm = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"NORMAL");
QStringList geosrcvertnorm;
if (!srcnodenorm.isNull())
valueStringList(geosrcvertnorm,srcnodenorm,"float_array");
QDomNode srcnodetext = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"TEXCOORD");
QDomNode srcnodetext = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"TEXCOORD");
QStringList geosrcverttext;
if (!srcnodetext.isNull())
valueStringList(geosrcverttext,srcnodetext,"float_array");
QDomNode srcnodecolor = attributeSourcePerSimplex(vertices.at(0),*(info->doc),"COLOR");
QDomNode srcnodecolor = attributeSourcePerSimplex(vertices.at(0),*(info->dae->doc),"COLOR");
QStringList geosrcvertcol;
if (!srcnodecolor.isNull())
valueStringList(geosrcvertcol,srcnodecolor,"float_array");
@ -121,7 +123,7 @@ namespace io {
if (!wnsrc.isNull())
{
offnm = wnsrc.toElement().attribute("offset").toInt();
QDomNode sn = attributeSourcePerSimplex(tripatch.at(tript),*(info->doc),"NORMAL");
QDomNode sn = attributeSourcePerSimplex(tripatch.at(tript),*(info->dae->doc),"NORMAL");
valueStringList(wn,sn,"float_array");
}
@ -132,7 +134,7 @@ namespace io {
if (!wtsrc.isNull())
{
offtx = wtsrc.toElement().attribute("offset").toInt();
QDomNode st = attributeSourcePerSimplex(tripatch.at(tript),*(info->doc),"TEXCOORD");
QDomNode st = attributeSourcePerSimplex(tripatch.at(tript),*(info->dae->doc),"TEXCOORD");
valueStringList(wt,st,"float_array");
}
@ -143,7 +145,7 @@ namespace io {
if (!wcsrc.isNull())
{
offcl = wcsrc.toElement().attribute("offset").toInt();
QDomNode sc = attributeSourcePerSimplex(tripatch.at(tript),*(info->doc),"COLOR");
QDomNode sc = attributeSourcePerSimplex(tripatch.at(tript),*(info->dae->doc),"COLOR");
valueStringList(wc,sc,"float_array");
}
@ -241,6 +243,7 @@ namespace io {
}
}
}
return E_NOERROR;
}
else return E_NOMESH;
@ -254,7 +257,7 @@ namespace io {
QDomNodeList nlst = txlst.at(img).toElement().elementsByTagName("init_from");
if (nlst.size() > 0)
{
inf->dae->texturefile.push_back(nlst.at(0).firstChild().nodeValue());
inf->texturefile.push_back(nlst.at(0).firstChild().nodeValue());
}
}
}
@ -264,11 +267,10 @@ namespace io {
//merge all meshes in the collada's file in the templeted mesh m
//I assume the mesh
static int Open(OpenMeshType& m,const char* filename,AdditionalInfo*& addinfo, CallBackPos *cb=0)
static int Open(OpenMeshType& m,const char* filename,AdditionalInfo*& info, CallBackPos *cb=0)
{
AdditionalInfoDAE* inf = new AdditionalInfoDAE();
inf->dae = new InfoDAE();
InfoDAE* info = inf->dae;
QDomDocument* doc = new QDomDocument(filename);
QFile file(filename);
@ -281,10 +283,10 @@ namespace io {
}
file.close();
info->doc = doc;
inf->dae->doc = doc;
//GetTexture(*(info->doc),inf);
QDomNodeList scenes = info->doc->elementsByTagName("scene");
QDomNodeList scenes = inf->dae->doc->elementsByTagName("scene");
int scn_size = scenes.size();
if (scn_size == 0)
return E_NO3DSCENE;
@ -304,8 +306,8 @@ namespace io {
{
QString libscn_url;
referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
QDomNode nd = QDomNode(*(info->doc));
QDomNode visscn = findNodeBySpecificAttributeValue(*(info->doc),"visual_scene","id",libscn_url);
QDomNode nd = QDomNode(*(inf->dae->doc));
QDomNode visscn = findNodeBySpecificAttributeValue(*(inf->dae->doc),"visual_scene","id",libscn_url);
if(visscn.isNull())
return E_UNREFERENCEBLEDCOLLADAATTRIBUTE;
@ -322,9 +324,8 @@ namespace io {
{
geoinst_found |= true;
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
int geolib_size = geolib.size();
assert(geolib_size == 1);
QDomNodeList geolib = inf->dae->doc->elementsByTagName("library_geometries");
assert(geolib.size() == 1);
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
for(int geoinst_ind = 0;geoinst_ind < geoinst_size;++geoinst_ind)
@ -338,7 +339,7 @@ namespace io {
vcg::Matrix44f tr;
tr.SetIdentity();
TransfMatrix(visscn,geoinst.at(geoinst_ind),tr);
problem |= LoadMesh(m,info,geo,tr);
problem |= LoadMesh(m,inf,geo,tr);
if (problem) return problem;
}
}
@ -348,9 +349,8 @@ namespace io {
if (!geoinst_found)
{
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
int geolib_size = geolib.size();
assert(geolib_size == 1);
QDomNodeList geolib = inf->dae->doc->elementsByTagName("library_geometries");
assert(geolib.size() == 1);
QDomNodeList geochild = geolib.at(0).childNodes();
int geochild_size = geochild.size();
int problem = 0;
@ -358,11 +358,11 @@ namespace io {
{
vcg::Matrix44f tmp;
tmp.SetIdentity();
problem |= LoadMesh(m,info,geochild.at(chd),tmp);
problem |= LoadMesh(m,inf,geochild.at(chd),tmp);
if (problem) return problem;
}
}
addinfo = inf;
info = inf;
return E_NOERROR;
}
@ -375,9 +375,9 @@ namespace io {
bool bHasPerVertexNormal = false;
bool bHasPerVertexText = false;
AdditionalInfoDAE* inf = new AdditionalInfoDAE();
inf->dae = new InfoDAE();
InfoDAE* info = inf->dae;
AdditionalInfoDAE* info = new AdditionalInfoDAE();
info->dae = new InfoDAE();
QDomDocument* doc = new QDomDocument(filename);
QFile file(filename);
@ -391,9 +391,9 @@ namespace io {
file.close();
info->doc = doc;
GetTexture(*(info->doc),inf);
QDomNodeList scenes = info->doc->elementsByTagName("scene");
info->dae->doc = doc;
GetTexture(*(info->dae->doc),info);
QDomNodeList scenes = info->dae->doc->elementsByTagName("scene");
int scn_size = scenes.size();
@ -412,8 +412,8 @@ namespace io {
{
QString libscn_url;
referenceToANodeAttribute(instscenes.at(instscn),"url",libscn_url);
QDomNode nd = QDomNode(*(info->doc));
QDomNode visscn = findNodeBySpecificAttributeValue(*(info->doc),"visual_scene","id",libscn_url);
QDomNode nd = QDomNode(*(info->dae->doc));
QDomNode visscn = findNodeBySpecificAttributeValue(*(info->dae->doc),"visual_scene","id",libscn_url);
if(visscn.isNull())
return false;
@ -422,7 +422,6 @@ namespace io {
QDomNodeList visscn_child = visscn.childNodes();
//for each direct child of a libscn_url visual scene find if there is some geometry instance
int problem = 0;
for(int chdind = 0; chdind < visscn_child.size();++chdind)
{
//QDomNodeList& geoinst = visscn_child.at(chdind).toElement().elementsByTagName("instance_geometry");
@ -432,9 +431,8 @@ namespace io {
{
geoinst_found |= true;
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
int geolib_size = geolib.size();
assert(geolib_size == 1);
QDomNodeList geolib = info->dae->doc->elementsByTagName("library_geometries");
assert(geolib.size() == 1);
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
info->numvert = 0;
info->numface = 0;
@ -490,9 +488,8 @@ namespace io {
if (!geoinst_found)
{
QDomNodeList geolib = info->doc->elementsByTagName("library_geometries");
int geolib_size = geolib.size();
assert(geolib_size == 1);
QDomNodeList geolib = info->dae->doc->elementsByTagName("library_geometries");
assert(geolib.size() == 1);
QDomNodeList geochild = geolib.at(0).toElement().elementsByTagName("geometry");
//!!!!!!!!!!!!!!!!!here will be the code for geometry transformations!!!!!!!!!!!!!!!!!!!!!!
info->numvert = 0;
@ -554,8 +551,9 @@ namespace io {
delete (info->doc);
addinfo = inf;
delete (info->dae->doc);
info->dae->doc = NULL;
addinfo = info;
return true;
}
};

View File

@ -19,41 +19,41 @@
namespace vcg {
namespace tri {
namespace io {
class InfoDAE : public AdditionalInfo
class InfoDAE
{
public:
InfoDAE()
{
mask = 0;
numvert = 0;
numface = 0;
doc = NULL;
}
~InfoDAE()
{
delete doc;
texturefile.clear();
}
QDomDocument* doc;
std::vector<QString> texturefile;
};
class AdditionalInfoDAE : public AdditionalInfo
{
public:
vcg::tri::io::InfoDAE* dae;
std::vector<QString> texturefile;
AdditionalInfoDAE()
:AdditionalInfo()
{
mask = 0;
numvert = 0;
numface = 0;
}
~AdditionalInfoDAE()
{
delete dae;
texturefile.clear();
}
};
@ -94,7 +94,7 @@ namespace io {
else return dae_error_msg[error];
};
protected:
inline static void referenceToANodeAttribute(const QDomNode& n,const QString& attr,QString& url_st)
inline static void referenceToANodeAttribute(const QDomNode n,const QString& attr,QString& url_st)
{
url_st = n.toElement().attribute(attr);
int sz = url_st.size() - 1;
@ -116,12 +116,12 @@ namespace io {
return QDomNode();
}
inline static QDomNode findNodeBySpecificAttributeValue(const QDomNode& n,const QString& tag,const QString& attrname,const QString& attrvalue)
inline static QDomNode findNodeBySpecificAttributeValue(const QDomNode n,const QString& tag,const QString& attrname,const QString& attrvalue)
{
return findNodeBySpecificAttributeValue(n.toElement().elementsByTagName(tag),attrname,attrvalue);
}
inline static QDomNode findNodeBySpecificAttributeValue(const QDomDocument& n,const QString& tag,const QString& attrname,const QString& attrvalue)
inline static QDomNode findNodeBySpecificAttributeValue(const QDomDocument n,const QString& tag,const QString& attrname,const QString& attrvalue)
{
return findNodeBySpecificAttributeValue(n.elementsByTagName(tag),attrname,attrvalue);
}
@ -131,18 +131,18 @@ namespace io {
return ((list.size() > 0) ? true : false);
}
inline static bool isThereTag(const QDomNode& n,const QString& tagname)
inline static bool isThereTag(const QDomNode n,const QString& tagname)
{
return isThereTag(n.toElement().elementsByTagName(tagname));
}
inline static bool isThereTag(const QDomDocument& n,const QString& tagname)
inline static bool isThereTag(const QDomDocument n,const QString& tagname)
{
return isThereTag(n.elementsByTagName(tagname));
}
inline static QDomNode attributeSourcePerSimplex(const QDomNode& n,const QDomDocument& startpoint,const QString& sem)
inline static QDomNode attributeSourcePerSimplex(const QDomNode n,const QDomDocument startpoint,const QString& sem)
{
QDomNodeList vertattr = n.toElement().elementsByTagName("input");
for(int ind = 0;ind < vertattr.size();++ind)
@ -157,11 +157,10 @@ namespace io {
return QDomNode();
}
inline static void valueStringList(QStringList& res,const QDomNode& srcnode,const QString& tag)
inline static void valueStringList(QStringList& res,const QDomNode srcnode,const QString& tag)
{
QDomNodeList list = srcnode.toElement().elementsByTagName(tag);
int list_size = list.size();
assert(list_size == 1);
assert(list.size() == 1);
QString nd = list.at(0).firstChild().nodeValue();
res = nd.split(" ");
if (res.last() == "")
@ -181,7 +180,7 @@ namespace io {
}
inline static bool removeChildNode(QDomNode& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "")
inline static bool removeChildNode(QDomNode node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "")
{
QDomNodeList clst = node.childNodes();
for(int ii = 0;ii < clst.size();++ii)
@ -208,55 +207,6 @@ namespace io {
return true;
}
//inline static bool removeChildNode(QDomDocument& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "")
////inline static bool removeChildNode(QDomNode node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "")
//{
// QDomNodeList clst = node.childNodes();
// for(int ii = 0;ii < clst.size();++ii)
// {
// QDomNode oldchild = node.childNodes().at(ii);
// if (tag != "")
// {
// if ((attribname != "") && (attribvalue != ""))
// {
// if (clst.at(ii).toElement().attribute(attribname) == attribvalue)
// node.removeChild(oldchild);
// }
// else
// {
// QString nm = clst.at(ii).nodeName();
// if (clst.at(ii).nodeName() == tag)
// {
// node.removeChild(oldchild);
// }
// }
// }
// else node.removeChild(oldchild);
// }
// return true;
//}
/*inline static bool removeChildNode(QDomDocument node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "")
{
QDomNodeList clst = node.childNodes();
for(int ii = 0;ii < clst.size();++ii)
{
QDomNode oldchild = node.childNodes().at(ii);
if (tag != "")
{
if ((attribname != "") && (attribvalue != ""))
{
if (clst.at(ii).toElement().attribute(attribname) == attribvalue)
node.removeChild(oldchild);
}
else if (clst.at(ii).nodeName() == tag)
node.removeChild(oldchild);
}
else node.removeChild(oldchild);
}
return true;
}*/
static void ParseRotationMatrix(vcg::Matrix44f& m,const std::vector<QDomNode>& t)
{
vcg::Matrix44f tmp;
@ -273,7 +223,7 @@ namespace io {
m = m * tmp;
}
static void AddTranslation(vcg::Matrix44f& m,const QDomNode& t)
static void AddTranslation(vcg::Matrix44f& m,const QDomNode t)
{
QDomNode tr = t.firstChild();
QString coord = tr.nodeValue();
@ -290,7 +240,7 @@ namespace io {
m[2][3] = coordlist.at(2).toFloat();
}
static void TransfMatrix(const QDomNode& parentnode,const QDomNode& presentnode,vcg::Matrix44f& m)
static void TransfMatrix(const QDomNode parentnode,const QDomNode presentnode,vcg::Matrix44f& m)
{
if (presentnode == parentnode) return;
else