⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curveunit.cpp

📁 对测井数据显示、编辑、处理
💻 CPP
字号:
// CurveUnit.cpp: implementation of the CCurveUnit class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "WellDataProcess.h"
#include "CurveUnit.h"

#include "GlobalData.h"
#include "math.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCurveUnit::CCurveUnit()
{
	m_corCurve = RGB(0, 0, 0);    //曲线的颜色
	m_nCurveWidth  = 1;    //曲线的宽度
	m_nCurveStyle = PS_SOLID;    //曲线的线型
	m_nXBase       = 0;     //曲线的基线X坐标 
	m_nYBase      = 0;    //曲线的基线Y坐标
	m_nColWidth  = 100;   //曲线栏所占的宽度
	m_nColHeight   = 100;  //曲线栏的高度
	
	m_strCurveName   = "No Name";
	m_fStartDep      = 0.0f;
	m_fEndDep    =   0.0f;
	m_fSampleSpace  = 0.125f;
	m_fDataMax     =  -9999.0f;
	m_fDataMin     =  9999.0f;
	
	m_arrData.RemoveAll();    //曲线数据

}

CCurveUnit::~CCurveUnit()
{

}

BOOL CCurveUnit::HitTest(CPoint point)
{
	int   nDataNum = GetDataSize();
	float fScaleX  = (float) m_nColWidth / (m_fDataMax - m_fDataMin);
	float fScaleY  = (float) m_nColHeight / nDataNum;
	int x, y;
	for(int i = 0; i < nDataNum; i ++)
	{
		x = int (m_nXBase + (m_arrData[i] - m_fDataMin) * fScaleX);
		y = int (m_nYBase + i * fScaleY);
		if(point.x > x - 3 && point.x < x + 3 && point.y < y + 3 && point.y > y - 3)
		{
			m_bSelect = TRUE;
			return TRUE;
			break;
		}
		else
		{
			m_bSelect = FALSE;
		}
	}
 	return FALSE;
}

void CCurveUnit::Draw(CDC *pDC)
{
    
	int   nDataNum = GetDataSize();
	float fScaleX  = (float) m_nColWidth / (m_fDataMax - m_fDataMin);
	float fScaleY  = (float) m_nColHeight / nDataNum;
	int x0 = int (m_nXBase + (m_arrData[0] - m_fDataMin) * fScaleX);
	if(x0 < m_nXBase)
		x0 = m_nXBase;
	int y0 = m_nYBase;
	int x, y;
	CPen pen;
	COLORREF	color;
	color = GetDrawPenColor();
	pen.CreatePen(m_nCurveStyle, m_nCurveWidth, color);
	CPen* pOrigPen;
    pOrigPen = pDC->SelectObject(&pen);
	pDC->MoveTo(x0, y0);
	for(int i = 1; i < nDataNum; i ++)
	{
		x = int (m_nXBase + (m_arrData[i] - m_fDataMin) * fScaleX);
		if(x < m_nXBase)
			x = m_nXBase;
		y = int (m_nYBase + i * fScaleY);
		pDC->LineTo(x, y);
	}
    pDC->SelectObject(pOrigPen);
}

void CCurveUnit::SetColumProperty(int nXBase, int nYBase, int nColWidth, int nColHeight)
{
	m_nXBase = nXBase;
	m_nYBase = nYBase;
	m_nColWidth = nColWidth;
	m_nColHeight = nColHeight;
}

int CCurveUnit::GetXBase()
{
	return m_nXBase;
}

int CCurveUnit::GetYBase()
{
	return m_nYBase;	
}

int CCurveUnit::GetColWidth()
{
	return m_nColWidth;
}

int CCurveUnit::GetColHeight()
{
	return m_nColHeight;
}

void CCurveUnit::SetCurveProperty(COLORREF corCurve, int nCurveWidth, int nCurveStyle)
{
	m_corCurve = corCurve;
	m_nCurveWidth = nCurveWidth;
	m_nCurveStyle = nCurveStyle;
}

COLORREF CCurveUnit::GetCurveColor()
{
	return m_corCurve;
}

int CCurveUnit::GetCurveWidth()
{
	return m_nCurveWidth;
}

int CCurveUnit::GetCurveStyle()
{
	return m_nCurveStyle;
}

void CCurveUnit::SetDataProperty(float fStartDep, float fEndDep, float fSampleSpace)
{
	m_fStartDep = fStartDep;
	m_fEndDep = fEndDep;
	m_fSampleSpace = fSampleSpace;
}

float CCurveUnit::GetStartDep()
{
	return m_fStartDep;
}

float CCurveUnit::GetEndDep()
{
	return m_fEndDep;
}

float CCurveUnit::GetSampleSpace()
{
	return m_fSampleSpace;
}

void CCurveUnit::SetDataMaxMin(float fDataMax, float fDataMin)
{
	m_fDataMax = fDataMax;
	m_fDataMin = fDataMin;
}

float CCurveUnit::GetDataMin()
{
	return	m_fDataMin;
}

float CCurveUnit::GetDataMax()
{
	return m_fDataMax;
}

int CCurveUnit::AddDataPoint(float fvalue)
{
	return m_arrData.Add(fvalue);
}

float CCurveUnit::GetDataValue(int nIndex)
{
	return m_arrData[nIndex];
}

int CCurveUnit::GetDataSize()
{
	return m_arrData.GetSize(); 
}


CString CCurveUnit::GetCurveName()
{
	return m_strCurveName;
}

void CCurveUnit::SetCurveName(CString strCurveName)
{
	m_strCurveName = strCurveName;
}

COLORREF CCurveUnit::GetDrawPenColor()
{
	if(m_bSelect)
		return RGB(255, 255, 255);
	else
		return m_corCurve;
}

void CCurveUnit::SetDataValue(int nIndex, float fValue)
{
	m_arrData[nIndex] = fValue;
}

CCurveUnit::operator=(const CCurveUnit& other)
{
	// 如何进行数据的等同????
	m_corCurve = other.m_corCurve;
	m_fDataMax = other.m_fDataMax;
	m_fDataMin = other.m_fDataMin;
	m_fEndDep  = other.m_fEndDep;
	m_fSampleSpace = other.m_fSampleSpace;
	m_fStartDep  = other.m_fStartDep;
	m_nColHeight = other.m_nColHeight;
	m_nColWidth = other.m_nColWidth;
	m_nCurveStyle = other.m_nCurveStyle;
	m_nCurveWidth = other.m_nCurveWidth;
	m_nXBase = other.m_nXBase;
	m_nYBase = other.m_nYBase;
	m_strCurveName = other.m_strCurveName;

	
}

float CCurveUnit::GetMeanValue(int nIndex1, int nIndex2)
{
	if(nIndex1 > nIndex2)
		return 0.0f;
	float fvalue = 0.0f;
	int i;
	for(i = nIndex1; i <= nIndex2; i ++)
	{
		fvalue += m_arrData[i];
	}
	fvalue = fvalue / (nIndex2 - nIndex1);
	return fvalue;
}


void CCurveUnit::SetRoad(CRoadUnit* pRoadUnit)
{
	m_nColHeight = pRoadUnit->GetRoadHeight() - pRoadUnit->GetRoadHeadHeight();
	m_nColWidth = pRoadUnit->GetRoadWidth();
	CPoint point = pRoadUnit->GetOrgPoint();
    m_nXBase = point.x;
	m_nYBase = point.y + pRoadUnit->GetRoadHeadHeight();
}

float CCurveUnit::GetMeanValue(float startDep, float endDep, int nMeanMethod)
{
	if(startDep < m_fStartDep || endDep > m_fEndDep)
		return -99999.0f;
	int nCount = int((endDep - startDep) / m_fSampleSpace + 1);
	float fValue = 0;
	int nIndex = int ((startDep - m_fStartDep) / m_fSampleSpace);
	for(int i = 0; i < nCount; i ++)
	{
		nIndex ++;
		if(nMeanMethod == 0)
			fValue += m_arrData[nIndex];
		else
			fValue += float(log10(m_arrData[nIndex]));
	}
	fValue  = fValue / (float)nCount;
	if(nMeanMethod != 0)
		fValue = float(pow(10, fValue));
	return fValue;
}

float CCurveUnit::GetDepth(int nPosition)
{
	int   nDataNum = m_arrData.GetSize();
	float fScaleY  = float (nDataNum) / m_nColHeight;
	int   nIndex = int (fScaleY * (nPosition - m_nYBase) + 0.5);
	float fDepth = m_fStartDep + nIndex * m_fSampleSpace;
	if(fDepth > m_fEndDep)
		fDepth = m_fEndDep;
	if(fDepth < m_fStartDep)
		fDepth = m_fStartDep;
	return fDepth;
}

int CCurveUnit::GetXPosition(float fValue)
{
	float fScaleX  = (float) m_nColWidth / (m_fDataMax - m_fDataMin);
	int x = int (m_nXBase + (fValue - m_fDataMin) * fScaleX);
	return x;
}

COLORREF CCurveUnit::GetColorWithValue(float fValue)
{
	int nColorValue = int((fValue  -  m_fDataMin) * 255 / (m_fDataMax - m_fDataMin));
	return RGB(nColorValue, 255 - nColorValue, 0);
	
}

void CCurveUnit::CointuationDepth()
{
	float fValue = 0;
	for(int k = 0; k < int(50 / m_fSampleSpace); k ++)
	{
		fValue += m_arrData[k];
	}
	fValue = fValue / ( k + 1);
	
	if(m_fStartDep > 0)
	{
		m_fContDep = 1000 * m_fSampleSpace;
		
		for( int i = 0; i < int((m_fContDep) / m_fSampleSpace); i ++)
		{
			m_arrData.InsertAt(0, fValue);
		}
	}
}

int CCurveUnit::GetColorIndex(float fValue)
{
	int nColorIndex = int((fValue  -  m_fDataMin) * 63 / (m_fDataMax - m_fDataMin));
	
	return nColorIndex;
}

void CCurveUnit::SetColumYBase(int nYBase)
{
	m_nYBase = nYBase;
}

void CCurveUnit::SetColumHeight(int nColHeight)
{
	m_nColHeight = nColHeight;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -