Version: 6.3.1

Viewing 3D presentations

Examples of using 3D viewer functionaly from Python:

import os
from time import sleep

import salome

import VISU
from visu_gui import *

# Set the delay
delay = 4

# Set the directory containing MED files
datadir = os.getenv("DATA_DIR")

# Create a temporary 3D view
print "Create a temporary 3D view..."
myViewManager = myVisu.GetViewManager()
myTempView = myViewManager.Create3DView()
myTempView.SetTitle("The window will be soon destroyed!")
sleep(delay)

# Destroy the view
print "Destroy the view..."
myViewManager.Destroy(myTempView)
sleep(delay)

# Import a MED file 
medFile = os.path.join(datadir,"MedFiles","fra.med")
myResult = myVisu.ImportFile(medFile)

# Create a scalar map
meshName = 'LE VOLUME'
fieldEntity = VISU.NODE
fieldName = 'VITESSE'
timestampId = 1
myScalarMap = myVisu.ScalarMapOnField(myResult, meshName, fieldEntity, fieldName, timestampId)

# Create a new 3D view
print "Create a new 3D view..."
myView = myViewManager.Create3DView()

# Set the background
print "Set a blue background..."
bgColor = SALOMEDS.Color(0.0, 0.3, 1.0)
myView.SetBackground(bgColor)
myView.Update()
sleep(delay)

# Display the newly created scalar map
print "Display the scalar map..."
myView.Display(myScalarMap)
sleep(delay)

# Fit all
print "Fit all..."
myView.FitAll()
sleep(delay)

# Set the point of sight of the camera
print "Set the point of sight of the camera..."
myView.SetFocalPoint([1,5,10])
myView.Update()
sleep(delay)

# Fit all
print "Fit all..."
myView.FitAll()
sleep(delay)

# Change the scalar map range
print "Change the scalar map range..."
myScalarMap.SetRange(0.2, 0.9)
sleep(delay)

# Update the view
print "Update the view..."
myView.Update()
sleep(delay)

# Scale the view
print "Scale the view..."
myView.ScaleView(VISU.View3D.YAxis,10.0)
myView.ScaleView(VISU.View3D.XAxis,3.0)
myView.Update()
sleep(delay)

# Set the camera position in 3D space
print "Set the the camera position in 3D space..."
myView.SetPointOfView([0.01, 0.05, 0.03])
myView.Update()
sleep(delay)

# Fit all
print "Fit all..."
myView.FitAll()
sleep(delay)

# Store view parameters
stateName = "State1"
myView.SaveViewParams(stateName)

# Remove scale
print "Remove scale..."
myView.RemoveScale()
sleep(delay)

# Change the background
print "Set a dark background..."
bgColor = SALOMEDS.Color(0.0, 0.1, 0.2)
myView.SetBackground(bgColor)
sleep(delay)

# Update the view
print "Update the view..."
myView.Update()
sleep(delay)

# Set the top view
print "Set the top view..."
myView.SetView(VISU.View3D.TOP)
sleep(delay)

# Zooming out
print "Zooming out..."
aScale = myView.GetParallelScale()
for i in range(0,50) :
    aScale = aScale + 0.05
    myView.SetParallelScale(aScale)
    myView.Update()
    
sleep(delay)

# Zooming in
print "Zooming in..."
for i in range(0,75) :
    aScale = aScale - 0.05
    myView.SetParallelScale(aScale)
    myView.Update()
    
sleep(delay)

# Set the vertical line of the camera in 3D space
print "Set the vertical line of the camera in 3D space..."
aViewUp = myView.GetViewUp()
for i in range(0,40) :
    aViewUp[0] = aViewUp[0] + 0.1
    myView.SetViewUp(aViewUp) 
    myView.Update()

sleep(delay)

# Rotating Y
print "Rotating Y..."
aPoint = myView.GetPointOfView()
for i in range(0,150) :
    aPoint[1] = aPoint[1] + 1
    myView.SetPointOfView(aPoint) 
    myView.Update()

sleep(delay)

# Restore view parameters
print "Restore view parameters..."
myView.RestoreViewParams(stateName)
sleep(delay)

# Change presentation parameters:

# Make the scalar map shrinked
print "Make the scalar map shrinked..."
myView.SetShrinked(myScalarMap, True)
sleep(delay)

# Set the presentation type
print "Set the presentation type to SURFACEFRAME..."
myView.SetPresentationType(myScalarMap, VISU.SURFACEFRAME)
sleep(delay)

print "Set the presentation type to FEATURE_EDGES..."
myView.SetPresentationType(myScalarMap, VISU.FEATURE_EDGES)
sleep(delay)

# Update the object browser
salome.sg.updateObjBrowser(1)


Please, see View3D interface reference documentation for more details.

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS