| 1447 | } |
| 1448 | |
| 1449 | std::vector<InputCamera::Ptr> InputCamera::loadJSON(const std::string& jsonPath, const float zNear, const float zFar) |
| 1450 | { |
| 1451 | std::ifstream json_file(jsonPath, std::ios::in); |
| 1452 | |
| 1453 | if (!json_file) |
| 1454 | { |
| 1455 | std::cerr << "file loading failed: " << jsonPath << std::endl; |
| 1456 | return std::vector<InputCamera::Ptr>(); |
| 1457 | } |
| 1458 | |
| 1459 | std::vector<InputCamera::Ptr> cameras; |
| 1460 | |
| 1461 | picojson::value v; |
| 1462 | picojson::set_last_error(std::string()); |
| 1463 | std::string err = picojson::parse(v, json_file); |
| 1464 | if (!err.empty()) { |
| 1465 | picojson::set_last_error(err); |
| 1466 | json_file.setstate(std::ios::failbit); |
| 1467 | } |
| 1468 | |
| 1469 | picojson::array& frames = v.get<picojson::array>(); |
| 1470 | |
| 1471 | for (size_t i = 0; i < frames.size(); ++i) |
| 1472 | { |
| 1473 | int id = frames[i].get("id").get<double>(); |
| 1474 | std::string imgname = frames[i].get("img_name").get<std::string>(); |
| 1475 | int width = frames[i].get("width").get<double>(); |
| 1476 | int height = frames[i].get("height").get<double>(); |
| 1477 | float fy = frames[i].get("fy").get<double>(); |
| 1478 | float fx = frames[i].get("fx").get<double>(); |
| 1479 | |
| 1480 | sibr::InputCamera::Ptr camera = std::make_shared<InputCamera>(InputCamera(fy, fx, 0.0f, 0.0f, width, height, id)); |
| 1481 | |
| 1482 | picojson::array& pos = frames[i].get("position").get<picojson::array>(); |
| 1483 | sibr::Vector3f position(pos[0].get<double>(), pos[1].get<double>(), pos[2].get<double>()); |
| 1484 | |
| 1485 | //position.x() = 0; |
| 1486 | //position.y() = 0; |
| 1487 | //position.z() = 1; |
| 1488 | |
| 1489 | picojson::array& rot = frames[i].get("rotation").get<picojson::array>(); |
| 1490 | sibr::Matrix3f orientation; |
| 1491 | for (int i = 0; i < 3; i++) |
| 1492 | { |
| 1493 | picojson::array& row = rot[i].get<picojson::array>(); |
| 1494 | for (int j = 0; j < 3; j++) |
| 1495 | { |
| 1496 | orientation(i, j) = row[j].get<double>(); |
| 1497 | } |
| 1498 | } |
| 1499 | orientation.col(1) = -orientation.col(1); |
| 1500 | orientation.col(2) = -orientation.col(2); |
| 1501 | //orientation = sibr::Matrix3f::Identity(); |
| 1502 | |
| 1503 | camera->name(imgname); |
| 1504 | camera->position(position); |
| 1505 | camera->rotation(sibr::Quaternionf(orientation)); |
| 1506 | camera->znear(zNear); |