__normal_call void_type push_root (
		real_type *_pmin,
		real_type *_pmax
		)
	{
    /*---------------------------- de-alloc. existing */
		this->_nset.clear() ;
		this->_tset.clear() ;

    /*---------------------------- scale initial tria */
        real_type static constexpr _scal = 
            (real_type)+tria_pred::_dims ;

        real_type _pdel[tria_pred::_dims];
        for (auto _idim = tria_pred::_dims + 0 ; 
                  _idim-- != + 0 ; )
        {
            _pdel[_idim] = _pmax[_idim] -
                           _pmin[_idim] ;
        }

    /*---------------------------- push tria indexing */
		iptr_type _itri = _get_tria() ;
        for (auto _inod = tria_pred::_dims + 1 ; 
                  _inod-- != + 0 ; )
        {
            tria(_itri)->node(_inod) = _inod;
            
            tria(_itri)->fpos(_inod) = -1 ;
            
			tria(_itri)->next(_inod) =
                __doflip(this->null_flag());
        }

    /*------------------------- push node coordinates */
        for (auto _inod = tria_pred::_dims + 1 ; 
                  _inod-- != + 0 ; )
        {
	    iptr_type _jnod = _get_node() ;
	    for (auto _idim = tria_pred::_dims + 0 ; 
	              _idim-- != + 0 ; )
	    {
	        if (_idim != _jnod - 1 )
		        node(_jnod)->
		        pval(_idim) = _pmin [_idim];
	        else
		        node(_jnod)->
		        pval(_idim) = _pmin [_idim]+ 
		       _pdel[_idim] * _scal;
	    }
	    node(_jnod)->next() = _itri;
        }
	}
	__inline_call void_type find_pair (
		iptr_type  _ipos,
		iptr_type &_jpos,
		iptr_type  _ifac,
		iptr_type &_jfac,
		iptr_type &_flag
		) const
	{
	/*---------------- unwind face adjacency pointers */
		_jfac = __unflip(
			tria(_ipos)->fpos(_ifac)) ;
		
		_jpos = __unflip(
			tria(_ipos)->next(_ifac)) ;
		
		_flag = __isflip(
			tria(_ipos)->next(_ifac)) 
			  ? -1 : +1 ;
	}  
	__inline_call void_type push_pair (
	    iptr_type  _itri,
	    iptr_type  _jtri,
	    iptr_type  _ifac,
	    iptr_type  _jfac,
	    iptr_type  _flag
	    )
    {
    /*---------------- encode face adjacency pointers */
        if (_itri != this->null_flag())
		{
		    if (_flag >= +0)
		tria(_itri)->
		    next(_ifac) = _jtri ;
		    else
		tria(_itri)->
		    next(_ifac)=__doflip(_jtri) ;
		
		tria(_itri)->
	    fpos(_ifac) = (char_type)_jfac;
		}
		
		if (_jtri != this->null_flag())
		{
		    if (_flag >= +0)
		tria(_jtri)->
		    next(_jfac) = _itri ;
		    else
		tria(_jtri)->
		    next(_jfac)=__doflip(_itri) ;
		
		tria(_jtri)->
		fpos(_jfac) = (char_type)_ifac;
		}   
    } 
