OpenCASCADE Color Scale

OpenCASCADE Color Scale

eryar@163.com

Abstract. The color scale is a specialized label object that displays a color map and an accompanying numerical scale for color mapped or contour data plots. As the geometry modeling kernel of SALOME, OpenCASCADE provides the color scale function. The paper focus on the usage of color scale in OpenCASCADE.

Key Words. OpenCASCADE, Color Scale, 应力云图, 颜色映射表

1. Introduction

应力云图是一种应用广泛的标量场可视化方法,也经常用于表达矢量场或张量场的一个分量。云图在颜色与标量数据之间建立某种确定的映射关系,在计算机屏幕上绘制一个颜色离散变化的图像来显示科学计算结果。云图将标量场定义域内的数据值映射成不同的颜色,从而通过颜色变化来反映数据场中数据的变化规律。

很多数值分析软件后处理的结果都有绘制云图的功能。如下图所示为Abaqus软件产生的云图:

Figure 1.1 A Colored Stress Patterns by Abaqus

OpenCASCADE作为SALOME开源数值分析软件的几何造型内核,也提供了云图可视化的功能。本文主要介绍如何使用OpenCASCADE来显示模型的应力云图中的颜色映射表(Color Scale)。

2. Color Scale

云图绘制依赖于颜色集合与标量场数值集合之间的一一映射,即颜色映射表(Color Scale)。颜色映射表为区域填充时建立数值与颜色的映射关系。如下图所示:

Figure 2.1 Color Scale

作为分析对比参照标准,用户可以根据颜色线性表对应的数值范围,来判断某区域内数值分布规律。颜色线性表不仅应用于云图绘制,也应用于其他计算可视化算法中。

颜色线性表可以定义成不同的形式,多以对比鲜明的色彩作为线性表段颜色,在两个对比色之间采用过渡颜色。

在OpenCASCADE中颜色映射表的绘制是由Viewer来实现的。其Tcl命令为vcolorscale,如下所示:

Figure 2.2 Color Scale Tcl Command: vcolorscale

默认的颜色映射表的显示效果如下图所示:

Figure 2.3 Color Scale in Draw Test Harness

3. Tcl Test

OpenCASCADE基于Tcl/Tk的Draw Test Harness环境很方便测试一些想法。现在在Draw Test Harness中来显示一个完整的云图,如下图所示:

Figure 3.1 Color Scale in Draw Test Harness

实现上图的Tcl脚本代码如下所示:

#
#    Copyright (c) 2014 eryar All Rights Reserved.
#
#        File    : colorscale.tcl
#        Author  : eryar@163.com
#        Date    : 2014-09-20 18:10
#        Version : 1.0v
#
#    Description : Demonstrate the usage of OpenCASCADE color scale.
#
pload ALL

meshfromstl m data/stl/head.stl

meshcolors m nodaltex 0

# show the color sacle.
vcolorscale

vfit

首先加载所需要的所有模块,再从head.stl中加载网格模型;设置网格顶点颜色后就用vcolorscale命令打开发颜色映射表。

4.Code Analysis

根据Tcl命令找到对应的C++实现代码如下所示:

 

//=============================================================================
//function : VColorScale
//purpose  : representation color scale
//=============================================================================
#include <V3d_ColorScale.hxx>

