OpenVSP API Documentation 3.51.3
Loading...
Searching...
No Matches
Visualization Functions

The following group of functions allow for the OpenVSP GUI to be manipulated through the API. Click here to return to the main page. More...

Functions

void vsp::InitGUI ()
void vsp::StartGUI ()
void vsp::EnableStopGUIMenuItem ()
void vsp::DisableStopGUIMenuItem ()
void vsp::StopGUI ()
void vsp::PopupMsg (const std::string &msg)
void vsp::UpdateGUI ()
bool vsp::IsGUIBuild ()
void vsp::Lock ()
void vsp::Unlock ()
bool vsp::IsEventLoopRunning ()
void vsp::ScreenGrab (const std::string &fname, int w, int h, bool transparentBG, bool autocrop=false)
void vsp::SetViewAxis (bool vaxis)
void vsp::SetShowBorders (bool brdr)
void vsp::SetGeomDrawType (const std::string &geom_id, int type)
void vsp::SetGeomWireColor (const std::string &geom_id, int r, int g, int b)
void vsp::SetGeomDisplayType (const std::string &geom_id, int type)
int vsp::GetGeomDrawType (const std::string &geom_id)
int vsp::GetGeomDisplayType (const std::string &geom_id)
vec3d vsp::GetGeomWireColor (const std::string &geom_id)
std::string vsp::GetGeomMaterialName (const std::string &geom_id)
void vsp::AddMaterial (const std::string &name, const vec3d &ambient, const vec3d &diffuse, const vec3d &specular, const vec3d &emissive, const double &alpha, const double &shininess)
std::vector< std::string > vsp::GetMaterialNames ()
void vsp::SetBackground (double r, double g, double b)
void vsp::SetAllViews (int view)
void vsp::SetView (int viewport, int view)
void vsp::FitAllViews ()
void vsp::ResetViews ()
void vsp::SetWindowLayout (int r, int c)
void vsp::SetGUIElementDisable (int e, bool state)
void vsp::SetGUIScreenDisable (int s, bool state)
void vsp::SetGeomScreenDisable (int s, bool state)
void vsp::HideScreen (int s)
void vsp::ShowScreen (int s)

Detailed Description

Function Documentation

◆ AddMaterial()

void vsp::AddMaterial ( const std::string & name,
const vec3d & ambient,
const vec3d & diffuse,
const vec3d & specular,
const vec3d & emissive,
const double & alpha,
const double & shininess )
extern

Set the visualization material the specified geometry

string pid = AddGeom( "POD" );
AddMaterial( "RedGlass", vec3d( 44, 2, 2 ), vec3d( 156, 10, 10 ), vec3d( 185, 159, 159 ), vec3d( 44, 2, 2 ), 30, 0.4 );
SetGeomMaterialName( pid, "RedGlass" );
// The new material joins the library and can then be applied by name.
array< string > @mat_names = GetMaterialNames();
bool found = false;
for ( int i = 0; i < int( mat_names.size() ); i++ )
{
if ( mat_names[i] == "RedGlass" )
{
found = true;
}
}
if ( !found )
{
Print( "ERROR: AddMaterial did not add the material to the library" );
__failure++;
}
// Adding it again under the same name has to be rejected.
AddMaterial( "RedGlass", vec3d( 44, 2, 2 ), vec3d( 156, 10, 10 ), vec3d( 185, 159, 159 ), vec3d( 44, 2, 2 ), 30, 0.4 );
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: AddMaterial accepted a duplicate name" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
Definition Vec3d.h:243
std::string AddGeom(const std::string &type, const std::string &parent=std::string())
std::vector< std::string > GetMaterialNames()
void AddMaterial(const std::string &name, const vec3d &ambient, const vec3d &diffuse, const vec3d &specular, const vec3d &emissive, const double &alpha, const double &shininess)
Parameters
[in]namestring Material name
[in]ambientvec3d Ambient color RGB triple on scale [0, 255]
[in]diffusevec3d Diffuse color RGB triple on scale [0, 255]
[in]specularvec3d Specular color RGB triple on scale [0, 255]
[in]emissivevec3d Emissive color RGB triple on scale [0, 255]
[in]shininessdouble Shininess exponent on scale [0, 127]
[in]alphadouble Transparency factor on scale [0, 1]

