Skip to content

Commit 9d68380

Browse files
committed
remove v
2 parents a6cac28 + f26f6eb commit 9d68380

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

AGENTS.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# Repository Guidelines
22

33
## Project Structure & Module Organization
4-
Core C++ sources live in `src/spatialmp4`, with corresponding headers under `spatialmp4/`. Pybind11 bridge code is under `bindings/`, while the published Python package pieces sit in `python/`. Reference assets are stored in `video/`, reusable build logic in `cmake/`, and helper scripts in `scripts/`. End-user docs and design notes are collected in `docs/`, and runnable walkthroughs reside in `examples/`.
4+
Core C++ sources live in `src/spatialmp4`, with helpers under `src/spatialmp4/utilities` and Google Test fixtures in `src/spatialmp4/reader_test.cc`.
5+
Python bindings are assembled in `bindings/spatialmp4.cpp`, while Python packaging and tests sit in `python/`.
6+
Reference assets (for example `video/test.mp4`) and temporary visualization outputs (`tmp_vis_depth/`) are kept at the repository root.
7+
Example end-to-end scripts are available under `examples/python` and double as smoke tests for new features.
58

69
## Build, Test, and Development Commands
7-
Build FFmpeg and third-party dependencies once via `bash scripts/build_ffmpeg.sh` (or `pixi run build-ffmpeg`). Configure and compile the C++ library with `pixi run build`, which wraps the Ninja-based CMake invocation. For a clean rebuild, use `pixi run rebuild`. Run the C++ regression suite with `pixi run test` (expects `video/test.mp4` relative to `build/`), and execute Python coverage with `pixi run test-python`. When debugging locally outside Pixi, replicate the commands shown inside `pixi.toml`.
10+
Install third-party dependencies and FFmpeg once via `bash scripts/install_deps.sh` and `bash scripts/build_ffmpeg.sh`.
11+
A standard native build flow is `cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=OFF` followed by `cmake --build build`.
12+
When using Pixi, `pixi run build-ffmpeg`, `pixi run build`, and `pixi run rebuild` mirror those steps.
13+
Package the Python wheel with `pip install .` or `pixi run build` after enabling `-DBUILD_PYTHON=ON`.
14+
Run cpp unittest: `./build/host/test_reader`. Run python unittest: `pytest -s python/tests`
815

916
## Coding Style & Naming Conventions
10-
We enforce clang-format 17 using the repository `.clang-format` (Google base style, two-space indentation, 120 character limit). Ensure each new C++ source file includes the license header inserted by the `insert-license` pre-commit hook. Function and type names should be in PascalCase, while variables use lower_snake_case; mirror existing reader/writer APIs. Python modules follow PEP 8, with snake_case functions and CapWords classes. Install the hooks with `pre-commit install` and run `pre-commit run --all-files` before uploading.
17+
`.clang-format` enforces Google style with 2-space indentation, 120-character lines, and brace-on-same-line formatting. Run `pre-commit run --all-files` (configured for `clang-format` and license insertion) before submitting patches. C++ classes use PascalCase (e.g., `RandomAccessVideoReader`), member functions stay in UpperCamelCase, and local variables use snake_case. Python modules follow PEP 8 naming; prefer snake_case for functions and lower_case_with_underscores for files.
1118

1219
## Testing Guidelines
13-
Prefer authoring new C++ tests next to the feature under `src/spatialmp4/tests` or augmenting `test_reader`. Tests should gate on fixtures in `video/` or clearly documented synthetic inputs. Python tests belong in `python/tests/` and must start with `test_`. Document any new assets and keep them under 5 MB where possible. Capture expected outputs or assertions that cover RGB and depth code paths when adding spatial data features.
20+
Enable the C++ test suite with `cmake -B build -S . -DBUILD_TESTING=ON && cmake --build build`, then execute `VIDEO=../video/test.mp4 ./build/test_reader`. The Pixi shortcut `pixi run test` wraps the same flow. Python tests live in `python/tests` and use pytest; run them with `pixi run test-python` or `pytest python/tests`. New tests should follow the `test_*.py` or `*_test.cc` naming pattern and cover both RGB-only and depth-enabled paths; set the `VIDEO` environment variable when a custom fixture is required.
1421

