Ejemplo n.º 1
0
	ReturnType operator()( const T *data )
	{
		PrimitiveVariableMap::iterator it = m_mesh->variables.find( m_name );
		if ( it == m_mesh->variables.end() && !m_remove )
		{
			typename T::Ptr data2 = 0;

			std::map<ConstDataPtr, DataPtr>::iterator dataIt = m_visitedData.find( data );
			if ( dataIt != m_visitedData.end() )
			{
				data2 = runTimeCast<T>( dataIt->second );
			}
			
			if ( !data2 )
			{
				typedef typename T::ValueType::value_type ValueType;
				ValueType defaultValue = DefaultValue<ValueType>()();
				size_t size = m_mesh->variableSize( m_interpolation ) - data->readable().size();
				
				data2 = new T();
				data2->writable().insert( data2->writable().end(), size, defaultValue );
				data2->writable().insert( data2->writable().end(), data->readable().begin(), data->readable().end() );
			}
			
			m_mesh->variables[m_name] = PrimitiveVariable( m_interpolation, data2 );
			
			m_visitedData[data] = data2;
		}
	}
FromHoudiniCurvesConverter::DuplicateEnds::ReturnType FromHoudiniCurvesConverter::DuplicateEnds::operator()( typename T::Ptr data ) const
{
	assert( data );

	typedef typename T::ValueType::value_type ValueType;

	std::vector<ValueType> newValues;
	const std::vector<ValueType> &origValues = data->readable();
	
	size_t index = 0;
	for ( size_t i=0; i < m_vertsPerCurve.size(); i++ )
	{
		for ( size_t j=0; j < (size_t)m_vertsPerCurve[i]; j++, index++ )
		{
			newValues.push_back( origValues[index] );
			
			if ( j == 0 || j == (size_t)m_vertsPerCurve[i]-1 )
			{
				newValues.push_back( origValues[index] );
				newValues.push_back( origValues[index] );
			}
		}
	}
	
	data->writable().swap( newValues );
}
Ejemplo n.º 3
0
	ReturnType operator()( T * data )
	{
		typedef typename T::ValueType VecContainer;
		typedef typename VecContainer::value_type Vec;

		const VecContainer &points = data->readable();
		
		unsigned numElements = points.size();
		
		typename T::Ptr vD = new T();
		vTangentsData = vD;
		
		VecContainer &vTangents = vD->writable();
		vTangents.resize( numElements );
		
		PrimitiveEvaluator::ResultPtr result = m_evaluator->createResult();
		
		unsigned pIndex = 0;
		for( size_t curveIndex = 0; curveIndex < m_vertsPerCurve.size() ; curveIndex++ )
		{
			float v;
			float vStep = 1.0f / m_vertsPerCurve[curveIndex];
			
			for( int i = 0; i < m_vertsPerCurve[curveIndex]; i++ ) 
			{
				v = min( 1.0f, i * vStep );			
				m_evaluator->pointAtV( curveIndex, v, result );
				vTangents[ pIndex + i ] = result->vTangent().normalized();
			}
			pIndex += m_vertsPerCurve[curveIndex];
		}	
	}
