#include <RWStl.ixx>
#include <OSD_Protection.hxx>
#include <OSD_File.hxx>
+#include <Message_ProgressSentry.hxx>
#include <TCollection_AsciiString.hxx>
#include <Standard_NoMoreObject.hxx>
#include <Standard_TypeMismatch.hxx>
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
//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.);
+ }
+
+ 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();
}
+ }
}
-
- theFile.Close ();
- return Standard_True;
+ 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;
-
- //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 ()) {
+ char sval[512];
+
+ // 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;
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.);
+ 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();
+
+ // update progress only per 1k triangles
+ if (++aTriangleInd % IND_THRESHOLD == 0)
+ {
+ if (!aTPS.More())
+ break;
+ aTPS.Next();
}
- 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();
-
- 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();
}
}
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
//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];
#endif
file.Close();
- if (IsAscii) {
- return RWStl::ReadAscii (aPath);
- } else {
- return RWStl::ReadBinary (aPath);
- }
+ return IsAscii ? RWStl::ReadAscii (thePath, theProgInd)
+ : RWStl::ReadBinary (thePath, theProgInd);
}
//=======================================================================
//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;
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)
//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;
Standard_Integer i1,i2,i3;
Handle(StlMesh_Mesh) ReadMesh;
- aPath.SystemName( filename);
+ thePath.SystemName (filename);
// Open the file
FILE* file = fopen(filename.ToCString(),"r");
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]);
// 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";
#include <AIS_InteractiveContext.hxx>
#include <ViewerTest.hxx>
#include <Draw.hxx>
+#include <Draw_ProgressIndicator.hxx>
#include <RWStl.hxx>
#include <Quantity_Color.hxx>
#include <V3d_View.hxx>
//=======================================================================
//function : loadvrml
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer loadvrml
//=======================================================================
//function : storevrml
-//purpose :
+//purpose :
//=======================================================================
static Standard_Integer storevrml
filebuf foc;
ostream outStream (&foc);
if (foc.open (argv[2], ios::out))
- outStream << aScene;
+ outStream << aScene;
}
return 0;
}
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 );
if ( aContext.IsNull() )
{
- ViewerTest::ViewerInit();
+ ViewerTest::ViewerInit();
//To create a 3D view if it doesn't exist
aContext = ViewerTest::GetAISContext();
if( aContext.IsNull() )
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() )
{
}
//-----------------------------------------------------------------------------
-static Standard_Integer meshcolors( Draw_Interpretor& di,
- Standard_Integer argc,
+static Standard_Integer meshcolors( Draw_Interpretor& di,
+ Standard_Integer argc,
const char** argv )
{
try
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;
}
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();
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 );
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 );
}
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);
aScaleValue = 0;
}
- aScaleMap.Bind(anIter.Key(), aScaleValue);
+ aScaleMap.Bind(anIter.Key(), aScaleValue);
}
//set color map for builder and a color for invalid scale value
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())
anIC->Redisplay( aMesh );
}
else
- {
+ {
di << "Wrong mode name" << "\n";
return 0;
}
}
//-----------------------------------------------------------------------------
-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