我能否以类似于此C+的方式实例化C#类a+;例子? 我已经把下面的C++代码翻译成C,但是我不能确定在哪里和如何实例化类。如果我使用: customAnalysis test = new customAnalysis();

我能否以类似于此C+的方式实例化C#类a+;例子? 我已经把下面的C++代码翻译成C,但是我不能确定在哪里和如何实例化类。如果我使用: customAnalysis test = new customAnalysis();,c#,c++,porting,rhino3d,C#,C++,Porting,Rhino3d,它收到一条错误消息,告诉我该类是由Rhino3D实例化的,因此我不应该实例化它。但是我需要创建一个类的引用,这样我就可以得到它的静态成员m_am_id,它是由基类创建的 这是我遇到的问题: static class CZAnalysisVAM theZAnalysisVAM; 提前谢谢 C++代码: ////////////////////////////////////////////////////////////////// // // BEGIN Z analysis mode cla

它收到一条错误消息,告诉我该类是由Rhino3D实例化的,因此我不应该实例化它。但是我需要创建一个类的引用,这样我就可以得到它的静态成员
m_am_id
,它是由基类创建的

这是我遇到的问题:

static class CZAnalysisVAM theZAnalysisVAM;
提前谢谢

C++代码:

//////////////////////////////////////////////////////////////////
//
// BEGIN Z analysis mode class
// 

// This is an example that demonstrates how to add a false color
// analysis mode to Rhino.  This example uses false color to indicate
// the world "z" coordinate.

// {DF4688C-9671-4389-AC41-515B8693A783}
static const GUID FALSE_COLOR_EXAMPLE_ANALYSIS_MODE_ID =
{ 0xDF4688C, 0x9671, 0x4389, { 0xAC, 0x41, 0x51, 0x5B, 0x86, 0x93, 0xA7, 0x83 } };

class CZAnalysisVAM : public CRhinoVisualAnalysisMode
{
public:
  CZAnalysisVAM();
  ~CZAnalysisVAM();

  // virtual CRhinoVisualAnalysisMode override
  void GetAnalysisModeName( ON_wString& name ) const;

  // virtual CRhinoVisualAnalysisMode override
  bool ObjectSupportsAnalysisMode( const CRhinoObject* object ) const;

  // virtual CRhinoVisualAnalysisMode override
  void UpdateVertexColors( 
            const CRhinoObject* object, 
            ON_SimpleArray<const ON_Mesh *>& meshes 
            ) const;

  // virtual CRhinoVisualAnalysisMode override
  bool ShowIsoCurves() const;

  // virtual CRhinoVisualAnalysisMode override
  void DrawMeshObject( 
          const CRhinoMeshObject& mesh_object,
          CRhinoDisplayPipeline& dp
          );

  // virtual CRhinoVisualAnalysisMode override
  void DrawBrepObject( 
          const CRhinoBrepObject& brep_object,
          CRhinoDisplayPipeline& dp
          );

  bool m_bShowIsoCurves;

  // This simple example provides a false color based on the
  // world z coordinate.   For details, see the implementation
  // of the FalseColor function.
  ON_Interval m_z_range;  
  ON_Interval m_hue_range;

  ON_Color FalseColor(double z) const;

  // Returns a mapping tag that is used to detect when
  // a meshes colors need to be set.  For details, see the
  // implementation  of MappingTag and UpdateVertexColors.
  ON_MappingTag MappingTag() const;
};


// the one and only instance of a CZAnalysisVAM object.
// The CRhinoVisualAnalysisMode constructor registers the mode
// with Rhino.  This class must not be destroyed while Rhino
// is active.
static class CZAnalysisVAM theZAnalysisVAM;

