Detecting human body poses in 3D with Vision
At a glance
| Item | Summary |
|---|---|
| Purpose | Render skeletons of 3D body pose points in a scene overlaying the input image. |
| App architecture | A Swift sample with the source-visible chain HumanBodyPose3DApp → ContentView → HumanBodyPoseImageModel → HumanBodySkeletonRenderer → Vision APIs. |
| Main patterns | Publisher-backed observable state, Actor-isolated state |
| Project style | 8 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── HumanBodyPose3DApp/
│ ├── HumanBodyPose3DApp.swift
│ ├── Models/
│ │ ├── HumanBodyPoseImageModel.swift
│ │ └── HumanBodyPose3DDetector.swift
│ ├── Views/
│ │ ├── PhotoSelectionView.swift
│ │ ├── ContentView.swift
│ │ ├── HumanBodySkeletonRenderer.swift
│ │ ├── SkeletonSceneView.swift
│ │ └── HumanBodyPoseImage.swift
│ └── Info.plist
├── Configuration/
│ └── SampleCode.xcconfig
└── HumanBodyPose3DApp.xcodeproj/
├── .xcodesamplecode.plist
└── project.pbxproj
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 14 source declaration(s).
Overall architecture
flowchart LR
N1["HumanBodyPose3DApp"]
N2["ContentView"]
N3["HumanBodyPoseImageModel"]
N4["HumanBodySkeletonRenderer"]
N5["Vision APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
HumanBodyPose3DApp/HumanBodyPose3DApp.swift:11 — architecture anchor
@main
struct HumanBodyPose3DApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Vision.
Ownership and state
classDiagram
HumanBodyPoseImage o-- Image : image
HumanBodyPoseImage o-- PHAsset : selectedAsset
HumanBodyPoseImage o-- ImageState : imageState
HumanBodyPoseImage o-- PhotosPickerItem : imageSelection
Ownership evidence
HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:29 — stored dependency or nearest verified ownership anchor
struct HumanBodyPoseImage: Transferable {
let image: Image
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
HumanBodyPoseImage |
Image (image) |
stores or receives | Initialized by the owner; the binding is immutable |
HumanBodyPoseImage |
PHAsset (selectedAsset) |
stores or receives | App/module collaborators |
HumanBodyPoseImage |
ImageState (imageState) |
stores or receives | Owning type writes; wider scope can read |
HumanBodyPoseImage |
PhotosPickerItem (imageSelection) |
stores or receives | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
HumanBodyPose3DApp/HumanBodyPose3DApp.swift:12 — representative type boundary
struct HumanBodyPose3DApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
HumanBodyPose3DApp |
Application entry and top-level composition | App |
HumanBodyPoseImageModel |
Feature data or observable state | ObservableObject |
PhotoSelectionView |
User-interface presentation and input forwarding | View |
PhotoSelectorView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
HumanBodySkeletonRenderer |
Owns drawing, GPU, or presentation processing | NSObject |
SkeletonScene |
Scene lifecycle or scene-level composition | View |
PersonPlaceholderImageView |
User-interface presentation and input forwarding | View |
SelectablePersonPhotoView |
User-interface presentation and input forwarding | View |
ImageState |
Represents mutable feature state | Concrete collaborators/imported frameworks |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
calculateLocalAngleToParent (HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:21) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
runHumanBodyPose3DRequestOnImage (HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:42) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
imageState (HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:43) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
getAssetFileURL (HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:68) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
Reference code
HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:21 — representative boundary
public func calculateLocalAngleToParent(joint: VNHumanBodyPose3DObservation.JointName) -> simd_float3 {
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | HumanBodyPose3DApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | HumanBodyPoseImageModel |
The source’s Model suffix makes this role explicit. |
| Owns drawing, GPU, or presentation processing | HumanBodySkeletonRenderer |
The source’s Renderer suffix makes this role explicit. |
| Scene lifecycle or scene-level composition | SkeletonScene |
The source’s Scene suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, PersonPlaceholderImageView, PhotoSelectionView, PhotoSelectorView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Publisher-backed observable state | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:17 |
Published properties notify observers while mutation remains with the state object. |
| Actor-isolated state | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:53 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: HumanBodyPose3DApp; Model: HumanBodyPoseImageModel; Renderer: HumanBodySkeletonRenderer; Scene: SkeletonScene; View: ContentView, PersonPlaceholderImageView, PhotoSelectionView, PhotoSelectorView, SelectablePersonPhotoView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
loadOriginalFileURL,getAssetFileURL,loadAssetFromID,loadTransferable,requestAuthorization,relate3DSkeletonProportionToImagePlane,computeOffsetOfRoot,createInputImage2DNode. - Files:
HumanBodyPose3DApp/HumanBodyPose3DApp.swift,HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift,HumanBodyPose3DApp/Views/PhotoSelectionView.swift,HumanBodyPose3DApp/Views/ContentView.swift,HumanBodyPose3DApp/Views/HumanBodySkeletonRenderer.swift,HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift.
Architecture takeaways
HumanBodyPose3DAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, Vision, SceneKit, PhotosUI through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
HumanBodyPose3DApp/HumanBodyPose3DApp.swift |
HumanBodyPose3DApp |
HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift |
HumanBodyPoseImageModel, ImageState, TransferError, HumanBodyPoseImage |
HumanBodyPose3DApp/Views/PhotoSelectionView.swift |
PhotoSelectionView, PhotoSelectorView |
HumanBodyPose3DApp/Views/ContentView.swift |
ContentView |
HumanBodyPose3DApp/Views/HumanBodySkeletonRenderer.swift |
HumanBodySkeletonRenderer |
HumanBodyPose3DApp/Views/SkeletonSceneView.swift |
SkeletonScene |
HumanBodyPose3DApp/Views/HumanBodyPoseImage.swift |
HumanBodyImage, PersonPlaceholderImageView, SelectablePersonPhotoView |
HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift |
HumanBodyPose3DDetector |