<commit_before>#pragma once
#include "../common.hpp"
#include "copy_reference.hpp"
#include "type_exist.hpp"
namespace bbzy {
namespace type {
namespace detail {
template <class T, template <class...> class TemplateClassT>
struct IsTemplateOf
{
private:
	template <class HelperT>
	static void help(HelperT);

	template <template <class...> class HelperT, class... TemplateParamTs,
		class = EnableIf<std::is_same<HelperT<TemplateParamTs...>, TemplateClassT<TemplateParamTs...>>::value>>
	static int help(HelperT<TemplateParamTs...>);
public:
	enum
	{
		value = std::is_same<decltype(help(std::declval<Decay<T>>())), int>::value
	};
};

template <class T1, class T2>
struct AreSameTemplate
{
private:
	template <template <class...> class TemplateT,
		class... TemplateParams1,
		class... TemplateParams2>
	static int16_t help(TemplateT<TemplateParams1...>, TemplateT<TemplateParams2...>);

	template <class HelperT1, class HelperT2>
	static int8_t help(HelperT1, HelperT2);

public:
	enum
	{
		value = sizeof(decltype(help(std::declval<Decay<T1>>(), std::declval<Decay<T2>>()))) - 1
	};
};

template <class T, template <class...> class... TemplateTs>
struct IsAnyOfTemplates
{
private:
	template <class HelperT, template <class...> class... HelperTemplateTs>
	struct Helper;

	template <class HelperT,
		template <class...> class HelperTemplateT,
		template <class...> class... LeftTemplateTs>
	struct Helper<HelperT, HelperTemplateT, LeftTemplateTs...>
	{
		typedef Conditional<IsTemplateOf<HelperT, HelperTemplateT>::value,
			int, typename Helper<HelperT, LeftTemplateTs...>::type> type;
	};

	template <class HelperT>
	struct Helper<HelperT>
	{
		typedef void type;
	};

public:
	enum
	{
		value = std::is_same<typename Helper<T, TemplateTs...>::type, int>::value
	};
};

template <class T, template <class...> class NewTemplateT>
struct ChangeTemplate
{
private:
	template <class HelperT, template <class...> class HelperNewTemplateT>
	struct Helper;

	template <
		template <class...> class OriginalTemplateT,
		template <class...> class TargetTemplateT,
		class... TemplateParamTs>
	struct Helper<OriginalTemplateT<TemplateParamTs...>, TargetTemplateT>
	{
		using type = TargetTemplateT<TemplateParamTs...>;
	};

public:
	using type = CopyProp<typename Helper<Decay<T>, NewTemplateT>::type, T>;
};

template <class T, class... NewElementTs>
struct ChangeElementTypes
{
private:
	template <class HelperT>
	struct Helper;

	template <template <class...> class HelperT, class... TemplateParamTs>
	struct Helper<HelperT<TemplateParamTs...>>
	{
		using type = HelperT<NewElementTs...>;
	};

public:
	using type = CpProp<typename Helper<Decay<T>>::type, T>;
};

}

using detail::IsTemplateOf;

template <class T, template <class...> class TemplateClassT>
using TempOf = IsTemplateOf<T, TemplateClassT>;

using detail::AreSameTemplate;

template <class T1, class T2>
using SameTemp = AreSameTemplate<T1, T2>;

template <class T, template <class...> class... TemplateTs>
using IsAnyOfTemplates = detail::IsAnyOfTemplates<T, TemplateTs...>;

template <class T, template <class...> class... TemplateTs>
using AnyOfTs = IsAnyOfTemplates<T, TemplateTs...>;

template <class T, template <class...> class... TemplateTs>
using EnableTemplateOf = EnableIf<AnyOfTs<T, TemplateTs...>::value>;

template <class T, template <class...> class... TemplateTs>
using EnableTempOf = EnableTemplateOf<T, TemplateTs...>;

template <class T, template <class...> class NewTemplateT>
using ChangeTemplate = typename detail::ChangeTemplate<T, NewTemplateT>::type;

template <class T, template <class...> class NewTemplateT>
using ChTemp = ChangeTemplate<T, NewTemplateT>;

template <class T, class... NewElementTs>
using ChangeElementTypes = typename detail::ChangeElementTypes<T, NewElementTs...>::type;

template <class T, class... NewElementTs>
using ChElemTs = ChangeElementTypes<T, NewElementTs...>;

}
}
<commit_msg>Add uint8_t support<commit_after>#pragma once
#include <stdint.h>
#include "../common.hpp"
#include "copy_reference.hpp"
#include "type_exist.hpp"
namespace bbzy {
namespace type {
namespace detail {
template <class T, template <class...> class TemplateClassT>
struct IsTemplateOf
{
private:
	template <class HelperT>
	static void help(HelperT);

	template <template <class...> class HelperT, class... TemplateParamTs,
		class = EnableIf<std::is_same<HelperT<TemplateParamTs...>, TemplateClassT<TemplateParamTs...>>::value>>
	static int help(HelperT<TemplateParamTs...>);
public:
	enum
	{
		value = std::is_same<decltype(help(std::declval<Decay<T>>())), int>::value
	};
};

template <class T1, class T2>
struct AreSameTemplate
{
private:
	template <template <class...> class TemplateT,
		class... TemplateParams1,
		class... TemplateParams2>
	static int16_t help(TemplateT<TemplateParams1...>, TemplateT<TemplateParams2...>);

	template <class HelperT1, class HelperT2>
	static int8_t help(HelperT1, HelperT2);

public:
	enum
	{
		value = sizeof(decltype(help(std::declval<Decay<T1>>(), std::declval<Decay<T2>>()))) - 1
	};
};

template <class T, template <class...> class... TemplateTs>
struct IsAnyOfTemplates
{
private:
	template <class HelperT, template <class...> class... HelperTemplateTs>
	struct Helper;

	template <class HelperT,
		template <class...> class HelperTemplateT,
		template <class...> class... LeftTemplateTs>
	struct Helper<HelperT, HelperTemplateT, LeftTemplateTs...>
	{
		typedef Conditional<IsTemplateOf<HelperT, HelperTemplateT>::value,
			int, typename Helper<HelperT, LeftTemplateTs...>::type> type;
	};

	template <class HelperT>
	struct Helper<HelperT>
	{
		typedef void type;
	};

public:
	enum
	{
		value = std::is_same<typename Helper<T, TemplateTs...>::type, int>::value
	};
};

template <class T, template <class...> class NewTemplateT>
struct ChangeTemplate
{
private:
	template <class HelperT, template <class...> class HelperNewTemplateT>
	struct Helper;

	template <
		template <class...> class OriginalTemplateT,
		template <class...> class TargetTemplateT,
		class... TemplateParamTs>
	struct Helper<OriginalTemplateT<TemplateParamTs...>, TargetTemplateT>
	{
		using type = TargetTemplateT<TemplateParamTs...>;
	};

public:
	using type = CopyProp<typename Helper<Decay<T>, NewTemplateT>::type, T>;
};

template <class T, class... NewElementTs>
struct ChangeElementTypes
{
private:
	template <class HelperT>
	struct Helper;

	template <template <class...> class HelperT, class... TemplateParamTs>
	struct Helper<HelperT<TemplateParamTs...>>
	{
		using type = HelperT<NewElementTs...>;
	};

public:
	using type = CpProp<typename Helper<Decay<T>>::type, T>;
};

}

using detail::IsTemplateOf;

template <class T, template <class...> class TemplateClassT>
using TempOf = IsTemplateOf<T, TemplateClassT>;

using detail::AreSameTemplate;

template <class T1, class T2>
using SameTemp = AreSameTemplate<T1, T2>;

template <class T, template <class...> class... TemplateTs>
using IsAnyOfTemplates = detail::IsAnyOfTemplates<T, TemplateTs...>;

template <class T, template <class...> class... TemplateTs>
using AnyOfTs = IsAnyOfTemplates<T, TemplateTs...>;

template <class T, template <class...> class... TemplateTs>
using EnableTemplateOf = EnableIf<AnyOfTs<T, TemplateTs...>::value>;

template <class T, template <class...> class... TemplateTs>
using EnableTempOf = EnableTemplateOf<T, TemplateTs...>;

template <class T, template <class...> class NewTemplateT>
using ChangeTemplate = typename detail::ChangeTemplate<T, NewTemplateT>::type;

template <class T, template <class...> class NewTemplateT>
using ChTemp = ChangeTemplate<T, NewTemplateT>;

template <class T, class... NewElementTs>
using ChangeElementTypes = typename detail::ChangeElementTypes<T, NewElementTs...>::type;

template <class T, class... NewElementTs>
using ChElemTs = ChangeElementTypes<T, NewElementTs...>;

}
}
<|endoftext|>


<commit_before>/*********************************************************************************
* Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    David D. Marshall - initial code and implementation
********************************************************************************/

#ifndef eli_geom_general_bounding_box_hpp
#define eli_geom_general_bounding_box_hpp

#include "eli/code_eli.hpp"

#include "eli/util/tolerance.hpp"

namespace eli
{
  namespace geom
  {
    namespace general
    {
      template<typename data__, unsigned short dim__, typename tol__=eli::util::tolerance<data__> >
      class bounding_box
      {
        public:
          typedef data__ data_type;
          typedef unsigned short dimension_type;
          typedef Eigen::Matrix<data_type, 1, dim__> point_type;
          typedef typename point_type::Index index_type;
          typedef tol__ tolerance_type;

        public:
          bounding_box() : empty(true) {}
          bounding_box(const point_type &p) : empty(false), pmin(p), pmax(p) {}
          bounding_box(const bounding_box<data_type, dim__> &bb) : empty(bb.empty), pmin(bb.pmin), pmax(bb.pmax) {}
          ~bounding_box() {}

          bounding_box<data_type, dim__> & operator=(const bounding_box<data_type, dim__> &bb)
          {
            if (this!=&bb)
            {
              empty=bb.empty;
              pmin=bb.pmin;
              pmax=bb.pmax;
            }

            return (*this);
          }

          bool operator==(const bounding_box<data_type, dim__> &bb)
          {
            // if compared against self then true
            if (this==&bb)
              return true;

            // if both are empty sets then true
            if (empty && bb.empty)
              return true;

            // start comparing member data
            if (empty!=bb.empty)
              return false;
            if (pmin!=bb.pmin)
              return false;
            if (pmax!=bb.pmax)
              return false;

            return true;
          }

          bool operator!=(const bounding_box<data_type, dim__> &bb)
          {
            return !operator==(bb);
          }

          static dimension_type dimension() {return dim__;}

          bool empty_set() const {return empty;}

          void set_min(const point_type &pm)
          {
            if (empty_set())
            {
              pmax=pm;
              empty=false;
            }
            pmin=pm;
          }
          point_type get_min() const {return pmin;}

          void set_max(const point_type &pm)
          {
            if (empty_set())
            {
              pmin=pm;
              empty=false;
            }
            pmax=pm;
          }
          point_type get_max() const {return pmax;}

          // Get negative and positive points in relation to a specified normal vector direction
          void get_nppts( const point_type &nvec, point_type &npt, point_type &ppt ) const
          {
            for (index_type i=0; i<dim__; ++i)
            {
              npt(i) = pmax(i);
              ppt(i) = pmin(i);
              if ( nvec(i) >= 0.0 )
              {
                npt(i) = pmin(i);
                ppt(i) = pmax(i);
              }
            }
          }

          // Test whether bounding box intersects a plane given as a point/vector.
          bool intersect_plane( const point_type &pt, const point_type &nvec ) const
          {
            point_type npt, ppt;
            get_nppts( nvec, npt, ppt );

            data_type d = - nvec.dot( pt );

            if ( d + nvec.dot( ppt ) < 0.0 )
            {
              return false;
            }

            if ( d + nvec.dot( npt ) > 0.0 )
            {
              return false;
            }

            return true;
          }

          bool intersect_axis( const point_type &p, const index_type iax ) const
          {
            for ( index_type i = 0; i < dim__; ++i )
            {
              if ( i != iax )  // Ignore iax direction.  Otherwise a point intersection test.
              {
                if ( ( p(i) < pmin(i) ) || ( p(i) > pmax(i) ) )
                  return false;
              }
            }

            return true;
          }

          void clear()
          {
            empty=true;
            pmin.setZero();
            pmax.setZero();
          }

          bool add(const point_type &p)
          {
            index_type i;
            bool changed(false);

            // handle special case of no bounding box
            if (empty_set())
            {
              set_min(p);
              set_max(p);
              return true;
            }

            for (i=0; i<dim__; ++i)
            {
              if (p(i)<pmin(i))
              {
                changed=true;
                pmin(i)=p(i);
              }
              if (p(i)>pmax(i))
              {
                changed=true;
                pmax(i)=p(i);
              }
            }

            return changed;
          }

          bool add(const bounding_box<data_type, dim__> &bb)
          {
            bool rtn1=add(bb.pmin), rtn2=add(bb.pmax);
            return (rtn1 || rtn2);
          }

          bool inside(const point_type &p) const
          {
            for (index_type i=0; i<dim__; ++i)
            {
              if ( (p(i)<pmin(i)) || (p(i)>pmax(i)) )
                return false;
            }

            return true;
          }

          bool intersect(const bounding_box<data_type, dim__> &bb) const
          {
            const index_type nc(1<<dim__);
            point_type c[nc], bb_min(bb.get_min()), bb_max(bb.get_max());

            // set the first and last corner
            c[0]=bb_min;
            c[nc-1]=bb_max;

            // set the corners for 2 or 3 dimensional cases
            if (dim__>1)
            {
              c[1](0)=bb_max(0);
              c[1](1)=bb_min(1);
              c[2](0)=bb_min(0);
              c[2](1)=bb_max(1);
              if (dim__==3)
              {
                c[1](2)=bb_min(2);
                c[2](2)=bb_min(2);
              }
            }

            // set the remaining corners for 3 dimensional cases
            if (dim__>2)
            {
              c[3] << bb_max(0), bb_max(1), bb_min(2);
              c[4] << bb_min(0), bb_min(1), bb_max(2);
              c[5] << bb_max(0), bb_min(1), bb_max(2);
              c[6] << bb_min(0), bb_max(1), bb_max(2);
            }

            // if any corner is inside this bbox, then they intersect
            for (index_type i=0; i<nc; ++i)
            {
              if (inside(c[i]))
                return true;
            }

            // at this point know that no bb edge crosses this bbox, but need
            // to check if this bbox in entirely inside bb
            return bb.inside(pmin);
          }

        private:
          bool empty;
          point_type pmin, pmax;
      };
    }
  }
}
#endif
<commit_msg>Fix and simplify box-box intersection test<commit_after>/*********************************************************************************
* Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    David D. Marshall - initial code and implementation
********************************************************************************/

#ifndef eli_geom_general_bounding_box_hpp
#define eli_geom_general_bounding_box_hpp

#include "eli/code_eli.hpp"

#include "eli/util/tolerance.hpp"

namespace eli
{
  namespace geom
  {
    namespace general
    {
      template<typename data__, unsigned short dim__, typename tol__=eli::util::tolerance<data__> >
      class bounding_box
      {
        public:
          typedef data__ data_type;
          typedef unsigned short dimension_type;
          typedef Eigen::Matrix<data_type, 1, dim__> point_type;
          typedef typename point_type::Index index_type;
          typedef tol__ tolerance_type;

        public:
          bounding_box() : empty(true) {}
          bounding_box(const point_type &p) : empty(false), pmin(p), pmax(p) {}
          bounding_box(const bounding_box<data_type, dim__> &bb) : empty(bb.empty), pmin(bb.pmin), pmax(bb.pmax) {}
          ~bounding_box() {}

          bounding_box<data_type, dim__> & operator=(const bounding_box<data_type, dim__> &bb)
          {
            if (this!=&bb)
            {
              empty=bb.empty;
              pmin=bb.pmin;
              pmax=bb.pmax;
            }

            return (*this);
          }

          bool operator==(const bounding_box<data_type, dim__> &bb)
          {
            // if compared against self then true
            if (this==&bb)
              return true;

            // if both are empty sets then true
            if (empty && bb.empty)
              return true;

            // start comparing member data
            if (empty!=bb.empty)
              return false;
            if (pmin!=bb.pmin)
              return false;
            if (pmax!=bb.pmax)
              return false;

            return true;
          }

          bool operator!=(const bounding_box<data_type, dim__> &bb)
          {
            return !operator==(bb);
          }

          static dimension_type dimension() {return dim__;}

          bool empty_set() const {return empty;}

          void set_min(const point_type &pm)
          {
            if (empty_set())
            {
              pmax=pm;
              empty=false;
            }
            pmin=pm;
          }
          point_type get_min() const {return pmin;}

          void set_max(const point_type &pm)
          {
            if (empty_set())
            {
              pmin=pm;
              empty=false;
            }
            pmax=pm;
          }
          point_type get_max() const {return pmax;}

          // Get negative and positive points in relation to a specified normal vector direction
          void get_nppts( const point_type &nvec, point_type &npt, point_type &ppt ) const
          {
            for (index_type i=0; i<dim__; ++i)
            {
              npt(i) = pmax(i);
              ppt(i) = pmin(i);
              if ( nvec(i) >= 0.0 )
              {
                npt(i) = pmin(i);
                ppt(i) = pmax(i);
              }
            }
          }

          // Test whether bounding box intersects a plane given as a point/vector.
          bool intersect_plane( const point_type &pt, const point_type &nvec ) const
          {
            point_type npt, ppt;
            get_nppts( nvec, npt, ppt );

            data_type d = - nvec.dot( pt );

            if ( d + nvec.dot( ppt ) < 0.0 )
            {
              return false;
            }

            if ( d + nvec.dot( npt ) > 0.0 )
            {
              return false;
            }

            return true;
          }

          bool intersect_axis( const point_type &p, const index_type iax ) const
          {
            for ( index_type i = 0; i < dim__; ++i )
            {
              if ( i != iax )  // Ignore iax direction.  Otherwise a point intersection test.
              {
                if ( ( p(i) < pmin(i) ) || ( p(i) > pmax(i) ) )
                  return false;
              }
            }

            return true;
          }

