<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
*                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This library 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.                                             *
*                                                                             *
* This library 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 this library; if not, write to the Free Software Foundation,     *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/

#include <sofa/component/topology/MultilevelHexahedronSetTopologyContainer.h>
#include <sofa/core/ObjectFactory.h>

#include <sofa/component/container/VoxelGridLoader.h>

#include <sofa/component/topology/HexahedronData.h>
#include <sofa/component/topology/HexahedronData.inl>

#include <set>

namespace sofa
{
namespace component
{
namespace topology
{
using namespace std;
using namespace sofa::defaulttype;

SOFA_DECL_CLASS(MultilevelHexahedronSetTopologyContainer)
int MultilevelHexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container")
        .add< MultilevelHexahedronSetTopologyContainer >()
        ;

MultilevelHexahedronSetTopologyContainer::MultilevelHexahedronSetTopologyContainer()
    : HexahedronSetTopologyContainer(),
      _level(initData(&_level, 0, "level", "Number of resolution levels between the fine and coarse mesh")),
      _fineResolution(0,0,0),
      _coarseResolution(0,0,0)
{ }


MultilevelHexahedronSetTopologyContainer::~MultilevelHexahedronSetTopologyContainer()
{
    clear();
}

void MultilevelHexahedronSetTopologyContainer::init()
{
    HexahedronSetTopologyContainer::init();
}

void MultilevelHexahedronSetTopologyContainer::loadFromMeshLoader(sofa::component::container::MeshLoader* loader)
{
    sofa::component::container::VoxelGridLoader* rgLoader = dynamic_cast<sofa::component::container::VoxelGridLoader*> (loader);

    if(rgLoader)
    {
        // load points
        PointSetTopologyContainer::loadFromMeshLoader(loader);
        helper::ReadAccessor< Data< sofa::helper::vector<Hexahedron> > > m_hexahedron = d_hexahedron;
        rgLoader->getHexahedra(*(d_hexahedron.beginEdit()));
        d_hexahedron.endEdit();

        helper::vector<unsigned int> hexaIndexInRegularGrid;
        rgLoader->getIndicesInRegularGrid(hexaIndexInRegularGrid);

        rgLoader->getResolution(_fineResolution);

        _fineComponentInRegularGrid.resize(_fineResolution[0] * _fineResolution[1] * _fineResolution[2], NULL);

        const unsigned int numVoxels = m_hexahedron.size();

        // initialize the components
        // at the beginning the components of both levels are the same
        _coarseResolution = _fineResolution;

        _fineComponents.beginEdit()->reserve(numVoxels);
        _fineComponents.endEdit();
        _coarseComponents.beginEdit()->reserve(numVoxels);
        _coarseComponents.endEdit();
        for(unsigned int idx=0; idx<numVoxels; ++idx)
        {
            //	id = k * nx * ny + j * nx + i;
            const unsigned int id = hexaIndexInRegularGrid[idx];
            const unsigned int i = id % _fineResolution[0];
            const unsigned int j = (id / _fineResolution[0]) % _fineResolution[1];
            const unsigned int k = id / (_fineResolution[0] * _fineResolution[1]);

            Vec3i pos(i,j,k);
            std::set<Vec3i> voxels;
            voxels.insert(pos);

            MultilevelHexahedronSetTopologyContainer::Component *comp = new MultilevelHexahedronSetTopologyContainer::Component(pos, voxels);
            _fineComponents.beginEdit()->push_back(comp);
            _fineComponents.endEdit();
            _coarseComponents.beginEdit()->push_back(comp);
            _coarseComponents.endEdit();

            _fineComponentInRegularGrid[id] = comp;
        }
    }
}

void MultilevelHexahedronSetTopologyContainer::clear()<commit_msg>r7603/sofa-dev : FIX : some warnings due to the 39390 bug of gcc-4.4<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
*                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* This library 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.                                             *
*                                                                             *
* This library 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 this library; if not, write to the Free Software Foundation,     *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/

#include <sofa/component/topology/MultilevelHexahedronSetTopologyContainer.h>
#include <sofa/core/ObjectFactory.h>

#include <sofa/component/container/VoxelGridLoader.h>

#include <sofa/component/topology/HexahedronData.h>
#include <sofa/component/topology/HexahedronData.inl>

#include <set>

namespace sofa
{
namespace component
{
namespace topology
{
using namespace std;
using namespace sofa::defaulttype;

SOFA_DECL_CLASS(MultilevelHexahedronSetTopologyContainer)
int MultilevelHexahedronSetTopologyContainerClass = core::RegisterObject("Hexahedron set topology container")
        .add< MultilevelHexahedronSetTopologyContainer >()
        ;

MultilevelHexahedronSetTopologyContainer::MultilevelHexahedronSetTopologyContainer()
    : HexahedronSetTopologyContainer(),
      _level(initData(&_level, 0, "level", "Number of resolution levels between the fine and coarse mesh")),
      _fineResolution(0,0,0),
      _coarseResolution(0,0,0)
{ }


MultilevelHexahedronSetTopologyContainer::~MultilevelHexahedronSetTopologyContainer()
{
    clear();
}

void MultilevelHexahedronSetTopologyContainer::init()
{
    HexahedronSetTopologyContainer::init();
}

void MultilevelHexahedronSetTopologyContainer::loadFromMeshLoader(sofa::component::container::MeshLoader* loader)
{
    sofa::component::container::VoxelGridLoader* rgLoader = dynamic_cast<sofa::component::container::VoxelGridLoader*> (loader);

    if(rgLoader)
    {
        // load points
        PointSetTopologyContainer::loadFromMeshLoader(loader);
        helper::ReadAccessor< Data< sofa::helper::vector<Hexahedron> > > m_hexahedron = d_hexahedron;
        rgLoader->getHexahedra(*(d_hexahedron.beginEdit()));
        d_hexahedron.endEdit();

        helper::vector<unsigned int> hexaIndexInRegularGrid;
        rgLoader->getIndicesInRegularGrid(hexaIndexInRegularGrid);

        rgLoader->getResolution(_fineResolution);

        _fineComponentInRegularGrid.resize(_fineResolution[0] * _fineResolution[1] * _fineResolution[2], NULL);

        const unsigned int numVoxels = m_hexahedron.size();

        // initialize the components
        // at the beginning the components of both levels are the same
        _coarseResolution = _fineResolution;

        _fineComponents.beginEdit()->reserve(numVoxels);
        _fineComponents.endEdit();
        _coarseComponents.beginEdit()->reserve(numVoxels);
        _coarseComponents.endEdit();
        for(unsigned int idx=0; idx<numVoxels; ++idx)
        {
            //	id = k * nx * ny + j * nx + i;
            const unsigned int id = hexaIndexInRegularGrid[idx];
            const unsigned int i = id % _fineResolution[0];
            const unsigned int j = (id / _fineResolution[0]) % _fineResolution[1];
            const unsigned int k = id / (_fineResolution[0] * _fineResolution[1]);

            Vec3i pos(i,j,k);
            std::set<Vec3i> voxels;
            voxels.insert(&pos, 1+&pos); // Using this insert method avoid the 39390 bug of gcc-4.4

            MultilevelHexahedronSetTopologyContainer::Component *comp = new MultilevelHexahedronSetTopologyContainer::Component(pos, voxels);
            _fineComponents.beginEdit()->push_back(comp);
            _fineComponents.endEdit();
            _coarseComponents.beginEdit()->push_back(comp);
            _coarseComponents.endEdit();

            _fineComponentInRegularGrid[id] = comp;
        }
    }
}

void MultilevelHexahedronSetTopologyContainer::clear()
{'fraction_non_alphanumeric': 0.12738972302527277, 'fraction_numerical': 0.009605520843047655, 'mean_word_length': 2.4582392776523703, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3405532', 'n_tokens_mistral': 2865, 'n_tokens_neox': 2629, 'n_words': 636}