Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/mesh/valence_cache.h
- This file was moved from extern/draco/dracoenc/src/draco/mesh/valence_cache.h.
| Show All 30 Lines | |||||
| class ValenceCache { | class ValenceCache { | ||||
| const CornerTableT &table_; | const CornerTableT &table_; | ||||
| public: | public: | ||||
| explicit ValenceCache(const CornerTableT &table) : table_(table) {} | explicit ValenceCache(const CornerTableT &table) : table_(table) {} | ||||
| // Do not call before CacheValences() / CacheValencesInaccurate(). | // Do not call before CacheValences() / CacheValencesInaccurate(). | ||||
| inline int8_t ValenceFromCacheInaccurate(CornerIndex c) const { | inline int8_t ValenceFromCacheInaccurate(CornerIndex c) const { | ||||
| if (c == kInvalidCornerIndex) | if (c == kInvalidCornerIndex) { | ||||
| return -1; | return -1; | ||||
| } | |||||
| return ValenceFromCacheInaccurate(table_.Vertex(c)); | return ValenceFromCacheInaccurate(table_.Vertex(c)); | ||||
| } | } | ||||
| inline int32_t ValenceFromCache(CornerIndex c) const { | inline int32_t ValenceFromCache(CornerIndex c) const { | ||||
| if (c == kInvalidCornerIndex) | if (c == kInvalidCornerIndex) { | ||||
| return -1; | return -1; | ||||
| } | |||||
| return ValenceFromCache(table_.Vertex(c)); | return ValenceFromCache(table_.Vertex(c)); | ||||
| } | } | ||||
| inline int32_t ConfidentValenceFromCache(VertexIndex v) const { | inline int32_t ConfidentValenceFromCache(VertexIndex v) const { | ||||
| DRACO_DCHECK_LT(v.value(), table_.num_vertices()); | DRACO_DCHECK_LT(v.value(), table_.num_vertices()); | ||||
| DRACO_DCHECK_EQ(vertex_valence_cache_32_bit_.size(), table_.num_vertices()); | DRACO_DCHECK_EQ(vertex_valence_cache_32_bit_.size(), table_.num_vertices()); | ||||
| return vertex_valence_cache_32_bit_[v]; | return vertex_valence_cache_32_bit_[v]; | ||||
| } | } | ||||
| // Collect the valence for all vertices so they can be reused later. The | // Collect the valence for all vertices so they can be reused later. The | ||||
| // 'inaccurate' versions of this family of functions clips the true valence | // 'inaccurate' versions of this family of functions clips the true valence | ||||
| // of the vertices to 8 signed bits as a space optimization. This clipping | // of the vertices to 8 signed bits as a space optimization. This clipping | ||||
| // will lead to occasionally wrong results. If accurate results are required | // will lead to occasionally wrong results. If accurate results are required | ||||
| // under all circumstances, do not use the 'inaccurate' version or else | // under all circumstances, do not use the 'inaccurate' version or else | ||||
| // use it and fetch the correct result in the event the value appears clipped. | // use it and fetch the correct result in the event the value appears clipped. | ||||
| // The topology of the mesh should be a constant when Valence Cache functions | // The topology of the mesh should be a constant when Valence Cache functions | ||||
| // are being used. Modification of the mesh while cache(s) are filled will | // are being used. Modification of the mesh while cache(s) are filled will | ||||
| // not guarantee proper results on subsequent calls unless they are rebuilt. | // not guarantee proper results on subsequent calls unless they are rebuilt. | ||||
| void CacheValencesInaccurate() const { | void CacheValencesInaccurate() const { | ||||
| if (vertex_valence_cache_8_bit_.size() == 0) { | if (vertex_valence_cache_8_bit_.size() == 0) { | ||||
| const VertexIndex vertex_count = VertexIndex(table_.num_vertices()); | const VertexIndex vertex_count = VertexIndex(table_.num_vertices()); | ||||
| vertex_valence_cache_8_bit_.resize(vertex_count.value()); | vertex_valence_cache_8_bit_.resize(vertex_count.value()); | ||||
| for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) | for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) { | ||||
| vertex_valence_cache_8_bit_[v] = static_cast<int8_t>( | vertex_valence_cache_8_bit_[v] = static_cast<int8_t>( | ||||
| (std::min)(static_cast<int32_t>(std::numeric_limits<int8_t>::max()), | (std::min)(static_cast<int32_t>(std::numeric_limits<int8_t>::max()), | ||||
| table_.Valence(v))); | table_.Valence(v))); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| void CacheValences() const { | void CacheValences() const { | ||||
| if (vertex_valence_cache_32_bit_.size() == 0) { | if (vertex_valence_cache_32_bit_.size() == 0) { | ||||
| const VertexIndex vertex_count = VertexIndex(table_.num_vertices()); | const VertexIndex vertex_count = VertexIndex(table_.num_vertices()); | ||||
| vertex_valence_cache_32_bit_.resize(vertex_count.value()); | vertex_valence_cache_32_bit_.resize(vertex_count.value()); | ||||
| for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) | for (VertexIndex v = VertexIndex(0); v < vertex_count; v += 1) { | ||||
| vertex_valence_cache_32_bit_[v] = table_.Valence(v); | vertex_valence_cache_32_bit_[v] = table_.Valence(v); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| inline int8_t ConfidentValenceFromCacheInaccurate(CornerIndex c) const { | inline int8_t ConfidentValenceFromCacheInaccurate(CornerIndex c) const { | ||||
| DRACO_DCHECK_GE(c.value(), 0); | DRACO_DCHECK_GE(c.value(), 0); | ||||
| return ConfidentValenceFromCacheInaccurate(table_.ConfidentVertex(c)); | return ConfidentValenceFromCacheInaccurate(table_.ConfidentVertex(c)); | ||||
| } | } | ||||
| inline int32_t ConfidentValenceFromCache(CornerIndex c) const { | inline int32_t ConfidentValenceFromCache(CornerIndex c) const { | ||||
| DRACO_DCHECK_GE(c.value(), 0); | DRACO_DCHECK_GE(c.value(), 0); | ||||
| return ConfidentValenceFromCache(table_.ConfidentVertex(c)); | return ConfidentValenceFromCache(table_.ConfidentVertex(c)); | ||||
| } | } | ||||
| inline int8_t ValenceFromCacheInaccurate(VertexIndex v) const { | inline int8_t ValenceFromCacheInaccurate(VertexIndex v) const { | ||||
| DRACO_DCHECK_EQ(vertex_valence_cache_8_bit_.size(), table_.num_vertices()); | DRACO_DCHECK_EQ(vertex_valence_cache_8_bit_.size(), table_.num_vertices()); | ||||
| if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) | if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) { | ||||
| return -1; | return -1; | ||||
| } | |||||
| return ConfidentValenceFromCacheInaccurate(v); | return ConfidentValenceFromCacheInaccurate(v); | ||||
| } | } | ||||
| inline int8_t ConfidentValenceFromCacheInaccurate(VertexIndex v) const { | inline int8_t ConfidentValenceFromCacheInaccurate(VertexIndex v) const { | ||||
| DRACO_DCHECK_LT(v.value(), table_.num_vertices()); | DRACO_DCHECK_LT(v.value(), table_.num_vertices()); | ||||
| DRACO_DCHECK_EQ(vertex_valence_cache_8_bit_.size(), table_.num_vertices()); | DRACO_DCHECK_EQ(vertex_valence_cache_8_bit_.size(), table_.num_vertices()); | ||||
| return vertex_valence_cache_8_bit_[v]; | return vertex_valence_cache_8_bit_[v]; | ||||
| } | } | ||||
| // TODO(draco-eng) Add unit tests for ValenceCache functions. | // TODO(draco-eng) Add unit tests for ValenceCache functions. | ||||
| inline int32_t ValenceFromCache(VertexIndex v) const { | inline int32_t ValenceFromCache(VertexIndex v) const { | ||||
| DRACO_DCHECK_EQ(vertex_valence_cache_32_bit_.size(), table_.num_vertices()); | DRACO_DCHECK_EQ(vertex_valence_cache_32_bit_.size(), table_.num_vertices()); | ||||
| if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) | if (v == kInvalidVertexIndex || v.value() >= table_.num_vertices()) { | ||||
| return -1; | return -1; | ||||
| } | |||||
| return ConfidentValenceFromCache(v); | return ConfidentValenceFromCache(v); | ||||
| } | } | ||||
| // Clear the cache of valences and deallocate the memory. | // Clear the cache of valences and deallocate the memory. | ||||
| void ClearValenceCacheInaccurate() const { | void ClearValenceCacheInaccurate() const { | ||||
| vertex_valence_cache_8_bit_.clear(); | vertex_valence_cache_8_bit_.clear(); | ||||
| // Force erasure. | // Force erasure. | ||||
| IndexTypeVector<VertexIndex, int8_t>().swap(vertex_valence_cache_8_bit_); | IndexTypeVector<VertexIndex, int8_t>().swap(vertex_valence_cache_8_bit_); | ||||
| Show All 21 Lines | |||||