Open CASCADE Technology  7.5.0
Data Structures | Public Member Functions | Protected Member Functions
RWObj_Reader Class Referenceabstract

An abstract class implementing procedure to read OBJ file. More...

#include <RWObj_Reader.hxx>

Inheritance diagram for RWObj_Reader:
Inheritance graph
[legend]

Data Structures

struct  ObjVec3iHasher
 Hasher for 3 ordered integers. More...
 
class  VectorOfVertices
 Auxiliary structure holding vertex data either with single or double floating point precision. More...
 

Public Member Functions

 RWObj_Reader ()
 Empty constructor. More...
 
Standard_Boolean Read (const TCollection_AsciiString &theFile, const Message_ProgressRange &theProgress)
 Reads data from OBJ file. Unicode paths can be given in UTF-8 encoding. Returns true if success, false on error or user break. More...
 
Standard_Boolean Probe (const TCollection_AsciiString &theFile, const Message_ProgressRange &theProgress)
 Probe data from OBJ file (comments, external references) without actually reading mesh data. Although mesh data will not be collected, the full file content will be parsed, due to OBJ format limitations. More...
 
const TCollection_AsciiStringFileComments () const
 Returns file comments (lines starting with # at the beginning of file). More...
 
const NCollection_IndexedMap< TCollection_AsciiString > & ExternalFiles () const
 Return the list of external file references. More...
 
Standard_Integer NbProbeNodes () const
 Number of probed nodes. More...
 
Standard_Integer NbProbeElems () const
 
Standard_Size MemoryLimit () const
 Returns memory limit in bytes; -1 (no limit) by default. More...
 
void SetMemoryLimit (Standard_Size theMemLimit)
 Specify memory limit in bytes, so that import will be aborted by specified limit before memory allocation error occurs. More...
 
const RWMesh_CoordinateSystemConverterTransformation () const
 Return transformation from one coordinate system to another; no transformation by default. More...
 
void SetTransformation (const RWMesh_CoordinateSystemConverter &theCSConverter)
 Setup transformation from one coordinate system to another. OBJ file might be exported following various coordinate system conventions, so that it might be useful automatically transform data during file reading. More...
 
Standard_Boolean IsSinglePrecision () const
 Return single precision flag for reading vertex data (coordinates); FALSE by default. More...
 
void SetSinglePrecision (Standard_Boolean theIsSinglePrecision)
 Setup single/double precision flag for reading vertex data (coordinates). More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Protected Member Functions

Standard_Boolean read (const TCollection_AsciiString &theFile, const Message_ProgressRange &theProgress, const Standard_Boolean theToProbe)
 Reads data from OBJ file. Unicode paths can be given in UTF-8 encoding. Returns true if success, false on error or user break. More...
 
interface methods which should be implemented by sub-class
virtual Standard_Boolean addMesh (const RWObj_SubMesh &theMesh, const RWObj_SubMeshReason theReason)=0
 Add new sub-mesh. Basically, this method will be called multiple times for the same group with different reason, so that implementation should decide if previously allocated sub-mesh should be used or new one to be allocated. Sub-mesh command can be skipped if previous sub-mesh is empty, or if the reason is out of interest for particular reader (e.g. if materials are ignored, reader may ignore RWObj_SubMeshReason_NewMaterial reason). More...
 
virtual gp_Pnt getNode (Standard_Integer theIndex) const =0
 Retrieve sub-mesh node position, added by addNode(). More...
 
virtual Standard_Integer addNode (const gp_Pnt &thePnt)=0
 Callback function to be implemented in descendant. Should create new node with specified coordinates in the target model, and return its ID as integer. More...
 
virtual void setNodeNormal (const Standard_Integer theIndex, const Graphic3d_Vec3 &theNorm)=0
 Callback function to be implemented in descendant. Should set normal coordinates for specified node. More...
 
virtual void setNodeUV (const Standard_Integer theIndex, const Graphic3d_Vec2 &theUV)=0
 Callback function to be implemented in descendant. Should set texture coordinates for specified node. More...
 
virtual void addElement (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3, Standard_Integer theN4)=0
 Callback function to be implemented in descendant. Should create new element (triangle or quad if 4th index is != -1) built on specified nodes in the target model. More...
 

implementation details

NCollection_IndexedMap< TCollection_AsciiStringmyExternalFiles
 list of external file references More...
 
TCollection_AsciiString myFileComments
 file header comments More...
 
TCollection_AsciiString myFolder
 folder containing the OBJ file More...
 
RWMesh_CoordinateSystemConverter myCSTrsf
 coordinate system flipper More...
 
Standard_Size myMemLimitBytes
 memory limit in bytes More...
 
Standard_Size myMemEstim
 estimated memory occupation in bytes More...
 
Standard_Integer myNbLines
 number of parsed lines (e.g. current line) More...
 
Standard_Integer myNbProbeNodes
 number of probed nodes More...
 
Standard_Integer myNbProbeElems
 number of probed elements More...
 
Standard_Integer myNbElemsBig
 number of big elements (polygons with 5+ nodes) More...
 
Standard_Boolean myToAbort
 flag indicating abort state (e.g. syntax error) More...
 
VectorOfVertices myObjVerts
 temporary vector of vertices More...
 
NCollection_Vector< Graphic3d_Vec2myObjVertsUV
 temporary vector of UV parameters More...
 
NCollection_Vector< Graphic3d_Vec3myObjNorms
 temporary vector of normals More...
 
NCollection_DataMap< Graphic3d_Vec3i, Standard_Integer, ObjVec3iHashermyPackedIndices
 list of external file references More...
 
NCollection_DataMap< TCollection_AsciiString, RWObj_MaterialmyMaterials
 map of known materials More...
 
RWObj_SubMesh myActiveSubMesh
 active sub-mesh definition More...
 
std::vector< Standard_IntegermyCurrElem
 indices for the current element More...
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Detailed Description

An abstract class implementing procedure to read OBJ file.

This class is not bound to particular data structure and can be used to read the file directly into arbitrary data model. To use it, create descendant class and implement interface methods.

Call method Read() to read the file.

Constructor & Destructor Documentation

◆ RWObj_Reader()

RWObj_Reader::RWObj_Reader ( )

Empty constructor.

Member Function Documentation

◆ addElement()

virtual void RWObj_Reader::addElement ( Standard_Integer  theN1,
Standard_Integer  theN2,
Standard_Integer  theN3,
Standard_Integer  theN4 
)
protectedpure virtual

Callback function to be implemented in descendant. Should create new element (triangle or quad if 4th index is != -1) built on specified nodes in the target model.

Implemented in RWObj_TriangulationReader.

◆ addMesh()

virtual Standard_Boolean RWObj_Reader::addMesh ( const RWObj_SubMesh theMesh,
const RWObj_SubMeshReason  theReason 
)
protectedpure virtual

Add new sub-mesh. Basically, this method will be called multiple times for the same group with different reason, so that implementation should decide if previously allocated sub-mesh should be used or new one to be allocated. Sub-mesh command can be skipped if previous sub-mesh is empty, or if the reason is out of interest for particular reader (e.g. if materials are ignored, reader may ignore RWObj_SubMeshReason_NewMaterial reason).

Parameters
theMeshmesh definition
theReasonreason to create new sub-mesh
Returns
TRUE if new sub-mesh should be started since this point

Implemented in RWObj_TriangulationReader.

◆ addNode()

virtual Standard_Integer RWObj_Reader::addNode ( const gp_Pnt thePnt)
protectedpure virtual

Callback function to be implemented in descendant. Should create new node with specified coordinates in the target model, and return its ID as integer.

Implemented in RWObj_TriangulationReader.

◆ ExternalFiles()

const NCollection_IndexedMap<TCollection_AsciiString>& RWObj_Reader::ExternalFiles ( ) const
inline

Return the list of external file references.

◆ FileComments()

const TCollection_AsciiString& RWObj_Reader::FileComments ( ) const
inline

Returns file comments (lines starting with # at the beginning of file).

◆ getNode()

virtual gp_Pnt RWObj_Reader::getNode ( Standard_Integer  theIndex) const
protectedpure virtual

Retrieve sub-mesh node position, added by addNode().

Implemented in RWObj_TriangulationReader.

◆ IsSinglePrecision()

Standard_Boolean RWObj_Reader::IsSinglePrecision ( ) const
inline

Return single precision flag for reading vertex data (coordinates); FALSE by default.

◆ MemoryLimit()

Standard_Size RWObj_Reader::MemoryLimit ( ) const
inline

Returns memory limit in bytes; -1 (no limit) by default.

◆ NbProbeElems()

Standard_Integer RWObj_Reader::NbProbeElems ( ) const
inline

◆ NbProbeNodes()

Standard_Integer RWObj_Reader::NbProbeNodes ( ) const
inline

Number of probed nodes.

number of probed polygon elements (of unknown size).

◆ Probe()

Standard_Boolean RWObj_Reader::Probe ( const TCollection_AsciiString theFile,
const Message_ProgressRange theProgress 
)
inline

Probe data from OBJ file (comments, external references) without actually reading mesh data. Although mesh data will not be collected, the full file content will be parsed, due to OBJ format limitations.

Parameters
theFilepath to the file
theProgressprogress indicator
Returns
TRUE if success, FALSE on error or user break.
See also
FileComments(), ExternalFiles(), NbProbeNodes(), NbProbeElems().

◆ Read()

Standard_Boolean RWObj_Reader::Read ( const TCollection_AsciiString theFile,
const Message_ProgressRange theProgress 
)
inline

Reads data from OBJ file. Unicode paths can be given in UTF-8 encoding. Returns true if success, false on error or user break.

◆ read()

Standard_Boolean RWObj_Reader::read ( const TCollection_AsciiString theFile,
const Message_ProgressRange theProgress,
const Standard_Boolean  theToProbe 
)
protected

Reads data from OBJ file. Unicode paths can be given in UTF-8 encoding. Returns true if success, false on error or user break.

◆ SetMemoryLimit()

void RWObj_Reader::SetMemoryLimit ( Standard_Size  theMemLimit)
inline

Specify memory limit in bytes, so that import will be aborted by specified limit before memory allocation error occurs.

◆ setNodeNormal()

virtual void RWObj_Reader::setNodeNormal ( const Standard_Integer  theIndex,
const Graphic3d_Vec3 theNorm 
)
protectedpure virtual

Callback function to be implemented in descendant. Should set normal coordinates for specified node.

Parameters
theIndexnode ID as returned by addNode()
theNormnormal vector

Implemented in RWObj_TriangulationReader.

◆ setNodeUV()

virtual void RWObj_Reader::setNodeUV ( const Standard_Integer  theIndex,
const Graphic3d_Vec2 theUV 
)
protectedpure virtual

Callback function to be implemented in descendant. Should set texture coordinates for specified node.

Parameters
theIndexnode ID as returned by addNode()
theUVUV texture coordinates

Implemented in RWObj_TriangulationReader.

◆ SetSinglePrecision()

void RWObj_Reader::SetSinglePrecision ( Standard_Boolean  theIsSinglePrecision)
inline

Setup single/double precision flag for reading vertex data (coordinates).

◆ SetTransformation()

void RWObj_Reader::SetTransformation ( const RWMesh_CoordinateSystemConverter theCSConverter)
inline

Setup transformation from one coordinate system to another. OBJ file might be exported following various coordinate system conventions, so that it might be useful automatically transform data during file reading.

◆ Transformation()

const RWMesh_CoordinateSystemConverter& RWObj_Reader::Transformation ( ) const
inline

Return transformation from one coordinate system to another; no transformation by default.

Field Documentation

◆ myActiveSubMesh

RWObj_SubMesh RWObj_Reader::myActiveSubMesh
protected

active sub-mesh definition

◆ myCSTrsf

RWMesh_CoordinateSystemConverter RWObj_Reader::myCSTrsf
protected

coordinate system flipper

◆ myCurrElem

std::vector<Standard_Integer> RWObj_Reader::myCurrElem
protected

indices for the current element

◆ myExternalFiles

NCollection_IndexedMap<TCollection_AsciiString> RWObj_Reader::myExternalFiles
protected

list of external file references

◆ myFileComments

TCollection_AsciiString RWObj_Reader::myFileComments
protected

file header comments

◆ myFolder

TCollection_AsciiString RWObj_Reader::myFolder
protected

folder containing the OBJ file

◆ myMaterials

NCollection_DataMap<TCollection_AsciiString, RWObj_Material> RWObj_Reader::myMaterials
protected

map of known materials

◆ myMemEstim

Standard_Size RWObj_Reader::myMemEstim
protected

estimated memory occupation in bytes

◆ myMemLimitBytes

Standard_Size RWObj_Reader::myMemLimitBytes
protected

memory limit in bytes

◆ myNbElemsBig

Standard_Integer RWObj_Reader::myNbElemsBig
protected

number of big elements (polygons with 5+ nodes)

◆ myNbLines

Standard_Integer RWObj_Reader::myNbLines
protected

number of parsed lines (e.g. current line)

◆ myNbProbeElems

Standard_Integer RWObj_Reader::myNbProbeElems
protected

number of probed elements

◆ myNbProbeNodes

Standard_Integer RWObj_Reader::myNbProbeNodes
protected

number of probed nodes

◆ myObjNorms

NCollection_Vector<Graphic3d_Vec3> RWObj_Reader::myObjNorms
protected

temporary vector of normals

◆ myObjVerts

VectorOfVertices RWObj_Reader::myObjVerts
protected

temporary vector of vertices

◆ myObjVertsUV

NCollection_Vector<Graphic3d_Vec2> RWObj_Reader::myObjVertsUV
protected

temporary vector of UV parameters

◆ myPackedIndices

NCollection_DataMap<Graphic3d_Vec3i, Standard_Integer, ObjVec3iHasher> RWObj_Reader::myPackedIndices
protected

list of external file references

◆ myToAbort

Standard_Boolean RWObj_Reader::myToAbort
protected

flag indicating abort state (e.g. syntax error)


The documentation for this class was generated from the following file: