<commit_before>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005, 2006, 2007 Roman Schindlauer
 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Thomas Krennwallner
 * Copyright (C) 2009, 2010 Peter Schüller
 * Copyright (C) 2009 Peter Schüller
 *
 * This file is part of dlvhex.
 *
 * dlvhex is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * dlvhex is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with dlvhex; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

/**
 * @file   DLVResultParser.cpp
 * @author Roman Schindlauer
 * @author Peter Schüller
 * @date   Wed Mar 22 14:38:53 CET 2006
 *
 * @brief  DLV result parser using boost::spirit
 *
 *
 */

// activate benchmarking if activated by configure option --enable-debug
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

// use this for developing the parser
#undef CWDEBUG
#ifdef CWDEBUG
# ifndef _GNU_SOURCE
#  define _GNU_SOURCE
# endif
# include <libcwd/sys.h>
# include <libcwd/debug.h>
#endif

//#include "dlvhex2/DLVResultParser.hpp"
#include "dlvhex2/DLVresultParserDriver.h"

// use this for debugging parser progress (XML style)
#undef BOOST_SPIRIT_DEBUG

#include "dlvhex2/Benchmarking.h"
#include "dlvhex2/ID.h"
#include "dlvhex2/Term.h"
#include "dlvhex2/Atoms.h"
#include "dlvhex2/Registry.h"
#include "dlvhex2/Printer.h"
#include "dlvhex2/ProgramCtx.h"

#include <boost/optional.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/algorithm/string/trim.hpp>

#include <sstream>
#include <iostream>

namespace spirit = boost::spirit;
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;

DLVHEX_NAMESPACE_BEGIN

DLVResultParser::DLVResultParser(RegistryPtr reg):
  reg(reg),
  pMode(FirstOrder)
{
}

DLVResultParser::DLVResultParser(RegistryPtr reg, ParseMode mode):
  reg(reg),
  pMode(mode)
{
}

DLVResultParser::~DLVResultParser()
{
}

void
DLVResultParser::setParseMode(ParseMode mode)
{
	pMode = mode;
}

struct ParserState
{
  RegistryPtr registry;
  AnswerSet::Ptr current;
  DLVResultParser::AnswerSetAdder adder;
	bool dropPredicates;

  ParserState(
      RegistryPtr registry,
      DLVResultParser::AnswerSetAdder adder,
      bool dropPredicates):
    registry(registry),
    current(new AnswerSet(registry)),
		adder(adder),
    dropPredicates(dropPredicates) {}
};

#if 1
//
// useful phoenix operator debugging stuff:
// -> just add [ handle_dbg("message") ] to any rule/parser to get information
//
template<typename Attrib>
void houtput(Attrib const& a)
{
#ifdef CWDEBUG
  std::cerr << "XXX handling attribute " << libcwd::type_info_of(a).demangled_name() << std::endl;
#endif
};

template<>
void houtput(std::vector<char> const& a)
{
  std::cerr << "XXX got string  attribute '" << std::string(a.begin(), a.end()) << "'" << std::endl;
}

template<typename Content>
void houtput(boost::optional<Content> const& a)
{
  if( !a )
  {
    std::cerr << "XXX optional (unset):" << std::endl;
  }
  else
  {
    std::cerr << "XXX optional:" << std::endl;
  }
  houtput(a.get());
}

struct handle_dbg
{
  handle_dbg(std::string s): s(s) {}
  std::string s;
  template<typename Attrib>
  void operator()(Attrib& a, qi::unused_type, qi::unused_type) const
  {
    std::cerr << "DBG=" << s << std::endl;
    houtput(a);
  }
};
#endif

struct handle_int
{
  template <typename Context>
  void operator()(int i, Context& ctx, qi::unused_type) const
  {
    ID& ruleAttr = fusion::at_c<0>(ctx.attributes);

    ruleAttr = ID::termFromInteger(i);
    //std::cerr << "created int " << i << std::endl;
  }
};

namespace
{
  inline ID getOrRegisterTerm(RegistryPtr registry, const std::string& s)
  {
    ID id = registry->terms.getIDByString(s);
    if( id == ID_FAIL )
      {
        id = registry->preds.getIDByString(s);
        if( id == ID_FAIL )
          {
            Term term(ID::MAINKIND_TERM, s);
            // we can only get strings or constants
            assert(s[0] == '"' || islower(s[0]));
            id = registry->terms.storeAndGetID(term);
          }
      }
    return id;
  }
}

struct handle_ident
{
  handle_ident(ParserState& state): state(state) {}

  template <typename Context>
  void operator()(const std::string& s, Context& ctx, qi::unused_type) const
  {
    ID& ruleAttr = fusion::at_c<0>(ctx.attributes);

    ID id = getOrRegisterTerm(state.registry, s);
    ruleAttr = id;
    //std::cerr << "created ident '" << s << "'" << std::endl;
  }

  ParserState& state;
};

struct handle_finished_answerset
{
  handle_finished_answerset(ParserState& state): state(state) {}

  void operator()(qi::unused_type, qi::unused_type, qi::unused_type) const
  {
    // add current answer set as full answer set
    DBGLOG(DBG,"handling parsed answer set " << *state.current);
    state.adder(state.current);
    // create empty answer set for subsequent parsing
		state.current.reset(new AnswerSet(state.registry));
  }

  ParserState& state;
};

struct handle_fact
{
  handle_fact(ParserState& state): state(state) {}

  void operator()(
			boost::fusion::vector3<
				boost::optional<char>,
				std::string,
				boost::optional<Tuple> >& attr,
			qi::unused_type, qi::unused_type) const
  {
		// alias for fusion input
		bool strong_neg = !!fusion::at_c<0>(attr);
    assert(!strong_neg);
		const std::string& predicate = fusion::at_c<1>(attr);
    ID predid = getOrRegisterTerm(state.registry, predicate);
    OrdinaryAtom atom(ID::MAINKIND_ATOM);
    atom.tuple.push_back(predid);

    // aux predicates create aux atoms
    if( (predid & ID::PROPERTY_AUX) != 0 )
      atom.kind |= ID::PROPERTY_AUX;

    boost::optional<Tuple>& tup = fusion::at_c<2>(attr);
    if( !!tup )
      atom.tuple.insert(atom.tuple.end(), tup.get().begin(), tup.get().end());

    // TODO lookup by string in registry, then by tuple
    ID id = state.registry->ogatoms.getIDByTuple(atom.tuple);
    if( id == ID_FAIL )
    {
      {
        #warning parsing efficiency problem see HexGrammarPTToASTConverter
        std::stringstream ss;
        RawPrinter printer(ss, state.registry);
        Tuple::const_iterator it = atom.tuple.begin();
        printer.print(*it);
        it++;
        if( it != atom.tuple.end() )
        {
          ss << "(";
          printer.print(*it);
          it++;
          while(it != atom.tuple.end())
          {
            ss << ",";
            printer.print(*it);
            it++;
          }
          ss << ")";
        }
        atom.text = ss.str();
      }
      DBGLOG(DBG,"storing atom " << atom);
      id = state.registry->ogatoms.storeAndGetID(atom);
    }
    //TODO make more efficient (cache pointer to interpretation or even function object)
    DBGLOG(DBG,"setting fact " << id);
    state.current->interpretation->setFact(id.address);
  }

  ParserState& state;
};

// "The Grammar"
template<typename Iterator>
struct DLVResultGrammar:
  public qi::grammar<Iterator, ascii::space_type>
{
	DLVResultGrammar(ParserState& state):
		DLVResultGrammar::base_type(dlvline), state(state)
	{
    using spirit::int_;
    using spirit::_val;
    using spirit::_1;
    using qi::lexeme;
    using qi::char_;
    using qi::omit;
    using qi::lit;

		ident
			= lexeme[char_('"') > *(char_ - '"') > char_('"')]
      // @todo test performance
			//| lexeme[char_("a-z") >> *char_("a-zA-Z0-9_")];
			| lexeme[ascii::lower > *(ascii::alnum|char_('_'))];
		groundterm
			= int_ [ handle_int() ]
			| ident [ handle_ident(state) ]
      ;
		fact
			// char_ synthesizes a char attribute!
			= ( -char_('-') > ident > -params ) [ handle_fact(state) ] ;
		params
			%= '(' > groundterm > *(',' > groundterm) > ')';
		answerset
			= (lit('{') >> '}') [ handle_finished_answerset(state) ]
			| (lit('{') > fact > *(',' > fact) > lit('}') [ handle_finished_answerset(state) ]);
    /// @todo: do not throw away weak answer set information but store it
    costline
      = lit("Cost") > +(ascii::alnum|char_("[]<>():"));
		dlvline
			= (-lit("Best model:") >> answerset)
        |
        costline;

    #ifdef BOOST_SPIRIT_DEBUG
		BOOST_SPIRIT_DEBUG_NODE(dlvline);
		BOOST_SPIRIT_DEBUG_NODE(answerset);
		BOOST_SPIRIT_DEBUG_NODE(costline);
		BOOST_SPIRIT_DEBUG_NODE(fact);
		BOOST_SPIRIT_DEBUG_NODE(groundterm);
		BOOST_SPIRIT_DEBUG_NODE(ident);
    #endif
	}

	qi::rule<Iterator, ascii::space_type>                  dlvline,
                                                         answerset,
                                                         fact,
                                                         costline;
	qi::rule<Iterator, ID(), ascii::space_type>            groundterm;
	qi::rule<Iterator, std::string(), ascii::space_type>   ident;
	qi::rule<Iterator, Tuple(), ascii::space_type>         params;

	ParserState& state;
};

void
DLVResultParser::parse(
    std::istream& is,
    AnswerSetAdder adder) throw (SyntaxError)
{
	DLVHEX_BENCHMARK_REGISTER_AND_SCOPE(sid,"DLVResultParser::parse");

	bool dropPredicates =
		(pMode == DLVResultParser::HO);
	ParserState state(reg, adder, dropPredicates);

  typedef std::string::const_iterator forward_iterator_type;
  DLVResultGrammar<forward_iterator_type> grammar(state);
  unsigned errors = 0;
  do
  {
    // @todo: read each line to the next endl, then parse, then get exactly one answer set per parse, maybe reuse the grammar (state can be avoided by using attributes, AtomSetPtr and AtomPtr or just use a new AST with integers instead)

    // get next input line
    std::string input;
    std::getline(is, input);

    // break silently
    if( input.empty() )
      break;

    DBGLOG(DBG,"obtained " << input.size() << " characters from input stream via getline");

    if( is.bad() )
    {
      DBGLOG(DBG,"leaving DLVResultParser loop, stream bits are: "
          "fail " << is.fail() << ", bad " << is.bad() << ", eof " << is.eof());
      break;
    }

    // TODO allocate answer set here, just set bits in parser
    LOG(DBG,"parsing input from DLV: '" << input << "'");

    // convert input iterator to forward iterator, usable by spirit parser
    forward_iterator_type fwd_begin = input.begin();
    forward_iterator_type fwd_end = input.end();

    try
    {
      bool r = qi::phrase_parse(fwd_begin, fwd_end, grammar, ascii::space);

      // @todo: add better error message with position iterator
      if (!r || fwd_begin != fwd_end)
      {
        LOG(ERROR,"for input '" << input << "': r=" << r << " (begin!=end)=" << (fwd_begin != fwd_end));
        errors++;
      }
    }
    catch(const qi::expectation_failure<forward_iterator_type>& e)
    {
      LOG(ERROR,"for input '" << input << "': could not parse DLV output(expectation failure) " << e.what_);
      errors++;
    }
  }
  while(errors < 20);

  if( errors != 0  )
  {
		LOG(ERROR,"error count for parsing DLV output = " << errors);
    throw SyntaxError("Could not parse complete DLV output! (see error log messages)");
  }
}

DLVHEX_NAMESPACE_END

// Local Variables:
// mode: C++
// End:
<commit_msg>commented out overly verbose DLV result parser<commit_after>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005, 2006, 2007 Roman Schindlauer
 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Thomas Krennwallner
 * Copyright (C) 2009, 2010 Peter Schüller
 * Copyright (C) 2009 Peter Schüller
 *
 * This file is part of dlvhex.
 *
 * dlvhex is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * dlvhex is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with dlvhex; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

/**
 * @file   DLVResultParser.cpp
 * @author Roman Schindlauer
 * @author Peter Schüller
 * @date   Wed Mar 22 14:38:53 CET 2006
 *
 * @brief  DLV result parser using boost::spirit
 *
 *
 */

// activate benchmarking if activated by configure option --enable-debug
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

// use this for developing the parser
#undef CWDEBUG
#ifdef CWDEBUG
# ifndef _GNU_SOURCE
#  define _GNU_SOURCE
# endif
# include <libcwd/sys.h>
# include <libcwd/debug.h>
#endif

//#include "dlvhex2/DLVResultParser.hpp"
#include "dlvhex2/DLVresultParserDriver.h"

// use this for debugging parser progress (XML style)
#undef BOOST_SPIRIT_DEBUG

#include "dlvhex2/Benchmarking.h"
#include "dlvhex2/ID.h"
#include "dlvhex2/Term.h"
#include "dlvhex2/Atoms.h"
#include "dlvhex2/Registry.h"
#include "dlvhex2/Printer.h"
#include "dlvhex2/ProgramCtx.h"

#include <boost/optional.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/algorithm/string/trim.hpp>

#include <sstream>
#include <iostream>

namespace spirit = boost::spirit;
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;

DLVHEX_NAMESPACE_BEGIN

DLVResultParser::DLVResultParser(RegistryPtr reg):
  reg(reg),
  pMode(FirstOrder)
{
}

DLVResultParser::DLVResultParser(RegistryPtr reg, ParseMode mode):
  reg(reg),
  pMode(mode)
{
}

DLVResultParser::~DLVResultParser()
{
}

void
DLVResultParser::setParseMode(ParseMode mode)
{
	pMode = mode;
}

struct ParserState
{
  RegistryPtr registry;
  AnswerSet::Ptr current;
  DLVResultParser::AnswerSetAdder adder;
	bool dropPredicates;

  ParserState(
      RegistryPtr registry,
      DLVResultParser::AnswerSetAdder adder,
      bool dropPredicates):
    registry(registry),
    current(new AnswerSet(registry)),
		adder(adder),
    dropPredicates(dropPredicates) {}
};

#if 1
//
// useful phoenix operator debugging stuff:
// -> just add [ handle_dbg("message") ] to any rule/parser to get information
//
template<typename Attrib>
void houtput(Attrib const& a)
{
#ifdef CWDEBUG
  std::cerr << "XXX handling attribute " << libcwd::type_info_of(a).demangled_name() << std::endl;
#endif
};

template<>
void houtput(std::vector<char> const& a)
{
  std::cerr << "XXX got string  attribute '" << std::string(a.begin(), a.end()) << "'" << std::endl;
}

template<typename Content>
void houtput(boost::optional<Content> const& a)
{
  if( !a )
  {
    std::cerr << "XXX optional (unset):" << std::endl;
  }
  else
  {
    std::cerr << "XXX optional:" << std::endl;
  }
  houtput(a.get());
}

struct handle_dbg
{
  handle_dbg(std::string s): s(s) {}
  std::string s;
  template<typename Attrib>
  void operator()(Attrib& a, qi::unused_type, qi::unused_type) const
  {
    std::cerr << "DBG=" << s << std::endl;
    houtput(a);
  }
};
#endif

struct handle_int
{
  template <typename Context>
  void operator()(int i, Context& ctx, qi::unused_type) const
  {
    ID& ruleAttr = fusion::at_c<0>(ctx.attributes);

    ruleAttr = ID::termFromInteger(i);
    //std::cerr << "created int " << i << std::endl;
  }
};

namespace
{
  inline ID getOrRegisterTerm(RegistryPtr registry, const std::string& s)
  {
    ID id = registry->terms.getIDByString(s);
    if( id == ID_FAIL )
      {
        id = registry->preds.getIDByString(s);
        if( id == ID_FAIL )
          {
            Term term(ID::MAINKIND_TERM, s);
            // we can only get strings or constants
            assert(s[0] == '"' || islower(s[0]));
            id = registry->terms.storeAndGetID(term);
          }
      }
    return id;
  }
}

struct handle_ident
{
  handle_ident(ParserState& state): state(state) {}

  template <typename Context>
  void operator()(const std::string& s, Context& ctx, qi::unused_type) const
  {
    ID& ruleAttr = fusion::at_c<0>(ctx.attributes);

    ID id = getOrRegisterTerm(state.registry, s);
    ruleAttr = id;
    //std::cerr << "created ident '" << s << "'" << std::endl;
  }

  ParserState& state;
};

struct handle_finished_answerset
{
  handle_finished_answerset(ParserState& state): state(state) {}

  void operator()(qi::unused_type, qi::unused_type, qi::unused_type) const
  {
    // add current answer set as full answer set
    DBGLOG(DBG,"handling parsed answer set " << *state.current);
    state.adder(state.current);
    // create empty answer set for subsequent parsing
		state.current.reset(new AnswerSet(state.registry));
  }

  ParserState& state;
};

struct handle_fact
{
  handle_fact(ParserState& state): state(state) {}

  void operator()(
			boost::fusion::vector3<
				boost::optional<char>,
				std::string,
				boost::optional<Tuple> >& attr,
			qi::unused_type, qi::unused_type) const
  {
		// alias for fusion input
		bool strong_neg = !!fusion::at_c<0>(attr);
    assert(!strong_neg);
		const std::string& predicate = fusion::at_c<1>(attr);
    ID predid = getOrRegisterTerm(state.registry, predicate);
    OrdinaryAtom atom(ID::MAINKIND_ATOM);
    atom.tuple.push_back(predid);

    // aux predicates create aux atoms
    if( (predid & ID::PROPERTY_AUX) != 0 )
      atom.kind |= ID::PROPERTY_AUX;

    boost::optional<Tuple>& tup = fusion::at_c<2>(attr);
    if( !!tup )
      atom.tuple.insert(atom.tuple.end(), tup.get().begin(), tup.get().end());

    // TODO lookup by string in registry, then by tuple
    ID id = state.registry->ogatoms.getIDByTuple(atom.tuple);
    if( id == ID_FAIL )
    {
      {
        #warning parsing efficiency problem see HexGrammarPTToASTConverter
        std::stringstream ss;
        RawPrinter printer(ss, state.registry);
        Tuple::const_iterator it = atom.tuple.begin();
        printer.print(*it);
        it++;
        if( it != atom.tuple.end() )
        {
          ss << "(";
          printer.print(*it);
          it++;
          while(it != atom.tuple.end())
          {
            ss << ",";
            printer.print(*it);
            it++;
          }
          ss << ")";
        }
        atom.text = ss.str();
      }
      //DBGLOG(DBG,"storing atom " << atom);
      id = state.registry->ogatoms.storeAndGetID(atom);
    }
    //TODO make more efficient (cache pointer to interpretation or even function object)
    //DBGLOG(DBG,"setting fact " << id);
    state.current->interpretation->setFact(id.address);
  }

  ParserState& state;
};

// "The Grammar"
template<typename Iterator>
struct DLVResultGrammar:
  public qi::grammar<Iterator, ascii::space_type>
{
	DLVResultGrammar(ParserState& state):
		DLVResultGrammar::base_type(dlvline), state(state)
	{
    using spirit::int_;
    using spirit::_val;
    using spirit::_1;
    using qi::lexeme;
    using qi::char_;
    using qi::omit;
    using qi::lit;

		ident
			= lexeme[char_('"') > *(char_ - '"') > char_('"')]
      // @todo test performance
			//| lexeme[char_("a-z") >> *char_("a-zA-Z0-9_")];
			| lexeme[ascii::lower > *(ascii::alnum|char_('_'))];
		groundterm
			= int_ [ handle_int() ]
			| ident [ handle_ident(state) ]
      ;
		fact
			// char_ synthesizes a char attribute!
			= ( -char_('-') > ident > -params ) [ handle_fact(state) ] ;
		params
			%= '(' > groundterm > *(',' > groundterm) > ')';
		answerset
			= (lit('{') >> '}') [ handle_finished_answerset(state) ]
			| (lit('{') > fact > *(',' > fact) > lit('}') [ handle_finished_answerset(state) ]);
    /// @todo: do not throw away weak answer set information but store it
    costline
      = lit("Cost") > +(ascii::alnum|char_("[]<>():"));
		dlvline
			= (-lit("Best model:") >> answerset)
        |
        costline;

    #ifdef BOOST_SPIRIT_DEBUG
		BOOST_SPIRIT_DEBUG_NODE(dlvline);
		BOOST_SPIRIT_DEBUG_NODE(answerset);
		BOOST_SPIRIT_DEBUG_NODE(costline);
		BOOST_SPIRIT_DEBUG_NODE(fact);
		BOOST_SPIRIT_DEBUG_NODE(groundterm);
		BOOST_SPIRIT_DEBUG_NODE(ident);
    #endif
	}

	qi::rule<Iterator, ascii::space_type>                  dlvline,
                                                         answerset,
                                                         fact,
                                                         costline;
	qi::rule<Iterator, ID(), ascii::space_type>            groundterm;
	qi::rule<Iterator, std::string(), ascii::space_type>   ident;
	qi::rule<Iterator, Tuple(), ascii::space_type>         params;

	ParserState& state;
};

void
DLVResultParser::parse(
    std::istream& is,
    AnswerSetAdder adder) throw (SyntaxError)
{
	DLVHEX_BENCHMARK_REGISTER_AND_SCOPE(sid,"DLVResultParser::parse");

	bool dropPredicates =
		(pMode == DLVResultParser::HO);
	ParserState state(reg, adder, dropPredicates);

  typedef std::string::const_iterator forward_iterator_type;
  DLVResultGrammar<forward_iterator_type> grammar(state);
  unsigned errors = 0;
  do
  {
    // @todo: read each line to the next endl, then parse, then get exactly one answer set per parse, maybe reuse the grammar (state can be avoided by using attributes, AtomSetPtr and AtomPtr or just use a new AST with integers instead)

    // get next input line
    std::string input;
    std::getline(is, input);

    // break silently
    if( input.empty() )
      break;

    DBGLOG(DBG,"obtained " << input.size() << " characters from input stream via getline");

    if( is.bad() )
    {
      DBGLOG(DBG,"leaving DLVResultParser loop, stream bits are: "
          "fail " << is.fail() << ", bad " << is.bad() << ", eof " << is.eof());
      break;
    }

    // TODO allocate answer set here, just set bits in parser
    LOG(DBG,"parsing input from DLV: '" << input << "'");

    // convert input iterator to forward iterator, usable by spirit parser
    forward_iterator_type fwd_begin = input.begin();
    forward_iterator_type fwd_end = input.end();

    try
    {
      bool r = qi::phrase_parse(fwd_begin, fwd_end, grammar, ascii::space);

      // @todo: add better error message with position iterator
      if (!r || fwd_begin != fwd_end)
      {
        LOG(ERROR,"for input '" << input << "': r=" << r << " (begin!=end)=" << (fwd_begin != fwd_end));
        errors++;
      }
    }
    catch(const qi::expectation_failure<forward_iterator_type>& e)
    {
      LOG(ERROR,"for input '" << input << "': could not parse DLV output(expectation failure) " << e.what_);
      errors++;
    }
  }
  while(errors < 20);

  if( errors != 0  )
  {
		LOG(ERROR,"error count for parsing DLV output = " << errors);
    throw SyntaxError("Could not parse complete DLV output! (see error log messages)");
  }
}

DLVHEX_NAMESPACE_END

// Local Variables:
// mode: C++
// End:
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit (ITK)
  Module:
  Language:  C++
  Date:
  Version:

Copyright (c) 2000 National Library of Medicine
All rights reserved.

See COPYRIGHT.txt for copyright details.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include <iostream>
// This file has been generated by BuildHeaderTest.tcl
// Test to include each header file for Insight

