|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// CallCircle.cpp: implementation of the CCallCircle class.
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//////////////////////////////////////////////////////////////////////
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <math.h></math.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdlib.h></stdlib.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <search.h></search.h>
|
|
Toshihiro Shimizu |
890ddd |
//#include "myetc.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "CallCircle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//////////////////////////////////////////////////////////////////////
|
|
Toshihiro Shimizu |
890ddd |
// Construction/Destruction
|
|
Toshihiro Shimizu |
890ddd |
//////////////////////////////////////////////////////////////////////
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int callcircle_xydwCompare(const void *a, const void *b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
SXYDW *aa = (SXYDW *)a;
|
|
Toshihiro Shimizu |
890ddd |
SXYDW *bb = (SXYDW *)b;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (aa->w < bb->w)
|
|
Toshihiro Shimizu |
890ddd |
return -1;
|
|
Toshihiro Shimizu |
890ddd |
if (aa->w > bb->w)
|
|
Toshihiro Shimizu |
890ddd |
return 1;
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0), m_c(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int rr = (int)r + 1;
|
|
Toshihiro Shimizu |
890ddd |
rr *= 2;
|
|
Toshihiro Shimizu |
890ddd |
int dd = rr * 2 + 1;
|
|
Toshihiro Shimizu |
890ddd |
int dd2 = dd * dd;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (dd2 == 0) {
|
|
Toshihiro Shimizu |
890ddd |
null();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_c = new SXYDW[dd2];
|
|
Toshihiro Shimizu |
890ddd |
if (!m_c)
|
|
Toshihiro Shimizu |
890ddd |
throw SMemAllocError("in callCircle");
|
|
Toshihiro Shimizu |
890ddd |
for (int y = -rr; y <= rr; y++)
|
|
Toshihiro Shimizu |
890ddd |
for (int x = -rr; x <= rr; x++) {
|
|
Toshihiro Shimizu |
890ddd |
double d = sqrt((double)(x * x + y * y));
|
|
Toshihiro Shimizu |
890ddd |
if (d <= r && m_nb < dd2) {
|
|
Toshihiro Shimizu |
890ddd |
m_c[m_nb].x = x;
|
|
Toshihiro Shimizu |
890ddd |
m_c[m_nb].y = y;
|
|
Toshihiro Shimizu |
890ddd |
m_c[m_nb].w = d;
|
|
Toshihiro Shimizu |
890ddd |
m_nb++;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
qsort(m_c, m_nb, sizeof(SXYDW), callcircle_xydwCompare);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CCallCircle::null()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_nb = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_r = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
if (m_c) {
|
|
Toshihiro Shimizu |
890ddd |
delete[] m_c;
|
|
Toshihiro Shimizu |
890ddd |
m_c = 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CCallCircle::~CCallCircle()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
null();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CCallCircle::print()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*smsg_info(" --- CCallCircle ---");
|
|
Toshihiro Shimizu |
890ddd |
smsg_info(" m_nb=%d", m_nb);
|
|
Toshihiro Shimizu |
890ddd |
smsg_info(" m_r=%f", m_r);
|
|
Toshihiro Shimizu |
890ddd |
for( int i=0; i
|
|
Toshihiro Shimizu |
890ddd |
smsg_info(" %d. = (%d,%d,%f)", i, m_c[i].x,m_c[i].y,m_c[i].w);
|
|
Toshihiro Shimizu |
890ddd |
smsg_info(" --- ----------- ---\n");
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CCallCircle::draw(UCHAR *drawB, const int lX, const int lY,
|
|
Toshihiro Shimizu |
890ddd |
const int xx, const int yy, const double r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double aa = 2.0 * r / 3.0; // Size of antialising
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < m_nb && m_c[i].w <= r; i++) {
|
|
Toshihiro Shimizu |
890ddd |
double w = m_c[i].w;
|
|
Toshihiro Shimizu |
890ddd |
int x = xx + m_c[i].x;
|
|
Toshihiro Shimizu |
890ddd |
int y = yy + m_c[i].y;
|
|
Toshihiro Shimizu |
890ddd |
if (x >= 0 && y >= 0 && x < lX && y < lY) {
|
|
Toshihiro Shimizu |
890ddd |
UCHAR *pDB = drawB + y * lX + x;
|
|
Toshihiro Shimizu |
890ddd |
if (w <= aa) {
|
|
Toshihiro Shimizu |
890ddd |
*pDB = (UCHAR)255;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
double q = 255.0 * (r - w) / (r - aa);
|
|
Toshihiro Shimizu |
890ddd |
q = D_CUT_0_255(q);
|
|
Toshihiro Shimizu |
890ddd |
UCHAR ucq = UC_ROUND(q);
|
|
Toshihiro Shimizu |
890ddd |
(*pDB) = (*pDB) < ucq ? ucq : (*pDB);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|