本文整理汇总了C++中Box2i类的典型用法代码示例。如果您正苦于以下问题:C++ Box2i类的具体用法?C++ Box2i怎么用?C++ Box2i使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Box2i类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
ReturnType operator()( T *dataContainer )
{
assert( dataContainer );
const typename T::ValueType &data = dataContainer->readable();
ScaledDataConversion<typename T::ValueType::value_type, float> converter;
typedef boost::multi_array_ref< const typename T::ValueType::value_type, 2 > SourceArray2D;
typedef boost::multi_array_ref< unsigned int, 2 > TargetArray2D;
// Grab the display and data windows to avoid dereferencing pointers during the tight loop later...
const Box2i srcDisplayWindow = m_image->getDisplayWindow();
const Box2i srcDataWindow = m_image->getDataWindow();
const SourceArray2D sourceData( &data[0], extents[ srcDataWindow.size().y + 1 ][ srcDataWindow.size().x + 1 ] );
TargetArray2D targetData( &m_imageBuffer[0], extents[ srcDisplayWindow.size().y + 1 ][ srcDisplayWindow.size().x + 1 ] );
const Box2i copyRegion = boxIntersection( m_dataWindow, boxIntersection( srcDisplayWindow, srcDataWindow ) );
const unsigned int boxOffsetX = copyRegion.min.x - srcDisplayWindow.min.x;
const unsigned int boxOffsetY = copyRegion.min.y - srcDisplayWindow.min.y;
for ( int y = copyRegion.min.y; y <= copyRegion.max.y ; y++ )
{
for ( int x = copyRegion.min.x; x <= copyRegion.max.x ; x++ )
{
targetData[ (y - copyRegion.min.y) + boxOffsetY ][ (x - copyRegion.min.x) + boxOffsetX ]
|= std::min((unsigned int)1023, (unsigned int)(converter( sourceData[ y - srcDataWindow.min.y ][ x - srcDataWindow.min.x ] ) * 1023 )) << m_bitShift;
}
}
};
示例2: formatPlug
IECore::ImagePrimitivePtr ImagePlug::image() const
{
Format format = formatPlug()->getValue();
Box2i dataWindow = dataWindowPlug()->getValue();
Box2i newDataWindow( Imath::V2i(0) );
if( dataWindow.isEmpty() )
{
dataWindow = Box2i( Imath::V2i(0) );
}
else
{
newDataWindow = format.yDownToFormatSpace( dataWindow );
}
ImagePrimitivePtr result = new ImagePrimitive( newDataWindow, format.getDisplayWindow() );
ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
const vector<string> &channelNames = channelNamesData->readable();
vector<float *> imageChannelData;
for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ )
{
FloatVectorDataPtr cd = new FloatVectorData;
vector<float> &c = cd->writable();
c.resize( result->variableSize( PrimitiveVariable::Vertex ), 0.0f );
result->variables[*it] = PrimitiveVariable( PrimitiveVariable::Vertex, cd );
imageChannelData.push_back( &(c[0]) );
}
parallel_for( blocked_range2d<size_t>( 0, dataWindow.size().x+1, tileSize(), 0, dataWindow.size().y+1, tileSize() ),
GafferImage::Detail::CopyTiles( imageChannelData, channelNames, channelDataPlug(), dataWindow, Context::current(), tileSize()) );
return result;
}
示例3: engine
void DisplayIop::engine( int y, int x, int r, const DD::Image::ChannelSet &channels, DD::Image::Row &row )
{
Channel outputChannels[4] = { Chan_Red, Chan_Green, Chan_Blue, Chan_Alpha };
const char *inputChannels[] = { "R", "G", "B", "A", nullptr };
const ImagePrimitive *image = nullptr;
Box2i inputDataWindow;
Box2i inputDisplayWindow;
if( firstDisplayIop()->m_driver )
{
image = firstDisplayIop()->m_driver->image().get();
inputDataWindow = image->getDataWindow();
inputDisplayWindow = image->getDisplayWindow();
}
int i = 0;
while( inputChannels[i] )
{
const FloatVectorData *inputData = image ? image->getChannel<float>( inputChannels[i] ) : nullptr;
if( inputData )
{
float *output = row.writable( outputChannels[i] ) + x;
// remap coordinate relative to our data window. nuke images have pixel origin at bottom,
// cortex images have pixel origin at top.
V2i pDataWindow = V2i( x, inputDisplayWindow.max.y - y ) - inputDataWindow.min;
const float *input = &((inputData->readable())[pDataWindow.y*(inputDataWindow.size().x+1) + pDataWindow.x]);
memcpy( output, input, (r-x) * sizeof( float ) );
}
else
{
row.erase( outputChannels[i] );
}
i++;
}
}
示例4: readTypedChannel
DataPtr TIFFImageReader::readTypedChannel( const std::string &name, const Box2i &dataWindow )
{
typedef TypedData< std::vector< V > > TargetVector;
typename TargetVector::Ptr dataContainer = new TargetVector();
typename TargetVector::ValueType &data = dataContainer->writable();
std::vector<std::string> names;
channelNames( names );
std::vector<std::string>::iterator it = find( names.begin(), names.end(), name );
if ( it == names.end() )
{
throw IOException( (boost::format( "TIFFImageReader: Could not find channel \"%s\" while reading %s") % name % fileName() ).str() );
}
int channelOffset = std::distance( names.begin(), it );
assert( channelOffset >= 0 );
assert( channelOffset < (int)names.size() );
if ( channelOffset >= m_samplesPerPixel )
{
throw IOException( (boost::format( "TIFFImageReader: Insufficient samples-per-pixel (%d) for reading channel \"%s\"") % m_samplesPerPixel % name).str() );
}
int area = ( dataWindow.size().x + 1 ) * ( dataWindow.size().y + 1 );
assert( area >= 0 );
data.resize( area );
int dataWidth = 1 + dataWindow.size().x;
int bufferDataWidth = 1 + m_dataWindow.size().x;
ScaledDataConversion<T, V> converter;
int dataY = 0;
for ( int y = dataWindow.min.y - m_dataWindow.min.y ; y <= dataWindow.max.y - m_dataWindow.min.y ; ++y, ++dataY )
{
int dataX = 0;
for ( int x = dataWindow.min.x - m_dataWindow.min.x; x <= dataWindow.max.x - m_dataWindow.min.x ; ++x, ++dataX )
{
const T* buf = reinterpret_cast< T* >( & m_buffer[0] );
assert( buf );
// \todo Currently, we only support PLANARCONFIG_CONTIG for TIFFTAG_PLANARCONFIG.
assert( m_planarConfig == PLANARCONFIG_CONTIG );
typename TargetVector::ValueType::size_type dataOffset = dataY * dataWidth + dataX;
assert( dataOffset < data.size() );
data[dataOffset] = converter( buf[ m_samplesPerPixel * ( y * bufferDataWidth + x ) + channelOffset ] );
}
}
return dataContainer;
}
示例5: inPlug
void OSLImage::hashChannelNames( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
ImageProcessor::hashChannelNames( output, context, h );
inPlug()->channelNamesPlug()->hash( h );
const Box2i dataWindow = inPlug()->dataWindowPlug()->getValue();
if( !dataWindow.isEmpty() )
{
ContextPtr c = new Context( *context, Context::Borrowed );
c->set( ImagePlug::tileOriginContextName, ImagePlug::tileOrigin( dataWindow.min ) );
Context::Scope s( c.get() );
shadingPlug()->hash( h );
}
}
示例6: imageData
virtual void imageData( const Imath::Box2i &box, const float *data, size_t dataSize )
{
Box2i yUpBox = m_gafferFormat.yDownToFormatSpace( box );
const V2i boxMinTileOrigin = ImagePlug::tileOrigin( yUpBox.min );
const V2i boxMaxTileOrigin = ImagePlug::tileOrigin( yUpBox.max );
for( int tileOriginY = boxMinTileOrigin.y; tileOriginY <= boxMaxTileOrigin.y; tileOriginY += ImagePlug::tileSize() )
{
for( int tileOriginX = boxMinTileOrigin.x; tileOriginX <= boxMaxTileOrigin.x; tileOriginX += ImagePlug::tileSize() )
{
for( int channelIndex = 0, numChannels = channelNames().size(); channelIndex < numChannels; ++channelIndex )
{
const V2i tileOrigin( tileOriginX, tileOriginY );
ConstFloatVectorDataPtr tileData = getTile( tileOrigin, channelIndex );
if( !tileData )
{
// we've been sent data outside of the data window
continue;
}
// we must create a new object to hold the updated tile data,
// because the old one might well have been returned from
// computeChannelData and be being held in the cache.
FloatVectorDataPtr updatedTileData = tileData->copy();
vector<float> &updatedTile = updatedTileData->writable();
const Box2i tileBound( tileOrigin, tileOrigin + Imath::V2i( GafferImage::ImagePlug::tileSize() - 1 ) );
const Box2i transferBound = IECore::boxIntersection( tileBound, yUpBox );
for( int y = transferBound.min.y; y<=transferBound.max.y; ++y )
{
int srcY = m_gafferFormat.formatToYDownSpace( y );
size_t srcIndex = ( ( srcY - box.min.y ) * ( box.size().x + 1 ) * numChannels ) + ( transferBound.min.x - box.min.x ) + channelIndex;
size_t dstIndex = ( y - tileBound.min.y ) * ImagePlug::tileSize() + transferBound.min.x - tileBound.min.x;
const size_t srcEndIndex = srcIndex + transferBound.size().x * numChannels;
while( srcIndex <= srcEndIndex )
{
updatedTile[dstIndex] = data[srcIndex];
srcIndex += numChannels;
dstIndex++;
}
}
setTile( tileOrigin, channelIndex, updatedTileData );
}
}
}
dataReceivedSignal()( this, box );
}
示例7: formatPlug
IECore::ImagePrimitivePtr ImagePlug::image() const
{
Format format = formatPlug()->getValue();
Box2i dataWindow = dataWindowPlug()->getValue();
Box2i newDataWindow( Imath::V2i(0) );
if( dataWindow.isEmpty() )
{
dataWindow = Box2i( Imath::V2i(0) );
}
else
{
newDataWindow = format.yDownToFormatSpace( dataWindow );
}
// use the default format if we don't have an explicit one.
/// \todo: remove this once FormatPlug is handling it for
/// us during ExecutableNode::execute (see issue #887).
if( format.getDisplayWindow().isEmpty() )
{
format = Context::current()->get<Format>( Format::defaultFormatContextName, Format() );
}
ImagePrimitivePtr result = new ImagePrimitive( newDataWindow, format.getDisplayWindow() );
ConstCompoundObjectPtr metadata = metadataPlug()->getValue();
compoundObjectToCompoundData( metadata.get(), result->blindData() );
ConstStringVectorDataPtr channelNamesData = channelNamesPlug()->getValue();
const vector<string> &channelNames = channelNamesData->readable();
vector<float *> imageChannelData;
for( vector<string>::const_iterator it = channelNames.begin(), eIt = channelNames.end(); it!=eIt; it++ )
{
FloatVectorDataPtr cd = new FloatVectorData;
vector<float> &c = cd->writable();
c.resize( result->variableSize( PrimitiveVariable::Vertex ), 0.0f );
result->variables[*it] = PrimitiveVariable( PrimitiveVariable::Vertex, cd );
imageChannelData.push_back( &(c[0]) );
}
parallel_for( blocked_range3d<size_t>( 0, imageChannelData.size(), 1, 0, dataWindow.size().x+1, tileSize(), 0, dataWindow.size().y+1, tileSize() ),
GafferImage::Detail::CopyTiles( imageChannelData, channelNames, channelDataPlug(), dataWindow, Context::current(), tileSize()) );
return result;
}
示例8: setDisplayWindow
void ImagePrimitive::setDisplayWindow( const Box2i &displayWindow )
{
if ( displayWindow.isEmpty() )
{
throw InvalidArgumentException( "ImagePrimitive: Cannot set displayWindow to the empty window" );
}
m_displayWindow = displayWindow;
}
示例9: imageData
void ImageDisplayDriver::imageData( const Box2i &box, const float *data, size_t dataSize )
{
Box2i tmpBox = box;
Box2i dataWindow = m_image->getDataWindow();
tmpBox.extendBy( dataWindow );
if ( tmpBox != dataWindow )
{
throw Exception("The box is outside image data window.");
}
int pixelSize = channelNames().size();
if ( dataSize != (box.max.x - box.min.x + 1) * (box.max.y - box.min.y + 1) * channelNames().size() )
{
throw Exception("Invalid dataSize value.");
}
int channel, targetX, targetY, sourceWidth, sourceHeight, targetWidth;
sourceWidth = box.max.x - box.min.x + 1;
sourceHeight = box.max.y - box.min.y + 1;
targetWidth = dataWindow.max.x - dataWindow.min.x + 1;
channel = 0;
targetX = box.min.x - dataWindow.min.x;
targetY = box.min.y - dataWindow.min.y;
for ( vector<string>::const_iterator it = channelNames().begin(); it != channelNames().end(); it++, channel++ )
{
vector< float > &target = boost::static_pointer_cast< FloatVectorData >(m_image->variables[ *it ].data)->writable();
vector< float >::iterator targetIt;
const float *sourceIt = data+channel;
targetIt = target.begin()+targetWidth*targetY+targetX;
for ( int y = 0; y < sourceHeight; y++ )
{
for ( int x = 0; x < sourceWidth; x++ )
{
*targetIt = *sourceIt;
sourceIt += pixelSize;
targetIt++;
}
targetIt += targetWidth - sourceWidth;
}
}
}
示例10: iterateTiles
void iterateTiles(std::array<QuadSetup, N> quads, Intersector intersector) const
{
Box2i bounds;
for (const auto &q : quads)
bounds.grow(q.bounds);
if (bounds.empty())
return;
uint32 minX = uint32(bounds.min().x()) & ~TileMask, maxX = bounds.max().x();
uint32 minY = uint32(bounds.min().y()) & ~TileMask, maxY = bounds.max().y();
for (auto &q : quads) {
q.start(minX + TileSize*0.5f, minY + TileSize*0.5f);
for (int k = 0; k < 3; ++k) {
q.stepX[k] *= float(TileSize);
q.stepY[k] *= float(TileSize);
}
}
for (uint32 y = minY; y < maxY; y += TileSize) {
for (auto &q : quads)
q.beginRow();
for (uint32 x = minX; x < maxX; x += TileSize) {
float wMin = -1.0f;
for (auto &q : quads)
wMin = max(wMin, q.reduce());
if (wMin >= 0.0f) {
uint32 xjMax = min(x + TileSize, _res.x());
uint32 yjMax = min(y + TileSize, _res.y());
for (uint32 yj = y; yj < yjMax; ++yj)
for (uint32 xj = x; xj < xjMax; ++xj)
intersector(xj, yj, xj + yj*_res.x());
}
for (auto &q : quads)
q.stepCol();
}
for (auto &q : quads)
q.endRow();
}
}
示例11: channelName
void ImageSampler::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
ComputeNode::hash( output, context, h );
if( output->parent<Plug>() == colorPlug() )
{
std::string channel = channelName( output );
if( channel.size() )
{
V2f pixel = pixelPlug()->getValue();
Box2i sampleWindow;
sampleWindow.extendBy( V2i( pixel ) - V2i( 1 ) );
sampleWindow.extendBy( V2i( pixel ) + V2i( 1 ) );
Sampler sampler( imagePlug(), channel, sampleWindow );
sampler.hash( h );
h.append( pixel );
}
}
}
示例12: operator
void operator()( const blocked_range3d<size_t>& r ) const
{
ContextPtr context = new Context( *m_parentContext, Context::Borrowed );
Context::Scope scope( context.get() );
const Box2i operationWindow( V2i( r.rows().begin()+m_dataWindow.min.x, r.cols().begin()+m_dataWindow.min.y ), V2i( r.rows().end()+m_dataWindow.min.x-1, r.cols().end()+m_dataWindow.min.y-1 ) );
V2i minTileOrigin = ImagePlug::tileOrigin( operationWindow.min );
V2i maxTileOrigin = ImagePlug::tileOrigin( operationWindow.max );
size_t imageStride = m_dataWindow.size().x + 1;
for( size_t channelIndex = r.pages().begin(); channelIndex < r.pages().end(); ++channelIndex )
{
context->set( ImagePlug::channelNameContextName, m_channelNames[channelIndex] );
float *channelBegin = m_imageChannelData[channelIndex];
for( int tileOriginY = minTileOrigin.y; tileOriginY <= maxTileOrigin.y; tileOriginY += m_tileSize )
{
for( int tileOriginX = minTileOrigin.x; tileOriginX <= maxTileOrigin.x; tileOriginX += m_tileSize )
{
context->set( ImagePlug::tileOriginContextName, V2i( tileOriginX, tileOriginY ) );
Box2i tileBound( V2i( tileOriginX, tileOriginY ), V2i( tileOriginX + m_tileSize - 1, tileOriginY + m_tileSize - 1 ) );
Box2i b = boxIntersection( tileBound, operationWindow );
size_t tileStrideSize = sizeof(float) * ( b.size().x + 1 );
ConstFloatVectorDataPtr tileData = m_channelDataPlug->getValue();
const float *tileDataBegin = &(tileData->readable()[0]);
for( int y = b.min.y; y<=b.max.y; y++ )
{
const float *tilePtr = tileDataBegin + (y - tileOriginY) * m_tileSize + (b.min.x - tileOriginX);
float *channelPtr = channelBegin + ( m_dataWindow.size().y - ( y - m_dataWindow.min.y ) ) * imageStride + (b.min.x - m_dataWindow.min.x);
std::memcpy( channelPtr, tilePtr, tileStrideSize );
}
}
}
}
}
示例13: channelName
void ImageSampler::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
if( output->parent<Plug>() == colorPlug() )
{
float sample = 0;
std::string channel = channelName( output );
if( channel.size() )
{
V2f pixel = pixelPlug()->getValue();
Box2i sampleWindow;
sampleWindow.extendBy( V2i( pixel ) - V2i( 1 ) );
sampleWindow.extendBy( V2i( pixel ) + V2i( 1 ) );
Sampler sampler( imagePlug(), channel, sampleWindow, Filter::create( filterPlug()->getValue() ) );
sample = sampler.sample( pixel.x, pixel.y );
}
static_cast<FloatPlug *>( output )->setValue( sample );
return;
}
ComputeNode::compute( output, context );
}
示例14: medianCut
static void medianCut( const Array2D &luminance, const Array2D &summedLuminance, MedianCutSampler::Projection projection, const Box2i &area, vector<Box2i> &areas, vector<V2f> ¢roids, int depth, int maxDepth )
{
float radiansPerPixel = M_PI / (luminance.shape()[1]);
if( depth==maxDepth )
{
float totalEnergy = 0.0f;
V2f position( 0.0f );
for( int y=area.min.y; y<=area.max.y; y++ )
{
for( int x=area.min.x; x<=area.max.x; x++ )
{
float e = luminance[x][y];
position += V2f( x, y ) * e;
totalEnergy += e;
}
}
position /= totalEnergy;
centroids.push_back( position );
areas.push_back( area );
}
else
{
// find cut dimension
V2f size = area.size();
if( projection==MedianCutSampler::LatLong )
{
float centreY = (area.max.y + area.min.y) / 2.0f;
float centreAngle = (M_PI - radiansPerPixel) / 2.0f - centreY * radiansPerPixel;
size.x *= cosf( centreAngle );
}
int cutAxis = size.x > size.y ? 0 : 1;
float e = energy( summedLuminance, area );
float halfE = e / 2.0f;
Box2i lowArea = area;
while( e > halfE )
{
lowArea.max[cutAxis] -= 1;
e = energy( summedLuminance, lowArea );
}
Box2i highArea = area;
highArea.min[cutAxis] = lowArea.max[cutAxis] + 1;
medianCut( luminance, summedLuminance, projection, lowArea, areas, centroids, depth + 1, maxDepth );
medianCut( luminance, summedLuminance, projection, highArea, areas, centroids, depth + 1, maxDepth );
}
}
示例15: IOException
void DPXImageWriter::writeImage( const vector<string> &names, const ImagePrimitive *image, const Box2i &dataWindow ) const
{
// write the dpx in the standard 10bit log format
ofstream out;
out.open(fileName().c_str());
if ( !out.is_open() )
{
throw IOException( "DPXImageWriter: Error writing to " + fileName() );
}
/// We'd like RGB to be at the front, in that order, because it seems that not all readers support the channel identifiers!
vector<string> desiredChannelOrder;
desiredChannelOrder.push_back( "R" );
desiredChannelOrder.push_back( "G" );
desiredChannelOrder.push_back( "B" );
vector<string> namesCopy = names;
vector<string> filteredNames;
for ( vector<string>::const_iterator it = desiredChannelOrder.begin(); it != desiredChannelOrder.end(); ++it )
{
vector<string>::iterator res = find( namesCopy.begin(), namesCopy.end(), *it );
if ( res != namesCopy.end() )
{
namesCopy.erase( res );
filteredNames.push_back( *it );
}
}
for ( vector<string>::const_iterator it = namesCopy.begin(); it != namesCopy.end(); ++it )
{
filteredNames.push_back( *it );
}
assert( names.size() == filteredNames.size() );
Box2i displayWindow = image->getDisplayWindow();
int displayWidth = 1 + displayWindow.size().x;
int displayHeight = 1 + displayWindow.size().y;
// build the header
DPXFileInformation fi;
memset(&fi, 0, sizeof(fi));
DPXImageInformation ii;
memset(&ii, 0, sizeof(ii));
DPXImageOrientation ioi;
memset(&ioi, 0, sizeof(ioi));
DPXMotionPictureFilm mpf;
memset(&mpf, 0, sizeof(mpf));
DPXTelevisionHeader th;
memset(&th, 0, sizeof(th));
fi.magic = asBigEndian<>( 0x53445058 );
// compute data offsets
fi.gen_hdr_size = sizeof(fi) + sizeof(ii) + sizeof(ioi);
fi.gen_hdr_size = asBigEndian<>(fi.gen_hdr_size);
fi.ind_hdr_size = sizeof(mpf) + sizeof(th);
fi.ind_hdr_size = asBigEndian<>(fi.ind_hdr_size);
int header_size = sizeof(fi) + sizeof(ii) + sizeof(ioi) + sizeof(mpf) + sizeof(th);
fi.image_data_offset = header_size;
fi.image_data_offset = asBigEndian<>(fi.image_data_offset);
strcpy((char *) fi.vers, "V2.0");
strncpy( (char *) fi.file_name, fileName().c_str(), sizeof( fi.file_name ) );
// compute the current date and time
boost::posix_time::ptime utc = boost::posix_time::second_clock::universal_time();
boost::gregorian::date date = utc.date();
boost::posix_time::time_duration time = utc.time_of_day();
snprintf((char *) fi.create_time, sizeof( fi.create_time ), "%04d:%02d:%02d:%02d:%02d:%02d:%s",
static_cast<int>( date.year() ),
static_cast<int>( date.month() ),
static_cast<int>( date.day() ),
time.hours(),
time.minutes(),
time.seconds(),
"UTC"
);
snprintf((char *) fi.creator, sizeof( fi.creator ), "cortex");
snprintf((char *) fi.project, sizeof( fi.project ), "cortex");
snprintf((char *) fi.copyright, sizeof( fi.copyright ), "Unknown");
ii.orientation = 0; // left-to-right, top-to-bottom
ii.element_number = 1;
ii.pixels_per_line = displayWidth;
ii.lines_per_image_ele = displayHeight;
ii.element_number = asBigEndian<>(ii.element_number);
ii.pixels_per_line = asBigEndian<>(ii.pixels_per_line);
//.........这里部分代码省略.........