          void clear()
          {
            empty=true;
            pmin.setZero();
            pmax.setZero();
          }

          bool add(const point_type &p)
          {
            index_type i;
            bool changed(false);

            // handle special case of no bounding box
            if (empty_set())
            {
              set_min(p);
              set_max(p);
              return true;
            }

            for (i=0; i<dim__; ++i)
            {
              if (p(i)<pmin(i))
              {
                changed=true;
                pmin(i)=p(i);
              }
              if (p(i)>pmax(i))
              {
                changed=true;
                pmax(i)=p(i);
              }
            }

            return changed;
          }

          bool add(const bounding_box<data_type, dim__> &bb)
          {
            bool rtn1=add(bb.pmin), rtn2=add(bb.pmax);
            return (rtn1 || rtn2);
          }

          bool inside(const point_type &p) const
          {
            for (index_type i=0; i<dim__; ++i)
            {
              if ( (p(i)<pmin(i)) || (p(i)>pmax(i)) )
                return false;
            }

            return true;
          }

          bool intersect( const bounding_box<data_type, dim__> &bb ) const
          {
            point_type bmin = bb.get_min();
            point_type bmax = bb.get_max();

            bool res = true;

            for ( index_type i = 0; i < dim__; i++ )
            {
              res = res && ( pmin(i) <= bmax(i) && pmax(i) >= bmin(i) );
            }
            return res;
          }

        private:
          bool empty;
          point_type pmin, pmax;
      };
    }
  }
}
#endif
<|endoftext|>


<commit_before>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#ifndef itkFrequencyExpandImageFilter_hxx
#define itkFrequencyExpandImageFilter_hxx

#include <itkFrequencyExpandImageFilter.h>
#include <itkObjectFactory.h>
#include <itkNumericTraits.h>
#include <itkProgressReporter.h>
#include "itkInd2Sub.h"
#include <itkPasteImageFilter.h>
#include <itkImageRegionConstIterator.h>
#include <itkGaussianSpatialFunction.h>
#include <itkFrequencyImageRegionIteratorWithIndex.h>

namespace itk
{
/**
 * Default constructor
 */
template< typename TImageType>
FrequencyExpandImageFilter< TImageType >
::FrequencyExpandImageFilter()
{
  // Set default factors to 1
  for ( unsigned int j = 0; j < ImageDimension; j++ )
    {
    m_ExpandFactors[j] = 1;
    }
}

/**
 * Standard "PrintSelf" method
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::PrintSelf(std::ostream & os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);

  unsigned int j;
  os << indent << "ExpandFactors: [";
  for ( j = 0; j < ImageDimension - 1; j++ )
    {
    os << m_ExpandFactors[j] << ", ";
    }
  os << m_ExpandFactors[j] << "]" << std::endl;
}

/**
 * Set expand factors from a single unsigned int
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::SetExpandFactors(
  const unsigned int factor)
{
  unsigned int j;

  for ( j = 0; j < ImageDimension; j++ )
    {
    if ( factor != m_ExpandFactors[j] ) { break; }
    }
  if ( j < ImageDimension )
    {
    this->Modified();
    for ( j = 0; j < ImageDimension; j++ )
      {
      m_ExpandFactors[j] = factor;
      if ( m_ExpandFactors[j] < 1 ) { m_ExpandFactors[j] = 1; }
      }
    }
}

/**
 * Implementation Detail:
 * Assume Expand Factor = 2
 * Input image is pasted 2^ImageDimension times to form the outputImage.
 * The implementation calculate the number of different regions in an image,
 * depending on the dimension:
 * numberOfRegions = 2^dim (positive and negative frequencies per dim)
 * then uses function to convert a linear array of regions [0, ..., numberOfRegions - 1]
 * to binary subindices (only two options: positive or negative region)
 * In 3D: numberOfRegions = Nr = 2^3 = 8
 * sizeOfSubindices = [2,2,2]
 * Region = 0       -----> Ind2Sub(   0, [2,2,2]) = [0,0,0]
 * Region = 1       -----> Ind2Sub(   1, [2,2,2]) = [1,0,0]
 * Region = Nr - 1  -----> Ind2Sub(Nr-1, [2,2,2]) = [1,1,1]
 * So, if the result of Ind2Sub is 0 we paste the positive frequencies, if 1, negative freq
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::GenerateData()
{
  const ImageType * inputPtr  = this->GetInput();
  ImagePointer      outputPtr = this->GetOutput();
  // complex is initialized to zero directly.

  this->AllocateOutputs();
  outputPtr->FillBuffer(0);
  typename TImageType::SizeType inputSize = inputPtr->GetLargestPossibleRegion().GetSize();
  typename TImageType::IndexType inputOriginIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
  typename TImageType::SizeType outputSize = outputPtr->GetLargestPossibleRegion().GetSize();
  FixedArray<bool, TImageType::ImageDimension> inputSizeIsEven;

  const typename TImageType::IndexType indexRequested = outputPtr->GetLargestPossibleRegion().GetIndex();

  // Manage ImageDimension array linearly:{{{
  FixedArray<unsigned int , ImageDimension> nsizes;
  unsigned int numberOfRegions = 1;
  for (unsigned int dim = 0; dim < ImageDimension; ++dim)
    {
    nsizes[dim] = 2;
    numberOfRegions *= nsizes[dim];
    }
  FixedArray<unsigned int, ImageDimension> subIndices;
  /// }}}

  // Prepare filter to paste the different regions into output.
  typedef itk::PasteImageFilter<ImageType> PasteFilterType;
  typename PasteFilterType::Pointer pasteFilter = PasteFilterType::New();
  pasteFilter->SetSourceImage(inputPtr);
  pasteFilter->SetDestinationImage(outputPtr);
  pasteFilter->InPlaceOn();

  typedef typename ImageType::RegionType RegionType;
  ProgressReporter progress(this, 0, numberOfRegions );

  for (unsigned int n = 0; n < numberOfRegions; ++n)
    {
    subIndices = Ind2Sub<ImageDimension>(n, nsizes);
    RegionType zoneRegion;
    typename ImageType::SizeType  zoneSize    = inputSize;
    typename ImageType::IndexType inputIndex  = inputOriginIndex;
    typename ImageType::IndexType outputIndex = indexRequested;
    // We have to avoid break simmetry and the hermitian property.
    // So the output of a ComplexInverseFFT will generate complex images with non-zero imaginary part.
    for (unsigned int dim = 0; dim < ImageDimension; ++dim)
      {
      if(subIndices[dim] == 0) // positive frequencies
        outputIndex[dim] = indexRequested[dim];
      else // negative frequencies
        outputIndex[dim] = indexRequested[dim] + outputSize[dim] - zoneSize[dim];
      }
    zoneRegion.SetIndex(inputIndex);
    zoneRegion.SetSize(zoneSize);
    itkDebugMacro( << "n:" << n << " region: " << zoneRegion);

    pasteFilter->SetSourceRegion(zoneRegion);
    pasteFilter->SetDestinationIndex(outputIndex);
    if (n == numberOfRegions - 1) // Graft the output.
      {
      pasteFilter->GraftOutput(outputPtr);
      pasteFilter->Update();
      this->GraftOutput(pasteFilter->GetOutput());
      }
    else // update output
      {
      pasteFilter->Update();
      outputPtr = pasteFilter->GetOutput();
      }
    progress.CompletedPixel();
    }

    // // Apply a gaussian window of the size of the input.
    // typedef itk::GaussianSpatialFunction<double, ImageDimension> FunctionType;
    // typename FunctionType::Pointer gaussian = FunctionType::New();
    // typedef FixedArray< double, ImageDimension > ArrayType;
    // ArrayType m_Mean;
    // ArrayType m_Sigma;
    // double m_Scale = 1.0;
    // bool m_Normalized = true;
    // for (unsigned int i = 0; i<ImageDimension; ++i)
    //   {
    //   m_Mean[i] = inputPtr->GetLargestPossibleRegion().GetIndex()[i];
    //   // 6.0 is equivalent to 3sigmas (border values are close to zero)
    //   // m_Sigma[i] = outputSize[i]/(2*3.0);
    //   m_Sigma[i] = inputSize[i]/(2.0*2.35);
    //   }
    // gaussian->SetSigma(m_Sigma);
    // gaussian->SetMean(m_Mean);
    // gaussian->SetScale(m_Scale);
    // gaussian->SetNormalized(m_Normalized);
    //
    // // Create an iterator that will walk the output region
    // typedef itk::FrequencyImageRegionIteratorWithIndex< TImageType > OutputIterator;
    // OutputIterator outIt = OutputIterator( outputPtr,
    //     outputPtr->GetRequestedRegion() );
    // outIt.GoToBegin();
    // while( !outIt.IsAtEnd() )
    //   {
    //   typename TImageType::IndexType ind = outIt.GetFrequencyBin();
    //   typename FunctionType::InputType f;
    //   for (unsigned int i = 0; i<ImageDimension; ++i)
    //     {
    //     f[i] = static_cast<typename FunctionType::InputType::ValueType>(ind[i]);
    //     }
    //   const double value = gaussian->Evaluate(f);
    //   // Set the pixel value to the function value
    //   outIt.Set( outIt.Get() * static_cast<typename TImageType::PixelType::value_type>(value) );
    //   ++outIt;
    //   }
}

/**
 * GenerateInputRequesteRegion
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::GenerateInputRequestedRegion()
{
  // Call the superclass' implementation of this method
  Superclass::GenerateInputRequestedRegion();

  // Get pointers to the input and output
  ImagePointer inputPtr =
    const_cast< TImageType * >( this->GetInput() );
  ImagePointer outputPtr = this->GetOutput();

  if ( !inputPtr || !outputPtr )
    {
    return;
    }

  // We need to compute the input requested region (size and start index)
  unsigned int i;
  const typename TImageType::SizeType & outputRequestedRegionSize =
    outputPtr->GetRequestedRegion().GetSize();
  const typename TImageType::IndexType & outputRequestedRegionStartIndex =
    outputPtr->GetRequestedRegion().GetIndex();

  typename TImageType::SizeType inputRequestedRegionSize;
  typename TImageType::IndexType inputRequestedRegionStartIndex;

  /**
   * inputRequestedSize = (outputRequestedSize / ExpandFactor) + 1)
   * The extra 1 above is to take care of edge effects when streaming.
   */
  for ( i = 0; i < TImageType::ImageDimension; i++ )
    {
    inputRequestedRegionSize[i] =
      (SizeValueType)std::ceil( (double)outputRequestedRegionSize[i]
                      / (double)m_ExpandFactors[i] ) + 1;

    inputRequestedRegionStartIndex[i] =
      (SizeValueType)std::floor( (double)outputRequestedRegionStartIndex[i]
                       / (double)m_ExpandFactors[i] );
    }