Ejemplo n.º 4
0
typename T::Ptr vectorDataFromTypeDesc( TypeDesc type, void *&basePointer )
{
    typename T::Ptr result = new T();
    result->writable().resize( type.arraylen, typename T::ValueType::value_type( 0 ) );
    basePointer = result->baseWritable();
    return result;
}
ToHoudiniCurvesConverter::RemoveDuplicateEnds::ReturnType ToHoudiniCurvesConverter::RemoveDuplicateEnds::operator()( typename T::ConstPtr data ) const
{
	assert( data );

	typedef typename T::ValueType::value_type ValueType;

	const std::vector<ValueType> &origValues = data->readable();

	typename T::Ptr result = new T();
	std::vector<ValueType> &newValues = result->writable();
	
	size_t index = 0;
	for ( size_t i=0; i < m_vertsPerCurve.size(); i++ )
	{
		for ( size_t j=0; j < (size_t)m_vertsPerCurve[i]; j++, index++ )
		{
			if ( j > 1 && j < (size_t)m_vertsPerCurve[i]-2 )
			{
				newValues.push_back( origValues[index] );
			}
		}
	}
	
	return result;
}
Ejemplo n.º 6
0
static DataPtr evaluatePrimitiveVariable( std::vector<GxSurfacePoint> &points, const std::string &primVarName )
{
	typename T::Ptr result = new T;
	result->writable().resize( points.size() );
	if( points.size() )
	{
		GxEvaluateSurface( points.size(), &(points[0]), primVarName.c_str(), result->baseSize() / points.size(), result->baseWritable() );
	}
	return result;
}
Ejemplo n.º 7
0
	DataPtr operator() ( T * data ) const
	{
		assert( data );
		typedef typename T::ValueType::value_type Value;

		const unsigned vPoints = m_resolution.y;
		const unsigned uPoints = m_resolution.x;

		typename T::Ptr newData = new T();
		newData->writable().reserve( ( vPoints + 2 ) * uPoints );

		for ( unsigned int v = 0; v < vPoints; v++ )
		{
			size_t iSeg;
			float fSeg;

			if ( v == vPoints - 1 )
			{
				iSeg = m_curves->numSegments( m_curveIndex ) - 1;
				fSeg = 0.9999f;
			}
			else
			{
				float curveParam = float(v) / ( vPoints - 1 );
				fSeg = curveParam * m_curves->numSegments( m_curveIndex );
				iSeg = (size_t)floor( fSeg );
				fSeg = fSeg - iSeg;
			}

			const int num = v == 0 || v == vPoints - 1 ? 2 : 1;

			const size_t i0 = iSeg;
			const size_t i1 = std::min( iSeg + 1, m_curves->variableSize( PrimitiveVariable::Varying, m_curveIndex ) );

			for ( int x = 0; x < num; x++)
			{
				for ( unsigned u = 0; u < uPoints ; u ++)
				{
					Value value;
					LinearInterpolator<Value>()(
						data->readable()[ m_varyingOffset + i0 ],
						data->readable()[ m_varyingOffset + i1],
						fSeg,
						value
					);
					newData->writable().push_back( value );
				}
			}
		}

		return newData;
	}
Ejemplo n.º 8
0
		IECore::DataPtr operator()( typename T::Ptr inData )
		{
			assert( inData );

			const typename T::Ptr outData = new T();
			outData->writable().resize( m_vertIds->readable().size() );

			typename T::ValueType::iterator outIt = outData->writable().begin();

			for ( typename T::ValueType::size_type i = 0; i <  m_vertIds->readable().size(); i++ )
			{
				*outIt++ = inData->readable()[ m_vertIds->readable()[ i ] ];
			}

			return outData;
		}
Ejemplo n.º 9
0
	DataPtr operator() ( typename T::Ptr data ) const
	{
		assert( data );
		typedef typename T::ValueType::value_type Value;

		const unsigned vPoints = m_resolution.y;
		const unsigned uPoints = m_resolution.x;

		typename T::Ptr newData = new T();
		newData->writable().reserve( ( vPoints ) * uPoints );

		for ( unsigned int v = 0; v < vPoints; v++ )
		{
			int iSeg;
			float fSeg;

			if ( v == vPoints - 1 )
			{
				iSeg = m_curves->numSegments( m_curveIndex ) - 1;
				fSeg = 0.9999f;
			}
			else
			{
				float curveParam = float(v) / ( vPoints - 1 );
				fSeg = curveParam * m_curves->numSegments( m_curveIndex );
				iSeg = (int)floor( fSeg );
				fSeg = fSeg - iSeg;
			}

			for ( unsigned u = 0; u < uPoints ; u ++)
			{
				Value value;
				LinearInterpolator<Value>()(
					data->readable()[ m_varyingOffset + iSeg ],
					data->readable()[ m_varyingOffset + iSeg + 1],
					fSeg,
					value
				);
				newData->writable().push_back( value );
			}
		}

		return newData;
	}
Ejemplo n.º 10
0
		IECore::DataPtr operator()( const T *inData )
		{
			const typename T::Ptr outData = new T();
			typename T::ValueType &out = outData->writable();
			out.resize( m_numVertices );

			size_t inIndex = 0;
			size_t outIndex = 0;
			const typename T::ValueType &in = inData->readable();
			for( vector<int>::const_iterator it = m_vertsPerCurve.begin(), eIt = m_vertsPerCurve.end(); it != eIt; it++ )
			{
				for( int i=0; i<*it; i++ )
				{
					out[outIndex++] = in[inIndex];
				}
				inIndex += m_step;
			}

			return outData;
		}
