[返回博客](/cn/blog) # 渐进网格的新自动细节级别选择（第2部分，共2部分）

Egor Slupko 一月 14, 2021 [\#Visualize](/cn/blog/tag/visualize) [\#level of details](/cn/blog/tag/level-details) [\#getting started](/cn/blog/tag/getting-started)

<a class="a2a_button_facebook"></a><a class="a2a_button_twitter"></a><a class="a2a_button_linkedin"></a>

这是关于自动细节级别 (LOD) 选择系列文章的第二篇。有关该系列的第一篇文章，请参阅[第1部分](https://www.opendesign.com/blog/2020/december/new-automatic-lod-selection-progressive-meshes-part-1-2)。

Visualize SDK 21.4 支持 OdTvProgressiveMeshData 的自动细节级别选择。您可以通过调用以下方法启用它：

```
virtual OdTvResult setAutoLODSelection( LODAutoSelectType autoSelectType ) = 0;
```

其中 autoSelectType 是 LODAutoSelectType 值之一：

- OdTvProgressiveMeshData::kAutoLOD\_None 禁用自动 LOD 选择。
- OdTvProgressiveMeshData::kAutoLOD\_SqrInterpolation 启用 OdGiProgressiveMesh::kSqrInterpolation LOD 选择。
- OdTvProgressiveMeshData::kAutoLOD\_SqrtInterpolation 启用 OdGiProgressiveMesh::kSqrtInterpolation LOD 选择。
- OdTvProgressiveMeshData::kAutoLOD\_CustomInterpolation 启用 OdGiProgressiveMesh::kCustom LOD 选择。

可以使用以下方法指定插值参数：

```
virtual OdTvResult setAutoLODSelectMaxInterpolationThreshold( OdUInt32 nMax ) = 0;
virtual OdTvResult setAutoLODSelectMinInterpolationThreshold( OdUInt32 nMin ) = 0;
```

#### Visualize SDK 自定义 LOD 插值示例

OdTvCustomInterpolation 类用于为细节级别提供自定义插值。由于 Visualize SDK 不提供细节级别的线性插值，因此它是一个自定义实现：

```
class LinearInterpolation : public OdTvCustomInterpolation
{
public:
  virtual OdUInt32 interpolate( OdUInt32 minX, OdUInt32 minY, OdUInt32 maxX, OdUInt32 maxY, OdUInt32 x ) const
  {
    //interpolation: Y = A * x + B, where minY = A * minX + B and maxY = A * maxX + B
    double A = ( (double)( maxY - minY ) ) / ( (double)( maxX - minX ) );
    double B = maxY - A * maxX;
    return OdUInt32( A * x + B );
  }
};
…
LinearInterpolation* interp = new LinearInterpolation();
pPM->setAutoLODCustomInterpolation( interp );
pPM->setAutoLODSelection ( OdTvProgressiveMeshData::kAutoLOD_CustomInterpolation );
```

OdTvProgressiveMeshData 对象的所有属性都保存在 .vsf 文件中。但是，指向 OdTvCustomInterpolation 的指针无法保存。因此，OdTvProgressiveMeshData 在保存时，会为 getAutoLODSelectInterpolationThresholds() 返回的区间中的每个值调用 OdTvCustomInterpolation::interpolate() 方法。加载后，OdTvProgressiveMeshData 对象使用此数据执行自定义插值，直到指定新的 OdTvCustomInterpolation 对象指针。

## 今天就开始行动

**免费试用 ODA 软件 60 天。  
无风险，无需信用卡。**

[免费试用](https://www.opendesign.com/cn/free-trial)
