bool ToHoudiniPolygonsConverter::doConversion( const VisibleRenderable *renderable, GU_Detail *geo ) const { const MeshPrimitive *mesh = static_cast<const MeshPrimitive *>( renderable ); if ( !mesh ) { return false; } GA_Range newPoints = appendPoints( geo, mesh->variableSize( PrimitiveVariable::Vertex ) ); if ( !newPoints.isValid() || newPoints.empty() ) { return false; } GA_OffsetList pointOffsets; pointOffsets.reserve( newPoints.getEntries() ); for ( GA_Iterator it=newPoints.begin(); !it.atEnd(); ++it ) { pointOffsets.append( it.getOffset() ); } const std::vector<int> &vertexIds = mesh->vertexIds()->readable(); const std::vector<int> &verticesPerFace = mesh->verticesPerFace()->readable(); GA_OffsetList offsets; offsets.reserve( verticesPerFace.size() ); size_t vertCount = 0; size_t numPrims = geo->getNumPrimitives(); for ( size_t f=0; f < verticesPerFace.size(); f++ ) { GU_PrimPoly *poly = GU_PrimPoly::build( geo, 0, GU_POLY_CLOSED, 0 ); offsets.append( geo->primitiveOffset( numPrims + f ) ); for ( size_t v=0; v < (size_t)verticesPerFace[f]; v++ ) { poly->appendVertex( pointOffsets.get( vertexIds[ vertCount + verticesPerFace[f] - 1 - v ] ) ); } vertCount += verticesPerFace[f]; } GA_Range newPrims( geo->getPrimitiveMap(), offsets ); transferAttribs( geo, newPoints, newPrims ); // add the interpolation type if ( newPrims.isValid() ) { std::string interpolation = ( mesh->interpolation() == "catmullClark" ) ? "subdiv" : "poly"; StringVectorDataPtr interpolationVectorData = new StringVectorData(); interpolationVectorData->writable().push_back( interpolation ); std::vector<int> indexValues( newPrims.getEntries(), 0 ); IntVectorDataPtr indexData = new IntVectorData( indexValues ); ToHoudiniStringVectorAttribConverterPtr converter = new ToHoudiniStringVectorAttribConverter( interpolationVectorData ); converter->indicesParameter()->setValidatedValue( indexData ); converter->convert( "ieMeshInterpolation", geo, newPrims ); } return true; }
IECore::ConstStringVectorDataPtr ImageReader::computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const { std::string fileName = fileNamePlug()->getValue(); const ImageSpec *spec = imageCache()->imagespec( ustring( fileName.c_str() ) ); StringVectorDataPtr result = new StringVectorData(); result->writable() = spec->channelnames; return result; }
void SceneView::transferSelectionToContext() { /// \todo Use PathMatcherData for the context variable so we don't need /// to do this copying into StringVectorData. See related comments /// in SceneHierarchy.__transferSelectionFromContext StringVectorDataPtr s = new StringVectorData(); m_sceneGadget->getSelection()->readable().paths( s->writable() ); getContext()->set( "ui:scene:selectedPaths", s.get() ); }
void SceneView::transferSelectionToContext() { /// \todo If RenderableGadget used PathMatcherData, then we might not need /// to copy data here. const RenderableGadget::Selection &selection = m_renderableGadget->getSelection(); StringVectorDataPtr s = new StringVectorData(); s->writable().insert( s->writable().end(), selection.begin(), selection.end() ); getContext()->set( "ui:scene:selectedPaths", s.get() ); }
void setSelectedPaths( Context *context, const GafferScene::PathMatcher &paths ) { /// \todo: Switch to storing PathMatcherData after some thorough /// testing and a major version break. StringVectorDataPtr s = new StringVectorData; paths.paths( s->writable() ); context->set( g_selectedPathsName, s.get() ); }
ImageCompositeOp::ImageCompositeOp() : ImagePrimitiveOp( "ImageCompositeOp" ) { IntParameter::PresetsContainer operationPresets; operationPresets.push_back( IntParameter::Preset( "Over", Over ) ); operationPresets.push_back( IntParameter::Preset( "Max", Max ) ); operationPresets.push_back( IntParameter::Preset( "Min", Min ) ); operationPresets.push_back( IntParameter::Preset( "Multiply", Multiply ) ); m_operationParameter = new IntParameter( "operation", "operation description", Over, operationPresets ); StringVectorDataPtr defaultChannels = new StringVectorData; defaultChannels->writable().push_back( "R" ); defaultChannels->writable().push_back( "G" ); defaultChannels->writable().push_back( "B" ); m_channelNamesParameter = new StringVectorParameter( "channels", "The names of the channels to modify.", defaultChannels ); m_alphaChannelNameParameter = new StringParameter( "alphaChannelName", "The name of the channel which holds the alpha. This is used for both images.", "A" ); m_imageAParameter = new ImagePrimitiveParameter( "imageA", "imageA is the second image operand of the composite. It is named such that operation names like 'A over B' make sense. " "Therefore parameter named 'input' represents imageB", new ImagePrimitive() ); IntParameter::PresetsContainer inputModePresets; inputModePresets.push_back( IntParameter::Preset( "Premultiplied", Premultiplied ) ); inputModePresets.push_back( IntParameter::Preset( "Unpremultiplied", Unpremultiplied ) ); m_inputModeParameter = new IntParameter( "inputMode", "States whether the input images are premultiplied by their alpha.", Premultiplied, inputModePresets ); parameters()->addParameter( m_operationParameter ); parameters()->addParameter( m_channelNamesParameter ); parameters()->addParameter( m_alphaChannelNameParameter ); parameters()->addParameter( m_imageAParameter ); parameters()->addParameter( m_inputModeParameter ); }
IECore::ConstStringVectorDataPtr Shape::computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const { assert( parent == shapePlug() ); StringVectorDataPtr result = new StringVectorData(); result->writable().push_back( "R" ); result->writable().push_back( "G" ); result->writable().push_back( "B" ); result->writable().push_back( "A" ); return result; }
void updateLookThroughCamera() { if( !m_lookThroughCameraDirty ) { return; } m_lookThroughCameraDirty = false; m_lookThroughCamera = NULL; if( !enabledPlug()->getValue() ) { m_view->viewportGadget()->setCamera( m_originalCamera.get() ); m_view->viewportGadget()->setCameraEditable( true ); m_view->hideFilter()->pathsPlug()->setToDefault(); return; } // We want to look through a specific camera. // Retrieve it. Context::Scope scopedContext( m_view->getContext() ); try { const string cameraPathString = cameraPlug()->getValue(); if( cameraPathString.empty() ) { m_lookThroughCamera = GafferScene::camera( scenePlug() ); // primary render camera } else { ScenePlug::ScenePath cameraPath; ScenePlug::stringToPath( cameraPathString, cameraPath ); m_lookThroughCamera = GafferScene::camera( scenePlug(), cameraPath ); } } catch( ... ) { // If an invalid path has been entered for the camera, computation will fail. // We just ignore that and lock to the current camera instead. m_lookThroughCamera = NULL; } m_view->viewportGadget()->setCameraEditable( false ); if( m_lookThroughCamera ) { StringVectorDataPtr invisiblePaths = new StringVectorData(); invisiblePaths->writable().push_back( m_lookThroughCamera->getName() ); m_view->hideFilter()->pathsPlug()->setValue( invisiblePaths ); } else { m_view->hideFilter()->pathsPlug()->setToDefault(); } }
IECore::StringVectorDataPtr AlembicInput::childNames() const { StringVectorDataPtr resultData = new StringVectorData; std::vector<std::string> &resultVector = resultData->writable(); size_t numChildren = this->numChildren(); for( size_t i=0; i<numChildren; i++ ) { resultVector.push_back( m_data->object.getChildHeader( i ).getName() ); } return resultData; }
IECore::ConstStringVectorDataPtr Shuffle::computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const { StringVectorDataPtr resultData = inPlug()->channelNamesPlug()->getValue()->copy(); vector<string> &result = resultData->writable(); for( ChannelPlugIterator it( channelsPlug() ); !it.done(); ++it ) { string channelName = (*it)->outPlug()->getValue(); if( channelName != "" && find( result.begin(), result.end(), channelName ) == result.end() ) { result.push_back( channelName ); } } return resultData; }
TransformOp::TransformOp() : PrimitiveOp( "Applies a matrix transformation to primitive variables." ) { m_multiplyOp = new MatrixMultiplyOp; m_multiplyOp->copyParameter()->setTypedValue( false ); StringVectorDataPtr defaultPrimVars = new StringVectorData; defaultPrimVars->writable().push_back( "P" ); defaultPrimVars->writable().push_back( "N" ); m_primVarsParameter = new StringVectorParameter( "primVarsToModify", "The names of primitive variables which should be transformed according to their Geometric Interpretation.", defaultPrimVars ); parameters()->addParameter( m_multiplyOp->matrixParameter() ); parameters()->addParameter( m_primVarsParameter ); }
IECore::ConstStringVectorDataPtr Constant::computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const { std::string channelNamePrefix = layerPlug()->getValue(); if( !channelNamePrefix.empty() ) { channelNamePrefix += "."; } StringVectorDataPtr resultData = new StringVectorData(); vector<string> &result = resultData->writable(); result.push_back( channelNamePrefix + "R" ); result.push_back( channelNamePrefix + "G" ); result.push_back( channelNamePrefix + "B" ); result.push_back( channelNamePrefix + "A" ); return resultData; }
void CopyChannels::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const { if( output == mappingPlug() ) { const string channelMatchPatterns = channelsPlug()->getValue(); CompoundObjectPtr result = new CompoundObject(); StringVectorDataPtr channelNamesData = new StringVectorData; result->members()["__channelNames"] = channelNamesData; vector<string> &channelNames = channelNamesData->writable(); size_t i = 0; for( ImagePlugIterator it( inPlugs() ); !it.done(); ++i, ++it ) { /// \todo We need this check because an unconnected input /// has a default channelNames value of [ "R", "G", "B" ], /// when it should have an empty default instead. Fix /// the ImagePlug constructor and remove the check. if( !(*it)->getInput<Plug>() ) { continue; } ConstStringVectorDataPtr inputChannelNamesData = (*it)->channelNamesPlug()->getValue(); const vector<string> &inputChannelNames = inputChannelNamesData->readable(); for( vector<string>::const_iterator cIt = inputChannelNames.begin(), ceIt = inputChannelNames.end(); cIt != ceIt; ++cIt ) { if( i > 0 && !StringAlgo::matchMultiple( *cIt, channelMatchPatterns ) ) { continue; } if( find( channelNames.begin(), channelNames.end(), *cIt ) == channelNames.end() ) { channelNames.push_back( *cIt ); } result->members()[*cIt] = new IntData( i ); } } static_cast<CompoundObjectPlug *>( output )->setValue( result ); return; } ImageProcessor::compute( output, context ); }
DeepImageWriter::DeepImageWriter( const std::string &description ) : Parameterised( description ) { m_fileNameParameter = new FileNameParameter( "fileName", "The filename to be written to.", "", "", false ); StringVectorDataPtr defaultChannels = new StringVectorData(); std::vector<std::string> &channels = defaultChannels->writable(); channels.push_back( "R" ); channels.push_back( "G" ); channels.push_back( "B" ); channels.push_back( "A" ); m_channelsParameter = new StringVectorParameter( "channelNames", "The list of channels to write.", defaultChannels ); m_resolutionParameter = new V2iParameter( "resolution", "The resolution of the image to write.", new V2iData( Imath::V2i( 2048, 1556 ) ) ); parameters()->addParameter( m_fileNameParameter ); parameters()->addParameter( m_channelsParameter ); parameters()->addParameter( m_resolutionParameter ); parameters()->addParameter( new M44fParameter( "worldToCameraMatrix", "world to camera space transformation matrix", new M44fData() ) ); parameters()->addParameter( new M44fParameter( "worldToNDCMatrix", "world to screen space projection matrix", new M44fData() ) ); }
IECore::DataPtr RenderManShader::parameterValue( const Gaffer::Plug *parameterPlug, NetworkBuilder &network ) const { if( parameterPlug->typeId() == Plug::staticTypeId() ) { // coshader parameter const Plug *inputPlug = parameterPlug->source<Plug>(); if( inputPlug && inputPlug != parameterPlug ) { const RenderManShader *inputShader = inputPlug->parent<RenderManShader>(); if( inputShader ) { const std::string &handle = network.shaderHandle( inputShader ); if( handle.size() ) { return new StringData( handle ); } } } } else if( parameterPlug->isInstanceOf( ArrayPlug::staticTypeId() ) ) { // coshader array parameter StringVectorDataPtr value = new StringVectorData(); for( InputPlugIterator cIt( parameterPlug ); cIt != cIt.end(); ++cIt ) { const Plug *inputPlug = (*cIt)->source<Plug>(); const RenderManShader *inputShader = inputPlug && inputPlug != *cIt ? inputPlug->parent<RenderManShader>() : 0; if( inputShader ) { value->writable().push_back( network.shaderHandle( inputShader ) ); } else { value->writable().push_back( "" ); } } return value; } return Shader::parameterValue( parameterPlug, network ); }
static IECore::DataPtr convertMetadata( const OSLQuery::Parameter &metadata ) { if( metadata.type == TypeDesc::FLOAT ) { return new IECore::FloatData( metadata.fdefault[0] ); } else if( metadata.type == TypeDesc::INT ) { return new IECore::IntData( metadata.idefault[0] ); } else if( metadata.type == TypeDesc::STRING ) { return new IECore::StringData( metadata.sdefault[0].c_str() ); } else if( metadata.type.aggregate == TypeDesc::VEC3 ) { if( metadata.type.basetype == TypeDesc::FLOAT ) { if( metadata.type.vecsemantics == TypeDesc::COLOR ) { return new IECore::Color3fData( Imath::Color3f( metadata.fdefault[0], metadata.fdefault[1], metadata.fdefault[2] ) ); } else { return new IECore::V3fData( Imath::V3f( metadata.fdefault[0], metadata.fdefault[1], metadata.fdefault[2] ) ); } } else { return new IECore::V3iData( Imath::V3i( metadata.idefault[0], metadata.idefault[1], metadata.idefault[2] ) ); } } else if( metadata.type.arraylen > 0 ) { if( metadata.type.elementtype() == TypeDesc::FLOAT ) { return new FloatVectorData( metadata.fdefault ); } else if( metadata.type.elementtype() == TypeDesc::INT ) { return new IntVectorData( metadata.idefault ); } else if( metadata.type.elementtype() == TypeDesc::STRING ) { StringVectorDataPtr result = new StringVectorData; for( vector<ustring>::const_iterator it = metadata.sdefault.begin(), eIt = metadata.sdefault.end(); it != eIt; ++it ) { result->writable().push_back( it->string() ); } return result; } } IECore::msg( IECore::Msg::Warning, "OSLShader", string( "Metadata \"" ) + metadata.name.c_str() + "\" has unsupported type" ); return NULL; }
CompoundDataPtr BGEOParticleReader::readAttributes( const std::vector<std::string> &names ) { if( !open() ) { return 0; } CompoundDataPtr result = new CompoundData(); std::vector< struct AttrInfo > attrInfo; int intAttribBuffer[ 3 ]; int *intAttributePtr = &intAttribBuffer[0]; float floatAttribBuffer[ 4 ]; float *floatAttributePtr = &floatAttribBuffer[0]; vector<Record>::const_iterator it; for( it=m_header.attributes.begin(); it!=m_header.attributes.end(); it++ ) { V3fVectorDataPtr v3fVector = 0; V2fVectorDataPtr v2fVector = 0; FloatVectorDataPtr floatVector = 0; IntVectorDataPtr intVector = 0; StringVectorDataPtr stringVector = 0; DataPtr dataVector = 0; if ( it->size == 1 ) { if ( it->type == Float ) { floatVector = new FloatVectorData(); floatVector->writable().resize( numParticles() ); dataVector = floatVector; } else if ( it->type == Integer ) { intVector = new IntVectorData(); intVector->writable().resize( numParticles() ); dataVector = intVector; } else if ( it->type == Index ) { stringVector = new StringVectorData(); stringVector->writable().resize( numParticles() ); dataVector = stringVector; } } else if ( it->size == 2 ) { v2fVector = new V2fVectorData(); v2fVector->writable().resize( numParticles() ); dataVector = v2fVector; } else if ( it->size == 3 || it->size == 4 ) { v3fVector = new V3fVectorData(); v3fVector->writable().resize( numParticles() ); dataVector = v3fVector; } else { msg( Msg::Error, "BGEOParticleReader::readAttributes()", format( "Internal error. Unrecognized type '%d' of size '%d' while loading attribute %s." ) % it->type % it->size % it->name ); return 0; } AttrInfo info = { *it, dataVector, }; attrInfo.push_back( info ); } // read all of the data at once std::vector<char> dataBuffer; dataBuffer.resize( m_header.numPoints * m_header.dataSize ); char *dataBufferPtr = &dataBuffer[0]; m_iStream->seekg( ios_base::beg + m_header.firstPointPosition ); m_iStream->read( dataBufferPtr, m_header.numPoints * m_header.dataSize ); for ( int i = 0; i < m_header.numPoints; i++) { std::vector< struct AttrInfo >::iterator it; for (it = attrInfo.begin(); it != attrInfo.end(); it++) { // P contains an additional byte in the BGEO if ( it->info.type == Integer || it->info.type == Index ) { readAttributeData( &dataBufferPtr, intAttributePtr, it->info.size ); } else { readAttributeData( &dataBufferPtr, floatAttributePtr, it->info.size ); } switch (it->targetData->typeId()) { case V3fVectorDataTypeId: { V3f &p = staticPointerCast<V3fVectorData>(it->targetData)->writable()[ i ]; p[0] = floatAttributePtr[0]; p[1] = floatAttributePtr[1]; p[2] = floatAttributePtr[2]; break; } case V2fVectorDataTypeId: { V2f &p = staticPointerCast<V2fVectorData>(it->targetData)->writable()[ i ]; p[0] = floatAttributePtr[0]; p[1] = floatAttributePtr[1]; break; } case FloatVectorDataTypeId: staticPointerCast<FloatVectorData>(it->targetData)->writable()[ i ] = floatAttributePtr[0]; break; case IntVectorDataTypeId: staticPointerCast<IntVectorData>(it->targetData)->writable()[ i ] = intAttributePtr[0]; break; case StringVectorDataTypeId: { std::string value = it->info.indexableValues.at( intAttributePtr[0] ); staticPointerCast<StringVectorData>(it->targetData)->writable()[ i ] = value; break; } default: msg( Msg::Error, "BGEOParticleReader::readAttributes()", format( "Internal error. Unrecognized typeId '%d'." ) % it->targetData->typeId() ); return 0; } } } /// \todo Use particle ids for filtering. const Data *ids = 0; DataPtr filteredData = 0; // filter and convert each attribute individually. std::vector< struct AttrInfo >::const_iterator attrIt; for( attrIt=attrInfo.begin(); attrIt!=attrInfo.end(); attrIt++ ) { // The data had to be read, but we don't need to filter or store it if( find( names.begin(), names.end(), attrIt->info.name ) == names.end() ) { continue; } if ( attrIt->info.size == 1 ) { if ( attrIt->info.type == Float ) { switch( realType() ) { case ParticleReader::Native : case ParticleReader::Float : filteredData = filterAttr<FloatVectorData, FloatVectorData>( staticPointerCast<FloatVectorData>(attrIt->targetData), particlePercentage(), ids ); break; case ParticleReader::Double : filteredData = filterAttr<DoubleVectorData, FloatVectorData>( staticPointerCast<FloatVectorData>(attrIt->targetData), particlePercentage(), ids ); break; } } else if ( attrIt->info.type == Integer ) { filteredData = filterAttr<IntVectorData, IntVectorData>( staticPointerCast<IntVectorData>(attrIt->targetData), particlePercentage(), ids ); } else if ( attrIt->info.type == Index ) { filteredData = filterAttr<StringVectorData, StringVectorData>( staticPointerCast<StringVectorData>(attrIt->targetData), particlePercentage(), ids ); } } else if ( attrIt->info.size == 2 ) { if ( attrIt->info.type == Float ) { switch( realType() ) { case ParticleReader::Native : case ParticleReader::Float : filteredData = filterAttr<V2fVectorData, V2fVectorData>( staticPointerCast<V2fVectorData>(attrIt->targetData), particlePercentage(), ids ); break; case ParticleReader::Double : filteredData = filterAttr<V2dVectorData, V2fVectorData>( staticPointerCast<V2fVectorData>(attrIt->targetData), particlePercentage(), ids ); break; } } } else if ( attrIt->info.size == 3 || attrIt->info.size == 4 ) { if ( ( attrIt->info.type == Float ) || ( attrIt->info.type == Vector ) ) { switch( realType() ) { case ParticleReader::Native : case ParticleReader::Float : filteredData = filterAttr<V3fVectorData, V3fVectorData>( staticPointerCast<V3fVectorData>(attrIt->targetData), particlePercentage(), ids ); break; case ParticleReader::Double : filteredData = filterAttr<V3dVectorData, V3fVectorData>( staticPointerCast<V3fVectorData>(attrIt->targetData), particlePercentage(), ids ); break; } } } else { msg( Msg::Error, "BGEOParticleReader::readAttributes()", format( "Internal error. Unrecognized type '%d' of size '%d' while converting attribute %s." ) % attrIt->info.type % attrIt->info.size % attrIt->info.name ); return 0; } result->writable()[attrIt->info.name] = filteredData; } return result; }
void SceneView::updateLookThrough() { Context::Scope scopedContext( getContext() ); const ScenePlug *scene = preprocessedInPlug<ScenePlug>(); ConstCompoundObjectPtr globals = scene->globalsPlug()->getValue(); string cameraPathString; IECore::CameraPtr camera; if( lookThroughEnabledPlug()->getValue() ) { cameraPathString = lookThroughCameraPlug()->getValue(); if( cameraPathString.empty() ) { if( const StringData *cameraPathData = globals->member<StringData>( "render:camera" ) ) { cameraPathString = cameraPathData->readable(); } } if( !cameraPathString.empty() ) { ScenePlug::ScenePath cameraPath; ScenePlug::stringToPath( cameraPathString, cameraPath ); try { ConstCameraPtr constCamera = runTimeCast<const IECore::Camera>( scene->object( cameraPath ) ); if( constCamera ) { camera = constCamera->copy(); camera->setTransform( new MatrixTransform( scene->fullTransform( cameraPath ) ) ); // if the camera has an existing screen window, remove it. // if we didn't, it would conflict with the resolution we set // below, yielding squashed/stretched images. /// \todo Properly specify how cameras are represented in Gaffer /// (the Cortex representation is very renderer-centric, with no /// real world parameters like film back) so that this isn't necessary, /// and add nice overlays for resolution gate etc. camera->parameters().erase( "screenWindow" ); } } catch( ... ) { // if an invalid path has been entered for the camera, computation will fail. // we can just ignore that and fall through to lock to the current camera instead. cameraPathString = ""; } } if( !camera ) { // we couldn't find a render camera to lock to, but we can lock to the current // camera instead. camera = viewportGadget()->getCamera()->copy(); } } if( camera ) { camera->parameters()["resolution"] = new V2iData( viewportGadget()->getViewport() ); viewportGadget()->setCamera( camera ); viewportGadget()->setCameraEditable( false ); StringVectorDataPtr invisiblePaths = new StringVectorData(); invisiblePaths->writable().push_back( cameraPathString ); hideFilter()->pathsPlug()->setValue( invisiblePaths ); } else { viewportGadget()->setCameraEditable( true ); hideFilter()->pathsPlug()->setToDefault(); } }
ObjectPtr SLOReader::doOperation( const CompoundObject * operands ) { tbb::mutex::scoped_lock lock( g_mutex ); if( Slo_SetShader( (char *)fileName().c_str() ) ) { throw Exception( boost::str( boost::format( "Unable to set shader to \"%s\"" ) % fileName() ) ); } string name = Slo_GetName(); string type = Slo_TypetoStr( Slo_GetType() ); ShaderPtr result = new Shader( name, type ); CompoundDataPtr typeHints = new CompoundData; result->blindData()->writable().insert( pair<string, DataPtr>( "ri:parameterTypeHints", typeHints ) ); // we lose the ordering of parameter names when we put them in result->parameters(), // so we stick the correct order in the blind data as a workaround for anyone interested // in the true ordering. StringVectorDataPtr orderedParameterNames = new StringVectorData; result->blindData()->writable().insert( pair<string, DataPtr>( "ri:orderedParameterNames", orderedParameterNames ) ); // we don't have a way of communicating which parameters are outputs in the Shader::parametersData(), // so we work around that using the blind data too. StringVectorDataPtr outputParameterNames = new StringVectorData; result->blindData()->writable().insert( pair<string, DataPtr>( "ri:outputParameterNames", outputParameterNames ) ); int numArgs = Slo_GetNArgs(); for( int i=1; i<=numArgs; i++ ) { DataPtr data = 0; SLO_VISSYMDEF *arg = Slo_GetArgById( i ); switch( arg->svd_type ) { case SLO_TYPE_POINT : case SLO_TYPE_VECTOR : case SLO_TYPE_NORMAL : { if( arg->svd_arraylen==0 ) { const SLO_POINT *p = arg->svd_default.pointval; if( p ) { data = new V3fData( V3f( p->xval, p->yval, p->zval ) ); } else { // 0 length and null value signifies a variable length array data = new V3fVectorData(); } } else { V3fVectorDataPtr vData = new V3fVectorData(); data = vData; for( int j=0; j<arg->svd_arraylen; j++ ) { SLO_VISSYMDEF *a = Slo_GetArrayArgElement( arg, j ); const SLO_POINT *p = a->svd_default.pointval; vData->writable().push_back( V3f( p->xval, p->yval, p->zval ) ); } } typeHints->writable().insert( pair<string, DataPtr>( arg->svd_name, new StringData( Slo_TypetoStr( arg->svd_type ) ) ) ); break; } case SLO_TYPE_COLOR : { if( arg->svd_arraylen==0 ) { const SLO_POINT *p = arg->svd_default.pointval; if( p ) { data = new Color3fData( Color3f( p->xval, p->yval, p->zval ) ); } else { // 0 length and null value signifies a variable length array data = new Color3fVectorData(); } } else { Color3fVectorDataPtr vData = new Color3fVectorData(); data = vData; for( int j=0; j<arg->svd_arraylen; j++ ) { SLO_VISSYMDEF *a = Slo_GetArrayArgElement( arg, j ); const SLO_POINT *p = a->svd_default.pointval; vData->writable().push_back( Color3f( p->xval, p->yval, p->zval ) ); } } } break; case SLO_TYPE_SCALAR : { if( arg->svd_arraylen==0 ) { const float *value = arg->svd_default.scalarval; if( value ) { data = new FloatData( *value ); } else { // 0 length and null value signifies a variable length array data = new FloatVectorData(); } } else { FloatVectorDataPtr vData = new FloatVectorData(); data = vData; for( int j=0; j<arg->svd_arraylen; j++ ) { SLO_VISSYMDEF *a = Slo_GetArrayArgElement( arg, j ); vData->writable().push_back( *(a->svd_default.scalarval) ); } if( arg->svd_arraylen==3 ) { // allow V3fData and V3fVectorData to be mapped to float[3] parameters. typeHints->writable().insert( pair<string, DataPtr>( arg->svd_name, new StringData( "float[3]" ) ) ); } } } break; case SLO_TYPE_STRING : { if( arg->svd_arraylen==0 ) { const char *defaultValue = arg->svd_default.stringval; if( defaultValue ) { data = new StringData( defaultValue ); } else { // 0 length and null value signifies a variable length array data = new StringVectorData(); } } else { StringVectorDataPtr vData = new StringVectorData(); data = vData; for( int j=0; j<arg->svd_arraylen; j++ ) { SLO_VISSYMDEF *a = Slo_GetArrayArgElement( arg, j ); // sometimes the default value for an element of a string array can be a null pointer. // i'm not sure what the meaning of this is. the 3delight shaderinfo utility reports such values // as "(null)", so that's what we do too. const char *defaultValue = a->svd_default.stringval; vData->writable().push_back( defaultValue ? defaultValue : "(null)" ); } } } break; case SLO_TYPE_MATRIX : { if( arg->svd_arraylen==0 ) { const float *m = arg->svd_default.matrixval; if( m ) { M44f mm( m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15] ); data = new M44fData( mm ); } else { // 0 length and null value signifies a variable length array data = new M44fVectorData(); } } else { M44fVectorDataPtr vData = new M44fVectorData(); data = vData; for( int j=0; j<arg->svd_arraylen; j++ ) { SLO_VISSYMDEF *a = Slo_GetArrayArgElement( arg, j ); const float *m = a->svd_default.matrixval; M44f mm( m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15] ); vData->writable().push_back( mm ); } } } break; case SLO_TYPE_SHADER : { if( arg->svd_arraylen==0 ) { if( !arg->svd_valisvalid ) { // variable length array data = new StringVectorData(); } else { data = new StringData(); } } else { StringVectorDataPtr sData = new StringVectorData(); data = sData; sData->writable().resize( arg->svd_arraylen ); } typeHints->writable().insert( pair<string, DataPtr>( arg->svd_name, new StringData( Slo_TypetoStr( arg->svd_type ) ) ) ); } break; default : msg( Msg::Warning, "SLOReader::read", format( "Parameter \"%s\" has unsupported type." ) % arg->svd_name ); } if( data ) { orderedParameterNames->writable().push_back( arg->svd_name ); result->parameters().insert( CompoundDataMap::value_type( arg->svd_name, data ) ); if( arg->svd_storage == SLO_STOR_OUTPUTPARAMETER ) { outputParameterNames->writable().push_back( arg->svd_name ); } } } // shader annotations CompoundDataPtr annotations = new CompoundData; result->blindData()->writable().insert( pair<string, DataPtr>( "ri:annotations", annotations ) ); #ifndef PRMANEXPORT for( int i=1, n=Slo_GetNAnnotations(); i <= n; i++ ) { const char *key = Slo_GetAnnotationKeyById( i ); annotations->writable()[key] = new StringData( Slo_GetAnnotationByKey( key ) ); } #endif Slo_EndShader(); return result; }
void ToHoudiniGeometryConverter::transferAttribValues( const Primitive *primitive, GU_Detail *geo, const GA_Range &points, const GA_Range &prims, PrimitiveVariable::Interpolation vertexInterpolation, PrimitiveVariable::Interpolation primitiveInterpolation, PrimitiveVariable::Interpolation pointInterpolation, PrimitiveVariable::Interpolation detailInterpolation ) const { GA_OffsetList offsets; if ( prims.isValid() ) { const GA_PrimitiveList &primitives = geo->getPrimitiveList(); for ( GA_Iterator it=prims.begin(); !it.atEnd(); ++it ) { const GA_Primitive *prim = primitives.get( it.getOffset() ); size_t numPrimVerts = prim->getVertexCount(); for ( size_t v=0; v < numPrimVerts; v++ ) { if ( prim->getTypeId() == GEO_PRIMPOLY ) { offsets.append( prim->getVertexOffset( numPrimVerts - 1 - v ) ); } else { offsets.append( prim->getVertexOffset( v ) ); } } } } GA_Range vertRange( geo->getVertexMap(), offsets ); UT_String filter( attributeFilterParameter()->getTypedValue() ); // match all the string variables to each associated indices variable /// \todo: replace all this logic with IECore::IndexedData once it exists... PrimitiveVariableMap stringsToIndices; for ( PrimitiveVariableMap::const_iterator it=primitive->variables.begin() ; it != primitive->variables.end(); it++ ) { if ( !primitive->isPrimitiveVariableValid( it->second ) ) { IECore::msg( IECore::MessageHandler::Warning, "ToHoudiniGeometryConverter", "PrimitiveVariable " + it->first + " is invalid. Ignoring." ); filter += UT_String( " ^" + it->first ); continue; } ToHoudiniAttribConverterPtr converter = ToHoudiniAttribConverter::create( it->second.data ); if ( !converter ) { continue; } if ( it->second.data->isInstanceOf( StringVectorDataTypeId ) ) { std::string indicesVariableName = it->first + "Indices"; PrimitiveVariableMap::const_iterator indices = primitive->variables.find( indicesVariableName ); if ( indices != primitive->variables.end() && indices->second.data->isInstanceOf( IntVectorDataTypeId ) && primitive->isPrimitiveVariableValid( indices->second ) ) { stringsToIndices[it->first] = indices->second; filter += UT_String( " ^" + indicesVariableName ); } } } bool convertStandardAttributes = m_convertStandardAttributesParameter->getTypedValue(); if ( convertStandardAttributes && UT_String( "s" ).multiMatch( filter ) && UT_String( "t" ).multiMatch( filter ) ) { // convert s and t to uv PrimitiveVariableMap::const_iterator sPrimVar = primitive->variables.find( "s" ); PrimitiveVariableMap::const_iterator tPrimVar = primitive->variables.find( "t" ); if ( sPrimVar != primitive->variables.end() && tPrimVar != primitive->variables.end() ) { if ( sPrimVar->second.interpolation == tPrimVar->second.interpolation ) { const FloatVectorData *sData = runTimeCast<const FloatVectorData>( sPrimVar->second.data ); const FloatVectorData *tData = runTimeCast<const FloatVectorData>( tPrimVar->second.data ); if ( sData && tData ) { const std::vector<float> &s = sData->readable(); const std::vector<float> &t = tData->readable(); std::vector<Imath::V3f> uvw; uvw.reserve( s.size() ); for ( size_t i=0; i < s.size(); ++i ) { uvw.push_back( Imath::V3f( s[i], 1 - t[i], 0 ) ); } GA_Range range = vertRange; if ( sPrimVar->second.interpolation == pointInterpolation ) { range = points; } ToHoudiniAttribConverterPtr converter = ToHoudiniAttribConverter::create( new V3fVectorData( uvw ) ); converter->convert( "uv", geo, range ); filter += " ^s ^t"; } } } } UT_StringMMPattern attribFilter; attribFilter.compile( filter ); // add the primitive variables to the various GEO_AttribDicts based on interpolation type for ( PrimitiveVariableMap::const_iterator it=primitive->variables.begin() ; it != primitive->variables.end(); it++ ) { UT_String varName( it->first ); if ( !varName.multiMatch( attribFilter ) ) { continue; } PrimitiveVariable primVar = processPrimitiveVariable( primitive, it->second ); ToHoudiniAttribConverterPtr converter = ToHoudiniAttribConverter::create( primVar.data ); if ( !converter ) { continue; } PrimitiveVariable::Interpolation interpolation = primVar.interpolation; if ( converter->isInstanceOf( (IECore::TypeId)ToHoudiniStringVectorAttribConverterTypeId ) ) { PrimitiveVariableMap::const_iterator indices = stringsToIndices.find( it->first ); if ( indices != stringsToIndices.end() ) { ToHoudiniStringVectorAttribConverter *stringVectorConverter = IECore::runTimeCast<ToHoudiniStringVectorAttribConverter>( converter ); PrimitiveVariable indicesPrimVar = processPrimitiveVariable( primitive, indices->second ); stringVectorConverter->indicesParameter()->setValidatedValue( indicesPrimVar.data ); interpolation = indices->second.interpolation; } } const std::string name = ( convertStandardAttributes ) ? processPrimitiveVariableName( it->first ) : it->first; if ( interpolation == detailInterpolation ) { // add detail attribs converter->convert( name, geo ); } else if ( interpolation == pointInterpolation ) { // add point attribs if ( name == "P" ) { // special case for P transferP( runTimeCast<const V3fVectorData>( primVar.data ), geo, points ); } else { converter->convert( name, geo, points ); } } else if ( interpolation == primitiveInterpolation ) { // add primitive attribs converter->convert( name, geo, prims ); } else if ( interpolation == vertexInterpolation ) { // add vertex attribs converter->convert( name, geo, vertRange ); } } // add the name attribute based on blindData const StringData *nameData = primitive->blindData()->member<StringData>( "name" ); if ( nameData ) { if ( prims.isValid() ) { StringVectorDataPtr nameVectorData = new StringVectorData(); nameVectorData->writable().push_back( nameData->readable() ); std::vector<int> indexValues( prims.getEntries(), 0 ); IntVectorDataPtr indexData = new IntVectorData( indexValues ); ToHoudiniStringVectorAttribConverterPtr converter = new ToHoudiniStringVectorAttribConverter( nameVectorData ); converter->indicesParameter()->setValidatedValue( indexData ); converter->convert( "name", geo, prims ); } } }
void DisplayDriverServer::Session::handleReadOpenParameters( const boost::system::error_code& error ) { if (error) { msg( Msg::Error, "DisplayDriverServer::Session::handleReadOpenParameters", error.message().c_str() ); m_socket.close(); return; } StringDataPtr displayDriverType; Box2iDataPtr displayWindow, dataWindow; StringVectorDataPtr channelNames; CompoundDataPtr parameters; bool scanLineOrder = false; bool acceptsRepeatedData = false; // handle imageOpen parameters. try { MemoryIndexedIOPtr io = new MemoryIndexedIO( m_buffer, IndexedIO::rootPath, IndexedIO::Exclusive | IndexedIO::Read ); displayWindow = staticPointerCast<Box2iData>( Object::load( io, "displayWindow" ) ); dataWindow = staticPointerCast<Box2iData>( Object::load( io, "dataWindow" ) ); channelNames = staticPointerCast<StringVectorData>( Object::load( io, "channelNames" ) ); parameters = staticPointerCast<CompoundData>( Object::load( io, "parameters" ) ); const StringData *displayType = parameters->member<StringData>( "remoteDisplayType", true /* throw if missing */ ); // create a displayDriver using the factory function. m_displayDriver = DisplayDriver::create( displayType->readable(), displayWindow->readable(), dataWindow->readable(), channelNames->readable(), parameters ); scanLineOrder = m_displayDriver->scanLineOrderOnly(); acceptsRepeatedData = m_displayDriver->acceptsRepeatedData(); } catch( std::exception &e ) { msg( Msg::Error, "DisplayDriverServer::Session::handleReadOpenParameters", e.what() ); sendException( e.what() ); m_socket.close(); return; } try { // send the result back. sendResult( DisplayDriverServerHeader::imageOpen, sizeof(scanLineOrder) ); m_socket.send( boost::asio::buffer( &scanLineOrder, sizeof(scanLineOrder) ) ); sendResult( DisplayDriverServerHeader::imageOpen, sizeof(acceptsRepeatedData) ); m_socket.send( boost::asio::buffer( &acceptsRepeatedData, sizeof(acceptsRepeatedData) ) ); // prepare for getting imageData packages boost::asio::async_read( m_socket, boost::asio::buffer( m_header.buffer(), m_header.headerLength), boost::bind( &DisplayDriverServer::Session::handleReadHeader, SessionPtr(this), boost::asio::placeholders::error ) ); } catch( std::exception &e ) { msg( Msg::Error, "DisplayDriverServer::Session::handleReadOpenParameters", e.what() ); m_socket.close(); } }