#include "itkAcosImageAdaptor.h"
#include "itkAddImageAdaptor.h"
#include "itkAddPixelAccessor.h"
#include "itkAffineTransform.txx"
#include "itkArray.txx"
#include "itkArray2D.txx"
#include "itkAsinImageAdaptor.h"
#include "itkAtanImageAdaptor.h"
#include "itkAutoPointer.h"
#include "itkAzimuthElevationToCartesianTransform.txx"
#include "itkBSplineDeformableTransform.txx"
#include "itkBSplineDerivativeKernelFunction.h"
#include "itkBSplineInterpolationWeightFunction.txx"
#include "itkBSplineKernelFunction.h"
#include "itkBackwardDifferenceOperator.txx"
#include "itkBinaryBallStructuringElement.txx"
#include "itkBinaryThresholdImageFunction.txx"
#include "itkBloxBoundaryPointImage.txx"
#include "itkBloxBoundaryPointItem.txx"
#include "itkBloxBoundaryPointPixel.txx"
#include "itkBloxBoundaryProfileImage.txx"
#include "itkBloxBoundaryProfileItem.txx"
#include "itkBloxBoundaryProfilePixel.txx"
#include "itkBloxCoreAtomImage.txx"
#include "itkBloxCoreAtomItem.txx"
#include "itkBloxCoreAtomPixel.txx"
#include "itkBloxImage.txx"
#include "itkBloxItem.h"
#include "itkBloxPixel.txx"
#include "itkBluePixelAccessor.h"
#include "itkBoundingBox.txx"
#include "itkByteSwapper.txx"
#include "itkCellBoundary.txx"
#include "itkCellInterface.txx"
#include "itkCellInterfaceVisitor.h"
#include "itkCenteredAffineTransform.txx"
#include "itkCenteredRigid2DTransform.txx"
#include "itkCenteredTransformInitializer.txx"
#include "itkCentralDifferenceImageFunction.txx"
#include "itkColorTable.txx"
#include "itkCommand.h"
#include "itkConceptChecking.h"
#include "itkConditionalConstIterator.txx"
#include "itkConditionalIterator.txx"
#include "itkConicShellInteriorExteriorSpatialFunction.txx"
#include "itkConstNeighborhoodIterator.txx"
#include "itkConstRandomAccessNeighborhoodIterator.txx"
#include "itkConstShapedNeighborhoodIterator.txx"
#include "itkConstSliceIterator.h"
#include "itkConstSmartNeighborhoodIterator.txx"
#include "itkConstantBoundaryCondition.h"
#include "itkContinuousIndex.h"
#include "itkCosImageAdaptor.h"
#include "itkCovariantVector.txx"
#include "itkCreateObjectFunction.h"
#include "itkDataObject.h"
#include "itkDecisionRuleBase.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkDefaultImageTraits.h"
#include "itkDefaultPixelAccessor.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkDenseFiniteDifferenceImageFilter.txx"
#include "itkDerivativeOperator.txx"
#include "itkDifferenceImageFilter.txx"
#include "itkDirectory.h"
#include "itkDynamicLoader.h"
#include "itkElasticBodyReciprocalSplineKernelTransform.txx"
#include "itkElasticBodySplineKernelTransform.txx"
#include "itkEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkEuler2DTransform.txx"
#include "itkEuler3DTransform.txx"
#include "itkEventObject.h"
#include "itkExceptionObject.h"
#include "itkExpImageAdaptor.h"
#include "itkExpNegativeImageAdaptor.h"
#include "itkFastMutexLock.h"
#include "itkFileOutputWindow.h"
#include "itkFiniteDifferenceFunction.txx"
#include "itkFiniteDifferenceImageFilter.txx"
#include "itkFixedArray.txx"
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
#include "itkFloodFilledFunctionConditionalIterator.txx"
#include "itkFloodFilledImageFunctionConditionalConstIterator.txx"
#include "itkFloodFilledImageFunctionConditionalIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalConstIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalIterator.txx"
#include "itkForwardDifferenceOperator.txx"
#include "itkFrustumSpatialFunction.txx"
#include "itkFunctionBase.h"
#include "itkGaussianKernelFunction.h"
#include "itkGaussianOperator.txx"
#include "itkGaussianSpatialFunction.txx"
#include "itkGreenPixelAccessor.h"
#include "itkHexahedronCell.txx"
#include "itkHexahedronCellTopology.h"
#include "itkIdentityTransform.h"
#include "itkImage.txx"
#include "itkImageAdaptor.txx"
#include "itkImageBase.txx"
#include "itkImageBoundaryCondition.h"
#include "itkImageConstIterator.txx"
#include "itkImageConstIteratorWithIndex.txx"
#include "itkImageContainerInterface.h"
#include "itkImageFunction.txx"
#include "itkImageIterator.txx"
#include "itkImageIteratorWithIndex.txx"
#include "itkImageLinearConstIteratorWithIndex.txx"
#include "itkImageLinearIteratorWithIndex.txx"
#include "itkImageRandomConstIteratorWithIndex.txx"
#include "itkImageRandomIteratorWithIndex.txx"
#include "itkImageRegion.txx"
#include "itkImageRegionConstIterator.txx"
#include "itkImageRegionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionIteratorWithIndex.txx"
#include "itkImageRegionIterator.txx"
#include "itkImageRegionIteratorWithIndex.txx"
#include "itkImageRegionMultidimensionalSplitter.txx"
#include "itkImageRegionReverseConstIterator.txx"
#include "itkImageRegionReverseIterator.txx"
#include "itkImageRegionSplitter.txx"
#include "itkImageReverseConstIterator.txx"
#include "itkImageReverseIterator.txx"
#include "itkImageSliceConstIteratorWithIndex.txx"
#include "itkImageSliceIteratorWithIndex.txx"
#include "itkImageSource.txx"
#include "itkImageToImageFilter.txx"
#include "itkImageToImageFilterDetail.h"
#include "itkImportImageContainer.txx"
#include "itkInPlaceImageFilter.txx"
#include "itkIndent.h"
#include "itkIndex.h"
#include "itkIndexedContainerInterface.h"
#include "itkIntTypes.h"
#include "itkInteriorExteriorSpatialFunction.txx"
#include "itkInterpolateImageFunction.h"
#include "itkIterationReporter.h"
#include "itkKLMSegmentationBorder.h"
#include "itkKLMSegmentationRegion.h"
#include "itkKernelFunction.h"
#include "itkKernelTransform.txx"
#include "itkLaplacianOperator.txx"
#include "itkLevelSet.h"
#include "itkLevelSetFunction.txx"
#include "itkLevelSetFunctionBase.txx"
#include "itkLightObject.h"
#include "itkLightProcessObject.h"
#include "itkLineCell.txx"
#include "itkLinearInterpolateImageFunction.txx"
#include "itkLog10ImageAdaptor.h"
#include "itkLogImageAdaptor.h"
#include "itkMacro.h"
#include "itkMapContainer.txx"
#include "itkMatrix.txx"
#include "itkMaximumDecisionRule.h"
#include "itkMeanImageFunction.txx"
#include "itkMedianImageFunction.txx"
#include "itkMesh.txx"
#include "itkMeshRegion.h"
#include "itkMeshSource.txx"
#include "itkMeshToMeshFilter.txx"
#include "itkMetaDataDictionary.h"
#include "itkMetaDataObject.txx"
#include "itkMetaDataObjectBase.h"
#include "itkMinimumDecisionRule.h"
#include "itkMultiThreader.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkNeighborhood.txx"
#include "itkNeighborhoodAlgorithm.txx"
#include "itkNeighborhoodAllocator.h"
#include "itkNeighborhoodBinaryThresholdImageFunction.txx"
#include "itkNeighborhoodInnerProduct.txx"
#include "itkNeighborhoodIterator.txx"
#include "itkNeighborhoodOperator.txx"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementPixelAccessor.h"
#include "itkNumericTraits.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkObjectFactoryBase.h"
#include "itkObjectStore.txx"
#include "itkOffset.h"
#include "itkOutputWindow.h"
#include "itkPeriodicBoundaryCondition.txx"
#include "itkPixelAccessor.h"
#include "itkPixelTraits.h"
#include "itkPoint.txx"
#include "itkPointLocator.txx"
#include "itkPointSet.txx"
#include "itkPolygonCell.txx"
#include "itkProcessObject.h"
#include "itkProgressReporter.h"
#include "itkQuadraticEdgeCell.txx"
#include "itkQuadraticTriangleCell.txx"
#include "itkQuadraticTriangleCellTopology.h"
#include "itkQuadrilateralCell.txx"
#include "itkQuadrilateralCellTopology.h"
#include "itkQuaternionRigidTransform.txx"
#include "itkRGBAPixel.txx"
#include "itkRGBPixel.txx"
#include "itkRGBToVectorImageAdaptor.h"
#include "itkRGBToVectorPixelAccessor.h"
#include "itkRandomAccessNeighborhoodIterator.txx"
#include "itkRedPixelAccessor.h"
#include "itkRegion.h"
#include "itkRigid2DTransform.txx"
#include "itkRigid3DPerspectiveTransform.txx"
#include "itkRigid3DTransform.txx"
#include "itkSTLConstContainerAdaptor.h"
#include "itkSTLContainerAdaptor.h"
#include "itkScalarToRGBPixelFunctor.txx"
#include "itkScalarVector.h"
#include "itkScaleTransform.txx"
#include "itkSegmentationBorder.h"
#include "itkSegmentationLevelSetFunction.txx"
#include "itkSegmentationRegion.h"
#include "itkShapedNeighborhoodIterator.txx"
#include "itkSimilarity2DTransform.txx"
#include "itkSimpleFastMutexLock.h"
#include "itkSinImageAdaptor.h"
#include "itkSize.h"
#include "itkSliceIterator.h"
#include "itkSmartNeighborhoodIterator.txx"
#include "itkSmartPointer.h"
#include "itkSmartPointerForwardReference.txx"
#include "itkSobelOperator.txx"
#include "itkSpatialFunction.txx"
#include "itkSphereSpatialFunction.txx"
#include "itkSqrtImageAdaptor.h"
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkTanImageAdaptor.h"
#include "itkTetrahedronCell.txx"
#include "itkTetrahedronCellTopology.h"
#include "itkTextOutput.h"
#include "itkThinPlateR2LogRSplineKernelTransform.txx"
#include "itkThinPlateSplineKernelTransform.txx"
#include "itkTimeProbe.h"
#include "itkTimeProbesCollectorBase.h"
#include "itkTimeStamp.h"
#include "itkTorusInteriorExteriorSpatialFunction.txx"
#include "itkTransform.txx"
#include "itkTranslationTransform.txx"
#include "itkTriangleCell.txx"
#include "itkTriangleCellTopology.h"
#include "itkValarrayImageContainer.h"
#include "itkVarianceImageFunction.txx"
#include "itkVector.txx"
#include "itkVectorContainer.txx"
#include "itkVectorInterpolateImageFunction.h"
#include "itkVectorLinearInterpolateImageFunction.txx"
#include "itkVectorNeighborhoodInnerProduct.txx"
#include "itkVectorToRGBImageAdaptor.h"
#include "itkVectorToRGBPixelAccessor.h"
#include "itkVersion.h"
#include "itkVersor.txx"
#include "itkVersorRigid3DTransform.txx"
#include "itkVersorTransform.txx"
#include "itkVertexCell.txx"
#include "itkVolumeSplineKernelTransform.txx"
#include "itkWeakPointer.h"
#include "itkXMLFileOutputWindow.h"
#include "itkZeroFluxNeumannBoundaryCondition.txx"
#include "itk_alloc.h"
#include "itk_hash_map.h"
#include "itk_hash_set.h"
#include "itk_hashtable.h"
#include "vcl_alloc.h"

int main ( int , char*  )
{

  return 0;
}

<commit_msg>ENH: Updated to latest headers<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit (ITK)
  Module:
  Language:  C++
  Date:
  Version:

Copyright (c) 2000 National Library of Medicine
All rights reserved.

See COPYRIGHT.txt for copyright details.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include <iostream>
// This file has been generated by BuildHeaderTest.tcl
// Test to include each header file for Insight

