diff --git a/NifExport/NifExport_VC80.vcproj b/NifExport/NifExport_VC80.vcproj index b128f28abc3df8ecde4bdda6ac78165a12393e3c..feda5c82534e8cca2aad0cf732653b53a1de33e5 100644 --- a/NifExport/NifExport_VC80.vcproj +++ b/NifExport/NifExport_VC80.vcproj @@ -1000,23 +1000,27 @@ Name="TriStripper" > <File - RelativePath="TriStripper\cache_simulator.h" + RelativePath=".\TriStripper\detail\cache_simulator.h" > </File> <File - RelativePath="TriStripper\graph_array.h" + RelativePath=".\TriStripper\detail\connectivity_graph.h" > </File> <File - RelativePath="TriStripper\heap_array.h" + RelativePath=".\TriStripper\detail\graph_array.h" > </File> <File - RelativePath=".\TriStripper\public_types.h" + RelativePath=".\TriStripper\detail\heap_array.h" > </File> <File - RelativePath="TriStripper\tri_stripper.h" + RelativePath=".\TriStripper\detail\policy.h" + > + </File> + <File + RelativePath=".\TriStripper\detail\types.h" > </File> </Filter> diff --git a/NifExport/TriStripper/cache_simulator.h b/NifExport/TriStripper/cache_simulator.h deleted file mode 100755 index edad27da2a52f84212b7a3cc6f2e866bc6899992..0000000000000000000000000000000000000000 --- a/NifExport/TriStripper/cache_simulator.h +++ /dev/null @@ -1,92 +0,0 @@ - -#pragma once - - - -// namespace triangle_stripper -namespace triangle_stripper { - - - - -// FIFO Cache simulator -class cache_simulator -{ -public: - - typedef unsigned int index; - - cache_simulator(); - - void clear(); - void resize(const size_t Size); - void reset(); - size_t size() const; - - void push(const index i, const bool CountCacheHit = false); - - void ResetHitCount(); - size_t HitCount() const; - -protected: - typedef std::deque<index> indices_deque; - - indices_deque m_Cache; - size_t m_NbHits; -}; - - - - -inline cache_simulator::cache_simulator() : m_NbHits(0) { } - - -inline void cache_simulator::clear() { - m_Cache.clear(); -} - - -inline void cache_simulator::resize(const size_t Size) { - m_Cache.resize(Size, static_cast<index>(-1)); -} - - -inline void cache_simulator::reset() { - std::fill(m_Cache.begin(), m_Cache.end(), static_cast<index>(-1)); - ResetHitCount(); -} - - -inline size_t cache_simulator::size() const { - return m_Cache.size(); -} - - -inline void cache_simulator::push(const index i, const bool CountCacheHit) { - - // Should we count the cache hits? - if (CountCacheHit) { - if (std::find(m_Cache.begin(), m_Cache.end(), i) != m_Cache.end()) - ++m_NbHits; - } - - // Manage the indices cache as a FIFO structure - m_Cache.push_front(i); - m_Cache.pop_back(); -} - - -inline void cache_simulator::ResetHitCount() { - m_NbHits = 0; -} - - -inline size_t cache_simulator::HitCount() const { - return m_NbHits; -} - - - -} // namespace triangle_stripper - - diff --git a/NifExport/TriStripper/detail/cache_simulator.h b/NifExport/TriStripper/detail/cache_simulator.h new file mode 100644 index 0000000000000000000000000000000000000000..1281d5104c23c00d4b0cd9610460b9e79ef0bf21 --- /dev/null +++ b/NifExport/TriStripper/detail/cache_simulator.h @@ -0,0 +1,154 @@ +// +// Copyright (C) 2004 Tanguy Fautré. +// For conditions of distribution and use, +// see copyright notice in tri_stripper.h +// +////////////////////////////////////////////////////////////////////// +// SVN: $Id: cache_simulator.h 86 2005-06-08 17:47:27Z gpsnoopy $ +////////////////////////////////////////////////////////////////////// + +#ifndef TRI_STRIPPER_HEADER_GUARD_CACHE_SIMULATOR_H +#define TRI_STRIPPER_HEADER_GUARD_CACHE_SIMULATOR_H + +#include <algorithm> +#include <limits> +#include <deque> + + + + +namespace triangle_stripper { + + namespace detail { + + + + +class cache_simulator +{ +public: + cache_simulator(); + + void clear(); + void resize(size_t Size); + void reset(); + void push_cache_hits(bool Enabled = true); + size_t size() const; + + void push(index i, bool CountCacheHit = false); + void merge(const cache_simulator & Backward, size_t PossibleOverlap); + + void reset_hitcount(); + size_t hitcount() const; + +protected: + typedef std::deque<index> indices_deque; + + indices_deque m_Cache; + size_t m_NbHits; + bool m_PushHits; +}; + + + + + +////////////////////////////////////////////////////////////////////////// +// cache_simulator inline functions +////////////////////////////////////////////////////////////////////////// + +inline cache_simulator::cache_simulator() + : m_NbHits(0), + m_PushHits(true) +{ + +} + + +inline void cache_simulator::clear() +{ + reset_hitcount(); + m_Cache.clear(); +} + + +inline void cache_simulator::resize(const size_t Size) +{ + m_Cache.resize(Size, std::numeric_limits<index>::max()); +} + + +inline void cache_simulator::reset() +{ + std::fill(m_Cache.begin(), m_Cache.end(), std::numeric_limits<index>::max()); + reset_hitcount(); +} + + +inline void cache_simulator::push_cache_hits(bool Enabled) +{ + m_PushHits = Enabled; +} + + +inline size_t cache_simulator::size() const +{ + return m_Cache.size(); +} + + +inline void cache_simulator::push(const index i, const bool CountCacheHit) +{ + if (CountCacheHit || m_PushHits) { + + if (std::find(m_Cache.begin(), m_Cache.end(), i) != m_Cache.end()) { + + // Should we count the cache hits? + if (CountCacheHit) + ++m_NbHits; + + // Should we not push the index into the cache if it's a cache hit? + if (! m_PushHits) + return; + } + } + + // Manage the indices cache as a FIFO structure + m_Cache.push_front(i); + m_Cache.pop_back(); +} + + +inline void cache_simulator::merge(const cache_simulator & Backward, const size_t PossibleOverlap) +{ + const size_t Overlap = std::min(PossibleOverlap, size()); + + for (size_t i = 0; i < Overlap; ++i) + push(Backward.m_Cache[i], true); + + m_NbHits += Backward.m_NbHits; +} + + +inline void cache_simulator::reset_hitcount() +{ + m_NbHits = 0; +} + + +inline size_t cache_simulator::hitcount() const +{ + return m_NbHits; +} + + + + + } // namespace detail + +} // namespace triangle_stripper + + + + +#endif // TRI_STRIPPER_HEADER_GUARD_CACHE_SIMULATOR_H diff --git a/NifExport/TriStripper/detail/connectivity_graph.h b/NifExport/TriStripper/detail/connectivity_graph.h new file mode 100644 index 0000000000000000000000000000000000000000..e5cbc4638a97466c8c54ab3372a207828717118d --- /dev/null +++ b/NifExport/TriStripper/detail/connectivity_graph.h @@ -0,0 +1,36 @@ +// +// Copyright (C) 2004 Tanguy Fautré. +// For conditions of distribution and use, +// see copyright notice in tri_stripper.h +// +////////////////////////////////////////////////////////////////////// +// SVN: $Id: connectivity_graph.h 86 2005-06-08 17:47:27Z gpsnoopy $ +////////////////////////////////////////////////////////////////////// + +#ifndef TRI_STRIPPER_HEADER_GUARD_CONNECTIVITY_GRAPH_H +#define TRI_STRIPPER_HEADER_GUARD_CONNECTIVITY_GRAPH_H + +#include "public_types.h" + +#include "graph_array.h" +#include "types.h" + + + + +namespace triangle_stripper +{ + + namespace detail + { + + void make_connectivity_graph(graph_array<triangle> & Triangles, const indices & Indices); + + } + +} + + + + +#endif // TRI_STRIPPER_HEADER_GUARD_CONNECTIVITY_GRAPH_H diff --git a/NifExport/TriStripper/detail/graph_array.h b/NifExport/TriStripper/detail/graph_array.h new file mode 100644 index 0000000000000000000000000000000000000000..764998ee938d62aff10a0d45381efebebb1965a6 --- /dev/null +++ b/NifExport/TriStripper/detail/graph_array.h @@ -0,0 +1,460 @@ +// +// Copyright (C) 2004 Tanguy Fautré. +// For conditions of distribution and use, +// see copyright notice in tri_stripper.h +// +////////////////////////////////////////////////////////////////////// +// SVN: $Id: graph_array.h 86 2005-06-08 17:47:27Z gpsnoopy $ +////////////////////////////////////////////////////////////////////// + +#ifndef TRI_STRIPPER_HEADER_GUARD_GRAPH_ARRAY_H +#define TRI_STRIPPER_HEADER_GUARD_GRAPH_ARRAY_H + +#include <cassert> +#include <algorithm> +#include <functional> +#include <limits> +#include <vector> + + + + +namespace triangle_stripper { + + namespace detail { + + + + +// graph_array main class +template <class nodetype> +class graph_array +{ +public: + + class arc; + class node; + + // New types + typedef size_t nodeid; + typedef nodetype value_type; + typedef std::vector<node> node_vector; + typedef typename node_vector::iterator node_iterator; + typedef typename node_vector::const_iterator const_node_iterator; + typedef typename node_vector::reverse_iterator node_reverse_iterator; + typedef typename node_vector::const_reverse_iterator const_node_reverse_iterator; + + typedef graph_array<nodetype> graph_type; + + + // graph_array::arc class + class arc + { + public: + node_iterator terminal() const; + + protected: + friend class graph_array<nodetype>; + + arc(node_iterator Terminal); + + node_iterator m_Terminal; + }; + + + // New types + typedef std::vector<arc> arc_list; + typedef typename arc_list::iterator out_arc_iterator; + typedef typename arc_list::const_iterator const_out_arc_iterator; + + + // graph_array::node class + class node + { + public: + void mark(); + void unmark(); + bool marked() const; + + bool out_empty() const; + size_t out_size() const; + + out_arc_iterator out_begin(); + out_arc_iterator out_end(); + const_out_arc_iterator out_begin() const; + const_out_arc_iterator out_end() const; + + value_type & operator * (); + value_type * operator -> (); + const value_type & operator * () const; + const value_type * operator -> () const; + + value_type & operator = (const value_type & Elem); + + protected: + friend class graph_array<nodetype>; + friend class std::vector<node>; + + node(arc_list & Arcs); + + arc_list & m_Arcs; + size_t m_Begin; + size_t m_End; + + value_type m_Elem; + bool m_Marker; + }; + + + graph_array(); + explicit graph_array(size_t NbNodes); + + // Node related member functions + bool empty() const; + size_t size() const; + + node & operator [] (nodeid i); + const node & operator [] (nodeid i) const; + + node_iterator begin(); + node_iterator end(); + const_node_iterator begin() const; + const_node_iterator end() const; + + node_reverse_iterator rbegin(); + node_reverse_iterator rend(); + const_node_reverse_iterator rbegin() const; + const_node_reverse_iterator rend() const; + + // Arc related member functions + out_arc_iterator insert_arc(nodeid Initial, nodeid Terminal); + out_arc_iterator insert_arc(node_iterator Initial, node_iterator Terminal); + + // Optimized (overloaded) functions + void swap(graph_type & Right); + friend void swap(graph_type & Left, graph_type & Right) { Left.swap(Right); } + +protected: + graph_array(const graph_type &); + graph_type & operator = (const graph_type &); + + node_vector m_Nodes; + arc_list m_Arcs; +}; + + + +// Additional "low level", graph related, functions +template <class nodetype> +void unmark_nodes(graph_array<nodetype> & G); + + + + + +////////////////////////////////////////////////////////////////////////// +// graph_array::arc inline functions +////////////////////////////////////////////////////////////////////////// + +template <class N> +inline graph_array<N>::arc::arc(node_iterator Terminal) + : m_Terminal(Terminal) { } + + +template <class N> +inline typename graph_array<N>::node_iterator graph_array<N>::arc::terminal() const +{ + return m_Terminal; +} + + + +////////////////////////////////////////////////////////////////////////// +// graph_array::node inline functions +////////////////////////////////////////////////////////////////////////// + +template <class N> +inline graph_array<N>::node::node(arc_list & Arcs) + : m_Arcs(Arcs), + m_Begin(std::numeric_limits<size_t>::max()), + m_End(std::numeric_limits<size_t>::max()), + m_Marker(false) +{ + +} + + +template <class N> +inline void graph_array<N>::node::mark() +{ + m_Marker = true; +} + + +template <class N> +inline void graph_array<N>::node::unmark() +{ + m_Marker = false; +} + + +template <class N> +inline bool graph_array<N>::node::marked() const +{ + return m_Marker; +} + + +template <class N> +inline bool graph_array<N>::node::out_empty() const +{ + return (m_Begin == m_End); +} + + +template <class N> +inline size_t graph_array<N>::node::out_size() const +{ + return (m_End - m_Begin); +} + + +template <class N> +inline typename graph_array<N>::out_arc_iterator graph_array<N>::node::out_begin() +{ + return (m_Arcs.begin() + m_Begin); +} + + +template <class N> +inline typename graph_array<N>::out_arc_iterator graph_array<N>::node::out_end() +{ + return (m_Arcs.begin() + m_End); +} + + +template <class N> +inline typename graph_array<N>::const_out_arc_iterator graph_array<N>::node::out_begin() const +{ + return (m_Arcs.begin() + m_Begin); +} + + +template <class N> +inline typename graph_array<N>::const_out_arc_iterator graph_array<N>::node::out_end() const +{ + return (m_Arcs.begin() + m_End); +} + + +template <class N> +inline N & graph_array<N>::node::operator * () +{ + return m_Elem; +} + + +template <class N> +inline N * graph_array<N>::node::operator -> () +{ + return &m_Elem; +} + + +template <class N> +inline const N & graph_array<N>::node::operator * () const +{ + return m_Elem; +} + + +template <class N> +inline const N * graph_array<N>::node::operator -> () const +{ + return &m_Elem; +} + + +template <class N> +inline N & graph_array<N>::node::operator = (const N & Elem) +{ + return (m_Elem = Elem); +} + + + +////////////////////////////////////////////////////////////////////////// +// graph_array inline functions +////////////////////////////////////////////////////////////////////////// + +template <class N> +inline graph_array<N>::graph_array() { } + + +template <class N> +inline graph_array<N>::graph_array(const size_t NbNodes) + : m_Nodes(NbNodes, node(m_Arcs)) +{ + // optimisation: we consider that, averagely, a triangle may have at least 2 neighbours + // otherwise we are just wasting a bit of memory, but not that much + m_Arcs.reserve(NbNodes * 2); +} + + +template <class N> +inline bool graph_array<N>::empty() const +{ + return m_Nodes.empty(); +} + + +template <class N> +inline size_t graph_array<N>::size() const +{ + return m_Nodes.size(); +} + + +template <class N> +inline typename graph_array<N>::node & graph_array<N>::operator [] (const nodeid i) +{ + assert(i < size()); + + return m_Nodes[i]; +} + + +template <class N> +inline const typename graph_array<N>::node & graph_array<N>::operator [] (const nodeid i) const +{ + assert(i < size()); + + return m_Nodes[i]; +} + + +template <class N> +inline typename graph_array<N>::node_iterator graph_array<N>::begin() +{ + return m_Nodes.begin(); +} + + +template <class N> +inline typename graph_array<N>::node_iterator graph_array<N>::end() +{ + return m_Nodes.end(); +} + + +template <class N> +inline typename graph_array<N>::const_node_iterator graph_array<N>::begin() const +{ + return m_Nodes.begin(); +} + + +template <class N> +inline typename graph_array<N>::const_node_iterator graph_array<N>::end() const +{ + return m_Nodes.end(); +} + + +template <class N> +inline typename graph_array<N>::node_reverse_iterator graph_array<N>::rbegin() +{ + return m_Nodes.rbegin(); +} + + +template <class N> +inline typename graph_array<N>::node_reverse_iterator graph_array<N>::rend() +{ + return m_Nodes.rend(); +} + + +template <class N> +inline typename graph_array<N>::const_node_reverse_iterator graph_array<N>::rbegin() const +{ + return m_Nodes.rbegin(); +} + + +template <class N> +inline typename graph_array<N>::const_node_reverse_iterator graph_array<N>::rend() const +{ + return m_Nodes.rend(); +} + + +template <class N> +inline typename graph_array<N>::out_arc_iterator graph_array<N>::insert_arc(const nodeid Initial, const nodeid Terminal) +{ + assert(Initial < size()); + assert(Terminal < size()); + + return insert_arc(m_Nodes.begin() + Initial, m_Nodes.begin() + Terminal); +} + + +template <class N> +inline typename graph_array<N>::out_arc_iterator graph_array<N>::insert_arc(const node_iterator Initial, const node_iterator Terminal) +{ + assert((Initial >= begin()) && (Initial < end())); + assert((Terminal >= begin()) && (Terminal < end())); + + node & Node = * Initial; + + if (Node.out_empty()) { + + Node.m_Begin = m_Arcs.size(); + Node.m_End = m_Arcs.size() + 1; + + } else { + + // we optimise here for make_connectivity_graph() + // we know all the arcs for a given node are successively and sequentially added + assert(Node.m_End == m_Arcs.size()); + + ++(Node.m_End); + } + + m_Arcs.push_back(arc(Terminal)); + + out_arc_iterator it = m_Arcs.end(); + return (--it); +} + + +template <class N> +inline void graph_array<N>::swap(graph_type & Right) +{ + std::swap(m_Nodes, Right.m_Nodes); + std::swap(m_Arcs, Right.m_Arcs); +} + + + +////////////////////////////////////////////////////////////////////////// +// additional functions +////////////////////////////////////////////////////////////////////////// + +template <class N> +inline void unmark_nodes(graph_array<N> & G) +{ + std::for_each(G.begin(), G.end(), std::mem_fun_ref(&graph_array<N>::node::unmark)); +} + + + + + } // namespace detail + +} // namespace triangle_stripper + + + + +#endif // TRI_STRIPPER_HEADER_GUARD_GRAPH_ARRAY_H diff --git a/NifExport/TriStripper/detail/heap_array.h b/NifExport/TriStripper/detail/heap_array.h new file mode 100644 index 0000000000000000000000000000000000000000..598d40bfd64af93faccc2d8ffaa3a340ade13236 --- /dev/null +++ b/NifExport/TriStripper/detail/heap_array.h @@ -0,0 +1,297 @@ +// +// Copyright (C) 2004 Tanguy Fautré. +// For conditions of distribution and use, +// see copyright notice in tri_stripper.h +// +////////////////////////////////////////////////////////////////////// +// SVN: $Id: heap_array.h 86 2005-06-08 17:47:27Z gpsnoopy $ +////////////////////////////////////////////////////////////////////// + +#ifndef TRI_STRIPPER_HEADER_GUARD_HEAP_ARRAY_H +#define TRI_STRIPPER_HEADER_GUARD_HEAP_ARRAY_H + +#include <vector> + + + + +namespace triangle_stripper { + + namespace detail { + + + + +// mutable heap +// can be interfaced pretty muck like an array +template <class T, class CmpT = std::less<T> > +class heap_array +{ +public: + + // Pre = PreCondition, Post = PostCondition + + heap_array() : m_Locked(false) { } // Post: ((size() == 0) && ! locked()) + + void clear(); // Post: ((size() == 0) && ! locked()) + + void reserve(size_t Size); + size_t size() const; + + bool empty() const; + bool locked() const; + bool removed(size_t i) const; // Pre: (valid(i)) + bool valid(size_t i) const; + + size_t position(size_t i) const; // Pre: (valid(i)) + + const T & top() const; // Pre: (! empty()) + const T & peek(size_t i) const; // Pre: (! removed(i)) + const T & operator [] (size_t i) const; // Pre: (! removed(i)) + + void lock(); // Pre: (! locked()) Post: (locked()) + size_t push(const T & Elem); // Pre: (! locked()) + + void pop(); // Pre: (locked() && ! empty()) + void erase(size_t i); // Pre: (locked() && ! removed(i)) + void update(size_t i, const T & Elem); // Pre: (locked() && ! removed(i)) + +protected: + + heap_array(const heap_array &); + heap_array & operator = (const heap_array &); + + class linker + { + public: + linker(const T & Elem, size_t i) + : m_Elem(Elem), m_Index(i) { } + + T m_Elem; + size_t m_Index; + }; + + typedef std::vector<linker> linked_heap; + typedef std::vector<size_t> finder; + + void Adjust(size_t i); + void Swap(size_t a, size_t b); + bool Less(const linker & a, const linker & b) const; + + linked_heap m_Heap; + finder m_Finder; + CmpT m_Compare; + bool m_Locked; +}; + + + + + +////////////////////////////////////////////////////////////////////////// +// heap_indexed inline functions +////////////////////////////////////////////////////////////////////////// + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::clear() +{ + m_Heap.clear(); + m_Finder.clear(); + m_Locked = false; +} + + +template <class T, class CmpT> +inline bool heap_array<T, CmpT>::empty() const +{ + return m_Heap.empty(); +} + + +template <class T, class CmpT> +inline bool heap_array<T, CmpT>::locked() const +{ + return m_Locked; +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::reserve(const size_t Size) +{ + m_Heap.reserve(Size); + m_Finder.reserve(Size); +} + + +template <class T, class CmpT> +inline size_t heap_array<T, CmpT>::size() const +{ + return m_Heap.size(); +} + + +template <class T, class CmpT> +inline const T & heap_array<T, CmpT>::top() const +{ + assert(! empty()); + + return m_Heap.front().m_Elem; +} + + +template <class T, class CmpT> +inline const T & heap_array<T, CmpT>::peek(const size_t i) const +{ + assert(! removed(i)); + + return (m_Heap[m_Finder[i]].m_Elem); +} + + +template <class T, class CmpT> +inline const T & heap_array<T, CmpT>::operator [] (const size_t i) const +{ + return peek(i); +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::pop() +{ + assert(locked()); + assert(! empty()); + + Swap(0, size() - 1); + m_Heap.pop_back(); + + if (! empty()) + Adjust(0); +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::lock() +{ + assert(! locked()); + + m_Locked =true; +} + + +template <class T, class CmpT> +inline size_t heap_array<T, CmpT>::push(const T & Elem) +{ + assert(! locked()); + + const size_t Id = size(); + m_Finder.push_back(Id); + m_Heap.push_back(linker(Elem, Id)); + Adjust(Id); + + return Id; +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::erase(const size_t i) +{ + assert(locked()); + assert(! removed(i)); + + const size_t j = m_Finder[i]; + Swap(j, size() - 1); + m_Heap.pop_back(); + + if (j != size()) + Adjust(j); +} + + +template <class T, class CmpT> +inline bool heap_array<T, CmpT>::removed(const size_t i) const +{ + assert(valid(i)); + + return (m_Finder[i] >= m_Heap.size()); +} + + +template <class T, class CmpT> +inline bool heap_array<T, CmpT>::valid(const size_t i) const +{ + return (i < m_Finder.size()); +} + + +template <class T, class CmpT> +inline size_t heap_array<T, CmpT>::position(const size_t i) const +{ + assert(valid(i)); + + return (m_Heap[i].m_Index); +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::update(const size_t i, const T & Elem) +{ + assert(locked()); + assert(! removed(i)); + + const size_t j = m_Finder[i]; + m_Heap[j].m_Elem = Elem; + Adjust(j); +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::Adjust(size_t i) +{ + assert(i < m_Heap.size()); + + size_t j; + + // Check the upper part of the heap + for (j = i; (j > 0) && (Less(m_Heap[(j - 1) / 2], m_Heap[j])); j = ((j - 1) / 2)) + Swap(j, (j - 1) / 2); + + // Check the lower part of the heap + for (i = j; (j = 2 * i + 1) < size(); i = j) { + if ((j + 1 < size()) && (Less(m_Heap[j], m_Heap[j + 1]))) + ++j; + + if (Less(m_Heap[j], m_Heap[i])) + return; + + Swap(i, j); + } +} + + +template <class T, class CmpT> +inline void heap_array<T, CmpT>::Swap(const size_t a, const size_t b) +{ + std::swap(m_Heap[a], m_Heap[b]); + + m_Finder[(m_Heap[a].m_Index)] = a; + m_Finder[(m_Heap[b].m_Index)] = b; +} + + +template <class T, class CmpT> +inline bool heap_array<T, CmpT>::Less(const linker & a, const linker & b) const +{ + return m_Compare(a.m_Elem, b.m_Elem); +} + + + + + } // namespace detail + +} // namespace triangle_stripper + + + + +#endif // TRI_STRIPPER_HEADER_GUARD_HEAP_ARRAY_H diff --git a/NifExport/TriStripper/detail/policy.h b/NifExport/TriStripper/detail/policy.h new file mode 100644 index 0000000000000000000000000000000000000000..c1a7c0a71eaf9485c2d8ee7113309d8526a85cfc --- /dev/null +++ b/NifExport/TriStripper/detail/policy.h @@ -0,0 +1,66 @@ +// +// Copyright (C) 2004 Tanguy Fautré. +// For conditions of distribution and use, +// see copyright notice in tri_stripper.h +// +////////////////////////////////////////////////////////////////////// +// SVN: $Id: policy.h 86 2005-06-08 17:47:27Z gpsnoopy $ +////////////////////////////////////////////////////////////////////// + +#ifndef TRI_STRIPPER_HEADER_GUARD_POLICY_H +#define TRI_STRIPPER_HEADER_GUARD_POLICY_H + +#include "public_types.h" +#include "types.h" + + + + +namespace triangle_stripper { + + namespace detail { + + + + +class policy +{ +public: + policy(size_t MinStripSize, bool Cache); + + strip BestStrip() const; + void Challenge(strip Strip, size_t Degree, size_t CacheHits); + +private: + strip m_Strip; + size_t m_Degree; + size_t m_CacheHits; + + const size_t m_MinStripSize; + const bool m_Cache; +}; + + + + + +inline policy::policy(size_t MinStripSize, bool Cache) +: m_Degree(0), m_CacheHits(0), m_MinStripSize(MinStripSize), m_Cache(Cache) { } + + +inline strip policy::BestStrip() const +{ + return m_Strip; +} + + + + + } // namespace detail + +} // namespace triangle_stripper + + + + +#endif // TRI_STRIPPER_HEADER_GUARD_POLICY_H diff --git a/NifExport/TriStripper/detail/types.h b/NifExport/TriStripper/detail/types.h new file mode 100644 index 0000000000000000000000000000000000000000..5b0419f08ed683c204ae322a2fbc04e1030bb949 --- /dev/null +++ b/NifExport/TriStripper/detail/types.h @@ -0,0 +1,101 @@ +// +// Copyright (C) 2004 Tanguy Fautré. +// For conditions of distribution and use, +// see copyright notice in tri_stripper.h +// +////////////////////////////////////////////////////////////////////// +// SVN: $Id: types.h 86 2005-06-08 17:47:27Z gpsnoopy $ +////////////////////////////////////////////////////////////////////// + +#ifndef TRI_STRIPPER_HEADER_GUARD_TYPES_H +#define TRI_STRIPPER_HEADER_GUARD_TYPES_H + + + + +namespace triangle_stripper { + + namespace detail { + + + + +class triangle +{ +public: + triangle() { } + triangle(index A, index B, index C) + : m_A(A), m_B(B), m_C(C), m_StripID(0) { } + + void ResetStripID() { m_StripID = 0; } + void SetStripID(size_t StripID) { m_StripID = StripID; } + size_t StripID() const { return m_StripID; } + + index A() const { return m_A; } + index B() const { return m_B; } + index C() const { return m_C; } + +private: + index m_A; + index m_B; + index m_C; + + size_t m_StripID; +}; + + + +class triangle_edge +{ +public: + triangle_edge(index A, index B) + : m_A(A), m_B(B) { } + + index A() const { return m_A; } + index B() const { return m_B; } + + bool operator == (const triangle_edge & Right) const { + return ((A() == Right.A()) && (B() == Right.B())); + } + +private: + index m_A; + index m_B; +}; + + + +enum triangle_order { ABC, BCA, CAB }; + + + +class strip +{ +public: + strip() + : m_Start(0), m_Order(ABC), m_Size(0) { } + + strip(size_t Start, triangle_order Order, size_t Size) + : m_Start(Start), m_Order(Order), m_Size(Size) { } + + size_t Start() const { return m_Start; } + triangle_order Order() const { return m_Order; } + size_t Size() const { return m_Size; } + +private: + size_t m_Start; + triangle_order m_Order; + size_t m_Size; +}; + + + + + } // namespace detail + +} // namespace triangle_stripper + + + + +#endif // TRI_STRIPPER_HEADER_GUARD_TYPES_H diff --git a/NifExport/TriStripper/graph_array.h b/NifExport/TriStripper/graph_array.h deleted file mode 100755 index 0d85c687a41966a88a18ca05c42cac0ff52abb96..0000000000000000000000000000000000000000 --- a/NifExport/TriStripper/graph_array.h +++ /dev/null @@ -1,428 +0,0 @@ -// graph_array.h: interface for the graph_array class. -// -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2002 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@pandora.be -// -////////////////////////////////////////////////////////////////////// -// -// Semi-dynamic directed graph -// *************************** -// -// Current version: 3.00 BETA 5 (17/04/2003) -// -// Comment: graph_array is equivalent to an array of nodes linked by -// arcs. -// This means you can't change the size (the number of nodes) -// of the graph once you created it (setsize() will delete -// any previous nodes and arcs). -// But you can add or remove arcs. -// -// History: - 3.00 BETA 6 (22/09/2003) - Improved std C++ compliance -// - 3.00 BETA 5 (17/04/2003) - Fixed template graph related functions -// - 3.00 BETA 4 (11/12/2002) - Fixed a typo in erase_arcs -// - 3.00 BETA 3 (04/12/2002) - Added empty() -// - Changed some parameters from copy to reference -// - Fixed a bug with erase_arc -// - Un-inlined external functions -// - Added "insert_arc" which is equivalent to "insert" -// - 3.00 BETA 2 (16/11/2002) - Improved portability -// - 3.00 BETA 1 (27/08/2002) - First public release -// -////////////////////////////////////////////////////////////////////// - -#pragma once - - - -// namespace common_structures -namespace common_structures { - - - - -// graph_array main class -template <class nodetype, class arctype> -class graph_array -{ -public: - - class arc; - class node; - - // New types - typedef size_t nodeid; - typedef typename std::vector<node>::iterator node_iterator; - typedef typename std::vector<node>::const_iterator const_node_iterator; - typedef typename std::vector<node>::reverse_iterator node_reverse_iterator; - typedef typename std::vector<node>::const_reverse_iterator const_node_reverse_iterator; - - typedef graph_array<nodetype, arctype> _mytype; - - - // graph_array::arc class - class arc - { - public: - arc & mark() { m_Marker = true; return (* this); } - arc & unmark() { m_Marker = false; return (* this); } - bool marked() const { return m_Marker; } - - node_iterator initial() const { return m_Initial; } - node_iterator terminal() const { return m_Terminal; } - - arctype & operator * () { return m_Elem; } - arctype * operator -> () { return &m_Elem; } - const arctype & operator * () const { return m_Elem; } - const arctype * operator -> () const { return &m_Elem; } - - protected: - friend class graph_array<nodetype, arctype>; - - arc(const node_iterator & Initial, const node_iterator & Terminal) - : m_Initial(Initial), m_Terminal(Terminal), m_Marker(false) { } - - arc(const node_iterator & Initial, const node_iterator & Terminal, const arctype & Elem) - : m_Initial(Initial), m_Terminal(Terminal), m_Elem(Elem), m_Marker(false) { } - - node_iterator m_Initial; - node_iterator m_Terminal; - arctype m_Elem; - bool m_Marker; - }; - - - // New types - typedef typename std::list<arc>::iterator out_arc_iterator; - typedef typename std::list<arc>::const_iterator const_out_arc_iterator; - - - // graph_array::node class - class node - { - public: - node & mark() { m_Marker = true; return (* this); } - node & unmark() { m_Marker = false; return (* this); } - bool marked() const { return m_Marker; } - - bool out_empty() const { return m_OutArcs.empty(); } - size_t number_of_out_arcs() const { return m_OutArcs.size(); } - - out_arc_iterator out_begin() { return m_OutArcs.begin(); } - out_arc_iterator out_end() { return m_OutArcs.end(); } - const_out_arc_iterator out_begin() const { return m_OutArcs.begin(); } - const_out_arc_iterator out_end() const { return m_OutArcs.end(); } - - nodetype & operator * () { return m_Elem; } - nodetype * operator -> () { return &m_Elem; } - const nodetype & operator * () const { return m_Elem; } - const nodetype * operator -> () const { return &m_Elem; } - - nodetype & operator = (const nodetype & Elem) { return (m_Elem = Elem); } - - protected: - friend class graph_array<nodetype, arctype>; - friend class std::vector<node>; - - node() : m_Marker(false) { } - - std::list<arc> m_OutArcs; - nodetype m_Elem; - bool m_Marker; - }; - - - // Construction/Destruction - graph_array(); - explicit graph_array(const size_t NbNodes); - - // Node related member functions - void clear(); - bool empty() const; - void setsize(const size_t NbNodes); - size_t size() const; - - node & operator [] (const nodeid & i); - const node & operator [] (const nodeid & i) const; - - node_iterator begin(); - node_iterator end(); - const_node_iterator begin() const; - const_node_iterator end() const; - - node_reverse_iterator rbegin(); - node_reverse_iterator rend(); - const_node_reverse_iterator rbegin() const; - const_node_reverse_iterator rend() const; - - // Arc related member functions - size_t number_of_arcs() const; - - void erase_arcs(); - void erase_arcs(const node_iterator & Initial); - out_arc_iterator erase_arc(const out_arc_iterator & Pos); - - out_arc_iterator insert_arc(const nodeid & Initial, const nodeid & Terminal); - out_arc_iterator insert_arc(const nodeid & Initial, const nodeid & Terminal, const arctype & Elem); - out_arc_iterator insert_arc(const node_iterator & Initial, const node_iterator & Terminal); - out_arc_iterator insert_arc(const node_iterator & Initial, const node_iterator & Terminal, const arctype & Elem); - - // Another interface for insert_arc - out_arc_iterator insert(const nodeid & Initial, const nodeid & Terminal) { return insert_arc(Initial, Terminal); } - out_arc_iterator insert(const nodeid & Initial, const nodeid & Terminal, const arctype & Elem) { return insert_arc(Initial, Terminal, Elem); } - out_arc_iterator insert(const node_iterator & Initial, const node_iterator & Terminal) { return insert_arc(Initial, Terminal); } - out_arc_iterator insert(const node_iterator & Initial, const node_iterator & Terminal, const arctype & Elem) { return insert_arc(Initial, Terminal, Elem); } - - // Optimized (overloaded) functions - void swap(_mytype & Right); - friend void swap(_mytype & Left, _mytype & Right) { Left.swap(Right); } - -protected: - size_t m_NbArcs; - std::vector<node> m_Nodes; -}; - - - -// Additional "low level", graph related, functions -template <class nodetype, class arctype> -void unmark_nodes(graph_array<nodetype, arctype> & G); - -template <class graph_node> -void unmark_arcs_from_node(graph_node & N); - -template <class nodetype, class arctype> -void unmark_arcs(graph_array<nodetype, arctype> & G); - -class unmark_arc -{ -public: - template <class A> - void operator () (A & Arc) const { Arc.unmark(); } -}; - - - - -////////////////////////////////////////////////////////////////////////// -// graph_array Inline functions -////////////////////////////////////////////////////////////////////////// - -template <class nodetype, class arctype> -inline graph_array<nodetype, arctype>::graph_array() : m_NbArcs(0) { } - - -template <class nodetype, class arctype> -inline graph_array<nodetype, arctype>::graph_array(const size_t NbNodes) : m_NbArcs(0), m_Nodes(NbNodes) { } - - -template <class nodetype, class arctype> -inline void graph_array<nodetype, arctype>::clear() { - m_NbArcs = 0; - m_Nodes.clear(); -} - - - -template <class nodetype, class arctype> -inline bool graph_array<nodetype, arctype>::empty() const { - return m_Nodes.empty(); -} - - -template <class nodetype, class arctype> -inline size_t graph_array<nodetype, arctype>::size() const { - return m_Nodes.size(); -} - - -template <class nodetype, class arctype> -inline void graph_array<nodetype, arctype>::setsize(const size_t NbNodes) { - clear(); - m_Nodes.resize(NbNodes); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::node & graph_array<nodetype, arctype>::operator [] (const nodeid & i) { - // Debug check - assert(i < size()); - - return m_Nodes[i]; -} - - -template <class nodetype, class arctype> -inline const typename graph_array<nodetype, arctype>::node & graph_array<nodetype, arctype>::operator [] (const nodeid & i) const { - // Debug check - assert(i < size()); - - return m_Nodes[i]; -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::node_iterator graph_array<nodetype, arctype>::begin() { - return m_Nodes.begin(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::node_iterator graph_array<nodetype, arctype>::end() { - return m_Nodes.end(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::const_node_iterator graph_array<nodetype, arctype>::begin() const { - return m_Nodes.begin(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::const_node_iterator graph_array<nodetype, arctype>::end() const { - return m_Nodes.end(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::node_reverse_iterator graph_array<nodetype, arctype>::rbegin() { - return m_Nodes.rbegin(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::node_reverse_iterator graph_array<nodetype, arctype>::rend() { - return m_Nodes.rend(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::const_node_reverse_iterator graph_array<nodetype, arctype>::rbegin() const { - return m_Nodes.rbegin(); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::const_node_reverse_iterator graph_array<nodetype, arctype>::rend() const { - return m_Nodes.rend(); -} - - -template <class nodetype, class arctype> -inline size_t graph_array<nodetype, arctype>::number_of_arcs() const { - return m_NbArcs; -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::out_arc_iterator graph_array<nodetype, arctype>::insert_arc(const nodeid & Initial, const nodeid & Terminal) { - return (insert(begin() + Initial, begin() + Terminal)); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::out_arc_iterator graph_array<nodetype, arctype>::insert_arc(const nodeid & Initial, const nodeid & Terminal, const arctype & Elem) { - return (insert(begin() + Initial, begin() + Terminal, Elem)); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::out_arc_iterator graph_array<nodetype, arctype>::insert_arc(const node_iterator & Initial, const node_iterator & Terminal) { - ++m_NbArcs; - Initial->m_OutArcs.push_back(arc(Initial, Terminal)); - return (--(Initial->m_OutArcs.end())); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::out_arc_iterator graph_array<nodetype, arctype>::insert_arc(const node_iterator & Initial, const node_iterator & Terminal, const arctype & Elem) { - ++m_NbArcs; - Initial->m_OutArcs.push_back(arc(Initial, Terminal, Elem)); - return (--(Initial->m_OutArcs.end())); -} - - -template <class nodetype, class arctype> -inline typename graph_array<nodetype, arctype>::out_arc_iterator graph_array<nodetype, arctype>::erase_arc(const out_arc_iterator & Pos) { - --m_NbArcs; - return (Pos->initial()->m_OutArcs.erase(Pos)); -} - - -template <class nodetype, class arctype> -inline void graph_array<nodetype, arctype>::erase_arcs(const node_iterator & Initial) { - m_NbArcs -= (Initial->m_OutArcs.size()); - Initial->m_OutArcs.clear(); -} - - -template <class nodetype, class arctype> -inline void graph_array<nodetype, arctype>::erase_arcs() { - m_NbArcs = 0; - for (nodeid i = 0; i < size(); ++i) - m_Nodes[i].m_OutArcs.clear(); -} - - -template <class nodetype, class arctype> -inline void graph_array<nodetype, arctype>::swap(_mytype & Right) { - std::swap(m_NbArcs, Right.m_NbArcs); - std::swap(m_Nodes, Right.m_Nodes); -} - - - -////////////////////////////////////////////////////////////////////////// -// additional functions -////////////////////////////////////////////////////////////////////////// - -template <class nodetype, class arctype> -void unmark_nodes(graph_array<nodetype, arctype> & G) -{ - typedef typename graph_array<nodetype, arctype>::node_iterator node_it; - - for (node_it NodeIt = G.begin(); NodeIt != G.end(); ++NodeIt) - NodeIt->unmark(); -} - - -template <class graph_node> -void unmark_arcs_from_node(graph_node & N) -{ - std::for_each(N.out_begin(), N.out_end(), unmark_arc()); -} - - -template <class nodetype, class arctype> -void unmark_arcs(graph_array<nodetype, arctype> & G) -{ - typedef typename graph_array<nodetype, arctype>::node_iterator node_it; - - for (node_it NodeIt = G.begin(); NodeIt != G.end(); ++NodeIt) - unmark_arcs_from_node(* NodeIt); -} - - - - -} // namespace common_structures diff --git a/NifExport/TriStripper/heap_array.h b/NifExport/TriStripper/heap_array.h deleted file mode 100755 index 1cd0ad8c0dc51e82dafd037460f80e8ed07e8273..0000000000000000000000000000000000000000 --- a/NifExport/TriStripper/heap_array.h +++ /dev/null @@ -1,276 +0,0 @@ -// heap_array.h: interface for the heap_array class. -// -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2002 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@pandora.be -// -////////////////////////////////////////////////////////////////////// -// -// Semi-dynamic indexed heap -// ************************* -// -// Current version: 1.00 BETA 1 (24/10/2002) -// -// Comment: heap_array acts like a normal heap, you can push elements -// and then get the greatest one. -// However you cannot push any more element once an element -// has been removed (pop, erase, etc...). -// Elements can be modified after they've been pushed into -// the heap via their index. -// -// History: - -// -////////////////////////////////////////////////////////////////////// - -#pragma once - - - -// namespace common_structures -namespace common_structures { - - - - -template <class T, class CmpT = std::less<T> > -class heap_array -{ -public: - - struct heap_is_locked { }; - - - // heap_array main interface. Pre = PreCondition, Post = PostCondition - - heap_array() : m_Locked(false) { } // Post: ((size() == 0) && ! locked()) - - void clear(); // Post: ((size() == 0) && ! locked()) - - void reserve(size_t Size); - size_t size() const; - - bool empty() const; - bool locked() const; - bool removed(size_t i) const; // Pre: (valid(i)) - bool valid(size_t i) const; - - const T & top() const; // Pre: (! empty()) - const T & peek(size_t i) const; // Pre: (valid(i) && ! removed(i)) - const T & operator [] (size_t i) const; // Pre: (valid(i) && ! removed(i)) - - size_t push(const T & Elem); // Pre: (! locked()) else throw (heap_is_locked) - - void pop(); // Pre: (! empty()) Post: (locked()) - void erase(size_t i); // Pre: (valid(i) && ! removed(i)) Post: (locked()) - void update(size_t i, const T & Elem); // Pre: (valid(i) && ! removed(i)) Post: (locked()) - -protected: - - struct linker { - linker(const T & Elem, size_t i) : m_Elem(Elem), m_Index(i) { } - - T m_Elem; - size_t m_Index; - }; - - typedef std::vector<linker> linked_heap; - typedef std::vector<size_t> finder; - - void Adjust(size_t i); - void Swap(size_t a, size_t b); - bool Less(const linker & a, const linker & b) const; - - linked_heap m_Heap; - finder m_Finder; - CmpT m_Compare; - bool m_Locked; -}; - - - - -////////////////////////////////////////////////////////////////////////// -// heap_indexed Inline functions -////////////////////////////////////////////////////////////////////////// - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::clear() { - m_Heap.clear(); - m_Finder.clear(); - m_Locked = false; -} - - -template <class T, class CmpT> -inline bool heap_array<T, CmpT>::empty() const { - return m_Heap.empty(); -} - - -template <class T, class CmpT> -inline bool heap_array<T, CmpT>::locked() const { - return m_Locked; -} - - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::reserve(size_t Size) { - m_Heap.reserve(Size); - m_Finder.reserve(Size); -} - - -template <class T, class CmpT> -inline size_t heap_array<T, CmpT>::size() const { - return m_Heap.size(); -} - - -template <class T, class CmpT> -inline const T & heap_array<T, CmpT>::top() const { - // Debug check to ensure heap is not empty - assert(! empty()); - - return m_Heap.front().m_Elem; -} - - -template <class T, class CmpT> -inline const T & heap_array<T, CmpT>::peek(size_t i) const { - // Debug check to ensure element is still present - assert(! removed(i)); - - return (m_Heap[m_Finder[i]].m_Elem); -} - - -template <class T, class CmpT> -inline const T & heap_array<T, CmpT>::operator [] (size_t i) const { - return peek(i); -} - - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::pop() { - m_Locked = true; - - // Debug check to ensure heap is not empty - assert(! empty()); - - Swap(0, size() - 1); - m_Heap.pop_back(); - Adjust(0); -} - - -template <class T, class CmpT> -inline size_t heap_array<T, CmpT>::push(const T & Elem) { - if (m_Locked) - throw heap_is_locked(); - - size_t Id = size(); - m_Finder.push_back(Id); - m_Heap.push_back(linker(Elem, Id)); - Adjust(Id); - - return Id; -} - - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::erase(size_t i) { - m_Locked = true; - - // Debug check to ensure element is still present - assert(! removed(i)); - - size_t j = m_Finder[i]; - Swap(j, size() - 1); - m_Heap.pop_back(); - Adjust(j); -} - - -template <class T, class CmpT> -inline bool heap_array<T, CmpT>::removed(size_t i) const { - return (m_Finder[i] >= m_Heap.size()); -} - - -template <class T, class CmpT> -inline bool heap_array<T, CmpT>::valid(size_t i) const { - return (i < m_Finder.size()); -} - - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::update(size_t i, const T & Elem) { - // Debug check to ensure element is still present - assert(! removed(i)); - - size_t j = m_Finder[i]; - m_Heap[j].m_Elem = Elem; - Adjust(j); -} - - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::Adjust(size_t i) { - size_t j; - - // Check the upper part of the heap - for (j = i; (j > 0) && (Less(m_Heap[(j - 1) / 2], m_Heap[j])); j = ((j - 1) / 2)) - Swap(j, (j - 1) / 2); - - // Check the lower part of the heap - for (i = j; (j = 2 * i + 1) < size(); i = j) { - if ((j + 1 < size()) && (Less(m_Heap[j], m_Heap[j + 1]))) - ++j; - - if (Less(m_Heap[j], m_Heap[i])) - return; - - Swap(i, j); - } -} - - -template <class T, class CmpT> -inline void heap_array<T, CmpT>::Swap(size_t a, size_t b) { - std::swap(m_Heap[a], m_Heap[b]); - - // use (size_t &) to get rid of a bogus compile warning - (size_t &) (m_Finder[(m_Heap[a].m_Index)]) = a; - (size_t &) (m_Finder[(m_Heap[b].m_Index)]) = b; -} - - -template <class T, class CmpT> -inline bool heap_array<T, CmpT>::Less(const linker & a, const linker & b) const { - return m_Compare(a.m_Elem, b.m_Elem); -} - - - - -} // namespace common_structures - diff --git a/NifExport/TriStripper/public_types.h b/NifExport/TriStripper/public_types.h deleted file mode 100644 index 5fc7cd15640254ce9fc78c3287daa9eb3c6dfd3a..0000000000000000000000000000000000000000 --- a/NifExport/TriStripper/public_types.h +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright (C) 2004 Tanguy Fautré. -// For conditions of distribution and use, -// see copyright notice in tri_stripper.h -// -////////////////////////////////////////////////////////////////////// -// SVN: $Id: public_types.h 86 2005-06-08 17:47:27Z gpsnoopy $ -////////////////////////////////////////////////////////////////////// - -#ifndef TRI_STRIPPER_HEADER_GUARD_PUBLIC_TYPES_H -#define TRI_STRIPPER_HEADER_GUARD_PUBLIC_TYPES_H - -#include <vector> - - - - -namespace triangle_stripper -{ - - typedef size_t index; - typedef std::vector<index> indices; - - enum primitive_type - { - TRIANGLES = 0x0004, // = GL_TRIANGLES - TRIANGLE_STRIP = 0x0005 // = GL_TRIANGLE_STRIP - }; - - struct primitive_group - { - indices Indices; - primitive_type Type; - }; - - typedef std::vector<primitive_group> primitive_vector; - -} - - - - -#endif // TRI_STRIPPER_HEADER_GUARD_PUBLIC_TYPES_H diff --git a/NifExport/TriStripper/tri_stripper.h b/NifExport/TriStripper/tri_stripper.h deleted file mode 100755 index feacf5ac5145692c0d1066ff62a9560bf9fff1d6..0000000000000000000000000000000000000000 --- a/NifExport/TriStripper/tri_stripper.h +++ /dev/null @@ -1,190 +0,0 @@ - -////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2004 Tanguy Fautré. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. -// -// Tanguy Fautré -// softdev@telenet.be -// -////////////////////////////////////////////////////////////////////// -// -// Tri Stripper -// ************ -// -// Post TnL cache aware triangle stripifier in O(n.log(n)). -// -// History: see ChangeLog -// -////////////////////////////////////////////////////////////////////// -// SVN: $Id: tri_stripper.h 86 2005-06-08 17:47:27Z gpsnoopy $ -////////////////////////////////////////////////////////////////////// - -// Protection against old C habits -#if defined(max) -#error "'max' macro defined! It's against the C++ standard. Please use 'std::max' instead (undefine 'max' macro if it was defined in another library)." -#endif - -// Protection against old C habits -#if defined(min) -#error "'min' macro defined! It's against the C++ standard. Please use 'std::min' instead (undefine 'min' macro if it was defined in another library)." -#endif - - - -#ifndef TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H -#define TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H - -#include "public_types.h" - -#include "detail/cache_simulator.h" -#include "detail/graph_array.h" -#include "detail/heap_array.h" -#include "detail/types.h" - - - - -namespace triangle_stripper { - - - - -class tri_stripper -{ -public: - - tri_stripper(const indices & TriIndices); - - void Strip(primitive_vector * out_pPrimitivesVector); - - /* Stripifier Algorithm Settings */ - - // Set the post-T&L cache size (0 disables the cache optimizer). - void SetCacheSize(size_t CacheSize = 10); - - // Set the minimum size of a triangle strip (should be at least 2 triangles). - // The stripifier discard any candidate strips that does not satisfy the minimum size condition. - void SetMinStripSize(size_t MinStripSize = 2); - - // Set the backward search mode in addition to the forward search mode. - // In forward mode, the candidate strips are build with the current candidate triangle being the first - // triangle of the strip. When the backward mode is enabled, the stripifier also tests candidate strips - // where the current candidate triangle is the last triangle of the strip. - // Enable this if you want better results at the expense of being slightly slower. - // Note: Do *NOT* use this when the cache optimizer is enabled; it only gives worse results. - void SetBackwardSearch(bool Enabled = false); - - // Set the cache simulator FIFO behavior (does nothing if the cache optimizer is disabled). - // When enabled, the cache is simulated as a simple FIFO structure. However, when - // disabled, indices that trigger cache hits are not pushed into the FIFO structure. - // This allows simulating some GPUs that do not duplicate cache entries (e.g. NV25 or greater). - void SetPushCacheHits(bool Enabled = true); - - /* End Settings */ - -private: - - typedef detail::graph_array<detail::triangle> triangle_graph; - typedef detail::heap_array<size_t, std::greater<size_t> > triangle_heap; - typedef std::vector<size_t> candidates; - typedef triangle_graph::node_iterator tri_iterator; - typedef triangle_graph::const_node_iterator const_tri_iterator; - typedef triangle_graph::out_arc_iterator link_iterator; - typedef triangle_graph::const_out_arc_iterator const_link_iterator; - - void InitTriHeap(); - void Stripify(); - void AddLeftTriangles(); - void ResetStripIDs(); - - detail::strip FindBestStrip(); - detail::strip ExtendToStrip(size_t Start, detail::triangle_order Order); - detail::strip BackExtendToStrip(size_t Start, detail::triangle_order Order, bool ClockWise); - const_link_iterator LinkToNeighbour(const_tri_iterator Node, bool ClockWise, detail::triangle_order & Order, bool NotSimulation); - const_link_iterator BackLinkToNeighbour(const_tri_iterator Node, bool ClockWise, detail::triangle_order & Order); - void BuildStrip(const detail::strip Strip); - void MarkTriAsTaken(size_t i); - void AddIndex(index i, bool NotSimulation); - void BackAddIndex(index i); - void AddTriangle(const detail::triangle & Tri, detail::triangle_order Order, bool NotSimulation); - void BackAddTriangle(const detail::triangle & Tri, detail::triangle_order Order); - - bool Cache() const; - size_t CacheSize() const; - - static detail::triangle_edge FirstEdge(const detail::triangle & Triangle, detail::triangle_order Order); - static detail::triangle_edge LastEdge(const detail::triangle & Triangle, detail::triangle_order Order); - - primitive_vector m_PrimitivesVector; - triangle_graph m_Triangles; - triangle_heap m_TriHeap; - candidates m_Candidates; - detail::cache_simulator m_Cache; - detail::cache_simulator m_BackCache; - size_t m_StripID; - size_t m_MinStripSize; - bool m_BackwardSearch; - bool m_FirstRun; -}; - - - - - -////////////////////////////////////////////////////////////////////////// -// tri_stripper inline functions -////////////////////////////////////////////////////////////////////////// - -inline void tri_stripper::SetCacheSize(const size_t CacheSize) -{ - m_Cache.resize(CacheSize); - m_BackCache.resize(CacheSize); -} - - -inline void tri_stripper::SetMinStripSize(const size_t MinStripSize) -{ - if (MinStripSize < 2) - m_MinStripSize = 2; - else - m_MinStripSize = MinStripSize; -} - - -inline void tri_stripper::SetBackwardSearch(const bool Enabled) -{ - m_BackwardSearch = Enabled; -} - - - -inline void tri_stripper::SetPushCacheHits(bool Enabled) -{ - m_Cache.push_cache_hits(Enabled); -} - - - - -} // namespace triangle_stripper - - - - -#endif // TRI_STRIPPER_HEADER_GUARD_TRI_STRIPPER_H