예제 #1
0
 void maximum(const eVector4 &v)
 {
     x = eMax(x, v.x);
     y = eMax(y, v.y);
     z = eMax(y, v.z);
     w = eMax(y, v.w);
 }
예제 #2
0
void eProfilerZone::updateStats()
{
    eArray<eF32> &hist = m_stats.history;

    hist.append(getSelfTimeMs());
    while (hist.size() >= eProfilerZoneStats::MAX_SAMPLES)
        hist.removeAt(0);

    m_stats.max = hist[0];
    m_stats.min = hist[0];
    m_stats.mean = hist[0];

    for (eU32 k=1; k<hist.size(); k++)
    {
        const eF32 v = hist[k];
        m_stats.max = eMax(m_stats.max, v);
        m_stats.min = eMin(m_stats.min, v);
        m_stats.mean += v;
    }

    eASSERT(!hist.isEmpty());
    m_stats.mean /= (eF32)hist.size();

    eF32 var = 0.0f;
    for (eU32 k=1; k<hist.size(); k++)
        var += eSqr(hist[k]-m_stats.mean);

    m_stats.stdDev = (hist.size() > 1 ? eSqrt(var/(eF32)(hist.size()-1)) : 0.0f);
}
예제 #3
0
파일: 2DRaw.cpp 프로젝트: phamquy/ImageProc
//************************************
// Method:    operator-
// FullName:  unary invert operator: element = 255 - element
// Access:    
// Returns:   
// Qualifier: 
// Parameter: 
//************************************
const C2DRaw& C2DRaw::operator-() const
{
	ASSERT(IsValid());
	C2DRaw temp(m_nRows, m_nColums);
	element eMax(ELEMENT_MAX);

	for(int i=0; i<temp.GetNumberOfRow(); i++)
	{
		for(int j=0; j< temp.GetNumberOfCol(); j++)
		{
			temp.SetElementAt(i, j, eMax - GetElementAt(i,j));
		}
	}
	return temp;
}
예제 #4
0
PCPtr getHalo(const ofVec3f& min, const ofVec3f& max, const float& haloSize, const PCPtr& cloudSrc)
{
	PCPtr trimmedCloud (new PC());
	vector<int> indices;
	ofVec3f vMin = min - haloSize;
	ofVec3f vMax = max + haloSize;

	Eigen::Vector4f eMax(vMax.x,vMax.y,vMax.z,1);
	Eigen::Vector4f eMin(vMin.x,vMin.y,vMin.z,1);
	
	pcl::getPointsInBox(*cloudSrc,eMin,eMax,indices);
			
	for(int i = 0; i < indices.size(); i++)
		trimmedCloud->push_back(cloudSrc->at(indices.at(i)));
	return trimmedCloud;
}
예제 #5
0
const eProfilerZone * eProfiler::getThreadZones(eU32 index, eU32 &numZones, eF32 &totalFrameMs, const eChar *&threadName)
{
    eASSERT(index < m_threads.size());

    eScopedLock lock(m_mutex);
    const eProfilerThread *pt = m_threads[index];
    const eProfilerZone *zones = pt->getLastZones(numZones);
    totalFrameMs = 0.0f;
    threadName = pt->getThreadName();
    
    for (eU32 i=0; i<numZones; i++)
        totalFrameMs += zones[i].getSelfTimeMs();

    totalFrameMs = eMax(0.1f, totalFrameMs); // minimum 1 micro-second to avoid division-by-zero
    return zones;
}
예제 #6
0
eBool eLight::activateScissor(const eSize &viewport, const eCamera &cam) const
{
    eRect rect(0, 0, viewport.x, viewport.y);
    const eVector3 viewPos = m_pos*cam.getViewMatrix();

    // negate z because original code was for OpenGL
    // (right-handed coordinate system, but DirectX
    // uses a left-handed one)
    const eVector3 l(viewPos.x, viewPos.y, -viewPos.z);
    const eVector3 ll(l.x*l.x, l.y*l.y, l.z*l.z);
    const eF32 r = m_range;
    const eF32 rr = r*r;
    const eF32 e0 = 1.2f;
    const eF32 e1 = 1.2f*cam.getAspectRatio();

    eF32 d = rr*ll.x-(ll.x+ll.z)*(rr-ll.z);
    if (d >= 0.0f)
    {
        d = eSqrt(d);

        const eF32 nx0 = (r*l.x +d)/(ll.x+ll.z);
        const eF32 nx1 = (r*l.x-d)/(ll.x+ll.z);
        const eF32 nz0 = (r-nx0*l.x)/l.z;
        const eF32 nz1 = (r-nx1*l.x)/l.z;
        const eF32 pz0 = (ll.x+ll.z-rr)/(l.z-(nz0/nx0)*l.x);
        const eF32 pz1 = (ll.x+ll.z-rr)/(l.z-(nz1/nx1)*l.x);

        if (pz0 < 0.0f)
        {
            const eF32 fx = nz0*e0/nx0;
            const eInt ix = eFtoL((fx+1.0f)*(eF32)viewport.x*0.5f);
            const eF32 px = -pz0*nz0/nx0;

            if (px < l.x)
                rect.x0 = eMax(rect.x0, ix);
            else
                rect.x1 = eMin(rect.x1, ix);
        }

        if (pz1 < 0.0f)
        {
            const eF32 fx = nz1*e0/nx1;
            const eInt ix = eFtoL((fx+1.0f)*(eF32)viewport.x*0.5f);
            const eF32 px = -pz1*nz1/nx1;

            if (px < l.x)
                rect.x0 = eMax(rect.x0, ix);
            else
                rect.x1 = eMin(rect.x1, ix);
        }
    }

    d = rr*ll.y-(ll.y+ll.z)*(rr-ll.z);
    if (d >= 0.0f)
    {
        d = eSqrt(d);

        const eF32 ny0 = (r*l.y +d)/(ll.y+ll.z);
        const eF32 ny1 = (r*l.y-d)/(ll.y+ll.z);
        const eF32 nz0 = (r-ny0*l.y)/l.z;
        const eF32 nz1 = (r-ny1*l.y)/l.z;
        const eF32 pz0 = (ll.y+ll.z-rr)/(l.z-(nz0/ny0)*l.y);
        const eF32 pz1 = (ll.y+ll.z-rr)/(l.z-(nz1/ny1)*l.y);

        if (pz0 < 0.0f)
        {
            const eF32 fy = nz0*e1/ny0;
            const eInt iy = eFtoL((fy+1.0f)*(eF32)viewport.y*0.5f);
            const eF32 py = -pz0*nz0/ny0;

            if (py < l.y)
                rect.y0 = eMax(rect.y0, iy);
            else
                rect.y1 = eMin(rect.y1, iy);
        }

        if (pz1 < 0.0f)
        {
            const eF32 fy = nz1*e1/ny1;
            const eInt iy = eFtoL((fy+1.0f)*(eF32)viewport.y*0.5f);
            const eF32 py = -pz1*nz1/ny1;

            if (py < l.y)
                rect.y0 = eMax(rect.y0, iy);
            else
                rect.y1 = eMin(rect.y1, iy);
        }
    }

    // finally check calculated rect and set if it's valid
    const eInt n = rect.getWidth()*rect.getHeight();
    if (n <= 0)
        return eFALSE;

    eRenderState &rs = eGfx->getRenderState();

    if (n == viewport.x*viewport.y || rect.x0 > rect.x1 || rect.y0 > rect.y1)
        rs.scissorTest = eFALSE;
    else
    {
        rs.scissorRect = eRect(rect.x0, viewport.y-rect.y1, rect.x1, viewport.y-rect.y0);
        rs.scissorTest = eTRUE;
    }

    return eTRUE;
}
예제 #7
0
eF32 tfADSR::process(tfADSR::State *state, eU32 len, eF32 a, eF32 d, eF32 s, eF32 r, eF32 slope, eU32 sampleRate)
{
    eF32 attack,decay,sustain,release;
    eF32 scale = 0.00050f * (sampleRate / 44100.0f) * len;

    a = ePow(a, 3);
    d = ePow(d, 3);
    r = ePow(r, 3);

    a = eMax(0.000000001f, a);
    attack = -eLog(a * .94f) * scale;
        
    if (d <= 0)
        decay = -1.0f;
    else
        decay = eLog(d * .94f) * 0.25f * scale;

    sustain = eMax(s, 0.0f);

    r = eMax(r, 0.000000001f);
    release = eLog(r * .94f) * 0.25f * scale;
    
    eF32 volume = state->volume;
    switch (state->state)
    {
        case ADSR_STATE_ATTACK:
            volume += attack;
            if (volume >= 1.0f)
            {
                volume = 1.0f;
                state->state = ADSR_STATE_DECAY;
            }
            break;
        case ADSR_STATE_DECAY:
            {
                eF32 diff = 0.01f + (volume - sustain);
                eF32 range = 1.0f - sustain;
                eF32 pos = diff / range;
                eF32 slope_f = ePow(pos, slope);

                volume += decay * slope_f;

                if (volume <= sustain)
                {
                    volume = sustain;
                    state->state = ADSR_STATE_SUSTAIN;
                }
            }
            break;
        case ADSR_STATE_SUSTAIN:
            if (volume < sustain)
            {
                volume -= decay;
                if (volume > sustain)
                {
                    volume = sustain;
                }
            }
            else if (volume > sustain)
            {
                volume += decay;
                if (volume < sustain)
                {
                    volume = sustain;
                }
            }
            break;
        case ADSR_STATE_RELEASE:
            {
                eF32 slope_f = ePow(volume, slope);

                volume += release * slope_f;

                if (volume <= 0.001f)
                {
                    volume = 0.0f;
                    state->state = ADSR_STATE_FINISHED;
                }
            }
            break;
        case ADSR_STATE_FINISHED:
            break;
    }

    state->volume = volume;

    return volume;
}