float pcl::RangeImageNew::ComputeAngularResolutionWidth(CloudType::ConstPtr cloud)
{
  float total_angle = 0.0f;
  unsigned int valid_angle_counter = 0;
  // Traverse the grid in pairs of a point and the point to the right of it.
  for(unsigned int col = 0; col < cloud->width - 1; ++col) // (width - 1) because there is no point to the right of the last column!
  {
    for(unsigned int row = 0; row < cloud->height; ++row) 
    {
      CloudType::PointType p0 = (*cloud)(col, row);
      CloudType::PointType p1 = (*cloud)(col + 1, row);
      if(IsNan(p0) || IsNan(p1))
        {
        continue;
        }
      else
      {
        total_angle = AngleBetweenPointVectors(p0, p1);
        valid_angle_counter++;
      }
    }
  }
  float average_angle = total_angle/static_cast<float>(valid_angle_counter);
  return average_angle;
}
示例#2
0
void CCalculator::CalculateTwoOperandsFunction(SFunctionData & fnInfo)
{
	double firstOperand = GetValue(fnInfo.firstOperand);
	double secondOperand = GetValue(fnInfo.secondOperand);

	if (!IsNan(firstOperand) && !IsNan(secondOperand))
	{
		double result = std::numeric_limits<double>::quiet_NaN();
		switch (fnInfo.operatorType)
		{
		case Operator::Plus:
			result = firstOperand + secondOperand;
			break;
		case Operator::Slash:
			result = firstOperand / secondOperand;
			break;
		case Operator::Star:
			result = firstOperand * secondOperand;
			break;
		case Operator::Minus:
			result = firstOperand - secondOperand;
			break;
		}

		fnInfo.value = result;
	}
}
示例#3
0
inline void ApplyPower<false>(float * pix, const float * power)
{
    // Note: Set NaNs to 0 to match the SSE path.
    pix[0] = IsNan(pix[0]) ? 0.0f : (pix[0]<0.f ? pix[0] : powf(pix[0], power[0]));
    pix[1] = IsNan(pix[1]) ? 0.0f : (pix[1]<0.f ? pix[1] : powf(pix[1], power[1]));
    pix[2] = IsNan(pix[2]) ? 0.0f : (pix[2]<0.f ? pix[2] : powf(pix[2], power[2]));
}
示例#4
0
void FDrawPointer::draw(Qwt3D::Triple const& pos)
{
    if(IsNan(Pointer->x) || IsNan(Pointer->y)) return;

    if(pos.x == Pointer->x && pos.y == Pointer->y)
    {

        double PtsSize = (((plot->hull().maxVertex - plot->hull().minVertex).length())/plot->hull().maxVertex.length())*10;

        //É preciso salvar o status de tamanho anterior pra não dar erro na projeção de curvas (Isoline projections).
        GLfloat _SizePrevious;
        glGetFloatv(GL_POINT_SIZE, &_SizePrevious);

        glPointSize(PtsSize);
        glEnable(GL_POINT_SMOOTH);
        glColor3d(1, 1, 0); // Yellow

        glBegin(GL_POINTS);
        glVertex3d(pos.x,pos.y,pos.z);
        glEnd();

        //Retomando o status anterior as mudanças.
        glDisable(GL_POINT_SMOOTH);
        glPointSize(_SizePrevious);

    }
}
示例#5
0
// This is the 'final' version of the AlmostEqualUlps function.
// The optional checks are included for completeness, but in many
// cases they are not necessary, or even not desirable.
bool AlmostEqualUlpsFinal(float A, float B, int maxUlps)
{
    // There are several optional checks that you can do, depending
    // on what behavior you want from your floating point comparisons.
    // These checks should not be necessary and they are included
    // mainly for completeness.

#ifdef  INFINITYCHECK
    // If A or B are infinity (positive or negative) then
    // only return true if they are exactly equal to each other -
    // that is, if they are both infinities of the same sign.
    // This check is only needed if you will be generating
    // infinities and you don't want them 'close' to numbers
    // near FLT_MAX.
    if (IsInfinite(A) || IsInfinite(B))
        return A == B;
#endif

#ifdef  NANCHECK
    // If A or B are a NAN, return false. NANs are equal to nothing,
    // not even themselves.
    // This check is only needed if you will be generating NANs
    // and you use a maxUlps greater than 4 million or you want to
    // ensure that a NAN does not equal itself.
    if (IsNan(A) || IsNan(B))
        return false;
#endif

#ifdef  SIGNCHECK
    // After adjusting floats so their representations are lexicographically
    // ordered as twos-complement integers a very small positive number
    // will compare as 'close' to a very small negative number. If this is
    // not desireable, and if you are on a platform that supports
    // subnormals (which is the only place the problem can show up) then
    // you need this check.
    // The check for A == B is because zero and negative zero have different
    // signs but are equal to each other.
    if (Sign(A) != Sign(B))
        return A == B;
#endif

    int aInt = *(int*)&A;
    // Make aInt lexicographically ordered as a twos-complement int
    if (aInt < 0)
        aInt = 0x80000000 - aInt;
    // Make bInt lexicographically ordered as a twos-complement int
    int bInt = *(int*)&B;
    if (bInt < 0)
        bInt = 0x80000000 - bInt;

    // Now we can compare aInt and bInt to find out how far apart A and B
    // are.
    int intDiff = abs(aInt - bInt);
    if (intDiff <= maxUlps)
        return true;
    return false;
}
  // Calculate high pressure rate coefficients at current T.
  void IrreversibleUnimolecularReaction::HighPresRateCoeffs(vector<double> *pCoeffs) {

    vector<double> rctGrainDOS, rctGrainEne;
    m_rct1->getDOS().getGrainDensityOfStates(rctGrainDOS);
    m_rct1->getDOS().getGrainEnergies(rctGrainEne);
    const size_t MaximumGrain = (getEnv().MaxGrn-get_fluxFirstNonZeroIdx());
    const double beta = getEnv().beta;

    double kf(0.0);
    for(size_t i(0); i < MaximumGrain; ++i)
      kf += m_GrainKfmc[i] * exp( log(rctGrainDOS[i]) - beta * rctGrainEne[i]);

    const double rctprtfn = canonicalPartitionFunction(rctGrainDOS, rctGrainEne, beta);
    //printf("temperature: %f\ttsprtfn: %f\trctprtfn: %f\n",1/beta/boltzmann_RCpK, kf, rctprtfn);
	ctest << "temperature, tsprtfn, rctprtfn:    " << 1.0/beta/boltzmann_RCpK << "    " << kf << "    " << rctprtfn << endl;
	kf /= rctprtfn;
	

    if (pCoeffs) {
      pCoeffs->push_back(kf) ;
      const double Keq = calcEquilibriumConstant() ;
      if(!IsNan(Keq)) {
        pCoeffs->push_back(kf/Keq) ;
        pCoeffs->push_back(Keq) ;
      }
    } else {
      const double temperature = 1./(boltzmann_RCpK * beta);
      ctest << endl << "Canonical pseudo first order forward rate constant of irreversible reaction "
				<< getName() << " = " << kf << " s-1 (" << temperature << " K)" << endl;
    }
  }
示例#7
0
Color Color::FromString(const char *str)
{
    assume(str);
    if (!str)
        return Color();
    MATH_SKIP_WORD(str, "Color");
    MATH_SKIP_WORD(str, "(");
    Color c;
    // Use DeserializeFloat() instead of duplicating its code but comply 
    // with the old strtod behavior where 0 is used on conversion failure.
    c.r = DeserializeFloat(str, &str); if (IsNan(c.r)) c.r = 0.f;
    c.g = DeserializeFloat(str, &str); if (IsNan(c.g)) c.g = 0.f;
    c.b = DeserializeFloat(str, &str); if (IsNan(c.b)) c.b = 0.f;
    if (str && *str != '\0') // alpha optional
    {
        c.a = DeserializeFloat(str, &str);
        if (IsNan(c.a)) c.a = 01.f;
    }
    return c;
}
float pcl::RangeImageNew::ComputeMaxAngleHeight(CloudType::ConstPtr cloud)
{
  // Compute the average of the angle between extreme points
  float total_angle = 0.0f;
  unsigned int valid_angle_counter = 0;
  for(unsigned int col = 0; col < cloud->width; ++col)
  {
    CloudType::PointType p0 = (*cloud)(col, 0);
    CloudType::PointType p1 = (*cloud)(col, cloud->height - 1);
    if(IsNan(p0) || IsNan(p1))
      {
      continue;
      }
    else
    {
      total_angle = AngleBetweenPointVectors(p0, p1);
      valid_angle_counter++;
    }
  }
  float average_angle = total_angle/static_cast<float>(valid_angle_counter);
  return average_angle;
}
示例#9
0
bool AABB::IsDegenerate() const
{
#ifdef _MSC_VER
	// MSVC generates code that assumes nans can't be present - add an explicit check for that case.
	return IsNan(minPoint.x) || IsNan(minPoint.y) || IsNan(minPoint.z) ||
		IsNan(maxPoint.x) || IsNan(maxPoint.y) || IsNan(maxPoint.z) ||
		!(minPoint.x < maxPoint.x && minPoint.y < maxPoint.y && minPoint.z < maxPoint.z);
#else
	return !(minPoint.x < maxPoint.x && minPoint.y < maxPoint.y && minPoint.z < maxPoint.z);
#endif
}
示例#10
0
char *SerializeFloat(float f, char *dstStr)
{
	if (!IsNan(f))
	{
#ifdef MATH_WITH_GRISU3
		int numChars = dtoa_grisu3((double)f, dstStr);
		return dstStr + numChars;
#else
		return dstStr + sprintf(dstStr, "%.17g", f);
#endif
	}
	else
	{
		u32 u = ReinterpretAsU32(f);
		int numChars = sprintf(dstStr, "NaN(%8X)", (unsigned int)u);
		return dstStr + numChars;
	}
}
static inline void BinarizeFloatFeature(int featureIdx,
                                        const TDocumentStorage& docStorage,
                                        const TDocSelector& docSelector,
                                        const TVector<float>& borders,
                                        ENanMode nanMode,
                                        NPar::TLocalExecutor& localExecutor,
                                        int floatFeatureIdx,
                                        TAllFeatures* features,
                                        bool* seenNans) {
    size_t docCount = docSelector.GetDocCount();
    const TVector<float>& src = docStorage.Factors[featureIdx];
    TVector<ui8>& hist = features->FloatHistograms[floatFeatureIdx];

    hist.resize(docCount);

    ui8* histData = hist.data();
    const float* featureBorderData = borders.data();
    const int featureBorderSize = borders.ysize();

    localExecutor.ExecRange([&] (int i) {
        const auto& featureVal = src[docSelector(i)];
        if (IsNan(featureVal)) {
            *seenNans = true;
            histData[i] = nanMode == ENanMode::Min ? 0 : featureBorderSize;
        } else {
            int j = 0;
            while (j < featureBorderSize && featureVal > featureBorderData[j]) {
                ++histData[i];
                ++j;
            }
        //    histData[i] = LowerBound(featureBorderData, featureBorderData + featureBorderSize, featureVal) - featureBorderData;
        }
    }
    , NPar::TLocalExecutor::TExecRangeParams(0, docCount).SetBlockSize(1000)
    , NPar::TLocalExecutor::WAIT_COMPLETE);
}
示例#12
0
void CXTPMarkupGrid::SetFinalSize(CXTPMarkupDefinitionCollection* pDefinitions, int finalSize)
{
	CXTPMarkupDefinitionBase** pTempDefinitions = new CXTPMarkupDefinitionBase*[pDefinitions->GetCount()];

	int length = 0;
	int num2 = pDefinitions->GetCount();
	double num3 = 0;
	for (int i = 0; i < pDefinitions->GetCount(); i++)
	{
		CXTPMarkupDefinitionBase* pDefinition = pDefinitions->GetItem(i);

		if (pDefinition->GetUserSize()->IsStar())
		{
			pTempDefinitions[length++] = pDefinition;
			double d = pDefinition->GetUserSize()->GetValue();
			if (d == 0)
			{
				pDefinition->m_nMeasureSize = 0;
				pDefinition->m_nSizeCache = 0;
			}
			else
			{
				pDefinition->m_nMeasureSize = d;
				int num6 = IsNan(pDefinition->GetUserMaxSize()) ? pDefinition->m_nMinSize : max(pDefinition->m_nMinSize, pDefinition->GetUserMaxSize());
				pDefinition->m_nSizeCache = (double)num6 / (double)d;
			}
		}
		else
		{
			pTempDefinitions[--num2] = pDefinition;
			double nMinSizeForArrange = 0;
			switch (pDefinition->GetUserSize()->GetUnitType())
			{
			case CXTPMarkupGridLength::unitTypeAuto:
				nMinSizeForArrange = pDefinition->m_nMinSize;
				break;

			case CXTPMarkupGridLength::unitTypePixel:
				nMinSizeForArrange = pDefinition->GetUserSize()->GetValue();
				break;
			}
			int nUserMaxSize = pDefinition->GetUserMaxSize();
			pDefinition->m_nSizeCache = max(pDefinition->m_nMinSize, min(nMinSizeForArrange, nUserMaxSize));
			num3 += pDefinition->m_nSizeCache;
		}
	}
	if (length > 0)
	{
		qsort(pTempDefinitions, length, sizeof(CXTPMarkupDefinitionBase*), StarDistributionOrderComparer);

		double num9 = 0;
		int nIndex;
		for (nIndex = length - 1; nIndex >= 0; nIndex--)
		{
			num9 += pTempDefinitions[nIndex]->m_nMeasureSize;
			pTempDefinitions[nIndex]->m_nSizeCache = num9;
		}
		for (nIndex = 0; nIndex < length; nIndex++)
		{
			CXTPMarkupDefinitionBase* pDefinition = pTempDefinitions[nIndex];

			int num11;
			double nMeasureSize = pDefinition->m_nMeasureSize;
			if (nMeasureSize == 0)
			{
				num11 = pDefinition->m_nMinSize;
			}
			else
			{
				double num13 = max((double) (finalSize - num3), (double) 0) * (nMeasureSize / pDefinition->m_nSizeCache);
				num11 = min((int)num13, pDefinition->GetUserMaxSize());
				num11 = max(pDefinition->m_nMinSize, num11);
			}
			pDefinition->m_nSizeCache = num11;
			num3 += num11;
		}
	}
	if (num3 > finalSize)
	{
		qsort(pTempDefinitions, length, sizeof(CXTPMarkupDefinitionBase*), DistributionOrderComparer);

		double num14 = finalSize - num3;
		for (int k = 0; k < pDefinitions->GetCount(); k++)
		{
			double num16 = pTempDefinitions[k]->m_nSizeCache + (num14 / ((double) (pDefinitions->GetCount() - k)));
			num16 = min(max(num16, pTempDefinitions[k]->m_nMinSize), pTempDefinitions[k]->m_nSizeCache);
			num14 -= num16 - pTempDefinitions[k]->m_nSizeCache;
			pTempDefinitions[k]->m_nSizeCache = num16;
		}
	}
	pDefinitions->GetItem(0)->m_nFinalOffset = 0;
	for (int j = 1; j < pDefinitions->GetCount(); j++)
	{
		pDefinitions->GetItem(j)->m_nFinalOffset = pDefinitions->GetItem(j - 1)->m_nFinalOffset + (int)pDefinitions->GetItem(j - 1)->m_nSizeCache;
	}

	delete[] pTempDefinitions;
}
示例#13
0
static void OutputConstantUnion(TInfoSink& out, const TIntermTyped* node, const TConstUnionArray& constUnion, int depth)
{
    int size = node->getType().computeNumComponents();

    for (int i = 0; i < size; i++) {
        OutputTreeText(out, node, depth);
        switch (constUnion[i].getType()) {
        case EbtBool:
            if (constUnion[i].getBConst())
                out.debug << "true";
            else
                out.debug << "false";

            out.debug << " (" << "const bool" << ")";

            out.debug << "\n";
            break;
        case EbtFloat:
        case EbtDouble:
#ifdef AMD_EXTENSIONS
        case EbtFloat16:
#endif
            {
                const double value = constUnion[i].getDConst();
                // Print infinities and NaNs in a portable way.
                if (IsInfinity(value)) {
                    if (value < 0)
                        out.debug << "-1.#INF\n";
                    else
                        out.debug << "+1.#INF\n";
                } else if (IsNan(value))
                    out.debug << "1.#IND\n";
                else {
                    const int maxSize = 300;
                    char buf[maxSize];
                    snprintf(buf, maxSize, "%f", value);

                    out.debug << buf << "\n";
                }
            }
            break;
        case EbtInt:
            {
                const int maxSize = 300;
                char buf[maxSize];
                snprintf(buf, maxSize, "%d (%s)", constUnion[i].getIConst(), "const int");

                out.debug << buf << "\n";
            }
            break;
        case EbtUint:
            {
                const int maxSize = 300;
                char buf[maxSize];
                snprintf(buf, maxSize, "%u (%s)", constUnion[i].getUConst(), "const uint");

                out.debug << buf << "\n";
            }
            break;
        case EbtInt64:
            {
                const int maxSize = 300;
                char buf[maxSize];
                snprintf(buf, maxSize, "%lld (%s)", constUnion[i].getI64Const(), "const int64_t");

                out.debug << buf << "\n";
            }
            break;
        case EbtUint64:
            {
                const int maxSize = 300;
                char buf[maxSize];
                snprintf(buf, maxSize, "%llu (%s)", constUnion[i].getU64Const(), "const uint64_t");

                out.debug << buf << "\n";
            }
            break;
        default:
            out.info.message(EPrefixInternalError, "Unknown constant", node->getLoc());
            break;
        }
    }
}
示例#14
0
bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
{
    CBotStack* pStk1 = pStack->AddStack(this);  // adds an item to the stack
                                                // or return in case of recovery
//  if ( pStk1 == EOX ) return true;

    // according to recovery, it may be in one of two states

    if ( pStk1->GetState() == 0 )                   // first state, evaluates the left operand
    {
        if (!m_leftop->Execute(pStk1) ) return false;   // interrupted here?

        // for OR and AND logic does not evaluate the second expression if not necessary
        if ( (GetTokenType() == ID_LOG_AND || GetTokenType() == ID_TXT_AND ) && pStk1->GetVal() == false )
        {
            CBotVar*    res = CBotVar::Create("", CBotTypBoolean);
            res->SetValInt(false);
            pStk1->SetVar(res);
            return pStack->Return(pStk1);               // transmits the result
        }
        if ( (GetTokenType() == ID_LOG_OR||GetTokenType() == ID_TXT_OR) && pStk1->GetVal() == true )
        {
            CBotVar*    res = CBotVar::Create("", CBotTypBoolean);
            res->SetValInt(true);
            pStk1->SetVar(res);
            return pStack->Return(pStk1);               // transmits the result
        }

        // passes to the next step
        pStk1->SetState(1);         // ready for further
    }


    // requires a little more stack to avoid touching the result
    // of which is left on the stack, precisely

    CBotStack* pStk2 = pStk1->AddStack();               // adds an item to the stack
                                                        // or return in case of recovery

    // 2e état, évalue l'opérande de droite
    if ( pStk2->GetState() == 0 )
    {
        if ( !m_rightop->Execute(pStk2) ) return false;     // interrupted here?
        pStk2->IncState();
    }

    assert(pStk1->GetVar() != nullptr && pStk2->GetVar() != nullptr);
    CBotTypResult       type1 = pStk1->GetVar()->GetTypResult();      // what kind of results?
    CBotTypResult       type2 = pStk2->GetVar()->GetTypResult();

    CBotStack* pStk3 = pStk2->AddStack(this);               // adds an item to the stack
    if ( pStk3->IfStep() ) return false;                    // shows the operation if step by step

    // creates a temporary variable to put the result
    // what kind of result?
    int TypeRes = std::max(type1.GetType(), type2.GetType());

    // see "any type convertible chain" in compile method
    if ( GetTokenType() == ID_ADD &&
        (type1.Eq(CBotTypString) || type2.Eq(CBotTypString)) )
    {
        TypeRes = CBotTypString;
    }

    switch ( GetTokenType() )
    {
    case ID_LOG_OR:
    case ID_LOG_AND:
    case ID_TXT_OR:
    case ID_TXT_AND:
    case ID_EQ:
    case ID_NE:
    case ID_HI:
    case ID_LO:
    case ID_HS:
    case ID_LS:
        TypeRes = CBotTypBoolean;
        break;
    case ID_DIV:
        TypeRes = std::max(TypeRes, static_cast<int>(CBotTypFloat));
    }

    // creates a variable for the result
    CBotVar*    result = CBotVar::Create("", TypeRes);

    // get left and right operands
    CBotVar*    left  = pStk1->GetVar();
    CBotVar*    right = pStk2->GetVar();

    // creates a variable to perform the calculation in the appropriate type
    if ( TypeRes != CBotTypString )                                     // keep string conversion
    {
        TypeRes = std::max(type1.GetType(), type2.GetType());
    }
    else
    {
        left->Update(nullptr);
        right->Update(nullptr);
    }

    if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) )
    {
        TypeRes = CBotTypString;
    }

    CBotVar*    temp;

    if ( TypeRes == CBotTypPointer ) TypeRes = CBotTypNullPointer;
    if ( TypeRes == CBotTypClass ) temp = CBotVar::Create("", CBotTypResult(CBotTypIntrinsic, type1.GetClass() ) );
    else                           temp = CBotVar::Create("", TypeRes );

    CBotError err = CBotNoErr;
    // is a operation according to request

    switch (GetTokenType())
    {
    case ID_ADD:
        if ( !IsNan(left, right, &err) )    result->Add(left , right);      // addition
        break;
    case ID_SUB:
        if ( !IsNan(left, right, &err) )    result->Sub(left , right);      // substraction
        break;
    case ID_MUL:
        if ( !IsNan(left, right, &err) )    result->Mul(left , right);      // multiplies
        break;
    case ID_POWER:
        if ( !IsNan(left, right, &err) )    result->Power(left , right);    // power
        break;
    case ID_DIV:
        if ( !IsNan(left, right, &err) )    err = result->Div(left , right);// division
        break;
    case ID_MODULO:
        if ( !IsNan(left, right, &err) )    err = result->Modulo(left , right);// remainder of division
        break;
    case ID_LO:
        if ( !IsNan(left, right, &err) )
            result->SetValInt(temp->Lo(left , right));  // lower
        break;
    case ID_HI:
        if ( !IsNan(left, right, &err) )
            result->SetValInt(temp->Hi(left , right));  // top
        break;
    case ID_LS:
        if ( !IsNan(left, right, &err) )
            result->SetValInt(temp->Ls(left , right));  // less than or equal
        break;
    case ID_HS:
        if ( !IsNan(left, right, &err) )
            result->SetValInt(temp->Hs(left , right));  // greater than or equal
        break;
    case ID_EQ:
        if ( IsNan(left, right) )
            result->SetValInt(left->GetInit() ==  right->GetInit()) ;
        else
            result->SetValInt(temp->Eq(left , right));  // equal
        break;
    case ID_NE:
        if ( IsNan(left, right) )
             result->SetValInt(left ->GetInit() !=  right->GetInit()) ;
        else
            result->SetValInt(temp->Ne(left , right));  // different
        break;
    case ID_TXT_AND:
    case ID_LOG_AND:
    case ID_AND:
        if ( !IsNan(left, right, &err) )    result->And(left , right);      // AND
        break;
    case ID_TXT_OR:
    case ID_LOG_OR:
    case ID_OR:
        if ( !IsNan(left, right, &err) )    result->Or(left , right);       // OR
        break;
    case ID_XOR:
        if ( !IsNan(left, right, &err) )    result->XOr(left , right);      // exclusive OR
        break;
    case ID_ASR:
        if ( !IsNan(left, right, &err) )    result->ASR(left , right);
        break;
    case ID_SR:
        if ( !IsNan(left, right, &err) )    result->SR(left , right);
        break;
    case ID_SL:
        if ( !IsNan(left, right, &err) )    result->SL(left , right);
        break;
    default:
        assert(0);
    }
    delete temp;

    pStk2->SetVar(result);                      // puts the result on the stack
    if ( err ) pStk2->SetError(err, &m_token);  // and the possible error (division by zero)

//  pStk1->Return(pStk2);                       // releases the stack
    return pStack->Return(pStk2);               // transmits the result
}
示例#15
0
void CXTPMarkupGrid::ResolveStar(CXTPMarkupDefinitionCollection* pDefinitions, double availableSize)
{
	CXTPMarkupDefinitionBase** pTempDefinitions = new CXTPMarkupDefinitionBase*[pDefinitions->GetCount()];

	int length = 0;
	double num2 = 0;

	for (int i = 0; i < pDefinitions->GetCount(); i++)
	{
		CXTPMarkupDefinitionBase* pDefinition = pDefinitions->GetItem(i);

		switch (pDefinition->m_nSizeType)
		{
		case sizeTypePixel:
			num2 += pDefinition->m_nMeasureSize;
			continue;

		case sizeTypeAuto:
			num2 +=  pDefinition->m_nMinSize;
			continue;

		case sizeTypeStar:
			{
				pTempDefinitions[length++] = pDefinition;
				double num4 = pDefinition->GetUserSize()->GetValue();
				if (num4 != 0)
				{
					pDefinition->m_nMeasureSize = num4;
					double num5 = IsNan(pDefinition->GetUserMaxSize()) ? pDefinition->m_nMinSize : max(pDefinition->m_nMinSize, pDefinition->GetUserMaxSize());
					pDefinition->m_nSizeCache = num5 / num4;
				}
				else
				{
					pDefinition->m_nMeasureSize = 0;
					pDefinition->m_nSizeCache = 0;
				}
				continue;
			}
		}
	}
	if (length > 0)
	{
		qsort(pTempDefinitions, length, sizeof(CXTPMarkupDefinitionBase*), StarDistributionOrderComparer);

		int nIndex;
		double num6 = 0;
		for (nIndex = length - 1; nIndex >= 0; nIndex--)
		{
			num6 += pTempDefinitions[nIndex]->m_nMeasureSize;
			pTempDefinitions[nIndex]->m_nSizeCache = num6;
		}

		for (nIndex = 0; nIndex < length; nIndex++)
		{
			CXTPMarkupDefinitionBase* pDefinition = pTempDefinitions[nIndex];

			int nMinSize;
			double nMeasureSize = pDefinition->m_nMeasureSize;
			if (nMeasureSize == 0)
			{
				nMinSize = pDefinition->m_nMinSize;
			}
			else
			{
				int num10 = (int)(max((double) (availableSize - num2), (double) 0) * (nMeasureSize / pDefinition->m_nSizeCache));
				nMinSize = min(num10, pDefinition->GetUserMaxSize());
				nMinSize = max(pDefinition->m_nMinSize, nMinSize);
			}
			pDefinition->m_nMeasureSize = nMinSize;
			num2 += nMinSize;
		}
	}

	delete[] pTempDefinitions;
}
示例#16
0
void CXTPMarkupGrid::EnsureMinSizeInDefinitionRange(CXTPMarkupDefinitionCollection* pDefinitions, int start, int count, int requestedSize)
{
	if (requestedSize == 0)
		return;

	CXTPMarkupDefinitionBase** pTempDefinitions = new CXTPMarkupDefinitionBase*[pDefinitions->GetCount()];

	int num = start + count;
	int nCountAuto = 0;
	double dTotalMinSize = 0;
	double dTotalPreferedSize = 0;
	double dTotalMaxSize = 0;
	double dMaxSize = 0;

	for (int i = start; i < num; i++)
	{
		CXTPMarkupDefinitionBase* pDefinition = pDefinitions->GetItem(i);
		double minSize = pDefinition->m_nMinSize;
		double preferredSize = pDefinition->GetPreferredSize();
		double maxSize = IsNan(pDefinition->GetUserMaxSize()) ? minSize : max(minSize, pDefinition->GetUserMaxSize());

		dTotalMinSize += minSize;
		dTotalPreferedSize += preferredSize;
		dTotalMaxSize += maxSize;
		pDefinition->m_nSizeCache = maxSize;
		if (dMaxSize < maxSize)
		{
			dMaxSize = maxSize;
		}
		if (pDefinition->GetUserSize()->IsAuto())
		{
			nCountAuto++;
		}
		pTempDefinitions[i - start] = pDefinition;
	}

	if (requestedSize > dTotalMinSize)
	{
		if (requestedSize <= dTotalPreferedSize)
		{
			qsort(pTempDefinitions, count, sizeof(CXTPMarkupDefinitionBase*), SpanPreferredDistributionOrderComparer);

			int index = 0;
			double d = requestedSize;
			while (index < nCountAuto)
			{
				d -= pTempDefinitions[index]->m_nMinSize;
				index++;
			}
			while (index < count)
			{
				double a = min(d / ((double) (count - index)), pTempDefinitions[index]->GetPreferredSize());
				if (a > pTempDefinitions[index]->m_nMinSize)
				{
					pTempDefinitions[index]->UpdateMinSize((int)a);
				}
				d -= a;
				index++;
			}
		}
		else if (requestedSize <= dTotalMaxSize)
		{
			qsort(pTempDefinitions, count, sizeof(CXTPMarkupDefinitionBase*), SpanMaxDistributionOrderComparer);
			int n = 0;
			double d = requestedSize - dTotalPreferedSize;
			while (n < (count - nCountAuto))
			{
				double num16 = pTempDefinitions[n]->GetPreferredSize();
				double num17 = num16 + (d / ((double) ((count - nCountAuto) - n)));
				pTempDefinitions[n]->UpdateMinSize((int)min(num17, pTempDefinitions[n]->m_nSizeCache));
				d -= pTempDefinitions[n]->m_nMinSize - num16;
				n++;
			}
			while (n < count)
			{
				double num18 = pTempDefinitions[n]->m_nMinSize;
				double num19 = num18 + (d / ((double) (count - n)));
				pTempDefinitions[n]->UpdateMinSize((int)(min(num19, pTempDefinitions[n]->m_nSizeCache)));
				d -= pTempDefinitions[n]->m_nMinSize - num18;
				n++;
			}
		}
		else
		{
			double dAverage = (double)requestedSize / ((double) count);
			if (dAverage < dMaxSize)
			{
				double num21 = (dMaxSize * count) - dTotalMaxSize;
				double num22 = requestedSize - dTotalMaxSize;
				for (int j = 0; j < count; j++)
				{
					double num24 = ((dMaxSize - pTempDefinitions[j]->m_nSizeCache) * num22) / num21;
					pTempDefinitions[j]->UpdateMinSize(int(pTempDefinitions[j]->m_nSizeCache + num24));
				}
			}
			else
			{
				for (int k = 0; k < count; k++)
				{
					pTempDefinitions[k]->UpdateMinSize((int)dAverage);
				}
			}
		}
	}

	delete[] pTempDefinitions;
}
示例#17
0
// Calculate Standard Deviation for the values
void MgFeatureNumericFunctions::GetStandardDeviationCategories( VECTOR &values, int numCats,
                                                                double dataMin, double dataMax,
                                                                VECTOR &distValues)
{
    // Expected categories should be more than zero
    if (numCats <= 0)
    {
        STRING message = MgServerFeatureUtil::GetMessage(L"MgInvalidComputedProperty");

        MgStringCollection arguments;
        arguments.Add(message);
        throw new MgFeatureServiceException(L"MgServerSelectFeatures.GetEqualCategories", __LINE__, __WFILE__, &arguments, L"", NULL);
    }

    // collect information about the data values
    double min = DoubleMaxValue;
    double max = -DoubleMaxValue;
    double mean = 0;

    int cnt = (int)values.size();
    if (cnt <= 0) { return; } // Nothing to do, we just send back Property Definition to clients from reader

    for (int i=0; i < cnt; i++)
    {
        double val = values[i];

        if (val > max)
            max = val;
        if (val < min)
            min = val;
        mean += val;
    }

    // expand min and max a little to account for numerical instability
    double delta = 0.0001 * (max - min);
    min -= delta;
    max += delta;

    // compute the mean, variance and standard deviation
    double count = (double)cnt;  // (guaranteed to be > 0)
    mean /= count;
    double variance = 0;

    for (int i=0; i < cnt; i++)
    {
        double val = values[i];
        variance += (val - mean) * (val - mean);
    }

    double deviation = sqrt(variance / count);

    // fill in the middle category/categories
    double* cats = new double[numCats+1];
    int midCat, highMidCat;
    if (numCats % 2 == 0)
    {
        midCat = numCats / 2;
        highMidCat = midCat;
        cats[midCat] = mean;
    }
    else
    {
        midCat = (numCats - 1) / 2;
        highMidCat = midCat + 1;
        cats[midCat] = mean - 0.5 * deviation;
        cats[highMidCat] = mean + 0.5 * deviation;
    }

    // fill in the other categories
    for (int i=midCat-1; i>=0; i--)
        cats[i] = cats[i+1] - deviation;

    for (int i=highMidCat; i<=numCats; i++)
        cats[i] = cats[i-1] + deviation;

    // if the data method specifies strict a strict min and/or max, use them
    if (!IsInf(dataMin) && !IsNan(dataMin) && (dataMin != -DoubleMaxValue))
        min = dataMin;
    if (!IsInf(dataMax) && !IsNan(dataMax) && (dataMax != DoubleMaxValue))
        max = dataMax;

    // flatten/clip any categories that extend beyond the min/max range
    for (int i=0; i<=numCats; i++)
    {
        if (cats[i] < min)
            cats[i] = min;
        else if (cats[i] > max)
            cats[i] = max;
    }

    for (int kk = 0; kk < numCats+1; kk++)
    {
        distValues.push_back(cats[kk]);
    }

    delete[] cats; // Delete the memory allocated before
}
示例#18
0
//****************************************************************
bool OpSort::ProcessVec(std::vector<OBBase*>& vec)
{
  // Make a vector containing both the OBBase* and the descriptor value and the sort it
  if(!IsNan(_pDesc->Predict(vec[0], &_pDescOption)))
  {
    //a numerical descriptor
    //Copy into a pair vector
    std::vector<std::pair<OBBase*,double> > valvec;
    valvec.reserve(vec.size());
    std::vector<OBBase*>::iterator iter;
    for(iter=vec.begin();iter!=vec.end();++iter)
      valvec.push_back(std::make_pair<OBBase*,double>(*iter, _pDesc->Predict(*iter, &_pDescOption)));

    //Sort
    std::sort(valvec.begin(),valvec.end(), Order<double>(_pDesc, _rev));

    //Copy back
    std::vector<std::pair<OBBase*,double> >::iterator valiter;
    iter=vec.begin();
    for(valiter=valvec.begin();valiter!=valvec.end();++valiter, ++iter)
    {
      *iter = valiter->first;
      if(_addDescToTitle)
      {
        std::stringstream ss;
        ss << (*iter)->GetTitle() << ' ' << valiter->second;
        (*iter)->SetTitle(ss.str().c_str());
      }
    }
  }
  else
  {
    //a string descriptor
    //Copy into a pair vector
    std::vector<std::pair<OBBase*,std::string> > valvec;
    valvec.reserve(vec.size());
    std::vector<OBBase*>::iterator iter;
    std::string s;
    for(iter=vec.begin();iter!=vec.end();++iter)
    {
      _pDesc->GetStringValue(*iter, s, &_pDescOption);
      valvec.push_back(std::make_pair<OBBase*,std::string>(*iter, s));
    }

    //Sort
    std::sort(valvec.begin(),valvec.end(), Order<std::string>(_pDesc, _rev));

    //Copy back
    std::vector<std::pair<OBBase*,std::string> >::iterator valiter;
    iter=vec.begin();
    for(valiter=valvec.begin();valiter!=valvec.end();++valiter, ++iter)
    {
      *iter = valiter->first;
      if(_addDescToTitle)
      {
        std::stringstream ss;
        ss << (*iter)->GetTitle() << ' ' << valiter->second;
        (*iter)->SetTitle(ss.str().c_str());
      }
    }
  }

  return true;
}