diff --git a/src/RWStl/RWStl.cdl b/src/RWStl/RWStl.cdl index d6685e6a41..24cd048ded 100755 --- a/src/RWStl/RWStl.cdl +++ b/src/RWStl/RWStl.cdl @@ -21,24 +21,28 @@ uses OSD, Standard, - StlMesh + StlMesh, + Message is - WriteBinary (aMesh : Mesh from StlMesh; aPath : Path from OSD) + WriteBinary (aMesh : Mesh from StlMesh; aPath : Path from OSD; + aProgInd : ProgressIndicator from Message = NULL) returns Boolean from Standard; ---Purpose : write the meshing in a file following the -- binary format of an STL file. -- Returns false if the cannot be opened; - WriteAscii (aMesh : Mesh from StlMesh; aPath : Path from OSD) + WriteAscii (aMesh : Mesh from StlMesh; aPath : Path from OSD; + aProgInd : ProgressIndicator from Message = NULL) returns Boolean from Standard; ---Purpose : write the meshing in a file following the -- Ascii format of an STL file. -- Returns false if the cannot be opened; - ReadFile (aPath : Path from OSD) returns + ReadFile (aPath : Path from OSD; + aProgInd : ProgressIndicator from Message = NULL) returns Mesh from StlMesh; ---Purpose : This method will chwck if the file is a binary -- file or an AsciiFile testing the 5 first @@ -46,7 +50,8 @@ is -- ascii file. If we do not find that word we assume -- that it is a binary file. - ReadBinary (aPath : Path from OSD) returns + ReadBinary (aPath : Path from OSD; + aProgInd : ProgressIndicator from Message = NULL) returns Mesh from StlMesh; ---Purpose : Read a meshing from a binary file -- Raises NoMoreObject from Standard if a statement @@ -54,7 +59,8 @@ is -- Raises TypeMisMatch if a token has not the good -- type (often real) - ReadAscii (aPath : Path from OSD) returns + ReadAscii (aPath : Path from OSD; + aProgInd : ProgressIndicator from Message = NULL) returns Mesh from StlMesh; ---Purpose : Read a meshing from a binary file -- Raises NoMoreObject from Standard if a statement diff --git a/src/RWStl/RWStl.cxx b/src/RWStl/RWStl.cxx index 6bee4c329b..1abe9eb393 100755 --- a/src/RWStl/RWStl.cxx +++ b/src/RWStl/RWStl.cxx @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ static const int HEADER_SIZE = 84; static const int SIZEOF_STL_FACET = 50; static const int STL_MIN_FILE_SIZE = 284; static const int ASCII_LINES_PER_FACET = 7; +static const int IND_THRESHOLD = 1000; // increment the indicator every 1k triangles //======================================================================= //function : WriteInteger @@ -108,94 +110,114 @@ inline static Standard_Real ReadFloat2Double(OSD_File &aFile) //purpose : write a binary STL file in Little Endian format //======================================================================= -Standard_Boolean RWStl::WriteBinary(const Handle(StlMesh_Mesh)& aMesh, const OSD_Path& aPath) +Standard_Boolean RWStl::WriteBinary (const Handle(StlMesh_Mesh)& theMesh, + const OSD_Path& thePath, + const Handle(Message_ProgressIndicator)& theProgInd) { - - OSD_File theFile = OSD_File (aPath); - theFile.Build(OSD_WriteOnly,OSD_Protection()); + OSD_File aFile (thePath); + aFile.Build (OSD_WriteOnly, OSD_Protection()); Standard_Real x1, y1, z1; Standard_Real x2, y2, z2; Standard_Real x3, y3, z3; - //pgo Standard_Real x,y,z; - + // writing 80 bytes of the trash? char sval[80]; - Standard_Integer NBTRIANGLES=0; - unsigned int NBT; - NBTRIANGLES = aMesh->NbTriangles(); - NBT = NBTRIANGLES ; - theFile.Write ((Standard_Address)sval,80); - WriteInteger(theFile,NBT); -// theFile.Write ((Standard_Address)&NBT,4); + aFile.Write ((Standard_Address)sval,80); + WriteInteger (aFile, theMesh->NbTriangles()); + int dum=0; - StlMesh_MeshExplorer aMexp (aMesh); - - - for (Standard_Integer nbd=1;nbd<=aMesh->NbDomains();nbd++) { - for (aMexp.InitTriangle (nbd); aMexp.MoreTriangle (); aMexp.NextTriangle ()) { - aMexp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3); - //pgo aMexp.TriangleOrientation (x,y,z); - gp_XYZ Vect12 ((x2-x1), (y2-y1), (z2-z1)); - gp_XYZ Vect13 ((x3-x1), (y3-y1), (z3-z1)); - gp_XYZ Vnorm = Vect12 ^ Vect13; - Standard_Real Vmodul = Vnorm.Modulus (); - if (Vmodul > gp::Resolution()) { - Vnorm.Divide(Vmodul); - } - else { - // si Vnorm est quasi-nul, on le charge a 0 explicitement - Vnorm.SetCoord (0., 0., 0.); - } - - WriteDouble2Float (theFile,Vnorm.X()); - WriteDouble2Float (theFile,Vnorm.Y()); - WriteDouble2Float (theFile,Vnorm.Z()); - - WriteDouble2Float (theFile,x1); - WriteDouble2Float (theFile,y1); - WriteDouble2Float (theFile,z1); - - WriteDouble2Float (theFile,x2); - WriteDouble2Float (theFile,y2); - WriteDouble2Float (theFile,z2); - - WriteDouble2Float (theFile,x3); - WriteDouble2Float (theFile,y3); - WriteDouble2Float (theFile,z3); - - theFile.Write (&dum,2); + StlMesh_MeshExplorer aMexp (theMesh); + // create progress sentry for domains + Standard_Integer aNbDomains = theMesh->NbDomains(); + Message_ProgressSentry aDPS (theProgInd, "Mesh domains", 0, aNbDomains, 1); + for (Standard_Integer nbd = 1; nbd <= aNbDomains && aDPS.More(); nbd++, aDPS.Next()) + { + // create progress sentry for triangles in domain + Message_ProgressSentry aTPS (theProgInd, "Triangles", 0, + theMesh->NbTriangles (nbd), IND_THRESHOLD); + Standard_Integer aTriangleInd = 0; + for (aMexp.InitTriangle (nbd); aMexp.MoreTriangle(); aMexp.NextTriangle()) + { + aMexp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3); + //pgo aMexp.TriangleOrientation (x,y,z); + gp_XYZ Vect12 ((x2-x1), (y2-y1), (z2-z1)); + gp_XYZ Vect13 ((x3-x1), (y3-y1), (z3-z1)); + gp_XYZ Vnorm = Vect12 ^ Vect13; + Standard_Real Vmodul = Vnorm.Modulus (); + if (Vmodul > gp::Resolution()) + { + Vnorm.Divide(Vmodul); + } + else + { + // si Vnorm est quasi-nul, on le charge a 0 explicitement + Vnorm.SetCoord (0., 0., 0.); } - } - theFile.Close (); - return Standard_True; + WriteDouble2Float (aFile, Vnorm.X()); + WriteDouble2Float (aFile, Vnorm.Y()); + WriteDouble2Float (aFile, Vnorm.Z()); + + WriteDouble2Float (aFile, x1); + WriteDouble2Float (aFile, y1); + WriteDouble2Float (aFile, z1); + + WriteDouble2Float (aFile, x2); + WriteDouble2Float (aFile, y2); + WriteDouble2Float (aFile, z2); + + WriteDouble2Float (aFile, x3); + WriteDouble2Float (aFile, y3); + WriteDouble2Float (aFile, z3); + + aFile.Write (&dum, 2); + + // update progress only per 1k triangles + if (++aTriangleInd % IND_THRESHOLD == 0) + { + if (!aTPS.More()) + break; + aTPS.Next(); + } + } + } + aFile.Close(); + Standard_Boolean isInterrupted = !aDPS.More(); + return !isInterrupted; } //======================================================================= //function : WriteAscii //purpose : write an ASCII STL file //======================================================================= -Standard_Boolean RWStl::WriteAscii(const Handle(StlMesh_Mesh)& aMesh, const OSD_Path& aPath) +Standard_Boolean RWStl::WriteAscii (const Handle(StlMesh_Mesh)& theMesh, + const OSD_Path& thePath, + const Handle(Message_ProgressIndicator)& theProgInd) { - OSD_File theFile = OSD_File (aPath); + OSD_File theFile (thePath); theFile.Build(OSD_WriteOnly,OSD_Protection()); - TCollection_AsciiString buf = TCollection_AsciiString ("solid\n"); + TCollection_AsciiString buf ("solid\n"); theFile.Write (buf,buf.Length());buf.Clear(); Standard_Real x1, y1, z1; Standard_Real x2, y2, z2; Standard_Real x3, y3, z3; + char sval[512]; - //pgo Standard_Real x,y,z; - - char sval[16]; - - StlMesh_MeshExplorer aMexp (aMesh); - - for (Standard_Integer nbd=1;nbd<=aMesh->NbDomains();nbd++) { - for (aMexp.InitTriangle (nbd); aMexp.MoreTriangle (); aMexp.NextTriangle ()) { + // create progress sentry for domains + Standard_Integer aNbDomains = theMesh->NbDomains(); + Message_ProgressSentry aDPS (theProgInd, "Mesh domains", 0, aNbDomains, 1); + StlMesh_MeshExplorer aMexp (theMesh); + for (Standard_Integer nbd = 1; nbd <= aNbDomains && aDPS.More(); nbd++, aDPS.Next()) + { + // create progress sentry for triangles in domain + Message_ProgressSentry aTPS (theProgInd, "Triangles", 0, + theMesh->NbTriangles (nbd), IND_THRESHOLD); + Standard_Integer aTriangleInd = 0; + for (aMexp.InitTriangle (nbd); aMexp.MoreTriangle(); aMexp.NextTriangle()) + { aMexp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3); // Standard_Real x, y, z; @@ -203,76 +225,46 @@ Standard_Boolean RWStl::WriteAscii(const Handle(StlMesh_Mesh)& aMesh, const OSD_ gp_XYZ Vect12 ((x2-x1), (y2-y1), (z2-z1)); gp_XYZ Vect23 ((x3-x2), (y3-y2), (z3-z2)); - gp_XYZ Vnorm = Vect12 ^ Vect23; + gp_XYZ Vnorm = Vect12 ^ Vect23; Standard_Real Vmodul = Vnorm.Modulus (); - if (Vmodul > gp::Resolution()){ - Vnorm.Divide (Vmodul); + if (Vmodul > gp::Resolution()) + { + Vnorm.Divide (Vmodul); } - else { - // si Vnorm est quasi-nul, on le charge a 0 explicitement - Vnorm.SetCoord (0., 0., 0.); + else + { + // si Vnorm est quasi-nul, on le charge a 0 explicitement + Vnorm.SetCoord (0., 0., 0.); } - buf += " facet normal "; - sprintf (sval,"% 12e",Vnorm.X()); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",Vnorm.Y()); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",Vnorm.Z()); - buf += sval; - buf += '\n'; - theFile.Write (buf,buf.Length());buf.Clear(); - buf += " outer loop\n"; - theFile.Write (buf,buf.Length());buf.Clear(); + sprintf (sval, + " facet normal % 12e % 12e % 12e\n" + " outer loop\n" + " vertex % 12e % 12e % 12e\n" + " vertex % 12e % 12e % 12e\n" + " vertex % 12e % 12e % 12e\n" + " endloop\n" + " endfacet\n", + Vnorm.X(), Vnorm.Y(), Vnorm.Z(), + x1, y1, z1, + x2, y2, z2, + x3, y3, z3); + theFile.Write (buf, buf.Length()); buf.Clear(); - buf += " vertex "; - sprintf (sval,"% 12e",x1); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",y1); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",z1); - buf += sval; - buf += '\n'; - theFile.Write (buf,buf.Length());buf.Clear(); - - buf += " vertex "; - sprintf (sval,"% 12e",x2); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",y2); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",z2); - buf += sval; - buf += '\n'; - theFile.Write (buf,buf.Length());buf.Clear(); - - buf += " vertex "; - sprintf (sval,"% 12e",x3); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",y3); - buf += sval; - buf += " "; - sprintf (sval,"% 12e",z3); - buf += sval; - buf += '\n'; - theFile.Write (buf,buf.Length());buf.Clear(); - buf += " endloop\n"; - theFile.Write (buf,buf.Length());buf.Clear(); - buf += " endfacet\n"; - theFile.Write (buf,buf.Length());buf.Clear(); + // update progress only per 1k triangles + if (++aTriangleInd % IND_THRESHOLD == 0) + { + if (!aTPS.More()) + break; + aTPS.Next(); + } } } buf += "endsolid\n"; - theFile.Write (buf,buf.Length());buf.Clear(); - - theFile.Close (); - return Standard_True; + theFile.Write (buf, buf.Length()); buf.Clear(); + theFile.Close(); + Standard_Boolean isInterrupted = !aDPS.More(); + return !isInterrupted; } //======================================================================= //function : ReadFile @@ -280,9 +272,10 @@ Standard_Boolean RWStl::WriteAscii(const Handle(StlMesh_Mesh)& aMesh, const OSD_ //Warning : //======================================================================= -Handle_StlMesh_Mesh RWStl::ReadFile(const OSD_Path& aPath) +Handle_StlMesh_Mesh RWStl::ReadFile (const OSD_Path& thePath, + const Handle(Message_ProgressIndicator)& theProgInd) { - OSD_File file = OSD_File (aPath); + OSD_File file (thePath); file.Open(OSD_ReadOnly,OSD_Protection(OSD_RWD,OSD_RWD,OSD_RWD,OSD_RWD)); Standard_Boolean IsAscii; unsigned char str[128]; @@ -307,11 +300,8 @@ Handle_StlMesh_Mesh RWStl::ReadFile(const OSD_Path& aPath) #endif file.Close(); - if (IsAscii) { - return RWStl::ReadAscii (aPath); - } else { - return RWStl::ReadBinary (aPath); - } + return IsAscii ? RWStl::ReadAscii (thePath, theProgInd) + : RWStl::ReadBinary (thePath, theProgInd); } //======================================================================= @@ -320,7 +310,8 @@ Handle_StlMesh_Mesh RWStl::ReadFile(const OSD_Path& aPath) //Warning : //======================================================================= -Handle_StlMesh_Mesh RWStl::ReadBinary(const OSD_Path& aPath) +Handle_StlMesh_Mesh RWStl::ReadBinary (const OSD_Path& thePath, + const Handle(Message_ProgressIndicator)& /*theProgInd*/) { Standard_Integer NBFACET; Standard_Integer ifacet; @@ -331,7 +322,7 @@ Handle_StlMesh_Mesh RWStl::ReadBinary(const OSD_Path& aPath) adr = (Standard_Address)buftest; // Open the file - OSD_File theFile = OSD_File(aPath); + OSD_File theFile (thePath); theFile.Open(OSD_ReadOnly,OSD_Protection(OSD_RWD,OSD_RWD,OSD_RWD,OSD_RWD)); // the size of the file (minus the header size) @@ -396,7 +387,8 @@ Handle_StlMesh_Mesh RWStl::ReadBinary(const OSD_Path& aPath) //Warning : //======================================================================= -Handle_StlMesh_Mesh RWStl::ReadAscii(const OSD_Path& aPath) +Handle_StlMesh_Mesh RWStl::ReadAscii (const OSD_Path& thePath, + const Handle(Message_ProgressIndicator)& theProgInd) { TCollection_AsciiString filename; long ipos; @@ -407,7 +399,7 @@ Handle_StlMesh_Mesh RWStl::ReadAscii(const OSD_Path& aPath) Standard_Integer i1,i2,i3; Handle(StlMesh_Mesh) ReadMesh; - aPath.SystemName( filename); + thePath.SystemName (filename); // Open the file FILE* file = fopen(filename.ToCString(),"r"); @@ -444,7 +436,9 @@ Handle_StlMesh_Mesh RWStl::ReadAscii(const OSD_Path& aPath) ReadMesh->AddDomain(); // main reading - for (iTri = 0; iTri < nbTris; ++iTri) { + Message_ProgressSentry aPS (theProgInd, "Triangles", 0, (nbTris - 1) * 1.0 / IND_THRESHOLD, 1); + for (iTri = 0; iTri < nbTris && aPS.More();) + { // reading the facet normal fscanf(file,"%*s %*s %f %f %f\n",&x[0],&y[0],&z[0]); @@ -469,6 +463,9 @@ Handle_StlMesh_Mesh RWStl::ReadAscii(const OSD_Path& aPath) // skip the keywords "endfacet" fscanf(file,"%*s"); + // update progress only per 1k triangles + if (++iTri % IND_THRESHOLD == 0) + aPS.Next(); } #ifdef DEB cout << "end mesh\n"; diff --git a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx index 93fafe7745..1eb7656d5b 100755 --- a/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx +++ b/src/XSDRAWSTLVRML/XSDRAWSTLVRML.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -119,7 +120,7 @@ static Standard_Integer writevrml //======================================================================= //function : loadvrml -//purpose : +//purpose : //======================================================================= static Standard_Integer loadvrml @@ -184,7 +185,7 @@ static Standard_Integer loadvrml //======================================================================= //function : storevrml -//purpose : +//purpose : //======================================================================= static Standard_Integer storevrml @@ -216,7 +217,7 @@ static Standard_Integer storevrml filebuf foc; ostream outStream (&foc); if (foc.open (argv[2], ios::out)) - outStream << aScene; + outStream << aScene; } return 0; } @@ -233,9 +234,10 @@ static Standard_Integer createmesh return 1; } + // Progress indicator OSD_Path aFile( argv[2] ); - Handle( StlMesh_Mesh ) aSTLMesh = RWStl::ReadFile( aFile ); - // DBRep::Set(argv[1],shape); + Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1); + Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress); di << "Reading OK..." << "\n"; Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh ); @@ -267,7 +269,7 @@ static Standard_Integer createmesh if ( aContext.IsNull() ) { - ViewerTest::ViewerInit(); + ViewerTest::ViewerInit(); //To create a 3D view if it doesn't exist aContext = ViewerTest::GetAISContext(); if( aContext.IsNull() ) @@ -616,9 +618,9 @@ static Standard_Integer showonly di << "The context is null" << "\n"; else { - Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = + Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes()); - Handle(TColStd_HPackedMapOfInteger) aHiddenElements = + Handle(TColStd_HPackedMapOfInteger) aHiddenElements = new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements()); for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) { @@ -705,8 +707,8 @@ static Standard_Integer delmesh } //----------------------------------------------------------------------------- -static Standard_Integer meshcolors( Draw_Interpretor& di, - Standard_Integer argc, +static Standard_Integer meshcolors( Draw_Interpretor& di, + Standard_Integer argc, const char** argv ) { try @@ -720,9 +722,9 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, di << " elem2 - one color for one side"<<"\n"; di << " nodal - different color for each node"<< "\n"; di << " nodaltex - different color for each node with texture interpolation"<< "\n"; - di << " none - clear"<< "\n"; + di << " none - clear"<< "\n"; di << "isreflect : {0|1} "<< "\n"; - + return 0; } @@ -761,7 +763,7 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") ) { - Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder( + Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder( aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask ); // Color const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements(); @@ -780,10 +782,10 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, aMesh->AddBuilder( aBuilder, Standard_True ); } - + if( aMode.IsEqual("nodal") ) { - Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( + Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask ); aMesh->AddBuilder( aBuilder, Standard_True ); @@ -793,7 +795,7 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes ); for ( ; anIter.More(); anIter.Next() ) { - Quantity_Color aColor( (Quantity_NameOfColor)( + Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) ); aBuilder->SetColor( anIter.Key(), aColor ); } @@ -803,7 +805,7 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, if(aMode.IsEqual("nodaltex")) { // assign nodal builder to the mesh - Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( + Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask); aMesh->AddBuilder(aBuilder, Standard_True); aBuilder->UseTexture(Standard_True); @@ -846,7 +848,7 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, aScaleValue = 0; } - aScaleMap.Bind(anIter.Key(), aScaleValue); + aScaleMap.Bind(anIter.Key(), aScaleValue); } //set color map for builder and a color for invalid scale value @@ -854,7 +856,7 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, aBuilder->SetInvalidColor(Quantity_NOC_BLACK); aBuilder->SetTextureCoords(aScaleMap); aMesh->AddBuilder(aBuilder, Standard_True); - + //set viewer to display texures const Handle(V3d_Viewer)& aViewer = anIC->CurrentViewer(); for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) @@ -866,7 +868,7 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, anIC->Redisplay( aMesh ); } else - { + { di << "Wrong mode name" << "\n"; return 0; } @@ -881,8 +883,8 @@ static Standard_Integer meshcolors( Draw_Interpretor& di, } //----------------------------------------------------------------------------- -static Standard_Integer mesh_edge_width( Draw_Interpretor& di, - Standard_Integer argc, +static Standard_Integer mesh_edge_width( Draw_Interpretor& di, + Standard_Integer argc, const char** argv ) { try