예제 #1
0
파일: matrix.cpp 프로젝트: alinelena/aten
// Set value of variable
bool MatrixVariable::set(ReturnValue& rv)
{
	if (readOnly_)
	{
		Messenger::print("A constant value (in this case a matrix) cannot be assigned to.");
		return false;
	}
	bool success = false;
	if (rv.arraySize() == -1) matrixData_ = rv.asMatrix(success);
	else if (rv.arraySize() == 9)
	{
		matrixData_.setIdentity();
		for (int n=0; n<9; ++n)
		{
			matrixData_[n/3*4+n%3] = rv.asDouble(n, success);
			if (!success) break;
		}
	}
	else if (rv.arraySize() == 16)
	{
		for (int n=0; n<16; ++n)
		{
			matrixData_[n] = rv.asDouble(n, success);
			if (!success) break;
		}
	}
	else
	{
		Messenger::print("Error: Array assigned to matrix variable must contain nine or sixteen elements.");
		success = false;
	}
	return success;
}
예제 #2
0
파일: matrix.cpp 프로젝트: alinelena/aten
// Retrieve desired value
bool MatrixVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("MatrixVariable::retrieveAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for Matrix type.\n", i);
		Messenger::exit("MatrixVariable::retrieveAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;
	// Check for correct lack/presence of array index given
	if (hasArrayIndex)
	{
		Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name));
		Messenger::exit("MatrixVariable::retrieveAccessor");
		return false;
	}
	// Get current data from ReturnValue
	bool result = true;
	Matrix m = rv.asMatrix(result);
	if (result) switch (acc)
	{
		case (MatrixVariable::Determinant):
			rv.set(m.determinant());
			break;
		case (MatrixVariable::XX):
		case (MatrixVariable::XY):
		case (MatrixVariable::XZ):
		case (MatrixVariable::XW):
		case (MatrixVariable::YX):
		case (MatrixVariable::YY):
		case (MatrixVariable::YZ):
		case (MatrixVariable::YW):
		case (MatrixVariable::ZX):
		case (MatrixVariable::ZY):
		case (MatrixVariable::ZZ):
		case (MatrixVariable::ZW):
		case (MatrixVariable::WX):
		case (MatrixVariable::WY):
		case (MatrixVariable::WZ):
		case (MatrixVariable::WW):
			rv.set(m[acc-MatrixVariable::XX]);
			break;
		default:
			printf("Internal Error: Access to member '%s' has not been defined in MatrixVariable.\n", qPrintable(accessorData[i].name));
			result = false;
			break;
	}
	Messenger::exit("MatrixVariable::retrieveAccessor");
	return result;
}
예제 #3
0
파일: matrix.cpp 프로젝트: alinelena/aten
// Set from returnvalue node
bool MatrixArrayVariable::set(ReturnValue& rv)
{
	if (readOnly_)
	{
		Messenger::print("A constant value (in this case a matrix array) cannot be assigned to.");
		return false;
	}
	if (matrixArrayData_ == NULL)
	{
		printf("Internal Error: Array '%s' has not been initialised.\n", qPrintable(name_));
		return false;
	}
	// Loop over array elements and set them
	for (int i=0; i<arraySize_; i++) matrixArrayData_[i] = rv.asMatrix();
	return true;
}
예제 #4
0
파일: matrix.cpp 프로젝트: alinelena/aten
// Set array element from returnvalue node
bool MatrixArrayVariable::setAsArray(ReturnValue& rv, int arrayIndex)
{
	if (readOnly_)
	{
		Messenger::print("A constant value (in this case a matrix array?) cannot be assigned to.");
		return false;
	}
	if (matrixArrayData_ == NULL)
	{
		printf("Internal Error: Array '%s' has not been initialised.\n", qPrintable(name_));
		return false;
	}
	// Check index
	if ((arrayIndex < 0) || (arrayIndex >= arraySize_))
	{
		Messenger::print("Index %i out of bounds for array '%s'.", arrayIndex+1, qPrintable(name_));
		return false;
	}
	// Set individual element
	matrixArrayData_[arrayIndex] = rv.asMatrix();
	return true;
}
예제 #5
0
파일: matrix.cpp 프로젝트: alinelena/aten
// Perform desired function
bool MatrixVariable::performFunction(int i, ReturnValue& rv, TreeNode* node)
{
	Messenger::enter("MatrixVariable::performFunction");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nFunctions))
	{
		printf("Internal Error: FunctionAccessor id %i is out of range for Matrix type.\n", i);
		Messenger::exit("MatrixVariable::performFunction");
		return false;
	}

	// Get current data from ReturnValue
	bool result = true;
	Matrix m = rv.asMatrix();
	if (result) switch (i)
	{
		default:
			printf("Internal Error: Access to function '%s' has not been defined in MatrixVariable.\n", qPrintable(functionData[i].name));
			result = false;
			break;
	}
	Messenger::exit("MatrixVariable::performFunction");
	return result;
}