iCAx开思工具箱

标题: 再问曲面面积:现在有了函数,可为什么得不到我要的结果呢? [打印本页]

作者: suiyubing    时间: 2005-6-2 11:12
标题: 再问曲面面积:现在有了函数,可为什么得不到我要的结果呢?
以前连求曲面面积的函数都不知道,现在知道了,是UF_MODL_ask_mass_props_3d,看了那个例子后可以求一个实体的面积了,但是我想求曲面得面积,可怎么也做不到,问题到底出在哪里呢?请求高手指教,下面是我在例子的基础上写的程序,只做了一点点改动,但是结果却出现巨大差异。
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
{int irc = 0;
char *message = "Select Object";
UF_UI_selection_options_t opts;
UF_UI_mask_t mask;
int response;
  
tag_t *object;
  
int unhighlight=0;
char buffer[133];
char error[133];
    /* Initialize the API environment */
    int errorCode = UF_initialize();
  
    if ( 0 == errorCode )
    {
        /* TODO: Add your application code here */
opts.other_options = 0;
opts.reserved = NULL;
opts.num_mask_triples = 1;
opts.mask_triples = [$mask]
/* set up selectable type, subtype, solid type */
opts.mask_triples->object_type = UF_solid_type;
opts.mask_triples->object_subtype = UF_solid_face_subtype;
opts.mask_triples->solid_type = UF_UI_SEL_FEATURE_ANY_FACE;
/* set selection scope to be work part */
opts.scope = UF_UI_SEL_SCOPE_WORK_PART;
  
  int type = 2;
  int  unit = 3;
  int accuracy =  1;
  int  count = 0;
  
  int  i;
  double  acc_val[11] = {1,0,0,0,0,0,0,0,0,0,0};
  double  density = 1.0;
  double  massprop[47];
  double  massprop_stat[13];
  
irc = UF_UI_select_by_class(message,&opts,&response,
                                    [$count,&object)]
  
/* if no error, print information about selected object */
if (!irc)
{UF_UI_open_listing_window();
sprintf(buffer,"response= %d, object tag= %d", response, object);
  UF_UI_write_listing_window(buffer);
UF_MODL_ask_mass_props_3d(object,
                                       count,
                                       type,
                                       unit,
                                       density,
                                       accuracy,
                                       acc_val,
                                       massprop,
                                       massprop_stat);
  
for (i=0; i<47; i++)
     {
       sprintf(buffer,"[%d] = %f\n",i,massprop);
     UF_UI_write_listing_window(buffer);
}
    
for(i=0;i<count;i++)
  /* unhighlight selected object */
{UF_DISP_set_highlight(object,unhighlight);  
}
UF_free(object);
}
else  /* else get error message */
{
  UF_get_fail_message(irc,error);
  sprintf(buffer,"ERROR: %s\n",error);
UF_UI_write_listing_window(buffer);
}
  
        /* Terminate the API environment */
        errorCode = UF_terminate();
    }
但是如果把opts.mask_triples->object_type = UF_solid_type;
opts.mask_triples->object_subtype = UF_solid_face_subtype;
opts.mask_triples->solid_type = UF_UI_SEL_FEATURE_ANY_FACE;进行一下变动就可以求实体的面积了
opts.mask_triples->object_type = UF_solid_type;
opts.mask_triples->object_subtype = 0;
opts.mask_triples->solid_type = UF_UI_SEL_FEATURE_BODY;
比较罗索,但是还是邀请高手们帮忙看一下,自己实在不知道怎么去改才可以。我的目的只想求某一个曲面得面积,而非实体的。先谢谢了!
作者: thriller    时间: 2005-6-2 15:26
还是贴完整的代码吧
作者: suiyubing    时间: 2005-6-2 17:54
好吧,
#include <uf.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <stdio.h>
#include <uf_disp.h>
#include <uf_defs.h>
#include <uf_modl.h>
#include <uf_object_types.h>
#include <uf_modl_types.h>
#include <uf_obj.h>
#include <string.h>
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
#  include <strstream>
#   include <iostream>
  using std:strstream;
  using std::endl;  
  using std::ends;
  using std::cerr;
#else
#  include <strstream.h>
#   include <iostream.h>
#endif
#include "535.h"
  
//----------------------------------------------------------------------------
//  Activation Methods
//----------------------------------------------------------------------------
  
//  Explicit Activation
//      This entry point is used to activate the application explicitly, as in
//      "File->Execute UG/Open->User Function..."
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
{int irc = 0;
char *message = "Select Object";
UF_UI_selection_options_t opts;
UF_UI_mask_t mask;
int response;
  
tag_t *object;
  
int unhighlight=0;
char buffer[133];
char error[133];
    /* Initialize the API environment */
    int errorCode = UF_initialize();
  
    if ( 0 == errorCode )
    {
        /* TODO: Add your application code here */
opts.other_options = 0;
opts.reserved = NULL;
opts.num_mask_triples = 1;
opts.mask_triples = [$mask]
/* set up selectable type, subtype, solid type */
opts.mask_triples->object_type = UF_solid_type;
opts.mask_triples->object_subtype = UF_solid_face_subtype;
opts.mask_triples->solid_type = UF_UI_SEL_FEATURE_ANY_FACE;
/* set selection scope to be work part */
opts.scope = UF_UI_SEL_SCOPE_WORK_PART;
  
  int type = 2;
  int  unit = 3;
  int accuracy =  1;
  int  count = 0;
  
  int  i;
  double  acc_val[11] = {1,0,0,0,0,0,0,0,0,0,0};
  double  density = 1.0;
  double  massprop[47];
  double  massprop_stat[13];
  
irc = UF_UI_select_by_class(message,&opts,&response,
                                    [$count,&object)]
  
/* if no error, print information about selected object */
if (!irc)
{UF_UI_open_listing_window();
sprintf(buffer,"response= %d, object tag= %d", response, object);
  UF_UI_write_listing_window(buffer);
UF_MODL_ask_mass_props_3d(object,
                                       count,
                                       type,
                                       unit,
                                       density,
                                       accuracy,
                                       acc_val,
                                       massprop,
                                       massprop_stat);
  
for (i=0; i<47; i++)
     {
       sprintf(buffer,"[%d] = %f\n",i,massprop);
     UF_UI_write_listing_window(buffer);
}
    
for(i=0;i<count;i++)
  /* unhighlight selected object */
{UF_DISP_set_highlight(object,unhighlight);  
}
UF_free(object);
}
else  /* else get error message */
{
  UF_get_fail_message(irc,error);
  sprintf(buffer,"ERROR: %s\n",error);
UF_UI_write_listing_window(buffer);
}
  
        /* Terminate the API environment */
        errorCode = UF_terminate();
    }
  
    /* Print out any error messages */
   &nbsprintErrorMessage( errorCode );
}
  
//----------------------------------------------------------------------------
//  Utilities
//----------------------------------------------------------------------------
  
// Unload Handler
//     This function specifies when to unload your application from Unigraphics.
//     If your application registers a callback (from a MenuScript item or a
//     User Defined Object for example), this function MUST return
//     "UF_UNLOAD_UG_TERMINATE".
extern "C" int ufusr_ask_unload( void )
{
    return( UF_UNLOAD_UG_TERMINATE );
}
  
/* PrintErrorMessage
**
**     Prints error messages to standard error and the Unigraphics status
**     line. */
static void PrintErrorMessage( int errorCode )
{
    if ( 0 != errorCode )
    {
        /* Retrieve the associated error message */
        char message[133];
        UF_get_fail_message( errorCode, message );
  
        /* Print out the message */
        UF_UI_set_status( message );
  
        // Construct a buffer to hold the text.
        ostrstream error_message;
  
        // Initialize the buffer with the required text.
        error_message << endl
                      << "Error:" << endl
                      << message
                      << endl << endl << ends;
  
      // Write the message to standard error
        cerr << error_message.str();
    }
}
作者: suiyubing    时间: 2005-6-4 08:45
为什么没有人回应呢,这个代码看上去挺多的,其实也没有几句阿,肯请大家帮忙看一下呀,谢谢了
作者: 深夜摔键盘    时间: 2005-6-4 09:49
你的选择器用的不对啊。
  
你要选的应该是一个sheet body,而不是依附在实体上的face。
使用UF_UI_select_with_class_dialog,用系统默认的选择配置就可以。
作者: suiyubing    时间: 2005-6-4 20:11
真的不知道该怎么样感谢您,这个问题困了我将近一个月,现在终于有眉目了,谢谢。因为我要用到这个面积来计算我的曲面得展开精度,否则我的展开就会变得没有多少意义的。兴奋之余还要问一个问题:我的曲面模型是由两个曲面缝合在一起的,在求取曲面面积时我如果利用的是那个缝合以后的模型的话,用这个选择器就无法选中单独的某一个曲面,我在想可不可以利用选择器的细分功能对缝合后曲面模型的某一个面进行选取呢?这个地方真得很糊涂,还请高手指教。
作者: 深夜摔键盘    时间: 2005-6-5 17:08
缝合的曲面,是可以ask到其中的片体的,得到了片体的tag,就好办了。剩下的事情就是瞒天过海,不让sew的对象高亮,自己设置片体高亮试试
作者: jjf1120    时间: 2005-6-22 18:40
请问求曲面的面积,除了改UF_MODL_ask_mass_props_3d中的type值以外,还要改什么值,谢谢
作者: suiyubing    时间: 2005-6-22 21:54
那个函数的说明中说得听清楚的呀,你看一下帮助就知道怎么改了,因为看你怎么设置里面的值,所以还是你看一下
extern int UF_MODL_ask_mass_props_3d (
tag_t * objects,  
int num_objs,  
int type,  
int units,  
double density,  
int accuracy,  
double acc_value[ 11 ],  
double mass_props[ 47 ],  
double statistics[ 13 ] );
  
tag_t *  objects Input Array of solid or sheet body identifiers,
Solid bodies for analysis type 1,
Sheet bodies for analysis types 2 and 3  
int  num_objs Input Number of objects  
int  type Input Type of 3D Analysis
1 = Solid Bodies
2 = Thin Shell - Sheet Bodies
3 = Bounded by Sheet Bodies  
int  units Input Units of mass and length
1 = Pounds and inches
2 = Pounds and feet
3 = Grams and centimeters
4 = Kilograms and meters  
double  density Input Density - Mass per unit volume (Mass per unit area for thin
shell). Not used for solid body analysis; for solid bodies
the densities of the solid bodies are used in the analysis
and the density of the combined set of bodies is output
in the mass properties array (mass_props[46]).  
int  accuracy Input 1 = Use Accuracy
2 = Use Relative Tolerances  
double  acc_value[ 11 ] Input [0] = Accuracy value between 0.0 and 1.0
if accuracy = 1
[1-10] not used if accuracy = 1
[0] = Relative Tolerance for Area if accuracy = 2
[1] = Relative Tolerance for Volume
[2-4] = Relative Tolerances for First Moments (centroidal)
[5-7] = Relative Tolerances for Moments of Inertia
(centroidal)
[8-10]= Relative Tolerances for Products of Inertia
(centroidal)  
double  mass_props[ 47 ] Output Mass properties
[0] = Surface Area
[1] = Volume (0.0 For Thin Shell)
[2] = Mass
[3-5] = Center Of Mass (COFM), WCS
[6-8] = First Moments (centroidal)
[9-11] = Moments Of Inertia, WCS
[12-14] = Moments Of Inertia (centroidal)
[15] = Spherical Moment Of Inertia
[16-18] = Inertia Products, WCS
[19-21] = Inertia Products (centroidal)
[22-30] = Principal Axes, WCS
[31-33] = Principal Moments (centroidal)
[34-36] = Radii Of Gyration, WCS
[37-39] = Radii Of Gyration (centroidal)
[40] = Spherical Radius Of Gyration
[41-45] = Unused
[46] = Density  
double  statistics[ 13 ] Output Errors are Estimates of the Relative Tolerances
achieved if accuracy = 2; otherwise
+/- range errors are given
[0] = Error For Surface Area
[1] = Error For Volume
[2] = Error For Mass
[3] = Radius Of Error Sphere
[4] = Error For Moment XC
[5] = Error For Moment YC
[6] = Error For Moment ZC
[7] = Error For Moment Of Inertia XC
[8] = Error For Moment Of Inertia YC
[9] = Error For Moment Of Inertia ZC
[10] = Error For Product Of Inertia XCYC
[11] = Error For Product Of Inertia YCZC
[12] = Error For Product Of Inertia XCZC
作者: jjf1120    时间: 2005-6-23 16:45
我要求的是实体上任一个面的面积,不求它的表面积,我用ug自带的例子只能求出实体的表面积,修改代码以后,报错说是没有这种type类型,请问这个函数可以求实体上任一面的面积吗?可以求一个封闭曲线构成的区域的面积吗?我已经试了一天了,修改了选择器,也修改过了type值,就是求不出结果,能不能给我一个参考的例子,谢谢,我的邮箱是:jjf1120@163.com




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3