void write_plyFloat(char* outname, cv::Mat mat_Depth, cv::Mat mat_Color, cv::Mat mat_Faces){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << mat_Depth.rows << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "property uchar red\n"; ply2 << "property uchar green\n"; ply2 << "property uchar blue\n"; ply2 << "element face " << mat_Faces.rows << std::endl; ply2 << "property list uchar int vertex_indices\n"; ply2 << "end_header\n"; float colors[3]; for( int i = 0; i < mat_Depth.rows ; i++ ) { for (int j=0;j<3;j++) { colors[j] = mat_Color.at<float>(i,j); colors[j] = (colors[j]<0)?0:colors[j]; colors[j] = (colors[j]>255)?255:colors[j]; } ply2 << mat_Depth.at<float>(i,0) << " " << mat_Depth.at<float>(i,1) << " " << mat_Depth.at<float>(i,2) << " " << (int)colors[0] << " " << (int)colors[1] << " " << (int)colors[2] << std::endl; } for( int i = 0; i < mat_Faces.rows ; i++ ) { ply2 << "3 " << mat_Faces.at<int>(i,0) << " " << mat_Faces.at<int>(i,1) << " " << mat_Faces.at<int>(i,2) << " " << std::endl; } ply2.close(); }
void write_ply(char* outname, cv::Mat mat_Depth, cv::Mat mat_Color, cv::Mat mat_Faces){ mat_Color.convertTo(mat_Color,CV_8UC3); std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << mat_Depth.cols << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "property uchar red\n"; ply2 << "property uchar green\n"; ply2 << "property uchar blue\n"; ply2 << "element face " << mat_Faces.cols << std::endl; ply2 << "property list uchar int vertex_indices\n"; ply2 << "end_header\n"; for( int i = 0; i < mat_Depth.cols ; i++ ) { ply2 << mat_Depth.at<double>(0,i) << " " << mat_Depth.at<double>(1,i) << " " << mat_Depth.at<double>(2,i) << " " << (int)mat_Color.at<unsigned char>(0,i) << " " << (int)mat_Color.at<unsigned char>(1,i) << " " << (int)mat_Color.at<unsigned char>(2,i) << std::endl; } for( int i = 0; i < mat_Faces.cols ; i++ ) { ply2 << "3 " << mat_Faces.at<int>(0,i) << " " << mat_Faces.at<int>(1,i) << " " << mat_Faces.at<int>(2,i) << " " << std::endl; } ply2.close(); }
void write_ply(char* outname, cv::Mat mat_Depth,std::vector<cv::Vec3b> colors,cv::Mat faces){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << mat_Depth.cols << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "property uchar red\n"; ply2 << "property uchar green\n"; ply2 << "property uchar blue\n"; ply2 << "element face " << faces.cols << std::endl; ply2 << "property list uchar int vertex_indices\n"; ply2 << "end_header\n"; for( int i = 0; i < mat_Depth.cols ; i++ ) { ply2 << mat_Depth.at<double>(0,i) << " " << mat_Depth.at<double>(1,i) << " " << mat_Depth.at<double>(2,i) << " " << (int)colors[i](2) << " " << (int)colors[i](1) << " " << (int)colors[i](0) << std::endl; } for( int i = 0; i < faces.cols ; i++ ) { ply2 << "3 " << faces.at<int>(0,i) << " " << faces.at<int>(1,i) << " " << faces.at<int>(2,i) << " " << std::endl; } ply2.close(); }
void write_plyFloat(char* outname, cv::Mat mat_Depth){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << mat_Depth.cols << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "end_header\n"; for( int i = 0; i < mat_Depth.cols ; i++ ) { ply2 << mat_Depth.at<float>(0,i) << " " << mat_Depth.at<float>(1,i) << " " << mat_Depth.at<float>(2,i) << std::endl; } ply2.close(); }
void write_ply(char* outname, Eigen::Matrix3Xd* mesh){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << mesh->cols() << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "end_header\n"; for( int i = 0; i < mesh->cols() ; i++ ) { ply2 <<(*mesh)(0,i) << " " << (*mesh)(1,i) << " " << (*mesh)(2,i) << std::endl; } ply2.close(); }
void write_ply(char* outname, int count, float* points_){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << count << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "end_header\n"; for( int i = 0; i < count ; i++ ) { ply2 << points_[3*i] << " " << points_[3*i+1] << " " << points_[3*i+2] << std::endl; } ply2.close(); }
void write_ply(char* outname, std::vector<cv::Point3f> points){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << points.size() << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "end_header\n"; for( int i = 0; i < points.size() ; i++ ) { ply2 << points[i].x << " " << points[i].y << " " << points[i].z << std::endl; } ply2.close(); }
void write_ply(char* outname, bool* visible, cv::Mat mat_Depth,std::vector<cv::Vec3b> colors,cv::Mat faces){ std::vector<int> vindices; std::vector<int> vindices_inv; std::vector<int> findices; for (int i=0;i<colors.size();i++) { if (visible[i]) { vindices_inv.push_back(vindices.size()); vindices.push_back(i); } else vindices_inv.push_back(-1); } //printf("vindices_inv %d\n",vindices_inv.size()); for (int i=0;i<faces.cols;i++) { bool vis = true; for (int j=0;j<3;j++) if (!visible[faces.at<unsigned int>(j,i)]) { vis = false; break; } if (vis) findices.push_back(i); } std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << vindices.size() << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "property uchar red\n"; ply2 << "property uchar green\n"; ply2 << "property uchar blue\n"; ply2 << "element face " << findices.size() << std::endl; ply2 << "property list uchar int vertex_indices\n"; ply2 << "end_header\n"; for( int i = 0; i < vindices.size() ; i++ ) { int ind = vindices[i]; ply2 << mat_Depth.at<double>(0,ind) << " " << mat_Depth.at<double>(1,ind) << " " << mat_Depth.at<double>(2,ind) << " " << (int)colors[ind](2) << " " << (int)colors[ind](1) << " " << (int)colors[ind](0) << std::endl; } for( int i = 0; i < findices.size() ; i++ ) { ply2 << "3 " << vindices_inv[faces.at<unsigned int>(0,findices[i])] << " " << vindices_inv[faces.at<unsigned int>(1,findices[i])] << " " << vindices_inv[faces.at<unsigned int>(2,findices[i])] << " " << std::endl; } ply2.close(); }
CreatePolygonTreesTest() : _p0(nullptr), _p1(nullptr), _p2(nullptr), _p3(nullptr) { // create points and construct polygon _pnts.push_back(new GeoLib::Point(0.0,-1.0,0.0)); _pnts.push_back(new GeoLib::Point(1.0,0.0,0.0)); _pnts.push_back(new GeoLib::Point(0.0,1.0,0.0)); _pnts.push_back(new GeoLib::Point(-1.0,0.0,0.0)); _pnts.push_back(new GeoLib::Point(-0.9,0.0,0.0)); _pnts.push_back(new GeoLib::Point(0.75,-0.1,0.0)); _pnts.push_back(new GeoLib::Point(-0.75,-0.1,0.0)); // create closed polylines GeoLib::Polyline ply0(_pnts); ply0.addPoint(3); ply0.addPoint(1); ply0.addPoint(2); ply0.addPoint(3); GeoLib::Polyline ply1(_pnts); ply1.addPoint(0); ply1.addPoint(1); ply1.addPoint(3); ply1.addPoint(0); GeoLib::Polyline ply2(_pnts); ply2.addPoint(0); ply2.addPoint(1); ply2.addPoint(2); ply2.addPoint(3); ply2.addPoint(0); GeoLib::Polyline ply3(_pnts); ply3.addPoint(4); ply3.addPoint(5); ply3.addPoint(6); ply3.addPoint(4); // create polygons _p0 = new GeoLib::Polygon(ply0); _p1 = new GeoLib::Polygon(ply1); _p2 = new GeoLib::Polygon(ply2); _p3 = new GeoLib::Polygon(ply3); }
void write_ply(char* outname, cv::Mat mat_Depth, cv::Mat mat_Faces){ std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << mat_Depth.cols << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "element face " << mat_Faces.cols << std::endl; ply2 << "property list uchar int vertex_indices\n"; ply2 << "end_header\n"; for( int i = 0; i < mat_Depth.cols ; i++ ) { ply2 << mat_Depth.at<double>(0,i) << " " << mat_Depth.at<double>(1,i) << " " << mat_Depth.at<double>(2,i) << std::endl; } for( int i = 0; i < mat_Faces.cols ; i++ ) { ply2 << "3 " << mat_Faces.at<int>(0,i) << " " << mat_Faces.at<int>(1,i) << " " << mat_Faces.at<int>(2,i) << " " << std::endl; } ply2.close(); }
void write_ply(char* outname, int count, bool* visible, float* points_){ std::vector<int> inds; for (int i=0;i<count;i++){ if (visible[i]) inds.push_back(i); } std::ofstream ply2( outname ); ply2 << "ply\n"; ply2 << "format ascii 1.0\n"; ply2 << "element vertex " << inds.size() << std::endl; ply2 << "property float x\n"; ply2 << "property float y\n"; ply2 << "property float z\n"; ply2 << "end_header\n"; for( int i = 0; i < inds.size() ; i++ ) { int ind = inds[i]; ply2 << points_[3*ind] << " " << points_[3*ind+1] << " " << points_[3*ind+2] << std::endl; } ply2.close(); }