  typename TImageType::RegionType inputRequestedRegion;
  inputRequestedRegion.SetSize(inputRequestedRegionSize);
  inputRequestedRegion.SetIndex(inputRequestedRegionStartIndex);

  // Make sure the requested region is within largest possible.
  inputRequestedRegion.Crop( inputPtr->GetLargestPossibleRegion() );

  // Set the input requested region.
  inputPtr->SetRequestedRegion(inputRequestedRegion);
}

/**
 * GenerateOutputInformation
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::GenerateOutputInformation()
{
  // Call the superclass' implementation of this method
  Superclass::GenerateOutputInformation();

  // Get pointers to the input and output
  ImagePointer inputPtr =
    const_cast< TImageType * >( this->GetInput() );
  ImagePointer outputPtr = this->GetOutput();

  if ( !inputPtr || !outputPtr )
    {
    return;
    }

  // We need to compute the output spacing, the output image size, and the
  // output image start index
  const typename TImageType::SpacingType &
  inputSpacing = inputPtr->GetSpacing();
  const typename TImageType::SizeType &   inputSize =
    inputPtr->GetLargestPossibleRegion().GetSize();
  const typename TImageType::IndexType &  inputStartIndex =
    inputPtr->GetLargestPossibleRegion().GetIndex();
  const typename TImageType::PointType &
  inputOrigin = inputPtr->GetOrigin();

  typename TImageType::SpacingType outputSpacing;
  typename TImageType::SizeType outputSize;
  typename TImageType::IndexType outputStartIndex;
  typename TImageType::PointType outputOrigin;

  typename TImageType::SpacingType inputOriginShift;

  for ( unsigned int i = 0; i < TImageType::ImageDimension; i++ )
    {
    outputSpacing[i] = inputSpacing[i] / (float)m_ExpandFactors[i];
    outputSize[i] = inputSize[i] * (SizeValueType)m_ExpandFactors[i];
    outputStartIndex[i] = inputStartIndex[i] * (IndexValueType)m_ExpandFactors[i];
    const double fraction = (double)( m_ExpandFactors[i] - 1 ) / (double)m_ExpandFactors[i];
    inputOriginShift[i] = -( inputSpacing[i] / 2.0 ) * fraction;
    }

  const typename TImageType::DirectionType inputDirection = inputPtr->GetDirection();
  const typename TImageType::SpacingType outputOriginShift = inputDirection * inputOriginShift;

  outputOrigin = inputOrigin + outputOriginShift;

  outputPtr->SetSpacing(outputSpacing);
  outputPtr->SetOrigin(outputOrigin);

  typename TImageType::RegionType outputLargestPossibleRegion;
  outputLargestPossibleRegion.SetSize(outputSize);
  outputLargestPossibleRegion.SetIndex(outputStartIndex);

  outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
}
} // end namespace itk

#endif
<commit_msg>[STYLE] Remove outdated commented region.<commit_after>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#ifndef itkFrequencyExpandImageFilter_hxx
#define itkFrequencyExpandImageFilter_hxx

#include <itkFrequencyExpandImageFilter.h>
#include <itkObjectFactory.h>
#include <itkNumericTraits.h>
#include <itkProgressReporter.h>
#include "itkInd2Sub.h"
#include <itkPasteImageFilter.h>
#include <itkImageRegionConstIterator.h>
#include <itkGaussianSpatialFunction.h>
#include <itkFrequencyImageRegionIteratorWithIndex.h>

namespace itk
{
/**
 * Default constructor
 */
template< typename TImageType>
FrequencyExpandImageFilter< TImageType >
::FrequencyExpandImageFilter()
{
  // Set default factors to 1
  for ( unsigned int j = 0; j < ImageDimension; j++ )
    {
    m_ExpandFactors[j] = 2;
    }
}

