readstl syntax has been modified, so that it creates a single-face triangulation by default.
The argument "trinagulation" is no more supported.
The new argument "-brep" has been introduced to generate
a compound of per-triangle faces instead (old default behavior of the command).
const std::streamsize aDataToRead = aNbFacesInBuffer * aFaceDataLen;
if (theStream.read (aBuffer, aDataToRead).gcount() != aDataToRead)
{
- Message::DefaultMessenger()->Send ("Error: read filed", Message_Fail);
+ Message::DefaultMessenger()->Send ("Error: binary STL read failed", Message_Fail);
return false;
}
aBufferPtr = aBuffer;
Standard_Integer theArgc,
const char** theArgv)
{
- if (theArgc < 3)
- {
- theDI << "wrong number of parameters" << "\n";
- return 1;
- }
- else
+ TCollection_AsciiString aShapeName, aFilePath;
+ bool toCreateCompOfTris = false;
+ for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
{
- if (theArgc == 4 &&
- strcmp("triangulation", theArgv[3]) == 0)
+ TCollection_AsciiString anArg (theArgv[anArgIter]);
+ anArg.LowerCase();
+ if (aShapeName.IsEmpty())
{
- // Read STL file to the triangulation.
- Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
- Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile (theArgv[2], aProgress);
-
- TopoDS_Face aFace;
- BRep_Builder aB;
- aB.MakeFace(aFace);
- aB.UpdateFace(aFace, aTriangulation);
- DBRep::Set(theArgv[1], aFace);
+ aShapeName = theArgv[anArgIter];
+ }
+ else if (aFilePath.IsEmpty())
+ {
+ aFilePath = theArgv[anArgIter];
+ }
+ else if (anArg == "-brep")
+ {
+ toCreateCompOfTris = true;
+ if (anArgIter + 1 < theArgc
+ && ViewerTest::ParseOnOff (theArgv[anArgIter + 1], toCreateCompOfTris))
+ {
+ ++anArgIter;
+ }
}
else
{
- TopoDS_Shape aShape;
- Standard_DISABLE_DEPRECATION_WARNINGS
- StlAPI::Read(aShape, theArgv[2]);
- Standard_ENABLE_DEPRECATION_WARNINGS
- DBRep::Set(theArgv[1], aShape);
+ std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
+ return 1;
}
}
+ if (aFilePath.IsEmpty())
+ {
+ std::cout << "Syntax error: not enough arguments\n";
+ return 1;
+ }
+ TopoDS_Shape aShape;
+ if (!toCreateCompOfTris)
+ {
+ // Read STL file to the triangulation.
+ Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
+ Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile (aFilePath.ToCString(), aProgress);
+
+ TopoDS_Face aFace;
+ BRep_Builder aB;
+ aB.MakeFace (aFace);
+ aB.UpdateFace (aFace, aTriangulation);
+ aShape = aFace;
+ }
+ else
+ {
+ Standard_DISABLE_DEPRECATION_WARNINGS
+ StlAPI::Read(aShape, aFilePath.ToCString());
+ Standard_ENABLE_DEPRECATION_WARNINGS
+ }
+ DBRep::Set (aShapeName.ToCString(), aShape);
return 0;
}
theCommands.Add ("writevrml", "shape file [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 1 by default]",__FILE__,writevrml,g);
theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
- theCommands.Add ("readstl", "shape file [triangulation: no by default]",__FILE__,readstl,g);
+ theCommands.Add ("readstl",
+ "readstl shape file [-brep]"
+ "\n\t\t: Reads STL file and creates a new shape with specified name."
+ "\n\t\t: When -brep is specified, creates a Compound of per-triangle Faces."
+ "\n\t\t: Single triangulation-only Face is created otherwise (default).",
+ __FILE__, readstl, g);
theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
catch {exec chmod 777 ${aFile}}
if { [file exists ${aFile}] } {
- readstl result ${aFile}
+ readstl result ${aFile} -brep
checknbshapes result -vertex 8 -edge 18 -wire 12 -face 12 -shell 1 -solid 0 -compsolid 0 -compound 0 -shape 51
# Check file size
catch {exec chmod 777 ${aFile}}
if { [file exists ${aFile}] } {
- readstl result ${aFile}
+ readstl result ${aFile} -brep
checknbshapes result -vertex 8 -edge 18 -wire 12 -face 12 -shell 1 -solid 0 -compsolid 0 -compound 0 -shape 51
# Check file size
puts ""
pload VISUALIZATION XDE MODELING
-readstl m [locate_data_file model_stl_045.stl] triangulation
+readstl m [locate_data_file model_stl_045.stl]
vclear
vinit View1
vdisplay -dispMode 1 m
writestl comp $imagedir/${casename}.stl 1
# load STL
-readstl result $imagedir/${casename}.stl
+readstl result $imagedir/${casename}.stl -brep
# check that bounding box is
bounding -s result -save Xmin Ymin Zmin Xmax Ymax Zmax -nodraw
# Data Exchange - STL file having less than 4 triangles cannot be read
########################################################################
-readstl result [locate_data_file bug27622_Design1.stl]
+readstl result [locate_data_file bug27622_Design1.stl] -brep
set nbshapes_expected "
Number of shapes in result
-readstl m [locate_data_file bug28680_sample01b.stl] triangulation
+readstl m [locate_data_file bug28680_sample01b.stl]
# Number of triangles check
checktrinfo m -tri 62075 -nod 31879
set BugNumber OCC22670
-readstl res_mesh [locate_data_file OMF6391_box.stl]
+readstl res_mesh [locate_data_file OMF6391_box.stl] -brep
set aFile ${imagedir}/OCC22670.stl
file delete ${aFile}
writestl res_mesh ${aFile} ${anASCIImode}
catch {exec chmod 777 ${aFile}}
-readstl result ${aFile}
+readstl result ${aFile} -brep
checknbshapes result -vertex 8 -edge 18 -wire 12 -face 12 -shell 1 -solid 0 -compsolid 0 -compound 0 -shape 51
checkview -display result -2d -path ${imagedir}/${test_image}.png
set BugNumber OCC22670
set filepath [locate_data_file OMF6391_box.stl]
-if { [catch { readstl res_mesh $filepath } catch_result] } {
+if { [catch { readstl res_mesh $filepath -brep } catch_result] } {
puts "Faulty ${BugNumber}: here is reading problem"
} else {
set aFile $imagedir/${test_image}.stl
writestl res_mesh ${aFile} ${anASCIImode}
catch {exec chmod 777 ${aFile}}
- readstl result ${aFile}
+ readstl result ${aFile} -brep
checknbshapes result -vertex 8 -edge 18 -wire 12 -face 12 -shell 1 -solid 0 -compsolid 0 -compound 0 -shape 51
}
# STL
incmesh hammer 38.9076
writestl hammer $imagedir/hammer.stl
-readstl stl $imagedir/hammer.stl
+readstl stl $imagedir/hammer.stl -brep
checkshape stl
tolerance stl
checkarea stl 3.978e8 1e6 0.001
# StlAPI_Reader still use old Sewing algorithm
#######################################################################################
-## readstl command from XSDRAWSTLVRML.cxx file !!!!!
-
set BugNumber OCC6384
-readstl res_mesh [locate_data_file OMF6391_box.stl]
+readstl res_mesh [locate_data_file OMF6391_box.stl] -brep
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 22748 -nod 11376
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 130 -nod 67
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 150 -nod 77
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 4396 -nod 2200
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 290 -nod 147
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 200 -nod 102
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 146 -nod 75
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 13102 -nod 6553
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 2398 -nod 1201
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 40 -nod 22
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 58 -nod 31
# Save, read and delete file
writestl m $imagedir/${casename}
-readstl res $imagedir/${casename} triangulation
+readstl res $imagedir/${casename}
file delete $imagedir/${casename}
checktrinfo res -tri 56 -nod 30
-readstl m [locate_data_file model_stl_001.stl] triangulation
+readstl m [locate_data_file model_stl_001.stl]
# Number of triangles check
checktrinfo m -tri 3609 -nod 1807
-readstl m [locate_data_file model_stl_010.stl] triangulation
+readstl m [locate_data_file model_stl_010.stl]
# Number of triangles check
checktrinfo m -tri 26582 -nod 13346
-readstl m [locate_data_file model_stl_011.stl] triangulation
+readstl m [locate_data_file model_stl_011.stl]
# Number of triangles check
checktrinfo m -tri 9170 -nod 4595
-readstl m [locate_data_file model_stl_012.stl] triangulation
+readstl m [locate_data_file model_stl_012.stl]
# Number of triangles check
checktrinfo m -tri 10059 -nod 5036
-readstl m [locate_data_file model_stl_013.stl] triangulation
+readstl m [locate_data_file model_stl_013.stl]
# Number of triangles check
checktrinfo m -tri 8773 -nod 4406
-readstl m [locate_data_file model_stl_014.stl] triangulation
+readstl m [locate_data_file model_stl_014.stl]
# Number of triangles check
checktrinfo m -tri 18462 -nod 9272
-readstl m [locate_data_file model_stl_015.stl] triangulation
+readstl m [locate_data_file model_stl_015.stl]
# Number of triangles check
checktrinfo m -tri 7662 -nod 3836
-readstl m [locate_data_file model_stl_002.stl] triangulation
+readstl m [locate_data_file model_stl_002.stl]
# Number of triangles check
checktrinfo m -tri 19034 -nod 9535
-readstl m [locate_data_file model_stl_003.stl] triangulation
+readstl m [locate_data_file model_stl_003.stl]
# Number of triangles check
checktrinfo m -tri 3236 -nod 1620
-readstl m [locate_data_file model_stl_004.stl] triangulation
+readstl m [locate_data_file model_stl_004.stl]
# Number of triangles check
checktrinfo m -tri 15479 -nod 7793
-readstl m [locate_data_file model_stl_005.stl] triangulation
+readstl m [locate_data_file model_stl_005.stl]
# Number of triangles check
checktrinfo m -tri 10526 -nod 5265
-readstl m [locate_data_file model_stl_006.stl] triangulation
+readstl m [locate_data_file model_stl_006.stl]
# Number of triangles check
checktrinfo m -tri 14447 -nod 7264
-readstl m [locate_data_file model_stl_007.stl] triangulation
+readstl m [locate_data_file model_stl_007.stl]
# Number of triangles check
checktrinfo m -tri 4199 -nod 2109
-readstl m [locate_data_file model_stl_008.stl] triangulation
+readstl m [locate_data_file model_stl_008.stl]
# Number of triangles check
checktrinfo m -tri 22149 -nod 11118
-readstl m [locate_data_file model_stl_009.stl] triangulation
+readstl m [locate_data_file model_stl_009.stl]
# Number of triangles check
checktrinfo m -tri 5678 -nod 2841
-readstl m [locate_data_file model_stl_016.stl] triangulation
+readstl m [locate_data_file model_stl_016.stl]
# Number of triangles check
checktrinfo m -tri 68 -nod 36
-readstl m [locate_data_file model_stl_025.stl] triangulation
+readstl m [locate_data_file model_stl_025.stl]
# Number of triangles check
checktrinfo m -tri 54364 -nod 24452
-readstl m [locate_data_file model_stl_026.stl] triangulation
+readstl m [locate_data_file model_stl_026.stl]
# Number of triangles check
checktrinfo m -tri 41113 -nod 18457
-readstl m [locate_data_file model_stl_027.stl] triangulation
+readstl m [locate_data_file model_stl_027.stl]
# Number of triangles check
checktrinfo m -tri 7440 -nod 3720
-readstl m [locate_data_file model_stl_028.stl] triangulation
+readstl m [locate_data_file model_stl_028.stl]
# Number of triangles check
checktrinfo m -tri 10956 -nod 5238
-readstl m [locate_data_file model_stl_029.stl] triangulation
+readstl m [locate_data_file model_stl_029.stl]
# Number of triangles check
checktrinfo m -tri 33313 -nod 15442
-readstl m [locate_data_file model_stl_030.stl] triangulation
+readstl m [locate_data_file model_stl_030.stl]
# Number of triangles check
checktrinfo m -tri 38380 -nod 19158
-readstl m [locate_data_file model_stl_017.stl] triangulation
+readstl m [locate_data_file model_stl_017.stl]
# Number of triangles check
checktrinfo m -tri 1 -nod 3
-readstl m [locate_data_file model_stl_018.stl] triangulation
+readstl m [locate_data_file model_stl_018.stl]
# Number of triangles check
checktrinfo m -tri 2 -nod 5
-readstl m [locate_data_file model_stl_019.stl] triangulation
+readstl m [locate_data_file model_stl_019.stl]
# Number of triangles check
checktrinfo m -tri 509952 -nod 254992
-readstl m [locate_data_file model_stl_020.stl] triangulation
+readstl m [locate_data_file model_stl_020.stl]
# Number of triangles check
checktrinfo m -tri 26840 -nod 13432
-readstl m [locate_data_file model_stl_021.stl] triangulation
+readstl m [locate_data_file model_stl_021.stl]
# Number of triangles check
checktrinfo m -tri 63268 -nod 31445
-readstl m [locate_data_file model_stl_022.stl] triangulation
+readstl m [locate_data_file model_stl_022.stl]
# Number of triangles check
checktrinfo m -tri 4388 -nod 2194
-readstl m [locate_data_file model_stl_023.stl] triangulation
+readstl m [locate_data_file model_stl_023.stl]
# Number of triangles check
checktrinfo m -tri 288 -nod 144
-readstl m [locate_data_file model_stl_024.stl] triangulation
+readstl m [locate_data_file model_stl_024.stl]
# Number of triangles check
checktrinfo m -tri 116 -nod 60
-readstl m [locate_data_file model_stl_031.stl] triangulation
+readstl m [locate_data_file model_stl_031.stl]
# Number of triangles check
checktrinfo m -tri 29606 -nod 14817
-readstl m [locate_data_file model_stl_040.stl] triangulation
+readstl m [locate_data_file model_stl_040.stl]
# Number of triangles check
checktrinfo m -tri 5720 -nod 2864
-readstl m [locate_data_file model_stl_041.stl] triangulation
+readstl m [locate_data_file model_stl_041.stl]
# Number of triangles check
checktrinfo m -tri 6082 -nod 3052
-readstl m [locate_data_file model_stl_042.stl] triangulation
+readstl m [locate_data_file model_stl_042.stl]
# Number of triangles check
checktrinfo m -tri 10131 -nod 5068
-readstl m [locate_data_file model_stl_043.stl] triangulation
+readstl m [locate_data_file model_stl_043.stl]
# Number of triangles check
checktrinfo m -tri 17780 -nod 8954
-readstl m [locate_data_file model_stl_044.stl] triangulation
+readstl m [locate_data_file model_stl_044.stl]
# Number of triangles check
checktrinfo m -tri 5998 -nod 3002
-readstl m [locate_data_file model_stl_045.stl] triangulation
+readstl m [locate_data_file model_stl_045.stl]
# Number of triangles check
checktrinfo m -tri 19011 -nod 9598
-readstl m [locate_data_file model_stl_032.stl] triangulation
+readstl m [locate_data_file model_stl_032.stl]
# Number of triangles check
checktrinfo m -tri 4340 -nod 2172
-readstl m [locate_data_file model_stl_033.stl] triangulation
+readstl m [locate_data_file model_stl_033.stl]
# Number of triangles check
checktrinfo m -tri 25560 -nod 12928
-readstl m [locate_data_file model_stl_034.stl] triangulation
+readstl m [locate_data_file model_stl_034.stl]
# Number of triangles check
checktrinfo m -tri 10762 -nod 5387
-readstl m [locate_data_file model_stl_035.stl] triangulation
+readstl m [locate_data_file model_stl_035.stl]
# Number of triangles check
checktrinfo m -tri 21778 -nod 10963
-readstl m [locate_data_file model_stl_036.stl] triangulation
+readstl m [locate_data_file model_stl_036.stl]
# Number of triangles check
checktrinfo m -tri 7806 -nod 3907
-readstl m [locate_data_file model_stl_037.stl] triangulation
+readstl m [locate_data_file model_stl_037.stl]
# Number of triangles check
checktrinfo m -tri 8286 -nod 4164
-readstl m [locate_data_file model_stl_038.stl] triangulation
+readstl m [locate_data_file model_stl_038.stl]
# Number of triangles check
checktrinfo m -tri 6811 -nod 3408
-readstl m [locate_data_file model_stl_039.stl] triangulation
+readstl m [locate_data_file model_stl_039.stl]
# Number of triangles check
checktrinfo m -tri 19651 -nod 9862
fconfigure $fd -translation crlf
puts $fd $minimal_ascii_stl
close $fd
-readstl res_one_ascii_dos ${imagedir}/${casename}_one_ascii_dos.stl
+readstl res_one_ascii_dos ${imagedir}/${casename}_one_ascii_dos.stl -brep
checknbshapes res_one_ascii_dos -face 1
puts "\n#======================================================================"
fconfigure $fd -translation lf
puts $fd $minimal_ascii_stl
close $fd
-readstl res_one_ascii_unix ${imagedir}/${casename}_one_ascii_unix.stl
+readstl res_one_ascii_unix ${imagedir}/${casename}_one_ascii_unix.stl -brep
checknbshapes res_one_ascii_unix -face 1
puts "\n#======================================================================"
fconfigure $fd -translation lf
puts -nonewline $fd $minimal_ascii_stl
close $fd
-readstl res_one_ascii_noeol ${imagedir}/${casename}_one_ascii_noeol.stl
+readstl res_one_ascii_noeol ${imagedir}/${casename}_one_ascii_noeol.stl -brep
checknbshapes res_one_ascii_noeol -face 1
puts "\n#======================================================================"
fconfigure $fd -translation crlf
puts $fd "solid \nendsolid"
close $fd
-readstl res_zero_ascii_dos ${imagedir}/${casename}_zero_ascii_dos.stl
+readstl res_zero_ascii_dos ${imagedir}/${casename}_zero_ascii_dos.stl -brep
puts "\n#======================================================================"
puts "# Ascii file with no facets, LF"
fconfigure $fd -translation lf
puts $fd "solid \nendsolid"
close $fd
-readstl res_zero_ascii_unix ${imagedir}/${casename}_zero_ascii_unix.stl
+readstl res_zero_ascii_unix ${imagedir}/${casename}_zero_ascii_unix.stl -brep
puts "\n#======================================================================"
puts "# Binary file with single facet"
puts -nonewline $fd "stl [string repeat { } 76]"
puts -nonewline $fd [binary format if3f3f3f3t 1 {0 0 1} {0 0 0} {1 0 0} {0 1 0} 0]
close $fd
-readstl res_one_binary ${imagedir}/${casename}_one_binary.stl
+readstl res_one_binary ${imagedir}/${casename}_one_binary.stl -brep
checknbshapes res_one_binary -face 1
puts "\n#======================================================================"
fconfigure $fd -translation binary
puts -nonewline $fd "stl [string repeat { } 76][binary format i 0]"
close $fd
-readstl res_zero_binary ${imagedir}/${casename}_zero_binary.stl
+readstl res_zero_binary ${imagedir}/${casename}_zero_binary.stl -brep
puts "\n#======================================================================"
puts "# Empty file"
puts "REQUIRED ALL: Error: unexpected format of facet at line 2"
set fd [open ${imagedir}/${casename}_empty.stl w]
close $fd
-readstl res_empty ${imagedir}/${casename}_empty.stl
+readstl res_empty ${imagedir}/${casename}_empty.stl -brep