Esempio n. 4
0
    Py::Object triangulate(const Py::Tuple& args)
    {
        PyObject *pcObj;
        double searchRadius;
        double mu=2.5;
        if (!PyArg_ParseTuple(args.ptr(), "O!d|d", &(Points::PointsPy::Type), &pcObj, &searchRadius, &mu))
            throw Py::Exception();

        Points::PointsPy* pPoints = static_cast<Points::PointsPy*>(pcObj);
        Points::PointKernel* points = pPoints->getPointKernelPtr();
        
        Mesh::MeshObject* mesh = new Mesh::MeshObject();
        SurfaceTriangulation tria(*points, *mesh);
        tria.perform(searchRadius, mu);

        return Py::asObject(new Mesh::MeshPy(mesh));
    }
	__inline_call iptr_type _get_tria (
		)
	{
		iptr_type _ipos = -1;
		if (this->_ftri.count() != +0 )
		{
    /*------------------------ recycle from free list */
			this->
		   _ftri._pop_tail(_ipos) ;
		}
		else
		{
    /*------------------------ alloc. from underlying */
			_ipos = (iptr_type)
                this->_tset.count() ;
            this->_tset.push_tail() ;
		}

		tria(_ipos)->mark() = +0 ;

		return ( _ipos ) ;
	}
    __normal_call void_type roll_back (
        list_type &_tnew,
        list_type &_told
        )
    {
        iptr_type _npos ;
        iptr_type _fpos ;
        for (auto _tpos  = _tnew.head();
                  _tpos != _tnew.tend();
                ++_tpos )
        {
        for (_npos = tria_pred::_dims+1; 
             _npos-- != +0 ; )
        {
            node(tria(*_tpos )
               ->node( _npos))
               ->next() = null_flag();
        }
        }
        
        for (auto _tpos  = _told.head();
                  _tpos != _told.tend();
                ++_tpos )
        {
        for (_npos = tria_pred::_dims+1; 
             _npos-- != +0 ; )
        {
            node(tria(*_tpos )
               ->node( _npos))
               ->next() = *_tpos ;
        }

        for (_fpos = tria_pred::_dims+1; 
             _fpos-- != +0 ; )
        {
            iptr_type  _tadj;
            iptr_type  _fadj;
            iptr_type  _flag;
            find_pair(*_tpos, _tadj , 
                _fpos, _fadj, _flag )  ;

            push_pair(*_tpos, _tadj , 
                       _fpos, _fadj , 
                       _flag) ;
        }
        }

        for (auto _tpos  = _tnew.head();
                  _tpos != _tnew.tend();
                ++_tpos )
        {
        for (_npos = tria_pred::_dims+1; 
             _npos-- != +0 ; )
        {
            if (node(tria(*_tpos )
                   ->node( _npos)) 
                   ->mark()>= +0 )
            if (node(tria(*_tpos )
                   ->node( _npos))
                   ->next() == null_flag())
            {
           _put_node(tria(*_tpos )
                   ->node( _npos)) ;
            }
        }
        }
        
        for (auto _tpos  = _tnew.head();
                  _tpos != _tnew.tend();
                ++_tpos )
        {
            _put_tria(*_tpos) ;
        }
    }
	__normal_call bool_type push_node (
		real_type *_ppos,
		iptr_type &_node,
		iptr_type  _hint  = null_flag() ,
	    list_type *_tnew  = nullptr   ,
        list_type *_told  = nullptr   ,
        list_type *_circ  = nullptr
		)
	{
        this->_work.clear ();

	/*--------------------------- _find enclosing element */
		iptr_type _elem = -1;
		if (walk_mesh_node(_ppos, _elem, _hint))
		{

	/*--------------------------- push new node onto list */
		_node = _get_node() ;
        for (auto _idim = tria_pred::_dims + 0 ; 
                  _idim-- != +0 ; )
        {
        node(_node)->pval(_idim) = _ppos[_idim];
        }	

    /*--------------------------- grab enclosing indexing */
        iptr_type _tnod[ +1 + tria_pred::_dims];
        for (auto _inod = tria_pred::_dims + 1 ; 
                  _inod-- != +0 ; )
        {
        _tnod[_inod] = tria(_elem)->node(_inod);
        }

    /*--------------------------- test for node duplicate */
        real_type _dist  = 
            std::numeric_limits
                <real_type>::infinity() ;
                
        for (auto _inod = tria_pred::_dims + 1 ; 
                  _inod-- != +0 ; )
        {
        _dist = std::min(_dist,
            tria_pred::lensqr_kd(_ppos,
                &node(_tnod[_inod])->pval(+0)));
        }

        if (_dist == (real_type)0.)
        {
            _put_node(_node) ;
        /*----------------------- bail-out on duplicates! */
            return ( false ) ;
        }

    /*-------------------- retriangulate enclosing cavity */
		typename tria_pred::
		template circ_pred<
            self_type> _pred( _ppos) ;
		
		if (_circ == nullptr)
        walk_tria_list(_elem, +1   , 
                       _pred, _work) ;
        else
        _work.push_tail(_circ->head(), 
                        _circ->tend()
                       ) ;
            
        star_tria_void(_work, _node, 
                   +1, _tnew, _told) ;

    /*-------------------- delaunay topology is recovered */
        return (  true ) ;
		}
		
		return ( false ) ;
	}