#include "itkAcosImageAdaptor.h"
#include "itkAddImageAdaptor.h"
#include "itkAddPixelAccessor.h"
#include "itkAffineTransform.txx"
#include "itkArray.txx"
#include "itkArray2D.txx"
#include "itkAsinImageAdaptor.h"
#include "itkAtanImageAdaptor.h"
#include "itkAutoPointer.h"
#include "itkAzimuthElevationToCartesianTransform.txx"
#include "itkBSplineDeformableTransform.txx"
#include "itkBSplineDerivativeKernelFunction.h"
#include "itkBSplineInterpolationWeightFunction.txx"
#include "itkBSplineKernelFunction.h"
#include "itkBackwardDifferenceOperator.txx"
#include "itkBinaryBallStructuringElement.txx"
#include "itkBinaryThresholdImageFunction.txx"
#include "itkBloxBoundaryPointImage.txx"
#include "itkBloxBoundaryPointItem.txx"
#include "itkBloxBoundaryPointPixel.txx"
#include "itkBloxBoundaryProfileImage.txx"
#include "itkBloxBoundaryProfileItem.txx"
#include "itkBloxBoundaryProfilePixel.txx"
#include "itkBloxCoreAtomImage.txx"
#include "itkBloxCoreAtomItem.txx"
#include "itkBloxCoreAtomPixel.txx"
#include "itkBloxImage.txx"
#include "itkBloxItem.h"
#include "itkBloxPixel.txx"
#include "itkBluePixelAccessor.h"
#include "itkBoundingBox.txx"
#include "itkByteSwapper.txx"
#include "itkCellBoundary.txx"
#include "itkCellInterface.txx"
#include "itkCellInterfaceVisitor.h"
#include "itkCenteredAffineTransform.txx"
#include "itkCenteredRigid2DTransform.txx"
#include "itkCenteredTransformInitializer.txx"
#include "itkCentralDifferenceImageFunction.txx"
#include "itkColorTable.txx"
#include "itkCommand.h"
#include "itkConceptChecking.h"
#include "itkConditionalConstIterator.txx"
#include "itkConditionalIterator.txx"
#include "itkConicShellInteriorExteriorSpatialFunction.txx"
#include "itkConstNeighborhoodIterator.txx"
#include "itkConstRandomAccessNeighborhoodIterator.txx"
#include "itkConstShapedNeighborhoodIterator.txx"
#include "itkConstSliceIterator.h"
#include "itkConstSmartNeighborhoodIterator.txx"
#include "itkConstantBoundaryCondition.h"
#include "itkContinuousIndex.h"
#include "itkCosImageAdaptor.h"
#include "itkCovariantVector.txx"
#include "itkCreateObjectFunction.h"
#include "itkDataObject.h"
#include "itkDecisionRuleBase.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkDefaultImageTraits.h"
#include "itkDefaultPixelAccessor.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkDenseFiniteDifferenceImageFilter.txx"
#include "itkDerivativeOperator.txx"
#include "itkDifferenceImageFilter.txx"
#include "itkDirectory.h"
#include "itkDynamicLoader.h"
#include "itkElasticBodyReciprocalSplineKernelTransform.txx"
#include "itkElasticBodySplineKernelTransform.txx"
#include "itkEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkEuler2DTransform.txx"
#include "itkEuler3DTransform.txx"
#include "itkEventObject.h"
#include "itkExceptionObject.h"
#include "itkExpImageAdaptor.h"
#include "itkExpNegativeImageAdaptor.h"
#include "itkFastMutexLock.h"
#include "itkFileOutputWindow.h"
#include "itkFiniteDifferenceFunction.txx"
#include "itkFiniteDifferenceImageFilter.txx"
#include "itkFixedArray.txx"
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
#include "itkFloodFilledFunctionConditionalIterator.txx"
#include "itkFloodFilledImageFunctionConditionalConstIterator.txx"
#include "itkFloodFilledImageFunctionConditionalIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalConstIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalIterator.txx"
#include "itkForwardDifferenceOperator.txx"
#include "itkFrustumSpatialFunction.txx"
#include "itkFunctionBase.h"
#include "itkGaussianKernelFunction.h"
#include "itkGaussianOperator.txx"
#include "itkGaussianSpatialFunction.txx"
#include "itkGreenPixelAccessor.h"
#include "itkHexahedronCell.txx"
#include "itkHexahedronCellTopology.h"
#include "itkIdentityTransform.h"
#include "itkImage.txx"
#include "itkImageAdaptor.txx"
#include "itkImageBase.txx"
#include "itkImageBoundaryCondition.h"
#include "itkImageConstIterator.txx"
#include "itkImageConstIteratorWithIndex.txx"
#include "itkImageContainerInterface.h"
#include "itkImageFunction.txx"
#include "itkImageIterator.txx"
#include "itkImageIteratorWithIndex.txx"
#include "itkImageLinearConstIteratorWithIndex.txx"
#include "itkImageLinearIteratorWithIndex.txx"
#include "itkImageRandomConstIteratorWithIndex.txx"
#include "itkImageRandomIteratorWithIndex.txx"
#include "itkImageRegion.txx"
#include "itkImageRegionConstIterator.txx"
#include "itkImageRegionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionIteratorWithIndex.txx"
#include "itkImageRegionIterator.txx"
#include "itkImageRegionIteratorWithIndex.txx"
#include "itkImageRegionMultidimensionalSplitter.txx"
#include "itkImageRegionReverseConstIterator.txx"
#include "itkImageRegionReverseIterator.txx"
#include "itkImageRegionSplitter.txx"
#include "itkImageReverseConstIterator.txx"
#include "itkImageReverseIterator.txx"
#include "itkImageSliceConstIteratorWithIndex.txx"
#include "itkImageSliceIteratorWithIndex.txx"
#include "itkImageSource.txx"
#include "itkImageToImageFilter.txx"
#include "itkImageToImageFilterDetail.h"
#include "itkImportImageContainer.txx"
#include "itkInPlaceImageFilter.txx"
#include "itkIndent.h"
#include "itkIndex.h"
#include "itkIndexedContainerInterface.h"
#include "itkIntTypes.h"
#include "itkInteriorExteriorSpatialFunction.txx"
#include "itkInterpolateImageFunction.h"
#include "itkIterationReporter.h"
#include "itkKLMSegmentationBorder.h"
#include "itkKLMSegmentationRegion.h"
#include "itkKernelFunction.h"
#include "itkKernelTransform.txx"
#include "itkLaplacianOperator.txx"
#include "itkLevelSet.h"
#include "itkLevelSetFunction.txx"
#include "itkLevelSetFunctionBase.txx"
#include "itkLightObject.h"
#include "itkLightProcessObject.h"
#include "itkLineCell.txx"
#include "itkLinearInterpolateImageFunction.txx"
#include "itkLog10ImageAdaptor.h"
#include "itkLogImageAdaptor.h"
#include "itkMacro.h"
#include "itkMapContainer.txx"
#include "itkMatrix.txx"
#include "itkMaximumDecisionRule.h"
#include "itkMaximumRatioDecisionRule.h"
#include "itkMeanImageFunction.txx"
#include "itkMedianImageFunction.txx"
#include "itkMesh.txx"
#include "itkMeshRegion.h"
#include "itkMeshSource.txx"
#include "itkMeshToMeshFilter.txx"
#include "itkMetaDataDictionary.h"
#include "itkMetaDataObject.txx"
#include "itkMetaDataObjectBase.h"
#include "itkMinimumDecisionRule.h"
#include "itkMultiThreader.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkNeighborhood.txx"
#include "itkNeighborhoodAlgorithm.txx"
#include "itkNeighborhoodAllocator.h"
#include "itkNeighborhoodBinaryThresholdImageFunction.txx"
#include "itkNeighborhoodInnerProduct.txx"
#include "itkNeighborhoodIterator.txx"
#include "itkNeighborhoodOperator.txx"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementPixelAccessor.h"
#include "itkNumericTraits.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkObjectFactoryBase.h"
#include "itkObjectStore.txx"
#include "itkOffset.h"
#include "itkOutputWindow.h"
#include "itkPeriodicBoundaryCondition.txx"
#include "itkPixelAccessor.h"
#include "itkPixelTraits.h"
#include "itkPoint.txx"
#include "itkPointLocator.txx"
#include "itkPointSet.txx"
#include "itkPolygonCell.txx"
#include "itkProcessObject.h"
#include "itkProgressReporter.h"
#include "itkQuadraticEdgeCell.txx"
#include "itkQuadraticTriangleCell.txx"
#include "itkQuadraticTriangleCellTopology.h"
#include "itkQuadrilateralCell.txx"
#include "itkQuadrilateralCellTopology.h"
#include "itkQuaternionRigidTransform.txx"
#include "itkRGBAPixel.txx"
#include "itkRGBPixel.txx"
#include "itkRGBToVectorImageAdaptor.h"
#include "itkRGBToVectorPixelAccessor.h"
#include "itkRandomAccessNeighborhoodIterator.txx"
#include "itkRedPixelAccessor.h"
#include "itkRegion.h"
#include "itkRigid2DTransform.txx"
#include "itkRigid3DPerspectiveTransform.txx"
#include "itkRigid3DTransform.txx"
#include "itkSTLConstContainerAdaptor.h"
#include "itkSTLContainerAdaptor.h"
#include "itkScalarToRGBPixelFunctor.txx"
#include "itkScalarVector.h"
#include "itkScaleTransform.txx"
#include "itkSegmentationBorder.h"
#include "itkSegmentationLevelSetFunction.txx"
#include "itkSegmentationRegion.h"
#include "itkShapedNeighborhoodIterator.txx"
#include "itkSimilarity2DTransform.txx"
#include "itkSimpleFastMutexLock.h"
#include "itkSinImageAdaptor.h"
#include "itkSize.h"
#include "itkSliceIterator.h"
#include "itkSmartNeighborhoodIterator.txx"
#include "itkSmartPointer.h"
#include "itkSmartPointerForwardReference.txx"
#include "itkSobelOperator.txx"
#include "itkSpatialFunction.txx"
#include "itkSphereSpatialFunction.txx"
#include "itkSqrtImageAdaptor.h"
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkTanImageAdaptor.h"
#include "itkTetrahedronCell.txx"
#include "itkTetrahedronCellTopology.h"
#include "itkTextOutput.h"
#include "itkThinPlateR2LogRSplineKernelTransform.txx"
#include "itkThinPlateSplineKernelTransform.txx"
#include "itkTimeProbe.h"
#include "itkTimeProbesCollectorBase.h"
#include "itkTimeStamp.h"
#include "itkTorusInteriorExteriorSpatialFunction.txx"
#include "itkTransform.txx"
#include "itkTranslationTransform.txx"
#include "itkTriangleCell.txx"
#include "itkTriangleCellTopology.h"
#include "itkValarrayImageContainer.h"
#include "itkVarianceImageFunction.txx"
#include "itkVector.txx"
#include "itkVectorContainer.txx"
#include "itkVectorInterpolateImageFunction.h"
#include "itkVectorLinearInterpolateImageFunction.txx"
#include "itkVectorNeighborhoodInnerProduct.txx"
#include "itkVectorToRGBImageAdaptor.h"
#include "itkVectorToRGBPixelAccessor.h"
#include "itkVersion.h"
#include "itkVersor.txx"
#include "itkVersorRigid3DTransform.txx"
#include "itkVersorTransform.txx"
#include "itkVertexCell.txx"
#include "itkVolumeSplineKernelTransform.txx"
#include "itkWeakPointer.h"
#include "itkXMLFileOutputWindow.h"
#include "itkZeroFluxNeumannBoundaryCondition.txx"
#include "itk_alloc.h"
#include "itk_hash_map.h"
#include "itk_hash_set.h"
#include "itk_hashtable.h"
#include "vcl_alloc.h"

int main ( int , char*  )
{

  return 0;
}

<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit (ITK)
  Module:
  Language:  C++
  Date:
  Version:

Copyright (c) 2000 National Library of Medicine
All rights reserved.

See COPYRIGHT.txt for copyright details.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include <iostream>
// This file has been generated by BuildHeaderTest.tcl
// Test to include each header file for Insight

#include "itkAcosImageAdaptor.h"
#include "itkAddImageAdaptor.h"
#include "itkAddPixelAccessor.h"
#include "itkAffineTransform.txx"
#include "itkArray.txx"
#include "itkArray2D.txx"
#include "itkAsinImageAdaptor.h"
#include "itkAtanImageAdaptor.h"
#include "itkAutoPointer.h"
#include "itkAzimuthElevationToCartesianTransform.txx"
#include "itkBSplineDeformableTransform.txx"
#include "itkBSplineDerivativeKernelFunction.h"
#include "itkBSplineInterpolationWeightFunction.txx"
#include "itkBSplineKernelFunction.h"
#include "itkBackwardDifferenceOperator.txx"
#include "itkBinaryBallStructuringElement.txx"
#include "itkBinaryThresholdImageFunction.txx"
#include "itkBloxBoundaryPointImage.txx"
#include "itkBloxBoundaryPointItem.txx"
#include "itkBloxBoundaryPointPixel.txx"
#include "itkBloxBoundaryProfileImage.txx"
#include "itkBloxBoundaryProfileItem.txx"
#include "itkBloxBoundaryProfilePixel.txx"
#include "itkBloxCoreAtomImage.txx"
#include "itkBloxCoreAtomItem.txx"
#include "itkBloxCoreAtomPixel.txx"
#include "itkBloxImage.txx"
#include "itkBloxItem.h"
#include "itkBloxPixel.txx"
#include "itkBluePixelAccessor.h"
#include "itkBoundingBox.txx"
#include "itkByteSwapper.txx"
#include "itkCellBoundary.txx"
#include "itkCellInterface.txx"
#include "itkCellInterfaceVisitor.h"
#include "itkCenteredRigid2DTransform.txx"
#include "itkCentralDifferenceImageFunction.txx"
#include "itkColorTable.txx"
#include "itkCommand.h"
#include "itkConceptChecking.h"
#include "itkConditionalConstIterator.txx"
#include "itkConditionalIterator.txx"
#include "itkConicShellInteriorExteriorSpatialFunction.txx"
#include "itkConstNeighborhoodIterator.txx"
#include "itkConstRandomAccessNeighborhoodIterator.txx"
#include "itkConstShapedNeighborhoodIterator.txx"
#include "itkConstSliceIterator.h"
#include "itkConstSmartNeighborhoodIterator.txx"
#include "itkConstantBoundaryCondition.h"
#include "itkContinuousIndex.h"
#include "itkCosImageAdaptor.h"
#include "itkCovariantVector.txx"
#include "itkCreateObjectFunction.h"
#include "itkDataObject.h"
#include "itkDecisionRuleBase.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkDefaultImageTraits.h"
#include "itkDefaultPixelAccessor.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkDenseFiniteDifferenceImageFilter.txx"
#include "itkDerivativeOperator.txx"
#include "itkDifferenceImageFilter.txx"
#include "itkDirectory.h"
#include "itkDynamicLoader.h"
#include "itkElasticBodyReciprocalSplineKernelTransform.txx"
#include "itkElasticBodySplineKernelTransform.txx"
#include "itkEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkEntropyPreservingGradientMagnitudeImageFunction.txx"
#include "itkEuler2DTransform.txx"
#include "itkEventObject.h"
#include "itkExceptionObject.h"
#include "itkExpImageAdaptor.h"
#include "itkExpNegativeImageAdaptor.h"
#include "itkFastMutexLock.h"
#include "itkFileOutputWindow.h"
#include "itkFiniteDifferenceFunction.txx"
#include "itkFiniteDifferenceImageFilter.txx"
#include "itkFixedArray.txx"
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
#include "itkFloodFilledFunctionConditionalIterator.txx"
#include "itkFloodFilledImageFunctionConditionalConstIterator.txx"
#include "itkFloodFilledImageFunctionConditionalIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalConstIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalIterator.txx"
#include "itkForwardDifferenceOperator.txx"
#include "itkFrustumSpatialFunction.txx"
#include "itkFunctionBase.h"
#include "itkGaussianKernelFunction.h"
#include "itkGaussianOperator.txx"
#include "itkGaussianSpatialFunction.txx"
#include "itkGreenPixelAccessor.h"
#include "itkHexahedronCell.txx"
#include "itkHexahedronCellTopology.h"
#include "itkIdentityTransform.h"
#include "itkImage.txx"
#include "itkImageAdaptor.txx"
#include "itkImageBase.txx"
#include "itkImageBoundaryCondition.h"
#include "itkImageConstIterator.txx"
#include "itkImageConstIteratorWithIndex.txx"
#include "itkImageContainerInterface.h"
#include "itkImageFunction.txx"
#include "itkImageIO.h"
#include "itkImageIOCommon.h"
#include "itkImageIterator.txx"
#include "itkImageIteratorWithIndex.txx"
#include "itkImageLinearConstIteratorWithIndex.txx"
#include "itkImageLinearIteratorWithIndex.txx"
#include "itkImageRandomConstIteratorWithIndex.txx"
#include "itkImageRandomIteratorWithIndex.txx"
#include "itkImageRegion.txx"
#include "itkImageRegionConstIterator.txx"
#include "itkImageRegionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionIteratorWithIndex.txx"
#include "itkImageRegionIterator.txx"
#include "itkImageRegionIteratorWithIndex.txx"
#include "itkImageRegionMultidimensionalSplitter.txx"
#include "itkImageRegionReverseConstIterator.txx"
#include "itkImageRegionReverseIterator.txx"
#include "itkImageRegionSplitter.txx"
#include "itkImageReverseConstIterator.txx"
#include "itkImageReverseIterator.txx"
#include "itkImageSliceConstIteratorWithIndex.txx"
#include "itkImageSliceIteratorWithIndex.txx"
#include "itkImageSource.txx"
#include "itkImageToImageFilter.txx"
#include "itkImageToImageFilterDetail.h"
#include "itkImportImageContainer.txx"
#include "itkIndent.h"
#include "itkIndex.h"
#include "itkIndexedContainerInterface.h"
#include "itkIntTypes.h"
#include "itkInteriorExteriorSpatialFunction.txx"
#include "itkInterpolateImageFunction.h"
#include "itkIterationReporter.h"
#include "itkKLMSegmentationBorder.h"
#include "itkKLMSegmentationRegion.h"
#include "itkKernelFunction.h"
#include "itkKernelTransform.txx"
#include "itkLaplacianOperator.txx"
#include "itkLevelSet.h"
#include "itkLevelSetCurvatureFunction.txx"
#include "itkLevelSetFunction.txx"
#include "itkLevelSetFunctionBase.txx"
#include "itkLightObject.h"
#include "itkLightProcessObject.h"
#include "itkLineCell.txx"
#include "itkLinearInterpolateImageFunction.txx"
#include "itkLog10ImageAdaptor.h"
#include "itkLogImageAdaptor.h"
#include "itkMacro.h"
#include "itkMapContainer.txx"
#include "itkMatrix.txx"
#include "itkMaximumDecisionRule.h"
#include "itkMeanImageFunction.txx"
#include "itkMedianImageFunction.txx"
#include "itkMesh.txx"
#include "itkMeshRegion.h"
#include "itkMeshSource.txx"
#include "itkMeshToMeshFilter.txx"
#include "itkMinimumDecisionRule.h"
#include "itkMultiThreader.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkNeighborhood.txx"
#include "itkNeighborhoodAlgorithm.txx"
#include "itkNeighborhoodAllocator.h"
#include "itkNeighborhoodBinaryThresholdImageFunction.txx"
#include "itkNeighborhoodInnerProduct.txx"
#include "itkNeighborhoodIterator.txx"
#include "itkNeighborhoodOperator.txx"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementPixelAccessor.h"
#include "itkNumericTraits.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkObjectFactoryBase.h"
#include "itkObjectStore.txx"
#include "itkOffset.h"
#include "itkOutputWindow.h"
#include "itkPixelAccessor.h"
#include "itkPixelTraits.h"
#include "itkPoint.txx"
#include "itkPointLocator.txx"
#include "itkPointSet.txx"
#include "itkPolygonCell.txx"
#include "itkProcessObject.h"
#include "itkProgressReporter.h"
#include "itkQuadraticEdgeCell.txx"
#include "itkQuadraticTriangleCell.txx"
#include "itkQuadraticTriangleCellTopology.h"
#include "itkQuadrilateralCell.txx"
#include "itkQuadrilateralCellTopology.h"
#include "itkQuaternionRigidTransform.txx"
#include "itkRGBAPixel.txx"
#include "itkRGBPixel.txx"
#include "itkRandomAccessNeighborhoodIterator.txx"
#include "itkRedPixelAccessor.h"
#include "itkRegion.h"
#include "itkRigid2DTransform.txx"
#include "itkRigid3DPerspectiveTransform.txx"
#include "itkRigid3DTransform.txx"
#include "itkSTLConstContainerAdaptor.h"
#include "itkSTLContainerAdaptor.h"
#include "itkScalarVector.h"
#include "itkScaleTransform.txx"
#include "itkSegmentationBorder.h"
#include "itkSegmentationLevelSetFunction.txx"
#include "itkSegmentationRegion.h"
#include "itkShapedNeighborhoodIterator.txx"
#include "itkSimilarity2DTransform.txx"
#include "itkSimpleFastMutexLock.h"
#include "itkSinImageAdaptor.h"
#include "itkSize.h"
#include "itkSliceIterator.h"
#include "itkSmartNeighborhoodIterator.txx"
#include "itkSmartPointer.h"
#include "itkSmartPointerForwardReference.txx"
#include "itkSobelOperator.txx"
#include "itkSpatialFunction.txx"
#include "itkSphereSpatialFunction.txx"
#include "itkSqrtImageAdaptor.h"
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkTanImageAdaptor.h"
#include "itkTetrahedronCell.txx"
#include "itkTetrahedronCellTopology.h"
#include "itkTextOutput.h"
#include "itkThinPlateR2LogRSplineKernelTransform.txx"
#include "itkThinPlateSplineKernelTransform.txx"
#include "itkTimeProbe.h"
#include "itkTimeProbesCollectorBase.h"
#include "itkTimeStamp.h"
#include "itkTorusInteriorExteriorSpatialFunction.txx"
#include "itkTransform.txx"
#include "itkTranslationTransform.txx"
#include "itkTriangleCell.txx"
#include "itkTriangleCellTopology.h"
#include "itkUpwindDerivativeImageFunction.txx"
#include "itkValarrayImageContainer.h"
#include "itkVarianceImageFunction.txx"
#include "itkVector.txx"
#include "itkVectorContainer.txx"
#include "itkVectorInterpolateImageFunction.h"
#include "itkVectorLinearInterpolateImageFunction.txx"
#include "itkVectorNeighborhoodInnerProduct.txx"
#include "itkVersion.h"
#include "itkVersor.txx"
#include "itkVersorRigid3DTransform.txx"
#include "itkVersorTransform.txx"
#include "itkVertexCell.txx"
#include "itkVolumeSplineKernelTransform.txx"
#include "itkWeakPointer.h"
#include "itkXMLFileOutputWindow.h"
#include "itkZeroFluxNeumannBoundaryCondition.txx"
#include "itk_alloc.h"
#include "itk_hash_map.h"
#include "itk_hash_set.h"
#include "itk_hashtable.h"
#include "vcl_alloc.h"

int main ( int , char*  )
{

  return 0;
}

<commit_msg>ENH: Updated to latest headers<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit (ITK)
  Module:
  Language:  C++
  Date:
  Version:

Copyright (c) 2000 National Library of Medicine
All rights reserved.

See COPYRIGHT.txt for copyright details.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include <iostream>
// This file has been generated by BuildHeaderTest.tcl
// Test to include each header file for Insight