CZAnalysisVAM::CZAnalysisVAM() 
: CRhinoVisualAnalysisMode( FALSE_COLOR_EXAMPLE_ANALYSIS_MODE_ID,
                            CRhinoVisualAnalysisMode::false_color_style
                            )
{
  m_bShowIsoCurves = true;

  // In a real plug-in, user interface would allow
  // the user to change these intervals.

  m_z_range.Set(-10.0,10.0);
  m_hue_range.Set(0.0,4.0*ON_PI/3.0); // red to green to blue
}

CZAnalysisVAM::~CZAnalysisVAM()
{
}

void CZAnalysisVAM::GetAnalysisModeName( ON_wString& name ) const
{
  // This name shows up in the object properties details
  // report when the object is in the analysis mode.
  name = L"Z analysis";
}

bool CZAnalysisVAM::ObjectSupportsAnalysisMode( const CRhinoObject* object ) const
{
  // This function should return true if the analysis mode works
  // on the object.  This example works on meshes and breps, so
  // its version of ObjectSupportsAnalysisMode looks like this.

  bool rc = false;
  if ( object )
  {
    switch(object->ObjectType())
    {
    case ON::mesh_object:
      if ( CRhinoMeshObject::Cast(object) )
        rc = true;
      break;

    case ON::surface_object:
    case ON::polysrf_filter:
    case ON::brep_object:
      if ( CRhinoBrepObject::Cast(object) )
        rc = true;
      break;
    }
  }
  return rc;
}

ON_MappingTag CZAnalysisVAM::MappingTag() const
{
  ON_MappingTag mt;

  // Since the false colors that are shown will change if
  // the mesh is transformed, we have to initialize the
  // transformation.
  mt.m_mesh_xform.Identity();

  // This is the analysis mode id passed to the 
  // CRhinoVisualAnalysisMode constructor. Use the
  // m_am_id member and it this code will alwasy 
  // work correctly.
  mt.m_mapping_id = m_am_id;

  // This is a 32 bit CRC or the information used to
  // set the false colors.
  // For this example, the m_z_range and m_hue_range
  // intervals controlthe colors, so we calculate 
  // their crc.
  mt.m_mapping_crc = 0;
  mt.m_mapping_crc = ON_CRC32(mt.m_mapping_crc,sizeof(m_z_range),&m_z_range);
  mt.m_mapping_crc = ON_CRC32(mt.m_mapping_crc,sizeof(m_hue_range),&m_hue_range);

  return mt;
}

ON_Color CZAnalysisVAM::FalseColor(double z) const
{
  // Simple example of one way to change a number 
  // into a color.
  double s = m_z_range.NormalizedParameterAt(z);
  if ( s < 0.0 ) s = 0.0; else if (s > 1.0) s = 1.0;
  double hue = m_hue_range.ParameterAt(s);
  ON_Color c;
  c.SetHSV( hue, 1.0, 1.0 );
  return c;
}

void CZAnalysisVAM::UpdateVertexColors( 
            const CRhinoObject* object, 
            ON_SimpleArray<const ON_Mesh *>& meshes 
            ) const
{
  // Rhino calls this function when it is time for you
  // to set the false colors on the analysis mesh vertices.
  // For breps, there is one mesh per face.  For mesh objects,
  // there is a single mesh.
  const int count = meshes.Count();
  if (count > 0 )
  {
    // A "mapping tag" is used to determine if the colors
    // need to be set.
    ON_MappingTag mt = MappingTag();

    const ON_Mesh * const * mesh_list = meshes.Array();
    for ( int mi = 0; mi < count; mi++ )
    {
      const ON_Mesh* mesh = mesh_list[mi];
      if ( mesh && mt.Compare(mesh->m_Ctag) )
      {
        // The mesh's mapping tag is different from ours. Either
        // the mesh has no false colors, has false colors set by
        // another analysis mode, has false colors set using
        // different m_z_range[]/m_hue_range[] values, or the
        // mesh has been moved.  In any case, we need to set
        // the false colors to the ones we want.

        const int vcount = mesh->m_V.Count();
        ON_SimpleArray<ON_Color>& vertex_colors = const_cast<ON_Mesh*>(mesh)->m_C;
        vertex_colors.SetCount(0);     // in case something else had set the colors
        vertex_colors.Reserve(vcount); // for efficiency
        for (int vi = 0; vi < vcount; vi++ )
        {
          double z = mesh->m_V[vi].z;
          ON_Color c = FalseColor(z);
          vertex_colors.Append(c);
        }

        // set the mesh's color tag 
        const_cast<ON_Mesh*>(mesh)->m_Ctag = mt;
      }
    }
  }
}