◆ DisableStopGUIMenuItem()

void vsp::DisableStopGUIMenuItem ( )
extern

Disable Stop GUI Menu Item from the OpenVSP GUI.

This reverses the operation of EnableStopGUIMenuItem.

void StartGUI()
void DisableStopGUIMenuItem()
void EnableStopGUIMenuItem()
See also
EnableStopGUIMenuItem

◆ EnableStopGUIMenuItem()

void vsp::EnableStopGUIMenuItem ( )
extern

Enable Stop GUI Menu Item from the OpenVSP GUI.

Typically used for the blocking-mode OpenVSP GUI from the API.

This will add a "Stop GUI" option to the file pulldown menu and will also cause the exit button on the window frame to have the same effect. When selected, these options will stop the OpenVSP GUI event loop, returning control to the API program. OpenVSP will not terminate, the model will remain in memory and will be responsive to subsequent API calls.

See also
DisableStopGUIMenuItem

◆ FitAllViews()

void vsp::FitAllViews ( )
extern

Fit contents to all viewports

void FitAllViews()

◆ GetGeomDisplayType()

int vsp::GetGeomDisplayType ( const std::string & geom_id)
extern

Get the display type of the specified geometry

string pid = AddGeom( "POD" );
{
Print( "ERROR: GetGeomDisplayType did not report the type that was set" );
__failure++;
}
{
Print( "ERROR: GetGeomDisplayType did not follow a second set" );
__failure++;
}
@ DISPLAY_DEGEN_PLATE
Definition APIDefines.h:433
@ DISPLAY_BEZIER
Definition APIDefines.h:431
int GetGeomDisplayType(const std::string &geom_id)
void SetGeomDisplayType(const std::string &geom_id, int type)
See also
DISPLAY_TYPE, SetGeomDisplayType
Parameters
[in]geom_idstring Geom ID
Returns
int Display type enum (i.e. DISPLAY_BEZIER)

◆ GetGeomDrawType()

int vsp::GetGeomDrawType ( const std::string & geom_id)
extern

Set the visualization material the specified geometry

string pid = AddGeom( "POD" );
SetGeomMaterialName( pid, "Ruby" );
// Ruby is one of the materials the library ships with.
array< string > @mat_names = GetMaterialNames();
bool found = false;
for ( int i = 0; i < int( mat_names.size() ); i++ )
{
if ( mat_names[i] == "Ruby" )
{
found = true;
}
}
if ( !found )
{
Print( "ERROR: Ruby is not in the material library" );
__failure++;
}
// A material that is not in the library has to be rejected.
SetGeomMaterialName( pid, "NoSuchMaterial" );
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: SetGeomMaterialName accepted an unknown material" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
Parameters
[in]geom_idstring Geom ID
[in]namestring Material name

Get the draw type of the specified geometry

string pid = AddGeom( "POD", "" );
{
Print( "ERROR: GetGeomDrawType did not report the type that was set" );
__failure++;
}
{
Print( "ERROR: GetGeomDrawType did not follow a second set" );
__failure++;
}
@ GEOM_DRAW_WIRE
Definition APIDefines.h:441
@ GEOM_DRAW_SHADE
Definition APIDefines.h:443
int GetGeomDrawType(const std::string &geom_id)
void SetGeomDrawType(const std::string &geom_id, int type)
See also
DRAW_TYPE, SetGeomDrawType
Parameters
[in]geom_idstring Geom ID
Returns
int Draw type enum (i.e. GEOM_DRAW_SHADE)

◆ GetGeomMaterialName()

std::string vsp::GetGeomMaterialName ( const std::string & geom_id)
extern

Get the name of the visualization material applied to the specified geometry