#include "itkAcosImageAdaptor.h"
#include "itkAddImageAdaptor.h"
#include "itkAddPixelAccessor.h"
#include "itkAffineTransform.txx"
#include "itkArray.txx"
#include "itkArray2D.txx"
#include "itkAsinImageAdaptor.h"
#include "itkAtanImageAdaptor.h"
#include "itkAutoPointer.h"
#include "itkAzimuthElevationToCartesianTransform.txx"
#include "itkBSplineDeformableTransform.txx"
#include "itkBSplineDerivativeKernelFunction.h"
#include "itkBSplineInterpolationWeightFunction.txx"
#include "itkBSplineKernelFunction.h"
#include "itkBackwardDifferenceOperator.txx"
#include "itkBinaryBallStructuringElement.txx"
#include "itkBinaryThresholdImageFunction.txx"
#include "itkBloxBoundaryPointImage.txx"
#include "itkBloxBoundaryPointItem.txx"
#include "itkBloxBoundaryPointPixel.txx"
#include "itkBloxBoundaryProfileImage.txx"
#include "itkBloxBoundaryProfileItem.txx"
#include "itkBloxBoundaryProfilePixel.txx"
#include "itkBloxCoreAtomImage.txx"
#include "itkBloxCoreAtomItem.txx"
#include "itkBloxCoreAtomPixel.txx"
#include "itkBloxImage.txx"
#include "itkBloxItem.h"
#include "itkBloxPixel.txx"
#include "itkBluePixelAccessor.h"
#include "itkBoundingBox.txx"
#include "itkByteSwapper.txx"
#include "itkCellBoundary.txx"
#include "itkCellInterface.txx"
#include "itkCellInterfaceVisitor.h"
#include "itkCenteredRigid2DTransform.txx"
#include "itkCenteredTransformInitializer.txx"
#include "itkCentralDifferenceImageFunction.txx"
#include "itkColorTable.txx"
#include "itkCommand.h"
#include "itkConceptChecking.h"
#include "itkConditionalConstIterator.txx"
#include "itkConditionalIterator.txx"
#include "itkConicShellInteriorExteriorSpatialFunction.txx"
#include "itkConstNeighborhoodIterator.txx"
#include "itkConstRandomAccessNeighborhoodIterator.txx"
#include "itkConstShapedNeighborhoodIterator.txx"
#include "itkConstSliceIterator.h"
#include "itkConstSmartNeighborhoodIterator.txx"
#include "itkConstantBoundaryCondition.h"
#include "itkContinuousIndex.h"
#include "itkCosImageAdaptor.h"
#include "itkCovariantVector.txx"
#include "itkCreateObjectFunction.h"
#include "itkDataObject.h"
#include "itkDecisionRuleBase.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkDefaultImageTraits.h"
#include "itkDefaultPixelAccessor.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkDenseFiniteDifferenceImageFilter.txx"
#include "itkDerivativeOperator.txx"
#include "itkDifferenceImageFilter.txx"
#include "itkDirectory.h"
#include "itkDynamicLoader.h"
#include "itkElasticBodyReciprocalSplineKernelTransform.txx"
#include "itkElasticBodySplineKernelTransform.txx"
#include "itkEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkEntropyPreservingGradientMagnitudeImageFunction.txx"
#include "itkEuler2DTransform.txx"
#include "itkEventObject.h"
#include "itkExceptionObject.h"
#include "itkExpImageAdaptor.h"
#include "itkExpNegativeImageAdaptor.h"
#include "itkFastMutexLock.h"
#include "itkFileOutputWindow.h"
#include "itkFiniteDifferenceFunction.txx"
#include "itkFiniteDifferenceImageFilter.txx"
#include "itkFixedArray.txx"
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
#include "itkFloodFilledFunctionConditionalIterator.txx"
#include "itkFloodFilledImageFunctionConditionalConstIterator.txx"
#include "itkFloodFilledImageFunctionConditionalIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalConstIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalIterator.txx"
#include "itkForwardDifferenceOperator.txx"
#include "itkFrustumSpatialFunction.txx"
#include "itkFunctionBase.h"
#include "itkGaussianKernelFunction.h"
#include "itkGaussianOperator.txx"
#include "itkGaussianSpatialFunction.txx"
#include "itkGreenPixelAccessor.h"
#include "itkHexahedronCell.txx"
#include "itkHexahedronCellTopology.h"
#include "itkIdentityTransform.h"
#include "itkImage.txx"
#include "itkImageAdaptor.txx"
#include "itkImageBase.txx"
#include "itkImageBoundaryCondition.h"
#include "itkImageConstIterator.txx"
#include "itkImageConstIteratorWithIndex.txx"
#include "itkImageContainerInterface.h"
#include "itkImageFunction.txx"
#include "itkImageIO.h"
#include "itkImageIOCommon.h"
#include "itkImageIterator.txx"
#include "itkImageIteratorWithIndex.txx"
#include "itkImageLinearConstIteratorWithIndex.txx"
#include "itkImageLinearIteratorWithIndex.txx"
#include "itkImageRandomConstIteratorWithIndex.txx"
#include "itkImageRandomIteratorWithIndex.txx"
#include "itkImageRegion.txx"
#include "itkImageRegionConstIterator.txx"
#include "itkImageRegionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionIteratorWithIndex.txx"
#include "itkImageRegionIterator.txx"
#include "itkImageRegionIteratorWithIndex.txx"
#include "itkImageRegionMultidimensionalSplitter.txx"
#include "itkImageRegionReverseConstIterator.txx"
#include "itkImageRegionReverseIterator.txx"
#include "itkImageRegionSplitter.txx"
#include "itkImageReverseConstIterator.txx"
#include "itkImageReverseIterator.txx"
#include "itkImageSliceConstIteratorWithIndex.txx"
#include "itkImageSliceIteratorWithIndex.txx"
#include "itkImageSource.txx"
#include "itkImageToImageFilter.txx"
#include "itkImageToImageFilterDetail.h"
#include "itkImportImageContainer.txx"
#include "itkIndent.h"
#include "itkIndex.h"
#include "itkIndexedContainerInterface.h"
#include "itkIntTypes.h"
#include "itkInteriorExteriorSpatialFunction.txx"
#include "itkInterpolateImageFunction.h"
#include "itkIterationReporter.h"
#include "itkKLMSegmentationBorder.h"
#include "itkKLMSegmentationRegion.h"
#include "itkKernelFunction.h"
#include "itkKernelTransform.txx"
#include "itkLaplacianOperator.txx"
#include "itkLevelSet.h"
#include "itkLevelSetCurvatureFunction.txx"
#include "itkLevelSetFunction.txx"
#include "itkLevelSetFunctionBase.txx"
#include "itkLightObject.h"
#include "itkLightProcessObject.h"
#include "itkLineCell.txx"
#include "itkLinearInterpolateImageFunction.txx"
#include "itkLog10ImageAdaptor.h"
#include "itkLogImageAdaptor.h"
#include "itkMacro.h"
#include "itkMapContainer.txx"
#include "itkMatrix.txx"
#include "itkMaximumDecisionRule.h"
#include "itkMeanImageFunction.txx"
#include "itkMedianImageFunction.txx"
#include "itkMesh.txx"
#include "itkMeshRegion.h"
#include "itkMeshSource.txx"
#include "itkMeshToMeshFilter.txx"
#include "itkMinimumDecisionRule.h"
#include "itkMultiThreader.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkNeighborhood.txx"
#include "itkNeighborhoodAlgorithm.txx"
#include "itkNeighborhoodAllocator.h"
#include "itkNeighborhoodBinaryThresholdImageFunction.txx"
#include "itkNeighborhoodInnerProduct.txx"
#include "itkNeighborhoodIterator.txx"
#include "itkNeighborhoodOperator.txx"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementPixelAccessor.h"
#include "itkNumericTraits.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkObjectFactoryBase.h"
#include "itkObjectStore.txx"
#include "itkOffset.h"
#include "itkOutputWindow.h"
#include "itkPixelAccessor.h"
#include "itkPixelTraits.h"
#include "itkPoint.txx"
#include "itkPointLocator.txx"
#include "itkPointSet.txx"
#include "itkPolygonCell.txx"
#include "itkProcessObject.h"
#include "itkProgressReporter.h"
#include "itkQuadraticEdgeCell.txx"
#include "itkQuadraticTriangleCell.txx"
#include "itkQuadraticTriangleCellTopology.h"
#include "itkQuadrilateralCell.txx"
#include "itkQuadrilateralCellTopology.h"
#include "itkQuaternionRigidTransform.txx"
#include "itkRGBAPixel.txx"
#include "itkRGBPixel.txx"
#include "itkRandomAccessNeighborhoodIterator.txx"
#include "itkRedPixelAccessor.h"
#include "itkRegion.h"
#include "itkRigid2DTransform.txx"
#include "itkRigid3DPerspectiveTransform.txx"
#include "itkRigid3DTransform.txx"
#include "itkSTLConstContainerAdaptor.h"
#include "itkSTLContainerAdaptor.h"
#include "itkScalarVector.h"
#include "itkScaleTransform.txx"
#include "itkSegmentationBorder.h"
#include "itkSegmentationLevelSetFunction.txx"
#include "itkSegmentationRegion.h"
#include "itkShapedNeighborhoodIterator.txx"
#include "itkSimilarity2DTransform.txx"
#include "itkSimpleFastMutexLock.h"
#include "itkSinImageAdaptor.h"
#include "itkSize.h"
#include "itkSliceIterator.h"
#include "itkSmartNeighborhoodIterator.txx"
#include "itkSmartPointer.h"
#include "itkSmartPointerForwardReference.txx"
#include "itkSobelOperator.txx"
#include "itkSpatialFunction.txx"
#include "itkSphereSpatialFunction.txx"
#include "itkSqrtImageAdaptor.h"
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkTanImageAdaptor.h"
#include "itkTetrahedronCell.txx"
#include "itkTetrahedronCellTopology.h"
#include "itkTextOutput.h"
#include "itkThinPlateR2LogRSplineKernelTransform.txx"
#include "itkThinPlateSplineKernelTransform.txx"
#include "itkTimeProbe.h"
#include "itkTimeProbesCollectorBase.h"
#include "itkTimeStamp.h"
#include "itkTorusInteriorExteriorSpatialFunction.txx"
#include "itkTransform.txx"
#include "itkTranslationTransform.txx"
#include "itkTriangleCell.txx"
#include "itkTriangleCellTopology.h"
#include "itkUpwindDerivativeImageFunction.txx"
#include "itkValarrayImageContainer.h"
#include "itkVarianceImageFunction.txx"
#include "itkVector.txx"
#include "itkVectorContainer.txx"
#include "itkVectorInterpolateImageFunction.h"
#include "itkVectorLinearInterpolateImageFunction.txx"
#include "itkVectorNeighborhoodInnerProduct.txx"
#include "itkVersion.h"
#include "itkVersor.txx"
#include "itkVersorRigid3DTransform.txx"
#include "itkVersorTransform.txx"
#include "itkVertexCell.txx"
#include "itkVolumeSplineKernelTransform.txx"
#include "itkWeakPointer.h"
#include "itkXMLFileOutputWindow.h"
#include "itkZeroFluxNeumannBoundaryCondition.txx"
#include "itk_alloc.h"
#include "itk_hash_map.h"
#include "itk_hash_set.h"
#include "itk_hashtable.h"
#include "vcl_alloc.h"

int main ( int , char*  )
{

  return 0;
}

<|endoftext|>


<commit_before>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2018, 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 John Haddon 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 "GafferScene/UDIMQuery.h"
#include "GafferScene/SceneAlgo.h"

#include "IECoreScene/MeshPrimitive.h"
#include "IECoreScene/Output.h"
#include "IECore/StringAlgo.h"

#include "tbb/concurrent_vector.h"
#include "boost/algorithm/string/replace.hpp"
#include "boost/container/flat_set.hpp"

using namespace IECore;
using namespace IECoreScene;
using namespace Gaffer;
using namespace GafferScene;

IE_CORE_DEFINERUNTIMETYPED( UDIMQuery );

size_t UDIMQuery::g_firstPlugIndex = 0;

UDIMQuery::UDIMQuery( const std::string &name )
	:	ComputeNode( name )
{
	storeIndexOfNextChild( g_firstPlugIndex );
	addChild( new ScenePlug( "in", Plug::In ) );
	addChild( new StringPlug( "uvSet", Plug::In, "uv" ) );
	addChild( new StringPlug( "attributes", Plug::In, "" ) );
	addChild( new FilterPlug( "filter" ) );
	addChild( new CompoundObjectPlug( "out", Plug::Out, new IECore::CompoundObject(), Plug::Flags::Default ) );
}

UDIMQuery::~UDIMQuery()
{
}

GafferScene::ScenePlug *UDIMQuery::inPlug()
{
	return getChild<ScenePlug>( g_firstPlugIndex );
}

const GafferScene::ScenePlug *UDIMQuery::inPlug() const
{
	return getChild<ScenePlug>( g_firstPlugIndex );
}

Gaffer::StringPlug *UDIMQuery::uvSetPlug()
{
	return getChild<StringPlug>( g_firstPlugIndex + 1 );
}

const Gaffer::StringPlug *UDIMQuery::uvSetPlug() const
{
	return getChild<StringPlug>( g_firstPlugIndex + 1 );
}

Gaffer::StringPlug *UDIMQuery::attributesPlug()
{
	return getChild<StringPlug>( g_firstPlugIndex + 2 );
}

const Gaffer::StringPlug *UDIMQuery::attributesPlug() const
{
	return getChild<StringPlug>( g_firstPlugIndex + 2 );
}

GafferScene::FilterPlug *UDIMQuery::filterPlug()
{
	return getChild<FilterPlug>( g_firstPlugIndex + 3 );
}

const GafferScene::FilterPlug *UDIMQuery::filterPlug() const
{
	return getChild<FilterPlug>( g_firstPlugIndex + 3 );
}

Gaffer::CompoundObjectPlug *UDIMQuery::outPlug()
{
	return getChild<CompoundObjectPlug>( g_firstPlugIndex + 4 );
}

const Gaffer::CompoundObjectPlug *UDIMQuery::outPlug() const
{
	return getChild<CompoundObjectPlug>( g_firstPlugIndex + 4 );
}