Ejemplo n.º 11
0
IECore::ObjectPtr FromMayaArrayDataConverter<F,T>::doConversion( const MObject &object, IECore::ConstCompoundObjectPtr operands ) const
{
    typename MArrayTraits<F>::DataFn fnArrayData( object );
    if( !fnArrayData.hasObj( object ) )
    {
        return 0;
    }

    F array = fnArrayData.array();
    typename T::Ptr resultData = new T;
    typename T::ValueType &resultArray = resultData->writable();

    resultArray.resize( array.length() );
    for( unsigned int i=0; i<resultArray.size(); i++ )
    {
        resultArray[i] = IECore::convert<typename T::ValueType::value_type, typename MArrayTraits<F>::ValueType>( array[i] );
    }

    return resultData;
}
Ejemplo n.º 12
0
 Analysis::Result::Ptr DetectIn(LookaheadPluginsStorage<T>& container, DataLocation::Ptr input, const Module::DetectCallback& callback) const
 {
   const bool firstScan = 0 == Offset;
   const std::size_t maxSize = input->GetData()->Size();
   for (typename T::Iterator::Ptr iter = container.Enumerate(); iter->IsValid(); iter->Next())
   {
     Time::Timer timer;
     const typename T::Ptr plugin = iter->Get();
     const Analysis::Result::Ptr result = plugin->Detect(Params, input, callback);
     const String id = plugin->GetDescription()->Id();
     if (const std::size_t usedSize = result->GetMatchedDataSize())
     {
       Statistic::Self().AddAimed(*plugin, timer);
       Dbg("Detected %1% in %2% bytes at %3%.", id, usedSize, input->GetPath()->AsString());
       return result;
     }
     else
     {
       if (!firstScan)
       {
         Statistic::Self().AddMissed(*plugin, timer);
         timer = Time::Timer();
       }
       const std::size_t lookahead = result->GetLookaheadOffset();
       container.SetPluginLookahead(*plugin, id, lookahead);
       if (lookahead == maxSize)
       {
         Statistic::Self().AddAimed(*plugin, timer);
       }
       else
       {
         Statistic::Self().AddScanned(*plugin, timer);
       }
     }
   }
   const std::size_t minLookahead = container.GetMinimalPluginLookahead();
   return Analysis::CreateUnmatchedResult(minLookahead);
 }
Ejemplo n.º 13
0
	ReturnType operator()( typename T::Ptr data )
	{
		typedef typename T::ValueType Container;
		typedef typename Container::value_type V;

		Container &output = data->writable();
		
		V2i paddedSize = m_size + V2i( 2 );

		V *op = &(output[0]);
		const char *ip = &(m_input[0]) + paddedSize.x + 1;
		for( int y=0; y<m_size.y; y++ )
		{
			for( int x=0; x<m_size.x; x++ )
			{
				*op++ = *ip++;
			}
			ip +=2; // skip padding on right and left of next row
		}
	}
Ejemplo n.º 14
0
	object operator()( typename T::Ptr data )
	{
		return object( data->readable() );
	}
Ejemplo n.º 15
0
typename T::Ptr geometricVectorDataFromTypeDesc( TypeDesc type, void *&basePointer )
{
    typename T::Ptr result = vectorDataFromTypeDesc<T>( type, basePointer );
    result->setInterpretation( geometricInterpretationFromVecSemantics( (TypeDesc::VECSEMANTICS)type.vecsemantics ) );
    return result;
}
static typename T::Ptr hexToDecVector( const char *s )
{
	typename T::Ptr result = new T;
	IECore::hexToDec<typename T::ValueType::value_type>( s, s + strlen( s ), std::back_insert_iterator<typename T::ValueType>( result->writable() ) );
	return result;
}
Ejemplo n.º 17
0
	DataPtr operator() ( typename T::Ptr data ) const
	{
		assert( data );
		return new TypedData< typename T::ValueType::value_type >( data->readable()[ m_curveIndex ] );
	}
Ejemplo n.º 18
0
	ReturnType operator()( T * data )
	{
		typedef typename T::ValueType VecContainer;
		typedef typename VecContainer::value_type Vec;

		const VecContainer &points = data->readable();
		
		// the uvIndices array is indexed as with any other facevarying data. the values in the
		// array specify the connectivity of the uvs - where two facevertices have the same index
		// they are known to be sharing a uv. for each one of these unique indices we compute
		// the tangents and normal, by accumulating all the tangents and normals for the faces
		// that reference them. we then take this data and shuffle it back into facevarying
		// primvars for the mesh.
		int numUniqueTangents = 1 + *max_element( m_uvIds.begin(), m_uvIds.end() );
		
		VecContainer uTangents( numUniqueTangents, Vec( 0 ) );
		VecContainer vTangents( numUniqueTangents, Vec( 0 ) );
		VecContainer normals( numUniqueTangents, Vec( 0 ) );
		
		for( size_t faceIndex = 0; faceIndex < m_vertsPerFace.size() ; faceIndex++ )
		{
			
			assert( m_vertsPerFace[faceIndex] == 3 );

			// indices into the facevarying data for this face 
			size_t fvi0 = faceIndex * 3;
			size_t fvi1 = fvi0 + 1;
			size_t fvi2 = fvi1 + 1;
			assert( fvi2 < m_vertIds.size() );
			assert( fvi2 < m_u.size() );
			assert( fvi2 < m_v.size() );
			
			// positions for each vertex of this face
			const Vec &p0 = points[ m_vertIds[ fvi0 ] ];
			const Vec &p1 = points[ m_vertIds[ fvi1 ] ];
			const Vec &p2 = points[ m_vertIds[ fvi2 ] ];

			// uv coordinates for each vertex of this face
			const Imath::V2f uv0( m_u[ fvi0 ], m_v[ fvi0 ] );
			const Imath::V2f uv1( m_u[ fvi1 ], m_v[ fvi1 ] );
			const Imath::V2f uv2( m_u[ fvi2 ], m_v[ fvi2 ] );

			// compute tangents and normal for this face
			const Vec e0 = p1 - p0;
			const Vec e1 = p2 - p0;

			const Imath::V2f e0uv = uv1 - uv0;
			const Imath::V2f e1uv = uv2 - uv0;

			Vec tangent   = ( e0 * -e1uv.y + e1 * e0uv.y ).normalized();
			Vec bitangent = ( e0 * -e1uv.x + e1 * e0uv.x ).normalized();

			Vec normal = (p2-p1).cross(p0-p1);
			normal.normalize();

			// and accumlate them into the computation so far
			uTangents[ m_uvIds[fvi0] ] += tangent;
			uTangents[ m_uvIds[fvi1] ] += tangent;
			uTangents[ m_uvIds[fvi2] ] += tangent;
			
			vTangents[ m_uvIds[fvi0] ] += bitangent;
			vTangents[ m_uvIds[fvi1] ] += bitangent;
			vTangents[ m_uvIds[fvi2] ] += bitangent;
			
			normals[ m_uvIds[fvi0] ] += normal;
			normals[ m_uvIds[fvi1] ] += normal;
			normals[ m_uvIds[fvi2] ] += normal;
			
		}

		// normalize and orthogonalize everything
		for( size_t i = 0; i < uTangents.size(); i++ )
		{
			normals[i].normalize();

			uTangents[i].normalize();
			vTangents[i].normalize();

			// Make uTangent/vTangent orthogonal to normal
			uTangents[i] -= normals[i] * uTangents[i].dot( normals[i] );
			vTangents[i] -= normals[i] * vTangents[i].dot( normals[i] );

			uTangents[i].normalize();
			vTangents[i].normalize();

			if ( m_orthoTangents )
			{
				vTangents[i] -= uTangents[i] * vTangents[i].dot( uTangents[i] );
				vTangents[i].normalize();
			}
		
			// make things less sinister
			if( uTangents[i].cross( vTangents[i] ).dot( normals[i] ) < 0.0f )
			{
				uTangents[i] *= -1.0f;
			}
		}
		
		// convert the tangents back to facevarying data and add that to the mesh
		typename T::Ptr fvUD = new T();
		typename T::Ptr fvVD = new T();
		fvUTangentsData = fvUD;
		fvVTangentsData = fvVD;
		
		VecContainer &fvUTangents = fvUD->writable();
		VecContainer &fvVTangents = fvVD->writable();
		fvUTangents.resize( m_uvIds.size() );
		fvVTangents.resize( m_uvIds.size() );
		
		for( unsigned i=0; i<m_uvIds.size(); i++ )
		{
			fvUTangents[i] = uTangents[m_uvIds[i]];
			fvVTangents[i] = vTangents[m_uvIds[i]];
		}

	}