Click here to Skip to main content
15,898,134 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionAnnoying problem with VISTA and Win7 and above? Pin
Kushagra Tiwari8-Dec-09 8:38
Kushagra Tiwari8-Dec-09 8:38 
AnswerRe: Annoying problem with VISTA and Win7 and above? Pin
Richard MacCutchan8-Dec-09 9:57
mveRichard MacCutchan8-Dec-09 9:57 
AnswerRe: Annoying problem with VISTA and Win7 and above? Pin
Rolf Kristensen10-Dec-09 11:23
Rolf Kristensen10-Dec-09 11:23 
QuestionSeparating business and presentation logic in different threads Pin
crewchill8-Dec-09 7:42
crewchill8-Dec-09 7:42 
AnswerRe: Separating business and presentation logic in different threads [modified] Pin
Rolf Kristensen10-Dec-09 11:35
Rolf Kristensen10-Dec-09 11:35 
QuestionWhat Will Happen? Two Projects Merging together that both access a DLL Pin
Greg Mort8-Dec-09 5:44
Greg Mort8-Dec-09 5:44 
AnswerRe: What Will Happen? Two Projects Merging together that both access a DLL Pin
PJ Arends8-Dec-09 7:24
professionalPJ Arends8-Dec-09 7:24 
Questionprogram too big to fit in memory ??? Pin
a04.lqd8-Dec-09 5:01
a04.lqd8-Dec-09 5:01 
this code: define Bspline curve, when i run it, i found:
"program too big to fit in memory" (although i restart computer)
???





#include "StdAfx.h"
#include "process.h"

#ifndef _MYBSPLINE_H__
#define _MYBSPLINE_H__

#ifndef ABS
# define ABS(x) ((x<0) ? (-1*(x)) : x)
#endif

typedef struct _MYPOINT
{
double x;
double y;
} MYPOINT;
//----------------------------------------------------------------------------------------------------
class CMyBSpline
{
public:
CMyBSpline(void);
~CMyBSpline(void);

void SetDegree(int nK); // Thiet lap bac cua da thuc neu ban muon
void Generate(MYPOINT* pControl, int n); // Thuc hien sinh cac diem dua tren cac diem dieu khien
int GetPointNum(); // Tra ve so diem sinh ra
MYPOINT* GetPoints(); // Tra ve con tro tro toi dau mang chua cac diem sinh

private:
MYPOINT* m_pPoints; // Mang chua cac diem B-Spline
int m_nNum; // So diem tren B-Spline sinh ra

int m_nK; // Bac cua da thuc
int* m_pU; // Mang chua cac Knots

void AllocateBSplinePoints(int n); // Cap phat vung nho luu tru diem tren B-Spline
void FreeBSplinePoints(); // Giai phong vung nho luu tru diem tren B-Spline

void AllocateKnot(int n); // Cap phat vung nho chua diem Knot
void FreeKnot(); // Giap phong bo nho da cap phat de luu diem Knot
void ComputeKnots(int n); // Tinh toan Knots

double FactorN(int t, int k, double v); // Tinh he so da thuc Ni,k(u)
void ComputeP(MYPOINT* pControl, int n, double u, MYPOINT& pt); // Tinh gia tri da thuc P(u)
};

#endif



CMyBSpline::CMyBSpline(void)
{
m_nK = 4; // Mac dinh
m_pPoints = NULL;
m_nNum = 0;
m_pU = NULL;
}

CMyBSpline::~CMyBSpline(void)
{
FreeKnot();
FreeBSplinePoints();
}

// Cap phat vung nho luu tru diem tren B-Spline
// n: So diem can cap phat
void CMyBSpline::AllocateBSplinePoints(int n)
{
if (m_pPoints!=NULL)
FreeBSplinePoints();
m_pPoints = new MYPOINT[n];
m_nNum = n;
}

// Giai phong vung nho luu tru diem tren B-Spline
void CMyBSpline::FreeBSplinePoints()
{
if (m_pPoints!=NULL)
delete [] m_pPoints;
m_pPoints = NULL;
m_nNum = 0;
}

// Cap phat bo nho de luu diem Knot
// n: So diem control point
// So diem Knots la: n+m_nK+1
void CMyBSpline::AllocateKnot(int n)
{
if (m_pU!=NULL)
FreeKnot();
m_pU = new int[n+m_nK+1];
}

// Giai phong bo nho da cap phat de luu cac diem Knot
void CMyBSpline::FreeKnot()
{
if (m_pU!=NULL)
{
delete [] m_pU;
m_pU = NULL;
}
}

// n: So diem control point
// Mang Knots luu trong m_pU
void CMyBSpline::ComputeKnots(int n)
{
int j;
for (j=0; j<=n+m_nK; j++)
{
if (j<m_nK)
m_pU[j]=0;
else if ((m_nK<=j) && (j<=n))
m_pU[j]=j-m_nK+1;
else if (j>n)
m_pU[j]=n-m_nK+2;
}
}

