Beispiel #1
0
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;
}
TopoDS_Shape openSTEP(char const *filename)
{
    STEPControl_Reader reader;
    IFSelect_ReturnStatus status = reader.ReadFile(filename);

    assert(status == IFSelect_RetDone);

    reader.TransferRoots();

    return reader.OneShape();
}
Beispiel #3
0
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;
}
Beispiel #4
0
void CMainFrame::OnFileOpen()
{
	// TODO: 在此添加命令处理程序代码
	// TODO: 在此添加命令处理程序代码
	CFileDialog dialog(
		TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
		NULL,
		NULL,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		TEXT("STEP file(*.step;*.stp)|*.step;*.stp|All Files (*.*)|*.*||"),
		this);

	if (dialog.DoModal() == IDOK) {
		CString filePath = dialog.GetPathName();
		char file_str[1024] = {0};
		WideCharToMultiByte(CP_ACP, 0, filePath.GetString(), filePath.GetLength(), file_str, 1024, NULL, NULL);

		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
		SetStatus(_T("加载文件中..."));

		STEPControl_Reader reader;
		if (reader.ReadFile(file_str) != IFSelect_RetDone) {
			AfxMessageBox(_T("文件打开错误!"));
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
			ResetStatus();
			return;
		}
		SetStatus(_T("模型转换"));

		Handle(AIS_InteractiveContext) m_context = ((CMCApp*)AfxGetApp())->GetAISContext();

		Standard_Integer nbRoots = reader.NbRootsForTransfer();
		cout << "Number of roots in STEP file: " << nbRoots << endl;

		Standard_Integer NbTrans = reader.TransferRoots();
		// translates all transferable roots, and returns the number of
		//successful translations
		cout << "STEP roots transferred: " << NbTrans << endl;
		Standard_Integer NbShapes = reader.NbShapes();
		cout << "Number of resulting shapes is: " << NbShapes << endl;

		m_rootTopoShape = reader.Shape();// reader.OneShape();
		if (!m_rootTopoShape.IsNull()) {
			if (m_context->HasOpenedContext())
				m_context->CloseAllContexts();
			m_context->RemoveAll();
			TopAbs_ShapeEnum shapeType = m_rootTopoShape.ShapeType();
			if (shapeType == TopAbs_COMPOUND) {
				Quantity_NameOfColor colors[] = {
					Quantity_NOC_RED,
					Quantity_NOC_SKYBLUE,
					Quantity_NOC_SALMON,
					Quantity_NOC_GREEN,
					Quantity_NOC_ORANGE,
					Quantity_NOC_DEEPSKYBLUE1,
					Quantity_NOC_GOLD,
					Quantity_NOC_CYAN4,
					Quantity_NOC_DEEPPINK4,
					Quantity_NOC_INDIANRED,
					Quantity_NOC_BROWN
				};

				Standard_Integer i=0;
				for (TopExp_Explorer solidExp(m_rootTopoShape, TopAbs_SOLID); solidExp.More(); solidExp.Next(), ++i)
				{
					TopoDS_Shape solid = TopoDS::Solid(solidExp.Current());
					for (TopExp_Explorer faceExp(solid, TopAbs_FACE); faceExp.More(); faceExp.Next())
					{
						//Geom_BezierSurface 
						//Geom_Geometry *g;
						//g->GetType();
					}
					Handle(AIS_Shape) aisShape = new AIS_Shape(solid);
					m_context->SetDisplayMode(aisShape, 1, Standard_False);
					m_context->Display(aisShape, Standard_False);
					m_context->SetWidth(aisShape, 2, Standard_False);
					m_context->SetMaterial(aisShape, Graphic3d_NOM_PLASTIC, Standard_False);
					m_context->SetColor(aisShape, colors[i % (sizeof(colors) / sizeof(Quantity_NameOfColor))], Standard_False);
				}

			}
			else {
				m_rootAISShape = new AIS_Shape(m_rootTopoShape);
				//m_context->SetColor(m_rootAISShape, Quantity_NOC_SALMON);
				//m_context->SetMaterial(m_rootAISShape, Graphic3d_NOM_METALIZED);
				m_context->SetDisplayMode(m_rootAISShape, true);
				m_context->Display(m_rootAISShape);
				m_context->SetSelectionMode(m_rootAISShape, 4);
				m_context->SetHilightColor(Quantity_NOC_LIGHTBLUE);
			}
			
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
		}
		else {
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
			AfxMessageBox(_T("模型为空!"));
		}


		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
		ResetStatus();
		m_wndView.Reset();
	}
}
Beispiel #5
0
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");

}