Example #1
0
void MeshGeometry::extract_faces_from_hexes() {
    const VectorI& voxels = m_voxels;
    typedef std::map<Multiplet, int> FaceCounter;
    FaceCounter face_counter;

    for (size_t i=0; i<voxels.size(); i+= m_vertex_per_voxel) {
        VectorI voxel = voxels.segment(i, m_vertex_per_voxel);
        // Note that the order of vertices below are predefined by MSH format,
        // each face should have normal pointing outward.
        assert(voxel.size() == 8);
        Multiplet voxel_faces[6] = {
            Multiplet(Vector4I(voxel[0], voxel[1], voxel[5], voxel[4])), // Bottom
            Multiplet(Vector4I(voxel[2], voxel[3], voxel[7], voxel[6])), // Top
            Multiplet(Vector4I(voxel[0], voxel[4], voxel[7], voxel[3])), // Left
            Multiplet(Vector4I(voxel[1], voxel[2], voxel[6], voxel[5])), // Right
            Multiplet(Vector4I(voxel[4], voxel[5], voxel[6], voxel[7])), // Front
            Multiplet(Vector4I(voxel[0], voxel[3], voxel[2], voxel[1]))  // Back
        };

        for (size_t j=0; j<6; j++) {
            if (face_counter.find(voxel_faces[j]) == face_counter.end()) {
                face_counter[voxel_faces[j]] = 1;
            } else {
                face_counter[voxel_faces[j]] += 1;
            }
        }
    }

    std::vector<int> vertex_buffer;
    for (FaceCounter::const_iterator itr = face_counter.begin();
            itr!=face_counter.end(); itr++) {
        if (itr->second != 1 && itr->second != 2) {
            const Vector4I& face = itr->first.get_ori_data();
            std::stringstream err_msg;
            err_msg << "Non-manifold mesh detected!" << std::endl;
            err_msg << "Face <"
                << face[0] << ", "
                << face[1] << ", "
                << face[2] << ", "
                << face[3] << "> has "
                << itr->second << " adjacent volume elements";
            throw RuntimeError(err_msg.str());
        }
        if (itr->second == 1) {
            const VectorI& f = itr->first.get_ori_data();
            assert(f.size() == 4);
            vertex_buffer.push_back(f[0]);
            vertex_buffer.push_back(f[1]);
            vertex_buffer.push_back(f[2]);
            vertex_buffer.push_back(f[3]);
        }
    }

    m_faces.resize(vertex_buffer.size());
    std::copy(vertex_buffer.begin(), vertex_buffer.end(), m_faces.data());
    m_vertex_per_face = 4;
}
void BodyPartClassifier::initCentroidpoint(void)
{
	// initialize memory
	memset(m_CoordWorldSpace,0, INFER_IMAGE_HEIGHT*INFER_IMAGE_WIDTH*sizeof(Vector4));
	memset(m_PartCentroid,0, _SUPPROT_PERSON_NUMBER_*_BODY_PART_NUMBER_*sizeof(Vector4));
	memset(m_PartCount,0, _SUPPROT_PERSON_NUMBER_*_BODY_PART_NUMBER_*sizeof(int));

	int x, y;
	int orix,oriy,pid,partid;
	ushort depthv;
	Vector4 worldcord;
	float probability;
#pragma omp parallel for private(x,orix,oriy,depthv,pid,worldcord,partid,probability)
	for (y = 0; y < INFER_IMAGE_HEIGHT; y++)
	{
		for (x = 0; x < INFER_IMAGE_WIDTH; x++)
		{
			orix = (int)(m_ScaleWidth * x);
			oriy = (int)(m_ScaleHeight * y);
			depthv = m_DepthMat.ptr<ushort>(oriy)[orix];
			pid = m_MaskMat.ptr<uchar>(oriy)[orix];

			if(pid == 0 || pid > _SUPPROT_PERSON_NUMBER_)
				continue;

			ImageToWorldSpace(Vector4I(x,y,depthv),worldcord);

			m_CoordWorldSpace[y][x] = worldcord;

			for (partid = 0; partid < _BODY_PART_NUMBER_; partid++)
			{
				probability = m_PriorMat[pid - 1][partid].ptr<float>(y)[x];
				probability /= (m_forest.TreeNumber()*255.0f);
				m_PriorMat[pid - 1][partid].ptr<float>(y)[x] = probability;

				if (probability > 0.14f)
				{
					m_PartCentroid[pid - 1][partid].x += worldcord.x;
					m_PartCentroid[pid - 1][partid].y += worldcord.y;
					m_PartCentroid[pid - 1][partid].z += worldcord.z;

					m_PartCount[pid - 1][partid] += 1;
				}

			}
		}
	}
}
Example #3
0
void ManualMesh::position(float x,float y,float z,float w)
{
	if(!begun)return;
	if(vertex.size() ==0 && strip.size() == 0)beginStrip();
	vertex.push_back(Vector4I(x,y,z,w));
}