string pid = AddGeom( "POD" );
SetGeomMaterialName( pid, "Ruby" );
if ( GetGeomMaterialName( pid ) != "Ruby" )
{
Print( "ERROR: GetGeomMaterialName did not report the material that was set" );
__failure++;
}
// The name that comes back has to be one the library knows.
array< string > @mat_names = GetMaterialNames();
bool found = false;
for ( int i = 0; i < int( mat_names.size() ); i++ )
{
if ( mat_names[i] == GetGeomMaterialName( pid ) )
{
found = true;
}
}
if ( !found )
{
Print( "ERROR: GetGeomMaterialName reported a material the library does not have" );
__failure++;
}
std::string GetGeomMaterialName(const std::string &geom_id)
See also
SetGeomMaterialName, GetMaterialNames
Parameters
[in]geom_idstring Geom ID
Returns
string Material name

◆ GetGeomWireColor()

vec3d vsp::GetGeomWireColor ( const std::string & geom_id)
extern

Get the wireframe color of the specified geometry. The color components are returned in the X, Y and Z members of the vector as red, green and blue over the range [0, 255].

string pid = AddGeom( "POD", "" );
SetGeomWireColor( pid, 0, 0, 255 );
vec3d color = GetGeomWireColor( pid );
if ( !closeTo( color.x(), 0, 1e-9 ) || !closeTo( color.y(), 0, 1e-9 ) || !closeTo( color.z(), 255, 1e-9 ) )
{
Print( "ERROR: GetGeomWireColor did not report the color that was set" );
__failure++;
}
// Each Geom carries its own color.
string p2id = AddGeom( "POD", "" );
SetGeomWireColor( p2id, 255, 0, 0 );
if ( !closeTo( GetGeomWireColor( pid ).z(), 255, 1e-9 ) )
{
Print( "ERROR: setting one Geom's color disturbed another" );
__failure++;
}
double y() const
Definition Vec3d.h:477
double x() const
Definition Vec3d.h:440
double z() const
Definition Vec3d.h:514
void SetGeomWireColor(const std::string &geom_id, int r, int g, int b)
vec3d GetGeomWireColor(const std::string &geom_id)
See also
SetGeomWireColor
Parameters
[in]geom_idstring Geom ID
Returns
vec3d Red, green and blue components of the wireframe color

◆ GetMaterialNames()

std::vector< std::string > vsp::GetMaterialNames ( )
extern

Get the names of all visualization materials

array< string > @mat_array = GetMaterialNames();
if ( mat_array.length() == 0 )
{
Print( "ERROR: GetMaterialNames returned nothing" );
__failure++;
}
for ( int i = 0; i < int( mat_array.size() ); i++ )
{
Print( mat_array[i] );
}
Returns
vector<string> Array of material names

◆ HideScreen()

void vsp::HideScreen ( int s)
extern

Hide an OpenVSP GUI screen

@ VSP_CFD_MESH_SCREEN
Definition APIDefines.h:987
void HideScreen(int s)
Parameters
[in]sint GUI_VSP_SCREEN enum for screen

◆ InitGUI()

void vsp::InitGUI ( )
extern

Low level routine that should be called to set up GUI before running StartGUI()

void InitGUI()

◆ IsEventLoopRunning()

bool vsp::IsEventLoopRunning ( )
extern

Test if the OpenVSP GUI event loop is running.

{
Print( "Event loop is running." );
}
bool IsEventLoopRunning()
Returns
bool True if the OpenVSP GUI event loop is running. False otherwise.

◆ IsGUIBuild()

bool vsp::IsGUIBuild ( )
extern

Test if the current OpenVSP build includes graphics capabilities.

if ( IsGUIBuild() )
{
Print( "OpenVSP build is graphics capable." );
}
else
{
Print( "OpenVSP build is not graphics capable." );
}
bool IsGUIBuild()
Returns
bool True if the current OpenVSP build includes graphics capabilities. False otherwise.

◆ Lock()

void vsp::Lock ( )
extern

Obtain the lock on the OpenVSP GUI event loop. This will prevent the interactive GUI from updating or accepting user input until the lock is released – thereby allowing longer-time commands including analyses to execute without the chance of the OpenVSP state changing during execution.

