199 lines
5.2 KiB
C++
199 lines
5.2 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeGridLine.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: ÀàµÄ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeGridLine.h"
|
|
#include "TGPoint2D.h"
|
|
#include "TPGeCurve2D.h"
|
|
#include "TPGeLandform.h"
|
|
|
|
TPGeGridLine::TPGeGridLine() : m_pCurveElev(NULL)
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGridLine::~TPGeGridLine()
|
|
{
|
|
if (m_pCurveElev != NULL )
|
|
{
|
|
delete m_pCurveElev;
|
|
}
|
|
}
|
|
|
|
bool TPGeGridLine::operator < (const TPGeGridLine&)const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool TPGeGridLine::operator > (const TPGeGridLine&)const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void TPGeGridLine::CreateFrom(const TPGeLandform* pLand,bool bXLine,double lowValue)
|
|
{
|
|
ASSERT(pLand != NULL);
|
|
if (m_pCurveElev != NULL)
|
|
{
|
|
delete m_pCurveElev;
|
|
}
|
|
|
|
double nElev = pLand->GetElev();
|
|
const TPGeCurve2D& outline = pLand->Outline();
|
|
TGObjectList inList,outList,midList;
|
|
outline.Cut(*this,inList,outList,inList);
|
|
for (outList.MoveToFirst();!outList.IsOut();outList.MoveToNext())
|
|
{
|
|
TGObject* pObj = outList.GetCurData();
|
|
if (IS_TYPE(pObj,TPGeGLineSeg2D))
|
|
{
|
|
TPGeExtend2D ext2d;
|
|
if (pObj->GetExtend2D(ext2d))
|
|
{
|
|
if (bXLine)
|
|
{
|
|
m_allInvisibleExt.AddTail(ext2d.GetXExtend());
|
|
|
|
double nValue = ext2d.GetXExtend().GetMin();
|
|
double distValue = nValue - lowValue;
|
|
long iCol = (long)(distValue / pLand->GetDistX());
|
|
TPGeGridNode nodeElev1(TGPoint(nValue,nElev),2);
|
|
m_allPointElev.SortIn(nodeElev1);
|
|
if (UP_ZEROD(distValue - iCol * pLand->GetDistX()) &&
|
|
DOWN_ZEROD(distValue - (iCol + 1) * pLand->GetDistX()))
|
|
{
|
|
if (m_allSeg[iCol] == NULL)
|
|
{
|
|
m_allSeg[iCol] = new TPGeGridSeg;
|
|
}
|
|
TPGeGridNode node(TGPoint(nValue,basePoint.y,nElev),2);
|
|
outline.Pt2Pa(node,node.m_nPara);
|
|
m_allSeg[iCol]->m_lstCutPoint.SortIn(node);
|
|
}
|
|
|
|
nValue = ext2d.GetXExtend().GetMax();
|
|
TPGeGridNode nodeElev2(TGPoint(nValue,nElev),2);
|
|
m_allPointElev.SortIn(nodeElev1);
|
|
distValue = nValue-lowValue;
|
|
iCol = (long)(distValue / pLand->GetDistX());
|
|
if (UP_ZEROD(distValue - iCol * pLand->GetDistX()) &&
|
|
DOWN_ZEROD(distValue - (iCol + 1) * pLand->GetDistX()))
|
|
{
|
|
if (m_allSeg[iCol] == NULL)
|
|
{
|
|
m_allSeg[iCol] = new TPGeGridSeg;
|
|
}
|
|
TPGeGridNode node(TGPoint(nValue,basePoint.y,nElev),2);
|
|
outline.Pt2Pa(node,node.m_nPara);
|
|
m_allSeg[iCol]->m_lstCutPoint.SortIn(node);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_allInvisibleExt.AddTail(ext2d.GetYExtend());
|
|
|
|
double nValue = ext2d.GetYExtend().GetMin();
|
|
TPGeGridNode nodeElev1(TGPoint(nValue,nElev),2);
|
|
m_allPointElev.SortIn(nodeElev1);
|
|
|
|
double distValue = nValue-lowValue;
|
|
long iRow = (long)(distValue / pLand->GetDistY());
|
|
if (UP_ZEROD(distValue - iRow * pLand->GetDistY()) &&
|
|
DOWN_ZEROD(distValue - (iRow + 1) * pLand->GetDistY()))
|
|
{
|
|
if (m_allSeg[iRow] == NULL)
|
|
{
|
|
m_allSeg[iRow] = new TPGeGridSeg;
|
|
}
|
|
TPGeGridNode node(TGPoint(basePoint.x,nValue,nElev),2);
|
|
outline.Pt2Pa(node,node.m_nPara);
|
|
m_allSeg[iRow]->m_lstCutPoint.SortIn(node);
|
|
}
|
|
|
|
nValue = ext2d.GetYExtend().GetMax();
|
|
TPGeGridNode nodeElev2(TGPoint(nValue,nElev),2);
|
|
m_allPointElev.SortIn(nodeElev2);
|
|
|
|
distValue = nValue-lowValue;
|
|
iRow = (long)(distValue / pLand->GetDistY());
|
|
if (UP_ZEROD(distValue - iRow * pLand->GetDistY()) &&
|
|
DOWN_ZEROD(distValue - (iRow + 1) * pLand->GetDistY()))
|
|
{
|
|
if (m_allSeg[iRow] == NULL)
|
|
{
|
|
m_allSeg[iRow] = new TPGeGridSeg;
|
|
}
|
|
TPGeGridNode node = TGPoint(basePoint.x,nValue,nElev);
|
|
outline.Pt2Pa(node,node.m_nPara);
|
|
m_allSeg[iRow]->m_lstCutPoint.SortIn(node);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (long i = 1; i < pLand->GetLength(); i++)
|
|
{
|
|
const TPGeCurve2D &curve = pLand->GetPData(i);
|
|
TGObjectList buf;
|
|
curve.Intersect(*this, buf);
|
|
double nElev = curve.GetElev();
|
|
for (buf.MoveToFirst();!buf.IsOut();buf.MoveToNext())
|
|
{
|
|
TGObject *pObj = buf.GetCurData();
|
|
if (IS_TYPE(pObj,TGPoint2D))
|
|
{
|
|
TGPoint2D *pPt = (TGPoint2D*)pObj;
|
|
if (bXLine)
|
|
{
|
|
TPGeGridNode nodeElev(TGPoint(pPt->x,nElev),3);
|
|
m_allPointElev.SortIn(nodeElev);
|
|
}
|
|
else
|
|
{
|
|
TPGeGridNode nodeElev(TGPoint(pPt->y,nElev),3);
|
|
m_allPointElev.SortIn(nodeElev);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TGMLine2D *pMLine2D = new TGMLine2D(m_allPointElev.GetLength());
|
|
for (m_allPointElev.MoveToFirst();!m_allPointElev.IsOut();m_allPointElev.MoveToNext())
|
|
{
|
|
(*pMLine2D)[m_allPointElev.GetCur()] = m_allPointElev.GetCurData();
|
|
}
|
|
m_pCurveElev = pMLine2D;
|
|
}
|
|
|
|
bool TPGeGridLine::IsVisible(double value)const
|
|
{
|
|
for (long i = 0; i < m_allInvisibleExt.GetLength();i++)
|
|
{
|
|
const TPGeExtend&ext = m_allInvisibleExt.GetAt(i);
|
|
if (ext.IsInside(value))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
double TPGeGridLine::GetElev(double x)const
|
|
{
|
|
TPGeGLine2D line(TGVector2D(0,1),TGPoint(x,0));
|
|
TGObjectList res;
|
|
if (!m_pCurveElev->Intersect(line, res))
|
|
{
|
|
return 0;
|
|
}
|
|
return res.GetAt(0)->GetSamplePoint().y;
|
|
} |