View unanswered posts | View active topics It is currently Tue Mar 19, 2019 9:56 pm



Reply to topic  [ 5 posts ] 
 3DXmlToWorld behaviour not expected 
Author Message

Joined: Fri Aug 26, 2011 12:25 pm
Posts: 2
Post 3DXmlToWorld behaviour not expected
Hello,

I use GLC_Lib to import and convert 3dxml files.
I noticed that these files are not well imported.

Actually the <OccurenceId> tag in DefaultViewProperties was not well read according 3dxml specifications, causing misreading of visibility.
I join the correction of this bug located in the loadDefaultViewProperty() function.

Code:
void GLC_3dxmlToWorld::loadDefaultViewProperty()
{
    QSet<unsigned int> vOccurenceIds;
    // Load the graphics properties
   while(endElementNotReached(m_pStreamReader, "DefaultViewProperty"))
   {
        if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "OccurenceId"))
        {
            //unsigned int occurenceId= getContent(m_pStreamReader, "OccurenceId").toUInt();
            while(endElementNotReached(m_pStreamReader, "OccurenceId"))
            {
                unsigned int occurenceId = getContent(m_pStreamReader, "id").section('#',-1).toUInt() ;
                vOccurenceIds.insert(occurenceId);
                readNext();
                readNext();
            }
        }
      if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "GraphicProperties"))
      {
         while(endElementNotReached(m_pStreamReader, "GraphicProperties"))
         {

                if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "GeneralAttributes"))
            {
                    QString visibleString= readAttribute("visible", true);
                    if (visibleString != "true")
               {
                        for(QSet<unsigned int>::iterator it = vOccurenceIds.begin();it != vOccurenceIds.end();it++) {
                            if (!m_OccurenceAttrib.contains(*it))
                            {
                                OccurenceAttrib* pOccurenceAttrib= new OccurenceAttrib();
                                pOccurenceAttrib->m_IsVisible= false;
                                m_OccurenceAttrib.insert(*it, pOccurenceAttrib);
                            }
                            else m_OccurenceAttrib.value(*it)->m_IsVisible= false;
                        }
               }
            }
                else if ((QXmlStreamReader::StartElement == m_pStreamReader->tokenType()) && (m_pStreamReader->name() == "SurfaceAttributes"))
            {
               goToElement(m_pStreamReader, "Color");
               const double red= readAttribute("red", true).toDouble();
               const double green= readAttribute("green", true).toDouble();
               const double blue= readAttribute("blue", true).toDouble();
               double alpha= 1.0;
               QString alphaString= readAttribute("alpha", false);
               if (!alphaString.isEmpty()) alpha= alphaString.toDouble();

                    for(QSet<unsigned int>::iterator it = vOccurenceIds.begin();it != vOccurenceIds.end();it++) {

                        GLC_RenderProperties* pRenderProperties= new GLC_RenderProperties();
                        if (red != -1.0f)
                        {
                            QColor diffuseColor;
                            diffuseColor.setRgbF(red, green, blue, alpha);
                            GLC_Material* pMaterial= new GLC_Material();
                            pMaterial->setDiffuseColor(diffuseColor);
                            pRenderProperties->setOverwriteMaterial(pMaterial);
                            pRenderProperties->setRenderingMode(glc::OverwriteMaterial);
                        }
                        else if (alpha < 1.0f)
                        {
                            pRenderProperties->setOverwriteTransparency(static_cast<float>(alpha));
                            pRenderProperties->setRenderingMode(glc::OverwriteTransparency);
                        }

                        if (!m_OccurenceAttrib.contains(*it))
                        {
                            OccurenceAttrib* pOccurenceAttrib= new OccurenceAttrib();
                            pOccurenceAttrib->m_pRenderProperties= pRenderProperties;
                            m_OccurenceAttrib.insert(*it, pOccurenceAttrib);
                        }
                        else m_OccurenceAttrib.value(*it)->m_pRenderProperties= pRenderProperties;
                    }

            }

            readNext();;
         }

      }

      readNext();;
   }

   // Check if an error Occur
   if (m_pStreamReader->hasError())
   {
      QString message(QString("GLC_3dxmlToWorld::loadDefaultViewProperty An error occur in ") + m_FileName);
      GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::WrongFileFormat);
      clear();
      throw(fileFormatException);
   }

}


We also have to correct some destructors :
Code:
GLC_3dxmlToWorld::~GLC_3dxmlToWorld()
{
   delete m_pStreamReader;
   m_pStreamReader= NULL;

   delete m_pCurrentFile;
   delete m_p3dxmlArchive;

   clearMaterialHash();

   // Clear specific attributes hash table
    QHash<unsigned int, OccurenceAttrib*>::iterator iAttrib= m_OccurenceAttrib.begin();
    while (m_OccurenceAttrib.end() != iAttrib)
   {
      delete iAttrib.value();
      ++iAttrib;
   }
   m_OccurenceAttrib.clear();
}


And

Code:
   inline ~OccurenceAttrib()
        {
            if(m_pRenderProperties) {
                delete m_pRenderProperties;
            }
        }


