Example #1
0
 /**
  * Compute the bounding box of the shape and return the maximum bound value
  *
  * @param shape
  * @return
  */
 public static float getMaxBound(final TopoDS_Shape shape) {
   Bnd_Box box = new Bnd_Box();
   BRepBndLib.add(shape, box);
   double[] bbox = box.get();
   double minBoundingBox =
       Math.max(Math.max(bbox[3] - bbox[0], bbox[4] - bbox[1]), bbox[5] - bbox[2]);
   return (float) minBoundingBox;
 }
Example #2
0
  public static List<float[]> createEdgeArrays(final TopoDS_Shape topoDS_Shape) {

    final List edgeArrays = new ArrayList<float[]>();

    TopExp_Explorer explorer = new TopExp_Explorer();
    HashSet<TopoDS_Edge> alreadyDone = new HashSet<TopoDS_Edge>();
    Bnd_Box box = new Bnd_Box();
    BRepBndLib.add(topoDS_Shape, box);

    double[] bbox = box.get();
    // double[] bbox=computeBoundingBox();

    double boundingBoxDeflection =
        0.0005 * Math.max(Math.max(bbox[3] - bbox[0], bbox[4] - bbox[1]), bbox[5] - bbox[2]);

    for (explorer.init(topoDS_Shape, TopAbs_ShapeEnum.EDGE); explorer.more(); explorer.next()) {
      TopoDS_Shape s = explorer.current();
      if (!(s instanceof TopoDS_Edge)) continue; // should not happen!
      TopoDS_Edge e = (TopoDS_Edge) s;

      if (!alreadyDone.add(e)) continue;

      double[] range = BRep_Tool.range(e);
      Geom_Curve gc = BRep_Tool.curve(e, range);
      float[] array;
      if (gc != null) {
        GeomAdaptor_Curve adaptator = new GeomAdaptor_Curve(gc);
        GCPnts_UniformDeflection deflector = new GCPnts_UniformDeflection();

        deflector.initialize(adaptator, boundingBoxDeflection, range[0], range[1]);
        int npts = deflector.nbPoints();

        // Allocate one additional point at each end  = parametric value 0, 1
        array = new float[(npts + 2) * 3];
        int j = 0;
        double[] values = adaptator.value(range[0]);
        array[j++] = (float) values[0];
        array[j++] = (float) values[1];
        array[j++] = (float) values[2];
        // All intermediary points
        for (int i = 0; i < npts; ++i) {
          values = adaptator.value(deflector.parameter(i + 1));
          array[j++] = (float) values[0];
          array[j++] = (float) values[1];
          array[j++] = (float) values[2];
        }
        // Add last point
        values = adaptator.value(range[1]);
        array[j++] = (float) values[0];
        array[j++] = (float) values[1];
        array[j++] = (float) values[2];
        edgeArrays.add(array);
      } else {
        if (!BRep_Tool.degenerated(e)) {
          // So, there is no curve, and the edge is not degenerated?
          // => draw lines between the vertices and ignore curvature
          // best approximation we can do
          ArrayList<double[]> aa = new ArrayList<double[]>(); // store points here
          for (TopExp_Explorer explorer2 = new TopExp_Explorer(s, TopAbs_ShapeEnum.VERTEX);
              explorer2.more();
              explorer2.next()) {
            TopoDS_Shape sv = explorer2.current();
            if (!(sv instanceof TopoDS_Vertex)) continue; // should not happen!
            TopoDS_Vertex v = (TopoDS_Vertex) sv;
            aa.add(BRep_Tool.pnt(v));
          }
          array = new float[aa.size() * 3];
          for (int i = 0, j = 0; i < aa.size(); i++) {
            double[] f = aa.get(i);
            array[j++] = (float) f[0];
            array[j++] = (float) f[1];
            array[j++] = (float) f[2];
          }
          edgeArrays.add(array);
        }
      }
    }

    return edgeArrays;
  }