/**
 * Standard "PrintSelf" method
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::PrintSelf(std::ostream & os, Indent indent) const
{
  Superclass::PrintSelf(os, indent);

  unsigned int j;
  os << indent << "ExpandFactors: [";
  for ( j = 0; j < ImageDimension - 1; j++ )
    {
    os << m_ExpandFactors[j] << ", ";
    }
  os << m_ExpandFactors[j] << "]" << std::endl;
}

/**
 * Set expand factors from a single unsigned int
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::SetExpandFactors(
  const unsigned int factor)
{
  unsigned int j;
  for ( j = 0; j < ImageDimension; j++ )
    {
    if ( factor != m_ExpandFactors[j] ) { break; }
    }
  if ( j < ImageDimension )
    {
    this->Modified();
    for ( j = 0; j < ImageDimension; j++ )
      {
      m_ExpandFactors[j] = factor;
      if ( m_ExpandFactors[j] < 1 ) { m_ExpandFactors[j] = 1; }
      }
    }
}

/**
 * Implementation Detail:
 * Assume Expand Factor = 2
 * Input image is pasted 2^ImageDimension times to form the outputImage.
 * The implementation calculate the number of different regions in an image,
 * depending on the dimension:
 * numberOfRegions = 2^dim (positive and negative frequencies per dim)
 * then uses function to convert a linear array of regions [0, ..., numberOfRegions - 1]
 * to binary subindices (only two options: positive or negative region)
 * In 3D: numberOfRegions = Nr = 2^3 = 8
 * sizeOfSubindices = [2,2,2]
 * Region = 0       -----> Ind2Sub(   0, [2,2,2]) = [0,0,0]
 * Region = 1       -----> Ind2Sub(   1, [2,2,2]) = [1,0,0]
 * Region = Nr - 1  -----> Ind2Sub(Nr-1, [2,2,2]) = [1,1,1]
 * So, if the result of Ind2Sub is 0 we paste the positive frequencies, if 1, negative freq
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::GenerateData()
{
  const ImageType * inputPtr  = this->GetInput();
  ImagePointer      outputPtr = this->GetOutput();
  // complex is initialized to zero directly.

  this->AllocateOutputs();
  outputPtr->FillBuffer(0);
  typename TImageType::SizeType inputSize = inputPtr->GetLargestPossibleRegion().GetSize();
  typename TImageType::IndexType inputOriginIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
  typename TImageType::SizeType outputSize = outputPtr->GetLargestPossibleRegion().GetSize();
  FixedArray<bool, TImageType::ImageDimension> inputSizeIsEven;

  const typename TImageType::IndexType indexRequested = outputPtr->GetLargestPossibleRegion().GetIndex();

  // Manage ImageDimension array linearly:{{{
  FixedArray<unsigned int , ImageDimension> nsizes;
  unsigned int numberOfRegions = 1;
  for (unsigned int dim = 0; dim < ImageDimension; ++dim)
    {
    nsizes[dim] = 2;
    numberOfRegions *= nsizes[dim];
    }
  FixedArray<unsigned int, ImageDimension> subIndices;
  /// }}}

  // Prepare filter to paste the different regions into output.
  typedef itk::PasteImageFilter<ImageType> PasteFilterType;
  typename PasteFilterType::Pointer pasteFilter = PasteFilterType::New();
  pasteFilter->SetSourceImage(inputPtr);
  pasteFilter->SetDestinationImage(outputPtr);
  pasteFilter->InPlaceOn();

  typedef typename ImageType::RegionType RegionType;
  ProgressReporter progress(this, 0, numberOfRegions );

  for (unsigned int n = 0; n < numberOfRegions; ++n)
    {
    subIndices = Ind2Sub<ImageDimension>(n, nsizes);
    RegionType zoneRegion;
    typename ImageType::SizeType  zoneSize    = inputSize;
    typename ImageType::IndexType inputIndex  = inputOriginIndex;
    typename ImageType::IndexType outputIndex = indexRequested;
    // We have to avoid break simmetry and the hermitian property.
    // So the output of a ComplexInverseFFT will generate complex images with non-zero imaginary part.
    for (unsigned int dim = 0; dim < ImageDimension; ++dim)
      {
      if(subIndices[dim] == 0) // positive frequencies
        outputIndex[dim] = indexRequested[dim];
      else // negative frequencies
        outputIndex[dim] = indexRequested[dim] + outputSize[dim] - zoneSize[dim];
      }
    zoneRegion.SetIndex(inputIndex);
    zoneRegion.SetSize(zoneSize);
    itkDebugMacro( << "n:" << n << " region: " << zoneRegion);

    pasteFilter->SetSourceRegion(zoneRegion);
    pasteFilter->SetDestinationIndex(outputIndex);
    if (n == numberOfRegions - 1) // Graft the output.
      {
      pasteFilter->GraftOutput(outputPtr);
      pasteFilter->Update();
      this->GraftOutput(pasteFilter->GetOutput());
      }
    else // update output
      {
      pasteFilter->Update();
      outputPtr = pasteFilter->GetOutput();
      }
    progress.CompletedPixel();
    }
}

/**
 * GenerateInputRequesteRegion
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::GenerateInputRequestedRegion()
{
  // Call the superclass' implementation of this method
  Superclass::GenerateInputRequestedRegion();

  // Get pointers to the input and output
  ImagePointer inputPtr =
    const_cast< TImageType * >( this->GetInput() );
  ImagePointer outputPtr = this->GetOutput();

  if ( !inputPtr || !outputPtr )
    {
    return;
    }

  // We need to compute the input requested region (size and start index)
  unsigned int i;
  const typename TImageType::SizeType & outputRequestedRegionSize =
    outputPtr->GetRequestedRegion().GetSize();
  const typename TImageType::IndexType & outputRequestedRegionStartIndex =
    outputPtr->GetRequestedRegion().GetIndex();

  typename TImageType::SizeType inputRequestedRegionSize;
  typename TImageType::IndexType inputRequestedRegionStartIndex;

  /**
   * inputRequestedSize = (outputRequestedSize / ExpandFactor) + 1)
   * The extra 1 above is to take care of edge effects when streaming.
   */
  for ( i = 0; i < TImageType::ImageDimension; i++ )
    {
    inputRequestedRegionSize[i] =
      (SizeValueType)std::ceil( (double)outputRequestedRegionSize[i]
                      / (double)m_ExpandFactors[i] ) + 1;

    inputRequestedRegionStartIndex[i] =
      (SizeValueType)std::floor( (double)outputRequestedRegionStartIndex[i]
                       / (double)m_ExpandFactors[i] );
    }

  typename TImageType::RegionType inputRequestedRegion;
  inputRequestedRegion.SetSize(inputRequestedRegionSize);
  inputRequestedRegion.SetIndex(inputRequestedRegionStartIndex);

  // Make sure the requested region is within largest possible.
  inputRequestedRegion.Crop( inputPtr->GetLargestPossibleRegion() );

  // Set the input requested region.
  inputPtr->SetRequestedRegion(inputRequestedRegion);
}

/**
 * GenerateOutputInformation
 */
template< typename TImageType>
void
FrequencyExpandImageFilter< TImageType >
::GenerateOutputInformation()
{
  // Call the superclass' implementation of this method
  Superclass::GenerateOutputInformation();

  // Get pointers to the input and output
  ImagePointer inputPtr =
    const_cast< TImageType * >( this->GetInput() );
  ImagePointer outputPtr = this->GetOutput();

  if ( !inputPtr || !outputPtr )
    {
    return;
    }

  // We need to compute the output spacing, the output image size, and the
  // output image start index
  const typename TImageType::SpacingType &
  inputSpacing = inputPtr->GetSpacing();
  const typename TImageType::SizeType &   inputSize =
    inputPtr->GetLargestPossibleRegion().GetSize();
  const typename TImageType::IndexType &  inputStartIndex =
    inputPtr->GetLargestPossibleRegion().GetIndex();
  const typename TImageType::PointType &
  inputOrigin = inputPtr->GetOrigin();

  typename TImageType::SpacingType outputSpacing;
  typename TImageType::SizeType outputSize;
  typename TImageType::IndexType outputStartIndex;
  typename TImageType::PointType outputOrigin;

  typename TImageType::SpacingType inputOriginShift;

  for ( unsigned int i = 0; i < TImageType::ImageDimension; i++ )
    {
    outputSpacing[i] = inputSpacing[i] / (float)m_ExpandFactors[i];
    outputSize[i] = inputSize[i] * (SizeValueType)m_ExpandFactors[i];
    outputStartIndex[i] = inputStartIndex[i] * (IndexValueType)m_ExpandFactors[i];
    const double fraction = (double)( m_ExpandFactors[i] - 1 ) / (double)m_ExpandFactors[i];
    inputOriginShift[i] = -( inputSpacing[i] / 2.0 ) * fraction;
    }

  const typename TImageType::DirectionType inputDirection = inputPtr->GetDirection();
  const typename TImageType::SpacingType outputOriginShift = inputDirection * inputOriginShift;

  outputOrigin = inputOrigin + outputOriginShift;

  outputPtr->SetSpacing(outputSpacing);
  outputPtr->SetOrigin(outputOrigin);

  typename TImageType::RegionType outputLargestPossibleRegion;
  outputLargestPossibleRegion.SetSize(outputSize);
  outputLargestPossibleRegion.SetIndex(outputStartIndex);

  outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);
}
} // end namespace itk

#endif
<|endoftext|>


<commit_before>#include <debugger/path.h>
#include <bee/utility/unicode.h>
#include <deque>
#if defined(_WIN32)
#include <Windows.h>
#else
#include <unistd.h>
#include <memory>
#endif

namespace vscode { namespace path {
	static bool is_sep(char c)
	{
		return c == '/' || c == '\\';
	}

	static void path_push(std::deque<std::string>& stack, const std::string& path)
	{
		if (path.empty()) {
			// do nothing
		}
		else if (path == ".." && !stack.empty() && stack.back() != "..") {
			stack.pop_back();
		}
		else if (path != ".") {
			stack.push_back(path);
		}
	}

	static std::string path_currentpath()
	{
#if defined(_WIN32)
		DWORD len = GetCurrentDirectoryW(0, nullptr);
		if (len == 0) {
			return std::string("c:");
		}
		std::wstring r;
		r.resize(len);
		GetCurrentDirectoryW((DWORD)r.size(), &r.front());
		return bee::w2u(r);
#else
		for (long path_max = 128;; path_max *= 2)
		{
			std::unique_ptr<char[]> buf(new char[static_cast<std::size_t>(path_max)]);
			if (::getcwd(buf.get(), static_cast<std::size_t>(path_max)) == 0) {
				if (errno != ERANGE) {
					break;
				}
			}
			else {
				return buf.get();
			}
		}
		return std::string("~/");
#endif
	}

	static std::string path_normalize(const std::string& path, std::deque<std::string>& stack)
	{
		std::string root;
		size_t pos = path.find(':', 0);
		if (pos == path.npos) {
			root = path_normalize(path_currentpath(), stack);
			pos = 0;
		}
		else {
			pos++;
			root = path.substr(0, pos);
		}

		for (size_t i = pos; i < path.size(); ++i) {
			char c = path[i];
			if (is_sep(c)) {
				if (i > pos) {
					path_push(stack, path.substr(pos, i - pos));
				}
				pos = i + 1;
			}
		}
		path_push(stack, path.substr(pos));
		return root;
	}

	static std::string path_create(const std::string& path, const std::deque<std::string>& stack, char sep)
	{
		std::string result = path;
		for (auto& e : stack) {
			result += sep + e;
		}
		return result;
	}

	template <typename EQUAL>
	bool glob_match(const std::string_view& pattern, const std::string_view& target, EQUAL equal)
	{
		auto p = pattern.data();
		auto pe = pattern.data() + pattern.size();
		auto q = target.data();
		auto qe = target.data() + target.size();
		for (;;) {
			if (p == pe) {
				return q == qe;
			}
			if (*p == '*') {
				++p;
				for (auto backtracker = qe; backtracker >= q; --backtracker) {
					if (glob_match(std::string_view(p, pe - p), std::string_view(backtracker, qe - backtracker), equal)) {
						return true;
					}
				}
				break;
			}
			if (q == qe) {
				break;
			}
			if (*p != '?' && !equal(*p, *q)) {
				break;
			}
			++p, ++q;
		}
		return false;
	}

	int tochar(char c) {
		if (c == '/') return '\\';
		return tolower((int)(unsigned char)c);
	}

