You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

740 lines
12 KiB
C++

#include "MLPoint.h"
#include "MLPlNode.h"
#include "MLFuncom.h"
MLPoint::MLPoint(void)
:MLVector()
{
memset(m_name, 0, 32);
m_cz = 0;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( double vx, double vy )
:MLVector(vx, vy)
{
memset(m_name, 0, 32);
m_cz = 0;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( double vx, double vy, double vz )
:MLVector(vx, vy, vz)
{
memset(m_name, 0, 32);
m_cz = 0;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( double vx, double vy, double vz,double vcz )
:MLVector(vx, vy, vz)
{
memset(m_name, 0, 32);
m_cz = vcz;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( double vx, double vy, double vz, double vcz, double vl )
:MLVector(vx, vy, vz)
{
memset(m_name, 0, 32);
m_cz = vcz;
m_l = vl;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( double vx, double vy, char* name )
{
memcpy(m_name, name, 32);
m_x = vx;
m_y = vy;
m_z = 0;
m_cz = 0;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( double vx, double vy, double vz, char* name )
:MLVector(vx, vy, vz)
{
memcpy(m_name, name, 32);
m_cz = 0;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( const MLPlNode& node )
{
memset(m_name, 0, 32);
m_cz = 0;
m_x = node.x;
m_y = node.y;
m_z = node.z;
m_l = node.l;
m_type = -1;
m_index = -1;
}
MLPoint::MLPoint( const MLPoint& dPoint )
{
memcpy(m_name, dPoint.name, 32);
m_x = dPoint.x;
m_y = dPoint.y;
m_z = dPoint.z;
m_cz = dPoint.cz;
m_l = dPoint.l;
m_type = dPoint.type;
m_index = dPoint.index;
}
MLPoint::MLPoint( const QPointF& point )
{
memset(m_name, 0, 32);
m_x = point.x();
m_y = point.y();
m_z = 0;
m_cz = 0;
m_l =-1;
m_type = -1;
m_index = -1;
}
MLPoint::~MLPoint(void)
{
}
const char* MLPoint::getName() const
{
return m_name;
}
void MLPoint::setName(const char* name )
{
memcpy(m_name, name, 32);
}
void MLPoint::setName(const QString& name)
{
memcpy(m_name, name.toLocal8Bit().data(), 32);
}
QString MLPoint::getNameQStr()
{
return QString::fromLocal8Bit(m_name);
}
void MLPoint::setCZ( double cz )
{
m_cz = cz;
}
double MLPoint::getCZ() const
{
return m_cz;
}
double& MLPoint::getCZ()
{
return m_cz;
}
double MLPoint::getL() const
{
return m_l;
}
void MLPoint::setL( double l )
{
m_l = l;
}
int MLPoint::getType() const
{
return m_type;
}
void MLPoint::setType( int type )
{
m_type = type;
}
int MLPoint::getIndex() const
{
return m_index;
}
int& MLPoint::getIndex()
{
return m_index;
}
void MLPoint::setIndex(int idx)
{
m_index = idx;
}
void MLPoint::setPoint( double dbx,double dby,double dbz )
{
m_x = dbx;
m_y = dby;
m_z = dbz;
}
void MLPoint::setPoint( const MLPoint& dPoint )
{
m_x = dPoint.x;
m_y = dPoint.y;
m_z = dPoint.z;
}
void MLPoint::setPoint( const MLPlNode& node )
{
m_x = node.x;
m_y = node.y;
m_z = node.z;
}
void MLPoint::setPoint( const QPointF& point )
{
m_x = point.x();
m_y = point.y();
}
void MLPoint::offset( double offsetx, double offsety )
{
m_x += offsetx;
m_y += offsety;
}
bool MLPoint::Equ(const MLPoint& other, int dot /*= 6*/)
{
if (::Equ(m_x, other.m_x, dot) &&
::Equ(m_x, other.m_x, dot))
{
return true;
}
return false;
}
MLPoint& MLPoint::operator = (const MLPoint& dPoint) throw()
{
memcpy(m_name, dPoint.name, 32);
m_x = dPoint.x;
m_y = dPoint.y;
m_z = dPoint.z;
m_cz = dPoint.cz;
m_l = dPoint.l;
m_type = dPoint.type;
m_index = dPoint.index;
return (*this);
}
MLPoint& MLPoint::operator = (const QPoint& point) throw()
{
m_x = point.x();
m_y = point.y();
return *this;
}
MLPlNode MLPoint::toPlNode()const
{
MLPlNode node;
node.x = m_x;
node.y = m_y;
node.z = m_z;
return node;
}
QPoint MLPoint::toQPoint()const
{
QPoint point;
point.setX(m_x);
point.setY(m_y);
return point;
}
QPointF MLPoint::toQPointF()const
{
QPointF point;
point.setX(m_x);
point.setY(m_y);
return point;
}
void MLPoint::readPoint( QDataStream& in )
{
in.readRawData(m_name, 32);
double data[5] = { 0 };
int type[2] = { 0 };
in.readRawData((char*)data, sizeof(double) * 5);
in.readRawData((char*)type, sizeof(int) * 2);
m_x = data[0];
m_y = data[1];
m_z = data[2];
m_cz = data[3];
m_l = data[4];
m_type = type[0];
m_index = type[1];
//in >> m_x; //x<><78><EFBFBD><EFBFBD>
//in >> m_y; //y<><79><EFBFBD><EFBFBD>
//in >> m_z; //Zֵ
//in >> m_cz; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
//in >> m_l; //<2F>ڵ㳤<DAB5><E3B3A4>λ<EFBFBD><CEBB>
//in >> m_type; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//in >> m_index;
}
void MLPoint::readPoint( FILE* fr )
{
}
void MLPoint::writePoint( QDataStream& out )
{
out.writeRawData(m_name, 32);
double data[5] = {0};
int type[2] = {0};
data[0] = m_x;
data[1] = m_y;
data[2] = m_z;
data[3] = m_cz;
data[4] = m_l;
type[0] = m_type;
type[1] = m_index;
out.writeRawData((char*)data, sizeof(double) * 5);
out.writeRawData((char*)type, sizeof(int) * 2);
//out << m_x; //x<><78><EFBFBD><EFBFBD>
//out << m_y; //y<><79><EFBFBD><EFBFBD>
//out << m_z; //Zֵ
//out << m_cz; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
//out << m_l; //<2F>ڵ㳤<DAB5><E3B3A4>λ<EFBFBD><CEBB>
//out << m_type; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//out << m_index;
}
QDataStream &operator<<(QDataStream &stream, const MLPoint &point)
{
stream.writeRawData(point.getName(), 32);
double data[5] = { 0 };
int type[2] = { 0 };
data[0] = point.x;
data[1] = point.y;
data[2] = point.z;
data[3] = point.cz;
data[4] = point.l;
type[0] = point.type;
type[1] = point.index;
stream.writeRawData((char*)data, sizeof(double) * 5);
stream.writeRawData((char*)type, sizeof(int) * 2);
return stream;
}
QDataStream &operator>>(QDataStream &stream, MLPoint &point)
{
char name[32] = { 0 };
double data[5] = { 0 };
int type[2] = { 0 };
stream.readRawData(name, 32);
point.setName(name);
stream.readRawData((char*)data, sizeof(double) * 5);
stream.readRawData((char*)type, sizeof(int) * 2);
point.setPoint(data[0], data[1], data[2]);
point.cz = data[3];
point.l = data[4];
point.type = type[0];
point.index = type[1];
return stream;
}
void MLPoint::writePoint( FILE* fw )
{
}
//////////////////////////////////////////////////////////////////////////
MLPointAry::MLPointAry()
{
m_bCalPos = false;
}
MLPointAry::~MLPointAry()
{
}
void MLPointAry::clear()
{
m_PointAry.clear();
}
int MLPointAry::count() const
{
return m_PointAry.count();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void MLPointAry::resetCount(int count)
{
m_PointAry.resize(count);
}
void MLPointAry::append( const MLPoint& dPoint )
{
m_PointAry.append(dPoint);
}
void MLPointAry::append( const MLPlNode& node )
{
m_PointAry.append(MLPoint(node));
}
void MLPointAry::append( double x, double y, double z/*=0*/ )
{
m_PointAry.append(MLPoint(x, y, z));
}
void MLPointAry::append( const MLPointAry& pointAry )
{
for (int i=0;i<pointAry.count();i++)
{
m_PointAry.append(pointAry[i]);
}
}
const MLPoint& MLPointAry::at( int index ) const
{
return m_PointAry.at(index);
}
void MLPointAry::setAt( int index, const MLPoint& dPoint )
{
if (index >=0 && index < count())
{
m_PointAry[index] = dPoint;
}
}
const MLPoint& MLPointAry::getAt( int index ) const
{
if (index<0)
{
return m_PointAry.back();
}
return m_PointAry.at(index);
}
void MLPointAry::createPoint( int nNum )
{
m_PointAry.resize(nNum);
}
void MLPointAry::removeAt( int index )
{
m_PointAry.remove(index);
}
void MLPointAry::insertAt( int index, const MLPoint& dPoint )
{
m_PointAry.insert(index, dPoint);
}
MLPoint& MLPointAry::operator[]( int index )
{
if (index >=0 && index < count())
{
return m_PointAry[index];
}
MLPoint pt;
return pt;
}
const MLPoint& MLPointAry::operator[]( int index ) const
{
if (index >=0 && index < count())
{
return m_PointAry[index];
}
return MLPoint();
}
void MLPointAry::operator = (const MLPointAry& pointAry) throw()
{
m_PointAry.clear();
m_PointAry.resize(pointAry.count());
memcpy(m_PointAry.data(), pointAry.getData(), sizeof(MLPoint) * pointAry.count());
}
void MLPointAry::copy( const MLPointAry& pointAry )
{
m_PointAry.clear();
m_PointAry.resize(pointAry.count());
//for (int i=0;i<pointAry.count();i++)
// m_PointAry[i] = pointAry[i];
memcpy(m_PointAry.data(), pointAry.getData(), sizeof(MLPoint) * pointAry.count());
}
MLPoint* MLPointAry::getData()
{
return m_PointAry.data();
}
const MLPoint* MLPointAry::getData() const
{
return m_PointAry.data();
}
void MLPointAry::read( QDataStream& in )
{
int count = 0;
in >> count;
m_PointAry.resize(count);
if (count >0)
{
in.readRawData((char*)m_PointAry.data(), sizeof(MLPoint)*count);
}
//MLPoint* pPoint = new MLPoint[count];
//in.readRawData((char*)pPoint, sizeof(MLPoint)*count);
//memcpy(m_PointAry.data(), pPoint, sizeof(MLPoint)*count);
}
void MLPointAry::write( QDataStream& out )
{
int count = MLPointAry::count();
out << count;
if (count>0)
{
out.writeRawData((char*)m_PointAry.data(), sizeof(MLPoint)*count);
}
}
double MLPointAry::getDistance()
{
if(count() <=1) return 0.0;
if (this->at(count()-1).l <=0.0)
{
calPointPos();
}
return this->at(count()-1).l;
}
void MLPointAry::calPointPos()
{
int nCount = this->count();
if(nCount <=0) return ;
(*this)[0].l = 0.0;
for(int i=1;i<nCount;i++)
{
(*this)[i].l = (*this)[i-1].l + sqrt(pow((at(i).x - at(i-1).x),2) + pow((at(i).y - at(i-1).y),2));
}
}
//<2F><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
int MLPointAry::bs(double dl, const MLPointAry& pointAry)
{
int n = count();
int w, start = 0, End = n-1;
if (n <= 0)
return -1;
if (dl < pointAry[start].l)
return -1;
if (!(pointAry[start].l < dl))
return start;
if (pointAry[End].l < dl)
return -1;
if (!(dl < pointAry[End].l))
return End;
while (End-start >= 2)
{
w = (End+start)/2;
if (dl < pointAry[w].l)
End = w;
else if (pointAry[w].l < dl)
start = w;
else
return w;
}
return -1;
}
void MLPointAry::sort( const MLPointAry& pointAry )
{
}
void MLPointAry::calculateBox()
{
/*if (m_bBox.isValid())
return ;
m_bBox.left = at(0).x;
m_bBox.right= m_bBox.left;
m_bBox.top = at(0).y;
m_bBox.bottom = m_bBox.top;
for(int i=1;i<count();i++)
{
if(m_bBox.left > at(i).x)
m_bBox.left = at(i).x;
if(m_bBox.right < at(i).x)
m_bBox.right = at(i).x;
if(m_bBox.bottom >at(i).y)
m_bBox.bottom = at(i).y;
if(m_bBox.top <at(i).y)
m_bBox.top = at(i).y;
}*/
}
/*
MLBox MLPointAry::getBoundingBox() const
{
return m_bBox;
}*/
// <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ĵ<EFBFBD>
MLPoint MLPointAry::getCenterPt()
{
calculateBox();
MLPoint dpt;
/*dpt.x = m_bBox.left + m_bBox.width()*0.5;
dpt.y = m_bBox.top + m_bBox.height()*0.5;*/
return dpt;
}
int MLPointAry::findIndex(double x)
{
int n = m_PointAry.count();
int w, start = 0, End = n-1;
if (n <= 0)
return -1;
if (x < m_PointAry[start].x)
return -1;
if (!(m_PointAry[start].x < x))
return start;
if (m_PointAry[End].x < x)
return -1;
if (!(x < m_PointAry[End].x))
return End;
while (End-start >= 2)
{
w = (End+start)/2;
if (x < m_PointAry[w].x)
End = w;
else if (m_PointAry[w].x < x)
start = w;
else
return w;
}
return End;
}
double MLPointAry::getYAscX( double x )
{
/*int index = AscFindByXX(*this, x);
if (index >0)
{
}
else
{
index = -index - 1;
}
if (index <=0)
return 0;
double x1 = m_PointAry[index-1].x;
double y1 = m_PointAry[index-1].y;
double x2 = m_PointAry[index].x;
double y2 = m_PointAry[index].y;
double y = CZ(x, x1, x2, y1, y2);*/
return 0;// y;
}
double MLPointAry::getYDescX( double x )
{
/*int index = AscFindByXX(*this, x);
if (index >0)
{
}
else
{
index = -index - 1;
}
if (index <=0)
return 0;
double x1 = m_PointAry[index-1].x;
double y1 = m_PointAry[index-1].y;
double x2 = m_PointAry[index].x;
double y2 = m_PointAry[index].y;
double y = CZ(x, x1, x2, y1, y2);
return y;*/
return 0;
}
//MLPline MLPointAry::toPline()
//{
// MLPline polyline;
// polyline.resize(m_PointAry.count());
// for (int i=0;i<m_PointAry.count();i++)
// {
// polyline.setAtPt(i, m_PointAry[i].toPlNode());
// }
// return polyline;
//}