Hi, I figured I would post some source code that gives a feel for what i'm
working on:  it is working C++ code , but demonstrates a bit more of my
approach thusfar.

The code below loads a solid from a STEP file, prints out the boundaries of
the solid, and then sections the solid at a particular zlevel.
It uses built-in OCC libraries to dump the shapes at various stages so that
I can use the Draw harness that coes with OCC to visualize the results.

The source below should compile against OCC v 6.3.0

>>>BEGIN SOURCE
// testOCC_console.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include "stdio.h"
#include "STEPControl_Reader.hxx"
#include <iostream>
#include <fstream>
#include <map>
#include "TopoDS_Shape.hxx"
#include "TopAbs_ShapeEnum.hxx"
#include "TopTools.hxx"
#include "Standard_OStream.hxx"
#include "StlAPI.hxx"
#include "StlAPI_Reader.hxx"
#include "BRepTools.hxx"
#include "gp.hxx"
#include "gp_Pln.hxx"
#include "gp_Pnt.hxx"
#include "gp_Ax1.hxx"
#include "gp_Ax2.hxx"
#include "gp_Ax3.hxx"
#include "BRepAlgo_Section.hxx"
#include "BRepAlgoAPI_Section.hxx"
#include "BRepAlgo_Cut.hxx"
#include "BRepAlgoAPI_Cut.hxx"
#include "BRepBndLib.hxx"
#include "BRepBuilderAPI_MakeFace.hxx"
#include "Bnd_Box.hxx"
#include "ShapeAnalysis_FreeBounds.hxx"
#include "TopTools_ListOfShape.hxx"
#include "BRepPrimAPI_MakeHalfSpace.hxx"
#include "TopoDS.hxx"
#include "TopoDS_Face.hxx"
#include "BRepBuilderAPI_Copy.hxx"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    STEPControl_Reader r;
    StlAPI_Reader stlReader;

    BRepTools bTools;
    BRepBndLib bndLib;
    Bnd_Box boundaries;


    r.ReadFile("Test.STEP");
    int numItems= r.NbRootsForTransfer();
    int numTranslated = r.TransferRoots();

    //TopoDS_Shape stlShape;

    //stlReader.Read(stlShape ,"Test.stl");
    TopoDS_Shape sh = r.OneShape();
    BRepBuilderAPI_Copy copier;
    //find out the boundaries of the shapes
    bndLib.Add(sh,boundaries);

    double xmin,xmax,ymin,ymax,zmin,zmax;
    boundaries.Get(xmin,ymin,zmin,xmax,ymax,zmax);


    cout << "Woo! " << numTranslated << " Shapes Read." << endl;

    printf("Boundaries: min[ %0.3f,%0.3f,%0.3f ] max [ %0.3f,%0.3f,%0.3f
]",
        xmin,ymin,zmin,xmax,ymax,zmax);


    bTools.Write(sh,"Test.out");
    //bTools.Write(stlShape,"TestStl.out");

    //make a cutting plane
    gp_Pnt pnt (1,1,-12);
    gp_Pnt pnt2 (0,0,0);
    gp_Ax3 csys (pnt,gp().DZ() );
    gp_Pln cuttingPlane (csys );

    //make a halfspace from the plane

    BRepBuilderAPI_MakeFace bff(cuttingPlane );

    TopoDS_Face face = bff.Face();

    BRepPrimAPI_MakeHalfSpace hs (face,pnt2);
    hs.Build();

    //calling halfSpace.Shape() does not work!
    TopoDS_Shape halfSpace = hs.Solid();
    bTools.Write(face,"face.out");
    bTools.Write(sh,"original.out");
    bTools.Write(halfSpace,"halfspace.out");
    cout << "Made Cutting Face.";

    BRepAlgoAPI_Cut cut (sh,halfSpace);
    cout << "Cut Completed" << endl;
    cut.Build();
    TopoDS_Shape theCut = cut.Shape();
    //TopoDS_Shape section = cut.Shape();
    bTools.Write(theCut,"Section.out");

    cout << "Write Completed" << endl;
    //now try to join the sections into a wire

    return 0;

}
>>>>>>END SOURCE

On Fri, Oct 10, 2008 at 1:13 PM, Cowdens <[EMAIL PROTECTED]> wrote:

> Hi, yes its more like a STL slicer. In practice, though, I'm part of a
> "splinter group" of repstrap folks, who are using conventional 3-axis mills
> and a RepRap extruder to make a rapid proto machine.
>
> In my case, I'm interested in creating G-code for the toolpaths, because I
> already have a 3-axis machine available that I'm converting to a "RepStrap"
> by adding an extruder in place of the spindle.
>
> I am happy to share my code-- I can believe anyone would do otherwise, whos
> using other people's OS code :)
>
> A RepStrap guy by the name of Enirque has built a python based slicer for
> STL, and my hope is to be able to integrate abililty to read step and STL
> by
> using pythonocc.  His tool is fantastic-- but, it is (a) a bit slow, and
> (b)
> cannot handle bad STL, (c) cannot handle STEP, so I'm hoping to fix that...
>
>
>
> -----Original Message-----
> From: Jelle Feringa [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 10, 2008 7:33 AM
> To: Cowdens
> Cc: minerva-pythonocc@gna.org
> Subject: Re: [Minerva-pythonocc] pythonOCC 0.96 and STEP import bug
>
> Dave,
>
> Let me thank you for sharing your code too, this is really a wonderful
> contribution to this list.
> I didnt get the notion of toolpath though, I thought you're builing
> something closer related to a Stereolithography model slicer, than NC /
> G-code generation for CNC milling?
>
> Btw., the RepRap project rules ;')
>
> -jelle
>
>
_______________________________________________
Minerva-pythonocc mailing list
Minerva-pythonocc@gna.org
https://mail.gna.org/listinfo/minerva-pythonocc

Reply via email to