	std::string normalize(const std::string& path, char sep)
	{
		std::deque<std::string> stack;
		std::string result = path_normalize(path, stack);
		return path_create(result, stack, sep);
	}

	std::string filename(const std::string& path)
	{
		for (ptrdiff_t pos = path.size() - 1; pos >= 0; --pos) {
			char c = path[pos];
			if (is_sep(c)) {
				return path.substr(pos + 1);
			}
		}
		return path;
	}

	bool glob_match(const std::string& pattern, const std::string& target)
	{
		return glob_match(pattern, target, [](char a, char b) { return tochar(a) == tochar(b); });
	}

	std::string relative(const std::string& path, const std::string& base, char sep)
	{
		std::deque<std::string> spath, sbase;
		std::string rpath = path_normalize(path, spath);
		std::string rbase = path_normalize(base, sbase);
		if (rpath != rbase) {
			return path_create(rpath, spath, sep);
		}
		while (!spath.empty() && !sbase.empty() && spath.front() == sbase.front()) {
			spath.pop_front();
			sbase.pop_front();
		}
		if (spath.empty() && sbase.empty()) {
			return "." + sep;
		}
		std::string result = "";
		for (auto& e : sbase) {
			result += sep + "..";
		}
		for (auto& e : spath) {
			result += sep + e;
		}
		return result.substr(1);
	}
}}
<commit_msg>修正一个bug<commit_after>#include <debugger/path.h>
#include <bee/utility/unicode.h>
#include <bee/utility/dynarray.h>
#include <deque>
#if defined(_WIN32)
#include <Windows.h>
#else
#include <unistd.h>
#include <memory>
#endif

namespace vscode { namespace path {
	static bool is_sep(char c)
	{
		return c == '/' || c == '\\';
	}

	static void path_push(std::deque<std::string>& stack, const std::string& path)
	{
		if (path.empty()) {
			// do nothing
		}
		else if (path == ".." && !stack.empty() && stack.back() != "..") {
			stack.pop_back();
		}
		else if (path != ".") {
			stack.push_back(path);
		}
	}

	static std::string path_currentpath()
	{
#if defined(_WIN32)
		DWORD len = GetCurrentDirectoryW(0, nullptr);
		if (len == 0) {
			return std::string("c:");
		}
		std::dynarray<wchar_t> r(len);
		len = GetCurrentDirectoryW(len, r.data());
		return bee::w2u(std::wstring_view(r.data(), len));
#else
		for (long path_max = 128;; path_max *= 2)
		{
			std::unique_ptr<char[]> buf(new char[static_cast<std::size_t>(path_max)]);
			if (::getcwd(buf.get(), static_cast<std::size_t>(path_max)) == 0) {
				if (errno != ERANGE) {
					break;
				}
			}
			else {
				return buf.get();
			}
		}
		return std::string("~/");
#endif
	}

	static std::string path_normalize(const std::string& path, std::deque<std::string>& stack)
	{
		std::string root;
		size_t pos = path.find(':', 0);
		if (pos == path.npos) {
			root = path_normalize(path_currentpath(), stack);
			pos = 0;
		}
		else {
			pos++;
			root = path.substr(0, pos);
		}

		for (size_t i = pos; i < path.size(); ++i) {
			char c = path[i];
			if (is_sep(c)) {
				if (i > pos) {
					path_push(stack, path.substr(pos, i - pos));
				}
				pos = i + 1;
			}
		}
		path_push(stack, path.substr(pos));
		return root;
	}

	static std::string path_create(const std::string& path, const std::deque<std::string>& stack, char sep)
	{
		std::string result = path;
		for (auto& e : stack) {
			result += sep + e;
		}
		return result;
	}

	template <typename EQUAL>
	bool glob_match(const std::string_view& pattern, const std::string_view& target, EQUAL equal)
	{
		auto p = pattern.data();
		auto pe = pattern.data() + pattern.size();
		auto q = target.data();
		auto qe = target.data() + target.size();
		for (;;) {
			if (p == pe) {
				return q == qe;
			}
			if (*p == '*') {
				++p;
				for (auto backtracker = qe; backtracker >= q; --backtracker) {
					if (glob_match(std::string_view(p, pe - p), std::string_view(backtracker, qe - backtracker), equal)) {
						return true;
					}
				}
				break;
			}
			if (q == qe) {
				break;
			}
			if (*p != '?' && !equal(*p, *q)) {
				break;
			}
			++p, ++q;
		}
		return false;
	}

	int tochar(char c) {
		if (c == '/') return '\\';
		return tolower((int)(unsigned char)c);
	}

	std::string normalize(const std::string& path, char sep)
	{
		std::deque<std::string> stack;
		std::string result = path_normalize(path, stack);
		return path_create(result, stack, sep);
	}

	std::string filename(const std::string& path)
	{
		for (ptrdiff_t pos = path.size() - 1; pos >= 0; --pos) {
			char c = path[pos];
			if (is_sep(c)) {
				return path.substr(pos + 1);
			}
		}
		return path;
	}

	bool glob_match(const std::string& pattern, const std::string& target)
	{
		return glob_match(pattern, target, [](char a, char b) { return tochar(a) == tochar(b); });
	}

	std::string relative(const std::string& path, const std::string& base, char sep)
	{
		std::deque<std::string> spath, sbase;
		std::string rpath = path_normalize(path, spath);
		std::string rbase = path_normalize(base, sbase);
		if (rpath != rbase) {
			return path_create(rpath, spath, sep);
		}
		while (!spath.empty() && !sbase.empty() && spath.front() == sbase.front()) {
			spath.pop_front();
			sbase.pop_front();
		}
		if (spath.empty() && sbase.empty()) {
			return "." + sep;
		}
		std::string result = "";
		for (auto& e : sbase) {
			result += sep + "..";
		}
		for (auto& e : spath) {
			result += sep + e;
		}
		return result.substr(1);
	}
}}
<|endoftext|>


<commit_before>//checks if a is divisible by b by using the modulo operator

bool divisible(int a,int b){
    if(a%b==0) return true;
    return false;
}
<commit_msg>Update Divisibility.cpp<commit_after>//checks if a is divisible by b by using the modulo operator

bool divisible(int a,int b){
    return (a%b==0);
}
<|endoftext|>


<commit_before>/*
    This file is part of Csound.

        Copyright (C) 2014 Rory Walsh

    The Csound 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.

    Csound 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 Csound; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA
 */

#include "OpcodeBase.hpp"
#include <algorithm>
#include <cmath>
#include <dirent.h>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <vector>

using namespace std;
using namespace csound;

/* this function will load all samples of supported types into function
   tables number 'index' and upwards.
   It return the number of samples loaded */
int loadSamplesToTables(CSOUND *csound, int index, char *directory,
                        int skiptime, int format, int channel);

//-----------------------------------------------------------------
//      i-rate class
//-----------------------------------------------------------------
class iftsamplebank : public OpcodeBase<iftsamplebank> {
public:
  // Outputs.
  MYFLT *numberOfFiles;
  // Inputs.
  STRINGDAT *sDirectory;
  MYFLT *index;
  //    MYFLT* trigger;
  MYFLT *skiptime;
  MYFLT *format;
  MYFLT *channel;

  iftsamplebank() {
    channel = 0;
    index = 0;
    skiptime = 0;
    format = 0;
    index = 0;
    numberOfFiles = 0;
    sDirectory = NULL;
  }

  // init-pass
  int init(CSOUND *csound) {

    *numberOfFiles = loadSamplesToTables(
        csound, *index, (char *)sDirectory->data, *skiptime, *format, *channel);
    return OK;
  }

  int noteoff(CSOUND *) { return OK; }
};

//-----------------------------------------------------------------
//      k-rate class
//-----------------------------------------------------------------
class kftsamplebank : public OpcodeBase<kftsamplebank> {
public:
  // Outputs.
  MYFLT *numberOfFiles;
  // Inputs.
  STRINGDAT *sDirectory;
  MYFLT *index;
  MYFLT *trigger;
  MYFLT *skiptime;
  MYFLT *format;
  MYFLT *channel;
  int internalCounter;
  kftsamplebank() : internalCounter(0) {
    channel = 0;
    index = 0;
    skiptime = 0;
    format = 0;
    index = 0;
    trigger = 0;
  }

  // init-pass
  int init(CSOUND *csound) {
    IGN(csound);
    *numberOfFiles =
          loadSamplesToTables(csound, *index, (char *)sDirectory->data,
                              *skiptime, *format, *channel);
    *trigger = 0;
    return OK;
  }

  int noteoff(CSOUND *) { return OK; }

  int kontrol(CSOUND *csound) {
    // if directry changes update tables..
    if (*trigger == 1) {
      *numberOfFiles =
          loadSamplesToTables(csound, *index, (char *)sDirectory->data,
                              *skiptime, *format, *channel);
      *trigger = 0;
    }
    return OK;
  }
};