void UDIMQuery::affects( const Plug *input, AffectedPlugsContainer &outputs ) const
{
	ComputeNode::affects( input, outputs );

	if(
		input == uvSetPlug() ||
		input == attributesPlug() ||
		input == filterPlug() ||
		input == inPlug()->objectPlug() ||
		input == inPlug()->attributesPlug()
	)
	{
		outputs.push_back( outPlug() );
	}
}

namespace
{

struct InfoHashAccumulator
{
	bool operator()( const GafferScene::ScenePlug *in, const GafferScene::ScenePlug::ScenePath &path )
	{
		IECore::MurmurHash locationHash;
		in->objectPlug()->hash( locationHash );
		locationHash.append( in->fullAttributesHash( path ) );
		std::string pathStr;
		ScenePlug::pathToString( path, pathStr );
		m_hashes.push_back( std::pair<std::string, IECore::MurmurHash>( pathStr, locationHash ) );
		return true;
	}

	void appendHash( IECore::MurmurHash &h )
	{
		std::sort( m_hashes.begin(), m_hashes.end() );
		for( const auto &i : m_hashes )
		{
			h.append( i.first );
			h.append( i.second );
		}
	}

	tbb::concurrent_vector< std::pair< std::string, IECore::MurmurHash > > m_hashes;
};

} // namespace

void UDIMQuery::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	ComputeNode::hash( output, context, h );
	if( output == outPlug() )
	{
		uvSetPlug()->hash( h );
		attributesPlug()->hash( h );

		InfoHashAccumulator f;
		GafferScene::SceneAlgo::filteredParallelTraverse( inPlug(), filterPlug(), f );
		f.appendHash( h );
	}
}

namespace {

struct BakeInfoData
{
	std::string mesh;
	boost::container::flat_set<int> udims;
	CompoundObjectPtr attributes;
};

struct InfoDataAccumulator
{
	InfoDataAccumulator( std::string uvSet, std::string attributeNames )
		: m_uvSet( uvSet ), m_attributeNames( attributeNames )
	{
	}

	bool operator()( const GafferScene::ScenePlug *in, const GafferScene::ScenePlug::ScenePath &path )
	{
		IECore::CompoundObjectPtr locationDict;

		IECore::ConstObjectPtr object = in->objectPlug()->getValue();
		const IECoreScene::MeshPrimitive *meshPrimitive = runTimeCast<const IECoreScene::MeshPrimitive>( object.get() );
		if( !meshPrimitive ) return true;

		// First check if there are face-varying UVs
		bool faceVarying = true;
		auto uvs = meshPrimitive->variableIndexedView<IECore::V2fVectorData>( m_uvSet,  IECoreScene::PrimitiveVariable::FaceVarying );
		if( !uvs )
		{
			// Next check for vertex UVs
			faceVarying = false;
			uvs = meshPrimitive->variableIndexedView<IECore::V2fVectorData>( m_uvSet,  IECoreScene::PrimitiveVariable::Vertex );
		}

		if( !uvs )
		{
			// No face-varying or vertex UVs
			return true;
		}

		const IntVectorData *vertsPerFaceData = meshPrimitive->verticesPerFace();
		const std::vector<int> &vertsPerFace = vertsPerFaceData->readable();

		BakeInfoData &info = *m_data.grow_by( 1 );
		ScenePlug::pathToString( path, info.mesh );

		// We check the center UVs of each face, because the edge uvs could lie directly on a UDIM boundary,
		// and without checking adjacency information, it would be impossible to tell which UDIM the edge
		// belongs to.  Checking face centers is fairly simple, and is completely accurate except in extreme
		// cases of polygons spanning multiple UDIMs, which is not done according to UDIM conventions.
		int faceVertId = 0;
		for( int numVerts : vertsPerFace )
		{
			Imath::V2f accum = Imath::V2f(0);
			if( faceVarying )
			{
				for( int i = 0; i < numVerts; i++ )
				{
					accum += (*uvs)[faceVertId];
					faceVertId++;
				}
			}
			else
			{
				for( int i = 0; i < numVerts; i++ )
				{
					accum += (*uvs)[ meshPrimitive->vertexIds()->readable()[faceVertId] ];
					faceVertId++;
				}
			}
			Imath::V2f centerUV = accum / numVerts;
			int udim = 1001 + int( floor( centerUV[0] ) ) + 10 * int( floor( centerUV[1] ) );

			info.udims.insert( udim );
		}

		info.attributes = new CompoundObject();
		if( m_attributeNames.size() )
		{
			IECore::ConstCompoundObjectPtr inAttributes = in->fullAttributes( path );
			for( const auto &i : inAttributes->members() )
			{
				if( StringAlgo::matchMultiple( i.first, m_attributeNames ) )
				{
					info.attributes->members()[ i.first ] = i.second;
				}
			}
		}

		return true;
	}

	std::string m_uvSet;
	IECore::StringAlgo::MatchPattern m_attributeNames;
	tbb::concurrent_vector< BakeInfoData > m_data;
};

} // namespace

void UDIMQuery::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == outPlug() )
	{
		InfoDataAccumulator f( uvSetPlug()->getValue(), attributesPlug()->getValue() );
		GafferScene::SceneAlgo::filteredParallelTraverse( inPlug(), filterPlug(), f );

		IECore::CompoundObjectPtr result = new IECore::CompoundObject();

		for( const auto &i : f.m_data )
		{
			for( int udim : i.udims )
			{
				std::string udimStr = std::to_string( udim );

				CompoundObjectPtr udimEntry = result->member<CompoundObject>(
					udimStr, /* throwExceptions = */ false, /* createIfMissing = */ true
				);

				// Result treated as const anyway, so this is safe.
				udimEntry->members()[i.mesh] = const_cast<CompoundObject*>( i.attributes.get() );
			}
		}
		static_cast<CompoundObjectPlug *>( output )->setValue( result );
	}
	else
	{
		ComputeNode::compute( output, context );
	}
}
<commit_msg>UDIMQuery : Report bad UVs instead of allowing crash<commit_after>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2018, 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 John Haddon 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 "GafferScene/UDIMQuery.h"
#include "GafferScene/SceneAlgo.h"

#include "IECoreScene/MeshPrimitive.h"
#include "IECoreScene/Output.h"
#include "IECore/StringAlgo.h"

#include "tbb/concurrent_vector.h"
#include "boost/algorithm/string/replace.hpp"
#include "boost/container/flat_set.hpp"

using namespace IECore;
using namespace IECoreScene;
using namespace Gaffer;
using namespace GafferScene;

IE_CORE_DEFINERUNTIMETYPED( UDIMQuery );

size_t UDIMQuery::g_firstPlugIndex = 0;

UDIMQuery::UDIMQuery( const std::string &name )
	:	ComputeNode( name )
{
	storeIndexOfNextChild( g_firstPlugIndex );
	addChild( new ScenePlug( "in", Plug::In ) );
	addChild( new StringPlug( "uvSet", Plug::In, "uv" ) );
	addChild( new StringPlug( "attributes", Plug::In, "" ) );
	addChild( new FilterPlug( "filter" ) );
	addChild( new CompoundObjectPlug( "out", Plug::Out, new IECore::CompoundObject(), Plug::Flags::Default ) );
}

UDIMQuery::~UDIMQuery()
{
}

GafferScene::ScenePlug *UDIMQuery::inPlug()
{
	return getChild<ScenePlug>( g_firstPlugIndex );
}

const GafferScene::ScenePlug *UDIMQuery::inPlug() const
{
	return getChild<ScenePlug>( g_firstPlugIndex );
}

Gaffer::StringPlug *UDIMQuery::uvSetPlug()
{
	return getChild<StringPlug>( g_firstPlugIndex + 1 );
}

const Gaffer::StringPlug *UDIMQuery::uvSetPlug() const
{
	return getChild<StringPlug>( g_firstPlugIndex + 1 );
}

Gaffer::StringPlug *UDIMQuery::attributesPlug()
{
	return getChild<StringPlug>( g_firstPlugIndex + 2 );
}

const Gaffer::StringPlug *UDIMQuery::attributesPlug() const
{
	return getChild<StringPlug>( g_firstPlugIndex + 2 );
}

GafferScene::FilterPlug *UDIMQuery::filterPlug()
{
	return getChild<FilterPlug>( g_firstPlugIndex + 3 );
}

const GafferScene::FilterPlug *UDIMQuery::filterPlug() const
{
	return getChild<FilterPlug>( g_firstPlugIndex + 3 );
}

Gaffer::CompoundObjectPlug *UDIMQuery::outPlug()
{
	return getChild<CompoundObjectPlug>( g_firstPlugIndex + 4 );
}

const Gaffer::CompoundObjectPlug *UDIMQuery::outPlug() const
{
	return getChild<CompoundObjectPlug>( g_firstPlugIndex + 4 );
}

void UDIMQuery::affects( const Plug *input, AffectedPlugsContainer &outputs ) const
{
	ComputeNode::affects( input, outputs );

	if(
		input == uvSetPlug() ||
		input == attributesPlug() ||
		input == filterPlug() ||
		input == inPlug()->objectPlug() ||
		input == inPlug()->attributesPlug()
	)
	{
		outputs.push_back( outPlug() );
	}
}

namespace
{

struct InfoHashAccumulator
{
	bool operator()( const GafferScene::ScenePlug *in, const GafferScene::ScenePlug::ScenePath &path )
	{
		IECore::MurmurHash locationHash;
		in->objectPlug()->hash( locationHash );
		locationHash.append( in->fullAttributesHash( path ) );
		std::string pathStr;
		ScenePlug::pathToString( path, pathStr );
		m_hashes.push_back( std::pair<std::string, IECore::MurmurHash>( pathStr, locationHash ) );
		return true;
	}

	void appendHash( IECore::MurmurHash &h )
	{
		std::sort( m_hashes.begin(), m_hashes.end() );
		for( const auto &i : m_hashes )
		{
			h.append( i.first );
			h.append( i.second );
		}
	}

	tbb::concurrent_vector< std::pair< std::string, IECore::MurmurHash > > m_hashes;
};

} // namespace

void UDIMQuery::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	ComputeNode::hash( output, context, h );
	if( output == outPlug() )
	{
		uvSetPlug()->hash( h );
		attributesPlug()->hash( h );

		InfoHashAccumulator f;
		GafferScene::SceneAlgo::filteredParallelTraverse( inPlug(), filterPlug(), f );
		f.appendHash( h );
	}
}

namespace {

struct BakeInfoData
{
	std::string mesh;
	boost::container::flat_set<int> udims;
	CompoundObjectPtr attributes;
};

struct InfoDataAccumulator
{
	InfoDataAccumulator( std::string uvSet, std::string attributeNames )
		: m_uvSet( uvSet ), m_attributeNames( attributeNames )
	{
	}

	bool operator()( const GafferScene::ScenePlug *in, const GafferScene::ScenePlug::ScenePath &path )
	{
		IECore::CompoundObjectPtr locationDict;

		IECore::ConstObjectPtr object = in->objectPlug()->getValue();
		const IECoreScene::MeshPrimitive *meshPrimitive = runTimeCast<const IECoreScene::MeshPrimitive>( object.get() );
		if( !meshPrimitive )
		{
			return true;
		}

		// First check if there are face-varying UVs
		bool faceVarying = true;
		auto uvs = meshPrimitive->variableIndexedView<IECore::V2fVectorData>( m_uvSet,  IECoreScene::PrimitiveVariable::FaceVarying );
		if( !uvs )
		{
			// Next check for vertex UVs
			faceVarying = false;
			uvs = meshPrimitive->variableIndexedView<IECore::V2fVectorData>( m_uvSet,  IECoreScene::PrimitiveVariable::Vertex );
		}

		if( !uvs )
		{
			// No face-varying or vertex UVs
			return true;
		}

		std::string pathString;
		ScenePlug::pathToString( path, pathString );
		unsigned int targetSize = meshPrimitive->variableSize( faceVarying ? IECoreScene::PrimitiveVariable::FaceVarying : IECoreScene::PrimitiveVariable::Vertex );
		if( uvs->size() != targetSize )
		{
			throw IECore::Exception(
				boost::str(
					boost::format(
						"Cannot query UDIMs.  Bad uvs at location %s.  Required count %i but found %i."
					) % pathString % targetSize % uvs->size()
				)
			);
		}

		const IntVectorData *vertsPerFaceData = meshPrimitive->verticesPerFace();
		const std::vector<int> &vertsPerFace = vertsPerFaceData->readable();

		BakeInfoData &info = *m_data.grow_by( 1 );
		info.mesh = pathString;

		// We check the center UVs of each face, because the edge uvs could lie directly on a UDIM boundary,
		// and without checking adjacency information, it would be impossible to tell which UDIM the edge
		// belongs to.  Checking face centers is fairly simple, and is completely accurate except in extreme
		// cases of polygons spanning multiple UDIMs, which is not done according to UDIM conventions.
		int faceVertId = 0;
		for( int numVerts : vertsPerFace )
		{
			Imath::V2f accum = Imath::V2f(0);
			if( faceVarying )
			{
				for( int i = 0; i < numVerts; i++ )
				{
					accum += (*uvs)[faceVertId];
					faceVertId++;
				}
			}
			else
			{
				for( int i = 0; i < numVerts; i++ )
				{
					accum += (*uvs)[ meshPrimitive->vertexIds()->readable()[faceVertId] ];
					faceVertId++;
				}
			}
			Imath::V2f centerUV = accum / numVerts;
			int udim = 1001 + int( floor( centerUV[0] ) ) + 10 * int( floor( centerUV[1] ) );

			info.udims.insert( udim );
		}

		info.attributes = new CompoundObject();
		if( m_attributeNames.size() )
		{
			IECore::ConstCompoundObjectPtr inAttributes = in->fullAttributes( path );
			for( const auto &i : inAttributes->members() )
			{
				if( StringAlgo::matchMultiple( i.first, m_attributeNames ) )
				{
					info.attributes->members()[ i.first ] = i.second;
				}
			}
		}

		return true;
	}

