void DepthExporter::exportPlyCloud(string filename, int width, int height, const bool* mask, const float* depth, const unsigned char* color) { ofstream ply; ply.open(ofToDataPath(filename).c_str(), ios::out | ios::binary); if (ply.is_open()) { // create all the vertices stringstream vertices(ios::in | ios::out | ios::binary); int total = exportPlyVertices(vertices, width, height, mask, depth, color); // write the header ply << "ply" << endl; ply << "format binary_little_endian 1.0" << endl; ply << "element vertex " << total << endl; ply << "property float x" << endl; ply << "property float y" << endl; ply << "property float z" << endl; if (color != NULL) { ply << "property uchar red" << endl; ply << "property uchar green" << endl; ply << "property uchar blue" << endl; } ply << "end_header" << endl; // write all the vertices ply << vertices.rdbuf(); } }
int CRodObj::exportElemNodes(FILE *fp, const int baseno, const double *pmatrix, const double thickness) { extern void exportPlyVertices(FILE *fp, Vector3d *pVertex, const int nv, double _th, double *pThick, const int baseno, const double *pmatrix); exportPlyVertices(fp, m_pVertex, m_nVertexCount, thickness, NULL, baseno, pmatrix); return m_nVertexCount; }
int CTriangleObj::exportElemNodes(FILE *fp, const int baseno, const double *pmatrix, const double thickness) { exportPlyVertices(fp, m_pVertex, m_nVertexCount, thickness, NULL, baseno, pmatrix); return m_nVertexCount; }
void DepthExporter::exportPlyMesh(string filename, int width, int height, const bool* mask, const float* depth, const unsigned char* color) { ofstream ply; ply.open(ofToDataPath(filename).c_str(), ios::out | ios::binary); if (ply.is_open()) { int n = width * height; unsigned int* names = new unsigned int[n]; // label all the vertices int total = 0; for (int i = 0; i < n; i++) if (!mask[i]) names[i] = total++; // create all the vertices stringstream vertices(ios::in | ios::out | ios::binary); exportPlyVertices(vertices, width, height, mask, depth, color); // create all the faces int totalFaces = 0; int nw, ne, sw, se; stringstream faces(ios::in | ios::out | ios::binary); for (int y = 0; y < height - 1; y++) { for (int x = 0; x < width - 1; x++) { nw = y * width + x; ne = nw + 1; sw = nw + width; se = ne + width; if (!mask[nw] && !mask[se]) { if (!mask[ne]) { exportPlyFace(faces, names[se], names[ne], names[nw]); totalFaces++; } if (!mask[sw]) { exportPlyFace(faces, names[sw], names[se], names[nw]); totalFaces++; } } else if (!mask[ne] && !mask[sw]) { if (!mask[nw]) { exportPlyFace(faces, names[sw], names[ne], names[nw]); totalFaces++; } if (!mask[se]) { exportPlyFace(faces, names[sw], names[se], names[ne]); totalFaces++; } } } } // write the header ply << "ply" << endl; ply << "format binary_little_endian 1.0" << endl; ply << "element vertex " << total << endl; ply << "property float x" << endl; ply << "property float y" << endl; ply << "property float z" << endl; if (color != NULL) { ply << "property uchar red" << endl; ply << "property uchar green" << endl; ply << "property uchar blue" << endl; } ply << "element face " << totalFaces << endl; ply << "property list uchar uint vertex_indices" << endl; ply << "end_header" << endl; ply << vertices.rdbuf(); ply << faces.rdbuf(); delete [] names; } }