//-----------------------------------------------------------------
//      load samples into function tables
//-----------------------------------------------------------------
int loadSamplesToTables(CSOUND *csound, int index, char *directory,
                        int skiptime, int format, int channel) {

  if (directory) {
    DIR *dir = opendir(directory);
    std::vector<std::string> fileNames;
    std::vector<std::string> fileExtensions;
    int noOfFiles = 0;
    fileExtensions.push_back(".wav");
    fileExtensions.push_back(".aiff");
    fileExtensions.push_back(".ogg");
    fileExtensions.push_back(".flac");

    // check for valid path first
    if (dir) {
      struct dirent *ent;
      while ((ent = readdir(dir)) != NULL) {
        std::ostringstream fullFileName;
        // only use supported file types
        for (int i = 0; (size_t)i < fileExtensions.size(); i++)
        {
          std::string fname = ent->d_name;
          std::string extension;
          if(fname.find_last_of(".") != std::string::npos)
            extension = fname.substr(fname.find_last_of("."));

          if(extension == fileExtensions[i])
            {
              if (strlen(directory) > 2) {
#if defined(WIN32)
              fullFileName << directory << "\\" << ent->d_name;
#else
              fullFileName << directory << "/" << ent->d_name;
#endif
            }
            else
              fullFileName << ent->d_name;

            noOfFiles++;

            fileNames.push_back(fullFileName.str());
          }
        }
      }

      // Sort names
      std::sort(fileNames.begin(), fileNames.end());

      // push statements to score, starting with table number 'index'
      for (int y = 0; (size_t)y < fileNames.size(); y++) {
        std::ostringstream statement;
        statement << "f" << index + y << " 0 0 1 \"" << fileNames[y] << "\" "
                  << skiptime << " " << format << " " << channel << "\n";
        // csound->MessageS(csound, CSOUNDMSG_ORCH, statement.str().c_str());
        csound->InputMessage(csound, statement.str().c_str());
      }

      closedir(dir);
    } else {
      csound->Message(csound,
                      Str("Cannot load file. Error opening directory: %s\n"),
                      directory);
    }

    // return number of files
    return noOfFiles;
  } else
    return 0;
}

typedef struct {
  OPDS h;
  ARRAYDAT *outArr;
  STRINGDAT *directoryName;
  MYFLT *extension;
} DIR_STRUCT;

/* this function will looks for files of a set type, in a particular directory
 */
std::vector<std::string> searchDir(CSOUND *csound, char *directory,
                                   char *extension);

#include "arrays.h"
#if 0
/* from Opcodes/arrays.c */
static inline void tabensure(CSOUND *csound, ARRAYDAT *p, int size) {
    if (p->data==NULL || p->dimensions == 0 ||
        (p->dimensions==1 && p->sizes[0] < size)) {
      size_t ss;
      if (p->data == NULL) {
        CS_VARIABLE* var = p->arrayType->createVariable(csound, NULL);
        p->arrayMemberSize = var->memBlockSize;
      }
      ss = p->arrayMemberSize*size;
      if (p->data==NULL) {
        p->data = (MYFLT*)csound->Calloc(csound, ss);
        p->allocated = ss;
      }
      else if (ss > p->allocated) {
        p->data = (MYFLT*) csound->ReAlloc(csound, p->data, ss);
        p->allocated = ss;
      }
      if (p->dimensions==0) {
        p->dimensions = 1;
        p->sizes = (int32_t*)csound->Malloc(csound, sizeof(int32_t));
      }
    }
    p->sizes[0] = size;
}
#endif

static int directory(CSOUND *csound, DIR_STRUCT *p) {
  int inArgCount = p->INOCOUNT;
  char *extension, *file;
  std::vector<std::string> fileNames;

  if (inArgCount == 0)
    return csound->InitError(
        csound, "%s", Str("Error: you must pass a directory as a string."));

  if (inArgCount == 1) {
    fileNames = searchDir(csound, p->directoryName->data, (char *)"");
  }

  else if (inArgCount == 2) {
    CS_TYPE *argType = csound->GetTypeForArg(p->extension);
    if (strcmp("S", argType->varTypeName) == 0) {
      extension = csound->Strdup(csound, ((STRINGDAT *)p->extension)->data);
      fileNames = searchDir(csound, p->directoryName->data, extension);
    } else
      return csound->InitError(csound,
                               "%s", Str("Error: second parameter to directory"
                                   " must be a string"));
  }

  int numberOfFiles = fileNames.size();
  tabinit(csound, p->outArr, numberOfFiles);
  STRINGDAT *strings = (STRINGDAT *)p->outArr->data;

  for (int i = 0; i < numberOfFiles; i++) {
    file = &fileNames[i][0u];
    strings[i].size = strlen(file) + 1;
    strings[i].data = csound->Strdup(csound, file);
  }

  fileNames.clear();

  return OK;
}

//-----------------------------------------------------------------
//      load samples into function tables
//-----------------------------------------------------------------
std::vector<std::string> searchDir(CSOUND *csound, char *directory,
                                   char *extension) {
  std::vector<std::string> fileNames;
  if (directory) {
    DIR *dir = opendir(directory);
    std::string fileExtension(extension);
    int noOfFiles = 0;

    // check for valid path first
    if (dir) {
      struct dirent *ent;
      while ((ent = readdir(dir)) != NULL) {
        std::ostringstream fullFileName;

        std::string fname = ent->d_name;
        size_t lastPos = fname.find_last_of(".");
        if (fname.length() > 2 && (fileExtension.empty() ||
            (lastPos != std::string::npos &&
            fname.substr(lastPos) == fileExtension))) {
          if (strlen(directory) > 2) {
#if defined(WIN32)
            fullFileName << directory << "\\" << ent->d_name;
#else
            fullFileName << directory << "/" << ent->d_name;
#endif
          } else
            fullFileName << ent->d_name;

          noOfFiles++;
          fileNames.push_back(fullFileName.str());
        }
      }

      // Sort names
      std::sort(fileNames.begin(), fileNames.end());
    } else {
      csound->Message(csound, Str("Cannot find directory. "
                                  "Error opening directory: %s\n"),
                      directory);
    }
    closedir(dir);
  }

  return fileNames;
}

