Hi Sebastien,

I made a gaussian curvature viewer quite some time ago.
Perhaps it offers a perspective to Graphic3d_* methods.

-jelle

from OCC.Viewer import wxViewer3d
import OCC as occ
import wx, random, sys
import occ_utils as utils


'''

TODO:

Use Graphic3d_ArrayOfPrimitives


'''



#===============================================================================
# MODULE GAUSSIAN
#===============================================================================


from debug import printf, timer

@timer
def curvatureBounds(uv_nodes, curvature):
    minGauss, maxGauss = 0., 0.
    
    for i in xrange(1, uv_nodes.Length()+1):
        u,v = uv_nodes(i).XY().Coord()
        curvature.SetParameters(u,v)
        g = curvature.GaussianCurvature()
        if g < minGauss: minGauss = g
        if g > maxGauss: maxGauss = g
    
    print 'Min Gauss, Max Gauss', minGauss, maxGauss
    return minGauss, maxGauss

@timer
def gaussian_colored_vertices(myGroup, face):
    '''computes an array of colored vertices from a set of nodes & uv_nodes
    
    myGroup is a occ.Graphic3d_Group object
    face can be anything occ.Brep_Tool can get a triangulation from
    
    '''
    T = occ.BRep_Tool().Triangulation(face, face.Location()).GetObject()

    printf(T.NbNodes)
    printf(T.NbTriangles)
    
    nodes, uv_nodes, triangles, normals = T.Nodes(), T.UVNodes(), T.Triangles(), T.Normals()
    
    printf(triangles.Length)
    
    
    # Set up the function for computing curvature
    h_srf = occ.BRep_Tool().Surface(face)
    uv_domain = occ.GeomLProp_SurfaceTool().Bounds(h_srf)
    curvature = occ.GeomLProp_SLProps(h_srf,
                                            uv_domain[0],
                                             uv_domain[2],
                                              1,
                                               0.0001
                                                 )
    
    maxVisualizedCurvature, minVisualizedCurvature = curvatureBounds(uv_nodes, curvature)
    
    
    # provisional color mapping
    colors = {
              # Red
              0:   occ.Quantity_Color(occ.Quantity_NOC_RED),
              1:   occ.Quantity_Color(occ.Quantity_NOC_RED1),
              2:   occ.Quantity_Color(occ.Quantity_NOC_RED2),
              3:   occ.Quantity_Color(occ.Quantity_NOC_RED3),
              4:   occ.Quantity_Color(occ.Quantity_NOC_RED4),
              # Green
              5:   occ.Quantity_Color(occ.Quantity_NOC_GREEN),
              6:   occ.Quantity_Color(occ.Quantity_NOC_GREEN1),
              7:   occ.Quantity_Color(occ.Quantity_NOC_GREEN2),
              8:   occ.Quantity_Color(occ.Quantity_NOC_GREEN3),
              9:   occ.Quantity_Color(occ.Quantity_NOC_GREEN4),
              # Blue
              10:   occ.Quantity_Color(occ.Quantity_NOC_BLUEVIOLET),
              11:   occ.Quantity_Color(occ.Quantity_NOC_BLUE1),
              12:   occ.Quantity_Color(occ.Quantity_NOC_BLUE2),
              13:   occ.Quantity_Color(occ.Quantity_NOC_BLUE3),
              14:   occ.Quantity_Color(occ.Quantity_NOC_BLUE4),
              #?
              15:   occ.Quantity_Color(occ.Quantity_NOC_BLUE4),
              } 
    
    nColors = len(colors.values())
    span = (maxVisualizedCurvature - minVisualizedCurvature) / nColors
    spanNumber = 0
    curvatureStrength=0.
    
    minGauss, maxGauss = 0.,0.
    
    # is the overhead in looking up the OCC methods, in this *huge* python file?
    
    #maxVertexs, maxEdges=0, hasVNormals=False, hasVColors=False,hasTexels=False, hasEdgeInfos=False)

    # Fans is ok...
    triArr = occ.Graphic3d_ArrayOfTriangleFans(triangles.Length()*3, 0, False, True)

#    _points = occ.Graphic3d_Array1OfVertexC(1,nodes.Length()*3)
#    _edges  =  occ.Aspect_Array1OfEdge(1,nodes.Length()*3)
    
