<commit_before>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2007-2009, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of Image Engine Design nor the names of any
//       other contributors to this software may be used to endorse or
//       promote products derived from this software without specific prior
//       written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include "IECore/ImageReader.h"
#include "IECore/VectorTypedData.h"
#include "IECore/TypedParameter.h"
#include "IECore/ImagePrimitive.h"
#include "IECore/CompoundParameter.h"
#include "IECore/FileNameParameter.h"
#include "IECore/ObjectParameter.h"
#include "IECore/NullObject.h"
#include "IECore/BoxOps.h"

using namespace std;
using namespace IECore;
using namespace boost;
using namespace Imath;

IE_CORE_DEFINERUNTIMETYPED( ImageReader );

ImageReader::ImageReader( const std::string &name, const std::string &description ) :
		Reader( name, description, new ObjectParameter( "result", "The loaded object", new NullObject, ImagePrimitive::staticTypeId() ) )
{
	m_dataWindowParameter = new Box2iParameter(
		"dataWindow",
		"The area for which data should be loaded. The default value (an empty box) "
		"is used to specify that the full data window should be loaded. Other values may be specified "
		"to load just a section of the image."
	);

	m_displayWindowParameter = new Box2iParameter(
		"displayWindow",
		"The displayWindow for the ImagePrimitive created during loading. The default value (an empty box) "
		"is used to specify that the displayWindow should be inferred from the file itself. On rare occasions "
		"it may be useful to specify an alternative using this parameter. Note that this parameter is completely "
		"independent of the dataWindow parameter."
	);

	m_channelNamesParameter = new StringVectorParameter(
		"channels",
		"The names of all channels to load from the file. If the list is empty (the default value) "
		"then all channels are loaded."
	);

	parameters()->addParameter( m_dataWindowParameter );
	parameters()->addParameter( m_displayWindowParameter );
	parameters()->addParameter( m_channelNamesParameter );
}

ObjectPtr ImageReader::doOperation( ConstCompoundObjectPtr operands )
{

	Box2i displayWind = displayWindowParameter()->getTypedValue();
	if( displayWind.isEmpty() )
	{
		displayWind = displayWindow();
	}
	Box2i dataWind = dataWindowToRead();


	// create our ImagePrimitive
	ImagePrimitivePtr image = new ImagePrimitive( dataWind, displayWind );

	// fetch all the user-desired channels with

	// the derived class' readChannel() implementation

	vector<string> channelNames;
	channelsToRead( channelNames );

	vector<string>::const_iterator ci = channelNames.begin();
	while( ci != channelNames.end() )
	{
		DataPtr d = readChannel( *ci, dataWind );

		assert( d  );
		assert( d->typeId()==FloatVectorDataTypeId || d->typeId()==HalfVectorDataTypeId || d->typeId()==IntVectorDataTypeId );

		PrimitiveVariable p( PrimitiveVariable::Vertex, d );
		assert( image->isPrimitiveVariableValid( p ) );

		image->variables[*ci] = p;

		ci++;
	}

	return image;
}

DataPtr ImageReader::readChannel( const std::string &name )
{
	vector<string> allNames;
	channelNames( allNames );

	if ( find( allNames.begin(), allNames.end(), name ) == allNames.end() )
	{
		throw InvalidArgumentException( "Non-existent image channel requested" );
	}

	Box2i d = dataWindowToRead();
	return readChannel( name, d );
}<commit_msg>patch for image reader types from <NAME><commit_after>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2007-2009, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of Image Engine Design nor the names of any
//       other contributors to this software may be used to endorse or
//       promote products derived from this software without specific prior
//       written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include "IECore/ImageReader.h"
#include "IECore/VectorTypedData.h"
#include "IECore/TypedParameter.h"
#include "IECore/ImagePrimitive.h"
#include "IECore/CompoundParameter.h"
#include "IECore/FileNameParameter.h"
#include "IECore/ObjectParameter.h"
#include "IECore/NullObject.h"
#include "IECore/BoxOps.h"

using namespace std;
using namespace IECore;
using namespace boost;
using namespace Imath;

IE_CORE_DEFINERUNTIMETYPED( ImageReader );

ImageReader::ImageReader( const std::string &name, const std::string &description ) :
		Reader( name, description, new ObjectParameter( "result", "The loaded object", new NullObject, ImagePrimitive::staticTypeId() ) )
{
	m_dataWindowParameter = new Box2iParameter(
		"dataWindow",
		"The area for which data should be loaded. The default value (an empty box) "
		"is used to specify that the full data window should be loaded. Other values may be specified "
		"to load just a section of the image."
	);

	m_displayWindowParameter = new Box2iParameter(
		"displayWindow",
		"The displayWindow for the ImagePrimitive created during loading. The default value (an empty box) "
		"is used to specify that the displayWindow should be inferred from the file itself. On rare occasions "
		"it may be useful to specify an alternative using this parameter. Note that this parameter is completely "
		"independent of the dataWindow parameter."
	);

	m_channelNamesParameter = new StringVectorParameter(
		"channels",
		"The names of all channels to load from the file. If the list is empty (the default value) "
		"then all channels are loaded."
	);

	parameters()->addParameter( m_dataWindowParameter );
	parameters()->addParameter( m_displayWindowParameter );
	parameters()->addParameter( m_channelNamesParameter );
}

ObjectPtr ImageReader::doOperation( ConstCompoundObjectPtr operands )
{

	Box2i displayWind = displayWindowParameter()->getTypedValue();
	if( displayWind.isEmpty() )
	{
		displayWind = displayWindow();
	}
	Box2i dataWind = dataWindowToRead();


	// create our ImagePrimitive
	ImagePrimitivePtr image = new ImagePrimitive( dataWind, displayWind );

	// fetch all the user-desired channels with

	// the derived class' readChannel() implementation

	vector<string> channelNames;
	channelsToRead( channelNames );

	vector<string>::const_iterator ci = channelNames.begin();
	while( ci != channelNames.end() )
	{
		DataPtr d = readChannel( *ci, dataWind );

		assert( d  );
		assert( d->typeId()==FloatVectorDataTypeId || d->typeId()==HalfVectorDataTypeId || d->typeId()==UIntVectorDataTypeId );

		PrimitiveVariable p( PrimitiveVariable::Vertex, d );
		assert( image->isPrimitiveVariableValid( p ) );

		image->variables[*ci] = p;

		ci++;
	}

	return image;
}

DataPtr ImageReader::readChannel( const std::string &name )
{
	vector<string> allNames;
	channelNames( allNames );

	if ( find( allNames.begin(), allNames.end(), name ) == allNames.end() )
	{
		throw InvalidArgumentException( "Non-existent image channel requested" );
	}

	Box2i d = dataWindowToRead();
	return readChannel( name, d );
}
{'fraction_non_alphanumeric': 0.1201384646711464, 'fraction_numerical': 0.0026471187130930563, 'mean_word_length': 3.71579452712434, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857120', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2586, 'n_words': 1020}