Write the problem to a PLY file for inspection in Meshlab or CloudCompare.
| 178 | |
| 179 | // Write the problem to a PLY file for inspection in Meshlab or CloudCompare. |
| 180 | void BALProblem::WriteToPLYFile(const std::string& filename) const { |
| 181 | std::ofstream of(filename.c_str()); |
| 182 | |
| 183 | of << "ply" << '\n' |
| 184 | << "format ascii 1.0" << '\n' |
| 185 | << "element vertex " << num_cameras_ + num_points_ << '\n' |
| 186 | << "property float x" << '\n' |
| 187 | << "property float y" << '\n' |
| 188 | << "property float z" << '\n' |
| 189 | << "property uchar red" << '\n' |
| 190 | << "property uchar green" << '\n' |
| 191 | << "property uchar blue" << '\n' |
| 192 | << "end_header" << std::endl; |
| 193 | |
| 194 | // Export extrinsic data (i.e. camera centers) as green points. |
| 195 | double angle_axis[3]; |
| 196 | double center[3]; |
| 197 | for (int i = 0; i < num_cameras(); ++i) { |
| 198 | const double* camera = cameras() + camera_block_size() * i; |
| 199 | CameraToAngleAxisAndCenter(camera, angle_axis, center); |
| 200 | of << center[0] << ' ' << center[1] << ' ' << center[2] << " 0 255 0" |
| 201 | << '\n'; |
| 202 | } |
| 203 | |
| 204 | // Export the structure (i.e. 3D Points) as white points. |
| 205 | const double* points = parameters_ + camera_block_size() * num_cameras_; |
| 206 | for (int i = 0; i < num_points(); ++i) { |
| 207 | const double* point = points + i * point_block_size(); |
| 208 | for (int j = 0; j < point_block_size(); ++j) { |
| 209 | of << point[j] << ' '; |
| 210 | } |
| 211 | of << "255 255 255\n"; |
| 212 | } |
| 213 | of.close(); |
| 214 | } |
| 215 | |
| 216 | void BALProblem::CameraToAngleAxisAndCenter(const double* camera, |
| 217 | double* angle_axis, |