<commit_before>// 30 Oct 2002
// AC3D loader for models generated by the AC3D modeller (www.ac3d.org)
// part of this source code were supplied by the AC3D project (<NAME>)
// eg the basic parsing of an AC3D file.
// Conversion from AC3D scenegraph to OSG by <NAME>.

#include <vector>
#include <iostream>

#include <osg/GL>
#include <osg/GLU>

#include <osg/Math>
#include <osg/BlendFunc>
#include <osg/CullFace>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Geometry>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Material>
#include <osg/Math>
#include <osg/Texture2D>
#include <osg/TexEnv>
#include <osg/StateSet>
#include <osg/ShadeModel>
#include <osg/Math>
#include <osg/Notify>

#include <osgUtil/Tessellator>

#include <osgDB/FileNameUtils>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>

#include "Exception.h"
#include "Geode.h"

namespace ac3d {

osg::Node*
readFile(std::istream& stream, const osgDB::ReaderWriter::Options* options);

}

class geodeVisitor : public osg::NodeVisitor { // collects geodes from scene sub-graph attached to 'this'
        public:
            geodeVisitor():
                osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}

            ~geodeVisitor() { _geodelist.clear();}

            // one apply for each type of Node that might be a user transform
            virtual void apply(osg::Geode& geode) {
                _geodelist.push_back(&geode);
            }
            virtual void apply(osg::Group& gp){
                traverse(gp);    // must continue subgraph traversal.
            }
            std::vector<const osg::Geode *> getGeodes() {return _geodelist;}
        protected:

            typedef std::vector<const osg::Geode *>    Geodelist;
            Geodelist  _geodelist;
};

class ReaderWriterAC : public osgDB::ReaderWriter
{
    public:
        virtual const char* className() const { return "AC3D Database Reader"; }

        virtual bool acceptsExtension(const std::string& extension) const
        {
            return osgDB::equalCaseInsensitive(extension,"ac");
        }
        virtual ReadResult readNode(const std::string& file,const Options* options) const
        {
            std::string ext = osgDB::getFileExtension(file);
            if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

            // GWM added Dec 2003 - get full path name (change in osgDB handling of files).
            std::string fileName = osgDB::findDataFile( file, options );
            osg::notify(osg::INFO) << "osgDB ac3d reader: starting reading \"" << fileName << "\"" << std::endl;
            
            // <NAME> - correct return if path not found
            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;

            // allocate per file data and start reading
            std::ifstream fin;
            fin.open(fileName.c_str(), std::ios::in);
            if (!fin.is_open()) return ReadResult::FILE_NOT_FOUND;

            // code for setting up the database path so that internally referenced file are
            // searched for on relative paths. 
            osg::ref_ptr<Options> local_opt;
            if (options)
                local_opt = static_cast<Options*>(options->clone(osg::CopyOp::DEEP_COPY_ALL));
            else
                local_opt = new Options;
            local_opt->setDatabasePath(osgDB::getFilePath(fileName));

            ReadResult result = readNode(fin, local_opt.get());
            if (result.validNode())
                result.getNode()->setName(fileName);
            return result;
        }
        virtual ReadResult readNode(std::istream& fin, const Options* options) const
        {
            std::string header;
            fin >> header;
            if (header.substr(0, 4) != "AC3D")
                return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;

            return ac3d::readFile(fin, options);
        }
        virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName, const Options* /*options*/) const
        {
            std::string ext = osgDB::getFileExtension(fileName);
            if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
            geodeVisitor vs; // this collects geodes.
            std::vector<unsigned int>iNumMaterials;
            const_cast<osg::Node&>(node).accept(vs); // this parses the tree to streamd Geodes
            std::vector<const osg::Geode *> glist=vs.getGeodes();
            std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
            // Write out the file header
            std::vector<const osg::Geode *>::iterator itr;<commit_msg>From <NAME>, "I noticed the AC3D loader resets database path given as Options, preventing users to put textures in another directory. This patch adds the model path to the path list instead of replacing it."<commit_after>// 30 Oct 2002
// AC3D loader for models generated by the AC3D modeller (www.ac3d.org)
// part of this source code were supplied by the AC3D project (Andy Colebourne)
// eg the basic parsing of an AC3D file.
// Conversion from AC3D scenegraph to OSG by GW Michel.

#include <vector>
#include <iostream>

#include <osg/GL>
#include <osg/GLU>

#include <osg/Math>
#include <osg/BlendFunc>
#include <osg/CullFace>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Geometry>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Material>
#include <osg/Math>
#include <osg/Texture2D>
#include <osg/TexEnv>
#include <osg/StateSet>
#include <osg/ShadeModel>
#include <osg/Math>
#include <osg/Notify>

#include <osgUtil/Tessellator>

#include <osgDB/FileNameUtils>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>

#include "Exception.h"
#include "Geode.h"

namespace ac3d {

osg::Node*
readFile(std::istream& stream, const osgDB::ReaderWriter::Options* options);

}

class geodeVisitor : public osg::NodeVisitor { // collects geodes from scene sub-graph attached to 'this'
        public:
            geodeVisitor():
                osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}

            ~geodeVisitor() { _geodelist.clear();}

            // one apply for each type of Node that might be a user transform
            virtual void apply(osg::Geode& geode) {
                _geodelist.push_back(&geode);
            }
            virtual void apply(osg::Group& gp){
                traverse(gp);    // must continue subgraph traversal.
            }
            std::vector<const osg::Geode *> getGeodes() {return _geodelist;}
        protected:

            typedef std::vector<const osg::Geode *>    Geodelist;
            Geodelist  _geodelist;
};

