Version: 6.3.1
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes

DriverSTL_W_SMDS_Mesh Class Reference

#include <DriverSTL_W_SMDS_Mesh.h>

Inheritance diagram for DriverSTL_W_SMDS_Mesh:
Inheritance graph
[legend]

Public Types

enum  Status {
  DRS_OK, DRS_EMPTY, DRS_WARN_RENUMBER, DRS_WARN_SKIP_ELEM,
  DRS_FAIL
}

Public Member Functions

 DriverSTL_W_SMDS_Mesh ()
 ~DriverSTL_W_SMDS_Mesh ()
 Destructor deletes temporary faces.
virtual Status Perform ()
void SetIsAscii (const bool theIsAscii=false)
void SetMesh (SMDS_Mesh *theMesh)
void SetMeshId (int theMeshId)
void SetFile (const std::string &theFileName)

Protected Attributes

SMDS_MeshmyMesh
std::string myFile
int myMeshId

Private Member Functions

Status writeAscii () const
Status writeBinary () const
void findVolumeTriangles ()
 Finds free facets of volumes for which faces are missing in the mesh.
SMDS_ElemIteratorPtr getFaces () const
 Return iterator on both faces in the mesh and on temporary faces.

Private Attributes

bool myIsAscii
std::vector< const
SMDS_MeshElement * > 
myVolumeTrias

Detailed Description

Definition at line 37 of file DriverSTL_W_SMDS_Mesh.h.


Member Enumeration Documentation

enum Driver_Mesh::Status [inherited]
Enumerator:
DRS_OK 
DRS_EMPTY 
DRS_WARN_RENUMBER 
DRS_WARN_SKIP_ELEM 
DRS_FAIL 

Definition at line 48 of file Driver_Mesh.h.

              {
    DRS_OK,
    DRS_EMPTY,          // a file contains no mesh with the given name
    DRS_WARN_RENUMBER,  // a file has overlapped ranges of element numbers,
                        // so the numbers from the file are ignored
    DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
    DRS_FAIL            // general failure (exception etc.)
  };

Constructor & Destructor Documentation

DriverSTL_W_SMDS_Mesh::DriverSTL_W_SMDS_Mesh ( )

Definition at line 50 of file DriverSTL_W_SMDS_Mesh.cxx.

References myIsAscii.

{
  myIsAscii = false;
}
DriverSTL_W_SMDS_Mesh::~DriverSTL_W_SMDS_Mesh ( )

Destructor deletes temporary faces.

Definition at line 82 of file DriverSTL_W_SMDS_Mesh.cxx.

References myVolumeTrias.

{
  for ( unsigned i = 0; i < myVolumeTrias.size(); ++i )
    delete myVolumeTrias[i];
}

Member Function Documentation

void DriverSTL_W_SMDS_Mesh::findVolumeTriangles ( ) [private]

Finds free facets of volumes for which faces are missing in the mesh.

Definition at line 94 of file DriverSTL_W_SMDS_Mesh.cxx.

References SMDS_Mesh.FindElement(), SMDS_VolumeTool.GetFaceNodes(), SMDS_VolumeTool.IsFreeFace(), Driver_SMDS_Mesh.myMesh, myVolumeTrias, SMDS_VolumeTool.NbFaceNodes(), SMDS_VolumeTool.NbFaces(), SMESH_AdvancedEditor.nodes, SMDS_VolumeTool.Set(), SMDSAbs_Face, and SMDS_Mesh.volumesIterator().

Referenced by Perform().

{
  SMDS_VolumeTool myTool;
  SMDS_VolumeIteratorPtr vIt = myMesh->volumesIterator();
  while ( vIt->more() )
  {
    myTool.Set( vIt->next() );
    for ( int iF = 0; iF < myTool.NbFaces(); ++iF )
      if ( myTool.IsFreeFace( iF ))
      {
        const SMDS_MeshNode** n = myTool.GetFaceNodes(iF);
        int                 nbN = myTool.NbFaceNodes(iF);
        std::vector< const SMDS_MeshNode*> nodes( n, n+nbN );
        if ( !myMesh->FindElement( nodes, SMDSAbs_Face, /*Nomedium=*/false))
        {
          int nbTria = nbN - 2;
          for ( int iT = 0; iT < nbTria; ++iT )
          {
            myVolumeTrias.push_back( new SMDS_FaceOfNodes( n[0], n[1+iT], n[2+iT] ));
          }
        }
      }
  }
}
SMDS_ElemIteratorPtr DriverSTL_W_SMDS_Mesh::getFaces ( ) const [private]

Return iterator on both faces in the mesh and on temporary faces.

Definition at line 125 of file DriverSTL_W_SMDS_Mesh.cxx.

