您现在的位置:网站首页 > 经验分享 > 鞋业CAD软件柔性内核技术:源码[13]
设计师介绍:

昵称:烦夫子
类别:界面/平面设计师
年龄:37
现所在地:北京

查看该设计师的主页>>

关注好友

统计中心

主页浏览总数:24096
总积分:89
文章数:88
作品数:70

鞋业CAD软件柔性内核技术:源码[13]

作者:烦夫子  更新时间: 2007-11-19   浏览人数:18129  评论:0  
分享到:
开放源码:
                         柔性图形内核之十三
                         BSpline
//应用于CAD/CAM图形类程序设计
//我将逐步开放数以十万记的自主版权软件源码,谢谢大家的支持!
//以后将开源的项目: CAD、工控、机械设计图、电子布线图等
 

// BSpline.h: interface for the BSpline class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_BSPLINE_H__3126C9C8_E152_4458_8B27_C1740C899F20__INCLUDED_)
#define AFX_BSPLINE_H__3126C9C8_E152_4458_8B27_C1740C899F20__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Object.h"

typedef float   Coeff[4][4];

class SOFTDRAW_CLASS BSpline : public Object 
{

private:
    float   *t;     //节点参数值    (num+7个)
    Coeff   *coe;   //系数矩阵      (num-1个)
    Vector  *org;   //给定型值点    (num个)
    Vector  *ctl;   //曲线控制点    (num+2个)

    int     *pos;   //记录buf[i]属于哪一段曲线
    Vector  *buf;   //曲线细分後,逼近曲线的折线集
 int     *posbackup;         //每一次调用split()函数,pos都将改变。
                             //posbackup则不会变,它始终与buf对应。
 int     indexInPattern;     //TZH.Correct.13缝边刷新的修正

private:
 //计算BSpline基及其导数
    float B (int j, int k, float x) const;
    float dB (int j, int k, float x) const;

 //曲线反算时附加的端点条件
    Vector EndCondition (Vector& p1, Vector& p2, Vector& p3) const;

 //计算节点值
    int Knots (int num, Vector *p, float knotlen);

    //曲线细分
    int Split (float error, Vector **p) const;

    //曲线细分点数
    int SplitNum (float error) const;

    //计算系数矩阵
    void CalCoeff (Coeff& c, int i);

    //曲线方向求反
    void Inverse (int num, Vector *pv);
    void Flush ();
    void DrawArrow (CDC* hDC, float scale, DrawMode mode) const;   //绘曲线方向
    void DrawCtrls (CDC* dc, float scale) const;                   //绘曲线控制点
    void DrawHeads (CDC* dc, float scale, DrawMode mode) const;    //绘端点
 
public:
 int       segnum;                //buf的大小
 Vector    CurPt[20];
 int       CurveType;             //0表正常曲线,1表对称边属性, 2虚线等, 3 表明线
    int    previewmode;             //是否处于预览状态
 float    knotlen;
public:
               
    BSpline (const Object *p = NULL);
 virtual ~BSpline();

 int GetPoints (Vector *p) const;                    //得到曲线的结点在p中,返回结点个数
 int GetDiscretePoints (Vector *p) const;            //得到曲线细分点buf点放在p中,返回segnum
    void GetEndPoint (Vector& v1, Vector& v2) const;    //得到曲线的端点
    Vector GetTestPoint () const { return org[0];}      //得到第一个点
 
 void GetMinMax ();          //得到对象的最大最小点
    long GetSize () const;          //占用内存
    float GetLength () const;       //曲线长度
 void Reverse ();            //曲线反向
    COLORREF GetColor (DrawMode mode);
public:
    int Make (int num, Vector *p, int autodelete = 0);            //构造曲线
    void ToBezier (int i, Vector p[4]) const; 
    void Draw (CDC* hDC, float scale, DrawMode mode, int dispmode) const;
    void FastDraw (CDC* dc, float scale, DrawMode mode, TransformFunc func) const;
    void DrawBox (CDC* dc, float scale, int index, DrawMode mode) const;
 void DrawNodes (CDC* dc, float scale, DrawMode mode) const;    //绘节点

    Vector P (int i, float u) const;                     //求第i段上参数为u的点
    Vector TP (int i, float u) const;                    //切矢
    Vector T2P (int i, float u) const;                   //二阶导数
    Vector NP (int i, float u) const;                    //法矢

public:
    Object& ōperator = (const Object& aObject);
    int ōperator == (const Object& aObject);
    int operator ^ (const Object& aObject);
    int operator < (const BSpline& aBSpline);
    int operator << (const BSpline& aBSpline);
    int operator > (const BSpline& aBSpline);
 int operator >> (const BSpline& aBSpline);
 
    DECLARE_IO_METHOD (BSpline)

};

#endif // !defined(AFX_BSPLINE_H__3126C9C8_E152_4458_8B27_C1740C899F20__INCLUDED_)

(目前有0人发表看法,  我要发表评论
我要评论:
  只有登录后才能评论!
评论者: 匿名游客    (立即登录 或 注册)