class ReaderWriterAC : public osgDB::ReaderWriter
{
    public:
        virtual const char* className() const { return "AC3D Database Reader"; }

        virtual bool acceptsExtension(const std::string& extension) const
        {
            return osgDB::equalCaseInsensitive(extension,"ac");
        }
        virtual ReadResult readNode(const std::string& file,const Options* options) const
        {
            std::string ext = osgDB::getFileExtension(file);
            if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;

            // GWM added Dec 2003 - get full path name (change in osgDB handling of files).
            std::string fileName = osgDB::findDataFile( file, options );
            osg::notify(osg::INFO) << "osgDB ac3d reader: starting reading \"" << fileName << "\"" << std::endl;
            
            // <NAME> - correct return if path not found
            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;

            // allocate per file data and start reading
            std::ifstream fin;
            fin.open(fileName.c_str(), std::ios::in);
            if (!fin.is_open()) return ReadResult::FILE_NOT_FOUND;

            // code for setting up the database path so that internally referenced file are
            // searched for on relative paths. 
            osg::ref_ptr<Options> local_opt;
            if (options)
                local_opt = static_cast<Options*>(options->clone(osg::CopyOp::DEEP_COPY_ALL));
            else
                local_opt = new Options;
            local_opt->getDatabasePathList().push_back(osgDB::getFilePath(fileName));

            ReadResult result = readNode(fin, local_opt.get());
            if (result.validNode())
                result.getNode()->setName(fileName);
            return result;
        }
        virtual ReadResult readNode(std::istream& fin, const Options* options) const
        {
            std::string header;
            fin >> header;
            if (header.substr(0, 4) != "AC3D")
                return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;

            return ac3d::readFile(fin, options);
        }
        virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName, const Options* /*options*/) const
        {
            std::string ext = osgDB::getFileExtension(fileName);
            if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
            geodeVisitor vs; // this collects geodes.
            std::vector<unsigned int>iNumMaterials;
            const_cast<osg::Node&>(node).accept(vs); // this parses the tree to streamd Geodes
            std::vector<const osg::Geode *> glist=vs.getGeodes();
            std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
            // Write out the file header
            std::vector<const osg::Geode *>::iterator itr;
{'fraction_non_alphanumeric': 0.11722338204592903, 'fraction_numerical': 0.00511482254697286, 'mean_word_length': 2.631918119787718, 'pattern_counts': {'":': 0, '<': 90, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5870389', 'n_tokens_mistral': 2881, 'n_tokens_neox': 2806, 'n_words': 751}