extern "C" {

PUBLIC int csoundModuleInit_ftsamplebank(CSOUND *csound) {

  int status = csound->AppendOpcode(
      csound, (char *)"ftsamplebank.k", sizeof(kftsamplebank), 0, 3,
      (char *)"k", (char *)"Skkkkk",
      (int (*)(CSOUND *, void *))kftsamplebank::init_,
      (int (*)(CSOUND *, void *))kftsamplebank::kontrol_,
      (int (*)(CSOUND *, void *))0);

  status |= csound->AppendOpcode(
      csound, (char *)"ftsamplebank.i", sizeof(iftsamplebank), 0, 1,
      (char *)"i", (char *)"Siiii",
      (int (*)(CSOUND *, void *))iftsamplebank::init_,
      (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0);

  /*  status |= csound->AppendOpcode(csound,
      (char*)"ftsamplebank",
      0xffff,
      0,
      0,
      0,
      0,
      0,
      0,
      0); */

  status |= csound->AppendOpcode(
      csound, (char *)"directory", sizeof(DIR_STRUCT), 0, 1, (char *)"S[]",
      (char *)"SN", (int (*)(CSOUND *, void *))directory,
      (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0);
  return status;
}

#ifndef INIT_STATIC_MODULES
PUBLIC int csoundModuleCreate(CSOUND *csound) {
  IGN(csound);
  return 0;
}

PUBLIC int csoundModuleInit(CSOUND *csound) {
  return csoundModuleInit_ftsamplebank(csound);
}

PUBLIC int csoundModuleDestroy(CSOUND *csound) {
  IGN(csound);
  return 0;
}
#endif
}
<commit_msg>Update ftsamplebank.cpp<commit_after>/*
    This file is part of Csound.

        Copyright (C) 2014 Rory Walsh

    The Csound 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.

    Csound 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 Csound; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA
 */

#include "OpcodeBase.hpp"
#include <algorithm>
#include <cmath>
#include <dirent.h>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <vector>

using namespace std;
using namespace csound;

/* this function will load all samples of supported types into function
   tables number 'index' and upwards.
   It return the number of samples loaded */
int loadSamplesToTables(CSOUND *csound, int index, char *directory,
                        int skiptime, int format, int channel);

//-----------------------------------------------------------------
//      i-rate class
//-----------------------------------------------------------------
class iftsamplebank : public OpcodeBase<iftsamplebank> {
public:
  // Outputs.
  MYFLT *numberOfFiles;
  // Inputs.
  STRINGDAT *sDirectory;
  MYFLT *index;
  //    MYFLT* trigger;
  MYFLT *skiptime;
  MYFLT *format;
  MYFLT *channel;

  iftsamplebank() {
    channel = 0;
    index = 0;
    skiptime = 0;
    format = 0;
    index = 0;
    numberOfFiles = 0;
    sDirectory = NULL;
  }

  // init-pass
  int init(CSOUND *csound) {

    *numberOfFiles = loadSamplesToTables(
        csound, *index, (char *)sDirectory->data, *skiptime, *format, *channel);
    return OK;
  }

  int noteoff(CSOUND *) { return OK; }
};

//-----------------------------------------------------------------
//      k-rate class
//-----------------------------------------------------------------
class kftsamplebank : public OpcodeBase<kftsamplebank> {
public:
  // Outputs.
  MYFLT *numberOfFiles;
  // Inputs.
  STRINGDAT *sDirectory;
  MYFLT *index;
  MYFLT *trigger;
  MYFLT *skiptime;
  MYFLT *format;
  MYFLT *channel;
  int internalCounter;
  kftsamplebank() : internalCounter(0) {
    channel = 0;
    index = 0;
    skiptime = 0;
    format = 0;
    index = 0;
    trigger = 0;
  }

  // init-pass
  int init(CSOUND *csound) {
    IGN(csound);
    *numberOfFiles =
          loadSamplesToTables(csound, *index, (char *)sDirectory->data,
                              *skiptime, *format, *channel);
    *trigger = 0;
    return OK;
  }

  int noteoff(CSOUND *) { return OK; }

  int kontrol(CSOUND *csound) {
    // if directry changes update tables..
    if (*trigger == 1) {
      *numberOfFiles =
          loadSamplesToTables(csound, *index, (char *)sDirectory->data,
                              *skiptime, *format, *channel);
      *trigger = 0;
    }
    return OK;
  }
};

//-----------------------------------------------------------------
//      load samples into function tables
//-----------------------------------------------------------------
int loadSamplesToTables(CSOUND *csound, int index, char *directory,
                        int skiptime, int format, int channel) {

  if (directory) {
    DIR *dir = opendir(directory);
    std::vector<std::string> fileNames;
    std::vector<std::string> fileExtensions;
    int noOfFiles = 0;
    fileExtensions.push_back(".wav");
    fileExtensions.push_back(".aiff");
    fileExtensions.push_back(".ogg");
    fileExtensions.push_back(".flac");

    // check for valid path first
    if (dir) {
      struct dirent *ent;
      while ((ent = readdir(dir)) != NULL) {
        std::ostringstream fullFileName;
        // only use supported file types
        for (int i = 0; (size_t)i < fileExtensions.size(); i++)
        {
          std::string fname = ent->d_name;
          std::string extension;
          if(fname.find_last_of(".") != std::string::npos)
            extension = fname.substr(fname.find_last_of("."));

          if(extension == fileExtensions[i])
            {
              if (strlen(directory) > 0) {
#if defined(WIN32)
              fullFileName << directory << "\\" << ent->d_name;
#else
              fullFileName << directory << "/" << ent->d_name;
#endif
            }
            else
              fullFileName << ent->d_name;

            noOfFiles++;

            fileNames.push_back(fullFileName.str());
          }
        }
      }

      // Sort names
      std::sort(fileNames.begin(), fileNames.end());

      // push statements to score, starting with table number 'index'
      for (int y = 0; (size_t)y < fileNames.size(); y++) {
        std::ostringstream statement;
        statement << "f" << index + y << " 0 0 1 \"" << fileNames[y] << "\" "
                  << skiptime << " " << format << " " << channel << "\n";
        // csound->MessageS(csound, CSOUNDMSG_ORCH, statement.str().c_str());
        csound->InputMessage(csound, statement.str().c_str());
      }

      closedir(dir);
    } else {
      csound->Message(csound,
                      Str("Cannot load file. Error opening directory: %s\n"),
                      directory);
    }

    // return number of files
    return noOfFiles;
  } else
    return 0;
}

typedef struct {
  OPDS h;
  ARRAYDAT *outArr;
  STRINGDAT *directoryName;
  MYFLT *extension;
} DIR_STRUCT;

/* this function will looks for files of a set type, in a particular directory
 */
std::vector<std::string> searchDir(CSOUND *csound, char *directory,
                                   char *extension);

#include "arrays.h"
#if 0
/* from Opcodes/arrays.c */
static inline void tabensure(CSOUND *csound, ARRAYDAT *p, int size) {
    if (p->data==NULL || p->dimensions == 0 ||
        (p->dimensions==1 && p->sizes[0] < size)) {
      size_t ss;
      if (p->data == NULL) {
        CS_VARIABLE* var = p->arrayType->createVariable(csound, NULL);
        p->arrayMemberSize = var->memBlockSize;
      }
      ss = p->arrayMemberSize*size;
      if (p->data==NULL) {
        p->data = (MYFLT*)csound->Calloc(csound, ss);
        p->allocated = ss;
      }
      else if (ss > p->allocated) {
        p->data = (MYFLT*) csound->ReAlloc(csound, p->data, ss);
        p->allocated = ss;
      }
      if (p->dimensions==0) {
        p->dimensions = 1;
        p->sizes = (int32_t*)csound->Malloc(csound, sizeof(int32_t));
      }
    }
    p->sizes[0] = size;
}
#endif

static int directory(CSOUND *csound, DIR_STRUCT *p) {
  int inArgCount = p->INOCOUNT;
  char *extension, *file;
  std::vector<std::string> fileNames;

  if (inArgCount == 0)
    return csound->InitError(
        csound, "%s", Str("Error: you must pass a directory as a string."));

  if (inArgCount == 1) {
    fileNames = searchDir(csound, p->directoryName->data, (char *)"");
  }

  else if (inArgCount == 2) {
    CS_TYPE *argType = csound->GetTypeForArg(p->extension);
    if (strcmp("S", argType->varTypeName) == 0) {
      extension = csound->Strdup(csound, ((STRINGDAT *)p->extension)->data);
      fileNames = searchDir(csound, p->directoryName->data, extension);
    } else
      return csound->InitError(csound,
                               "%s", Str("Error: second parameter to directory"
                                   " must be a string"));
  }

  int numberOfFiles = fileNames.size();
  tabinit(csound, p->outArr, numberOfFiles);
  STRINGDAT *strings = (STRINGDAT *)p->outArr->data;

  for (int i = 0; i < numberOfFiles; i++) {
    file = &fileNames[i][0u];
    strings[i].size = strlen(file) + 1;
    strings[i].data = csound->Strdup(csound, file);
  }

  fileNames.clear();

  return OK;
}

//-----------------------------------------------------------------
//      load samples into function tables
//-----------------------------------------------------------------
std::vector<std::string> searchDir(CSOUND *csound, char *directory,
                                   char *extension) {
  std::vector<std::string> fileNames;
  if (directory) {
    DIR *dir = opendir(directory);
    std::string fileExtension(extension);
    int noOfFiles = 0;

    // check for valid path first
    if (dir) {
      struct dirent *ent;
      while ((ent = readdir(dir)) != NULL) {
        std::ostringstream fullFileName;

        std::string fname = ent->d_name;
        size_t lastPos = fname.find_last_of(".");
        if (fname.length() > 0 && (fileExtension.empty() ||
            (lastPos != std::string::npos &&
            fname.substr(lastPos) == fileExtension))) {
          if (strlen(directory) > 0) {
#if defined(WIN32)
            fullFileName << directory << "\\" << ent->d_name;
#else
            fullFileName << directory << "/" << ent->d_name;
#endif
          } else
            fullFileName << ent->d_name;

          noOfFiles++;
          fileNames.push_back(fullFileName.str());
        }
      }

      // Sort names
      std::sort(fileNames.begin(), fileNames.end());
    } else {
      csound->Message(csound, Str("Cannot find directory. "
                                  "Error opening directory: %s\n"),
                      directory);
    }
    closedir(dir);
  }

  return fileNames;
}

extern "C" {

PUBLIC int csoundModuleInit_ftsamplebank(CSOUND *csound) {

  int status = csound->AppendOpcode(
      csound, (char *)"ftsamplebank.k", sizeof(kftsamplebank), 0, 3,
      (char *)"k", (char *)"Skkkkk",
      (int (*)(CSOUND *, void *))kftsamplebank::init_,
      (int (*)(CSOUND *, void *))kftsamplebank::kontrol_,
      (int (*)(CSOUND *, void *))0);

  status |= csound->AppendOpcode(
      csound, (char *)"ftsamplebank.i", sizeof(iftsamplebank), 0, 1,
      (char *)"i", (char *)"Siiii",
      (int (*)(CSOUND *, void *))iftsamplebank::init_,
      (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0);

  /*  status |= csound->AppendOpcode(csound,
      (char*)"ftsamplebank",
      0xffff,
      0,
      0,
      0,
      0,
      0,
      0,
      0); */

  status |= csound->AppendOpcode(
      csound, (char *)"directory", sizeof(DIR_STRUCT), 0, 1, (char *)"S[]",
      (char *)"SN", (int (*)(CSOUND *, void *))directory,
      (int (*)(CSOUND *, void *))0, (int (*)(CSOUND *, void *))0);
  return status;
}

#ifndef INIT_STATIC_MODULES
PUBLIC int csoundModuleCreate(CSOUND *csound) {
  IGN(csound);
  return 0;
}

PUBLIC int csoundModuleInit(CSOUND *csound) {
  return csoundModuleInit_ftsamplebank(csound);
}

PUBLIC int csoundModuleDestroy(CSOUND *csound) {
  IGN(csound);
  return 0;
}
#endif
}
<|endoftext|>