void RedBufferInput::SetPos(int iNewPos) { // if we jump forward, we can't determine if a newline has been missed, so // need to mandate backwards travel only. if (iNewPos > iCharPos) throw; // assign the new position iCharPos = iNewPos; // now lookup the old row/col so we can track the text position. ListItType cIt(&cNewLineCharPosList); cIt.First(); int iFoundLine=0; while( (!cIt.IsDone()) && (!iFoundLine) ) { // get the current line and character positions. When the search is done, // the iteration will need to have overstepped the actual char pos, so // keeping a previous version. int iCurrLineCharPos = cIt.CurrentItem(); int iCurrLineNumber = cIt.CollectionIndex(); int iPrevLineCharPos = iCurrLineCharPos; int iPrevLineNumber = iCurrLineNumber; if (iNewPos <= iCurrLineCharPos) { iRow = iPrevLineNumber; iCol = iNewPos - iPrevLineCharPos; iFoundLine = 1; } cIt.Next(); } }
IECore::ConstStringVectorDataPtr Merge::computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const { IECore::StringVectorDataPtr outChannelStrVectorData( new IECore::StringVectorData() ); std::vector<std::string> &outChannels( outChannelStrVectorData->writable() ); // Iterate over the connected inputs. const ImagePlugList& inputs( m_inputs.inputs() ); const ImagePlugList::const_iterator end( m_inputs.endIterator() ); for ( ImagePlugList::const_iterator it( inputs.begin() ); it != end; ++it ) { if ( (*it)->getInput<ValuePlug>() ) { IECore::ConstStringVectorDataPtr inChannelStrVectorData((*it)->channelNamesPlug()->getValue() ); const std::vector<std::string> &inChannels( inChannelStrVectorData->readable() ); for ( std::vector<std::string>::const_iterator cIt( inChannels.begin() ); cIt != inChannels.end(); ++cIt ) { if ( std::find( outChannels.begin(), outChannels.end(), *cIt ) == outChannels.end() ) { outChannels.push_back( *cIt ); } } } } if ( !outChannels.empty() ) { return outChannelStrVectorData; } return inPlug()->channelNamesPlug()->defaultValue(); }
void ParametersInterpreter<NMSmodelT>::getUpperLowerBounds(std::vector<double>& upperBounds, std::vector<double>& lowerBounds) const { upperBounds.clear(); lowerBounds.clear(); for (typename ParametersMap::const_iterator it(parameters_.begin()); it != parameters_.end(); ++it) { if (it->second.boundaryType == Parameter::RelativeToSubjectValue) { std::vector<double> coefficients, groupedCoefficients; getCoefficients(it->first, coefficients); groupValues(it->second.muscleGroups, coefficients, groupedCoefficients); for (std::vector<double>::const_iterator cIt(groupedCoefficients.begin()); cIt != groupedCoefficients.end(); ++cIt) { double upperBoundValue = *cIt * (it->second.upperLimit); double lowerBoundValue = *cIt * (it->second.lowerLimit); upperBounds.push_back(upperBoundValue); lowerBounds.push_back(lowerBoundValue); } } else { upperBounds.insert(upperBounds.end(), it->second.size, it->second.upperLimit); lowerBounds.insert(lowerBounds.end(), it->second.size, it->second.lowerLimit); } } }
void ComplexSceneManager::scanParamFile( const Char8 *szFilename, std::vector<std::string> &vParams ) { FILE *pIn = fopen(szFilename, "r"); Char8 szRow[1024]; std::string szBuffer; const Char8 *szDelim = " \t\n "; vParams.clear(); while(!feof(pIn)) { fgets(szRow, 1024, pIn); szBuffer = szRow; if(feof(pIn) || szBuffer.empty() == true || szBuffer[0] == '\n' || szBuffer[0] == '#' ) { continue; } string_token_iterator cIt (szBuffer, szDelim); string_token_iterator cEnd; while(cIt != cEnd) { vParams.push_back(*cIt); ++cIt; } } fclose(pIn); }
void TiledImageBlockAccessor::open(const Char8 *szFilename) { fprintf(stderr, "Open Tiled %s\n", szFilename); FILE *pFile = fopen(szFilename, "r"); Char8 szRow[1024]; const Char8 *szDelim = " \t\n "; std::string szBuffer; if(pFile != NULL) { while(!feof(pFile)) { fgets(szRow, 1024, pFile); szBuffer.append(szRow); } PathHandler *pOrgHandler = ImageFileHandler::the()->getPathHandler(); PathHandler tmpHandler; tmpHandler.setBaseFile(szFilename); ImageFileHandler::the()->setPathHandler(&tmpHandler); fprintf(stderr, "got %s\n", szBuffer.c_str()); string_token_iterator cIt (szBuffer, szDelim); string_token_iterator cEnd; _uiColumns = TypeTraits<UInt32>::getFromCString((*cIt).c_str()); fprintf(stderr, "C: %d\n", _uiColumns); ++cIt; _uiRows = TypeTraits<UInt32>::getFromCString((*cIt).c_str()); fprintf(stderr, "R: %d\n", _uiRows); ++cIt; for(UInt32 i = 0; i < _uiRows * _uiColumns; ++i) { if(cIt == cEnd) { break; } fprintf(stderr, "File -%s-\n", (*cIt).c_str()); ImageBlockAccessorPtr pAccess; if(strncmp((*cIt).c_str(), "default:", 7) == 0) { DefaultBlockAccessorPtr pDefAccess( new DefaultBlockAccessor()); pAccess = pDefAccess; pDefAccess->open((*cIt).c_str()); } else { pAccess = ImageFileHandler::the()->open((*cIt).c_str()); } _vImages.push_back(pAccess); ++cIt; } ImageFileHandler::the()->setPathHandler(pOrgHandler); if(_vImages.size() != _uiRows * _uiColumns || _vImages.size() == 0) { fprintf(stderr, "Images missing %" PRISize " %d\n", _vImages.size(), _uiRows * _uiColumns); _vImages.clear(); return; } _vSampleDescs.resize(_vImages.size()); UInt32 uiIdx = 0; UInt32 uiOtherIdx = 0; _vSampleDescs[0].setBounds( 0, 0, _vImages[0]->getSize()[0], _vImages[0]->getSize()[1]); for(UInt32 i = 1; i < _uiRows; ++i) { uiIdx = i * _uiColumns; uiOtherIdx = uiIdx - _uiColumns; _vSampleDescs[uiIdx].setBounds( _vSampleDescs[uiOtherIdx].x0, _vSampleDescs[uiOtherIdx].y1, _vImages [uiIdx ]->getSize()[0], _vImages [uiIdx ]->getSize()[1]); } for(UInt32 i = 1; i < _uiColumns; ++i) { _vSampleDescs[i].setBounds( _vSampleDescs[i - 1].x1, _vSampleDescs[i - 1].y0, _vImages [i ]->getSize()[0], _vImages [i ]->getSize()[1]); } for(UInt32 i = 1; i < _uiRows; ++i) { for(UInt32 j = 1; j < _uiColumns; ++j) { uiIdx = i * _uiColumns + j; uiOtherIdx = (i - 1) * _uiColumns + (j - 1); _vSampleDescs[uiIdx].setBounds( _vSampleDescs[uiOtherIdx].x1, _vSampleDescs[uiOtherIdx].y1, _vImages [uiIdx ]->getSize()[0], _vImages [uiIdx ]->getSize()[1]); } } for(UInt32 i = 0; i < _uiRows; ++i) { for(UInt32 j = 0; j < _uiColumns; ++j) { uiIdx = i * _uiColumns + j; fprintf(stderr, "(%d)(%d %d) | %d %d %d %d\n", uiIdx, i, j, _vSampleDescs[uiIdx].x0, _vSampleDescs[uiIdx].y0, _vSampleDescs[uiIdx].x1, _vSampleDescs[uiIdx].y1); } } _vSize.setValues(_vSampleDescs.back().x1, _vSampleDescs.back().y1); GeoReferenceAttachment *pFirstRef = _vImages.front()->getGeoRef(); if(pFirstRef != NULL) { _pGeoRef = GeoReferenceAttachment::create(); _pGeoRef->setOrigin (pFirstRef->getOrigin ()); _pGeoRef->setPixelSize (pFirstRef->getPixelSize ()); _pGeoRef->setEllipsoidAxis(pFirstRef->getEllipsoidAxis()); _pGeoRef->setDatum (pFirstRef->getDatum ()); _pGeoRef->setNoDataValue (pFirstRef->getNoDataValue ()); } _eImgType = _vImages.front()->getType (); _eImgFormat = _vImages.front()->getFormat(); _fNoDataValue = _vImages.front()->getNoDataValue(); fclose(pFile); } }
void DefaultBlockAccessor::open(const Char8 *szFilename) { fprintf(stderr, "OpenDefault %s\n", szFilename); std::string szFName(szFilename); Char8 const *szDelim = ":"; string_token_iterator cIt (szFName, szDelim); string_token_iterator cEnd; fprintf(stderr, "File -%s-\n", (*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _iDefaultValue = TypeTraits<Int32>::getFromCString((*cIt).c_str()); fprintf(stderr, "Def %d\n", _iDefaultValue); ++cIt; if(cIt == cEnd) return; _vSize[0] = TypeTraits<Int32>::getFromCString((*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _vSize[1] = TypeTraits<Int32>::getFromCString((*cIt).c_str()); fprintf(stderr, "Size %d %d\n", _vSize[0], _vSize[1]); ++cIt; if(cIt == cEnd) return; _eImgType = Image::Type(TypeTraits<UInt32>::getFromCString((*cIt).c_str())); ++cIt; if(cIt == cEnd) return; _eImgFormat = Image::PixelFormat(TypeTraits<UInt32>::getFromCString((*cIt).c_str())); fprintf(stderr, "T: %x F: %x\n", _eImgType, _eImgFormat); ++cIt; if(cIt == cEnd) return; _pGeoRef = GeoReferenceAttachment::create(); _pGeoRef->editOrigin()[0] = TypeTraits<Real32>::getFromCString((*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _pGeoRef->editOrigin()[1] = TypeTraits<Real32>::getFromCString((*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _pGeoRef->editPixelSize()[0] = TypeTraits<Real32>::getFromCString((*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _pGeoRef->editPixelSize()[1] = TypeTraits<Real32>::getFromCString((*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _pGeoRef->editDatum() = TypeTraits<UInt32>::getFromCString((*cIt).c_str()); ++cIt; if(cIt == cEnd) return; _pGeoRef->editEllipsoidAxis()[0] = TypeTraits<Real32>::getFromCString((*cIt).c_str()); _pGeoRef->editEllipsoidAxis()[1] = TypeTraits<Real32>::getFromCString((*cIt).c_str()); fprintf(stderr, "GeoRef : %f %f | %f %f | %d | %f %f\n", _pGeoRef->getOrigin()[0], _pGeoRef->getOrigin()[1], _pGeoRef->getPixelSize()[0], _pGeoRef->getPixelSize()[1], _pGeoRef->getDatum(), _pGeoRef->getEllipsoidAxis()[0], _pGeoRef->getEllipsoidAxis()[1]); }