1522
## Commit & Pull Request Guidelines
16-
Commit messages are short, present-tense imperatives (e.g., `add depth frame normalizer`). Group related changes per commit; avoid umbrella “update” descriptions. Pull requests must describe the motivation, list functional changes, and call out breaking API shifts. Reference tracked issues with `Fixes #ID` when applicable, include reproduction or validation commands (copy the `pixi run …` steps), and attach screenshots for visualization updates.
23+
History favors short, imperative commit subjects (for example, `set loglevel in reader`). Keep message bodies concise, reference related issues, and group mechanical formatting changes separately from functional updates. Pull requests should describe the feature or fix, outline test coverage (`pixi run test`, `pixi run test-python`, manual example scripts), and include screenshots or logs when touching visualization or CLI output. Ensure CI prerequisites (FFmpeg build, dependencies) are documented in the PR notes for new contributors.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ camera_extrinsics GetRgbExtrinsicsLeft() const; // Left RGB camera extrinsics
268268
camera_extrinsics GetRgbExtrinsicsRight() const; // Right RGB camera extrinsics
269269
camera_intrinsics GetDepthIntrinsics() const; // Depth camera intrinsics
270270
camera_extrinsics GetDepthExtrinsics() const; // Depth camera extrinsics
271+
bool IsRgbDistorted() const; // Whether RGB stream applies lens distortion
272+
std::string GetRgbDistortionModel() const; // Distortion model name (e.g., kBrownConrady)
273+
std::string GetRgbDistortionParamsLeft() const; // Left RGB distortion parameters
274+
std::string GetRgbDistortionParamsRight() const; // Right RGB distortion parameters
271275
```
272276

273277
#### Reading Control Methods
@@ -378,6 +382,10 @@ Main class for reading SpatialMP4 files.
378382
- `get_rgb_extrinsics_right() -> CameraExtrinsics` — Get right RGB camera extrinsics.
379383
- `get_depth_intrinsics() -> CameraIntrinsics` — Get depth camera intrinsics.
380384
- `get_depth_extrinsics() -> CameraExtrinsics` — Get depth camera extrinsics.
385+
- `is_rgb_distorted() -> bool` — Whether the RGB stream includes lens distortion.
386+
- `get_rgb_distortion_model() -> str` — Distortion model name (`"kBrownConrady"`, etc.).
387+
- `get_rgb_distortion_params_left() -> str` — Serialized left-eye distortion parameters.
388+
- `get_rgb_distortion_params_right() -> str` — Serialized right-eye distortion parameters.
381389
- `get_pose_frames() -> List[PoseFrame]` — Get all pose frames.
382390
- `set_read_mode(mode: ReadMode)` — Set reading mode (see enums below).
383391
- `has_next() -> bool` — Whether there is a next frame.

bindings/spatialmp4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ PYBIND11_MODULE(spatialmp4, m) {
153153

154154
// Bind Reader class
155155
py::class_<SpatialML::Reader>(m, "Reader")
156-
.def(py::init<const std::string &>())
156+
.def(py::init<const std::string &, const std::string &>(), py::arg("filename"), py::arg("log_level") = "quiet")
157157
.def("has_rgb", &SpatialML::Reader::HasRGB)
158158
.def("has_depth", &SpatialML::Reader::HasDepth)
159159
.def("has_pose", &SpatialML::Reader::HasPose)

scripts/build_ffmpeg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ build_install_opencv() {
126126
BUILD_FLAGS="
127127
-D CMAKE_BUILD_TYPE=RELEASE
128128
-D BUILD_LIST=core,imgproc,imgcodecs
129-
-D WITH_TBB=ON
129+
-D WITH_TBB=OFF
130130
-D WITH_OPENEXR=ON
131131
-D WITH_EIGEN=ON
132132
-D WITH_GSTREAMER=OFF

src/spatialmp4/reader.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,31 @@ AVFrame* RandomAccessVideoReader::process_frame(AVFrame* frame) {
226226

227227
/******************** Reader ********************/
228228

229-
Reader::Reader(const std::string& filename)
229+
void SetFFmpegLogLevel(const std::string& log_level) {
230+
static const std::unordered_map<std::string, int> log_level_map = {
231+
{"quiet", AV_LOG_QUIET},
232+
{"panic", AV_LOG_PANIC},
233+
{"fatal", AV_LOG_FATAL},
234+
{"error", AV_LOG_ERROR},
235+
{"warning", AV_LOG_WARNING},
236+
{"info", AV_LOG_INFO},
237+
{"verbose", AV_LOG_VERBOSE},
238+
{"debug", AV_LOG_DEBUG},
239+
{"trace", AV_LOG_TRACE}
240+
};
241+
242+
auto it = log_level_map.find(log_level);
243+
if (it != log_level_map.end()) {
244+
av_log_set_level(it->second);
245+
} else {
246+
spdlog::warn("Invalid FFmpeg log level: '{}'. Using 'warning' as default.", log_level);
247+
av_log_set_level(AV_LOG_WARNING);
248+
}
249+
}
250+
251+
Reader::Reader(const std::string& filename, const std::string& log_level)
230252
: filename_(filename),
253+
log_level_(log_level),
231254
read_mode_(ReadMode::DEPTH_FIRST),
232255
pFormatCtx_(NULL),
233256
has_rgb_(false),
@@ -253,7 +276,8 @@ Reader::Reader(const std::string& filename)
253276
keyframe_rgb_idx_(0),
254277
allframe_rgb_idx_(0),
255278
keyframe_depth_idx_(0) {
256-
// av_log_set_level(AV_LOG_DEBUG);
279+
280+
SetFFmpegLogLevel(log_level_);
257281

258282
if (filename_.find(' ') != std::string::npos) {
259283
throw std::runtime_error("Find blank in filename, please fix it.");
@@ -821,7 +845,7 @@ bool Reader::SeekToRgbKeyframe(int64_t target_pts) {
821845
}
822846

823847
bool Reader::IsLastFrame() {
824-
std::cout << "GetIndex: " << GetIndex() << ", GetFrameCount: " << GetFrameCount() << std::endl;
848+
// std::cout << "GetIndex: " << GetIndex() << ", GetFrameCount: " << GetFrameCount() << std::endl;
825849
return GetIndex() == GetFrameCount() - 1;
826850
}
827851

src/spatialmp4/reader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class SPATIALMP4_EXPORT Reader {
102102
}
103103
}
104104

105-
Reader(const std::string& filename);
105+
Reader(const std::string& filename, const std::string& log_level);
106106
~Reader();
107107

108108
bool HasRGB() const { return has_rgb_; }
@@ -157,6 +157,7 @@ class SPATIALMP4_EXPORT Reader {
157157

158158
private:
159159
std::string filename_;
160+
std::string log_level_;
160161
ReadMode read_mode_;
161162
AVFormatContext* pFormatCtx_;
162163
AVPacket current_packet_;

0 commit comments

Comments
 (0)