]> gerrit.simantics Code Review - simantics/3d.git/blob - org.jcae.opencascade/src-java-test/org/jcae/opencascade/jni/FixSmallEdges.java
Include old 64-bit versions of org.jcae.opencascade and vtk bundles
[simantics/3d.git] / org.jcae.opencascade / src-java-test / org / jcae / opencascade / jni / FixSmallEdges.java
1 /*
2  * Project Info:  http://jcae.sourceforge.net
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 2.1 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17  *
18  * (C) Copyright 2007, by EADS France
19  */
20
21 package org.jcae.opencascade.jni;
22
23 import static org.junit.Assert.*;
24 import org.junit.Test;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import org.jcae.opencascade.Utilities;
31
32 /**
33  *
34  * @author Jerome Robert
35  */
36 public class FixSmallEdges {
37
38         private static int countSmallEdges(TopoDS_Shape shape, double minLength)
39         {
40                 TopExp_Explorer exp = new TopExp_Explorer(shape, TopAbs_ShapeEnum.EDGE);
41                 GProp_GProps property=new GProp_GProps();
42                 
43                 int count = 0;
44                 int index = 1;
45                 while(exp.more())
46                 {
47                         TopoDS_Edge edge = (TopoDS_Edge) exp.current();
48                         BRepGProp.linearProperties(edge, property);
49                         double l = property.mass();
50                         if(l < minLength)
51                         {
52                                 System.out.println(index+" "+l);
53                                 count++;                        
54                         }
55                         exp.next();
56                         index++;
57                 }
58                 return count;
59         }
60
61         public static void main(String[] args)
62         {
63                 try
64                 {
65                         if (args.length != 3) displayHelp();
66                         if (!new File(args[0]).canRead())
67                         {
68                                 System.out.println("Cannot open " + args[0]);
69                                 return;
70                         }
71
72                         double tolerance;
73                         try
74                         {
75                                 tolerance = Double.parseDouble(args[1]);
76                         }
77                         catch (NumberFormatException ex)
78                         {
79                                 displayHelp();
80                                 return;
81                         }
82
83                         if (!new File(args[2]).createNewFile())
84                         {
85                                 System.out.println("Cannot create " + args[2]);
86                                 return;
87                         }
88
89                         TopoDS_Shape shape = Utilities.readFile(args[0]);
90                         System.out.println("Number of small edges before: " +
91                                 countSmallEdges(shape, tolerance));
92                         ShapeFix_Wireframe fix =
93                                 new ShapeFix_Wireframe(shape);
94                         fix.setPrecision(tolerance);
95                         fix.fixSmallEdges();
96                         shape = fix.shape();
97                         System.out.println("Number of small edges after: " +
98                                 countSmallEdges(shape, tolerance));
99                         BRepTools.write(shape, args[2]);
100                 }
101                 catch (IOException ex)
102                 {
103                         Logger.getLogger(FixSmallEdges.class.getName()).
104                                 log(Level.SEVERE, null, ex);
105                 }
106         }
107
108         private static void displayHelp()
109         {
110                 System.out.println("Syntax: fixsmalledge <input file> <tolerance> <output file>");
111         }
112 }