References SMDS_Mesh.elementsIterator(), Driver_SMDS_Mesh.myMesh, myVolumeTrias, and SMDSAbs_Face.

Referenced by writeAscii(), and writeBinary().

{
  SMDS_ElemIteratorPtr facesIter = myMesh->elementsIterator(SMDSAbs_Face);
  SMDS_ElemIteratorPtr tmpTriaIter( new SMDS_ElementVectorIterator( myVolumeTrias.begin(),
                                                                    myVolumeTrias.end()));
  typedef std::vector< SMDS_ElemIteratorPtr > TElemIterVector;
  TElemIterVector iters(2);
  iters[0] = facesIter;
  iters[1] = tmpTriaIter;
  
  typedef SMDS_IteratorOnIterators<const SMDS_MeshElement *, TElemIterVector> TItersIter;
  return SMDS_ElemIteratorPtr( new TItersIter( iters ));
}
Driver_Mesh::Status DriverSTL_W_SMDS_Mesh::Perform ( ) [virtual]

Implements Driver_Mesh.

Definition at line 60 of file DriverSTL_W_SMDS_Mesh.cxx.

References Driver_Mesh.DRS_FAIL, Driver_Mesh.DRS_OK, findVolumeTriangles(), myIsAscii, Driver_SMDS_Mesh.myMesh, writeAscii(), and writeBinary().

Referenced by SMESH_Mesh.ExportSTL().

{
  Status aResult = DRS_OK;

  if ( !myMesh ) {
    fprintf(stderr, ">> ERROR : Mesh is null \n");
    return DRS_FAIL;
  }
  findVolumeTriangles();
  if ( myIsAscii )
    aResult = writeAscii();
  else
    aResult = writeBinary();

  return aResult;
}
void Driver_Mesh::SetFile ( const std::string &  theFileName) [inherited]
void DriverSTL_W_SMDS_Mesh::SetIsAscii ( const bool  theIsAscii = false)

Definition at line 55 of file DriverSTL_W_SMDS_Mesh.cxx.

References myIsAscii.

Referenced by SMESH_Mesh.ExportSTL().

{
  myIsAscii = theIsAscii;
}
void Driver_SMDS_Mesh::SetMesh ( SMDS_Mesh theMesh) [inherited]
void Driver_Mesh::SetMeshId ( int  theMeshId) [inherited]
Driver_Mesh::Status DriverSTL_W_SMDS_Mesh::writeAscii ( ) const [private]

Definition at line 221 of file DriverSTL_W_SMDS_Mesh.cxx.

References SMESH_test5.aFileName, Driver_Mesh.DRS_FAIL, Driver_Mesh.DRS_OK, getFaces(), getNormale(), getTriangles(), Driver_Mesh.myFile, ex29_refine.node(), MESHCUT.normale, SMDS_MeshNode.X(), SMDS_MeshNode.Y(), and SMDS_MeshNode.Z().

Referenced by Perform().

{
  Status aResult = DRS_OK;
  TCollection_AsciiString aFileName( (char *)myFile.c_str() );
  if ( aFileName.IsEmpty() ) {
    fprintf(stderr, ">> ERREOR : invalid file name \n");
    return DRS_FAIL;
  }

  OSD_File aFile = OSD_File(OSD_Path(aFileName));
  aFile.Build(OSD_WriteOnly,OSD_Protection());

  char sval[16];
  TCollection_AsciiString buf = TCollection_AsciiString ("solid\n");
  aFile.Write (buf,buf.Length());buf.Clear();

  const SMDS_MeshNode* triaNodes[2048];

  SMDS_ElemIteratorPtr itFaces = getFaces();
  while ( itFaces->more() )
  {
    const SMDS_MeshElement* aFace = itFaces->next();
    int nbTria = getTriangles( aFace, triaNodes );
    
    for ( int iT = 0, iN = 0; iT < nbTria; ++iT )
    {
      gp_XYZ normale = getNormale( triaNodes[iN],
                                   triaNodes[iN+1],
                                   triaNodes[iN+2] );

      buf += " facet normal "; 
      sprintf (sval,"% 12e",normale.X());
      buf += sval;
      buf += " "; 
      sprintf (sval,"% 12e",normale.Y());
      buf += sval;
      buf += " "; 
      sprintf (sval,"% 12e",normale.Z());
      buf += sval;
      buf += '\n';
      aFile.Write (buf,buf.Length());buf.Clear();
      buf += "   outer loop\n"; 
      aFile.Write (buf,buf.Length());buf.Clear();
      
      for ( int jN = 0; jN < 3; ++jN, ++iN ) {
        const SMDS_MeshNode* node = triaNodes[iN];
        buf += "     vertex "; 
        sprintf (sval,"% 12e",node->X());
        buf += sval;
        buf += " "; 
        sprintf (sval,"% 12e",node->Y());
        buf += sval;
        buf += " "; 
        sprintf (sval,"% 12e",node->Z());
        buf += sval;
        buf += '\n';
        aFile.Write (buf,buf.Length());buf.Clear();
      }
      buf += "   endloop\n"; 
      aFile.Write (buf,buf.Length());buf.Clear();
      buf += " endfacet\n"; 
      aFile.Write (buf,buf.Length());buf.Clear();
    } 
  }
  buf += "endsolid\n";
  aFile.Write (buf,buf.Length());buf.Clear();
  
  aFile.Close ();

  return aResult;
}
Driver_Mesh::Status DriverSTL_W_SMDS_Mesh::writeBinary ( ) const [private]

