View Issue Details

IDProjectCategoryView StatusLast Update
0032820Open CASCADEOCCT:Data Exchangepublic2022-07-20 18:05
Reporterkgv Assigned Todpasukhi  
PrioritynormalSeverityfeature 
Status resolvedResolutionopen 
Target Version7.7.0 
Summary0032820: Data Exchange - add VRML reader to XCAF document
Description0030115 introduced a tool for exporting XCAF document into VRML format, but there is still no symmetrical method for translation in opposite direction, which makes testing bugs like 0032819 difficult, although translation is relatively straightforward.

namespace
{
  //! Return string associated with VRML reader status.
  static const char* getVrmlErrorName (VrmlData_ErrorStatus theStatus)
  {
    switch (theStatus)
    {
      case VrmlData_StatusOK:              return "";
      case VrmlData_EmptyData:             return "EmptyData";
      case VrmlData_UnrecoverableError:    return "UnrecoverableError";
      case VrmlData_GeneralError:          return "GeneralError";
      case VrmlData_EndOfFile:             return "EndOfFile";
      case VrmlData_NotVrmlFile:           return "NotVrmlFile";
      case VrmlData_CannotOpenFile:        return "CannotOpenFile";
      case VrmlData_VrmlFormatError:       return "VrmlFormatError";
      case VrmlData_NumericInputError:     return "NumericInputError";
      case VrmlData_IrrelevantNumber:      return "IrrelevantNumber";
      case VrmlData_BooleanInputError:     return "BooleanInputError";
      case VrmlData_StringInputError:      return "StringInputError";
      case VrmlData_NodeNameUnknown:       return "NodeNameUnknown";
      case VrmlData_NonPositiveSize:       return "NonPositiveSize";
      case VrmlData_ReadUnknownNode:       return "ReadUnknownNode";
      case VrmlData_NonSupportedFeature:   return "NonSupportedFeature";
      case VrmlData_OutputStreamUndefined: return "OutputStreamUndefined";
      case VrmlData_NotImplemented:        return "NotImplemented";
    }
    return "UNKNOWN";
  }

  //! Process sub-shape.
  static void performMeshSubshape (RWMesh_NodeAttributeMap& theAttribMap,
                                   const VrmlData_DataMapOfShapeAppearance& theShapeAppMap,
                                   const TopoDS_Shape& theShape)
  {
    Handle(VrmlData_Appearance) anAppearance;
    if (theShapeAppMap.Find (theShape.TShape(), anAppearance))
    {
      if (!anAppearance.IsNull()
       && !anAppearance->Material().IsNull())
      {
        RWMesh_NodeAttributes aFaceAttribs;
        aFaceAttribs.Style.SetColorSurf (anAppearance->Material()->DiffuseColor());
        theAttribMap.Bind (theShape, aFaceAttribs);
      }
    }

    for (TopoDS_Iterator aSubShapeIter (theShape, true, false); aSubShapeIter.More(); aSubShapeIter.Next())
    {
      performMeshSubshape (theAttribMap, theShapeAppMap, aSubShapeIter.Value());
    }
  }
}

//! The VRML mesh reader.
class MyCafVrmlReader
{
  //! Read the mesh from specified file.
  bool performMesh (const TCollection_AsciiString& theFile,
                                            const Standard_Boolean theToProbe)
  {
    Standard_CLocaleSentry aLocaleSentry;
    std::ifstream aFile;
    OSD_OpenStream (aFile, theFile.ToCString(), std::ios::in | std::ios::binary);
    if (!aFile.is_open()
     || !aFile.good())
    {
      Message::SendFail (TCollection_AsciiString ("File '") + theFile + "' is not found");
      return false;
    }

    if (theToProbe)
    {
      return false; // unsupported
    }

    // determine file location to load associated files
    TCollection_AsciiString aFolder;
    {
      OSD_Path aPath (theFile);
      aPath.SetName ("");
      aPath.SetExtension ("");
      aPath.SystemName (aFolder);
    }

    VrmlData_Scene aScene;
    aScene.SetLinearScale (myUnitFactor);
    aScene.SetVrmlDir (aFolder);
    aScene << aFile;

    VrmlData_DataMapOfShapeAppearance aShapeAppMap;
    TopoDS_Shape aShape = aScene.GetShape (aShapeAppMap);
    if (!aShape.IsNull())
    {
      performMeshSubshape (myAttribMap, aShapeAppMap, aShape);
      myRootShapes.Append (aShape);
    }
    if (aScene.Status() != VrmlData_StatusOK
     || aShape.IsNull())
    {
      Message::SendFail (TCollection_AsciiString ("Error ") + getVrmlErrorName (aScene.Status())
                       + " occurred at line " + aScene.GetLineError()
                       + "\nwhile reading VRML file '" + theFile + "'");
      return false;
    }

    return true;
  }

protected:
  double myUnitFactor;  //!< length unit scale factor

};
Steps To ReproduceNot required
TagsNo tags attached.
Test case number

Relationships

related to 0032819 resolveddpasukhi Community Data Exchange - VrmlAPI_Writer does not write all colors 
child of 0030115 closedbugmaster Open CASCADE Data Exchange - Implementation of import from XCAF to VRML. 

Activities

git

2022-07-12 23:48

administrator   ~0109785

Branch CR32820 has been created by atychini.

SHA-1: d9d3fbf511678eda6cf185955df811f6673d3917


Detailed log of new commits:

Author: atychini
Date: Tue Jul 12 23:48:02 2022 +0300

    0032820: Data Exchange - add VRML reader to XCAF document
    
    Implementing VRML reader into XCAF document.

git

2022-07-13 13:12

administrator   ~0109796

Branch CR32820 has been updated forcibly by atychini.

SHA-1: 97d74810eeeb54cf8190564f52f46adf439395e2

atychini

2022-07-13 16:04

developer   ~0109797

Last edited: 2022-07-13 16:04

Dear @dpasukhi, please review branch CR32820
All tests are ok, see http://jenkins-test-08.nnov.opencascade.com/view/CR32820-master-atychini/view/ALL/

kgv

2022-07-13 16:27

developer   ~0109798

+  std::ifstream aFile;
+  OSD_OpenStream(aFile, theFile.ToCString(), std::ios::in | std::ios::binary);

Please use `OSD_FileSystem::DefaultFileSystem()`.

+  // determine file location to load associated files
+  TCollection_AsciiString aFolder;
+  {
+    OSD_Path aPath(theFile);
+    aPath.SetName("");
+    aPath.SetExtension("");
+    aPath.SystemName(aFolder);

Consider using `OSD_Path::FolderAndFileFromPath()` instead.

+
+class VrmlAPI_CafReader : public RWMesh_CafReader

Description is missing.

+      if (aFileUnitFactor <= 0.0)
+      {
+        Message::SendWarning() << "Warning: wrong length unit '" << aUnitStr << "'";
+      }

Invalid input should be a failure, not warning, I think.

+    if(aToUseExistingDoc)

`toUseExistingDoc` following OCCT name conventions.

+      Message::SendFail() << "Error: file reading failed '" << aFilePath;

Trailing open quote.

+  Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument(aDoc);

Unused variable.

-nocreatedoc

Looks like this option is mistreated.

+ReadVrml D $aFile
+XGetOneShape S_New D
+
+checktrinfo S_New -ref [trinfo S_Ref]
+
+Close D

It is essential making also screenshots of a document in 3D viewer and check colors are presented as expected.

+         "\n\t\t:   -memoryLimit    memory usage limit (in MiB)"

I don't see this option being implemented by new/old VRML reader logic, why it is exposed?

+         "\n\t\t:   -fileUnit       length unit of Vrml file content;"
+         "\n\t\t:   -memoryLimit    memory usage limit (in MiB)"
+         "\n\t\t:   -fileCoordSys   coordinate system defined by Vrml file; Yup when not specified."

Inconsistent separators in listing (".", ";", "").

+  //! Setting myUnitFactor to theUnitFactor
+  //! @param[in] theUnitFactor length unit scale factor
+  Standard_EXPORT void SetUnitFactor(const Standard_Real theUnitFactor);
+
+  //! Get the length unit scale factor
+  //! @return the length unit scale factor
+  Standard_EXPORT Standard_Real UnitFactor() const;

This property jeopardizes inheritance from RWMesh_CafReader and it's basic units conversion logic interface which is supposed to be used.

git

2022-07-18 11:46

administrator   ~0109851

Branch CR32820 has been updated forcibly by atychini.

SHA-1: f7e9e2f5a4d2d07cb9624e5299e892aee2134c4e

atychini

2022-07-20 09:43

developer   ~0109883

Dear dpasukhi, please review branch CR32820
Tests have completed successfully http://jenkins-test-08.nnov.opencascade.com/view/CR32820-master-atychini/view/ALL/

kgv

2022-07-20 17:55

developer   ~0109904

+      "(due to unexpected EOF, syntax error, memory limit)" << thePath;

Space is missing.

+      Message::SendFail() << "Error in the Vrml_Provider during reading the file " << thePath;

It is preferred to put file path into quotes.

+bool VrmlAPI_CafReader::performMesh(const TCollection_AsciiString& theFile,
+                                    const Message_ProgressRange&,
+                                    const Standard_Boolean)

Please don't ignore `theToProbe` parameter - return FALSE immediately if probing cannot be implemented.

git

2022-07-20 18:05

administrator   ~0109905

Branch CR32820 has been updated forcibly by atychini.

SHA-1: 715ed1bf5a17b1f2368d6de14c25c9dfe86d7de0

Issue History

Date Modified Username Field Change
2022-02-07 14:29 kgv New Issue
2022-02-07 14:29 kgv Assigned To => dpasukhi
2022-02-07 14:29 kgv Relationship added child of 0030115
2022-02-07 14:29 kgv Relationship added related to 0032819
2022-07-11 16:16 dpasukhi Assigned To dpasukhi => atychini
2022-07-12 23:48 git Note Added: 0109785
2022-07-13 13:12 git Note Added: 0109796
2022-07-13 16:03 atychini Assigned To atychini => dpasukhi
2022-07-13 16:03 atychini Status new => resolved
2022-07-13 16:03 atychini Steps to Reproduce Updated
2022-07-13 16:04 atychini Steps to Reproduce Updated
2022-07-13 16:04 atychini Note Added: 0109797
2022-07-13 16:04 atychini Note Edited: 0109797
2022-07-13 16:27 kgv Note Added: 0109798
2022-07-13 16:32 dpasukhi Assigned To dpasukhi => atychini
2022-07-13 16:32 dpasukhi Status resolved => assigned
2022-07-18 11:46 git Note Added: 0109851
2022-07-20 09:43 atychini Assigned To atychini => dpasukhi
2022-07-20 09:43 atychini Status assigned => resolved
2022-07-20 09:43 atychini Steps to Reproduce Updated
2022-07-20 09:43 atychini Note Added: 0109883
2022-07-20 17:55 kgv Note Added: 0109904
2022-07-20 18:05 git Note Added: 0109905