コード例 #1
0
ファイル: steploader.cpp プロジェクト: dunkyp/CascadeViewer
TopoDS_Shape StepLoader::get_shape() {
  TopoDS_Shape shape;
  STEPControl_Reader reader;
  reader.ReadFile(filename.toLocal8Bit());
  reader.TransferRoots();
  shape = reader.OneShape();
  BRepTools::Clean(shape);
  return shape;
}
コード例 #2
0
TopoDS_Shape openSTEP(char const *filename)
{
    STEPControl_Reader reader;
    IFSelect_ReturnStatus status = reader.ReadFile(filename);

    assert(status == IFSelect_RetDone);

    reader.TransferRoots();

    return reader.OneShape();
}
コード例 #3
0
ファイル: main.cpp プロジェクト: chfritz/step2stl
int step2stl(char *in, char *out) {

  // Read from STEP
  STEPControl_Reader reader;
  IFSelect_ReturnStatus stat = reader.ReadFile(in);

  Standard_Integer NbRoots = reader.NbRootsForTransfer();
  Standard_Integer NbTrans = reader.TransferRoots();
  TopoDS_Shape Original_Solid = reader.OneShape();

  // Write to STL
  StlAPI_Writer stlWriter = StlAPI_Writer();
  // stlWriter.SetCoefficient(0.0001);
  stlWriter.ASCIIMode() = Standard_False;
  stlWriter.Write( Original_Solid, out);

  return 1;
}
コード例 #4
0
ファイル: Translator.cpp プロジェクト: guervillep/Kunie
bool Translator::importSTEP(const QString& file)
{
    STEPControl_Reader reader;
    IFSelect_ReturnStatus status = reader.ReadFile(file.toUtf8().data());

    if(status == IFSelect_RetDone) {
        reader.PrintCheckLoad(false, IFSelect_ItemsByEntity);

        int nbr = reader.NbRootsForTransfer();
        reader.PrintCheckTransfer(false, IFSelect_ItemsByEntity);

        for (Standard_Integer n = 1; n <= nbr; n++) {
            bool ok = reader.TransferRoot(n);
            int nbs = reader.NbShapes();

            if (!ok || nbs == 0)
                continue;

            else if (nbr == 1 && nbs == 1) {
                TopoDS_Shape shape = reader.OneShape();
                if (shape.ShapeType() == TopAbs_COMPOUND) {
                    for (TopoDS_Iterator It(shape); It.More(); It.Next())
                        m_doc->insert(It.Value(), QFileInfo(file).baseName());
                    break;
                }
            }
            for (Standard_Integer i = 1; i <= nbs; i++) {
                TopoDS_Shape shape = reader.Shape(i);
                if (!shape.IsNull())
                    m_doc->insert(shape, QFileInfo(file).baseName());
            }
        }
        return true;
    }

    return false;
}
コード例 #5
0
ファイル: occdaemon.cpp プロジェクト: snaske/BlenderOCC
void loadSTEP(char* filename)
{
    if(!filename) return;
    std::cout << "test" << std::endl;
    boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "OCCSharedMem");  
    TestFaces *m_trisp = segment.find<TestFaces>("m_tris").first;
    //TestFaces *m_facesp = segment.find<TestFaces>("m_faces").first;

    Vector3DfAllocator vector3df_alloc_inst(segment.get_segment_manager());
    TestFace *m_facep = segment.construct<TestFace>("m_facep")(vector3df_alloc_inst);

    std::cout << "connected to shared mem" << std::endl;
    std::cout << filename << std::endl;

    //STEPControl_Reader *readerp = new STEPControl_Reader;
    STEPControl_Reader reader;
    std::cout << filename << std::endl;
    reader.ReadFile(filename);
    Standard_Integer NbRoots = reader.NbRootsForTransfer();
    std::cout << "Number of Roots in the STEP File: " << NbRoots << std::endl;
    Standard_Integer NbTrans = reader.TransferRoots();
    std::cout << "STEP roots transferred: " << NbTrans << std::endl;
    std::cout << "Number of resulting shapes is: " << reader.NbShapes() << std::endl;
    TopoDS_Shape resulting_shape = reader.OneShape();
    // gp_Trsf theTrans;
    // gp_Axl Axis = gp_Axl(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.)); 
    // theTrans.SetRotation(Axis,30*PI/180); // Rotation of 30 degrees 
    // BRepBuilderAPI_Transform myBRepTransformation(resulting_shape,theTrans,true); 
    // TopoDS_Shape TransformedShape = myBRepTransformation.Shape();
    TopoDS_Iterator topo_iter;
    //m_topodsshapes.push_back(resulting_shape);
    // BRepMesh::Mesh(resulting_shape, 0.05);
    TopExp_Explorer faceExp(resulting_shape, TopAbs_FACE);

    for(; faceExp.More(); faceExp.Next())
    {


        //  TopExp_Explorer vertexExp(faceExp.Current(), TopAbs_VERTEX);
        //int f_n = 0;
        TopLoc_Location L = faceExp.Current().Location();
        BRepMesh::Mesh(faceExp.Current(), .1);
        Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(TopoDS::Face(faceExp.Current()),L);
        //  const Poly_Array1OfTriangle & triangles = facing->Triangles();
        //  const TColgp_Array1OfPnt & nodes = facing->Nodes();
        //  std::cout << "opencascaded: facing->NbTriangles() = " << facing->NbTriangles() << std::endl;
        if (!facing.IsNull())
        {
            TopExp_Explorer vertexExp(faceExp.Current(), TopAbs_VERTEX);
            //int f_n = 0;
            //TopLoc_Location L = faceExp.Current().Location();
            // BRepMesh::Mesh(faceExp.Current(), .1);
            // Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(TopoDS::Face(faceExp.Current()),L);
            const Poly_Array1OfTriangle & triangles = facing->Triangles();
            const TColgp_Array1OfPnt & nodes = facing->Nodes();
            std::cout << "opencascaded: facing->NbTriangles() = " << facing->NbTriangles() << std::endl;

            for ( int i=facing->NbTriangles(); i >= 1; --i )
            {
                m_facep->clear();
                Poly_Triangle triangle = triangles(i);

                Standard_Integer node1,node2,node3;
                triangle.Get(node1, node2, node3);

                gp_Pnt v1 = nodes(node1).Transformed(L);
                gp_Pnt v2 = nodes(node2).Transformed(L);
                gp_Pnt v3 = nodes(node3).Transformed(L);

                m_facep->push_back(Vector3Df(v1.X(), v1.Y(), v1.Z()));
                m_facep->push_back(Vector3Df(v2.X(), v2.Y(), v2.Z()));
                m_facep->push_back(Vector3Df(v3.X(), v3.Y(), v3.Z()));
                m_trisp->push_back(*m_facep);

            }
        }
        /*
           for(; vertexExp.More(); vertexExp.Next())
           {
           m_facep->clear();
           const TopoDS_Vertex& aVertex = TopoDS::Vertex(vertexExp.Current());
        //TopoDS_Edge edge = TopoDS::Edge(shape);
        TopLoc_Location location;
        Standard_Real pFirst, pLast;
        //Handle(Geom_Curve) curve = BRep_Tool::Curve(anEdge, location, pFirst, pLast);
        //std::cout << "pFirst = " << pFirst << std::endl;
        gp_Pnt p = BRep_Tool::Pnt(aVertex);
        std::cout << "Vector3Df(" << p.X() << ", " << p.Y() << ", " << p.Z() << std::endl;
        //points.push_back(Vector3Df(p.X()/1000.0, p.Y()/1000.0, p.Z()/1000.0));
        m_facep->push_back(Vector3Df(p.X()/1000.0, p.Y()/1000.0, p.Z()/1000.0));
        //      TopLoc_Location L;
        //        Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(aFace,L);
        //        if(!(facing.IsNull()))std::cout << "Number of Triangles in Face #" << f_n << ": " << facing->NbTriangles() << std::endl;
        //        f_n++;
        }
        m_facesp->push_back(*m_facep);
        */
    }
    //std::cout << " opencascaded: m_trisp->size()" << m_trisp->size() << std::endl;

    //  segment.destroy<TestFaces>("m_tris");

}