1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33import sys
34from pathlib import Path
35import os
36
37import cadexchanger.CadExCore as cadex
38import cadexchanger.CadExAdvGeom as geom
39
40sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
41import cadex_license as license
42
43
44class PolyRepExplorer(cadex.ModelData_Part_VoidRepresentationVisitor):
45 def __init__(self):
46 super().__init__()
47 self.myNumberOfTriangles = 0
48
49 def VisitPoly(self, theRep: cadex.ModelData_PolyRepresentation):
50 aShapeList = theRep.Get()
51 for aShape in aShapeList:
53 anITS = cadex.ModelData_IndexedTriangleSet.Cast(aShape)
54 self.myNumberOfTriangles += anITS.NumberOfFaces()
55
56class TriangleCounter(cadex.ModelData_Model_VoidElementVisitor):
57 def __init__(self):
58 super().__init__()
59 self.myNumberOfTriangles = 0
60
61 def VisitPart(self, thePart: cadex.ModelData_Part):
62 aRepExplorer = PolyRepExplorer()
63 thePart.Accept(aRepExplorer)
64 self.myNumberOfTriangles += aRepExplorer.myNumberOfTriangles
65
66
67def main(theSource: str, theDest: str):
68 aKey = license.Value()
69
70 if not cadex.LicenseManager.Activate(aKey):
71 print("Failed to activate CAD Exchanger license.")
72 return 1
73
75
77
78
80 print("Failed to open and convert the file " + theSource)
81 return 1
82
83
84 aBeforeCounter = TriangleCounter()
85 aModel.AcceptElementVisitor(aBeforeCounter)
86 print(f"Model name: {aModel.Name()}")
87 print(f"# of triangles before: {aBeforeCounter.myNumberOfTriangles}")
88
89
90 aParams = geom.ModelSimplifier_MeshSimplifierParameters()
91 aParams.SetDegreeOfSimplification(geom.ModelSimplifier_MeshSimplifierParameters.High)
92
93 aSimplifier = geom.ModelSimplifier_MeshSimplifier()
94 aSimplifier.SetParameters(aParams)
95 aNewModel = aSimplifier.Perform(aModel)
96
97
98 anAfterCounter = TriangleCounter()
99 aNewModel.AcceptElementVisitor(anAfterCounter)
100 print(f"# of triangles after: {anAfterCounter.myNumberOfTriangles}")
101
102
104 print("Failed to save the .cdx file")
105 return 1
106
107 print("Completed")
108 return 0
109
110if __name__ == "__main__":
111 if len(sys.argv) != 3:
112 print(" <input_file> is a name of the VRML file to be read")
113 print(" <output_file> is a name of the CDX file to Save() the model")
114 sys.exit(1)
115
116 aSource = os.path.abspath(sys.argv[1])
117 aDest = os.path.abspath(sys.argv[2])
118
119 sys.exit(main(aSource, aDest))
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
static IdType GetTypeId()
Definition: ModelData_IndexedTriangleSet.cxx:134
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:33