当前位置: 首页>>代码示例>>C++>>正文


C++ TriangleList::resize方法代码示例

本文整理汇总了C++中TriangleList::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleList::resize方法的具体用法?C++ TriangleList::resize怎么用?C++ TriangleList::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TriangleList的用法示例。


在下文中一共展示了TriangleList::resize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calculateSplittingOfMesh

void calculateSplittingOfMesh() {
    
    //need to change dividing by also
    const unsigned dim = 32; //dimension of voxel grid (e.g. 32x32x32)
    int mass[dim] = {};
    int voxcount[dim] = {};
    float totalcount = 0;
    float massheight = 0;
    float totalmass = 0;
    int com[dim] = {};
    int average = 0;
    int cut1 = 0;
    int cut2 = 0;
    int pointer = 0;
    
    CompFab::Mesh tempMesh("bunny.obj", true);
    
    triangleList.resize(tempMesh.t.size());
    
    //copy triangles to global list
    for (unsigned i = 0; i < tempMesh.t.size(); ++i) {
        triangleList[i].v0 = tempMesh.v[tempMesh.t[i][0]];
        triangleList[i].v1 = tempMesh.v[tempMesh.t[i][1]];
        triangleList[i].v2 = tempMesh.v[tempMesh.t[i][2]];
    }
    
    //Create Voxel Grid
    V3 bbMax, bbMin;
    BBox(tempMesh, bbMin, bbMax);
    
    //Build Voxel Grid
    Real bbX = bbMax[0] - bbMin[0];
    Real bbY = bbMax[1] - bbMin[1];
    Real bbZ = bbMax[2] - bbMin[2];
    Real spacing;
    
    if (bbX > bbY && bbX > bbZ) {
        spacing = bbX / (Real)(dim - 2);
    } else if (bbY > bbX && bbY > bbZ) {
        spacing = bbY / (Real)(dim - 2);
    } else {
        spacing = bbZ / (Real)(dim - 2);
    }
    
    V3 hspacing(0.5 * spacing);

    voxelGrid = CompFab::VoxelGrid(bbMin - hspacing, dim, dim, dim, spacing);
    
    
    
    V3 voxelPos;
    V3 direction(1, 0, 0);
    /********* ASSIGNMENT *********/
    /* Iterate over all voxels in voxelGrid and test whether they are inside our outside of the
     * surface defined by the triangles in triangleList */
    for (int i = 0; i < dim; i++) {
        for (int k = 0; k < dim; k++) {
            for (int j = 0; j < dim; j++) {
                //find i-voxel
                V3 voxeli = V3(i * voxelGrid.spacing, 0, 0);
                //find j-voxel
                V3 voxelj = V3(0, j * voxelGrid.spacing, 0);
                //find k-voxel
                V3 voxelk = V3(0, 0, k * voxelGrid.spacing);
                //find the new position from iteration, start from origin then add each dimension
                voxelPos = voxelGrid.lowerLeft + voxeli + voxelj + voxelk;
                voxelGrid.isInside(i, j, k) = numSurfaceIntersections(voxelPos, direction) % 2;
                if (voxelGrid.isInside(i, j, k)) { mass[j]++; voxcount[j]++;}
            }
        }
    }
    //compilation of all COM after each layer is change to 0.2 mass
    
    for (int p = dim-1; p > 0-1; p--) {
        mass[p] = 0.2*mass[p];
        for (int q = 0; q < dim; q++) {
            totalmass = totalmass + mass[q];
            massheight = massheight + (mass[q] * q);
        }
        com[p]= ceil(massheight / totalmass);
        //printf("COM%d is %d\n", p, com[p]);
        totalmass = 0;
        massheight = 0;
    }
    int cut = dim - 1;
    for (int p = dim - 1; p > 0; p--) {
        if (com[cut] >= com[p]) {
            cut = p;
        }
    }
    
    for (int i = 0; i < dim; i++) {
        totalcount = totalcount + voxcount[i];
        printf("Layer%d voxcount=%d\n", i, voxcount[i]);
    }
    
    // sorts in ascending order
    std::sort(std::begin(voxcount), std::end(voxcount));
    
    //percentile calculation
//.........这里部分代码省略.........
开发者ID:nikhilsh,项目名称:Tribilizer,代码行数:101,代码来源:main.cpp


注:本文中的TriangleList::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。