#    triArr = occ.Graphic3d_ArrayOfTriangles(nodes.Length(), 0, False, True)
    
    print 'len triangles', triangles.Length()
    print 'len nodes*3', nodes.Length()*3
    
    nnn = 0
    for i in xrange(1, triangles.Length()+1):
        tri = triangles(i)
        
        for j in xrange(1,4):
            print 'global index', nnn
            vert_indx = tri(j)
            print 'vertex index', vert_indx
            
            u,v = uv_nodes(vert_indx).XY().Coord()
            curvature.SetParameters(round(u, 3), round(v, 3))
            _curvature = curvature.GaussianCurvature()
            
            if span !=0:
                spanNumber = 1 + ( _curvature - minVisualizedCurvature) / span
                #curvatureStrength = ( _curvature - minVisualizedCurvature - (spanNumber-1)*span) / span
            else:
                #curvatureStrength = 1.0
                spanNumber = 0
        
            if spanNumber > 0:
                idx = int(spanNumber-1)
                clr = colors[idx]
            else:
                clr = colors[0]
                
            triArr.AddVertex( nodes(vert_indx), clr)
            nnn+=1
   
    printf(triArr.HasVertexColors)
    print 'ArrayOfPoints is valid?', bool(triArr.IsValid())
   
    aspect = occ.Graphic3d_AspectFillArea3d()
    aspect.SetInteriorStyle(occ.Aspect_IS_SOLID)
    myGroup.Clear()
    myGroup.BeginPrimitives()
    
    myGroup.SetPrimitivesAspect(aspect.GetHandle())
    myGroup.AddPrimitiveArray(triArr.GetHandle())
    myGroup.EndPrimitives()
    print 'Done adding vertices'




#===============================================================================
# ACTUAL PROGRAM
#===============================================================================

sphere = utils.file_to_shape('c:\\Documents and Settings\\Administrator\\workspace\\foam_pavilion\\src\\test_srf_a.igs')
prs_sphere = occ.AIS_Shape(sphere)

# need to set the triangulation parameters before an object is presented

topoExplorer = occ.TopExp_Explorer()
topoExplorer.Init(sphere, occ.TopAbs_FACE)
#topoExplorer.Init(sphere.Shell(), occ.TopAbs_FACE)
tds = occ.TopoDS()
face = tds.Face(topoExplorer.Current())

# 370 seconds!!!
# 15463 triangles
occ.BRepMesh().Mesh(face, 200)

class AppFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "wxDisplay3d sample", style=wx.DEFAULT_FRAME_STYLE,size = (640,480))
        self.canva = wxViewer3d(self)
        #self.runTests()
    def runTests(self):
        self.canva._3dDisplay.Test()


app = wx.PySimpleApp()
wx.InitAllImageHandlers()
frame = AppFrame(None)
frame.Show(True)

display = frame.canva._3dDisplay
display.AISContext.SetIsoNumber(100)

view            = display.GetV3dView().GetObject()
viewer          = display.GetV3dViewer().GetObject()
d_ctx           = display.GetContext().GetObject()
prsMgr          = d_ctx.CollectorPrsMgr().GetObject()

d_ctx.Display(prs_sphere.GetHandle(), 1)
aPresentation   = prsMgr.CastPresentation(prs_sphere.GetHandle()).GetObject()
myGroup = occ.Prs3d_Root().CurrentGroup(aPresentation.Presentation()).GetObject()


T = occ.BRep_Tool().Triangulation(face, face.Location()).GetObject()


gaussian_colored_vertices(myGroup, face)


#===============================================================================
# PROFILING using hotshot
#===============================================================================

#import hotshot
#from hotshot import stats
#prof = hotshot.Profile("hotshot_gaussian_stats")
#prof.runcall(gaussian_colored_vertices, myGroup, nodes, uv_nodes, triangles, curvature, minGauss, maxGauss)
#prof.close()
#
#s = stats.load("hotshot_gaussian_stats")
#s.sort_stats("time").print_stats()

#===============================================================================
# PROFILING using cprofile
#===============================================================================

#import profile

#profile.run("gaussian_colored_vertices(myGroup, nodes, uv_nodes, triangles, curvature, minGauss, maxGauss)"
#, "gauss")
#
#import pstats
#p = pstats.Stats('gauss')
#p.strip_dirs()
#print '*'*24
#p.sort_stats('cum', 'time').print_stats()

#print '*'*24
#print 'callees'
#p.print_callees()
#print '*'*24
#print 'callers'
#p.print_callers()

app.SetTopWindow(frame)

print 'Start Main Loop...'

app.MainLoop()

On Mar 18, 2010, at 2:34 PM, Sébastien Ramage wrote:

Thank you, but since I want to use PythonOCC for other reason, I need to visualize the voxel with OCCT.

I hate failing so I continue my search and I found two things :
1- The Voxel documentation talk about "User draw", the user need to do the drawing by himself, and I found Graphic3d_Group.UserDraw but how it works ? What is Graphic3d_Group ?
2- To be display we need a AIS_InteractiveObject (just like AIS_Shape...) , Voxel_Prs is derivate from it, but maybe we can create our own AIS_InteractiveObject ?? (just like User_Cylinder in OCCT sample). I have try to create a python class derivate from AIS_InteractiveObject but python raise an error : No Constructor defined

any ideas ?



Le 18/03/2010 14:09, Dan Falck a écrit :
I know that this is a windows only project, but there might be some inspiration here:

http://code.google.com/p/voxelcut/

I've never used it, since I don't have windows here.

Dan

On 3/18/10 12:32 AM, Sébastien Ramage wrote:
Hi Thomas,

Voxel_VisDrawer.cxx and Voxel_VisDrawer.h are missing from OpenCascade, just because (in my opinion) they don't include them so Voxel visualization is not possible.
I've asked OpenCascade to send me the files and they answered that the files are available in the maintenance version 6.3.1 which is "delivered exclusively to our custom development, support or product clients, or via a separate yearly subscription."...
So I think there is no way to display voxel directly... we must do it by ourself, what a pity !

Below, the complete answer :

Dear Mr. Ramage,

Thank you for your request and your interest in Open CASCADE Technology software.
The files that you mention are available in Open CASCADE Technology maintenance version 6.3.1 as files VoxelClient_VisDrawer.cxx and VoxelClient_VisDrawer.h (they were renamed).

As you may learn from our web site at http://www.opencascade.org/support/alacarte/maintrel/, Open CASCADE Technology (OCCT) maintenance releases (such as 6.3.1) are delivered exclusively to our custom development, support or product clients, or via a separate yearly subscription. For your reference here below I list several commercial options to get access to OCCT maintenance releases :

a) Yearly subscription to maintenance releases

As I already mentioned above, the maintenance releases are also available to other parties which are not yet customers of OPEN CASCADE SA. Such availability becomes possible via yearly subscription to maintenance releases. This subscription grants you a right to receive (download) all sequential maintenance releases issued in the period of 1 year. The price of such subscription is 1,990 Euro.

b) Subscription to A la Carte support packages

As you may see from above we do not offer purchasing a single maintenance release but only a yearly pack. You may either choose this alternative or you may consider a possibility to purchase one of our A-la Carte support packages which grant you the same access and, in addition, allowing to use our various support services.

As you might already learn from our web site, for a wide range of companies, to cover all stages of software development process we offer support services including :

To take advantages of any and each of Open CASCADE support services, the best choice is to become a subscriber of one of our A la Carte support packages. In A la Carte package, you have a fixed number of "units" you can spend for any kind of support services according to the fixed rates detailed at A la Carte Support page. Three A la Carte options are at your disposal differing in the amount of available units :
  • Advantage = 42 units per quarter + 20 bonus units per year. This package costs 5,000 Euro per quarter.
  • Premium = 84 units per quarter + 44 bonus units per year. This package costs 10,000 Euro per quarter.
  • Excellence = 125 units per quarter + 72 bonus units per year. This package costs 15,000 Euro per quarter.
Please take a minute to study our A la Carte programs at http://www.opencascade.org/support/alacarte/.

c) Subscription to E-learning

The latest maintenance release of Open CASCADE Technology is available not only to our A la Carte clients but also to those customers who purchases our e-learning course (1,920 Euro).

Should you need any further information please do not hesitate to contact me at your earliest convenience.
Yours sincerely,
Sergey



Le 18/03/2010 00:07, Thomas Paviot a écrit :
Hi Sébastien,

Well, let's add these files to Display3d. But what should we put *inside* this files? Do you have any example of a voxel demo? I couldn't find one from the OCC forum.

Thomas 

_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users
_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users
_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to