	std::string m_uvSet;
	IECore::StringAlgo::MatchPattern m_attributeNames;
	tbb::concurrent_vector< BakeInfoData > m_data;
};

} // namespace

void UDIMQuery::compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const
{
	if( output == outPlug() )
	{
		InfoDataAccumulator f( uvSetPlug()->getValue(), attributesPlug()->getValue() );
		GafferScene::SceneAlgo::filteredParallelTraverse( inPlug(), filterPlug(), f );

		IECore::CompoundObjectPtr result = new IECore::CompoundObject();

		for( const auto &i : f.m_data )
		{
			for( int udim : i.udims )
			{
				std::string udimStr = std::to_string( udim );

				CompoundObjectPtr udimEntry = result->member<CompoundObject>(
					udimStr, /* throwExceptions = */ false, /* createIfMissing = */ true
				);

				// Result treated as const anyway, so this is safe.
				udimEntry->members()[i.mesh] = const_cast<CompoundObject*>( i.attributes.get() );
			}
		}
		static_cast<CompoundObjectPlug *>( output )->setValue( result );
	}
	else
	{
		ComputeNode::compute( output, context );
	}
}
<|endoftext|>


<commit_before>#include "Genes/Look_Ahead_Gene.h"

#include <cmath>
#include <cassert>
#include <memory>

#include "Genes/Gene.h"
#include "Utility.h"
#include "Game/Board.h"
#include "Game/Clock.h"
#include "Moves/Move.h"

Look_Ahead_Gene::Look_Ahead_Gene() :
    mean_game_length(50),
    game_length_uncertainty(0.5),
    speculation_constant(0.5),
    capturing_speculation_constant(0.5)
{
    recalculate_exponent();
}

void Look_Ahead_Gene::reset_properties() const
{
    properties["Mean Game Length"] = mean_game_length;
    properties["Game Length Uncertainty"] = game_length_uncertainty;
    properties["Speculation Constant"] = speculation_constant;
    properties["Capturing Speculation Constant"] = capturing_speculation_constant;
}

void Look_Ahead_Gene::load_properties()
{
    mean_game_length = properties["Mean Game Length"];
    game_length_uncertainty = properties["Game Length Uncertainty"];
    speculation_constant = properties["Speculation Constant"];
    capturing_speculation_constant = properties["Capturing Speculation Constant"];
    recalculate_exponent();
}

double Look_Ahead_Gene::time_to_examine(const Board& board, const Clock& clock) const
{
    auto time_left = clock.time_left(board.whose_turn());
    auto moves_to_reset = clock.moves_to_reset(board.whose_turn());

    auto moves_so_far = board.get_game_record().size()/2; // only count moves by this player
    auto moves_left = Math::average_moves_left(mean_game_length, game_length_uncertainty, moves_so_far);

    return time_left/std::min(moves_left, double(moves_to_reset));
}

void Look_Ahead_Gene::gene_specific_mutation()
{
    switch(Random::random_integer(1, 4))
    {
        case 1:
            mean_game_length = std::max(1.0, mean_game_length + Random::random_normal(1.0));
            break;
        case 2:
            game_length_uncertainty = std::abs(game_length_uncertainty + Random::random_normal(0.05));
            break;
        case 3:
            speculation_constant += Random::random_normal(0.05);
            speculation_constant = Math::clamp(speculation_constant, 0.0, 1.0);
            recalculate_exponent();
            break;
        case 4:
            capturing_speculation_constant += Random::random_normal(0.05);
            capturing_speculation_constant = Math::clamp(capturing_speculation_constant, 0.0, 1.0);
            recalculate_exponent();
            break;
        default:
            assert(false); // If here, random_integer() called with wrong parameters
            break;
    }
}

std::unique_ptr<Gene> Look_Ahead_Gene::duplicate() const
{
    return std::make_unique<Look_Ahead_Gene>(*this);
}

std::string Look_Ahead_Gene::name() const
{
    return "Look Ahead Gene";
}

double Look_Ahead_Gene::score_board(const Board&) const
{
    return 0.0;
}

bool Look_Ahead_Gene::enough_time_to_recurse(double time_allotted, const Board& board, double positions_per_second) const
{
    // The idea is that, if the time allotted to a move is less than the time
    // this gene thinks it takes to examine every move of the resulting board state
    // without recursion, then it should still recurse with a probability that is a
    // function of the ratio of the time allotted to time needed. The speculation_constant
    // specifies how often this should happen, with 0 being never and 1 being always
    // (see the recalculate_exponent() function for the math).

    auto minimum_time_to_recurse = board.legal_moves().size()/positions_per_second;
    auto base = time_allotted/minimum_time_to_recurse;

    if(base <= 0.0)
    {
        return false;
    }

    if(base >= 1.0)
    {
        return true;
    }

    auto exponent = (board.capture_possible() ? capturing_speculation_exponent : speculation_exponent);
    return Random::success_probability(std::pow(base, exponent));
}

void Look_Ahead_Gene::recalculate_exponent()
{
    if(speculation_constant > 0.0)
    {
        speculation_exponent = (1.0 - speculation_constant)/speculation_constant;
    }
    else
    {
        speculation_exponent = Math::infinity;
    }

    if(capturing_speculation_constant > 0.0)
    {
        capturing_speculation_exponent = (1.0 - capturing_speculation_constant)/capturing_speculation_constant;
    }
    else
    {
        capturing_speculation_exponent = Math::infinity;
    }

    // constant = 0.0 ==> exponent = infinity
    // constant = 0.5 ==> exponent = 1
    // constant = 1.0 ==> exponent = 0
    //
    // Additionally, the function is symmetric about constant = 0.5:
    //    constant --> 1 - constant ==> exponent --> 1/exponent
    //
    // This results in a value of the std::pow() expression in enough_time_to_recurse()
    //
    //    value = (0 < base < 1)^exponent
    //
    // Large exponents result in values near zero, which means recursion with little time
    // has little probability. Small exponents result in values near 1, so recursion with
    // little time is more likely.
}
<commit_msg>Prevent infinite recursion in untimed games<commit_after>#include "Genes/Look_Ahead_Gene.h"

#include <cmath>
#include <cassert>
#include <memory>

#include "Genes/Gene.h"
#include "Utility.h"
#include "Game/Board.h"
#include "Game/Clock.h"
#include "Moves/Move.h"

Look_Ahead_Gene::Look_Ahead_Gene() :
    mean_game_length(50),
    game_length_uncertainty(0.5),
    speculation_constant(0.5),
    capturing_speculation_constant(0.5)
{
    recalculate_exponent();
}

void Look_Ahead_Gene::reset_properties() const
{
    properties["Mean Game Length"] = mean_game_length;
    properties["Game Length Uncertainty"] = game_length_uncertainty;
    properties["Speculation Constant"] = speculation_constant;
    properties["Capturing Speculation Constant"] = capturing_speculation_constant;
}

void Look_Ahead_Gene::load_properties()
{
    mean_game_length = properties["Mean Game Length"];
    game_length_uncertainty = properties["Game Length Uncertainty"];
    speculation_constant = properties["Speculation Constant"];
    capturing_speculation_constant = properties["Capturing Speculation Constant"];
    recalculate_exponent();
}

double Look_Ahead_Gene::time_to_examine(const Board& board, const Clock& clock) const
{
    auto time_left = clock.time_left(board.whose_turn());
    auto moves_to_reset = clock.moves_to_reset(board.whose_turn());

    auto moves_so_far = board.get_game_record().size()/2; // only count moves by this player
    auto moves_left = Math::average_moves_left(mean_game_length, game_length_uncertainty, moves_so_far);

    return time_left/std::min(moves_left, double(moves_to_reset));
}

void Look_Ahead_Gene::gene_specific_mutation()
{
    switch(Random::random_integer(1, 4))
    {
        case 1:
            mean_game_length = std::max(1.0, mean_game_length + Random::random_normal(1.0));
            break;
        case 2:
            game_length_uncertainty = std::abs(game_length_uncertainty + Random::random_normal(0.05));
            break;
        case 3:
            speculation_constant += Random::random_normal(0.05);
            speculation_constant = Math::clamp(speculation_constant, 0.0, 1.0);
            recalculate_exponent();
            break;
        case 4:
            capturing_speculation_constant += Random::random_normal(0.05);
            capturing_speculation_constant = Math::clamp(capturing_speculation_constant, 0.0, 1.0);
            recalculate_exponent();
            break;
        default:
            assert(false); // If here, random_integer() called with wrong parameters
            break;
    }
}

std::unique_ptr<Gene> Look_Ahead_Gene::duplicate() const
{
    return std::make_unique<Look_Ahead_Gene>(*this);
}

std::string Look_Ahead_Gene::name() const
{
    return "Look Ahead Gene";
}

double Look_Ahead_Gene::score_board(const Board&) const
{
    return 0.0;
}

bool Look_Ahead_Gene::enough_time_to_recurse(double time_allotted, const Board& board, double positions_per_second) const
{
    // The idea is that, if the time allotted to a move is less than the time
    // this gene thinks it takes to examine every move of the resulting board state
    // without recursion, then it should still recurse with a probability that is a
    // function of the ratio of the time allotted to time needed. The speculation_constant
    // specifies how often this should happen, with 0 being never and 1 being always
    // (see the recalculate_exponent() function for the math).

    if(time_allotted <= 0)
    {
        return false;
    }

    auto minimum_time_to_recurse = board.legal_moves().size()/positions_per_second;
    auto base = time_allotted/minimum_time_to_recurse;

    if(base >= 1.0)
    {
        return true;
    }

    auto exponent = (board.capture_possible() ? capturing_speculation_exponent : speculation_exponent);
    return Random::success_probability(std::pow(base, exponent));
}

void Look_Ahead_Gene::recalculate_exponent()
{
    if(speculation_constant > 0.0)
    {
        speculation_exponent = (1.0 - speculation_constant)/speculation_constant;
    }
    else
    {
        speculation_exponent = Math::infinity;
    }

    if(capturing_speculation_constant > 0.0)
    {
        capturing_speculation_exponent = (1.0 - capturing_speculation_constant)/capturing_speculation_constant;
    }
    else
    {
        capturing_speculation_exponent = Math::infinity;
    }

    // constant = 0.0 ==> exponent = infinity
    // constant = 0.5 ==> exponent = 1
    // constant = 1.0 ==> exponent = 0
    //
    // Additionally, the function is symmetric about constant = 0.5:
    //    constant --> 1 - constant ==> exponent --> 1/exponent
    //
    // This results in a value of the std::pow() expression in enough_time_to_recurse()
    //
    //    value = (0 < base < 1)^exponent
    //
    // Large exponents result in values near zero, which means recursion with little time
    // has little probability. Small exponents result in values near 1, so recursion with
    // little time is more likely.
}
<|endoftext|>