bool CZAnalysisVAM::ShowIsoCurves() const
{
  // Most shaded analysis modes that work on breps have
  // the option of showing or hiding isocurves.  Run the
  // built-in Rhino ZebraAnalysis to see how Rhino handles
  // the user interface.  If controlling iso-curve visability 
  // is a feature you want to support, then provide user
  // interface to set this member variable.
  return m_bShowIsoCurves;
}

//
// END Z analysis mode class
// 
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//
//开始Z分析模式类
// 
//这是一个演示如何添加假颜色的示例
//Rhino的分析模式。此示例使用假颜色来表示
//世界“z”坐标。
//{DF4688C-9671-4389-AC41-515B8693A783}
静态常量GUID错误\u颜色\u示例\u分析\u模式\u ID=
{0xDF4688C,0x9671,0x4389,{0xAC,0x41,0x51,0x5B,0x86,0x93,0xA7,0x83};
CZVAM类:公共CRHINOVISUALANALYSMODE
{
公众:
czvam();
~czvam();
//虚拟CRHINOVISUALANALYSMODE覆盖
void GetAnalysisModeName(在字符串和名称上)常量;
//虚拟CRHINOVISUALANALYSMODE覆盖
bool objectsupportsananalysismode(const CRhinoObject*object)const;
//虚拟CRHINOVISUALANALYSMODE覆盖
无效更新颜色(
常量CRhinoObject*对象,
关于SimpleArray和mesh
)常数;
//虚拟CRHINOVISUALANALYSMODE覆盖
bool showisourves()常数;
//虚拟CRHINOVISUALANALYSMODE覆盖
无效对象(
const CRhinoMeshObject和mesh_对象,
Crhinodisplay管道和dp
);
//虚拟CRHINOVISUALANALYSMODE覆盖
无效DrawBrepObject(
const CRhinoBrepObject和brep_object,
Crhinodisplay管道和dp
);
布尔m_bShowIsoCurves;
//这个简单的示例提供了一个基于
//世界z坐标。有关详细信息,请参见实现
//FalseColor函数的。
关于m_区间m_z_区间;
关于m_间隔m_色调_范围;
彩色假彩色(双z)常数;
//返回一个映射标记,用于检测
//需要设置网格颜色。有关详细信息,请参阅
//MappingTag和UpdateVertexColor的实现。
ON_MappingTag MappingTag()常量;
};
//CZAnalysisVAM对象的唯一实例。
//CRHINOVISUALANALYSMODE构造函数注册模式
//和犀牛。在Rhino运行时,此类不能被销毁
//它是活动的。
静态类CZAnalysisVAM ThezanAnalysisVam;
CZAnalysisVAM::CZAnalysisVAM()
:CRHINOVISUALANALYSMODE(假颜色、示例、分析、模式、ID、,
CRHINOVISUALANALYSMODE::假彩色
)
{
m_b显示等曲线=真;
//在真正的插件中,用户界面将允许
//用户可以更改这些间隔。
m_z_范围集(-10.0,10.0);
m_hue_range.Set(0.0,4.0*ON_PI/3.0);//红色到绿色到蓝色
}
CZAnalysisVAM::~CZAnalysisVAM()
{
}
void CZAnalysisVAM::GetAnalysisModeName(在字符串和名称上)常量
{
//此名称显示在对象属性详细信息中
//当对象处于分析模式时报告。
名称=L“Z分析”;
}
bool CZAnalysisVAM::objectsupportsananalysismode(const CRhinoObject*object)const
{
//如果分析模式工作,此函数应返回true
//这个例子适用于网格和网格,所以
//它的ObjectSupportsAnalysisMode版本如下所示。
bool rc=假;
如果(对象)
{
开关(对象->对象类型())
{
大小写::网格\对象:
if(CRhinoMeshObject::Cast(对象))
rc=真;
打破
case ON::surface_对象:
案例::polysrf_过滤器:
案例::brep_对象:
if(CRhinoBrepObject::Cast(对象))
rc=真;
打破
}
}
返回rc;
}
关于_mappingtagczanalysisvam::MappingTag()常量
{
在地图上标记mt;
//因为如果
//网格变换后,我们必须初始化
//转变。
mt.m_mesh_xform.Identity();
//这是传递给的分析模式id
//CRHINOVISUALANALYSMODE构造函数。使用
//m_am_id成员,此代码将一直有效
//工作正常。
mt.m_mapping_id=m_am_id;
//这是一个32位CRC或用于
//设置假颜色。
//对于本例,m_z_范围和m_色调_范围
//间隔控制颜色,所以我们计算
//他们的crc。
mt.m_映射_crc=0;
mt.m_mapping_crc=ON_CRC32(mt.m_mapping_crc,sizeof(m_z_范围)和m_z_范围);
mt.m_mapping_crc=ON_CRC32(mt.m_mapping_crc,sizeof(m_色调范围)和m_色调范围);
返回mt;
}
关于颜色分析VAM::FalseColor(双z)常数
{
//更改数字的一种方法的简单示例
//变成一种颜色。
双s=m_z_范围。归一化参数(z);
如果(s<0.0)s=0.0;如果(s>1.0)s=1.0;
双色调=m色调范围。参数;
关于颜色c;
c、 SetHSV(色调,1.0,1.0);
返回c;
}
void CZAnalysisVAM::UpdateVertexColors(
常量CRhinoObject*对象,
关于SimpleArray和mesh
)常数
{
//Rhino在您需要时调用此函数
//在分析网格顶点上设置假颜色。
//对于BREP,每个面有一个网格。对于网格对象,
//只有一个网格。
const int count=meshes.count();
如果(计数>0)
{
//“映射标签”用于确定颜色
//需要设置。
ON_MappingTag mt=MappingTag();
网格上的常数*常数*网格列表=Mesh.Array();
对于(int mi=0;mim_Ctag))
{
//网格的映射标记与我们的不同
//网格没有假颜色,具有由设置的假颜色
//另一个分析
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using RMA.Rhino;
using RMA.OpenNURBS;

namespace MyPlugIn1
{



    public class customAnalysis : MRhinoVisualAnalysisMode
    {


        static Guid FALSE_COLOR_EXAMPLE_ANALYSIS_MODE_ID = new Guid("{B0CBD23A-089B-4fb2-A61A-6DE1238E7B74}");

        public OnInterval m_z_range;
        public OnInterval m_hue_range;

        bool m_bShowIsoCurves;

        public customAnalysis():base(FALSE_COLOR_EXAMPLE_ANALYSIS_MODE_ID,IRhinoVisualAnalysisMode.analysis_style.false_color_style) 
        {
            m_bShowIsoCurves = true;

            // In a real plug-in, user interface would allow
            // the user to change these intervals.

            m_z_range.Set(-10.0, 10.0);
            m_hue_range.Set(0.0, 4.0 * Math.PI / 3.0); // red to green to blue

        }


        public override string GetAnalysisModeName()
        {
            return "kineticMode";
        }


        public override bool ObjectSupportsAnalysisMode(IRhinoObject rh_object)
        {
            // This function should return true if the analysis mode works
            // on the object.  This example works on meshes and breps, so
            // its version of ObjectSupportsAnalysisMode looks like this.
            OnObject obj = rh_object.DuplicateOnObject();

            Boolean rc = false;
            if (null != rh_object && null != obj)
            {
                switch (rh_object.ObjectType())
                {
                    case IOn.object_type.mesh_object:
                        if (null != MRhinoMeshObject.Cast(obj))

                            rc = true;
                        break;

                    case IOn.object_type.surface_object:
                    case IOn.object_type.polysrf_filter:
                    case IOn.object_type.brep_object:
                        if (null != MRhinoBrepObject.Cast(obj))

                            rc = true;
                        break;
                }
            }
            return rc;
        }

        public override void UpdateVertexColors(IRhinoObject rh_object, OnMesh[] meshes)
        {
            int count = meshes.Length;

            if (count > 0)
            {
                // A "mapping tag" is used to determine if the colors
                // need to be set.
                OnMappingTag mt = MappingTag();

                //const ON_Mesh * const * mesh_list = meshes.Array();
                for (int mi = 0; mi < count; mi++)
                {
                    OnMesh mesh = meshes[mi];
                    if (null != mesh && mt.Compare(mesh.m_Ctag) > 0)
                    {
                        // The mesh's mapping tag is different from ours. Either
                        // the mesh has no false colors, has false colors set by
                        // another analysis mode, has false colors set using
                        // different m_z_range[]/m_hue_range[] values, or the
                        // mesh has been moved.  In any case, we need to set
                        // the false colors to the ones we want.

                        int vcount = mesh.m_V.Count();

                        ArrayOnColor vertex_colors = OnMesh.Cast(mesh).m_C;

                        vertex_colors.SetCount(0);     // in case something else had set the colors
                        vertex_colors.Reserve(vcount); // for efficiency

                        for (int vi = 0; vi < vcount; vi++)
                        {
                            double z = mesh.m_V[vi].z;
                            OnColor c = FalseColor(z);
                            vertex_colors.Append(c);
                        }

                        // set the mesh's color tag 
                        mesh.m_Ctag = mt;


                    }
                }
            }
        }

        public override bool ShowIsoCurves()
        {
            return m_bShowIsoCurves;
        }

        public override void DrawMeshObject(IRhinoMeshObject mesh_object, MRhinoDisplayPipeline dp)
        {
            base.DrawMeshObject(mesh_object, dp);
        }

        public override void DrawBrepObject(IRhinoBrepObject brep_object, MRhinoDisplayPipeline dp)
        {
            base.DrawBrepObject(brep_object, dp);
        }

        public OnMappingTag MappingTag()
        {

            OnMappingTag mt = null;

            // Since the false colors that are shown will change if
            // the mesh is transformed, we have to initialize the
            // transformation.
            mt.m_mesh_xform.Identity();

            // This is the analysis mode id passed to the 
            // CRhinoVisualAnalysisMode constructor. Use the
            // m_am_id member and it this code will alwasy 
            // work correctly.
            mt.m_mapping_id = m_am_id;

            // This is a 32 bit CRC or the information used to
            // set the false colors.
            // For this example, the m_z_range and m_hue_range
            // intervals control the colors, so we calculate 
            // their crc.
            mt.m_mapping_crc = 0;
            //mt.m_mapping_crc = ON_CRC32(mt.m_mapping_crc, m_z_range.Length, m_z_range);
            //mt.m_mapping_crc = ON_CRC32(mt.m_mapping_crc, m_hue_range.Length, m_hue_range);

           OnTextureMapping thomas = new OnTextureMapping();


            return mt;

        }


        public OnColor FalseColor(double z)
        {

            double s = m_z_range.NormalizedParameterAt(z);

            if (s < 0.0) s = 0.0; else if (s > 1.0) s = 1.0;

            double hue = m_hue_range.ParameterAt(s);

            OnColor c = new OnColor();

            c.SetHSV(hue, 1.0, 1.0);

            return c;

        }


        ~customAnalysis() { }

    }
}