History

Added some comments.

Andrzej Kapolka committed 12 years ago

Commit a0265601 parent 686ad4f2 files · +29 −6Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 2 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+26−6
@@ -1570,11 +1570,17 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1569 unmodified lines
15701570 QVector<VoxelPoint> vertices;
15711571 QVector<int> indices;
15721572
1573+ // see http://www.frankpetterson.com/publications/dualcontour/dualcontour.pdf for a description of the
1574+ // dual contour algorithm for generating meshes from voxel data using Hermite-tagged edges
15731575 const QVector<QRgb>& colorContents = color->getContents();
15741576 const QByteArray& materialContents = material->getContents();
15751577 const QVector<QRgb>& hermiteContents = hermite->getContents();
15761578 int size = color->getSize();
15771579 int area = size * size;
1580+
1581+ // number variables such as offset3 and alpha0 in this function correspond to cube corners, where the x, y, and z
1582+ // components are represented as bits in the 0, 1, and 2 position, respectively; hence, alpha0 is the value at
1583+ // the minimum x, y, and z corner and alpha7 is the value at the maximum x, y, and z
15781584 int offset3 = size + 1;
15791585 int offset5 = area + 1;
15801586 int offset6 = area + size;
@@ -1587,6 +1593,8 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 6 unmodified lines
15871593
15881594 const char* materialData = materialContents.constData();
15891595
1596+ // as we scan down the cube generating vertices between grid points, we remember the indices of the last
1597+ // (element, line, section--x, y, z) so that we can connect generated vertices as quads
15901598 int expanded = size + 1;
15911599 QVector<int> lineIndices(expanded, -1);
15921600 QVector<int> lastLineIndices(expanded, -1);
@@ -1609,6 +1617,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 16 unmodified lines
16091617 int alpha1 = alpha0, alpha2 = alpha0, alpha4 = alpha0;
16101618 int alphaTotal = alpha0;
16111619 int possibleTotal = EIGHT_BIT_MAXIMUM;
1620+
1621+ // cubes on the edge are two-dimensional: this ensures that their vertices will be shared between
1622+ // neighboring blocks, which share only one layer of points
16121623 bool middleX = (x != 0 && x != size);
16131624 bool middleY = (y != 0 && y != size);
16141625 bool middleZ = (z != 0 && z != size);
@@ -1653,6 +1664,8 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 38 unmodified lines
16531664 }
16541665 continue; // no corners set/all corners set
16551666 }
1667+ // the terrifying conditional code that follows checks each cube edge for a crossing, gathering
1668+ // its properties (color, material, normal) if one is present; as before, boundary edges are excluded
16561669 int clampedX = qMax(x - 1, 0), clampedY = qMax(y - 1, 0), clampedZ = qMax(z - 1, 0);
16571670 const QRgb* hermiteBase = hermiteData + clampedZ * hermiteArea + clampedY * hermiteStride +
16581671 clampedX * VoxelHermiteData::EDGE_COUNT;
@@ -1826,6 +1839,8 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 167 unmodified lines
18261839 }
18271840 crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite));
18281841 }
1842+ // at present, we simply average the properties of each crossing as opposed to finding the vertex that
1843+ // minimizes the quadratic error function as described in the reference paper
18291844 glm::vec3 center;
18301845 glm::vec3 normal;
18311846 const int MAX_MATERIALS_PER_VERTEX = 4;
@@ -1840,6 +1855,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
18401855 red += qRed(crossing.color);
18411856 green += qGreen(crossing.color);
18421857 blue += qBlue(crossing.color);
1858+
1859+ // when assigning a material, search for its presence and, if not found,
1860+ // place it in the first empty slot
18431861 if (crossing.material != 0) {
18441862 for (int j = 0; j < MAX_MATERIALS_PER_VERTEX; j++) {
18451863 if (materials[j] == crossing.material) {
@@ -1871,17 +1889,19 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 25 unmodified lines
18711889 int index = vertices.size();
18721890 vertices.append(point);
18731891
1892+ // the first x, y, and z are repeated for the boundary edge; past that, we consider generating
1893+ // quads for each edge that includes a transition, using indices of previously generated vertices
18741894 if (x != 0 && y != 0 && z != 0) {
18751895 if (alpha0 != alpha1) {
18761896 indices.append(index);
18771897 int index1 = lastLineIndices.at(x);
18781898 int index2 = lastPlaneIndices.at((y - 1) * expanded + x);
18791899 int index3 = lastPlaneIndices.at(y * expanded + x);
1880− if (alpha0 == 0) {
1900+ if (alpha0 == 0) { // quad faces negative x
18811901 indices.append(index3);
18821902 indices.append(index2);
18831903 indices.append(index1);
1884− } else {
1904+ } else { // quad faces positive x
18851905 indices.append(index1);
18861906 indices.append(index2);
18871907 indices.append(index3);
@@ -1893,11 +1913,11 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 5 unmodified lines
18931913 int index1 = lastIndex;
18941914 int index2 = lastPlaneIndices.at(y * expanded + x - 1);
18951915 int index3 = lastPlaneIndices.at(y * expanded + x);
1896− if (alpha0 == 0) {
1916+ if (alpha0 == 0) { // quad faces negative y
18971917 indices.append(index1);
18981918 indices.append(index2);
18991919 indices.append(index3);
1900− } else {
1920+ } else { // quad faces positive y
19011921 indices.append(index3);
19021922 indices.append(index2);
19031923 indices.append(index1);
@@ -1909,11 +1929,11 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 5 unmodified lines
19091929 int index1 = lastIndex;
19101930 int index2 = lastLineIndices.at(x - 1);
19111931 int index3 = lastLineIndices.at(x);
1912− if (alpha0 == 0) {
1932+ if (alpha0 == 0) { // quad faces negative z
19131933 indices.append(index3);
19141934 indices.append(index2);
19151935 indices.append(index1);
1916− } else {
1936+ } else { // quad faces positive z
19171937 indices.append(index1);
19181938 indices.append(index2);
19191939 indices.append(index3);