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软件产生的云图: 

wps_clip_image-8337

Figure 1.1 A Colored Stress Patterns by Abaqus 

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

2. Color Scale

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

wps_clip_image-10285

Figure 2.1 Color Scale 

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

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

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

wps_clip_image-28256

Figure 2.2 Color Scale Tcl Command: vcolorscale 

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

wps_clip_image-22753

Figure 2.3 Color Scale in Draw Test Harness 

3. Tcl Test

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

wps_clip_image-9599

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

posted @ 2014-09-20 20:16  opencascade  阅读(2403)  评论(0编辑  收藏  举报