And maybe due to comparison of const and non const iterators :

Code:
void GLC_3dxmlToWorld::clearMaterialHash()
{
    MaterialHash::iterator iMaterial= m_MaterialHash.begin();
    while (m_MaterialHash.end() != iMaterial)
   {
      if (iMaterial.value()->isUnused())
      {
         delete iMaterial.value();
      }
      ++iMaterial;
   }

   m_MaterialHash.clear();
}


Thank you for taking account these points,

Anthony


Fri Aug 26, 2011 12:44 pm
Profile
Site Admin

Joined: Sun Jan 03, 2010 4:27 pm
Posts: 390
Post Re: 3DXmlToWorld behaviour not expected
Hello,
Thanks for you interest about GLC_lib.
anthonysaunier wrote:
Hello,

I use GLC_Lib to import and convert 3dxml files.
I noticed that these files are not well imported.

Actually the <OccurenceId> tag in DefaultViewProperties was not well read according 3dxml specifications, causing misreading of visibility.
I join the correction of this bug located in the loadDefaultViewProperty() function.

Can you be more explicit about this bug ? (Send a sample 3DXML file)

anthonysaunier wrote:
We also have to correct some destructors :
Code:
GLC_3dxmlToWorld::~GLC_3dxmlToWorld()
{
   delete m_pStreamReader;
   m_pStreamReader= NULL;

   delete m_pCurrentFile;
   delete m_p3dxmlArchive;

   clearMaterialHash();

   // Clear specific attributes hash table
    QHash<unsigned int, OccurenceAttrib*>::iterator iAttrib= m_OccurenceAttrib.begin();
    while (m_OccurenceAttrib.end() != iAttrib)
   {
      delete iAttrib.value();
      ++iAttrib;
   }
   m_OccurenceAttrib.clear();
}


I'm not sure that there is a problem when comparing const_iterator between iterator...

anthonysaunier wrote:
Code:
   inline ~OccurenceAttrib()
        {
            if(m_pRenderProperties) {
                delete m_pRenderProperties;
            }
        }


There is no need to check the pointer for null-ness before passing it to delete.
See : DevX
@+


Fri Aug 26, 2011 2:14 pm
Profile

Joined: Fri Aug 26, 2011 12:25 pm
Posts: 2
Post Re: 3DXmlToWorld behaviour not expected
Hello again,

I already have problems comparing const_iterator and iterator from the stl. It's maybe not the case in Qt.
OK for the delete operator.

Considering the bug :

in the last version of GLC_Lib, the content of <OccurenceId> is read with the getContent() function, directly cast to unsigned int and return always 0 because this tag doesn't contain any integer value but a list of <id>filename#occurenceId</id> elements.
A DefaultViewProperty can be applied to many occurences at the same time.

Here is a piece of the 3dxml Sample from the free 3DXmlPlayer from Dassault :

Code:
   <DefaultView>
      <Viewpoint xsi:type="ParallelViewpointType" visualizedHeight="336.4707284" targetDistance="1401.501343" nearPlaneDistance="717.5784302" farPlaneDistance="2069.004395">
         <Position>-654.7354126 -704.961853 678.0846558</Position>
         <Sight>0.5839541554 0.6828992367 -0.4389148355</Sight>
         <Right>0.6628675461 -0.7132402062 -0.2278049141</Right>
         <Up>0.4686194956 0.1579147726 0.8691712618</Up>
      </Viewpoint>
      <DefaultViewProperty>
         <OccurenceId>
            <id>urn:3DXML:Sample.3dxml#6</id>
         </OccurenceId>
         <GraphicProperties xsi:type="GraphicPropertiesType">
            <SurfaceAttributes xsi:type="SurfaceAttributesType">
               <Color xsi:type="RGBAColorType" red="1" green="1" blue="1"/>
            </SurfaceAttributes>
         </GraphicProperties>
      </DefaultViewProperty>
   </DefaultView>


For now the defaultView part of the 3dxml is then not applied.

Anthony


Fri Aug 26, 2011 2:47 pm
Profile
Site Admin

Joined: Sun Jan 03, 2010 4:27 pm
Posts: 390
Post Re: 3DXmlToWorld behaviour not expected
Thanks for the correction.
After some tests, I will post feed back. ;)

@+


Mon Aug 29, 2011 8:55 pm
Profile
Site Admin

Joined: Sun Jan 03, 2010 4:27 pm
Posts: 390
Post Re: 3DXmlToWorld behaviour not expected
Hello,
After spending time to read 3DXML V3 and V4 documentation :
In 3DXML V3 an occurrence is defined with a Occurence Number => unsigned int
In 3DXML V4 an occurence is defined with a path of instance id and not several occurrence id.
So your correction proposition doesn't work ;)

The current released version of GLC_lib can only read the GraphicProperty of 3DXML V3
The latest development version can read both V3 and V4 GraphicProperty.

You can see the code on GLC_lib SVN.

@+


Sun Sep 25, 2011 10:11 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.