static int VColorScale (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
{
  if ( argc != 1 && argc != 4 && argc != 5 && argc != 6 && argc != 8 )
  {
    di << "Usage : " << argv[0] << " [RangeMin = 0 RangeMax = 100 Intervals = 10 HeightFont = 16 Position = Right X = 0 Y = 0]  " << "\n";
    return 1;
  }

  Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
  if(aContext.IsNull()) {
    di << argv[0] << " ERROR : use 'vinit' command before " << "\n";
    return -1;
  }

  Standard_Real minRange = 0. , maxRange = 100. ;

  Standard_Integer numIntervals = 10 ;
  Standard_Integer textHeight = 16;
  Aspect_TypeOfColorScalePosition position = Aspect_TOCSP_RIGHT;
  Standard_Real X = 0., Y = 0. ;

  if ( argc < 9 )
  {
     if( argc > 3 )
     {
       minRange = Draw::Atof( argv[1] );
       maxRange = Draw::Atof( argv[2] );
       numIntervals = Draw::Atoi( argv[3] );
     }
     if ( argc > 4 )
       textHeight = Draw::Atoi( argv[4] );
     if ( argc > 5 )
       position = (Aspect_TypeOfColorScalePosition)Draw::Atoi( argv[5] );
     if ( argc > 7 )
     {
       X = Draw::Atof( argv[6] );
       Y = Draw::Atof( argv[7] );
     }
  }
  Handle(V3d_View) curView = ViewerTest::CurrentView( );
  if ( curView.IsNull( ) )
    return 1;
  Handle(Aspect_ColorScale) aCSV = curView->ColorScale( );
  Handle(V3d_ColorScale) aCS = ( Handle( V3d_ColorScale )::DownCast( aCSV ) );
  if( ! aCS.IsNull( ) )
  {
    aCS->SetPosition( X , Y );
    aCS->SetHeight( 0.95) ;
    aCS->SetTextHeight( textHeight );
    aCS->SetRange( minRange , maxRange );
    aCS->SetNumberOfIntervals( numIntervals );
    aCS->SetLabelPosition( position );
    if( !curView->ColorScaleIsDisplayed() )
      curView->ColorScaleDisplay( );
  }
  return 0;
}

由上述代码可知,颜色映射表主要是设置当前View中的Aspect_ColorScale。显示颜色映射表主要是由类V3d_ColorScale实现。取得当前视图的颜色表对象后,设置相关参数,即可调用视图的ColorScaleDisplay()来显示了。

根据上述Draw Test Harness中的实现代码,可以很容易地在自己的程序中实现相关的功能了。

5.Conclusion

OpenCASCADE的视图也提供了显示颜色映射表的功能,通过设置视图的V3d_ColorScale的相关参数,即可显示出颜色映射表了。

 

6. References

1. 王成恩. 面向科学计算的网格划分与可视化技术. 科学出版社. 2011

 

PDF Version and Tcl Script: OpenCASCADE Color Scale

时间: 2024-09-20 01:11:56

OpenCASCADE Color Scale的相关文章

OpenCASCADE Outline

OpenCASCADE Outline eryar@163.com      有网友反映blog中关于OpenCASCADE的文章比较杂乱,不太好找,最好能提供一个大纲,这样方便查找.于是决定将这些学习时写的文章整理下,方便对OpenCASCADE的学习理解.其实在http://www.cnblogs.com/opencascade中,已经将文章按目录重新发表了一遍.可以按OpenCASCADE的模块的顺序来学习,也可以挑选自己感兴趣的部分来学习.      由于本人水平所限,文中的错误不妥之处

2008年Logo设计10大趋势

Logo是品牌图形区别的点睛之处,我们每天都要接触很多logo - 在高速公路上,在购买商品时,以及浏览各种网站.我们查看很多logo设计,并且去学习和了解设计师们设计Logo的原则和技巧,从而发现和总结出将来的logo设计趋势.(该文摘自 logo orange! ) Logos are the ultimate mark of distinction and everyone loves them. We see logos everyday - on the highways, on co

CSS3与页面布局学习总结(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)

CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象的动态语言,有java的影子,有C的味道,中间有比其它语言多的糟粕,使用预处理办法可以解决这些问题.其中Less[les]与Sass是CSS的预处理技术,而CoffeeScript.TypeScript则是javascript的预处理技术.  一.Less 1.1.概要 Less是一种动态样式语言,

使用CSS3的scale实现网页整体缩放

 QQ邮箱的网页整体缩放效果,原来实现方法如此简单,下面有个实现示例,大家可以参考下 今天学习了一下QQ邮箱的网页整体缩放效果,原来实现方法很简单,代码如下:   代码如下: <!DOCTYPE html>  <html>  <head>  <meta charset="utf-8" />  <meta name="viewport" content="width=device-width, initi

使用CSS3的scale实现网页整体缩放_javascript技巧

今天学习了一下QQ邮箱的网页整体缩放效果,原来实现方法很简单,代码如下: 复制代码 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no

OpenCascade Chinese Text Rendering

OpenCascade Chinese Text Rendering eryar@163.com Abstract. OpenCascade uses advanced text rendering powered by FTGL library. The FreeType provides vector text rendering, as a result the text can be rotated and zoomed without quality loss. FreeType al

OpenCascade MeshVS Usage

OpenCascade MeshVS Usage eryar@163.com Abstract. MeshVS means Mesh Visualization Service. It can be used to representation mesh in different style, such as colored stress patterns mesh, mesh with text and mesh like vector(with arrow). So MeshVS usual

OpenCascade Shape Representation in OpenSceneGraph

OpenCascade Shape Representation in OpenSceneGraph eryar@163.com 摘要Abstract:本文通过程序实例,将OpenCascade中的拓朴数据(边.面)离散化后在OpenSceneGraph中进行显示.有了这些离散数据,就可以不用OpenCascade的显示模块了,可以使用其他显示引擎对形状进行显示.即若要线框模式显示形状时,就绘制离散形状拓朴边后得到的多段线:若要实体渲染模式显示形状时,就绘制离散形状拓朴面得到的三角网格.理解这些

重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等

原文:重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等 [源码下载] 重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 系统 UI 获取系统的 UI 相关的设置信息 屏幕方向 Snap 为