// Tinh toan de quy he so da thuc: Ni,k(u)
// i: 0<=i<=n
// k: Bac cua da thuc
// u: La diem can tinh
double CMyBSpline::FactorN(int i, int k, double u)
{
double value;

if (k==1) // Dieu kien dung de quy
{
if ((m_pU[i]<=u) && (u<m_pU[i+1]))
value=1;
else
value=0;
}
else
{
if ((m_pU[i+k-1]==m_pU[i]) && (m_pU[i+k]==m_pU[i+1])) // Kiem tra dieu kien chia cho 0
value = 0;
else if (m_pU[i+k-1]==m_pU[i]) // Neu mau so bang 0 thi tinh theo cach khac
value = (m_pU[i+k] - u) / (m_pU[i+k] - m_pU[i+1]) * FactorN(i+1, k-1, u);
else if (m_pU[i+k]==m_pU[i+1]) // Neu mau so bang 0 thi tinh theo cach khac
value = (u - m_pU[i]) / (m_pU[i+k-1] - m_pU[i]) * FactorN(i, k-1, u);
else
value = (u - m_pU[i]) / (m_pU[i+k-1] - m_pU[i]) * FactorN(i, k-1, u) +
(m_pU[i+k] - u) / (m_pU[i+k] - m_pU[i+1]) * FactorN(i+1, k-1, u);
}

return value;
}

// Tinh gia tri da thuc P(u)
// pControl: Mang chua diem control point
// n: So diem control poiint
// u: Diem tinh
void CMyBSpline::ComputeP(MYPOINT* pControl, int n, double u, MYPOINT& pt)
{
double dFactor;

// Khoi tao lai cac gia tri
pt.x = 0;
pt.y = 0;

for (int i=0; i<=n; i++)
{
dFactor = FactorN(i, m_nK, u); // same blend is used for each dimension coordinate
pt.x += (pControl[i]).x * dFactor;
pt.y += (pControl[i]).y * dFactor;
}
}

// Thiet lap bac cua da thuc neu ban muon
void CMyBSpline::SetDegree(int nK)
{
m_nK = nK;
}

// Sinh ra cac diem tren B-Spline
// pControl: Mang chua cac diem dieu khien
// n: So diem dieu khien
void CMyBSpline::Generate(MYPOINT* pControl, int n)
{
// Hieu chinh lai gia tri cho phu hop
n--;

// Xoa cac diem cu
FreeBSplinePoints();

// Kiem tra dieu kien
if (n+2<=m_nK)
return; // Khong co duong cong

// Tinh so diem
// Tinh tuong doi so diem sinh B-Spline
int nNum = 0;
int nDiv = 0;
for (int i=0; i<n; i++)
{
nDiv = (int)(max(ABS(pControl[i+1].x-pControl[i].x), ABS(pControl[i+1].y-pControl[i].y))/0.5);
if (nDiv==0)
nDiv = 1;
nNum += nDiv+1;
}

// Cap phat va tinh cac diem Knots
AllocateKnot(n);
ComputeKnots(n);

// Cap phat bo nho luu diem tren B-Spline
AllocateBSplinePoints(nNum);

// Sinh cac diem tren B-Spline
MYPOINT pt;
double dInc = (double)(n-m_nK+2)/nNum;
double u = 0;
for (int nIdx=0; nIdx< nNum; nIdx++)
{
ComputeP(pControl, n, u, pt);
m_pPoints[nIdx].x = pt.x;
m_pPoints[nIdx].y = pt.y;
u += dInc;
}

FreeKnot();
}

int CMyBSpline::GetPointNum()
{
return m_nNum;
}

MYPOINT* CMyBSpline::GetPoints()
{
return m_pPoints;
}
AnswerRe: program too big to fit in memory ??? Pin
Chris Losinger8-Dec-09 5:11
professionalChris Losinger8-Dec-09 5:11 
QuestionRe: program too big to fit in memory ??? Pin
David Crow8-Dec-09 5:58
David Crow8-Dec-09 5:58 
AnswerRe: program too big to fit in memory ??? Pin
a04.lqd8-Dec-09 13:18
a04.lqd8-Dec-09 13:18 
AnswerRe: program too big to fit in memory ??? Pin
PCuong19838-Dec-09 14:39
professionalPCuong19838-Dec-09 14:39 
GeneralRe: program too big to fit in memory ??? Pin
a04.lqd8-Dec-09 15:09
a04.lqd8-Dec-09 15:09 
Questionwhat are these error ? Pin
a04.lqd8-Dec-09 4:18
a04.lqd8-Dec-09 4:18 
AnswerRe: what are these error ? Pin
Rajesh R Subramanian8-Dec-09 4:21
professionalRajesh R Subramanian8-Dec-09 4:21 
AnswerRe: what are these error ? Pin
a04.lqd8-Dec-09 4:34
a04.lqd8-Dec-09 4:34 
GeneralRe: what are these error ? Pin
Maximilien8-Dec-09 4:37
Maximilien8-Dec-09 4:37 
AnswerRe: what are these error ? Pin
David Crow8-Dec-09 4:53
David Crow8-Dec-09 4:53 
QuestionProgram Data Limits Pin
Grahamfff8-Dec-09 4:05
Grahamfff8-Dec-09 4:05 
QuestionRe: Program Data Limits Pin
Rajesh R Subramanian8-Dec-09 4:18
professionalRajesh R Subramanian8-Dec-09 4:18 
AnswerRe: Program Data Limits Pin
Grahamfff8-Dec-09 4:35
Grahamfff8-Dec-09 4:35 
GeneralRe: Program Data Limits Pin
Rolf Kristensen10-Dec-09 11:38
Rolf Kristensen10-Dec-09 11:38 
QuestionHow to keep contents of a TextBox in black when the TextBox is disabled? Pin
dipuks8-Dec-09 3:47
dipuks8-Dec-09 3:47 
AnswerRe: How to keep contents of a TextBox in black when the TextBox is disabled? Pin
Cedric Moonen8-Dec-09 4:04
Cedric Moonen8-Dec-09 4:04 
AnswerRe: How to keep contents of a TextBox in black when the TextBox is disabled? Pin
«_Superman_»8-Dec-09 4:15
professional«_Superman_»8-Dec-09 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.