Definition at line 293 of file DriverSTL_W_SMDS_Mesh.cxx.

References SMESH_test5.aFileName, Driver_Mesh.DRS_FAIL, Driver_Mesh.DRS_OK, SMDS_Mesh.facesIterator(), getFaces(), SMDS_Mesh.GetMeshInfo(), getNormale(), getTriangles(), SMDS_MeshElement.IsPoly(), LABEL_SIZE, Driver_Mesh.myFile, Driver_SMDS_Mesh.myMesh, myVolumeTrias, SMDS_MeshElement.NbNodes(), SMDS_MeshInfo.NbPolygons(), SMDS_MeshInfo.NbQuadrangles(), SMDS_MeshInfo.NbTriangles(), ex29_refine.node(), MESHCUT.normale, writeFloat(), writeInteger(), SMDS_MeshNode.X(), SMDS_MeshNode.Y(), and SMDS_MeshNode.Z().

Referenced by Perform().

{
  Status aResult = DRS_OK;
  TCollection_AsciiString aFileName( (char *)myFile.c_str() );
  if ( aFileName.IsEmpty() ) {
    fprintf(stderr, ">> ERREOR : invalid filename \n");
    return DRS_FAIL;
  }

  OSD_File aFile = OSD_File(OSD_Path(aFileName));
  aFile.Build(OSD_WriteOnly,OSD_Protection());

  // we first count the number of triangles
  // WARNING: counting triangles must be coherent with getTriangles()
  int nbTri = 0;
  const SMDS_MeshInfo& info = myMesh->GetMeshInfo();
  nbTri += info.NbTriangles();
  nbTri += info.NbQuadrangles() * 2;
  nbTri += myVolumeTrias.size();
  if ( info.NbPolygons() > 0 )
  {
    SMDS_FaceIteratorPtr itFaces = myMesh->facesIterator();
    while ( itFaces->more() )
    {
      const SMDS_MeshElement* aFace = itFaces->next();
      if ( aFace->IsPoly() )
        nbTri += aFace->NbNodes() - 2;
    }
  }

  // char sval[80]; -- avoid writing not initialized memory
  TCollection_AsciiString sval(LABEL_SIZE-1,' ');
  aFile.Write((Standard_Address)sval.ToCString(),LABEL_SIZE);

  // write number of triangles
  writeInteger(nbTri,aFile);  

  // Loop writing nodes

  int dum=0;

  const SMDS_MeshNode* triaNodes[2048];

  SMDS_ElemIteratorPtr itFaces = getFaces();
  while ( itFaces->more() )
  {
    const SMDS_MeshElement* aFace = itFaces->next();
    int nbTria = getTriangles( aFace, triaNodes );
    
    for ( int iT = 0, iN = 0; iT < nbTria; ++iT )
    {
      gp_XYZ normale = getNormale( triaNodes[iN],
                                   triaNodes[iN+1],
                                   triaNodes[iN+2] );
      writeFloat(normale.X(),aFile);
      writeFloat(normale.Y(),aFile);
      writeFloat(normale.Z(),aFile);

      for ( int jN = 0; jN < 3; ++jN, ++iN )
      {
        const SMDS_MeshNode* node = triaNodes[iN];
        writeFloat(node->X(),aFile);
        writeFloat(node->Y(),aFile);
        writeFloat(node->Z(),aFile);
      }
      aFile.Write (&dum,2);
    } 
  }
  aFile.Close ();

  return aResult;
}

Field Documentation

std::string Driver_Mesh.myFile [protected, inherited]

Definition at line 56 of file DriverSTL_W_SMDS_Mesh.h.

Referenced by DriverSTL_W_SMDS_Mesh(), Perform(), and SetIsAscii().

SMDS_Mesh* Driver_SMDS_Mesh.myMesh [protected, inherited]
int Driver_Mesh.myMeshId [protected, inherited]

Definition at line 63 of file Driver_Mesh.h.

Referenced by DriverMED_W_SMESHDS_Mesh.Perform(), and Driver_Mesh.SetMeshId().

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS