bool URPGAttributeComponent::Compare(FName AttributeA, FName AttributeB)
{
	if (GetNumericValue(AttributeA) > GetNumericValue(AttributeB))
		return true;

	return false;
}
void URPGAttributeComponent::ModifyAttribute(FModdableAttributes AttributeMod, TEnumAsByte<EAttributeOperation> OperationType)
{
	float AttributeValue = 0;
	AttributeValue = GetNumericValue(AttributeMod.AttributeName);

	switch (OperationType)
	{
	case EAttributeOperation::Attribute_Add:
		AttributeValue += AttributeMod.ModValue;
		SetNumericValue(AttributeValue, AttributeMod.AttributeName);
		return;
	case EAttributeOperation::Attribute_Subtract:
		AttributeValue -= AttributeMod.ModValue;
		SetNumericValue(AttributeValue, AttributeMod.AttributeName);
		return;
	case EAttributeOperation::Attribute_Multiply:
		AttributeValue *= AttributeMod.ModValue;
		SetNumericValue(AttributeValue, AttributeMod.AttributeName);
		return;
	case EAttributeOperation::Attribute_Divide:
		AttributeValue = (AttributeValue / AttributeMod.ModValue);
		SetNumericValue(AttributeValue, AttributeMod.AttributeName);
		return;
	case EAttributeOperation::Attribute_Set:
		AttributeValue = AttributeMod.ModValue;
		SetNumericValue(AttributeValue, AttributeMod.AttributeName);
		return;
	default:
		return;
	}
}
void URPGAttributeComponent::ChangeAttribute(FName AttributeName, float ModValue, TEnumAsByte<EAttributeOperation> OperationType)
{
	float AttributeValue = GetNumericValue(AttributeName);
	switch (OperationType)
	{
	case EAttributeOperation::Attribute_Add:
		AttributeValue += ModValue;
		SetNumericValue(AttributeValue, AttributeName);
		return;
	case EAttributeOperation::Attribute_Subtract:
		AttributeValue -= ModValue;
		SetNumericValue(AttributeValue, AttributeName);
		return;
	case EAttributeOperation::Attribute_Multiply:
		AttributeValue *= ModValue;
		SetNumericValue(AttributeValue, AttributeName);
		return;
	case EAttributeOperation::Attribute_Divide:
		AttributeValue = (AttributeValue / ModValue);
		SetNumericValue(AttributeValue, AttributeName);
		return;
	case EAttributeOperation::Attribute_Set:
		AttributeValue = ModValue;
		SetNumericValue(AttributeValue, AttributeName);
		return;
	default:
		return;
	}
}
bool URPGAttributeComponent::IsEqual(FName AttributeName, float EqualValue)
{
	float tempValue = GetNumericValue(AttributeName);
	if (tempValue == EqualValue)
	{
		return true;
	}
	return false;
}
bool URPGAttributeComponent::IsSmaller(FName AttributeName, float SmallerThan)
{
	float tempValue = GetNumericValue(AttributeName);
	if (tempValue > SmallerThan)
	{
		return false;
	}
	return true;
}
Exemplo n.º 6
0
 bool OptionsList::SetNumericValueIfUnset(const std::string& tag,
     Number value,
     bool allow_clobber, /* = true */
     bool dont_print /* = false */)
 {
   Number val;
   bool found = GetNumericValue(tag, val, "");
   if (!found) {
     return SetNumericValue(tag, value, allow_clobber, dont_print);
   }
   return true;
 }
float URPGAttributeComponent::AttributeOperation(FName AttributeName, float Value, TEnumAsByte<EAttributeOperation> OperationType)
{

	float AttributeValue = GetNumericValue(AttributeName);

	switch (OperationType)
	{
	case EAttributeOperation::Attribute_Add:
		return AttributeValue += Value;
	case EAttributeOperation::Attribute_Subtract:
		return AttributeValue -= Value;
	case EAttributeOperation::Attribute_Multiply:
		return AttributeValue *= Value;
	case EAttributeOperation::Attribute_Divide:
		return AttributeValue /= Value;
	case EAttributeOperation::Attribute_Set:
		return AttributeValue = Value;
	default:
		return 0;
	}
}
void URPGAttributeComponent::ModifyAttributeList(TArray<FModdableAttributes> Attributes, TEnumAsByte<EAttributeOperation> OperationType)
{
	if (Attributes.Num() > 0)
	{
		for (int32 Index = 0; Index < Attributes.Num(); Index++)
		{
			float AttributeValue = 0;
			AttributeValue = GetNumericValue(Attributes[Index].AttributeName);

			switch (OperationType)
			{
			case EAttributeOperation::Attribute_Add:
				AttributeValue += Attributes[Index].ModValue;
				SetNumericValue(AttributeValue, Attributes[Index].AttributeName);
				break;
			case EAttributeOperation::Attribute_Subtract:
				AttributeValue -= Attributes[Index].ModValue;
				SetNumericValue(AttributeValue, Attributes[Index].AttributeName);
				break;
			case EAttributeOperation::Attribute_Multiply:
				AttributeValue *= Attributes[Index].ModValue;
				SetNumericValue(AttributeValue, Attributes[Index].AttributeName);
				break;
			case EAttributeOperation::Attribute_Divide:
				AttributeValue = (AttributeValue / Attributes[Index].ModValue);
				SetNumericValue(AttributeValue, Attributes[Index].AttributeName);
				break;
			case EAttributeOperation::Attribute_Set:
				AttributeValue = Attributes[Index].ModValue;
				SetNumericValue(AttributeValue, Attributes[Index].AttributeName);
				break;
			default:
				return;
			}
		}
	}
}
Exemplo n.º 9
0
// Internal function used to get the DICOM header from the current file.
ILboolean iGetDicomHead(DICOMHEAD *Header)
{
	ILushort	GroupNum, ElementNum;
	ILboolean	ReachedData = IL_FALSE;
	ILubyte		Var2, UID[65];

	// Signature should be "DICM" at position 128.
	iseek(128, IL_SEEK_SET);
	if (iread(Header->Signature, 1, 4) != 4)
		return IL_FALSE;

//@TODO: What about the case when we are reading an image with Big Endian data?

	do {
		GroupNum = GetGroupNum(Header);
		ElementNum = GetShort(Header, GroupNum);;

		switch (GroupNum)
		{
			case 0x02:
				switch (ElementNum)
				{
					/*case 0x01:  // Version number
						if (!GetNumericValue(&Header->Version))
							return IL_FALSE;
						if (Header->Version != 0x0100)
							return IL_FALSE;
						break;*/

					case 0x10:
						//@TODO: Look at pg. 60 of 07_05pu.pdf (PS 3.5) for more UIDs.
						if (!GetUID(UID))
							return IL_FALSE;
						if (!strncmp((const char*)UID, "1.2.840.10008.1.2.2", 64))  // Explicit big endian
							Header->BigEndian = IL_TRUE;
                        else if (!strncmp((const char*)UID, "1.2.840.10008.1.2.1", 64))  // Explicit little endian
							Header->BigEndian = IL_FALSE;
                        else if (!strncmp((const char*)UID, "1.2.840.10008.1.2", 64))  // Implicit little endian
							Header->BigEndian = IL_FALSE;
						else 
							return IL_FALSE;  // Unrecognized UID.
						break;

					default:
						if (!SkipElement(Header, GroupNum, ElementNum))  // We do not understand this entry, so we just skip it.
							return IL_FALSE;
				}
				break;

			case 0x28:
				switch (ElementNum)
				{
					case 0x02:  // Samples per pixel
						if (!GetNumericValue(Header, GroupNum, &Header->Samples))
							return IL_FALSE;
						break;

					case 0x08:  // Number of frames, or depth
						if (!GetNumericValue(Header, GroupNum, &Header->Depth))
							return IL_FALSE;
						break;

					case 0x10:  // The number of rows
						if (!GetNumericValue(Header, GroupNum, &Header->Height))
							return IL_FALSE;
						break;

					case 0x11:  // The number of columns
						if (!GetNumericValue(Header, GroupNum, &Header->Width))
							return IL_FALSE;
						break;

					case 0x100:  // Bits allocated per sample
						if (!GetNumericValue(Header, GroupNum, &Header->BitsAllocated))
							return IL_FALSE;
						break;

					case 0x101:  // Bits stored per sample - Do we really need this information?
						if (!GetNumericValue(Header, GroupNum, &Header->BitsStored))
							return IL_FALSE;
						break;

					default:
						if (!SkipElement(Header, GroupNum, ElementNum))  // We do not understand this entry, so we just skip it.
							return IL_FALSE;
				}
				break;

			case 0x7FE0:
				switch (ElementNum)
				{
					case 0x10:  // This element is the actual pixel data.  We are done with the header here.
						if (igetc() != 'O')  // @TODO: Can we assume that this is always 'O'?
							return IL_FALSE;
						Var2 = igetc();
						if (Var2 != 'B' && Var2 != 'W' && Var2 != 'F')  // 'OB', 'OW' and 'OF' accepted for this element.
							return IL_FALSE;
						GetLittleUShort();  // Skip the 2 reserved bytes.
						Header->DataLen = GetInt(Header, GroupNum);//GetLittleUInt();
						ReachedData = IL_TRUE;
						break;
					default:
						if (!SkipElement(Header, GroupNum, ElementNum))  // We do not understand this entry, so we just skip it.
							return IL_FALSE;
				}
				break;

			default:
				if (!SkipElement(Header, GroupNum, ElementNum))  // We do not understand this entry, so we just skip it.
					return IL_FALSE;
		}
	} while (!ieof() && !ReachedData);

	if (ieof())
		return IL_FALSE;

	// Some DICOM images do not have the depth (number of frames) field.
	if (Header->Depth == 0)
		Header->Depth = 1;

	switch (Header->BitsAllocated)
	{
		case 8:
			Header->Type = IL_UNSIGNED_BYTE;
			break;
		case 16:
			Header->Type = IL_UNSIGNED_SHORT;
			break;
		case 32:
			Header->Type = IL_FLOAT;  //@TODO: Is this ever an integer?
			break;
		default:  //@TODO: Any other types we can deal with?
			return IL_FALSE;
	}

	// Cannot handle more than 4 channels in an image.
	if (Header->Samples > 4)
		return IL_FALSE;
	Header->Format = ilGetFormatBpp(Header->Samples);

	return IL_TRUE;
}
Exemplo n.º 10
0
void* 
StatisticsKeeper::run_undetached(void* /*arg*/)
{
    unsigned long sleepTime = fMilliseconds * 1000;
    time_t        startTime = time(NULL);
    time_t        usedTime; 

    unsigned long qlen    ;
    unsigned long killed  ;
    unsigned long total   ;
    unsigned long stored  ;
    unsigned long skipped ;
    unsigned long msgerror;
    unsigned long done    ;
    float precentage_done ;
    char  percentage[100] ;
    unsigned long bytesReceived;
    unsigned long bytesSent;
    unsigned long avgBytesReceivedPerSecond;

    while (KeepRunning())
    {
        omni_thread::sleep(0,sleepTime);
        if(valuesModified)
        {
            qlen    = GetNumericValue("Command Queue Length");
            killed  = GetNumericValue("Articles Killed");
            total   = GetNumericValue("Articles Present");
            stored  = GetNumericValue("Articles Written");
            skipped = GetNumericValue("Articles Skipped");
            msgerror= GetNumericValue("Articles ERROR");
            done    = killed+stored+skipped+msgerror;

            precentage_done = 
                (total==0?0.0:(((float)(done))/((float)total))*100.0);

            // I couldn't get the stream formatting to do what I wanted
            // So let's do this the traditional way.
            sprintf(percentage,"%3.0f",precentage_done);

            Lstatus 
                << "MSGS:"  << setw(4) << total      <<","    // Total
                << "TODO:"  << setw(4) << qlen       <<","    // Queue length
                << "DONE:"             << percentage << "%={" 
                << "STOR:"  << setw(4) << stored     <<","    // Stored
                << "SKIP:"  << setw(4) << skipped    <<","    // Skipped
                << "KILL:"  << setw(4) << killed     <<","    // Killed
                << "ERROR:" << setw(4) << msgerror   <<"} \r" // Error
                << flush;

            bytesReceived = GetNumericValue("Socket Received Bytes");
                    
            usedTime = time(NULL) - startTime;
            if (usedTime==0)
                avgBytesReceivedPerSecond = bytesReceived; // assume 1 second
            else
                avgBytesReceivedPerSecond = (bytesReceived)/(usedTime);

            SetProcTitle("%3d%% (%4d/%4d) @ Average %6d bytes/second.    ",
                    (unsigned long)precentage_done,done,total,
                    avgBytesReceivedPerSecond);
            
            valuesModified = false;
        }
    }

    Linfo << endl << flush;

    // ----------------------------
    // Print the overall statistics
    bytesSent     = GetNumericValue("Socket Send Bytes");
    bytesReceived = GetNumericValue("Socket Received Bytes");
    
    usedTime = time(NULL) - startTime;
    if (usedTime==0)
        avgBytesReceivedPerSecond = bytesReceived; // assume 1 second
    else
        avgBytesReceivedPerSecond = (bytesReceived)/(usedTime);

    Linfo << "Overall : ";
    Linfo << "OUT: " << setw(7) << bytesSent << " bytes, " 
          << "IN: " << setw(9) <<  bytesReceived << " bytes, "
          << "AVG: " << setw(7) << avgBytesReceivedPerSecond << " bytes/second" 
          << endl << flush;

    return NULL;
}