string pod_id = AddGeom( "POD" );
Lock();
string rid = ExecAnalysis( "CompGeom" );
array<string>@ mesh_id_vec = GetStringResults( rid, "Mesh_GeomID" );
DeleteGeomVec( mesh_id_vec );
std::string ExecAnalysis(const std::string &analysis)
void DeleteGeomVec(const std::vector< std::string > &del_vec)
const std::vector< std::string > & GetStringResults(const std::string &id, const std::string &name, int index=0)
void Lock()
void Unlock()
See also
Unlock

◆ PopupMsg()

void vsp::PopupMsg ( const std::string & msg)
extern

Cause OpenVSP to display a popup message.

PopupMsg( "This is a popup message." );
void PopupMsg(const std::string &msg)
Parameters
[in]msgstring Message to display.

◆ ResetViews()

void vsp::ResetViews ( )
extern

Reset views of all viewports

void ResetViews()

◆ ScreenGrab()

void vsp::ScreenGrab ( const std::string & fname,
int w,
int h,
bool transparentBG,
bool autocrop = false )
extern

Capture the specified screen and save to file. Note, VSP_USE_FLTK must be defined

int screenw = 2000; // Set screenshot width and height
int screenh = 2000;
string fname = "test_screen_grab.png";
ScreenGrab( fname, screenw, screenh, true, true ); // Take PNG screenshot
void ScreenGrab(const std::string &fname, int w, int h, bool transparentBG, bool autocrop=false)
Parameters
[in]fnamestring Output file name
[in]wint Width of screen grab
[in]hint Height of screen grab
[in]transparentBGbool Transparent background flag
[in]autocropbool Automatically crop transparent background flag

◆ SetAllViews()

void vsp::SetAllViews ( int view)
extern

Set the view of all viewports

@ CAM_CENTER
Definition APIDefines.h:195
void SetAllViews(int view)
Parameters
[in]viewint CAMERA_VIEW enum

◆ SetBackground()

void vsp::SetBackground ( double r,
double g,
double b )
extern

Set the background color

SetBackground( 1.0, 1.0, 1.0 ); // Set background to bright white
void SetBackground(double r, double g, double b)
Parameters
[in]rdouble Red 8-bit unsigned integer (range: 0-255)
[in]gdouble Green 8-bit unsigned integer (range: 0-255)
[in]bdouble Blue 8-bit unsigned integer (range: 0-255)

◆ SetGeomDisplayType()

void vsp::SetGeomDisplayType ( const std::string & geom_id,
int type )
extern

Set the display type of the specified geometry

string pid = AddGeom( "POD" ); // Add Pod for testing
SetGeomDisplayType( pid, DISPLAY_DEGEN_PLATE ); // Make pod appear as Bezier plate (Degen Geom)
// The display type is display state rather than model state, so there is
// nothing to read back. What has to hold is that a Geom which does not
// exist is rejected.
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: SetGeomDisplayType accepted a bad Geom ID" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
See also
DISPLAY_TYPE
Parameters
[in]geom_idstring Geom ID
[in]typeint Display type enum (i.e. DISPLAY_BEZIER)

◆ SetGeomDrawType()

void vsp::SetGeomDrawType ( const std::string & geom_id,
int type )
extern

Set the draw type of the specified geometry

string pid = AddGeom( "POD", "" ); // Add Pod for testing
SetGeomDrawType( pid, GEOM_DRAW_SHADE ); // Make pod appear as shaded
// The draw type is display state rather than model state, so there is
// nothing to read back. What has to hold is that a Geom which does not
// exist is rejected.
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: SetGeomDrawType accepted a bad Geom ID" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
See also
DRAW_TYPE
Parameters
[in]geom_idstring Geom ID
[in]typeint Draw type enum (i.e. GEOM_DRAW_SHADE)

◆ SetGeomScreenDisable()

void vsp::SetGeomScreenDisable ( int s,
bool state )
extern

Set whether geom screen is disabled

@ ALL_GEOM_SCREENS
Definition APIDefines.h:970
void SetGeomScreenDisable(int s, bool state)
Parameters
[in]sint GUI_GEOM_SCREEN enum for geom screen
[in]statebool True to disable geom screen

