Example #1
0
IECOREARNOLD_API AtArray *dataToArray( const std::vector<const IECore::Data *> &samples, int aiType )
{
	if( aiType == AI_TYPE_NONE )
	{
		bool isArray = false;
		aiType = parameterType( samples.front()->typeId(), isArray );
		if( aiType == AI_TYPE_NONE || !isArray )
		{
			return NULL;
		}
	}

	size_t arraySize = despatchTypedData<TypedDataSize, TypeTraits::IsTypedData, DespatchTypedDataIgnoreError>( const_cast<Data *>( samples.front() ) );
	ArrayPtr array(
		AiArrayAllocate( arraySize, samples.size(), aiType ),
		AiArrayDestroy
	);

	for( vector<const IECore::Data *>::const_iterator it = samples.begin(), eIt = samples.end(); it != eIt; ++it )
	{
		if( (*it)->typeId() != samples.front()->typeId() )
		{
			throw IECore::Exception( "ParameterAlgo::dataToArray() : Mismatched sample types." );
		}
		const size_t dataSize = despatchTypedData<TypedDataSize, TypeTraits::IsTypedData, DespatchTypedDataIgnoreError>( const_cast<Data *>( *it ) );
		if( dataSize != arraySize )
		{
			throw IECore::Exception( "ParameterAlgo::dataToArray() : Mismatched sample lengths." );
		}
		const void *dataAddress = despatchTypedData<TypedDataAddress, TypeTraits::IsTypedData, DespatchTypedDataIgnoreError>( const_cast<Data *>( *it ) );
		AiArraySetKey( array.get(), /* key = */ it - samples.begin(), dataAddress );
	}

	return array.release();
}
Example #2
0
AtArray *dataToArray( const IECore::Data *data, int aiType )
{
	if( aiType == AI_TYPE_NONE )
	{
		bool isArray = false;
		aiType = parameterType( data->typeId(), isArray );
		if( aiType == AI_TYPE_NONE || !isArray )
		{
			return NULL;
		}
	}
	// bools are a special case because of how the STL implements vector<bool>.
	// Since the base for vector<bool> are not actual booleans, we need to manually
	// convert to an AtArray here.
	else if( aiType == AI_TYPE_BOOLEAN )
	{
		const vector<bool> &booleans = static_cast<const BoolVectorData *>( data )->readable();
		vector<bool>::size_type booleansSize = booleans.size();
		AtArray* array = AiArrayAllocate( booleansSize, 1, AI_TYPE_BOOLEAN );
		for(vector<bool>::size_type i = 0; i < booleansSize; ++i){
			AiArraySetBool(array, i, booleans[i]);
		}
		return array;
	}

	const void *dataAddress = despatchTypedData<TypedDataAddress, TypeTraits::IsTypedData, DespatchTypedDataIgnoreError>( const_cast<Data *>( data ) );
	size_t dataSize = despatchTypedData<TypedDataSize, TypeTraits::IsTypedData, DespatchTypedDataIgnoreError>( const_cast<Data *>( data ) );
	return AiArrayConvert( dataSize, 1, aiType, dataAddress );
}
Example #3
0
void setParameter( AtNode *node, const char *name, const IECore::Data *value )
{
	const AtParamEntry *parameter = AiNodeEntryLookUpParameter( AiNodeGetNodeEntry( node ), name );
	if( parameter )
	{
		setParameter( node, parameter, value );
	}
	else
	{
		bool array = false;
		int type = parameterType( value->typeId(), array );
		if( type != AI_TYPE_NONE )
		{
			std::string typeString = "constant ";
			if( array )
			{
				typeString += "ARRAY ";
			}
			typeString += AiParamGetTypeName( type );
			AiNodeDeclare( node, name, typeString.c_str() );
			setParameterInternal( node, name, type, array, value );
		}
		else
		{
			msg(
				Msg::Warning,
				"setParameter",
				boost::format( "Unsupported data type \"%s\" for name \"%s\"" ) % value->typeName() % name
			);
		}
	}
}
Example #4
0
  SmartPointer<ParameterType> CommandManager::GetParameterType(const std::string& parameterTypeId) {
    this->CheckId(parameterTypeId);

    ParameterType::Pointer parameterType(parameterTypesById[parameterTypeId]);
    if (!parameterType) {
      parameterType = new ParameterType(parameterTypeId);
      parameterTypesById[parameterTypeId] = parameterType;
      parameterType->AddListener(parameterTypeListener);
    }

    return parameterType;
  }
Example #5
0
int parameterType( const IECore::Data *data, bool &array )
{
	int type = parameterType( data->typeId(), array );

	// if we have data of type vector, its interpretation matters
	if( type == AI_TYPE_VECTOR )
	{
		GeometricData::Interpretation interpretation = getGeometricInterpretation( data );
		if( interpretation == GeometricData::Point )
		{
			type = AI_TYPE_POINT;
		}
	}

	return type;
}
ParameterizedCommand::Pointer ParameterizedCommand::GenerateCommand(const SmartPointer<Command> command,
    const std::map<std::string, Object::Pointer>& parameters)
{
  // no parameters
  if (parameters.empty())
  {
    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, std::vector<Parameterization>()));
    return pCmd;
  }

  try
  {
    std::vector<Parameterization> parms;

    // iterate over given parameters
    for (std::map<std::string, Object::Pointer>::const_iterator i = parameters.begin();
        i != parameters.end(); ++i)
    {
      std::string key(i->first);

      // get the parameter from the command
      IParameter::Pointer parameter(command->GetParameter(key));

      // if the parameter is defined add it to the parameter list
      if (!parameter)
      {
        return ParameterizedCommand::Pointer(0);
      }
      ParameterType::Pointer parameterType(command->GetParameterType(key));
      if (!parameterType)
      {
        std::string val(*(i->second.Cast<ObjectString>()));
        parms.push_back(Parameterization(parameter, val));
      }
      else
      {
        IParameterValueConverter::Pointer valueConverter(parameterType
            ->GetValueConverter());
        if (valueConverter)
        {
          std::string val(valueConverter->ConvertToString(i->second));
          parms.push_back(Parameterization(parameter, val));
        }
        else
        {
          std::string val(*(i->second.Cast<ObjectString>()));
          parms.push_back(Parameterization(parameter, val));
        }
      }
    }

    // convert the parameters to an Parameterization array and create
    // the command
    ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, parms));
    return pCmd;
  }
  catch (const NotDefinedException* /*e*/)
  {
  }
  catch (const ParameterValueConversionException* /*e*/)
  {
  }
  return ParameterizedCommand::Pointer(0);
}