OpenVDBのコード規模を調べる
はじめに
OpenVDB は3次元グリッド上の疎なボリュームデータを効率よく保存し、操作するためのオープンソースのC++ライブラリである。
OpenVDBのコードを読み進めるにあたり、まずはコードの規模を把握することにした。 リポジトリにはライブラリ本体のほか、HoudiniやMayaとの連携機能、開発者向けの文書なども含まれている。
そこでリポジトリ全体のファイル数と行数をフォルダ毎に集計し、次にライブラリ本体のC++コードに対象を絞って規模を調べた。
調査には2026年10月29日の OpenVDB(コミット 8d298c0b) を使った。
フォルダ構成
リポジトリの上位階層とOpenVDB本体がある openvdb/openvdb/ の内訳を以下に示す。
|
|
リポジトリ全体のファイル件数
このリポジトリが管理しているファイルは1,570件ある。 そのうち1,565件がテキストファイル、5件がPNG画像である。
1,565件のテキストファイルの行数を合算すると計641,713行だった。 行数には空行とコメントを含めている。
下表にテキストファイル数と行数をまとめた。
| フォルダ | ファイル数 | 物理行数 |
|---|---|---|
| openvdb/ | 343 | 211,088 |
| openvdb_cmd/ | 49 | 26,274 |
| nanovdb/ | 182 | 80,115 |
| openvdb_ax/ | 413 | 58,991 |
| openvdb_houdini/ | 99 | 65,793 |
| openvdb_maya/ | 27 | 6,539 |
| openvdb_wolfram/ | 95 | 59,985 |
| ext/ | 45 | 79,147 |
| cmake/ | 19 | 4,086 |
| doc/ | 40 | 20,439 |
| .github/ | 11 | 1,661 |
| ci/ | 24 | 1,681 |
| pendingchanges/ | 1 | 3 |
| tsc/ | 206 | 19,638 |
| ルート直下のファイル | 11 | 6,273 |
| 全体 | 1,565 | 641,713 |
OpenVDB本体のファイル件数
前節でOpenVDB本体がある openvdb/openvdb には343件のファイルがあるとわかった。
この中には単体テストなども含まれるので、対象をOpenVDBそのものに関係するC++コードに絞ることにした。
集計対象
openvdb/openvdb/ 配下にある .h と .cc をOpenVDB本体のコードとして集計対象とした。
ただし、次のフォルダとファイルは対象から除いた。
- 単体テストの
unittest/ - Pythonバインディングの
python/ - 生成済みの数値テーブル
math/QuantizedUnitVec.cc READMEやCMakeLists.txtなど
集計方法
OpenVDBリポジトリのルートで次のコマンドを実行すると、Gitが追跡するファイルの総数と区分ごとの件数を確認できる。
|
|
上のコマンドで「OpenVDB本体」としたファイルは次のコマンドで確認できる。 出力の最後に合計ファイル数を表示する。
|
|
集計結果
openvdb/openvdb にあるファイル343件の内、OpenVDB本体のコードは195ファイルとわかった。
| 区分 | ファイル数 |
|---|---|
| OpenVDB本体 | 195 |
| 単体テスト (unittest/) | 126 |
| Pythonバインディング (python/) | 14 |
| 生成済み数値テーブル(math/QuantizedUnitVec.cc) | 1 |
| その他 (README, LICENSE, version.h.in, CMakeLists.txt など) | 7 |
合計 ( openvdb/openvdb のファイル総数) |
343 |
OpenVDB本体のファイル規模分布
OpenVDB本体は195ファイルということがわかったので、それらを物理行数で8つの区分に分け、規模分布を得ることにした。
集計対象
前節でOpenVDB本体のコードとして絞り込んだ195ファイルを集計対象とする。
集計方法
付録の summarize-file-sizes.py を実行して区分分けをする。引数で指定している counts.tsv は付録の count-openvdb-lines.py が出力したものである。
|
|
集計結果
4割以上が300行未満である一方、約4分の1が1,000行以上であるとわかった。
| 物理行数の区分 | ファイル数 | 割合(%) |
|---|---|---|
| 5000以上 | 1 | 0.5 |
| 3000以上5000未満 | 3 | 1.5 |
| 1500以上3000未満 | 20 | 10.3 |
| 1000以上1500未満 | 23 | 11.8 |
| 750以上1000未満 | 11 | 5.6 |
| 500以上750未満 | 30 | 15.4 |
| 300以上500未満 | 26 | 13.3 |
| 300未満 | 81 | 41.5 |
| 合計 | 195 | 100.0 |
なお、各区分の割合は小数第1位に丸めたため、表示値を足すと99.9%になる。合計欄の100.0%は件数から求めた。
OpenVDB本体のフォルダ毎の総行数と中央値
openvdb/openvdb/ にいくつかのフォルダに分かれているので、フォルダ毎に規模を確認することにした。
集計対象
対象は openvdb/openvdb/ 配下の195のファイルである。
集計方法
各ファイルを openvdb/openvdb/ 直下にあるフォルダ単位でまとめ、行数、中央値を求める。
ただし openvdb/openvdb/ 直下のファイルは「直下」にひとまとめにする。
中央値はファイルを行数順に並べたときの中央の値で、偶数件なら中央の2件の平均を取ることとする。
これらは付録の count-openvdb-lines.py が出力する counts.tsv の core_folder 欄で確認できる。
|
|
集計結果
最も総行数が多いフォルダはグリッドの演算や変換を扱う tools/ と判明した。同フォルダには56ファイルがあり、行数は52,533行であった。
| フォルダ | ファイル数 | 総行数 | 中央値 | 最大ファイル |
|---|---|---|---|---|
| tools/ | 56 | 52533 | 668 | VolumeToMesh.h(5245行) |
| points/ | 48 | 23284 | 289.5 | AttributeArray.h(2122行) |
| math/ | 26 | 21263 | 593 | Maps.h(2702行) |
| tree/ | 13 | 19820 | 1526 | RootNode.h(3522行) |
| 直下 | 14 | 5864 | 221 | Grid.h(1863行) |
| io/ | 15 | 5799 | 247 | Archive.cc(1360行) |
| util/ | 14 | 3422 | 155.5 | NodeMasks.h(1067行) |
| codecs/ | 7 | 1728 | 163 | PointDataCodec.h(523行) |
| simd/ | 1 | 693 | 693 | Simd.h(693行) |
| thread/ | 1 | 37 | 37 | Threading.h(37行) |
| 合計 | 195 | 134443 |
points/ と tree/ はどちらも約2万行だが、ファイルの分け方が違う。
点群を扱う points/ では48ファイルの中央値が289.5行なのに対して、木構造を扱う tree/ では13ファイルの中央値が1,526行だった。
木構造のファイルは、 RootNode.h (3,522行)、 InternalNode.h (3,477行)、 Tree.h (2,078行) LeafNode.h (1,871行) があり、木構造を読み進めるなら千行を超すヘッダーを複数読むことになる。
なお、参考までに最大ファイル欄にフォルダの中で最も行数の多いファイルを記載した。
|
|
まとめ
OpenVDBのリポジトリは文書やテストを含めて約64万行である。ライブラリ本体のC++コードに対象を絞ると195ファイルで約13万行だった。
木構造を扱う tree/ は13ファイル、19,820行であり、ライブラリ本体の約15%を占める。ファイル行数の中央値は1,526行で、フォルダ別の比較では最も大きかった。
付録 ファイル数と行数の集計スクリプト
下のPythonスクリプトを count-openvdb-lines.py として保存し、OpenVDBのローカルリポジトリへのパスを渡す。
GitとPython 3の標準ライブラリを使う。引数にコミットを指定しなければ、この記事で調べた 8d298c0b のファイルを読む。
|
|
出力はタブ区切りで、リポジトリ直下のフォルダ別のテキストファイル数と行数、C++本体のフォルダ別集計、C++ファイルごとの行数の順に並ぶ。
最初の集計ではNULバイトを含むファイルを件数と行数の両方から除く。空行とコメントも1行に数え、末尾に改行のない最終行も数える。
最初の TOTAL は1,565ファイル、641,713行である。C++本体に対象を絞った二つ目の TOTAL は195ファイル、134,443行になる。
集計スクリプトの全文
|
|
付録 ファイル規模分布の集計スクリプト
下のスクリプトを summarize-file-sizes.py と保存して実行する。
|
|
ファイル規模分布の集計スクリプト
|
|
付録 C++本体195ファイルの物理行数
ファイル別の行数一覧(195件)
openvdb/openvdb/ からの相対パスを行数の多い順に並べた。
| # | ファイル | 物理行数 |
|---|---|---|
| 1 | tools/VolumeToMesh.h | 5245 |
| 2 | tools/MeshToVolume.h | 4537 |
| 3 | tree/RootNode.h | 3522 |
| 4 | tree/InternalNode.h | 3477 |
| 5 | tools/LevelSetUtil.h | 2869 |
| 6 | math/Maps.h | 2702 |
| 7 | math/FiniteDifference.h | 2326 |
| 8 | math/Operators.h | 2129 |
| 9 | points/AttributeArray.h | 2122 |
| 10 | tree/Tree.h | 2078 |
| 11 | tools/FastSweeping.h | 1984 |
| 12 | points/impl/PointRasterizeSDFImpl.h | 1948 |
| 13 | tree/LeafNode.h | 1871 |
| 14 | Grid.h | 1863 |
| 15 | tree/NodeManager.h | 1835 |
| 16 | math/Stencils.h | 1821 |
| 17 | tools/PointIndexGrid.h | 1820 |
| 18 | math/ConjGradient.h | 1767 |
| 19 | tools/impl/LevelSetDilatedMeshImpl.h | 1628 |
| 20 | tools/Merge.h | 1600 |
| 21 | tree/LeafNodeBool.h | 1600 |
| 22 | points/impl/PointRasterizeFrustumImpl.h | 1580 |
| 23 | points/PointDataGrid.h | 1575 |
| 24 | tree/LeafNodeMask.h | 1526 |
| 25 | tools/impl/LevelSetTubesImpl.h | 1492 |
| 26 | tools/impl/ConvexVoxelizer.h | 1397 |
| 27 | points/AttributeSet.cc | 1383 |
| 28 | math/Mat4.h | 1370 |
| 29 | tree/TreeIterator.h | 1370 |
| 30 | tools/Diagnostics.h | 1362 |
| 31 | io/Archive.cc | 1360 |
| 32 | tools/Morphology.h | 1228 |
| 33 | tools/DenseSparseTools.h | 1192 |
| 34 | tools/GridOperators.h | 1182 |
| 35 | points/impl/PrincipalComponentAnalysisImpl.h | 1167 |
| 36 | tools/Composite.h | 1133 |
| 37 | tools/RayTracer.h | 1104 |
| 38 | tools/GridTransformer.h | 1078 |
| 39 | util/NodeMasks.h | 1067 |
| 40 | tools/PointPartitioner.h | 1052 |
| 41 | math/Mat.h | 1044 |
| 42 | tools/ParticleAtlas.h | 1035 |
| 43 | math/Math.h | 1029 |
| 44 | tools/ParticlesToLevelSet.h | 1027 |
| 45 | tools/VolumeToSpheres.h | 1023 |
| 46 | tools/Interpolation.h | 1019 |
| 47 | tree/ValueAccessor.h | 1017 |
| 48 | TypeList.h | 980 |
| 49 | tools/MultiResGrid.h | 968 |
| 50 | io/File.cc | 928 |
| 51 | tools/PoissonSolver.h | 901 |
| 52 | tools/Filter.h | 875 |
| 53 | math/Mat3.h | 848 |
| 54 | tree/LeafManager.h | 839 |
| 55 | points/impl/PointConversionImpl.h | 835 |
| 56 | points/impl/PointRasterizeEllipsoidsSDFImpl.h | 828 |
| 57 | Types.h | 783 |
| 58 | points/impl/PointMoveImpl.h | 767 |
| 59 | tools/FindActiveValues.h | 744 |
| 60 | io/Compression.h | 736 |
| 61 | util/PagedArray.h | 733 |
| 62 | points/PointTransfer.h | 732 |
| 63 | tools/ValueTransformer.h | 732 |
| 64 | math/Vec3.h | 721 |
| 65 | tools/LevelSetTracker.h | 700 |
| 66 | simd/Simd.h | 693 |
| 67 | tools/RayIntersector.h | 674 |
| 68 | tools/LevelSetMorph.h | 662 |
| 69 | points/impl/PointRasterizeTrilinearImpl.h | 631 |
| 70 | math/Quat.h | 626 |
| 71 | math/Vec4.h | 616 |
| 72 | points/impl/PointGroupImpl.h | 614 |
| 73 | tools/LevelSetFilter.h | 609 |
| 74 | math/Coord.h | 603 |
| 75 | tools/Clip.h | 597 |
| 76 | tools/LevelSetAdvect.h | 596 |
| 77 | tools/LevelSetMeasure.h | 589 |
| 78 | tools/VolumeAdvect.h | 588 |
| 79 | points/IndexFilter.h | 584 |
| 80 | math/Vec2.h | 583 |
| 81 | tools/Dense.h | 583 |
| 82 | points/StreamCompression.cc | 560 |
| 83 | points/impl/PointStatisticsImpl.h | 544 |
| 84 | points/AttributeSet.h | 537 |
| 85 | tools/LevelSetPlatonic.h | 532 |
| 86 | codecs/PointDataCodec.h | 523 |
| 87 | io/Codec.h | 522 |
| 88 | tools/Count.h | 507 |
| 89 | math/Transform.cc | 482 |
| 90 | points/impl/PointSampleImpl.h | 457 |
| 91 | tools/Prune.h | 448 |
| 92 | Grid.cc | 428 |
| 93 | tools/PotentialFlow.h | 428 |
| 94 | points/impl/PointScatterImpl.h | 424 |
| 95 | codecs/TopologyCodec.h | 423 |
| 96 | math/BBox.h | 423 |
| 97 | tools/PointScatter.h | 421 |
| 98 | Metadata.h | 416 |
| 99 | tools/Statistics.h | 409 |
| 100 | points/impl/PointAttributeImpl.h | 406 |
| 101 | points/AttributeArrayString.cc | 403 |
| 102 | tools/LevelSetRebuild.h | 400 |
| 103 | tools/PointAdvect.h | 395 |
| 104 | math/Stats.h | 385 |
| 105 | Platform.h | 360 |
| 106 | points/impl/PointMaskImpl.h | 358 |
| 107 | points/PointRasterizeSDF.h | 352 |
| 108 | tree/LeafBuffer.h | 347 |
| 109 | math/DDA.h | 344 |
| 110 | tools/LevelSetFracture.h | 337 |
| 111 | points/IndexIterator.h | 330 |
| 112 | tools/SignedFloodFill.h | 315 |
| 113 | math/Ray.h | 312 |
| 114 | io/Queue.cc | 306 |
| 115 | util/MapsUtil.h | 294 |
| 116 | tools/ChangeBackground.h | 293 |
| 117 | io/Compression.cc | 292 |
| 118 | points/StreamCompression.h | 292 |
| 119 | points/impl/PointReplicateImpl.h | 287 |
| 120 | math/Tuple.h | 279 |
| 121 | tools/TopologyToLevelSet.h | 277 |
| 122 | tools/VelocityFields.h | 276 |
| 123 | math/Transform.h | 271 |
| 124 | util/logging.cc | 265 |
| 125 | tools/Activate.h | 264 |
| 126 | tools/LevelSetSphere.h | 257 |
| 127 | points/PointRasterizeFrustum.h | 256 |
| 128 | tools/PointsToMask.h | 256 |
| 129 | tree/Iterator.h | 253 |
| 130 | math/Maps.cc | 252 |
| 131 | io/io.h | 250 |
| 132 | points/PointAdvect.h | 249 |
| 133 | io/Queue.h | 247 |
| 134 | points/AttributeArrayString.h | 247 |
| 135 | tools/NodeVisitor.h | 246 |
| 136 | io/File.h | 243 |
| 137 | points/PointConversion.h | 226 |
| 138 | points/PrincipalComponentAnalysis.h | 226 |
| 139 | openvdb.h | 225 |
| 140 | points/PointStatistics.h | 224 |
| 141 | io/Archive.h | 222 |
| 142 | tools/LevelSetTubes.h | 219 |
| 143 | MetaMap.h | 217 |
| 144 | points/impl/PointDeleteImpl.h | 209 |
| 145 | MetaMap.cc | 202 |
| 146 | points/AttributeArray.cc | 198 |
| 147 | codecs/ScalarCodec.h | 194 |
| 148 | util/CpuTimer.h | 192 |
| 149 | io/GridDescriptor.cc | 187 |
| 150 | util/logging.h | 179 |
| 151 | points/AttributeGroup.h | 176 |
| 152 | io/Stream.cc | 168 |
| 153 | points/PointAttribute.h | 167 |
| 154 | codecs/PointIndexCodec.h | 163 |
| 155 | util/Util.h | 163 |
| 156 | Metadata.cc | 159 |
| 157 | points/PointDataIO.h | 155 |
| 158 | tools/VectorTransformer.h | 155 |
| 159 | codecs/BoolCodec.h | 154 |
| 160 | points/PointScatter.h | 153 |
| 161 | util/Formats.cc | 148 |
| 162 | codecs/ValueMaskCodec.h | 146 |
| 163 | points/impl/PointCountImpl.h | 140 |
| 164 | tools/LevelSetDilatedMesh.h | 139 |
| 165 | io/Codec.cc | 135 |
| 166 | tools/Mask.h | 134 |
| 167 | math/Proximity.cc | 131 |
| 168 | openvdb.cc | 131 |
| 169 | points/PointGroup.h | 130 |
| 170 | points/PointSample.h | 126 |
| 171 | codecs/impl/ScalarLeafCodec.h | 125 |
| 172 | util/Formats.h | 124 |
| 173 | math/QuantizedUnitVec.h | 121 |
| 174 | points/AttributeGroup.cc | 120 |
| 175 | points/PointRasterizeTrilinear.h | 111 |
| 176 | io/GridDescriptor.h | 109 |
| 177 | util/Name.h | 107 |
| 178 | points/PointMask.h | 97 |
| 179 | io/Stream.h | 94 |
| 180 | points/PointMove.h | 94 |
| 181 | Exceptions.h | 85 |
| 182 | tree/NodeUnion.h | 85 |
| 183 | points/PointCount.h | 80 |
| 184 | points/PointDelete.h | 77 |
| 185 | points/PointReplicate.h | 71 |
| 186 | util/NullInterrupter.h | 56 |
| 187 | math/Proximity.h | 48 |
| 188 | util/Assert.h | 45 |
| 189 | thread/Threading.h | 37 |
| 190 | points/points.cc | 36 |
| 191 | util/Assert.cc | 34 |
| 192 | math/HalfDecl.h | 30 |
| 193 | util/ExplicitInstantiation.h | 15 |
| 194 | PlatformConfig.h | 8 |
| 195 | Platform.cc | 7 |