◆ SetGeomWireColor()

void vsp::SetGeomWireColor ( const std::string & geom_id,
int r,
int g,
int b )
extern

Set the wireframe color of the specified geometry

string pid = AddGeom( "POD", "" );
SetGeomWireColor( pid, 0, 0, 255 );
// The colour is display state rather than model state, so there is nothing
// to read back. What has to hold is that a Geom which does not exist is
// rejected.
SetGeomWireColor( "NOSUCHGEOM", 0, 0, 255 );
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: SetGeomWireColor accepted a bad Geom ID" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
Parameters
[in]geom_idstring Geom ID
[in]rint Red component of color [0, 255]
[in]gint Green component of color [0, 255]
[in]bint Blue component of color [0, 255]

◆ SetGUIElementDisable()

void vsp::SetGUIElementDisable ( int e,
bool state )
extern

Set whether all instances of GUI device type are disabled

@ GDEV_INPUT
Definition APIDefines.h:847
void SetGUIElementDisable(int e, bool state)
Parameters
[in]eint GDEV enum for GUI device type
[in]statebool True to disable GUI device type

◆ SetGUIScreenDisable()

void vsp::SetGUIScreenDisable ( int s,
bool state )
extern

Set whether screen is disabled

void SetGUIScreenDisable(int s, bool state)
Parameters
[in]sint GUI_VSP_SCREEN enum for screen
[in]statebool True to disable screen

◆ SetShowBorders()

void vsp::SetShowBorders ( bool brdr)
extern

Toggle viewing the border frame

SetShowBorders( false ); // Turn off red/black border on active window
void SetShowBorders(bool brdr)
Parameters
[in]brdrbool True to show the border frame, false to hide the border frame

◆ SetView()

void vsp::SetView ( int viewport,
int view )
extern

Set the view of a particular viewports

void SetView(int viewport, int view)
Parameters
[in]viewportint Viewport to set view
[in]viewint CAMERA_VIEW enum

◆ SetViewAxis()

void vsp::SetViewAxis ( bool vaxis)
extern

Toggle viewing the axis

SetViewAxis( false ); // Turn off axis marker in corner of viewscreen
void SetViewAxis(bool vaxis)
Parameters
[in]vaxisbool True to show the axis, false to hide the axis

◆ SetWindowLayout()

void vsp::SetWindowLayout ( int r,
int c )
extern

Set the rows and columns of the window layout

void SetWindowLayout(int r, int c)
Parameters
[in]rint Number of viewport rows
[in]cint Number of viewport columns

◆ ShowScreen()

void vsp::ShowScreen ( int s)
extern

Show an OpenVSP GUI screen

Parameters
[in]sint GUI_VSP_SCREEN enum for screen

◆ StartGUI()

void vsp::StartGUI ( )
extern

Launch the interactive OpenVSP GUI. In a multi-threaded environment, this must be called from the main thread only. This starts the GUI event loop. It will also show the main screen and screens displayed when StopGUI() was previously called.

◆ StopGUI()

void vsp::StopGUI ( )
extern

Stop OpenVSP GUI event loop and hide screens. Keep OpenVSP running and in memory.

void StopGUI()
See also
StartGUI

◆ Unlock()

void vsp::Unlock ( )
extern

Release the lock on the OpenVSP GUI event loop.

string pod_id = AddGeom( "POD" );
Lock();
string rid = ExecAnalysis( "CompGeom" );
array<string>@ mesh_id_vec = GetStringResults( rid, "Mesh_GeomID" );
DeleteGeomVec( mesh_id_vec );
See also
Lock

◆ UpdateGUI()

void vsp::UpdateGUI ( )
extern

Tell OpenVSP that the GUI needs to be updated.

string pod_id = AddGeom( "POD" );
string length = FindParm( pod_id, "Length", "Design" );
SetParmVal( length, 13.0 );
std::string FindParm(const std::string &parm_container_id, const std::string &parm_name, const std::string &group_name)
double SetParmVal(const std::string &parm_id, double val)
void UpdateGUI()
See also
StartGUI